agent-relay 1.3.0 → 1.3.1
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/dashboard/out/404.html +1 -1
- package/dist/dashboard/out/_next/static/chunks/{899-bb19a9b3d9b39ea6.js → 899-fc02ed79e3de4302.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/app/app/onboarding/page-8553743baca53a00.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/app/app/{page-5af1b6b439858aa6.js → page-c617745b81344f4f.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/app/connect-repos/page-3538dfe0ffe984b8.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/app/history/{page-8c8bed33beb2bf1c.js → page-abb9ab2d329f56e9.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/app/layout-c0d118c0f92d969c.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/app/login/{page-16f3b49e55b1e0ed.js → page-c22d080201cbd9fb.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/app/metrics/{page-ac39dc0cc3c26fa7.js → page-f829604fb75a831a.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/app/{page-4a5938c18a11a654.js → page-dc786c183425c2ac.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/app/pricing/page-b08ed1c34d14434a.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/app/providers/page-84322991d7244499.js +1 -0
- package/dist/dashboard/out/_next/static/chunks/app/providers/setup/[provider]/{page-09f9caae98a18c09.js → page-05606941a8e2be83.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/app/signup/{page-547dd0ca55ecd0ba.js → page-68d34f50baa8ab6b.js} +1 -1
- package/dist/dashboard/out/_next/static/chunks/{main-app-5d692157a8eb1fd9.js → main-app-6e8e8d3ef4e0192a.js} +1 -1
- package/dist/dashboard/out/_next/static/css/48a8fbe3e659080e.css +1 -0
- package/dist/dashboard/out/app/onboarding.html +1 -1
- package/dist/dashboard/out/app/onboarding.txt +2 -2
- package/dist/dashboard/out/app.html +1 -1
- package/dist/dashboard/out/app.txt +2 -2
- package/dist/dashboard/out/connect-repos.html +1 -1
- package/dist/dashboard/out/connect-repos.txt +2 -2
- package/dist/dashboard/out/history.html +1 -1
- package/dist/dashboard/out/history.txt +2 -2
- package/dist/dashboard/out/index.html +1 -1
- package/dist/dashboard/out/index.txt +2 -2
- package/dist/dashboard/out/login.html +2 -2
- package/dist/dashboard/out/login.txt +2 -2
- package/dist/dashboard/out/metrics.html +1 -1
- package/dist/dashboard/out/metrics.txt +2 -2
- package/dist/dashboard/out/pricing.html +2 -2
- package/dist/dashboard/out/pricing.txt +2 -2
- package/dist/dashboard/out/providers/setup/claude.html +1 -1
- package/dist/dashboard/out/providers/setup/claude.txt +2 -2
- package/dist/dashboard/out/providers/setup/codex.html +1 -1
- package/dist/dashboard/out/providers/setup/codex.txt +2 -2
- package/dist/dashboard/out/providers.html +1 -1
- package/dist/dashboard/out/providers.txt +2 -2
- package/dist/dashboard/out/signup.html +2 -2
- package/dist/dashboard/out/signup.txt +2 -2
- package/package.json +1 -1
- package/dist/dashboard/out/_next/static/chunks/app/app/onboarding/page-8939b0fc700f7eca.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/connect-repos/page-f45ecbc3e06134fc.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/layout-2433bb48965f4333.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/pricing/page-982a7000fee44014.js +0 -1
- package/dist/dashboard/out/_next/static/chunks/app/providers/page-ac3a6ac433fd6001.js +0 -1
- package/dist/dashboard/out/_next/static/css/85d2af9c7ac74d62.css +0 -1
- /package/dist/dashboard/out/_next/static/{T1tgCqVWHFIkV7ClEtzD7 → sDcbGRTYLcpPvyTs_rsNb}/_buildManifest.js +0 -0
- /package/dist/dashboard/out/_next/static/{T1tgCqVWHFIkV7ClEtzD7 → sDcbGRTYLcpPvyTs_rsNb}/_ssgManifest.js +0 -0
package/dist/dashboard/out/_next/static/chunks/{899-bb19a9b3d9b39ea6.js → 899-fc02ed79e3de4302.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[899],{9165:function(e,t,r){r.d(t,{Zk:function(){return i},_V:function(){return o},xv:function(){return d}});var s=r(9116);let n=new Set,a=null;function o(){return a}function l(e){let t=e.headers.get("X-CSRF-Token");t&&(a=t,(0,s.aM)(t))}function i(e){return n.add(e),()=>n.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 s=await fetch(e,{...t,credentials:"include",headers:r});l(s);let o=await s.json();if(401===s.status||"object"==typeof o&&null!==o&&("SESSION_EXPIRED"===o.code||"USER_NOT_FOUND"===o.code)){let e={error:o.error||"Session expired",code:o.code||"SESSION_EXPIRED",message:o.message||"Your session has expired. Please log in again."};return!function(e){for(let t of n)try{t(e)}catch(e){console.error("[cloudApi] Session expired listener error:",e)}}(e),{success:!1,error:e.message,sessionExpired:!0}}if(!s.ok)return{success:!1,error:o.error||"Request failed with status ".concat(s.status)};return{success:!0,data:o}}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"});l(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"});l(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 l(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"),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"}),getProviders:async()=>c("/api/providers"),disconnectProvider:async e=>c("/api/providers/".concat(encodeURIComponent(e)),{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"})}},637:function(e,t,r){r.d(t,{GW:function(){return i},hP:function(){return c},oU:function(){return l},yh:function(){return a}});let s={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"}},n=[{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 o(e){return e.toLowerCase().split("-").filter(Boolean)}function l(e){return o(e)[0]||e.toLowerCase()}function i(e){let t=l(e);return t in s?s[t]:n[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)%n.length]}function c(e){let t=o(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()}},5899:function(e,t,r){r.d(t,{g:function(){return nd}});var s=r(7437),n=r(2265),a=r(637);function o(e){let t=new Map;for(let r of e){let e=r.team||(0,a.oU)(r.name),s=(0,a.GW)(r.name),n=t.get(e);n||(n={prefix:e,displayName:d(e),color:s,agents:[],isExpanded:!0},t.set(e,n)),n.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 l(e){let t=e.split("-").filter(Boolean);return 0===t.length?e:d(t[t.length-1])}function i(e){return e.split("-").filter(Boolean).map(d).join(" > ")}function c(e,t){return t?e.filter(e=>(function(e,t){if(!t)return!0;let r=t.toLowerCase(),s=e.toLowerCase();return!!s.includes(r)||s.split("-").some(e=>e.includes(r))})(e.name,t)):e}function d(e){return e?e.charAt(0).toUpperCase()+e.slice(1):e}function x(e){let t=0,r=0,s=0;for(let n of e)"online"===n.status?t++:"offline"===n.status&&r++,n.needsAttention&&s++;return{total:e.length,online:t,offline:r,needsAttention:s}}function u(e){let{isProcessing:t,processingStartedAt:r,size:a="medium",showElapsed:o=!1,showLabel:l=!1}=e,[i,c]=(0,n.useState)(0);if((0,n.useEffect)(()=>{if(!t||!r){c(0);return}let e=()=>{c(Date.now()-r)};e();let s=setInterval(e,1e3);return()=>clearInterval(s)},[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,s.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-accent-purple",title:"Processing...",children:[(0,s.jsxs)("span",{className:"inline-flex items-center ".concat({small:"gap-0.5",medium:"gap-1",large:"gap-1.5"}[a]),children:[(0,s.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"0ms",animationDuration:"800ms"}}),(0,s.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"150ms",animationDuration:"800ms"}}),(0,s.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"300ms",animationDuration:"800ms"}})]}),l&&(0,s.jsx)("span",{className:"text-xs font-medium text-accent-purple",children:"thinking"}),o&&i>0&&(0,s.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 m(e){let{isProcessing:t}=e;return t?(0,s.jsx)("span",{className:"thinking-dot-inline",title:"Processing...",children:(0,s.jsx)("span",{className:"thinking-dot-pulse"})}):null}function h(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),s=t%60;return 0===s?"".concat(r,"h"):"".concat(r,"h ").concat(s,"m")}function p(e){let{agent:t,isSelected:r=!1,showBreadcrumb:n=!1,compact:o=!1,displayNameOverride:c,onClick:d,onMessageClick:x,onReleaseClick:p,onLogsClick:v,onProfileClick:w}=e,N=(0,a.GW)(t.name),k=(0,a.hP)(t.name),C=c||l(t.name),S=!t.lastMessageReceivedAt||t.lastOutputAt&&t.lastOutputAt>=t.lastMessageReceivedAt?0:Date.now()-t.lastMessageReceivedAt,L=t.isStuck||S>0,A=L?a.yh.stuck:a.yh[t.status]||a.yh.offline,M="online"===t.status,W=function(e,t,r,s){if(r&&s)return"Stuck - Agent received message ".concat(h(s)," 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)}}(t.status,t.isProcessing,L,S),E=()=>{null==d||d(t)},D=e=>{e.stopPropagation(),null==p||p(t)},B=e=>{e.stopPropagation(),null==v||v(t)},T=e=>{e.stopPropagation(),null==w||w(t)};return o?(0,s.jsxs)("div",{className:"\n group relative flex items-center gap-3 py-2.5 px-3 rounded-lg cursor-pointer\n transition-all duration-300 ease-out\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":"","\n "),onClick:E,style:{borderLeft:r?"2px solid ".concat(N.primary):"2px solid transparent",boxShadow:r?"inset 4px 0 12px -4px ".concat(N.primary,"40"):"none"},children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.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(M?"shadow-lg":"opacity-60","\n "),style:{background:"linear-gradient(135deg, ".concat(N.primary,", ").concat(N.primary,"99)"),boxShadow:M?"0 2px 12px ".concat(N.primary,"50"):"none"},children:[(0,s.jsx)("div",{className:"absolute inset-0 opacity-30",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.3) 0%, transparent 50%)"}}),(0,s.jsx)("span",{className:"relative z-10",style:{color:N.text},children:k})]}),M&&(0,s.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-bg-primary",style:{backgroundColor:A,boxShadow:"0 0 8px ".concat(A)},title:W})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"\n text-[13px] font-semibold tracking-tight truncate transition-colors duration-200\n ".concat(M?"text-text-primary":"text-text-secondary","\n "),children:C}),!c&&(0,s.jsx)("span",{className:"text-[10px] text-text-muted truncate font-mono opacity-70",children:i(t.name)})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[w&&(0,s.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 md:opacity-0 md:group-hover:opacity-100 hover:bg-[#a855f7]/10 hover:border-[#a855f7]/30 hover:text-[#a855f7] hover:shadow-[0_0_12px_rgba(168,85,247,0.25)]",onClick:T,title:"View profile",children:(0,s.jsx)(y,{})}),t.isSpawned&&v&&(0,s.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 md:opacity-0 md:group-hover:opacity-100 hover:bg-accent-cyan/10 hover:border-accent-cyan/30 hover:text-accent-cyan hover:shadow-[0_0_12px_rgba(0,217,255,0.25)]",onClick:B,title:"View logs",children:(0,s.jsx)(f,{})}),t.isSpawned&&p&&(0,s.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 md:opacity-0 md:group-hover:opacity-100 hover:bg-error/10 hover:border-error/30 hover:text-error hover:shadow-[0_0_12px_rgba(255,68,68,0.25)]",onClick:D,title:"Kill agent",children:(0,s.jsx)(b,{})}),t.isProcessing?(0,s.jsx)("div",{title:W,children:(0,s.jsx)(m,{isProcessing:!0})}):(0,s.jsx)("div",{className:"\n w-2 h-2 rounded-full transition-all duration-300\n ".concat(M?"animate-pulse":"","\n "),style:{backgroundColor:A,boxShadow:M?"0 0 6px ".concat(A):"none"},title:W}),t.needsAttention&&(0,s.jsx)("div",{className:"w-2 h-2 rounded-full bg-warning animate-pulse shadow-[0_0_8px_rgba(255,107,53,0.5)]",title:"Needs Attention - Agent requires user input or has pending decisions"}),L&&(0,s.jsxs)("div",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded bg-[#f97316]/20 text-[#f97316] text-[10px] font-medium animate-pulse",title:W,children:[(0,s.jsx)(j,{}),(0,s.jsx)("span",{children:h(S)})]})]})]}):(0,s.jsxs)("div",{className:"\n rounded-lg p-3 cursor-pointer transition-all duration-200\n hover:shadow-md hover:-translate-y-px\n ".concat(r?"border-2 shadow-[0_0_0_2px_rgba(74,158,255,0.15)]":"border","\n "),onClick:E,style:{backgroundColor:N.light,borderColor:N.primary},children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center font-semibold text-sm relative",style:{backgroundColor:N.primary},children:[(0,s.jsx)("span",{style:{color:N.text},children:k}),(0,s.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-white",style:{backgroundColor:A},title:W})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:C}),t.needsAttention&&(0,s.jsx)("span",{className:"bg-red-500 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:"!"}),L&&(0,s.jsxs)("span",{className:"bg-[#f97316] text-white text-[10px] font-bold px-1.5 py-0.5 rounded flex items-center gap-1",title:W,children:[(0,s.jsx)(j,{})," ",h(S)]})]}),n?(0,s.jsx)("span",{className:"text-xs text-text-muted truncate block",children:i(t.name)}):(0,s.jsx)("span",{className:"text-xs text-text-muted truncate block",children:t.name}),t.agentId&&(0,s.jsxs)("span",{className:"text-[10px] text-text-muted font-mono opacity-70",title:"Agent ID (use to resume)",children:["ID: ",t.agentId]})]})]}),t.isProcessing&&(0,s.jsxs)("div",{className:"mt-2 p-2 bg-indigo-50 rounded flex items-center gap-2 border border-indigo-200",children:[(0,s.jsx)(u,{isProcessing:!0,processingStartedAt:t.processingStartedAt,size:"medium",showElapsed:!0}),(0,s.jsx)("span",{className:"text-xs text-indigo-500 font-medium",children:"Thinking..."})]}),t.currentTask&&!t.isProcessing&&(0,s.jsxs)("div",{className:"mt-2 p-2 bg-bg-hover rounded text-xs",children:[(0,s.jsx)("span",{className:"text-text-muted mr-1",children:"Working on:"}),(0,s.jsx)("span",{className:"text-text-primary line-clamp-2",title:t.currentTask,children:t.currentTask})]}),(0,s.jsxs)("div",{className:"mt-3 flex justify-between items-center",children:[(0,s.jsxs)("div",{className:"flex gap-2 text-xs text-text-muted",children:[t.cli&&(0,s.jsx)("span",{className:"bg-bg-hover py-0.5 px-1.5 rounded",children:t.cli}),void 0!==t.messageCount&&t.messageCount>0&&(0,s.jsxs)("span",{style:{color:N.primary},children:[t.messageCount," msgs"]}),t.isSpawned&&(0,s.jsx)("span",{className:"bg-accent-light text-accent text-[10px] py-0.5 px-1.5 rounded uppercase font-medium",children:"spawned"})]}),(0,s.jsxs)("div",{className:"flex gap-1.5",children:[w&&(0,s.jsx)("button",{className:"relative bg-gradient-to-b from-[#2a1a3a] to-[#1a0f2a] text-[#a855f7] border border-[#402060] rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 shadow-[inset_0_1px_0_rgba(168,85,247,0.1),0_2px_4px_rgba(0,0,0,0.3)] overflow-hidden hover:bg-gradient-to-b hover:from-[#402060] hover:to-[#301a50] hover:border-[#a855f7] hover:shadow-[inset_0_1px_0_rgba(168,85,247,0.2),0_0_12px_rgba(168,85,247,0.4),0_2px_8px_rgba(0,0,0,0.4)] hover:scale-105 active:scale-[0.98]",onClick:T,title:"View profile",children:(0,s.jsx)(y,{})}),t.isSpawned&&v&&(0,s.jsx)("button",{className:"relative bg-gradient-to-b from-[#1a2a3a] to-[#0f1a2a] text-accent-cyan border border-[#204060] rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 shadow-[inset_0_1px_0_rgba(0,217,255,0.1),0_2px_4px_rgba(0,0,0,0.3)] overflow-hidden hover:bg-gradient-to-b hover:from-[#204060] hover:to-[#1a3a50] hover:border-accent-cyan hover:shadow-[inset_0_1px_0_rgba(0,217,255,0.2),0_0_12px_rgba(0,217,255,0.4),0_2px_8px_rgba(0,0,0,0.4)] hover:scale-105 active:scale-[0.98]",onClick:B,title:"View logs",children:(0,s.jsx)(f,{})}),t.isSpawned&&p&&(0,s.jsx)("button",{className:"relative bg-gradient-to-b from-[#3a1a1a] to-[#2a0f0f] text-[#ff6b6b] border border-[#4a2020] rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 shadow-[inset_0_1px_0_rgba(255,107,107,0.1),0_2px_4px_rgba(0,0,0,0.3)] overflow-hidden hover:bg-gradient-to-b hover:from-[#4a2020] hover:to-[#3a1515] hover:border-[#ff4444] hover:text-[#ff4444] hover:shadow-[inset_0_1px_0_rgba(255,68,68,0.2),0_0_12px_rgba(255,68,68,0.4),0_2px_8px_rgba(0,0,0,0.4)] hover:scale-105 active:scale-[0.98]",onClick:D,title:"Release agent",children:(0,s.jsx)(b,{})}),x&&(0,s.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:N.primary},onClick:e=>{e.stopPropagation(),null==x||x(t)},title:"Send message",children:(0,s.jsx)(g,{})})]})]})]})}function g(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.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 b(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",className:"release-icon",children:[(0,s.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,s.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,s.jsx)("line",{x1:"12",y1:"2",x2:"12",y2:"12",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"})]})}function f(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,s.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function j(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function y(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"12",cy:"7",r:"4"})]})}function v(e){let{agents:t,selectedAgent:r,searchQuery:a="",onAgentSelect:l,onAgentMessage:i,onReleaseClick:d,onLogsClick:x,compact:u=!1,showGroupStats:m=!0}=e,[h,p]=(0,n.useState)(new Set),[g,b]=(0,n.useState)(!0),f=(0,n.useMemo)(()=>c(t.filter(e=>!e.name.startsWith("__setup__")),a),[t,a]),j=(0,n.useMemo)(()=>o(f),[f]);(0,n.useMemo)(()=>{0===h.size&&j.length>0&&p(new Set(j.map(e=>e.prefix)))},[j]);let y=e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};return 0===t.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,s.jsx)(k,{}),(0,s.jsx)("p",{children:"No agents connected"})]}):0===f.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,s.jsx)(C,{}),(0,s.jsxs)("p",{children:['No agents match "',a,'"']})]}):(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[j.length>1&&(0,s.jsxs)("div",{className:"flex justify-between items-center py-2 px-3 text-xs text-text-muted",children:[(0,s.jsxs)("span",{children:[f.length," agents"]}),(0,s.jsx)("button",{className:"bg-transparent border-none text-accent cursor-pointer text-xs hover:underline",onClick:()=>{g?p(new Set):p(new Set(j.map(e=>e.prefix))),b(!g)},children:g?"Collapse all":"Expand all"})]}),j.map(e=>(0,s.jsx)(w,{group:e,isExpanded:h.has(e.prefix),selectedAgent:r,compact:u,showStats:m,onToggle:()=>y(e.prefix),onAgentSelect:l,onAgentMessage:i,onReleaseClick:d,onLogsClick:x},e.prefix))]})}function w(e){let{group:t,isExpanded:r,selectedAgent:n,compact:o,showStats:i,onToggle:c,onAgentSelect:d,onAgentMessage:u,onReleaseClick:m,onLogsClick:h}=e,g=i?x(t.agents):null;if(1===t.agents.length&&t.agents[0].name.toLowerCase()===t.prefix.toLowerCase()){let e=t.agents[0];return(0,s.jsx)("div",{className:"mb-1 py-1 px-2",children:(0,s.jsx)(p,{agent:e,isSelected:e.name===n,compact:o,onClick:d,onMessageClick:u,onReleaseClick:m,onLogsClick:h},e.name)})}return(0,s.jsxs)("div",{className:"mb-1",children:[(0,s.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,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{backgroundColor:t.color.primary}}),(0,s.jsx)(N,{expanded:r}),(0,s.jsx)("span",{className:"font-semibold text-text-primary",children:t.displayName}),(0,s.jsxs)("span",{className:"text-text-muted font-normal",children:["(",t.agents.length,")"]}),i&&g&&(0,s.jsxs)("div",{className:"ml-auto flex gap-2",children:[g.online>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-text-muted",title:"".concat(g.online," agent").concat(g.online>1?"s":""," online"),children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.online}}),g.online]}),g.needsAttention>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-text-muted",title:"".concat(g.needsAttention," agent").concat(g.needsAttention>1?"s":""," need").concat(1===g.needsAttention?"s":""," attention"),children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.attention}}),g.needsAttention]})]})]}),r&&(0,s.jsx)("div",{className:"py-1 pl-4 flex flex-col gap-1",children:t.agents.map(e=>(0,s.jsx)(p,{agent:e,isSelected:e.name===n,compact:o,displayNameOverride:l(e.name),onClick:d,onMessageClick:u,onReleaseClick:m,onLogsClick:h},e.name))})]})}function N(e){let{expanded:t}=e;return(0,s.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,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function k(){return(0,s.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,s.jsx)("circle",{cx:"12",cy:"8",r:"5"}),(0,s.jsx)("path",{d:"M20 21a8 8 0 1 0-16 0"})]})}function C(){return(0,s.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function S(e){return e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ")}function L(e){let{projects:t,localAgents:r=[],bridgeAgents:a=[],currentProject:o,selectedAgent:l,searchQuery:i="",onProjectSelect:c,onAgentSelect:d,onReleaseClick:x,onLogsClick:u,compact:m=!1}=e,[h,p]=(0,n.useState)(()=>new Set(t.map(e=>e.id))),g=(0,n.useMemo)(()=>{let e=i.toLowerCase().trim();if(!e)return{projects:t,localAgents:r,bridgeAgents:a};let s=r.filter(t=>{var r;return t.name.toLowerCase().includes(e)||(null===(r=t.currentTask)||void 0===r?void 0:r.toLowerCase().includes(e))}),n=a.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:t.map(t=>{var r;let s=(null===(r=t.name)||void 0===r?void 0:r.toLowerCase().includes(e))||t.path.toLowerCase().includes(e),n=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 s||n.length>0?{...t,agents:s?t.agents:n}:null}).filter(Boolean),localAgents:s,bridgeAgents:n}},[t,r,a,i]),b=e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},f=g.localAgents.length+g.projects.reduce((e,t)=>e+t.agents.length,0);if(0===f&&0===t.length&&0===r.length)return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-[#888] text-center",children:[(0,s.jsx)(T,{}),(0,s.jsx)("p",{children:"No projects or agents"})]});if(0===f&&i)return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-[#888] text-center",children:[(0,s.jsx)(R,{}),(0,s.jsxs)("p",{children:['No results for "',i,'"']})]});let j=g.projects.length>1;return(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[j&&g.bridgeAgents.length>0&&(0,s.jsx)(M,{agents:g.bridgeAgents,selectedAgent:l,compact:m,onAgentSelect:e=>null==d?void 0:d(e),onReleaseClick:x,onLogsClick:u}),!j&&g.localAgents.length>0&&(0,s.jsx)(A,{project:{id:"__local__",path:"",name:"Local",agents:g.localAgents},isExpanded:h.has("__local__"),isCurrentProject:!0,selectedAgent:l,compact:m,onToggle:()=>b("__local__"),onAgentSelect:e=>null==d?void 0:d(e),onReleaseClick:x,onLogsClick:u}),g.projects.map(e=>(0,s.jsx)(A,{project:e,isExpanded:h.has(e.id),isCurrentProject:e.id===o,selectedAgent:l,compact:m,isBridgeMode:j,onToggle:()=>b(e.id),onProjectSelect:()=>null==c?void 0:c(e),onAgentSelect:t=>null==d?void 0:d(t,e),onReleaseClick:x,onLogsClick:u},e.id))]})}function A(e){var t;let{project:r,isExpanded:o,isCurrentProject:l,selectedAgent:i,compact:c,isBridgeMode:d=!1,onToggle:x,onProjectSelect:u,onAgentSelect:m,onReleaseClick:h,onLogsClick:g}=e,[b,f]=(0,n.useState)(new Set),j=(0,n.useMemo)(()=>{let e=0,t=0;for(let s of r.agents)"online"===s.status&&e++,s.needsAttention&&t++;return{online:e,needsAttention:t,total:r.agents.length}},[r.agents]),{teams:y,ungroupedAgents:v}=(0,n.useMemo)(()=>{let e=new Map,t=[];for(let s of r.agents)if(s.team){let t=e.get(s.team)||[];t.push(s),e.set(s.team,t)}else t.push(s);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]),w=e=>{f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};(0,n.useEffect)(()=>{o&&0===b.size&&y.length>0&&f(new Set(y.map(e=>e.name)))},[o,y,b]);let N=(0,a.GW)(r.name||r.id),k=r.name||r.path.split("/").pop()||r.id;return(0,s.jsxs)("div",{className:"mb-1",children:[(0,s.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-[#e8e8e8] hover:bg-[var(--project-light)] ".concat(l?"bg-[rgba(0,255,200,0.08)]":""),onClick:x,onDoubleClick:u,style:{"--project-color":N.primary,"--project-light":N.light},children:[(0,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{background:N.primary}}),(0,s.jsx)(E,{expanded:o}),(0,s.jsx)(D,{color:N.primary}),(0,s.jsx)("span",{className:"font-semibold text-[#e8e8e8] whitespace-nowrap overflow-hidden text-ellipsis",children:k}),(0,s.jsxs)("span",{className:"text-[#888] font-normal flex-shrink-0",children:["(",j.total,")"]}),(0,s.jsxs)("div",{className:"ml-auto flex gap-2 flex-shrink-0",children:[j.online>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-[11px] text-[#666]",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.online}}),j.online]}),j.needsAttention>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-[11px] text-[#666]",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.attention}}),j.needsAttention]})]}),(null===(t=r.lead)||void 0===t?void 0:t.connected)&&(0,s.jsx)("span",{className:"text-[#ffd700] text-xs ml-1",title:"Lead: ".concat(r.lead.name),children:"★"}),d&&!l&&u&&(0,s.jsx)("button",{className:"ml-2 py-1 px-2 text-[10px] font-medium bg-accent-cyan/20 text-accent-cyan rounded border-none cursor-pointer opacity-0 group-hover:opacity-100 transition-opacity hover:bg-accent-cyan/30",onClick:e=>{e.stopPropagation(),u()},title:"Switch to this project",children:"Switch"})]}),o&&(0,s.jsxs)("div",{className:"py-1 pl-5 flex flex-col gap-1",children:[y.map(e=>(0,s.jsxs)("div",{className:"mb-0.5",children:[(0,s.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-[#b8b8b8] hover:bg-white/5",onClick:()=>w(e.name),children:[(0,s.jsx)(E,{expanded:b.has(e.name)}),(0,s.jsx)(B,{}),(0,s.jsx)("span",{className:"font-medium text-[#b8b8b8]",children:e.name}),(0,s.jsxs)("span",{className:"text-[#666] font-normal",children:["(",e.agents.length,")"]})]}),b.has(e.name)&&(0,s.jsx)("div",{className:"py-0.5 pl-4 flex flex-col gap-1",children:e.agents.map(t=>(0,s.jsx)(p,{agent:t,isSelected:t.name===i,compact:c,displayNameOverride:function(e,t){let r=e.toLowerCase(),s=t.toLowerCase().replace(/-?team$/i,"");if(s&&r.startsWith(s+"-")||s&&r.startsWith(s+"_"))return S(e.substring(s.length+1));let n=e.split("-");return n.length>1?S(n[n.length-1]):S(e)}(t.name,e.name),onClick:m,onReleaseClick:h,onLogsClick:g},t.name))})]},e.name)),v.map(e=>(0,s.jsx)(p,{agent:e,isSelected:e.name===i,compact:c,onClick:m,onReleaseClick:h,onLogsClick:g},e.name))]})]})}function M(e){let{agents:t,selectedAgent:r,compact:a,onAgentSelect:o,onReleaseClick:l,onLogsClick:i}=e,[c,d]=(0,n.useState)(!0);return(0,s.jsxs)("div",{className:"mb-2",children:[(0,s.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-[#e8e8e8] hover:bg-[rgba(168,85,247,0.1)]",onClick:()=>d(!c),children:[(0,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{background:"#a855f7"}}),(0,s.jsx)(E,{expanded:c}),(0,s.jsx)(W,{}),(0,s.jsx)("span",{className:"font-semibold text-[#e8e8e8]",children:"Bridge"}),(0,s.jsxs)("span",{className:"text-[#888] font-normal flex-shrink-0",children:["(",t.length,")"]})]}),c&&(0,s.jsx)("div",{className:"py-1 pl-5 flex flex-col gap-1",children:t.map(e=>(0,s.jsx)(p,{agent:e,isSelected:e.name===r,compact:a,onClick:o,onReleaseClick:l,onLogsClick:i},e.name))})]})}function W(){return(0,s.jsxs)("svg",{className:"flex-shrink-0 text-[#a855f7]",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function E(e){let{expanded:t}=e;return(0,s.jsx)("svg",{className:"transition-transform duration-200 text-[#888] flex-shrink-0 ".concat(t?"rotate-90":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function D(e){let{color:t}=e;return(0,s.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,s.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 B(){return(0,s.jsxs)("svg",{className:"text-[#888] flex-shrink-0",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function T(){return(0,s.jsx)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,s.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 R(){return(0,s.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function P(e){let{threads:t,currentThread:r,onThreadSelect:n,totalUnreadCount:a=0,isCollapsed:o=!1,onToggleCollapse:l}=e;return 0===t.length?null:(0,s.jsxs)("div",{className:"px-2 py-2",children:[(0,s.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:l,"aria-expanded":!o,"aria-label":o?"Expand threads":"Collapse threads",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(F,{isCollapsed:o}),(0,s.jsx)("span",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Threads"}),(0,s.jsxs)("span",{className:"text-xs text-text-dim font-mono",children:["(",t.length,")"]})]}),a>0&&(0,s.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})]}),!o&&(0,s.jsx)("div",{className:"space-y-1",children:t.map(e=>(0,s.jsx)(_,{thread:e,isSelected:r===e.id,onClick:()=>n(e.id)},e.id))})]})}function _(e){let{thread:t,isSelected:r,onClick:n}=e,a=t.unreadCount>0,o=function(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),s=Math.floor(r/6e4),n=Math.floor(r/36e5),a=Math.floor(r/864e5);return s<1?"now":s<60?"".concat(s,"m"):n<24?"".concat(n,"h"):a<7?"".concat(a,"d"):t.toLocaleDateString([],{month:"short",day:"numeric"})}(t.lastMessage.timestamp);return(0,s.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:n,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,s.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,s.jsx)("div",{className:"absolute inset-0 opacity-20",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%)"}}),(0,s.jsx)(I,{})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-text-muted font-mono",children:[(0,s.jsx)("span",{className:"truncate",children:t.participants.slice(0,2).join(", ")}),t.participants.length>2&&(0,s.jsxs)("span",{className:"text-text-dim",children:["+",t.participants.length-2]}),(0,s.jsx)("span",{className:"text-text-dim opacity-50",children:"\xb7"}),(0,s.jsx)("span",{className:"text-text-dim",children:o})]})]})]})}function I(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 F(e){let{isCollapsed:t}=e;return(0,s.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,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}var U=r(6272);let O="agent-relay-threads-collapsed",z="agent-relay-sidebar-tab";function H(e){let{agents:t,bridgeAgents:r=[],projects:a=[],currentUserName:o,humanUnreadCounts:l={},currentProject:i,selectedAgent:c,viewMode:d,isFleetAvailable:x,isConnected:u,isOpen:m=!1,activeThreads:h=[],currentThread:p,totalUnreadThreadCount:g=0,onAgentSelect:b,onHumanSelect:f,onProjectSelect:j,onViewModeChange:y,onSpawnClick:w,onReleaseClick:N,onLogsClick:k,onThreadSelect:C,onClose:S,onSettingsClick:A,onTrajectoryClick:M,hasActiveTrajectory:W,onFleetClick:E,isFleetViewActive:D,onCoordinatorClick:B,hasMultipleProjects:T}=e,[R,_]=(0,n.useState)(""),[I,F]=(0,n.useState)(()=>{try{let e=localStorage.getItem(z);return"team"===e?"team":"agents"}catch(e){return"agents"}}),[H,er]=(0,n.useState)(()=>{try{let e=localStorage.getItem(O);return"true"===e}catch(e){return!1}});(0,n.useEffect)(()=>{try{localStorage.setItem(z,I)}catch(e){}},[I]),(0,n.useEffect)(()=>{try{localStorage.setItem(O,String(H))}catch(e){}},[H]);let es=t.filter(e=>!e.isHuman),en=t.filter(e=>e.isHuman&&(!o||e.name.toLowerCase()!==o.toLowerCase())),ea=en.filter(e=>!R||e.name.toLowerCase().includes(R.toLowerCase())),eo=a.length>0;return(0,s.jsxs)("aside",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)("div",{className:"p-3 sm:p-4 border-b border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 mb-3",children:[(0,s.jsx)(U.K7,{size:24,withGlow:!0}),(0,s.jsx)("h1",{className:"text-base sm:text-lg font-display font-semibold m-0 text-text-primary",children:"Agent Relay"}),(0,s.jsx)(V,{isConnected:u}),(0,s.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:S,"aria-label":"Close sidebar",children:(0,s.jsx)(q,{})})]}),x&&(0,s.jsxs)("div",{className:"flex bg-bg-tertiary rounded-lg p-1",children:[(0,s.jsx)("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\n ".concat("local"===d?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>null==y?void 0:y("local"),children:"Local"}),(0,s.jsx)("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\n ".concat("fleet"===d?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>null==y?void 0:y("fleet"),children:"Fleet"})]})]}),en.length>0&&(0,s.jsxs)("div",{className:"flex bg-bg-tertiary rounded-lg p-1 mx-3 mt-3",children:[(0,s.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"===I?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>F("agents"),children:[(0,s.jsx)(Y,{}),"Agents",es.length>0&&(0,s.jsxs)("span",{className:"text-[10px] opacity-70",children:["(",es.length,")"]})]}),(0,s.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"===I?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>F("team"),children:[(0,s.jsx)($,{}),"Team",en.length>0&&(0,s.jsxs)("span",{className:"text-[10px] opacity-70",children:["(",en.length,")"]})]})]}),(0,s.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,s.jsx)(G,{}),(0,s.jsx)("input",{type:"text",placeholder:"agents"===I?"Search agents...":"Search team...",value:R,onChange:e=>_(e.target.value),className:"flex-1 bg-transparent border-none text-text-primary text-sm outline-none placeholder:text-text-muted"}),R&&(0,s.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:()=>_(""),children:(0,s.jsx)(K,{})})]}),h.length>0&&(0,s.jsx)("div",{className:"border-b border-border-subtle",children:(0,s.jsx)(P,{threads:h,currentThread:p,onThreadSelect:e=>null==C?void 0:C(e),totalUnreadCount:g,isCollapsed:H,onToggleCollapse:()=>er(!H)})}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto px-2",children:["team"===I&&en.length>0?(0,s.jsxs)("div",{className:"flex flex-col gap-1 py-2",children:[ea.map(e=>(0,s.jsxs)("button",{onClick:()=>f?f(e):null==b?void 0:b(e),className:"\n flex items-center gap-3 p-3 rounded-lg border transition-all duration-150 text-left w-full\n ".concat(c===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,s.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-9 h-9 rounded-full object-cover"}):(0,s.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,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.name}),(0,s.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.role||"Team Member"})]}),l[e.name]>0&&(0,s.jsx)("span",{className:"text-[11px] font-semibold px-2 py-0.5 rounded-full bg-accent-cyan/20 text-accent-cyan",children:l[e.name]}),(0,s.jsx)("div",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-dim")})]},e.name)),0===ea.length&&(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,s.jsx)(G,{}),(0,s.jsxs)("p",{className:"mt-3",children:['No team members match "',R,'"']})]})]}):eo?(0,s.jsx)(L,{projects:a,localAgents:es,bridgeAgents:r,currentProject:i,selectedAgent:c,searchQuery:R,onProjectSelect:j,onAgentSelect:b,onReleaseClick:N,onLogsClick:k,compact:!0}):(0,s.jsx)(v,{agents:es,selectedAgent:c,searchQuery:R,onAgentSelect:e=>null==b?void 0:b(e),onReleaseClick:N,onLogsClick:k,compact:!0,showGroupStats:!0}),"agents"===I&&en.length>0&&(0,s.jsxs)("div",{className:"mt-4 mb-2 pt-3 border-t border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-1 pb-2",children:[(0,s.jsx)("p",{className:"text-xs uppercase tracking-wide text-text-muted font-semibold m-0",children:"Direct messages"}),(0,s.jsxs)("span",{className:"text-[11px] text-text-muted",children:[ea.length," member",1===ea.length?"":"s"]})]}),(0,s.jsx)("div",{className:"flex flex-col gap-1",children:ea.length>0?ea.map(e=>(0,s.jsxs)("button",{onClick:()=>f?f(e):null==b?void 0:b(e),className:"\n flex items-center gap-3 p-2.5 rounded-lg border transition-all duration-150 text-left w-full\n ".concat(c===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,s.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-8 h-8 rounded-full object-cover"}):(0,s.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,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.name}),(0,s.jsx)("p",{className:"text-[11px] text-text-muted truncate",children:e.role||"Team Member"})]}),l[e.name]>0&&(0,s.jsx)("span",{className:"text-[11px] font-semibold px-2 py-0.5 rounded-full bg-accent-cyan/20 text-accent-cyan",children:l[e.name]}),(0,s.jsx)("div",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-dim")})]},e.name)):(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-6 px-3 text-text-muted text-center",children:[(0,s.jsx)(G,{}),(0,s.jsxs)("p",{className:"mt-2 text-xs",children:['No team members match "',R,'"']})]})})]})]}),(0,s.jsxs)("div",{className:"md:hidden border-t border-border-subtle p-3",children:[(0,s.jsx)("p",{className:"text-xs text-text-muted font-medium mb-2 px-1",children:"Quick Actions"}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[E&&(0,s.jsxs)("button",{className:"flex items-center gap-2 p-2.5 rounded-lg border text-sm transition-all duration-150 ".concat(D?"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:()=>{E(),null==S||S()},children:[(0,s.jsx)(X,{}),(0,s.jsx)("span",{children:"Fleet"})]}),M&&(0,s.jsxs)("button",{className:"flex items-center gap-2 p-2.5 rounded-lg border text-sm transition-all duration-150 relative ".concat(W?"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:()=>{M(),null==S||S()},children:[(0,s.jsx)(Q,{}),(0,s.jsx)("span",{children:"Trajectory"}),W&&(0,s.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 bg-accent-cyan rounded-full animate-pulse"})]}),T&&B&&(0,s.jsxs)("button",{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-purple",onClick:()=>{B(),null==S||S()},children:[(0,s.jsx)(ee,{}),(0,s.jsx)("span",{children:"Coordinator"})]}),(0,s.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==S?void 0:S(),children:[(0,s.jsx)(et,{}),(0,s.jsx)("span",{children:"Metrics"})]})]})]}),(0,s.jsxs)("div",{className:"p-3 sm:p-4 border-t border-border-subtle space-y-2",children:[(0,s.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:w,children:[(0,s.jsx)(Z,{}),"Spawn Agent"]}),(0,s.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:A,children:[(0,s.jsx)(J,{}),"Settings"]})]})]})}function V(e){let{isConnected:t}=e;return(0,s.jsxs)("div",{className:"flex items-center gap-1.5 ml-auto",children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(t?"bg-success animate-pulse-glow":"bg-text-dim")}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:t?"Live":"Offline"})]})}function G(){return(0,s.jsxs)("svg",{className:"text-text-muted",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function K(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Z(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function q(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function J(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 Y(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),(0,s.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,s.jsx)("path",{d:"M12 7v4"}),(0,s.jsx)("line",{x1:"8",y1:"16",x2:"8",y2:"16"}),(0,s.jsx)("line",{x1:"16",y1:"16",x2:"16",y2:"16"})]})}function $(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function X(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Q(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4"})})}function ee(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function et(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M3 3v18h18"}),(0,s.jsx)("path",{d:"M18 17V9"}),(0,s.jsx)("path",{d:"M13 17V5"}),(0,s.jsx)("path",{d:"M8 17v-3"})]})}function er(e){let{projects:t,recentProjects:r=[],currentProject:a,onProjectChange:o}=e,[l,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(-1),x=(0,n.useRef)(null),u=(0,n.useRef)([]),m=t.length>1,h=new Set(r.map(e=>e.id)),p=t.filter(e=>!h.has(e.id)),g=[...r,...p],b=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,n.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=e=>{if(l)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=u.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=u.current[r])||void 0===t||t.focus(),r});break;case"Enter":c>=0&&c<g.length&&(o(g[c]),i(!1),d(-1))}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,c,g,o]),(0,n.useEffect)(()=>{if(l){let e=g.findIndex(e=>e.id===(null==a?void 0:a.id));d(e>=0?e:0)}else d(-1)},[l,g,a]),0===t.length)?null:(0,s.jsxs)("div",{className:"relative",ref:x,children:[(0,s.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(!l),disabled:!m,"aria-expanded":l,"aria-haspopup":"listbox",children:[(0,s.jsx)(ea,{}),(0,s.jsx)("span",{className:"text-text-primary truncate max-w-[200px]",children:b(a)}),m&&(0,s.jsx)(eo,{isOpen:l})]}),l&&m&&(0,s.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,s.jsx)("div",{className:"px-3 py-2 border-b border-border-subtle",children:(0,s.jsx)("span",{className:"text-xs font-medium text-text-muted uppercase tracking-wider",children:"Switch Project"})}),(0,s.jsxs)("div",{className:"max-h-[300px] overflow-y-auto",role:"listbox",children:[r.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"px-3 py-1.5 bg-bg-tertiary/50",children:(0,s.jsxs)("span",{className:"text-[10px] font-medium text-text-muted uppercase tracking-wider flex items-center gap-1.5",children:[(0,s.jsx)(en,{}),"Recent"]})}),(0,s.jsx)("div",{className:"py-1",children:r.map((e,t)=>(0,s.jsx)(es,{project:e,index:t,isActive:(null==a?void 0:a.id)===e.id,isFocused:c===t,formatProjectName:b,buttonRefs:u,onSelect:()=>{o(e),i(!1)}},e.id))})]}),p.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"px-3 py-1.5 bg-bg-tertiary/50",children:(0,s.jsx)("span",{className:"text-[10px] font-medium text-text-muted uppercase tracking-wider",children:r.length>0?"All Projects":"Projects"})}),(0,s.jsx)("div",{className:"py-1",children:p.map((e,t)=>{let n=r.length+t;return(0,s.jsx)(es,{project:e,index:n,isActive:(null==a?void 0:a.id)===e.id,isFocused:c===n,formatProjectName:b,buttonRefs:u,onSelect:()=>{o(e),i(!1)}},e.id)})})]})]})]})]})}function es(e){var t,r;let{project:n,index:a,isActive:o,isFocused:l,formatProjectName:i,buttonRefs:c,onSelect:d}=e,x=i(n),u=(null===(t=n.agents)||void 0===t?void 0:t.length)||0;return(0,s.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(o?"bg-accent-cyan/10 text-accent-cyan":l?"bg-bg-hover text-text-primary":"bg-transparent text-text-primary hover:bg-bg-hover"),onClick:d,role:"option","aria-selected":o,tabIndex:l?0:-1,children:[(0,s.jsx)(ea,{className:o?"text-accent-cyan":"text-text-muted"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-medium text-sm truncate",children:x}),(0,s.jsx)("div",{className:"text-xs text-text-muted truncate",children:n.path})]}),(0,s.jsxs)("span",{className:"text-xs px-2 py-0.5 rounded-full ".concat(o?"bg-accent-cyan/20 text-accent-cyan":"bg-bg-tertiary text-text-muted"),children:[u," ",1===u?"agent":"agents"]}),(null===(r=n.lead)||void 0===r?void 0:r.connected)&&(0,s.jsx)("span",{className:"w-2 h-2 rounded-full bg-success animate-pulse",title:"Lead: ".concat(n.lead.name)}),o&&(0,s.jsx)(el,{})]})}function en(){return(0,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function ea(e){let{className:t="text-text-muted"}=e;return(0,s.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,s.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 eo(e){let{isOpen:t}=e;return(0,s.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,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function el(){return(0,s.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,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}var ei=r(9165);let ec={autoRefresh:!0,refreshInterval:3e4,autoWakeup:!1,onStatusChange:()=>{}};function ed(e){let{expanded:t=!1,autoWakeup:r=!1,onWakeup:a,onStatusChange:o,className:l=""}=e,[i,c]=(0,n.useState)(!1),[d,x]=(0,n.useState)(""),{workspace:u,exists:m,isLoading:h,isWakingUp:p,statusMessage:g,actionNeeded:b,wakeup:f}=function(){var e,t,r,s,a;let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l=null!==(e=o.autoRefresh)&&void 0!==e?e:ec.autoRefresh,i=null!==(t=o.refreshInterval)&&void 0!==t?t:ec.refreshInterval,c=null!==(r=o.autoWakeup)&&void 0!==r?r:ec.autoWakeup,d=(0,n.useRef)(null!==(s=o.onStatusChange)&&void 0!==s?s:ec.onStatusChange);d.current=null!==(a=o.onStatusChange)&&void 0!==a?a:ec.onStatusChange;let[x,u]=(0,n.useState)(null),[m,h]=(0,n.useState)(!1),[p,g]=(0,n.useState)(!0),[b,f]=(0,n.useState)(!1),[j,y]=(0,n.useState)(""),[v,w]=(0,n.useState)(null),[N,k]=(0,n.useState)(null),C=(0,n.useRef)(null),S=(0,n.useRef)(!0),L=(0,n.useRef)(null),A=(0,n.useCallback)(async()=>{try{g(!0),k(null);let e=await ei.xv.getPrimaryWorkspace();if(!S.current)return;if(e.success){if(h(e.data.exists),y(e.data.statusMessage),w(e.data.actionNeeded||null),e.data.workspace){let t=e.data.workspace;u(t),L.current&&L.current!==t.status&&d.current(t.status,!1),L.current=t.status}else u(null)}else k(e.error)}catch(e){S.current&&k("Failed to fetch workspace status")}finally{S.current&&g(!1)}},[]),M=(0,n.useRef)(i);M.current=i;let W=(0,n.useRef)(l);W.current=l;let E=(0,n.useCallback)(async()=>{if(!(null==x?void 0:x.id))return{success:!1,message:"No workspace to wake up"};try{f(!0),k(null);let e=await ei.xv.wakeupWorkspace(x.id);if(!S.current)return{success:!1,message:"Component unmounted"};if(e.success)return e.data.wasRestarted&&(y(e.data.message),w(null),d.current("starting",!0),C.current&&clearInterval(C.current),C.current=setInterval(A,5e3),setTimeout(()=>{S.current&&C.current&&(clearInterval(C.current),W.current&&(C.current=setInterval(A,M.current)))},12e4)),{success:!0,message:e.data.message};return k(e.error),{success:!1,message:e.error}}catch(t){let e=t instanceof Error?t.message:"Failed to wake up workspace";return S.current&&k(e),{success:!1,message:e}}finally{S.current&&f(!1)}},[null==x?void 0:x.id,A]);return(0,n.useEffect)(()=>(S.current=!0,A(),()=>{S.current=!1}),[A]),(0,n.useEffect)(()=>{if(l)return C.current=setInterval(A,i),()=>{C.current&&(clearInterval(C.current),C.current=null)}},[l,i,A]),(0,n.useEffect)(()=>{c&&(null==x?void 0:x.isStopped)&&!b&&E()},[c,null==x?void 0:x.isStopped,b,E]),{workspace:x,exists:m,isLoading:p,isWakingUp:b,statusMessage:j,actionNeeded:v,error:N,refresh:A,wakeup:E}}({autoWakeup:r,onStatusChange:(e,t)=>{null==o||o(e),t?(x("Workspace is starting up..."),c(!0),setTimeout(()=>c(!1),5e3)):"running"===e&&(x("Workspace is ready!"),c(!0),setTimeout(()=>c(!1),3e3))}}),j=(0,n.useCallback)(async()=>{let e=await f();e.success&&(null==a||a(),x(e.message),c(!0),setTimeout(()=>c(!1),5e3))},[f,a]),y=m?h&&!u?{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,s.jsx)(eg,{}),label:"Loading...",pulseColor:null}:(null==u?void 0:u.isRunning)?{color:"text-success",bgColor:"bg-success/10",borderColor:"border-success/30",icon:(0,s.jsx)(ex,{}),label:"Running",pulseColor:"bg-success"}:(null==u?void 0:u.isStopped)?{color:"text-amber-400",bgColor:"bg-amber-400/10",borderColor:"border-amber-400/30",icon:(0,s.jsx)(eu,{}),label:"Stopped",pulseColor:null}:(null==u?void 0:u.isProvisioning)||p?{color:"text-accent-cyan",bgColor:"bg-accent-cyan/10",borderColor:"border-accent-cyan/30",icon:(0,s.jsx)(em,{}),label:p?"Starting...":"Provisioning",pulseColor:"bg-accent-cyan"}:(null==u?void 0:u.hasError)?{color:"text-error",bgColor:"bg-error/10",borderColor:"border-error/30",icon:(0,s.jsx)(eh,{}),label:"Error",pulseColor:null}:{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,s.jsx)(ep,{}),label:"Unknown",pulseColor:null}:{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,s.jsx)(ep,{}),label:"No workspace",pulseColor:null};return t?(0,s.jsxs)("div",{className:"rounded-lg border ".concat(y.borderColor," ").concat(y.bgColor," p-4 ").concat(l),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:y.color,children:y.icon}),(0,s.jsx)("span",{className:"text-sm font-semibold ".concat(y.color),children:"Workspace Status"})]}),y.pulseColor&&(0,s.jsx)("span",{className:"w-2.5 h-2.5 rounded-full ".concat(y.pulseColor," animate-pulse")})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted",children:"Name"}),(0,s.jsx)("span",{className:"text-sm text-text-primary font-medium truncate max-w-[150px]",children:(null==u?void 0:u.name)||"None"})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted",children:"Status"}),(0,s.jsx)("span",{className:"text-sm font-medium ".concat(y.color),children:y.label})]}),g&&(0,s.jsx)("p",{className:"text-xs text-text-muted mt-2",children:g}),"wakeup"===b&&!p&&(0,s.jsx)("button",{onClick:j,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"===b&&(0,s.jsx)("a",{href:"/workspaces/".concat(null==u?void 0:u.id),className:"block w-full mt-3 px-3 py-2 text-sm font-medium text-center text-error bg-error/10 border border-error/30 rounded-lg hover:bg-error/20 transition-colors no-underline",children:"View error details"})]}),i&&(0,s.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:d})]}):(0,s.jsxs)("div",{className:"relative ".concat(l),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 rounded-lg border ".concat(y.bgColor," ").concat(y.borderColor," cursor-default"),title:g||y.label,children:[(0,s.jsx)("span",{className:y.color,children:y.icon}),(0,s.jsx)("span",{className:"text-xs font-medium ".concat(y.color," truncate max-w-[100px]"),title:g||y.label,children:y.label}),y.pulseColor&&(0,s.jsx)("span",{className:"w-2 h-2 rounded-full ".concat(y.pulseColor," animate-pulse")})]}),"wakeup"===b&&!p&&(0,s.jsx)("button",{onClick:j,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,s.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:d})]})}function ex(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function eu(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("rect",{x:"6",y:"6",width:"12",height:"12"})})}function em(){return(0,s.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,s.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function eh(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,s.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}function ep(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),(0,s.jsx)("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function eg(){return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeOpacity:"0.25"}),(0,s.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10"})]})}function eb(e){let{currentChannel:t,selectedAgent:r,projects:n=[],currentProject:o,recentProjects:l=[],onProjectChange:c,onCommandPaletteOpen:d,onSettingsClick:x,onHistoryClick:u,onNewConversationClick:m,onCoordinatorClick:h,onFleetClick:p,isFleetViewActive:g,onTrajectoryClick:b,hasActiveTrajectory:f,onMenuClick:j,hasUnreadNotifications:y}=e,v="general"===t,w=r?(0,a.GW)(r.name):null,N=n.length>1;return(0,s.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,s.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:j,"aria-label":"Open menu",children:[(0,s.jsx)(eC,{}),y&&(0,s.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)]"})]}),n.length>0&&c&&(0,s.jsx)("div",{className:"max-md:hidden mr-3",children:(0,s.jsx)(er,{projects:n,recentProjects:l,currentProject:null!=o?o:null,onProjectChange:c})}),n.length>0&&c&&(0,s.jsx)("div",{className:"w-px h-6 bg-border-subtle mr-3 max-md:hidden"}),(0,s.jsx)(ed,{className:"max-md:hidden mr-3"}),(0,s.jsx)("div",{className:"w-px h-6 bg-border-subtle mr-3 max-md:hidden"}),(0,s.jsx)("div",{className:"flex items-center gap-2 sm:gap-3 flex-1 min-w-0",children:v?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-accent-cyan text-base sm:text-lg font-mono",children:"#"}),(0,s.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate max-w-[100px] sm:max-w-none",children:"general"}),(0,s.jsx)("span",{className:"text-text-muted text-sm ml-2 pl-3 border-l border-border-subtle hidden md:inline",children:"All agent communications"})]}):r?(0,s.jsxs)(s.Fragment,{children:[(0,s.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,s.jsx)("span",{style:{color:null==w?void 0:w.text},children:(0,a.hP)(r.name)})}),(0,s.jsxs)("div",{className:"flex flex-col min-w-0",children:[(0,s.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate",children:r.name}),(0,s.jsx)("span",{className:"text-text-muted text-xs font-mono hidden md:block truncate",children:i(r.name)})]}),r.status&&(0,s.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})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-accent-cyan text-base sm:text-lg font-mono",children:"@"}),(0,s.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate",children:t})]})}),(0,s.jsxs)("div",{className:"flex items-center gap-1 sm:gap-2",children:[(0,s.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:m,title:"Start new conversation (⌘N)",children:[(0,s.jsx)(ef,{}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"New"}),(0,s.jsx)("span",{className:"hidden md:inline",children:"Message"})]}),(0,s.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,s.jsx)(ej,{}),(0,s.jsx)("span",{className:"hidden md:inline",children:"Search"}),(0,s.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,s.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:u,title:"Message History",children:(0,s.jsx)(ey,{})}),N&&(0,s.jsx)("button",{className:"hidden md:flex items-center justify-center 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:h,title:"Coordinator Agent",children:(0,s.jsx)(eS,{})}),p&&(0,s.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(g?"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:p,title:g?"Back to Chat":"Fleet Overview",children:(0,s.jsx)(ew,{})}),b&&(0,s.jsxs)("button",{className:"hidden md:flex items-center justify-center p-2 border rounded-lg cursor-pointer transition-all duration-150 relative ".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:b,title:"Trajectory Viewer",children:[(0,s.jsx)(eN,{}),f&&(0,s.jsx)("span",{className:"absolute -top-1 -right-1 w-2 h-2 bg-accent-cyan rounded-full animate-pulse"})]}),(0,s.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,s.jsx)(ev,{})}),(0,s.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:x,title:"Settings",children:(0,s.jsx)(ek,{})})]})]})}function ef(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("path",{d:"M12 20h9"}),(0,s.jsx)("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}function ej(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function ey(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function ev(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M3 3v18h18"}),(0,s.jsx)("path",{d:"M18 17V9"}),(0,s.jsx)("path",{d:"M13 17V5"}),(0,s.jsx)("path",{d:"M8 17v-3"})]})}function ew(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function eN(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4"})})}function ek(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 eC(){return(0,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,s.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,s.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}function eS(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}var eL=r(3225),eA=r(9880),eM=r(454),eW=r(1999),eE=r(290),eD=r(4327),eB=r(1202),eT=r(3706),eR=r(6011),eP=r(1801),e_=r(754),eI=r(3871),eF=r(5482),eU=r(5210),eO=r(963),ez=r(7711);function eH(e){let{status:t,size:r="small"}=e;if(!t)return null;let n={small:"w-3.5 h-3.5",medium:"w-4 h-4"}[r];return"sending"===t||"unread"===t?(0,s.jsx)("span",{className:"inline-flex items-center justify-center ".concat(n," text-text-muted"),title:"Sending...",children:(0,s.jsx)(eV,{className:n})}):"acked"===t||"read"===t?(0,s.jsx)("span",{className:"inline-flex items-center justify-center ".concat(n," text-success"),title:"Delivered",children:(0,s.jsx)(eG,{className:n})}):"failed"===t?(0,s.jsx)("span",{className:"inline-flex items-center justify-center ".concat(n," text-error"),title:"Delivery failed",children:(0,s.jsx)(eK,{className:n})}):null}function eV(e){let{className:t}=e;return(0,s.jsxs)("svg",{className:"animate-pulse ".concat(t),viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,s.jsx)("circle",{cx:"8",cy:"8",r:"6"}),(0,s.jsx)("path",{d:"M8 5v3l2 1",strokeLinecap:"round",strokeLinejoin:"round"})]})}function eG(e){let{className:t}=e;return(0,s.jsx)("svg",{className:t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M3 8l3 3 7-7",strokeLinecap:"round",strokeLinejoin:"round"})})}function eK(e){let{className:t}=e;return(0,s.jsxs)("svg",{className:t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"8",cy:"8",r:"6"}),(0,s.jsx)("line",{x1:"8",y1:"5",x2:"8",y2:"8",strokeLinecap:"round"}),(0,s.jsx)("circle",{cx:"8",cy:"11",r:"0.5",fill:"currentColor",stroke:"none"})]})}eL.Z.registerLanguage("javascript",eM.Z),eL.Z.registerLanguage("typescript",eW.Z),eL.Z.registerLanguage("python",eE.Z),eL.Z.registerLanguage("bash",eD.Z),eL.Z.registerLanguage("shell",eD.Z),eL.Z.registerLanguage("json",eB.Z),eL.Z.registerLanguage("markdown",eT.Z),eL.Z.registerLanguage("yaml",eR.Z),eL.Z.registerLanguage("css",eP.Z),eL.Z.registerLanguage("go",e_.Z),eL.Z.registerLanguage("rust",eI.Z),eL.Z.registerLanguage("sql",eF.Z),eL.Z.registerLanguage("ruby",eU.Z),eL.Z.registerLanguage("java",eO.Z),eL.Z.registerLanguage("docker",ez.Z),eL.Z.registerLanguage("dockerfile",ez.Z);let eZ={claude:{icon:"◈",color:"#00d9ff"},codex:{icon:"⬡",color:"#ff6b35"},gemini:{icon:"◇",color:"#a855f7"},openai:{icon:"◆",color:"#10a37f"},default:{icon:"●",color:"#00d9ff"}};function eq(e){let{messages:t,currentChannel:r,onThreadClick:a,highlightedMessageId:o,currentThread:l,agents:i=[],currentUser:c}=e,d=new Map;for(let e of i)e.isProcessing&&d.set(e.name,{isProcessing:!0,processingStartedAt:e.processingStartedAt});let x=new Map,u=(0,n.useRef)(null),[m,h]=(0,n.useState)(!0),p=(0,n.useRef)(0),g=(0,n.useRef)(r),b=(0,n.useRef)(!1),f=(0,n.useRef)(!1),j=t.filter(e=>l?e.id===l||e.thread===l:"general"===r?"*"===e.to||e.isBroadcast||"general"===e.channel:e.from===r||e.to===r);for(let e of j)("Dashboard"===e.from||c&&e.from===c.displayName)&&"*"!==e.to&&x.set(e.to,e.id);let y=j.length;if(y>p.current){let e=j[j.length-1],t=(null==e?void 0:e.from)==="Dashboard"||c&&(null==e?void 0:e.from)===c.displayName;(t||m)&&(b.current=!0,t&&!m&&h(!0))}p.current=y;let v=(0,n.useCallback)(()=>{if(!u.current||f.current)return;let e=u.current,t=e.scrollHeight-e.scrollTop-e.clientHeight;t<50&&!m?h(!0):t>150&&m&&h(!1)},[m]);return((0,n.useLayoutEffect)(()=>{if(b.current&&u.current){b.current=!1,f.current=!0;let e=u.current;e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{setTimeout(()=>{f.current=!1},50)})}},[j.length]),(0,n.useLayoutEffect)(()=>{if(r!==g.current&&(g.current=r,p.current=j.length,h(!0),u.current)){f.current=!0;let e=u.current;e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{setTimeout(()=>{f.current=!1},50)})}},[r,j.length]),0===j.length)?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center",children:[(0,s.jsx)(e1,{}),(0,s.jsx)("h3",{className:"m-0 mb-2 text-base font-display text-text-secondary",children:"No messages yet"}),(0,s.jsx)("p",{className:"m-0 text-sm",children:"general"===r?"Broadcast messages will appear here":"Messages with ".concat(r," will appear here")})]}):(0,s.jsx)("div",{className:"flex flex-col gap-1 p-2 sm:p-4 bg-bg-secondary h-full overflow-y-auto",ref:u,onScroll:v,children:j.map(e=>{let t=("Dashboard"===e.from||c&&e.from===c.displayName)&&"*"!==e.to&&x.get(e.to)===e.id?d.get(e.to):void 0;return(0,s.jsx)(eJ,{message:e,isHighlighted:e.id===o,onThreadClick:a,recipientProcessing:t,currentUser:c},e.id)})})}function eJ(e){let{message:t,isHighlighted:r,onThreadClick:a,recipientProcessing:o,currentUser:l}=e,i=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 s=new Date(r);return(s.setDate(s.getDate()-1),t.toDateString()===s.toDateString())?"Yesterday ".concat(t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(t.timestamp),c="Dashboard"===t.from||l&&t.from===l.displayName,d=c&&l?{icon:"",color:"#a855f7"}:function(e){let t=e.toLowerCase();if(t.includes("claude")||t.includes("anthropic"))return eZ.claude;if(t.includes("codex")||t.includes("openai")||t.includes("gpt"))return eZ.codex;if(t.includes("gemini")||t.includes("google")||t.includes("bard"))return eZ.gemini;let r=e.split("").reduce((e,t)=>e+t.charCodeAt(0),0),s=Object.keys(eZ).filter(e=>"default"!==e);return eZ[s[r%s.length]]}(t.from),x=c&&l?l.displayName:t.from,m=t.replyCount&&t.replyCount>0,h=c&&("acked"===t.status||"read"===t.status)&&(null==o?void 0:o.isProcessing);return(0,s.jsxs)("div",{className:"\n group flex gap-2 sm:gap-3 py-2 sm:py-3 px-2 sm:px-4 rounded-xl transition-all duration-150\n hover:bg-bg-card/50\n ".concat(r?"bg-warning-light/20 border-l-2 border-l-warning pl-2 sm:pl-3":"","\n "),children:[c&&(null==l?void 0:l.avatarUrl)?(0,s.jsx)("img",{src:l.avatarUrl,alt:x,className:"shrink-0 w-8 h-8 sm:w-10 sm:h-10 rounded-lg sm:rounded-xl border-2 object-cover",style:{borderColor:d.color,boxShadow:"0 0 16px ".concat(d.color,"30")}}):(0,s.jsx)("div",{className:"shrink-0 w-8 h-8 sm:w-10 sm:h-10 rounded-lg sm:rounded-xl flex items-center justify-center text-base sm:text-lg font-medium border-2",style:{backgroundColor:"".concat(d.color,"15"),borderColor:d.color,color:d.color,boxShadow:"0 0 16px ".concat(d.color,"30")},children:d.icon}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-1.5 flex-wrap",children:[(0,s.jsx)("span",{className:"font-display font-semibold text-sm",style:{color:d.color},children:x}),"*"!==t.to&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-dim text-xs",children:"→"}),(0,s.jsx)("span",{className:"font-medium text-sm text-accent-cyan",children:t.to})]}),t.thread&&(0,s.jsx)("span",{className:"text-xs py-0.5 px-2 rounded-full font-mono font-medium bg-accent-purple/20 text-accent-purple",children:t.thread}),"*"===t.to&&(0,s.jsx)("span",{className:"text-xs py-0.5 px-2 rounded-full uppercase font-medium bg-warning/20 text-warning",children:"broadcast"}),(0,s.jsx)("span",{className:"text-text-dim text-xs ml-auto font-mono",children:i}),c&&(0,s.jsx)(eH,{status:t.status,size:"small"}),h&&(0,s.jsx)(u,{isProcessing:!0,processingStartedAt:null==o?void 0:o.processingStartedAt,size:"small",showLabel:!0}),(0,s.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(m||t.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==a?void 0:a(t.thread||t.id),title:t.thread?"View thread: ".concat(t.thread):m?"".concat(t.replyCount," ").concat(1===t.replyCount?"reply":"replies"):"Reply in thread",children:[(0,s.jsx)(e2,{}),m&&(0,s.jsx)("span",{className:"text-xs font-medium",children:t.replyCount})]})]}),(0,s.jsx)("div",{className:"text-sm leading-relaxed text-text-primary whitespace-pre-wrap break-words",children:function(e){let t=e.replace(/\\n/g,"\n").replace(/\r\n/g,"\n").replace(/\r/g,"\n"),r=function(e){let t;let r=[],s=/```(\w*)\n([\s\S]*?)```/g,n=0;for(;null!==(t=s.exec(e));){if(t.index>n){let s=eQ(e.slice(n,t.index));r.push(...s)}r.push({type:"code",language:t[1]||"text",content:t[2]}),n=t.index+t[0].length}if(n<e.length){let t=eQ(e.slice(n));r.push(...t)}return 0===r.length?eQ(e):r}(t);return 1===r.length&&"text"===r[0].type?t.split("\n").map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[t>0&&(0,s.jsx)("br",{}),e0(e)]},t)):r.map((e,t)=>{if("code"===e.type)return(0,s.jsx)(eX,{code:e.content,language:e.language||"text"},t);if("table"===e.type)return(0,s.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},t);let r=e.content.split("\n");return(0,s.jsx)("span",{children:r.map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[t>0&&(0,s.jsx)("br",{}),e0(e)]},t))},t)})}(t.content)}),t.attachments&&t.attachments.length>0&&(0,s.jsx)(eY,{attachments:t.attachments})]})]})}function eY(e){let{attachments:t}=e,[r,a]=(0,n.useState)(null),o=t.filter(e=>e.mimeType.startsWith("image/"));return 0===o.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:o.map(e=>(0,s.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,s.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,s.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,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",className:"drop-shadow-lg",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),(0,s.jsx)("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),(0,s.jsx)("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})})]},e.id))}),r&&(0,s.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>a(null),children:(0,s.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,s.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,s.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,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,s.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,s.jsx)("p",{className:"text-white text-sm truncate",children:r.filename})})]})})]})}let e$={...eA.Z,'pre[class*="language-"]':{...eA.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-"]':{...eA.Z['code[class*="language-"]'],background:"transparent",fontSize:"0.75rem"}};function eX(e){let{code:t,language:r}=e,[a,o]=(0,n.useState)(!1),l=(0,n.useCallback)(async()=>{try{await navigator.clipboard.writeText(t),o(!0),setTimeout(()=>o(!1),2e3)}catch(e){console.error("Failed to copy:",e)}},[t]),i=r.toLowerCase().replace(/^(js|jsx)$/,"javascript").replace(/^(ts|tsx)$/,"typescript").replace(/^(py)$/,"python").replace(/^(rb)$/,"ruby").replace(/^(sh|shell|zsh)$/,"bash");return(0,s.jsxs)("div",{className:"relative group my-2",children:[(0,s.jsxs)("div",{className:"absolute top-2 right-2 flex items-center gap-2 z-10",children:[r&&"text"!==r&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-accent-cyan/20 text-accent-cyan font-mono",children:r}),(0,s.jsx)("button",{onClick:l,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:a?"✓ Copied":"Copy"})]}),(0,s.jsx)(eL.Z,{language:i,style:e$,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 eQ(e){let t=e.split("\n"),r=[],s=null;for(let e of t){let t=(e.match(/\|/g)||[]).length>=2||e.trim().startsWith("|")&&e.trim().endsWith("|")||/^[\s|:-]+$/.test(e)&&e.includes("-")&&e.includes("|")?"table":"text";s&&s.type===t?s.content+="\n"+e:(s&&r.push(s),s={type:t,content:e})}return s&&r.push(s),r}function e0(e){return e.split(/(`[^`]+`|https?:\/\/[^\s]+)/g).map((e,t)=>{if(!e)return null;if(e.startsWith("`")&&e.endsWith("`")&&e.length>2){let r=e.slice(1,-1);return(0,s.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:r},t)}return/^https?:\/\//.test(e)?(0,s.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan no-underline hover:underline",children:e},t):e})}function e1(){return(0,s.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,s.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 e2(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 e5(e){let{originalMessage:t,replies:r,onClose:a,onReply:o,isSending:l=!1,currentUser:i}=e,[c,d]=(0,n.useState)(""),x=(0,n.useRef)(null),u=(0,n.useRef)(null);(0,n.useEffect)(()=>{requestAnimationFrame(()=>{var e;null===(e=x.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})})},[r.length]),(0,n.useEffect)(()=>{var e;null===(e=u.current)||void 0===e||e.focus()},[null==t?void 0:t.id]);let m=async e=>{e.preventDefault(),c.trim()&&!l&&await o(c.trim())&&d("")};return t?(0,s.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary border-l border-border",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e6,{}),(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:"Thread"}),(0,s.jsxs)("span",{className:"text-text-muted text-xs",children:[r.length," ",1===r.length?"reply":"replies"]})]}),(0,s.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,s.jsx)(e8,{})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,s.jsx)("div",{className:"p-4 border-b border-border",children:(0,s.jsx)(e4,{message:t,isOriginal:!0,currentUser:i})}),(0,s.jsxs)("div",{className:"p-4 space-y-3",children:[0===r.length?(0,s.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,s.jsx)(e4,{message:e,currentUser:i},e.id)),(0,s.jsx)("div",{ref:x})]})]}),(0,s.jsx)("div",{className:"p-4 border-t border-border bg-bg-secondary",children:(0,s.jsxs)("form",{onSubmit:m,className:"flex gap-2",children:[(0,s.jsx)("textarea",{ref:u,value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),m(e))},placeholder:"Reply to thread...",disabled:l,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,s.jsx)("button",{type:"submit",disabled:!c.trim()||l,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:l?"Sending...":"Reply"})]})})]}):null}function e4(e){let{message:t,isOriginal:r,currentUser:o}=e,l=(0,a.GW)(t.from),i=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),c="Dashboard"===t.from||o&&t.from===o.displayName,d=c&&o?o.displayName:t.from;return(0,s.jsxs)("div",{className:"flex gap-3 ".concat(r?"":"pl-2"),children:[c&&(null==o?void 0:o.avatarUrl)?(0,s.jsx)("img",{src:o.avatarUrl,alt:d,className:"shrink-0 w-8 h-8 rounded-lg object-cover"}):(0,s.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,a.hP)(t.from)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:d}),"*"!==t.to&&!r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-muted text-xs",children:"→"}),(0,s.jsx)("span",{className:"text-sm text-accent",children:t.to})]}),(0,s.jsx)("span",{className:"text-text-muted text-xs",children:i}),r&&(0,s.jsx)("span",{className:"text-[10px] py-0.5 px-1.5 rounded bg-accent-light text-accent font-medium",children:"Original"})]}),(0,s.jsx)("div",{className:"text-sm leading-relaxed text-text-primary whitespace-pre-wrap break-words",children:t.content.replace(/\\n/g,"\n").replace(/\r\n/g,"\n").replace(/\r/g,"\n").split("\n").map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[t>0&&(0,s.jsx)("br",{}),function(e){let t=/(https?:\/\/[^\s]+)/g;return e.split(t).map((e,r)=>t.test(e)?(0,s.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:e},r):e)}(e)]},t))}),t.attachments&&t.attachments.length>0&&(0,s.jsx)(e3,{attachments:t.attachments})]})]})}function e3(e){let{attachments:t}=e,[r,a]=(0,n.useState)(null),o=t.filter(e=>e.mimeType.startsWith("image/"));return 0===o.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:o.map(e=>(0,s.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,s.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,s.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,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",className:"drop-shadow-lg",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),(0,s.jsx)("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),(0,s.jsx)("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})})]},e.id))}),r&&(0,s.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>a(null),children:(0,s.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,s.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,s.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,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,s.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,s.jsx)("p",{className:"text-white text-sm truncate",children:r.filename})})]})})]})}function e6(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-primary",children:(0,s.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 e8(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}let e9=["projects","agents","actions","navigation","settings"],e7={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 te(e){return e.isOpen?(0,s.jsx)(tt,{...e}):null}function tt(e){let{onClose:t,agents:r,projects:o=[],currentProject:l,onAgentSelect:i,onProjectSelect:c,onSpawnClick:d,onTaskCreate:x,onSettingsClick:u,onGeneralClick:m,customCommands:h=[]}=e,[p,g]=(0,n.useState)(""),[b,f]=(0,n.useState)(0),[j,y]=(0,n.useState)(null),v=(0,n.useRef)(b),w=(0,n.useRef)(null),N=(0,n.useRef)(null),k=(0,n.useRef)([]),[C,S]=(0,n.useState)("search"),[L,A]=(0,n.useState)(null),[M,W]=(0,n.useState)(""),[E,D]=(0,n.useState)("medium"),[B,T]=(0,n.useState)(!1),R=(0,n.useMemo)(()=>r.filter(e=>"offline"!==e.status&&"error"!==e.status),[r]),P=(0,n.useMemo)(()=>{if(!p.trim())return R;let e=p.toLowerCase();return R.filter(t=>t.name.toLowerCase().includes(e))},[R,p]),_=(0,n.useCallback)(()=>{S("task-select-agent"),g(""),f(0),A(null),W(""),D("medium")},[]),I=(0,n.useCallback)(async()=>{if(L&&M.trim()&&x){T(!0);try{await x({agentName:L.name,title:M.trim(),priority:E}),t()}catch(e){console.error("Failed to create task:",e)}finally{T(!1)}}},[L,M,E,x,t]);(0,n.useEffect)(()=>{v.current=b},[b]);let F=(0,n.useMemo)(()=>[...[...o].sort((e,t)=>{let r=e.id===l,s=t.id===l;if(r&&!s)return -1;if(!r&&s)return 1;let n=e.name||e.path.split("/").pop()||e.id,a=t.name||t.path.split("/").pop()||t.id;return n.localeCompare(a)}).map(e=>{let r=e.name||e.path.split("/").pop()||e.id,n=e.id===l;return{id:"project-".concat(e.id),label:r,description:n?"Current project • ".concat(e.agents.length," agents"):"".concat(e.agents.length," agents"),category:"projects",icon:n?(0,s.jsx)(tc,{}):(0,s.jsx)(ti,{}),action:()=>{null==c||c(e),t()}}}),...r.map(e=>({id:"agent-".concat(e.name),label:e.name,description:e.currentTask||e.status,category:"agents",icon:(0,s.jsx)(tr,{name:e.name}),action:()=>{i(e),t()}})),{id:"spawn-agent",label:"Spawn Agent",description:"Launch a new agent instance",category:"actions",icon:(0,s.jsx)(tn,{}),shortcut:"⌘⇧S",action:()=>{d(),t()}},{id:"broadcast",label:"Broadcast Message",description:"Send message to all agents",category:"actions",icon:(0,s.jsx)(ta,{}),action:()=>{t()}},...x?[{id:"assign-task",label:"Assign Task",description:"Create a task for an agent (creates bead)",category:"actions",icon:(0,s.jsx)(td,{}),shortcut:"⌘⇧T",action:()=>{_()}}]:[],{id:"nav-general",label:"Go to #general",description:"View all broadcast messages",category:"navigation",icon:(0,s.jsx)(to,{}),action:()=>{null==m||m(),t()}},...u?[{id:"settings",label:"Settings",description:"Configure dashboard preferences",category:"settings",icon:(0,s.jsx)(tl,{}),shortcut:"⌘,",action:()=>{u(),t()}}]:[],...h],[r,o,l,i,c,d,u,m,t,h]),U=(0,n.useMemo)(()=>{let e=F;if(j&&(e=e.filter(e=>e.category===j)),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},[F,p,j]),O=(0,n.useMemo)(()=>{let e={};for(let t of U)e[t.category]||(e[t.category]=[]),e[t.category].push(t);return e},[U]),z=(0,n.useMemo)(()=>e9.flatMap(e=>O[e]||[]),[O]);(0,n.useEffect)(()=>{f(0)},[p]),(0,n.useEffect)(()=>{g(""),f(0),y(null),S("search"),A(null),W(""),D("medium")},[]),(0,n.useEffect)(()=>{let e=k.current[b];e&&e.scrollIntoView({block:"nearest",behavior:"smooth"})},[b]),(0,n.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(),I());return}if("task-select-agent"===C){switch(e.key){case"ArrowDown":e.preventDefault(),f(e=>Math.min(e+1,P.length-1));break;case"ArrowUp":e.preventDefault(),f(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),P[v.current]&&(A(P[v.current]),S("task-details"),g(""));break;case"Escape":e.preventDefault(),S("search"),g("")}return}switch(e.key){case"ArrowDown":e.preventDefault(),f(e=>Math.min(e+1,z.length-1));break;case"ArrowUp":e.preventDefault(),f(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),z[v.current]&&z[v.current].action();break;case"Tab":e.preventDefault(),y(t=>{if(null===t)return e9[0];let r=e9.indexOf(t);return e.shiftKey?0===r?null:e9[r-1]:r===e9.length-1?null:e9[r+1]}),f(0);break;case"Escape":e.preventDefault(),j?(y(null),f(0)):t()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[z,P,C,b,j,t,I]);let H={projects:"Projects",agents:"Agents",actions:"Actions",navigation:"Navigation",settings:"Settings"},V=0;if("task-select-agent"===C)return(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,s.jsx)("button",{className:"p-1 rounded hover:bg-sidebar-border text-text-muted",onClick:()=>{S("search"),g("")},children:(0,s.jsx)(tx,{})}),(0,s.jsx)(td,{}),(0,s.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),f(0)}}),(0,s.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,s.jsx)("div",{className:"flex-1 overflow-y-auto p-2",ref:N,children:0===P.length?(0,s.jsx)("div",{className:"py-8 text-center text-text-muted text-sm",children:p?'No agents matching "'.concat(p,'"'):"No available agents"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider py-2 px-3",children:"Select Agent"}),P.map((e,t)=>{let r=(0,a.GW)(e.name);return(0,s.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===b?"bg-accent-light border border-accent/30":"bg-transparent hover:bg-sidebar-border","\n "),onClick:()=>{A(e),S("task-details"),g("")},onMouseEnter:()=>f(t),children:[(0,s.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,a.hP)(e.name)}),(0,s.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-text-muted truncate",children:e.currentTask||e.status})]})]},e.name)})]})})]})});if("task-details"===C&&L){let e=(0,a.GW)(L.name);return(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,s.jsx)("button",{className:"p-1 rounded hover:bg-sidebar-border text-text-muted",onClick:()=>{S("task-select-agent"),g("")},children:(0,s.jsx)(tx,{})}),(0,s.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,a.hP)(L.name)}),(0,s.jsxs)("span",{className:"text-base font-medium text-text-primary",children:["Assign task to ",L.name]})]}),(0,s.jsxs)("div",{className:"p-4 flex flex-col gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Task Title"}),(0,s.jsx)("input",{autoFocus:!0,type:"text",value:M,onChange:e=>W(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,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Priority"}),(0,s.jsx)("div",{className:"flex gap-2",children:Object.keys(e7).map(e=>{let t=e7[e],r=E===e;return(0,s.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:()=>D(e),children:t.label},e)})}),(0,s.jsxs)("p",{className:"text-xs text-text-dim mt-1.5",children:["Maps to beads priority P",e7[E].beadsPriority]})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2 border-t border-sidebar-border",children:[(0,s.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,s.jsx)("button",{type:"button",disabled:!M.trim()||B,onClick:I,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:B?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tu,{}),"Creating..."]}):(0,s.jsxs)(s.Fragment,{children:["Create Task",(0,s.jsx)("kbd",{className:"bg-black/20 rounded px-1 py-0.5 text-[10px]",children:"⌘↵"})]})})]})]})]})})}return(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,s.jsx)(ts,{}),j&&(0,s.jsxs)("button",{onClick:()=>{y(null),f(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:[H[j],(0,s.jsx)("span",{className:"text-accent-cyan/60",children:"\xd7"})]}),(0,s.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:j?"Search ".concat(H[j].toLowerCase(),"..."):"Search commands, agents...",value:p,onChange:e=>g(e.target.value)}),(0,s.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,s.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,s.jsx)("div",{className:"flex-1 overflow-y-auto p-2",ref:N,children:0===z.length?(0,s.jsxs)("div",{className:"py-8 text-center text-text-muted text-sm",children:['No results for "',p,'"']}):e9.map(e=>{let t=O[e];return(null==t?void 0:t.length)?(0,s.jsxs)("div",{className:"mb-2",children:[(0,s.jsx)("div",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider py-2 px-3",children:H[e]||e}),t.map(e=>{let t=V++;return(0,s.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===b?"bg-accent-light border border-accent/30":"bg-transparent hover:bg-sidebar-border","\n "),onClick:e.action,onMouseEnter:()=>f(t),children:[(0,s.jsx)("span",{className:"flex items-center justify-center w-7 h-7 text-text-muted",children:e.icon}),(0,s.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.label}),e.description&&(0,s.jsx)("span",{className:"text-xs text-text-muted truncate",children:e.description})]}),e.shortcut&&(0,s.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 tr(e){let{name:t}=e,r=(0,a.GW)(t);return(0,s.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,a.hP)(t)})}function ts(){return(0,s.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,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tn(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ta(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,s.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 to(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),(0,s.jsx)("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),(0,s.jsx)("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),(0,s.jsx)("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}function tl(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 ti(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 tc(){return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:(0,s.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,s.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,s.jsx)("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})})]})}function td(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-muted",children:[(0,s.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,s.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}function tx(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"15 18 9 12 15 6"})})}function tu(){return(0,s.jsx)("svg",{className:"animate-spin",width:"14",height:"14",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}let tm=[{id:"claude",name:"Claude",command:"claude",description:"Claude Code CLI agent",icon:"\uD83E\uDD16"},{id:"codex",name:"Codex",command:"codex",description:"OpenAI Codex agent",icon:"⚡"},{id:"gemini",name:"Gemini",command:"gemini",description:"Google Gemini CLI agent",icon:"\uD83D\uDC8E"},{id:"opencode",name:"OpenCode",command:"opencode",description:"OpenCode AI agent",icon:"\uD83D\uDD37"},{id:"droid",name:"Droid",command:"droid",description:"Factory Droid agent",icon:"\uD83E\uDD16"},{id:"custom",name:"Custom",command:"",description:"Custom command",icon:"\uD83D\uDD27"}];function th(e){let{isOpen:t,onClose:r,onSpawn:o,existingAgents:l,isSpawning:i=!1,error:c}=e,[d,x]=(0,n.useState)(tm[0]),[u,m]=(0,n.useState)(""),[h,p]=(0,n.useState)(""),[g,b]=(0,n.useState)(""),[f,j]=(0,n.useState)(""),[y,v]=(0,n.useState)(!1),[w,N]=(0,n.useState)(""),[k,C]=(0,n.useState)(""),[S,L]=(0,n.useState)(["EXPLICIT_ASK"]),[A,M]=(0,n.useState)(null),W=(0,n.useRef)(null),E="custom"===d.id?h:d.command,D=(0,n.useMemo)(()=>(function(e){let t=e.trim().split(" ")[0].toLowerCase();return t.startsWith("claude")||"codex"===t||"opencode"===t||"gemini"===t||"droid"===t?"subagent":"process"})(E),[E]),B=(0,n.useCallback)(()=>{let e="claude"===d.id?"claude":d.id,t=1;for(;l.includes("".concat(e,"-").concat(t));)t++;return"".concat(e,"-").concat(t)},[d,l]);(0,n.useEffect)(()=>{t&&(x(tm[0]),m(""),p(""),b(""),j(""),v(!1),N(""),C(""),L(["EXPLICIT_ASK"]),M(null),setTimeout(()=>{var e;return null===(e=W.current)||void 0===e?void 0:e.focus()},100))},[t]);let T=(0,n.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]),R=async e=>{e.preventDefault();let t=u.trim()||B(),s=T(t);if(s){M(s);return}if(!E.trim()){M("Command is required");return}if(y&&!w){M("Please select an agent to shadow");return}M(null),await o({name:t,command:E.trim(),cwd:g.trim()||void 0,team:f.trim()||void 0,shadowMode:D,shadowOf:y?w:void 0,shadowAgent:k.trim()||void 0,shadowTriggers:y?S:void 0,shadowSpeakOn:y?S:void 0})&&r()};if(!t)return null;let P=u?(0,a.GW)(u):(0,a.GW)(B()),_=c||A;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.jsxs)("div",{className:"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:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-5 border-b border-border",children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Spawn New Agent"}),(0,s.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,s.jsx)(tp,{})})]}),(0,s.jsxs)("form",{onSubmit:R,className:"p-6",children:[(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",children:"Agent Type"}),(0,s.jsx)("div",{className:"grid grid-cols-3 gap-2",children:tm.map(e=>(0,s.jsxs)("button",{type:"button",className:"\n flex flex-col items-center gap-1 py-3 px-2 border-2 rounded-lg cursor-pointer font-sans transition-all duration-150\n ".concat(d.id===e.id?"bg-accent/10 border-accent":"bg-bg-hover border-transparent hover:bg-bg-active","\n "),onClick:()=>x(e),children:[(0,s.jsx)("span",{className:"text-2xl",children:e.icon}),(0,s.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-text-muted text-center",children:e.description})]},e.id))})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-name",children:"Agent Name"}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"shrink-0 w-10 h-10 rounded-lg flex items-center justify-center text-sm font-semibold",style:{backgroundColor:P.primary,color:P.text},children:(0,a.hP)(u||B())}),(0,s.jsx)("input",{ref:W,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:B(),value:u,onChange:e=>{m(e.target.value),M(null)},disabled:i})]})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsxs)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-team",children:["Team ",(0,s.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,s.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:f,onChange:e=>j(e.target.value),disabled:i})]}),"custom"===d.id&&(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-command",children:"Command"}),(0,s.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:h,onChange:e=>p(e.target.value),disabled:i})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsxs)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-cwd",children:["Working Directory ",(0,s.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,s.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:g,onChange:e=>b(e.target.value),disabled:i})]}),(0,s.jsxs)("div",{className:"mb-5 p-4 border border-border rounded-lg bg-bg-hover/50",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary",children:"Shadow Mode"}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:["Shadow execution: ","subagent"===D?"Subagent (in-process)":"Process (separate)"]})]}),(0,s.jsx)("button",{type:"button",className:"\n relative w-11 h-6 rounded-full transition-colors duration-200\n ".concat(y?"bg-accent":"bg-bg-active","\n "),onClick:()=>v(!y),disabled:i,"aria-pressed":y,children:(0,s.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(y?"translate-x-5":"translate-x-0","\n ")})})]}),y&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-text-secondary mb-2",htmlFor:"shadow-of",children:"Shadow Agent"}),(0,s.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:w,onChange:e=>N(e.target.value),disabled:i,children:[(0,s.jsx)("option",{value:"",children:"Select an agent to shadow..."}),l.map(e=>(0,s.jsx)("option",{value:e,children:e},e))]})]}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsxs)("label",{className:"block text-sm font-medium text-text-secondary mb-2",htmlFor:"shadow-agent",children:["Shadow Agent Profile ",(0,s.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,s.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:k,onChange:e=>C(e.target.value),disabled:i})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-text-secondary mb-2",children:"Speak When"}),(0,s.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,s.jsx)("button",{type:"button",className:"\n py-1.5 px-3 rounded-md text-xs font-medium transition-all duration-150 border\n ".concat(S.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:()=>{S.includes(e.value)?L(S.filter(t=>t!==e.value)):L([...S,e.value])},disabled:i,title:e.description,children:e.label},e.value))})]})]})]}),_&&(0,s.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,s.jsx)(tg,{}),(0,s.jsx)("span",{children:_})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2 border-t border-border",children:[(0,s.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:i,children:"Cancel"}),(0,s.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:i,children:i?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tf,{}),"Spawning..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tb,{}),"Spawn Agent"]})})]})]})]})})}function tp(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tg(){return(0,s.jsxs)("svg",{className:"shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function tb(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.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,s.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,s.jsx)("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),(0,s.jsx)("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}function tf(){return(0,s.jsx)("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function tj(e){let{isOpen:t,onClose:r,onSend:o,agents:l,isSending:i=!1,error:c,preselectedAgent:d}=e,[x,u]=(0,n.useState)(""),[m,h]=(0,n.useState)(""),[p,g]=(0,n.useState)(""),[b,f]=(0,n.useState)(null),j=(0,n.useRef)(null),y=(0,n.useRef)(null),v=(0,n.useMemo)(()=>{if(!p.trim())return l;let e=p.toLowerCase();return l.filter(t=>{var r,s;return t.name.toLowerCase().includes(e)||(null===(r=t.role)||void 0===r?void 0:r.toLowerCase().includes(e))||(null===(s=t.team)||void 0===s?void 0:s.toLowerCase().includes(e))})},[l,p]);(0,n.useEffect)(()=>{t&&(u(d||""),h(""),g(""),f(null),setTimeout(()=>{var e,t;d?null===(e=j.current)||void 0===e||e.focus():null===(t=y.current)||void 0===t||t.focus()},100))},[t,d]);let w=async e=>{if(e.preventDefault(),!x){f("Please select an agent");return}if(!m.trim()){f("Please enter a message");return}f(null),await o(x,m.trim())&&r()},N=(0,n.useCallback)(e=>{u(e),f(null),setTimeout(()=>{var e;return null===(e=j.current)||void 0===e?void 0:e.focus()},50)},[]);if(!t)return null;let k=c||b,C=l.find(e=>e.name===x),S=C?(0,a.GW)(C.name):null;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between p-5 border-b border-border shrink-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center",children:(0,s.jsx)(ty,{})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"New Conversation"}),(0,s.jsx)("p",{className:"m-0 text-xs text-text-muted",children:"Start a direct message with an agent"})]})]}),(0,s.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,s.jsx)(tv,{})})]}),(0,s.jsxs)("form",{onSubmit:w,className:"flex flex-col flex-1 overflow-hidden",children:[(0,s.jsxs)("div",{className:"p-5 border-b border-border",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",children:"To"}),x?(0,s.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-bg-hover rounded-lg",children:[(0,s.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,a.hP)(x)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-semibold text-text-primary",children:x}),(null==C?void 0:C.role)&&(0,s.jsx)("div",{className:"text-xs text-text-muted truncate",children:C.role})]}),(0,s.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,s.jsx)(tN,{})})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"relative mb-3",children:[(0,s.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-muted",children:(0,s.jsx)(tw,{})}),(0,s.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,s.jsx)("div",{className:"max-h-[200px] overflow-y-auto border border-border rounded-lg",children:0===v.length?(0,s.jsx)("div",{className:"p-4 text-center text-text-muted text-sm",children:p?"No agents found":"No agents available"}):(0,s.jsxs)("div",{className:"divide-y divide-border",children:[(0,s.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,s.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg bg-warning/20 flex items-center justify-center",children:(0,s.jsx)(tk,{})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-semibold text-text-primary",children:"Everyone"}),(0,s.jsx)("div",{className:"text-xs text-text-muted",children:"Broadcast to all agents"})]})]}),v.map(e=>{let t=(0,a.GW)(e.name);return(0,s.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,s.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,a.hP)(e.name)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-text-primary",children:e.name}),(0,s.jsx)("span",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-muted")})]}),(e.role||e.team)&&(0,s.jsxs)("div",{className:"text-xs text-text-muted truncate",children:[e.role,e.role&&e.team&&" - ",e.team]})]})]},e.name)})]})})]})]}),(0,s.jsxs)("div",{className:"p-5 flex-1 overflow-hidden flex flex-col",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"message",children:"Message"}),(0,s.jsx)("textarea",{ref:j,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:"*"===x?"Write a message to all agents...":x?"Write a message to ".concat(x,"..."):"Select an agent first...",value:m,onChange:e=>{h(e.target.value),f(null)},disabled:i||!x})]}),k&&(0,s.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,s.jsx)(tS,{}),(0,s.jsx)("span",{children:k})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 p-5 pt-0 border-t border-border",children:[(0,s.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:i,children:"Cancel"}),(0,s.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:i||!x||!m.trim(),children:i?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tL,{}),"Sending..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tC,{}),"Send Message"]})})]})]})]})})}function ty(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent",children:[(0,s.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,s.jsx)("line",{x1:"9",y1:"10",x2:"15",y2:"10"})]})}function tv(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tw(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tN(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"1 4 1 10 7 10"}),(0,s.jsx)("path",{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"})]})}function tk(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-warning",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,s.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 tC(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,s.jsx)("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function tS(){return(0,s.jsxs)("svg",{className:"shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function tL(){return(0,s.jsx)("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}var tA=r(3083),tM=r(4736);function tW(e){let{workspaces:t=[],onWorkspaceCreated:r,onOpenWorkspace:a,csrfToken:o,className:l=""}=e,[i,c]=(0,n.useState)([]),[d,x]=(0,n.useState)("idle"),[u,m]=(0,n.useState)(null),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(""),[f,j]=(0,n.useState)("all"),y=new Map;t.forEach(e=>{e.repositoryFullName&&y.set(e.repositoryFullName,e)});let v=(0,n.useCallback)(async()=>{x("loading"),m(null);try{let e=await fetch("/api/repos/accessible?perPage=100",{credentials:"include"});if(!e.ok){let t=await e.json();if("NANGO_NOT_CONNECTED"===t.code)throw Error("GitHub not connected. Please reconnect your GitHub account.");throw Error(t.error||"Failed to fetch repositories")}let t=await e.json();c(t.repositories||[]),x("loaded")}catch(e){console.error("Error fetching accessible repos:",e),m(e instanceof Error?e.message:"Failed to load repositories"),x("error")}},[]);(0,n.useEffect)(()=>{v()},[v]);let w=(0,n.useCallback)(async e=>{p(e),m(null);try{let t={"Content-Type":"application/json"};o&&(t["X-CSRF-Token"]=o);let s=await fetch("/api/workspaces/quick",{method:"POST",credentials:"include",headers:t,body:JSON.stringify({repositoryFullName:e})}),n=await s.json();if(!s.ok)throw Error(n.error||"Failed to create workspace");null==r||r(n.workspaceId,e)}catch(e){console.error("Error creating workspace:",e),m(e instanceof Error?e.message:"Failed to create workspace")}finally{p(null)}},[o,r]),N=i.filter(e=>{if(g&&!e.fullName.toLowerCase().includes(g.toLowerCase()))return!1;let t=y.has(e.fullName);return("with-workspace"!==f||!!t)&&("without-workspace"!==f||!t)});return"loading"===d?(0,s.jsx)("div",{className:"flex items-center justify-center py-12 ".concat(l),children:(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsxs)("svg",{className:"w-8 h-8 text-accent-cyan animate-spin mx-auto",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,s.jsx)("p",{className:"mt-4 text-text-muted",children:"Loading repositories..."})]})}):"error"===d?(0,s.jsx)("div",{className:"p-6 ".concat(l),children:(0,s.jsxs)("div",{className:"bg-error/10 border border-error/20 rounded-xl p-4 text-center",children:[(0,s.jsx)("div",{className:"w-12 h-12 mx-auto mb-3 bg-error/20 rounded-full flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-6 h-6 text-error",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,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,s.jsx)("p",{className:"text-error mb-4",children:u}),(0,s.jsx)("button",{onClick:v,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"})]})}):(0,s.jsxs)("div",{className:l,children:[(0,s.jsxs)("div",{className:"p-4 border-b border-border-subtle",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-text-primary mb-1",children:"Repository Access"}),(0,s.jsx)("p",{className:"text-sm text-text-muted",children:"Repositories you have access to on GitHub. Create workspaces to enable dashboard and chat access."})]}),u&&(0,s.jsx)("div",{className:"mx-4 mt-4 p-3 bg-error/10 border border-error/20 rounded-lg",children:(0,s.jsx)("p",{className:"text-error text-sm",children:u})}),(0,s.jsx)("div",{className:"p-4 border-b border-border-subtle",children:(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,s.jsxs)("div",{className:"flex-1 relative",children:[(0,s.jsx)(tE,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-muted"}),(0,s.jsx)("input",{type:"text",placeholder:"Search repositories...",value:g,onChange:e=>b(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"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("button",{onClick:()=>j("all"),className:"px-3 py-2 text-sm rounded-lg border transition-colors ".concat("all"===f?"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-muted hover:text-text-primary"),children:["All (",i.length,")"]}),(0,s.jsx)("button",{onClick:()=>j("with-workspace"),className:"px-3 py-2 text-sm rounded-lg border transition-colors ".concat("with-workspace"===f?"bg-success/10 border-success/30 text-success":"bg-bg-tertiary border-border-subtle text-text-muted hover:text-text-primary"),children:"With Access"}),(0,s.jsx)("button",{onClick:()=>j("without-workspace"),className:"px-3 py-2 text-sm rounded-lg border transition-colors ".concat("without-workspace"===f?"bg-warning/10 border-warning/30 text-warning":"bg-bg-tertiary border-border-subtle text-text-muted hover:text-text-primary"),children:"No Access"})]})]})}),(0,s.jsx)("div",{className:"max-h-[500px] overflow-y-auto",children:0===N.length?(0,s.jsx)("div",{className:"py-12 text-center text-text-muted",children:g?(0,s.jsxs)("p",{children:['No repositories match "',g,'"']}):"all"!==f?(0,s.jsx)("p",{children:"No repositories in this category"}):(0,s.jsx)("p",{children:"No repositories found. Connect your GitHub account to see your repos."})}):(0,s.jsx)("div",{className:"divide-y divide-border-subtle",children:N.map(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"},n=y.get(e.fullName),o=h===e.fullName;return(0,s.jsxs)("div",{className:"flex items-center gap-4 p-4 hover:bg-bg-hover/50 transition-colors",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-bg-tertiary border border-border-subtle flex items-center justify-center flex-shrink-0",children:(0,s.jsx)(tD,{className:"text-text-muted"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,s.jsx)("p",{className:"font-medium text-text-primary truncate",children:e.fullName}),e.isPrivate&&(0,s.jsx)("span",{className:"px-1.5 py-0.5 text-xs bg-bg-tertiary border border-border-subtle rounded text-text-muted",children:"Private"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"px-2 py-0.5 text-xs rounded-full border ".concat(r.color),children:r.label}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:e.defaultBranch})]})]}),(0,s.jsx)("div",{className:"flex-shrink-0",children:n?(0,s.jsx)("button",{onClick:()=>null==a?void 0:a(n.id),className:"px-4 py-2 text-sm rounded-lg border transition-colors ".concat("running"===n.status?"bg-success/10 border-success/30 text-success hover:bg-success/20":"provisioning"===n.status?"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-muted hover:bg-bg-hover"),children:"running"===n.status?"Open Dashboard":"provisioning"===n.status?"Starting...":"stopped"===n.status?"Start":"View"}):(0,s.jsx)("button",{onClick:()=>w(e.fullName),disabled:o,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:o?(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsxs)("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Creating..."]}):"Enable Access"})})]},e.id)})})}),(0,s.jsx)("div",{className:"p-4 border-t border-border-subtle bg-bg-tertiary/50",children:(0,s.jsxs)("p",{className:"text-xs text-text-muted text-center",children:["Showing ",N.length," of ",i.length," repositories you have GitHub access to.",(0,s.jsx)("button",{onClick:v,className:"ml-2 text-accent-cyan hover:underline",children:"Refresh"})]})})]})}function tE(e){let{className:t=""}=e;return(0,s.jsxs)("svg",{className:t,width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tD(e){let{className:t=""}=e;return(0,s.jsx)("svg",{className:t,width:"18",height:"18",viewBox:"0 0 16 16",fill:"currentColor",children:(0,s.jsx)("path",{d:"M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8z"})})}let tB=[{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:"OpenAI",displayName:"Codex",description:"Codex - OpenAI coding assistant",color:"#10A37F",cliCommand:"codex login",apiKeyUrl:"https://platform.openai.com/api-keys",apiKeyName:"API key",supportsOAuth:!0,supportsDeviceFlow:!0},{id:"google",name:"Google",displayName:"Gemini",description:"Gemini - Google AI coding assistant",color:"#4285F4",cliCommand:"gemini",apiKeyUrl:"https://aistudio.google.com/app/apikey",apiKeyName:"API key",supportsOAuth:!0},{id:"opencode",name:"OpenCode",displayName:"OpenCode",description:"OpenCode - AI coding assistant",color:"#00D4AA",cliCommand:"opencode",supportsOAuth:!0},{id:"droid",name:"Factory",displayName:"Droid",description:"Droid - Factory AI coding agent",color:"#6366F1",cliCommand:"droid",supportsOAuth:!0}];function tT(e){var t;let{workspaceId:r,csrfToken:a,onClose:o}=e,[l,i]=(0,n.useState)(null),[c,d]=(0,n.useState)([]),[x,u]=(0,n.useState)(!0),[m,h]=(0,n.useState)(null),[p,g]=(0,n.useState)("general"),[b,f]=(0,n.useState)({}),[j,y]=(0,n.useState)(null),[v,w]=(0,n.useState)(""),[N,k]=(0,n.useState)(null),[C,S]=(0,n.useState)({}),[L,A]=(0,n.useState)({}),[M,W]=(0,n.useState)({anthropic:!0}),[E,D]=(0,n.useState)(null),[B,T]=(0,n.useState)(""),[R,P]=(0,n.useState)(!1),[_,I]=(0,n.useState)(null),[F,U]=(0,n.useState)(null);(0,n.useEffect)(()=>{!async function(){u(!0),h(null);let[e,t,s]=await Promise.all([ei.xv.getWorkspaceDetails(r),ei.xv.getRepos(),ei.xv.getMe()]);if(e.success?(i(e.data),e.data.customDomain&&T(e.data.customDomain)):h(e.error),t.success&&d(t.data.repositories),s.success){let e={openai:"codex"},t={};s.data.connectedProviders.forEach(r=>{t[r.provider]=!0;let s=e[r.provider];s&&(t[s]=!0)}),f(t)}u(!1)}()},[r]);let O=e=>{k(null),y(e.id)},z=async e=>{if(!v.trim()){k("Please enter an API key");return}k(null),y(e.id);try{let t={"Content-Type":"application/json"};a&&(t["X-CSRF-Token"]=a);let r=await fetch("/api/onboarding/token/".concat(e.id),{method:"POST",credentials:"include",headers:t,body:JSON.stringify({token:v.trim()})});if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to connect")}f(t=>({...t,[e.id]:!0})),w(""),y(null),S(t=>({...t,[e.id]:!1}))}catch(e){k(e instanceof Error?e.message:"Failed to connect"),y(null)}},H=(0,n.useCallback)(async()=>{if(!l||!window.confirm("Are you sure you want to restart this workspace?"))return;let e=await ei.xv.restartWorkspace(l.id);if(e.success){let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else h(e.error)},[l,r]),V=(0,n.useCallback)(async()=>{if(!l||!window.confirm("Are you sure you want to stop this workspace?"))return;let e=await ei.xv.stopWorkspace(l.id);if(e.success){let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else h(e.error)},[l,r]),G=(0,n.useCallback)(async e=>{if(!l)return;let t=await ei.xv.addReposToWorkspace(l.id,[e]);if(t.success){let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else h(t.error)},[l,r]),K=(0,n.useCallback)(async e=>{if(!l)return;D(e),h(null);let t=await ei.xv.syncRepo(e);if(t.success){let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else h(t.error);D(null)},[l,r]),Z=(0,n.useCallback)(async()=>{if(!l||!B.trim())return;P(!0),I(null),U(null);let e=await ei.xv.setCustomDomain(l.id,B.trim());if(e.success){U(e.data.instructions);let t=await ei.xv.getWorkspaceDetails(r);t.success&&i(t.data)}else I(e.error);P(!1)},[l,B,r]),q=(0,n.useCallback)(async()=>{if(!l)return;P(!0),I(null);let e=await ei.xv.verifyCustomDomain(l.id);if(e.success){let t=await ei.xv.getWorkspaceDetails(r);t.success&&i(t.data),"active"===e.data.status&&U(null)}else I(e.error);P(!1)},[l,r]),J=(0,n.useCallback)(async()=>{if(!l||!window.confirm("Are you sure you want to remove the custom domain?"))return;P(!0);let e=await ei.xv.removeCustomDomain(l.id);if(e.success){T(""),U(null);let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else I(e.error);P(!1)},[l,r]),Y=(0,n.useCallback)(async()=>{if(!l||!window.confirm('Are you sure you want to delete "'.concat(l.name,'"? This action cannot be undone.'))||!window.confirm("This will permanently delete all workspace data. Are you absolutely sure?"))return;let e=await ei.xv.deleteWorkspace(l.id);e.success?window.location.href="/app/onboarding?reason=deleted":h(e.error)},[l]);if(x)return(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"w-12 h-12 rounded-full border-2 border-accent-cyan/20 border-t-accent-cyan animate-spin"}),(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)("div",{className:"w-4 h-4 rounded-full bg-accent-cyan/40 animate-pulse"})})]}),(0,s.jsx)("span",{className:"ml-4 text-text-muted font-mono text-sm tracking-wide",children:"LOADING WORKSPACE CONFIG..."})]});if(m&&!l)return(0,s.jsx)("div",{className:"p-6",children:(0,s.jsxs)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error flex items-center gap-3",children:[(0,s.jsx)(tG,{}),(0,s.jsx)("span",{children:m})]})});if(!l)return null;let $=c.filter(e=>!l.repositories.some(t=>t.id===e.id)),X=[{id:"general",label:"General",icon:(0,s.jsx)(tU,{})},{id:"providers",label:"AI Providers",icon:(0,s.jsx)(tO,{})},{id:"repos",label:"Repositories",icon:(0,s.jsx)(tz,{})},{id:"github-access",label:"GitHub Access",icon:(0,s.jsx)(tV,{})},{id:"domain",label:"Domain",icon:(0,s.jsx)(tH,{})},{id:"danger",label:"Danger",icon:(0,s.jsx)(tG,{})}];return(0,s.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary",children:[(0,s.jsx)("div",{className:"flex gap-1 p-3 border-b border-border-subtle bg-gradient-to-b from-bg-tertiary to-bg-primary",children:X.map(e=>(0,s.jsxs)("button",{onClick:()=>g(e.id),className:"flex items-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium transition-all duration-200 ".concat(p===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,s.jsx)("span",{className:p===e.id?"text-accent-cyan":"text-text-muted",children:e.icon}),e.label]},e.id))}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[m&&(0,s.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,s.jsx)(tG,{}),(0,s.jsx)("span",{className:"flex-1",children:m}),(0,s.jsx)("button",{onClick:()=>h(null),className:"text-error/60 hover:text-error",children:(0,s.jsx)(t$,{})})]}),"general"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"Workspace Overview",subtitle:"Core configuration and status"}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsx)(tP,{label:"Name",value:l.name}),(0,s.jsx)(tP,{label:"Status",value:l.status.charAt(0).toUpperCase()+l.status.slice(1),valueColor:"running"===l.status?"text-success":"stopped"===l.status?"text-amber-400":"error"===l.status?"text-error":"text-text-muted",indicator:"running"===l.status}),(0,s.jsx)(tP,{label:"Public URL",value:l.publicUrl||"Not available",mono:!0}),(0,s.jsx)(tP,{label:"Compute Provider",value:l.computeProvider.charAt(0).toUpperCase()+l.computeProvider.slice(1)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)(tR,{title:"Actions",subtitle:"Manage workspace state"}),(0,s.jsxs)("div",{className:"flex gap-3 mt-4",children:["running"===l.status&&(0,s.jsx)(t_,{onClick:V,variant:"warning",icon:(0,s.jsx)(tZ,{}),children:"Stop Workspace"}),(0,s.jsx)(t_,{onClick:H,variant:"primary",icon:(0,s.jsx)(tq,{}),children:"Restart Workspace"})]})]})]}),"providers"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"AI Providers",subtitle:"Connect AI providers to spawn agents in this workspace"}),N&&(0,s.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,s.jsx)(tG,{}),(0,s.jsx)("span",{children:N})]}),(0,s.jsx)("div",{className:"space-y-4",children:tB.map(e=>(0,s.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle hover:border-border-medium transition-all duration-200",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-4",children:[(0,s.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center text-white font-bold text-lg shadow-lg",style:{backgroundColor:e.color,boxShadow:"0 4px 20px ".concat(e.color,"40")},children:e.displayName[0]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-base font-semibold text-text-primary",children:e.displayName}),(0,s.jsx)("p",{className:"text-sm text-text-muted",children:e.description})]})]}),b[e.id]?(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 bg-success/15 rounded-full border border-success/30",children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full bg-success animate-pulse"}),(0,s.jsx)("span",{className:"text-sm font-medium text-success",children:"Connected"})]}):null]}),!b[e.id]&&(0,s.jsx)("div",{className:"mt-5 pt-5 border-t border-border-subtle",children:j===e.id?M[e.id]?(0,s.jsx)(tM.$,{provider:{id:e.id,name:e.name,displayName:e.displayName,color:e.color},workspaceId:r,csrfToken:a,maxHeight:"350px",onSuccess:()=>{f(t=>({...t,[e.id]:!0})),y(null)},onCancel:()=>{y(null)},onError:e=>{k(e),y(null)},onConnectAnother:()=>{f(t=>({...t,[e.id]:!0})),y(null)}}):(0,s.jsx)(tA.j,{provider:{id:e.id,name:e.name,displayName:e.displayName,color:e.color,requiresUrlCopy:"codex"===e.id,supportsDeviceFlow:e.supportsDeviceFlow},workspaceId:r,csrfToken:a,useDeviceFlow:L[e.id]||!1,onSuccess:()=>{f(t=>({...t,[e.id]:!0})),y(null)},onCancel:()=>{y(null)},onError:e=>{k(e),y(null)}}):C[e.id]?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)("input",{type:"password",placeholder:"Enter ".concat(e.displayName," ").concat(e.apiKeyName||"API key"),value:j===e.id?v:"",onChange:t=>{y(e.id),w(t.target.value)},onFocus:()=>y(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,s.jsx)("button",{onClick:()=>z(e),disabled:j!==e.id||!v.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,s.jsxs)("p",{className:"text-xs text-text-muted",children:["Get your API key from"," ",(0,s.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,s.jsx)("button",{onClick:()=>S(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,s.jsxs)("div",{className:"space-y-3",children:["codex"===e.id&&(0,s.jsxs)("div",{className:"p-3 bg-accent-cyan/10 border border-accent-cyan/30 rounded-lg",children:[(0,s.jsx)("p",{className:"text-sm text-accent-cyan font-medium mb-1",children:"CLI-assisted authentication"}),(0,s.jsx)("p",{className:"text-xs text-accent-cyan/80",children:"Codex auth uses a CLI command to capture the OAuth callback locally. Click the button below and we'll show you a command with a unique session token to run in your terminal before signing in with OpenAI."})]}),e.supportsDeviceFlow&&(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-text-secondary cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:L[e.id]||!1,onChange:t=>A(r=>({...r,[e.id]:t.target.checked})),className:"w-4 h-4 rounded border-border-subtle bg-bg-card text-accent-cyan focus:ring-accent-cyan/30 cursor-pointer"}),"Use device flow (easier for containers/headless)"]}),(0,s.jsxs)("button",{onClick:()=>O(e),disabled:null!==j,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,s.jsx)(tK,{}),"Connect with ",e.displayName]}),e.apiKeyUrl&&(0,s.jsx)("button",{onClick:()=>S(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,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)("input",{type:"password",placeholder:"Enter ".concat(e.displayName," ").concat(e.apiKeyName||"API key"),value:j===e.id?v:"",onChange:t=>{y(e.id),w(t.target.value)},onFocus:()=>y(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,s.jsx)("button",{onClick:()=>z(e),disabled:j!==e.id||!v.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,s.jsxs)("p",{className:"text-xs text-text-muted",children:["Get your API key from"," ",(0,s.jsx)("a",{href:e.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan hover:underline",children:new URL(e.apiKeyUrl).hostname})]}),(0,s.jsxs)("p",{className:"text-xs text-amber-400/80",children:["OAuth not available for ",e.displayName," in container environments"]})]})}),(0,s.jsx)("div",{className:"mt-4 pt-4 border-t border-border-subtle",children:(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:["CLI: ",(0,s.jsx)("code",{className:"px-2 py-1 bg-bg-card rounded font-mono",children:e.cliCommand})]})})]},e.id))})]}),"repos"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"Connected Repositories",subtitle:"Repositories linked to this workspace"}),(0,s.jsx)("div",{className:"space-y-3",children:l.repositories.length>0?l.repositories.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-bg-card flex items-center justify-center",children:(0,s.jsx)(tz,{})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.fullName}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:e.lastSyncedAt?"Synced ".concat(new Date(e.lastSyncedAt).toLocaleDateString()):"Not synced"})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("button",{onClick:()=>K(e.id),disabled:E===e.id||"running"!==l.status,className:"px-3 py-1.5 bg-accent-cyan/10 border border-accent-cyan/30 text-accent-cyan rounded-lg text-xs font-semibold hover:bg-accent-cyan/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center gap-1.5",title:"running"!==l.status?"Workspace must be running to sync":"Sync repository",children:E===e.id?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tQ,{spinning:!0}),"Syncing..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tQ,{}),"Sync"]})}),(0,s.jsx)(tI,{status:e.syncStatus})]})]},e.id)):(0,s.jsxs)("div",{className:"p-6 bg-bg-tertiary rounded-lg border border-border-subtle border-dashed text-center",children:[(0,s.jsx)(tz,{className:"w-8 h-8 mx-auto mb-3 text-text-muted"}),(0,s.jsx)("p",{className:"text-sm text-text-muted",children:"No repositories connected"})]})}),$.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tR,{title:"Available Repositories",subtitle:"Add more repositories to this workspace"}),(0,s.jsx)("div",{className:"space-y-3",children:$.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-border-subtle hover:border-accent-cyan/30 transition-colors",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-bg-card flex items-center justify-center",children:(0,s.jsx)(tz,{})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.fullName}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:e.isPrivate?"Private":"Public"})]})]}),(0,s.jsx)("button",{onClick:()=>G(e.id),className:"px-4 py-2 bg-accent-cyan/10 border border-accent-cyan/30 text-accent-cyan rounded-lg text-xs font-semibold hover:bg-accent-cyan/20 transition-colors",children:"Add to Workspace"})]},e.id))})]})]}),"github-access"===p&&(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsx)(tR,{title:"GitHub Repository Access",subtitle:"Repositories you have access to via your GitHub account"}),(0,s.jsx)(tW,{workspaces:l&&(null===(t=l.repositories)||void 0===t?void 0:t.length)>0?[{id:l.id,name:l.name,repositoryFullName:l.repositories[0].fullName,status:l.status}]:[],onWorkspaceCreated:(e,t)=>{ei.xv.getWorkspaceDetails(e).then(e=>{e.success&&i(e.data)})},onOpenWorkspace:e=>{o&&o()},csrfToken:a,className:"bg-bg-tertiary rounded-xl border border-border-subtle overflow-hidden"})]}),"domain"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"Custom Domain",subtitle:"Connect your own domain to this workspace"}),(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-accent-purple/20 flex items-center justify-center",children:(0,s.jsx)(tH,{className:"text-accent-purple"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:"Premium Feature"}),(0,s.jsx)("p",{className:"text-xs text-text-secondary",children:"Requires Team or Enterprise plan"})]})]})}),l.customDomain?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide font-semibold",children:"Current Domain"}),(0,s.jsx)(tI,{status:l.customDomainStatus||"pending"})]}),(0,s.jsx)("p",{className:"text-lg font-mono text-text-primary",children:l.customDomain})]}),"pending"===l.customDomainStatus&&(0,s.jsx)(t_,{onClick:q,disabled:R,variant:"primary",icon:(0,s.jsx)(tJ,{}),fullWidth:!0,children:R?"Verifying...":"Verify DNS Configuration"}),(0,s.jsx)(t_,{onClick:J,disabled:R,variant:"danger",icon:(0,s.jsx)(tY,{}),fullWidth:!0,children:"Remove Custom Domain"})]}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-2 block",children:"Domain Name"}),(0,s.jsx)("input",{type:"text",value:B,onChange:e=>T(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,s.jsx)(t_,{onClick:Z,disabled:R||!B.trim(),variant:"primary",icon:(0,s.jsx)(tH,{}),fullWidth:!0,children:R?"Setting up...":"Set Custom Domain"})]}),_&&(0,s.jsx)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:_}),F&&(0,s.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle space-y-4",children:[(0,s.jsxs)("h4",{className:"text-sm font-semibold text-text-primary flex items-center gap-2",children:[(0,s.jsx)(tX,{}),"DNS Configuration Required"]}),(0,s.jsx)("p",{className:"text-xs text-text-secondary",children:"Add the following DNS record to your domain provider:"}),(0,s.jsxs)("div",{className:"grid grid-cols-3 gap-3",children:[(0,s.jsx)(tF,{label:"Type",value:F.type}),(0,s.jsx)(tF,{label:"Name",value:F.name}),(0,s.jsx)(tF,{label:"Value",value:F.value})]})]})]}),"danger"===p&&(0,s.jsx)("div",{className:"space-y-8",children:(0,s.jsxs)("div",{className:"p-6 bg-error/5 border-2 border-error/20 rounded-xl",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-error/20 flex items-center justify-center",children:(0,s.jsx)(tG,{className:"text-error"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-base font-semibold text-error",children:"Danger Zone"}),(0,s.jsx)("p",{className:"text-xs text-text-secondary",children:"These actions are destructive and cannot be undone"})]})]}),(0,s.jsx)("div",{className:"p-5 border border-error/30 rounded-lg bg-bg-primary",children:(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:"Delete Workspace"}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-1",children:"Permanently delete this workspace and all its data"})]}),(0,s.jsx)("button",{onClick:Y,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 tR(e){let{title:t,subtitle:r}=e;return(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:t}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-1",children:r})]})}function tP(e){let{label:t,value:r,valueColor:n="text-text-primary",mono:a=!1,indicator:o=!1}=e;return(0,s.jsxs)("div",{className:"p-4 bg-bg-tertiary rounded-lg border border-border-subtle",children:[(0,s.jsx)("label",{className:"text-xs text-text-muted uppercase tracking-wide font-medium",children:t}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[o&&(0,s.jsx)("div",{className:"w-2 h-2 rounded-full bg-success animate-pulse"}),(0,s.jsx)("p",{className:"text-sm font-medium ".concat(n," ").concat(a?"font-mono":""," break-all"),children:r})]})]})}function t_(e){let{children:t,onClick:r,disabled:n,variant:a,icon:o,fullWidth:l}=e;return(0,s.jsxs)("button",{onClick:r,disabled:n,className:"".concat(l?"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:[o,t]})}function tI(e){let{status:t}=e;return(0,s.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 tF(e){let{label:t,value:r}=e;return(0,s.jsxs)("div",{className:"p-3 bg-bg-card rounded-lg",children:[(0,s.jsx)("label",{className:"text-xs text-text-muted block mb-1",children:t}),(0,s.jsx)("p",{className:"font-mono text-sm text-text-primary break-all",children:r})]})}function tU(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 tO(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,s.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,s.jsx)("path",{d:"M2 12l10 5 10-5"})]})}function tz(e){let{className:t=""}=e;return(0,s.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,s.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 tH(e){let{className:t=""}=e;return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),(0,s.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 tV(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.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"})})}function tG(e){let{className:t=""}=e;return(0,s.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,s.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,s.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function tK(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,s.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function tZ(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("rect",{x:"6",y:"6",width:"12",height:"12"})})}function tq(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M23 4v6h-6"}),(0,s.jsx)("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function tJ(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function tY(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.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 t$(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tX(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function tQ(){let{spinning:e=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e?"animate-spin":"",children:[(0,s.jsx)("path",{d:"M23 4v6h-6"}),(0,s.jsx)("path",{d:"M1 20v-6h6"}),(0,s.jsx)("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10"}),(0,s.jsx)("path",{d:"M20.49 15a9 9 0 0 1-14.85 3.36L1 14"})]})}let t0={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"},t1={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 t2(e){var t;let{workspaceId:r,currentUserId:a}=e,[o,l]=(0,n.useState)([]),[i,c]=(0,n.useState)([]),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!0),[h,p]=(0,n.useState)(!0),[g,b]=(0,n.useState)(null),[f,j]=(0,n.useState)(null),[y,v]=(0,n.useState)(!1),[w,N]=(0,n.useState)(""),[k,C]=(0,n.useState)("member"),[S,L]=(0,n.useState)(!1),[A,M]=(0,n.useState)(null),[W,E]=(0,n.useState)(null);(0,n.useEffect)(()=>{(async function(){m(!0),b(null);let[e,t]=await Promise.all([ei.xv.getWorkspaceMembers(r),ei.xv.getPendingInvites()]);e.success?l(e.data.members):b(e.error),t.success&&c(t.data.invites.filter(e=>e.workspaceId===r)),m(!1)})()},[r]),(0,n.useEffect)(()=>{(async function(){p(!0);let e=await ei.xv.getRepoCollaborators(r);e.success&&x(e.data.collaborators||[]),p(!1)})()},[r]);let D=(0,n.useCallback)(async()=>{if(!w.trim()){M("Please enter a GitHub username");return}L(!0),M(null);let e=await ei.xv.inviteMember(r,w.trim(),k);if(e.success){let e=await ei.xv.getWorkspaceMembers(r);e.success&&l(e.data.members),N(""),v(!1),j("Invitation sent to ".concat(w)),setTimeout(()=>j(null),3e3)}else M(e.error);L(!1)},[r,w,k]),B=(0,n.useCallback)(async(e,t)=>{E(e);let s=await ei.xv.updateMemberRole(r,e,t);s.success?(l(r=>r.map(r=>r.id===e?{...r,role:t}:r)),j("Role updated successfully"),setTimeout(()=>j(null),3e3)):b(s.error),E(null)},[r]),T=(0,n.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 s=await ei.xv.removeMember(r,e.id);s.success?(l(t=>t.filter(t=>t.id!==e.id)),j("Member removed successfully"),setTimeout(()=>j(null),3e3)):b(s.error)},[r]),R=null===(t=o.find(e=>e.userId===a))||void 0===t?void 0:t.role,P="owner"===R||"admin"===R;return u?(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsx)(t5,{}),(0,s.jsx)("span",{className:"ml-3 text-text-muted",children:"Loading team members..."})]}):(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:"Team Members"}),(0,s.jsxs)("p",{className:"text-xs text-text-muted mt-1",children:[o.length," member",1!==o.length?"s":""]})]}),P&&(0,s.jsxs)("button",{onClick:()=>v(!y),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,s.jsx)(t4,{}),"Invite Member"]})]}),g&&(0,s.jsxs)("div",{className:"p-3 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:[g,(0,s.jsx)("button",{onClick:()=>b(null),className:"ml-2 text-error/70 hover:text-error",children:"\xd7"})]}),f&&(0,s.jsx)("div",{className:"p-3 bg-success/10 border border-success/30 rounded-lg text-success text-sm",children:f}),y&&(0,s.jsxs)("div",{className:"p-4 bg-bg-tertiary rounded-lg border border-border-subtle space-y-4",children:[(0,s.jsx)("h4",{className:"text-sm font-medium text-text-primary",children:"Invite New Member"}),A&&(0,s.jsx)("div",{className:"p-2 bg-error/10 border border-error/30 rounded text-error text-xs",children:A}),(0,s.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"GitHub Username"}),(0,s.jsx)("input",{type:"text",value:w,onChange:e=>N(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,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Role"}),(0,s.jsxs)("select",{value:k,onChange:e=>C(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,s.jsx)("option",{value:"admin",children:"Admin"}),(0,s.jsx)("option",{value:"member",children:"Member"}),(0,s.jsx)("option",{value:"viewer",children:"Viewer"})]})]})]}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:t1[k]}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-2",children:[(0,s.jsx)("button",{onClick:D,disabled:S||!w.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:S?"Sending...":"Send Invitation"}),(0,s.jsx)("button",{onClick:()=>{v(!1),N(""),M(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,s.jsx)("div",{className:"space-y-2",children:o.map(e=>{var t,r,n,o,l,i;return(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3",children:[(null===(t=e.user)||void 0===t?void 0:t.avatarUrl)?(0,s.jsx)("img",{src:e.user.avatarUrl,alt:e.user.githubUsername,className:"w-9 h-9 md:w-10 md:h-10 rounded-full"}):(0,s.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===(o=e.user)||void 0===o?void 0:null===(n=o.githubUsername)||void 0===n?void 0:null===(r=n[0])||void 0===r?void 0:r.toUpperCase())||"?"}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:(null===(l=e.user)||void 0===l?void 0:l.githubUsername)||"Unknown User"}),e.isPending&&(0,s.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,s.jsx)("span",{className:"text-xs text-text-muted",children:"(you)"})]}),(null===(i=e.user)||void 0===i?void 0:i.email)&&(0,s.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.user.email})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 ml-12 sm:ml-0",children:[P&&"owner"!==e.role&&e.userId!==a?(0,s.jsxs)("select",{value:e.role,onChange:t=>B(e.id,t.target.value),disabled:W===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(t0[e.role]," focus:outline-none"),children:[(0,s.jsx)("option",{value:"admin",children:"Admin"}),(0,s.jsx)("option",{value:"member",children:"Member"}),(0,s.jsx)("option",{value:"viewer",children:"Viewer"})]}):(0,s.jsx)("span",{className:"px-2 md:px-3 py-1 md:py-1.5 rounded-full text-[10px] md:text-xs font-medium ".concat(t0[e.role]),children:e.role.charAt(0).toUpperCase()+e.role.slice(1)}),P&&"owner"!==e.role&&e.userId!==a&&(0,s.jsx)("button",{onClick:()=>T(e),className:"p-1.5 text-text-muted hover:text-error rounded transition-colors",title:"Remove member",children:(0,s.jsx)(t3,{})})]})]},e.id)})}),(d.length>0||h)&&(0,s.jsxs)("div",{className:"mt-8",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:"Repo Collaborators"}),(0,s.jsx)("span",{className:"px-2 py-0.5 bg-accent-purple/10 text-accent-purple text-[10px] rounded-full",children:"GitHub Access"})]}),(0,s.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."}),h?(0,s.jsxs)("div",{className:"flex items-center gap-2 py-4",children:[(0,s.jsx)(t5,{}),(0,s.jsx)("span",{className:"text-sm text-text-muted",children:"Loading collaborators..."})]}):(0,s.jsx)("div",{className:"space-y-2",children:d.map(e=>{var t;return(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3",children:[e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.login,className:"w-9 h-9 md:w-10 md:h-10 rounded-full"}):(0,s.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,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.login}),(0,s.jsx)("span",{className:"text-[10px] px-2 py-0.5 bg-accent-purple/10 text-accent-purple rounded-full",children:"via GitHub"})]}),(0,s.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,s.jsx)("div",{className:"flex items-center gap-2 sm:gap-3 ml-12 sm:ml-0",children:(0,s.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,s.jsxs)("div",{className:"mt-8",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Your Pending Invitations"}),(0,s.jsx)("div",{className:"space-y-2",children:i.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-accent-cyan/30",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.workspaceName}),(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:["Invited by ",e.invitedBy," as ",e.role]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("button",{onClick:async()=>{(await ei.xv.acceptInvite(e.id)).success&&(c(t=>t.filter(t=>t.id!==e.id)),j("Invitation accepted!"),setTimeout(()=>j(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,s.jsx)("button",{onClick:async()=>{(await ei.xv.declineInvite(e.id)).success&&c(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,s.jsxs)("div",{className:"mt-8 p-4 bg-bg-tertiary/50 rounded-lg",children:[(0,s.jsx)("h4",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-3",children:"Role Permissions"}),(0,s.jsx)("div",{className:"space-y-2",children:Object.entries(t1).map(e=>{let[t,r]=e;return(0,s.jsxs)("div",{className:"flex items-start gap-2",children:[(0,s.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium ".concat(t0[t]," shrink-0"),children:t.charAt(0).toUpperCase()+t.slice(1)}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:r})]},t)})})]})]})}function t5(){return(0,s.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function t4(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function t3(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.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 t6={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"},t8={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"},t9={free:0,pro:1,team:2,enterprise:3};function t7(e){let{onUpgrade:t}=e,[r,a]=(0,n.useState)([]),[o,l]=(0,n.useState)("free"),[i,c]=(0,n.useState)(null),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!0),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(null),[f,j]=(0,n.useState)("month"),[y,v]=(0,n.useState)(null),[w,N]=(0,n.useState)(!1),[k,C]=(0,n.useState)(!1),[S,L]=(0,n.useState)(!1);(0,n.useEffect)(()=>{!async function(){m(!0),p(null);let[e,t,r]=await Promise.all([ei.xv.getBillingPlans(),ei.xv.getSubscription(),ei.xv.getInvoices()]);if(e.success&&a(e.data.plans),t.success){var s;l(t.data.tier),c(t.data.subscription),(null===(s=t.data.subscription)||void 0===s?void 0:s.interval)&&j(t.data.subscription.interval)}r.success&&x(r.data.invoices),e.success||p(e.error),m(!1)}()},[]);let A=(0,n.useCallback)(async e=>{v(e);let t=await ei.xv.createCheckoutSession(e,f);t.success&&t.data.checkoutUrl?window.location.href=t.data.checkoutUrl:t.success||(p(t.error),v(null))},[f]),M=(0,n.useCallback)(async()=>{N(!0);let e=await ei.xv.createBillingPortal();e.success&&e.data.portalUrl?window.location.href=e.data.portalUrl:e.success||p(e.error),N(!1)},[]),W=(0,n.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;C(!0);let e=await ei.xv.cancelSubscription();e.success?(c(e=>e?{...e,cancelAtPeriodEnd:!0}:null),b(e.data.message),setTimeout(()=>b(null),5e3)):p(e.error),C(!1)},[]),E=(0,n.useCallback)(async()=>{L(!0);let e=await ei.xv.resumeSubscription();e.success?(c(e=>e?{...e,cancelAtPeriodEnd:!1}:null),b(e.data.message),setTimeout(()=>b(null),3e3)):p(e.error),L(!1)},[]);return u?(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsx)(re,{}),(0,s.jsx)("span",{className:"ml-3 text-text-muted",children:"Loading billing information..."})]}):(0,s.jsxs)("div",{className:"space-y-8",children:[h&&(0,s.jsxs)("div",{className:"p-3 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:[h,(0,s.jsx)("button",{onClick:()=>p(null),className:"ml-2 text-error/70 hover:text-error",children:"\xd7"})]}),g&&(0,s.jsx)("div",{className:"p-3 bg-success/10 border border-success/30 rounded-lg text-success text-sm",children:g}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Current Plan"}),(0,s.jsx)("div",{className:"p-4 md:p-6 rounded-lg border-2 ".concat(t6[o]),children:(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("h4",{className:"text-lg md:text-xl font-bold text-text-primary capitalize",children:[o," Plan"]}),i?(0,s.jsx)("p",{className:"text-xs md:text-sm text-text-secondary mt-1",children:i.cancelAtPeriodEnd?(0,s.jsxs)("span",{className:"text-amber-400",children:["Cancels on ",new Date(i.currentPeriodEnd).toLocaleDateString()]}):(0,s.jsxs)(s.Fragment,{children:["Renews on ",new Date(i.currentPeriodEnd).toLocaleDateString(),(0,s.jsxs)("span",{className:"text-text-muted ml-2",children:["(","year"===i.interval?"Yearly":"Monthly",")"]})]})}):(0,s.jsx)("p",{className:"text-xs md:text-sm text-text-muted mt-1",children:t8[o]||t8.free})]}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[i&&!i.cancelAtPeriodEnd&&(0,s.jsx)("button",{onClick:W,disabled:k,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:k?"Canceling...":"Cancel Plan"}),(null==i?void 0:i.cancelAtPeriodEnd)&&(0,s.jsx)("button",{onClick:E,disabled:S,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:S?"Resuming...":"Resume Plan"}),i&&(0,s.jsx)("button",{onClick:M,disabled:w,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:w?"Opening...":"Manage Billing"})]})]})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-center gap-4",children:[(0,s.jsx)("span",{className:"text-sm font-medium ".concat("month"===f?"text-text-primary":"text-text-muted"),children:"Monthly"}),(0,s.jsx)("button",{onClick:()=>j(e=>"month"===e?"year":"month"),className:"relative w-14 h-7 bg-bg-tertiary rounded-full transition-colors",children:(0,s.jsx)("span",{className:"absolute top-1 w-5 h-5 bg-accent-cyan rounded-full transition-transform ".concat("year"===f?"translate-x-8":"translate-x-1")})}),(0,s.jsxs)("span",{className:"text-sm font-medium ".concat("year"===f?"text-text-primary":"text-text-muted"),children:["Yearly",(0,s.jsx)("span",{className:"ml-1 text-xs text-success",children:"(Save 20%)"})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Available Plans"}),(0,s.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=(t9[e.tier]||0)>(t9[o]||0),r=e.recommended&&t,n=(t9[e.tier]||0)<(t9[o]||0);return(0,s.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,s.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,s.jsx)("h4",{className:"text-lg font-bold text-text-primary",children:e.name}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-1 mb-4",children:e.description}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsxs)("span",{className:"text-3xl font-bold text-text-primary",children:["$","year"===f?e.price.yearly:e.price.monthly]}),(0,s.jsxs)("span",{className:"text-text-muted",children:["/","year"===f?"year":"month"]})]}),(0,s.jsx)("ul",{className:"space-y-2 mb-6",children:e.features.slice(0,5).map((e,t)=>(0,s.jsxs)("li",{className:"flex items-start gap-2 text-sm text-text-secondary",children:[(0,s.jsx)(rt,{className:"text-success shrink-0 mt-0.5"}),e]},t))}),o===e.tier?(0,s.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,s.jsx)("button",{onClick:()=>A(e.tier),disabled:null!==y,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:y===e.tier?"Loading...":n?"Downgrade":"Upgrade"})]},e.tier)})})]}),(0,s.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,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-base md:text-lg font-bold text-text-primary",children:"Enterprise"}),(0,s.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,s.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"})]})}),d.length>0&&(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Billing History"}),(0,s.jsx)("div",{className:"hidden md:block bg-bg-tertiary rounded-lg overflow-hidden",children:(0,s.jsxs)("table",{className:"w-full",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"border-b border-border-subtle",children:[(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Invoice"}),(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Date"}),(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Amount"}),(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Status"}),(0,s.jsx)("th",{className:"text-right px-4 py-3 text-xs font-semibold text-text-muted uppercase"})]})}),(0,s.jsx)("tbody",{children:d.map(e=>(0,s.jsxs)("tr",{className:"border-b border-border-subtle last:border-0",children:[(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-text-primary font-medium",children:e.number}),(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-text-secondary",children:new Date(e.date).toLocaleDateString()}),(0,s.jsxs)("td",{className:"px-4 py-3 text-sm text-text-primary",children:["$",(e.amount/100).toFixed(2)]}),(0,s.jsx)("td",{className:"px-4 py-3",children:(0,s.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,s.jsx)("td",{className:"px-4 py-3 text-right",children:e.pdfUrl&&(0,s.jsx)("a",{href:e.pdfUrl,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-accent-cyan hover:underline",children:"Download"})})]},e.id))})]})}),(0,s.jsx)("div",{className:"md:hidden space-y-3",children:d.map(e=>(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.number}),(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"text-text-muted",children:new Date(e.date).toLocaleDateString()}),(0,s.jsxs)("span",{className:"text-text-primary font-medium",children:["$",(e.amount/100).toFixed(2)]})]}),e.pdfUrl&&(0,s.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 re(){return(0,s.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function rt(e){let{className:t=""}=e;return(0,s.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,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}let rr={theme:"dark",compactMode:!1,showTimestamps:!0,soundEnabled:!0,notificationsEnabled:!0,autoScrollMessages:!0};function rs(e){var t,r;let{currentUserId:a,initialTab:o="dashboard",onClose:l}=e,[i,c]=(0,n.useState)(o),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(null),[h,p]=(0,n.useState)(!0),[g,b]=(0,n.useState)(rr);(0,n.useEffect)(()=>{(async function(){p(!0);let e=await ei.xv.getWorkspaceSummary();e.success&&e.data.workspaces.length>0&&(x(e.data.workspaces),m(e.data.workspaces[0].id)),p(!1)})()},[]),(0,n.useEffect)(()=>{let e=localStorage.getItem("dashboard-settings");if(e)try{b({...rr,...JSON.parse(e)})}catch(e){}},[]);let f=(e,t)=>{let r={...g,[e]:t};b(r),localStorage.setItem("dashboard-settings",JSON.stringify(r)),"theme"===e&&document.documentElement.setAttribute("data-theme",t)},j=[{id:"dashboard",label:"Dashboard",icon:(0,s.jsx)(rd,{})},{id:"workspace",label:"Workspace",icon:(0,s.jsx)(rx,{})},{id:"team",label:"Team",icon:(0,s.jsx)(ru,{})},{id:"billing",label:"Billing",icon:(0,s.jsx)(rm,{})}];return(0,s.jsxs)("div",{className:"fixed inset-0 z-50 bg-bg-deep",children:[(0,s.jsxs)("div",{className:"absolute inset-0 opacity-30",children:[(0,s.jsx)("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top_right,_rgba(0,217,255,0.08)_0%,_transparent_50%)]"}),(0,s.jsx)("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_bottom_left,_rgba(168,85,247,0.06)_0%,_transparent_50%)]"})]}),(0,s.jsxs)("div",{className:"relative h-full flex flex-col",children:[(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3 md:gap-4",children:[(0,s.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,s.jsx)(rc,{className:"text-white w-4 h-4 md:w-[18px] md:h-[18px]"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{className:"text-base md:text-lg font-bold text-text-primary tracking-tight",children:"Settings"}),(0,s.jsx)("p",{className:"text-[10px] md:text-xs text-text-muted hidden sm:block",children:"Manage your workspace and preferences"})]})]}),(0,s.jsx)("button",{onClick:l,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,s.jsx)(rh,{})})]}),(0,s.jsx)("div",{className:"border-b border-border-subtle bg-bg-secondary/50",children:(0,s.jsx)("div",{className:"flex justify-center overflow-x-auto scrollbar-hide",children:j.map(e=>(0,s.jsxs)("button",{onClick:()=>c(e.id),className:"flex items-center gap-2 px-6 py-3 text-sm font-medium transition-all whitespace-nowrap ".concat(i===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,s.jsx)("span",{className:i===e.id?"text-accent-cyan":"text-text-muted",children:e.icon}),e.label]},e.id))})}),("workspace"===i||"team"===i)&&d.length>0&&(0,s.jsx)("div",{className:"px-4 py-2 border-b border-border-subtle bg-bg-tertiary/50",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full shrink-0 ".concat((null===(t=d.find(e=>e.id===u))||void 0===t?void 0:t.status)==="running"?"bg-success":(null===(r=d.find(e=>e.id===u))||void 0===r?void 0:r.status)==="stopped"?"bg-amber-400":"bg-text-muted")}),1===d.length?(0,s.jsx)("span",{className:"text-sm text-text-primary",children:d[0].name}):(0,s.jsx)("select",{value:u||"",onChange:e=>m(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,s.jsx)("option",{value:e.id,children:e.name},e.id))})]})}),(0,s.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,s.jsx)("main",{className:"h-full overflow-y-auto",children:(0,s.jsxs)("div",{className:"max-w-4xl mx-auto p-4 md:p-8",children:["dashboard"===i&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(rn,{title:"Dashboard Settings",subtitle:"Customize your dashboard experience"}),(0,s.jsxs)(ra,{title:"Appearance",icon:(0,s.jsx)(rp,{}),children:[(0,s.jsx)(ro,{label:"Theme",description:"Choose your preferred color scheme",children:(0,s.jsxs)("select",{value:g.theme,onChange:e=>f("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,s.jsx)("option",{value:"dark",children:"Dark"}),(0,s.jsx)("option",{value:"light",children:"Light"}),(0,s.jsx)("option",{value:"system",children:"System"})]})}),(0,s.jsx)(ro,{label:"Compact Mode",description:"Reduce spacing and show more content",children:(0,s.jsx)(rl,{checked:g.compactMode,onChange:e=>f("compactMode",e)})}),(0,s.jsx)(ro,{label:"Show Timestamps",description:"Display timestamps on messages",children:(0,s.jsx)(rl,{checked:g.showTimestamps,onChange:e=>f("showTimestamps",e)})})]}),(0,s.jsxs)(ra,{title:"Notifications",icon:(0,s.jsx)(rg,{}),children:[(0,s.jsx)(ro,{label:"Sound Effects",description:"Play sounds for new messages",children:(0,s.jsx)(rl,{checked:g.soundEnabled,onChange:e=>f("soundEnabled",e)})}),(0,s.jsx)(ro,{label:"Browser Notifications",description:"Show desktop notifications",children:(0,s.jsx)(rl,{checked:g.notificationsEnabled,onChange:e=>f("notificationsEnabled",e)})})]}),(0,s.jsx)(ra,{title:"Behavior",icon:(0,s.jsx)(rc,{}),children:(0,s.jsx)(ro,{label:"Auto-scroll Messages",description:"Automatically scroll to new messages",children:(0,s.jsx)(rl,{checked:g.autoScrollMessages,onChange:e=>f("autoScrollMessages",e)})})})]}),"workspace"===i&&(0,s.jsx)(s.Fragment,{children:h?(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsx)("div",{className:"relative",children:(0,s.jsx)("div",{className:"w-12 h-12 rounded-full border-2 border-accent-cyan/20 border-t-accent-cyan animate-spin"})}),(0,s.jsx)("span",{className:"ml-4 text-text-muted",children:"Loading workspaces..."})]}):u?(0,s.jsx)(tT,{workspaceId:u,csrfToken:(0,ei._V)()||void 0,onClose:l}):(0,s.jsx)(ri,{icon:(0,s.jsx)(rx,{}),title:"No Workspace",description:"Create a workspace to get started with Agent Relay.",action:(0,s.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"===i&&(0,s.jsx)(s.Fragment,{children:u?(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(rn,{title:"Team Settings",subtitle:"Manage workspace members and permissions"}),(0,s.jsx)(t2,{workspaceId:u,currentUserId:a})]}):(0,s.jsx)(ri,{icon:(0,s.jsx)(ru,{}),title:"No Workspace Selected",description:"Select a workspace to manage team members."})}),"billing"===i&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(rn,{title:"Billing & Subscription",subtitle:"Manage your plan and payment methods"}),(0,s.jsx)(t7,{})]})]})})})]})]})}function rn(e){let{title:t,subtitle:r}=e;return(0,s.jsxs)("div",{className:"mb-8",children:[(0,s.jsx)("h2",{className:"text-2xl font-bold text-text-primary",children:t}),(0,s.jsx)("p",{className:"text-sm text-text-muted mt-1",children:r})]})}function ra(e){let{title:t,icon:r,children:n}=e;return(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-xl border border-border-subtle overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-6 py-4 border-b border-border-subtle bg-bg-secondary/50 flex items-center gap-3",children:[(0,s.jsx)("span",{className:"text-accent-cyan",children:r}),(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-primary uppercase tracking-wide",children:t})]}),(0,s.jsx)("div",{className:"divide-y divide-border-subtle",children:n})]})}function ro(e){let{label:t,description:r,children:n}=e;return(0,s.jsxs)("div",{className:"px-6 py-4 flex items-center justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:t}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:r})]}),n]})}function rl(e){let{checked:t,onChange:r}=e;return(0,s.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,s.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 ri(e){let{icon:t,title:r,description:n,action:a}=e;return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[(0,s.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,s.jsx)("h3",{className:"text-lg font-semibold text-text-primary mb-2",children:r}),(0,s.jsx)("p",{className:"text-sm text-text-muted max-w-sm mb-6",children:n}),a]})}function rc(e){let{className:t=""}=e;return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 rd(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"7",height:"9"}),(0,s.jsx)("rect",{x:"14",y:"3",width:"7",height:"5"}),(0,s.jsx)("rect",{x:"14",y:"12",width:"7",height:"9"}),(0,s.jsx)("rect",{x:"3",y:"16",width:"7",height:"5"})]})}function rx(){return(0,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.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 ru(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function rm(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"1",y:"4",width:"22",height:"16",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"1",y1:"10",x2:"23",y2:"10"})]})}function rh(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rp(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"13.5",cy:"6.5",r:"2.5"}),(0,s.jsx)("circle",{cx:"19",cy:"13.5",r:"2.5"}),(0,s.jsx)("circle",{cx:"6",cy:"12",r:"2.5"}),(0,s.jsx)("circle",{cx:"11",cy:"19",r:"2.5"}),(0,s.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 rg(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),(0,s.jsx)("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}let rb={theme:"system",notifications:{enabled:!0,sound:!0,desktop:!1,mentionsOnly:!1},display:{compactMode:!1,showTimestamps:!0,showAvatars:!0,animationsEnabled:!0},connection:{autoReconnect:!0,reconnectDelay:3e3,keepAliveInterval:3e4}};var rf=r(9116);function rj(e){let{isOpen:t,onClose:r}=e,[a,o]=(0,n.useState)("conversations"),[l,i]=(0,n.useState)([]),[c,d]=(0,n.useState)([]),[x,u]=(0,n.useState)([]),[m,h]=(0,n.useState)(null),[p,g]=(0,n.useState)(!1),[b,f]=(0,n.useState)(null),[j,y]=(0,n.useState)(""),[v,w]=(0,n.useState)(""),[N,k]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&(async()=>{let e=await rf.hi.getHistoryStats();e.success&&e.data&&h(e.data)})()},[t]),(0,n.useEffect)(()=>{t&&(async()=>{g(!0),f(null);try{if("conversations"===a){let e=await rf.hi.getHistoryConversations();e.success&&e.data?i(e.data.conversations):f(e.error||"Failed to fetch conversations")}else if("sessions"===a){let e=await rf.hi.getHistorySessions({agent:v||void 0,limit:50});e.success&&e.data?d(e.data.sessions):f(e.error||"Failed to fetch sessions")}else if("messages"===a){let r={limit:100,order:"desc"};if(j&&(r.search=j),N){let[s,n]=N.participants,a=await rf.hi.getHistoryMessages({...r,from:s,to:n}),o=await rf.hi.getHistoryMessages({...r,from:n,to:s});if(a.success&&o.success){var e,t;let r=[...(null===(e=a.data)||void 0===e?void 0:e.messages)||[],...(null===(t=o.data)||void 0===t?void 0:t.messages)||[]].sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime());u(r)}}else{let e=await rf.hi.getHistoryMessages(r);e.success&&e.data?u(e.data.messages):f(e.error||"Failed to fetch messages")}}}catch(e){f("Failed to load data")}finally{g(!1)}})()},[t,a,v,j,N]);let C=(0,n.useCallback)(e=>{k(e),o("messages")},[]),S=(0,n.useCallback)(()=>{k(null),o("conversations")},[]);return t?(0,s.jsx)("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center bg-black/50",children:(0,s.jsxs)("div",{className:"bg-bg-primary rounded-lg shadow-xl w-[90vw] max-w-4xl h-[80vh] flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,s.jsxs)("div",{className:"flex items-center gap-4",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-text-primary",children:"Conversation History"}),m&&(0,s.jsxs)("div",{className:"flex gap-4 text-sm text-text-muted",children:[(0,s.jsxs)("span",{children:[m.messageCount," messages"]}),(0,s.jsxs)("span",{children:[m.sessionCount," sessions"]}),(0,s.jsxs)("span",{children:[m.uniqueAgents," agents"]})]})]}),(0,s.jsx)("button",{onClick:r,className:"p-2 text-text-muted hover:text-text-primary rounded transition-colors","aria-label":"Close",children:(0,s.jsx)(rS,{})})]}),(0,s.jsxs)("div",{className:"flex items-center gap-4 p-4 border-b border-border",children:[(0,s.jsxs)("div",{className:"flex gap-1 bg-bg-secondary rounded-md p-1",children:[(0,s.jsx)(ry,{active:"conversations"===a,onClick:()=>{k(null),o("conversations")},children:"Conversations"}),(0,s.jsx)(ry,{active:"sessions"===a,onClick:()=>o("sessions"),children:"Sessions"}),(0,s.jsx)(ry,{active:"messages"===a,onClick:()=>o("messages"),children:"Messages"})]}),"messages"===a&&(0,s.jsx)("div",{className:"flex-1 max-w-xs",children:(0,s.jsx)("input",{type:"text",placeholder:"Search messages...",value:j,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,s.jsx)("div",{className:"flex-1 max-w-xs",children:(0,s.jsx)("input",{type:"text",placeholder:"Filter by agent...",value:v,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,s.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,s.jsx)(rL,{})," Back to conversations"]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:p?(0,s.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,s.jsx)(rA,{})}):b?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-error",children:b}):"conversations"===a?(0,s.jsx)(rv,{conversations:l,onConversationClick:C}):"sessions"===a?(0,s.jsx)(rw,{sessions:c}):(0,s.jsx)(rk,{messages:x,conversationTitle:N?"".concat(N.participants[0]," & ").concat(N.participants[1]):void 0})})]})}):null}function ry(e){let{active:t,onClick:r,children:n}=e;return(0,s.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:n})}function rv(e){let{conversations:t,onConversationClick:r}=e;return 0===t.length?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No conversations found"}):(0,s.jsx)("div",{className:"space-y-2",children:t.map((e,t)=>(0,s.jsxs)("div",{onClick:()=>r(e),className:"p-4 bg-bg-secondary rounded-lg cursor-pointer hover:bg-bg-tertiary transition-colors",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-text-primary",children:e.participants.join(" & ")}),(0,s.jsxs)("span",{className:"text-xs px-2 py-0.5 bg-accent/10 text-accent rounded-full",children:[e.messageCount," messages"]})]}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:rC(e.lastTimestamp)})]}),(0,s.jsx)("p",{className:"text-sm text-text-muted truncate",children:e.lastMessage})]},t))})}function rw(e){let{sessions:t}=e;return 0===t.length?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No sessions found"}):(0,s.jsx)("div",{className:"space-y-2",children:t.map(e=>(0,s.jsxs)("div",{className:"p-4 bg-bg-secondary rounded-lg",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-text-primary",children:e.agentName}),e.cli&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-bg-tertiary text-text-muted rounded",children:e.cli}),(0,s.jsx)(rN,{isActive:e.isActive,closedBy:e.closedBy})]}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:e.duration})]}),(0,s.jsxs)("div",{className:"flex items-center gap-4 text-sm text-text-muted",children:[(0,s.jsx)("span",{children:new Date(e.startedAt).toLocaleString()}),(0,s.jsxs)("span",{children:[e.messageCount," messages"]})]}),e.summary&&(0,s.jsx)("p",{className:"mt-2 text-sm text-text-muted truncate",children:e.summary})]},e.id))})}function rN(e){let{isActive:t,closedBy:r}=e;if(t)return(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-success/10 text-success rounded-full",children:"Active"});let n={agent:"bg-text-muted/10 text-text-muted",disconnect:"bg-warning/10 text-warning",error:"bg-error/10 text-error"},a=r?n[r]:n.agent;return(0,s.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,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No messages found"}):(0,s.jsxs)("div",{className:"space-y-4",children:[r&&(0,s.jsx)("h3",{className:"text-lg font-medium text-text-primary mb-4",children:r}),t.map(e=>(0,s.jsxs)("div",{className:"p-4 bg-bg-secondary rounded-lg",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-accent",children:e.from}),(0,s.jsx)("span",{className:"text-text-muted",children:"to"}),(0,s.jsx)("span",{className:"font-medium text-text-primary",children:"*"===e.to?"Everyone":e.to}),e.isBroadcast&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-accent/10 text-accent rounded-full",children:"Broadcast"}),e.isUrgent&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-error/10 text-error rounded-full",children:"Urgent"})]}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:rC(e.timestamp)})]}),(0,s.jsx)("p",{className:"text-sm text-text-primary whitespace-pre-wrap",children:e.content}),e.thread&&(0,s.jsxs)("div",{className:"mt-2 text-xs text-text-muted",children:["Thread: ",e.thread.slice(0,8),"..."]})]},e.id))]})}function rC(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),s=Math.floor(r/6e4),n=Math.floor(r/36e5),a=Math.floor(r/864e5);return s<1?"just now":s<60?"".concat(s,"m ago"):n<24?"".concat(n,"h ago"):a<7?"".concat(a,"d ago"):t.toLocaleDateString()}function rS(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rL(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"15 18 9 12 15 6"})})}function rA(){return(0,s.jsx)("svg",{className:"animate-spin text-accent",width:"24",height:"24",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function rM(e,t){let r=e.substring(0,t).match(/(?:^|[\s(])@(\S*)$/);return r?r[1]:null}function rW(e,t,r){let s=e.substring(0,r),n=e.substring(r),a=s.match(/(?:^|[\s(])@(\S*)$/);if(a){let r=a.index||0,s=a[0].charAt(0),o=e.substring(0,"@"===s?r:r+1),l="@".concat(t," "),i=o.length+l.length;return{value:o+l+n,cursorPosition:i}}return{value:e,cursorPosition:r}}function rE(e){let{agents:t,humanUsers:r=[],inputValue:o,cursorPosition:l,onSelect:i,onClose:c,isVisible:d}=e,[x,u]=(0,n.useState)(0),m=(0,n.useRef)(null),h=(0,n.useMemo)(()=>rM(o,l),[o,l]),p=(0,n.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,n.useMemo)(()=>{if(null===h)return[];let e=h.toLowerCase(),s=[];("*".includes(e)||"everyone".includes(e)||"all".includes(e)||"broadcast".includes(e)||""===e)&&s.push({name:"*",displayName:"@everyone",description:"Broadcast to all agents",isBroadcast:!0});let n=e.startsWith("team:")||e.startsWith("team"),a=e.startsWith("team:")?e.substring(5):e.replace(/^team/,"");(n||""===e)&&p.forEach((t,r)=>{let n=r.toLowerCase();(""===a||n.includes(a)||"team:".concat(n).includes(e))&&s.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 o=new Set(t.map(e=>e.name.toLowerCase()));return r.filter(t=>{let r=t.username.toLowerCase();return r.includes(e)&&!o.has(r)}).forEach(e=>{s.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=>{s.push({name:e.name,displayName:"@".concat(e.name),description:e.team?"".concat(e.status||"Agent"," \xb7 ").concat(e.team):e.status||"Agent"})}),s},[h,t,r,p]);(0,n.useEffect)(()=>{u(0)},[g.length]),(0,n.useEffect)(()=>{if(!m.current)return;let e=m.current.querySelector('[data-selected="true"]');e&&e.scrollIntoView({block:"nearest"})},[x]);let b=(0,n.useCallback)(e=>{if(d&&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[x];if(t){let e=rW(o,t.name,l);i(t.name,e.value)}break;case"Escape":e.preventDefault(),c()}},[d,g,x,o,l,i,c]);(0,n.useEffect)(()=>{if(d)return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[d,b]);let f=(0,n.useCallback)(e=>{let t=rW(o,e.name,l);i(e.name,t.value)},[o,l,i]);return d&&0!==g.length?(0,s.jsx)("div",{className:"absolute bottom-full left-0 right-0 max-h-[200px] overflow-y-auto bg-[#1a1d21] border border-white/10 rounded-lg shadow-[0_-4px_20px_rgba(0,0,0,0.4)] z-[100] mb-1",ref:m,children:g.map((e,t)=>(0,s.jsxs)("div",{"data-selected":t===x,className:"flex items-center gap-2.5 py-2 px-3 cursor-pointer transition-colors duration-150 ".concat(t===x?"bg-white/[0.08]":"hover:bg-white/[0.08]"),onClick:()=>f(e),onMouseEnter:()=>u(t),children:[e.isHuman&&e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-7 h-7 rounded-md object-cover"}):(0,s.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,a.GW)(e.name).primary},children:e.isBroadcast?"*":e.isTeam?(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}):e.isHuman?(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"12",cy:"7",r:"4"})]}):(0,a.hP)(e.name)}),(0,s.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-[#d1d2d3]",children:e.displayName}),(0,s.jsx)("span",{className:"text-xs text-[#8d8d8e] truncate",children:e.description})]})]},e.name))}):null}function rD(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 rB(e,t,r){let s=e.substring(0,r),n=e.substring(r),a=s.match(/(?:^|[\s(])@(\S*)$/);if(a){let r=a.index||0,s=a[0].charAt(0);return e.substring(0,"@"===s?r:r+1)+"@".concat(t," ")+n}return e}let rT=new Map;function rR(e){let{inputValue:t,cursorPosition:r,onSelect:a,onClose:o,isVisible:l,apiBase:i=""}=e,[c,d]=(0,n.useState)(0),[x,u]=(0,n.useState)([]),[m,h]=(0,n.useState)(!1),[p,g]=(0,n.useState)(null),b=(0,n.useRef)(null),f=(0,n.useRef)(null),j=(0,n.useMemo)(()=>rD(t,r),[t,r]);(0,n.useEffect)(()=>{if(!l||null===j){u([]);return}let e=j||"__root__",t=rT.get(e);if(t&&Date.now()-t.timestamp<3e4){u(t.files),g(null);return}f.current&&f.current.abort();let r=new AbortController;f.current=r;let s=setTimeout(async()=>{h(!0),g(null);try{let t=j||"",s=await fetch("".concat(i,"/api/files?q=").concat(encodeURIComponent(t),"&limit=15"),{signal:r.signal});if(!s.ok)throw Error("Failed to fetch files");let n=((await s.json()).files||[]).map(e=>({path:e.path,name:e.name,isDirectory:e.isDirectory||!1}));rT.set(e,{files:n,timestamp:Date.now()}),u(n)}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;g("Failed to load files"),u([])}finally{h(!1)}},150);return()=>{clearTimeout(s),r.abort()}},[l,j,i]),(0,n.useEffect)(()=>{d(0)},[x.length]),(0,n.useEffect)(()=>{if(!b.current)return;let e=b.current.querySelector('[data-selected="true"]');e&&e.scrollIntoView({block:"nearest"})},[c]);let y=(0,n.useCallback)(e=>{if(l&&0!==x.length)switch(e.key){case"ArrowDown":e.preventDefault(),d(e=>(e+1)%x.length);break;case"ArrowUp":e.preventDefault(),d(e=>(e-1+x.length)%x.length);break;case"Enter":case"Tab":e.preventDefault();let s=x[c];if(s){let e=rB(t,s.path,r);a(s.path,e)}break;case"Escape":e.preventDefault(),o()}},[l,x,c,t,r,a,o]);(0,n.useEffect)(()=>{if(l)return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[l,y]);let v=(0,n.useCallback)(e=>{let s=rB(t,e.path,r);a(e.path,s)},[t,r,a]);return l&&(0!==x.length||m||p)?(0,s.jsxs)("div",{className:"absolute bottom-full left-0 right-0 max-h-[240px] overflow-y-auto bg-[#1a1d21] border border-white/10 rounded-lg shadow-[0_-4px_20px_rgba(0,0,0,0.4)] z-[100] mb-1",ref:b,children:[(0,s.jsxs)("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wider text-[#8d8d8e] border-b border-white/5 flex items-center gap-2",children:[(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,s.jsx)("polyline",{points:"13 2 13 9 20 9"})]}),"Files ",j&&(0,s.jsxs)("span",{className:"text-[#6b6b6c]",children:['matching "',j,'"']})]}),m&&0===x.length&&(0,s.jsxs)("div",{className:"px-3 py-4 text-sm text-[#8d8d8e] text-center",children:[(0,s.jsx)("svg",{className:"animate-spin mx-auto mb-2",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})}),"Searching files..."]}),p&&(0,s.jsx)("div",{className:"px-3 py-4 text-sm text-red-400 text-center",children:p}),x.map((e,t)=>(0,s.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-white/[0.08]":"hover:bg-white/[0.08]"),onClick:()=>v(e),onMouseEnter:()=>d(t),children:[(0,s.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-[#8d8d8e]",style:{background:e.isDirectory?"rgba(251, 191, 36, 0.15)":"rgba(96, 165, 250, 0.15)"},children:e.isDirectory?(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#fbbf24",strokeWidth:"2",children:(0,s.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,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#60a5fa",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,s.jsx)("polyline",{points:"13 2 13 9 20 9"})]})}),(0,s.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-[#d1d2d3] truncate",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-[#6b6b6c] truncate",children:e.path})]})]},e.path)),!m&&!p&&0===x.length&&j&&(0,s.jsxs)("div",{className:"px-3 py-4 text-sm text-[#8d8d8e] text-center",children:['No files found matching "',j,'"']})]}):null}function rP(e){let{workspaces:t,activeWorkspaceId:r,onSelect:a,onAddWorkspace:o,onWorkspaceSettings:l,isLoading:i=!1}=e,[c,d]=(0,n.useState)(!1),x=(0,n.useRef)(null),u=t.find(e=>e.id===r);return(0,n.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=e=>{"Escape"===e.key&&d(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[]),(0,s.jsxs)("div",{className:"relative w-full",ref:x,children:[(0,s.jsxs)("button",{className:"w-full flex items-center gap-2 px-3 py-2.5 bg-[#2a2a3e] border border-[#3a3a4e] rounded-lg text-[#e8e8e8] text-sm cursor-pointer transition-all hover:bg-[#3a3a4e] hover:border-[#4a4a5e] disabled:opacity-60 disabled:cursor-not-allowed",onClick:()=>d(!c),disabled:i,children:[i?(0,s.jsx)("span",{className:"flex-1 text-left text-[#666]",children:"Loading..."}):u?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r_,{provider:u.provider}),(0,s.jsx)("span",{className:"flex-1 text-left font-medium",children:u.name}),u.gitBranch&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-[#888] bg-white/5 px-1.5 py-0.5 rounded",children:[(0,s.jsx)(rU,{}),u.gitBranch]})]}):(0,s.jsx)("span",{className:"flex-1 text-left text-[#666]",children:"Select workspace..."}),(0,s.jsx)(rF,{isOpen:c})]}),c&&(0,s.jsxs)("div",{className:"absolute top-[calc(100%+4px)] left-0 right-0 bg-[#1a1a2e] border border-[#3a3a4e] rounded-lg shadow-[0_10px_40px_rgba(0,0,0,0.4)] z-[1000] overflow-hidden",children:[(0,s.jsx)("div",{className:"max-h-[300px] overflow-y-auto",children:0===t.length?(0,s.jsxs)("div",{className:"py-6 px-4 text-center text-[#666] text-[13px] leading-relaxed",children:["No workspaces added yet.",(0,s.jsx)("br",{}),"Add a repository to get started."]}):t.map(e=>(0,s.jsxs)("button",{className:"w-full flex items-center gap-2.5 px-3 py-2.5 bg-transparent border-none text-[#e8e8e8] text-sm cursor-pointer transition-colors text-left hover:bg-white/5 ".concat(e.id===r?"bg-[rgba(0,200,150,0.1)]":""),onClick:()=>{a(e),d(!1)},children:[(0,s.jsx)(r_,{provider:e.provider}),(0,s.jsxs)("div",{className:"flex-1 flex flex-col gap-0.5 min-w-0",children:[(0,s.jsx)("span",{className:"font-medium",children:e.name}),(0,s.jsx)("span",{className:"text-[11px] text-[#666] overflow-hidden text-ellipsis whitespace-nowrap",children:e.path})]}),(0,s.jsx)(rI,{status:e.status})]},e.id))}),(0,s.jsxs)("div",{className:"p-2 border-t border-[#3a3a4e] space-y-1.5",children:[l&&u&&(0,s.jsxs)("button",{className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-transparent border border-[#3a3a4e] rounded-md text-[#888] text-[13px] cursor-pointer transition-all hover:bg-white/5 hover:border-[#4a4a5e] hover:text-[#e8e8e8]",onClick:()=>{l(),d(!1)},children:[(0,s.jsx)(rz,{}),"Workspace Settings"]}),(0,s.jsxs)("button",{className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-transparent border border-dashed border-[#3a3a4e] rounded-md text-[#888] text-[13px] cursor-pointer transition-all hover:bg-white/5 hover:border-[#4a4a5e] hover:text-[#e8e8e8]",onClick:o,children:[(0,s.jsx)(rO,{}),"Add Workspace"]})]})]})]})}function r_(e){let{provider:t}=e,r={claude:"\uD83E\uDD16",codex:"\uD83E\uDDE0",gemini:"✨",generic:"\uD83D\uDCC1"};return(0,s.jsx)("span",{className:"text-base",title:t,children:r[t]||r.generic})}function rI(e){let{status:t}=e,r={active:"bg-green-500",inactive:"bg-gray-500",error:"bg-red-500"};return(0,s.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 ".concat(r[t]||r.inactive),title:t})}function rF(e){let{isOpen:t}=e;return(0,s.jsx)("svg",{className:"text-[#666] transition-transform ".concat(t?"rotate-180":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function rU(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,s.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,s.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,s.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})}function rO(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function rz(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 rH(e){let{isOpen:t,onClose:r,onAdd:a,isAdding:o=!1,error:l}=e,[i,c]=(0,n.useState)(""),[d,x]=(0,n.useState)(""),[u,m]=(0,n.useState)(null),h=(0,n.useRef)(null);(0,n.useEffect)(()=>{t&&h.current&&h.current.focus()},[t]),(0,n.useEffect)(()=>{t||(c(""),x(""),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=l||u;return(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-[#e8e8e8]",children:"Add Workspace"}),(0,s.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,s.jsx)(rV,{})})]}),(0,s.jsxs)("form",{onSubmit:p,children:[(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{htmlFor:"workspace-path",className:"block mb-2 text-[13px] font-medium text-[#e8e8e8]",children:"Repository Path"}),(0,s.jsx)("input",{ref:h,id:"workspace-path",type:"text",value:i,onChange:e=>{c(e.target.value),m(null)},placeholder:"/path/to/repository",disabled:o,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,s.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,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{htmlFor:"workspace-name",className:"block mb-2 text-[13px] font-medium text-[#e8e8e8]",children:"Display Name (optional)"}),(0,s.jsx)("input",{id:"workspace-name",type:"text",value:d,onChange:e=>x(e.target.value),placeholder:"My Project",disabled:o,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,s.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,s.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,s.jsxs)("div",{className:"flex gap-3 justify-end mt-6",children:[(0,s.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:o,children:"Cancel"}),(0,s.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:o||!i.trim(),children:o?"Adding...":"Add Workspace"})]})]})]})})}function rV(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}let rG=0;function rK(){return"log-".concat(Date.now(),"-").concat(++rG)}var rZ=r(9540),rq=r(1561),rJ=r(7418);let rY=(0,n.createContext)({wsBaseUrl:null,isCloudMode:!1});function r$(e){let{children:t,wsUrl:r}=e,a=(0,n.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,s.jsx)(rY.Provider,{value:a,children:t})}let rX={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 rQ(e){let{agentName:t,maxHeight:r="500px",showHeader:o=!0,onClose:l,className:i=""}=e,c=(0,n.useRef)(null),d=(0,n.useRef)(null),x=(0,n.useRef)(null),u=(0,n.useRef)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(null),p=(0,n.useRef)(0),[g,b]=(0,n.useState)(!1),[f,j]=(0,n.useState)(!1),[y,v]=(0,n.useState)(null),[w,N]=(0,n.useState)(!1),[k,C]=(0,n.useState)(""),[S,L]=(0,n.useState)(0),A=(0,n.useRef)(null),M=(0,a.GW)(t),W=function(e){let{wsBaseUrl:t}=(0,n.useContext)(rY);return(0,n.useMemo)(()=>{if(t)return"".concat(t).concat(e);let r="https:"===window.location.protocol?"wss:":"ws:",{hostname:s,port:n}=window.location;return"".concat(r,"//").concat(window.location.host).concat(e)},[t,e])}("/ws/logs/".concat(encodeURIComponent(t)));(0,n.useEffect)(()=>{if(!c.current)return;let e=new rZ.o({theme:rX,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 rq.X,r=new rJ.Z;e.loadAddon(t),e.loadAddon(r),e.open(c.current),t.fit(),d.current=e,x.current=t,u.current=r;let s=new ResizeObserver(()=>{t.fit()});return s.observe(c.current),()=>{s.disconnect(),e.dispose(),d.current=null,x.current=null,u.current=null}},[]);let E=(0,n.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;j(!0),v(null);let s=new WebSocket(W);m.current=s,s.onopen=()=>{var e;b(!0),j(!1),v(null),p.current=0,null===(e=d.current)||void 0===e||e.writeln("\x1b[90m[Connected to ".concat(t," log stream]\x1b[0m"))},s.onclose=e=>{var t,r;if(b(!1),j(!1),m.current=null,h.current&&(clearTimeout(h.current),h.current=null),4404===e.code){null===(r=d.current)||void 0===r||r.writeln("\x1b[31m[Agent not found]\x1b[0m");return}let s=Math.min(1e3*Math.pow(2,p.current),3e4);p.current++,null===(t=d.current)||void 0===t||t.writeln("\x1b[90m[Disconnected. Reconnecting in ".concat(s/1e3,"s...]\x1b[0m")),h.current=setTimeout(()=>{E()},s)},s.onerror=()=>{v(Error("WebSocket connection error")),j(!1)},s.onmessage=e=>{var t,r,s;try{let s=JSON.parse(e.data);if("error"===s.type){null===(t=d.current)||void 0===t||t.writeln("\x1b[31mError: ".concat(s.error,"\x1b[0m"));return}if("subscribed"===s.type)return;if("history"===s.type&&Array.isArray(s.lines)){s.lines.forEach(e=>{var t;null===(t=d.current)||void 0===t||t.writeln(e),L(e=>e+1)});return}if("log"===s.type||"output"===s.type){let e=s.content||s.data||s.message||"";if(e){null===(r=d.current)||void 0===r||r.write(e);let t=(e.match(/\n/g)||[]).length;t>0&&L(e=>e+t)}return}s.lines&&Array.isArray(s.lines)&&s.lines.forEach(e=>{var t;let r="string"==typeof e?e:e.content;null===(t=d.current)||void 0===t||t.writeln(r),L(e=>e+1)})}catch(t){if("string"==typeof e.data){null===(s=d.current)||void 0===s||s.write(e.data);let t=(e.data.match(/\n/g)||[]).length;t>0&&L(e=>e+t)}}}},[W,t]),D=(0,n.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null),m.current&&(m.current.close(),m.current=null),b(!1),j(!1)},[]),B=(0,n.useCallback)(()=>{var e;null===(e=d.current)||void 0===e||e.clear(),L(0)},[]),T=(0,n.useCallback)(e=>{C(e),e&&u.current&&u.current.findNext(e,{caseSensitive:!1})},[]),R=(0,n.useCallback)(()=>{k&&u.current&&u.current.findNext(k,{caseSensitive:!1})},[k]),P=(0,n.useCallback)(()=>{k&&u.current&&u.current.findPrevious(k,{caseSensitive:!1})},[k]);return(0,n.useEffect)(()=>(E(),()=>{D()}),[E,D]),(0,n.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?P():R())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[w,R,P]),(0,s.jsxs)("div",{className:"xterm-log-viewer flex flex-col rounded-xl overflow-hidden border border-[#2a2d35] shadow-2xl ".concat(i),style:{background:"linear-gradient(180deg, #0d0f14 0%, #0a0c10 100%)",boxShadow:"0 0 60px -15px ".concat(M.primary,"25, 0 25px 50px -12px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255,255,255,0.02)")},children:[o&&(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"flex items-center gap-2",children:(0,s.jsxs)("div",{className:"flex gap-1.5",children:[(0,s.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,s.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,s.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,s.jsx)("div",{className:"w-px h-4 bg-[#30363d]"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(r0,{}),(0,s.jsx)("span",{className:"text-sm font-semibold",style:{color:M.primary},children:t}),(0,s.jsx)(r8,{isConnected:g,isConnecting:f})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.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,s.jsx)(r1,{})}),(0,s.jsx)("button",{className:"p-1.5 rounded-lg hover:bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-all duration-200",onClick:B,title:"Clear logs",children:(0,s.jsx)(r2,{})}),(0,s.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?D:E,title:g?"Disconnect":"Connect",children:g?(0,s.jsx)(r3,{}):(0,s.jsx)(r4,{})}),l&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"w-px h-4 bg-[#30363d] mx-1"}),(0,s.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,s.jsx)(r5,{})})]})]})]}),w&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-[#21262d] bg-[#161b22]",children:[(0,s.jsx)(r1,{}),(0,s.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=>T(e.target.value)}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{className:"px-2 py-0.5 text-xs rounded bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-colors",onClick:P,title:"Previous (Shift+Enter)",children:"↑"}),(0,s.jsx)("button",{className:"px-2 py-0.5 text-xs rounded bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-colors",onClick:R,title:"Next (Enter)",children:"↓"})]})]}),y&&(0,s.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,s.jsx)(r6,{}),(0,s.jsx)("span",{children:y.message}),(0,s.jsx)("button",{className:"ml-auto text-xs px-2 py-0.5 rounded bg-[#f85149]/20 hover:bg-[#f85149]/30 transition-colors",onClick:E,children:"Retry"})]}),(0,s.jsx)("div",{ref:c,className:"flex-1 overflow-hidden",style:{maxHeight:r,minHeight:"200px"}}),(0,s.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,s.jsx)("div",{className:"flex items-center gap-3",children:(0,s.jsxs)("span",{className:"tabular-nums font-mono text-[#6e7681]",children:[S," lines"]})}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-[#6e7681] font-mono uppercase tracking-wider text-[10px]",children:"PTY stream"}),(0,s.jsx)("div",{className:"w-2 h-2 rounded-full transition-all duration-300 ".concat(g?"bg-[#3fb950]":f?"bg-[#d29922] animate-pulse":"bg-[#484f58]"),style:{boxShadow:g?"0 0 8px rgba(63,185,80,0.6)":"none"}})]})]})]})}function r0(){return(0,s.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,s.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,s.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function r1(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-[#8b949e]",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function r2(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.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 r5(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function r4(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function r3(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,s.jsx)("rect",{x:"6",y:"4",width:"4",height:"16"}),(0,s.jsx)("rect",{x:"14",y:"4",width:"4",height:"16"})]})}function r6(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function r8(e){let{isConnected:t,isConnecting:r}=e;return r?(0,s.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,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#d29922] animate-pulse"}),"connecting"]}):t?(0,s.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,s.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,s.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,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58]"}),"offline"]})}function r9(e){let{agentName:t,mode:r="panel",maxHeight:o="500px",showHeader:l=!0,autoScrollDefault:i=!0,onClose:c,onExpand:d,className:x=""}=e,[u,m]=(0,n.useState)(i),h=(0,n.useRef)(null),{logs:p,isConnected:g,isConnecting:b}=function(e){let{agentName:t,maxLines:r=5e3,autoConnect:s=!0,reconnect:a=!0,maxReconnectAttempts:o=1/0}=e,[l,i]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),[x,u]=(0,n.useState)(!1),[m,h]=(0,n.useState)(null),p=(0,n.useRef)(null),g=(0,n.useRef)(0),b=(0,n.useRef)(null),f=(0,n.useRef)(t),j=(0,n.useRef)(!0),y=(0,n.useRef)(!1),v=(0,n.useRef)(new WeakMap),w=(0,n.useRef)(new WeakMap);f.current=t;let N=(0,n.useCallback)(()=>{var e,t;if(j.current=!0,(null===(e=p.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN||(null===(t=p.current)||void 0===t?void 0:t.readyState)===WebSocket.CONNECTING||y.current)return;y.current=!0,u(!0),h(null);let s=function(e){let t="/ws/logs/".concat(encodeURIComponent(e)),r="https:"===window.location.protocol?"wss:":"ws:",{hostname:s,port:n}=window.location;return"".concat(r,"//").concat(window.location.host).concat(t)}(f.current);try{let e=new WebSocket(s);p.current=e,v.current.set(e,!1),w.current.set(e,!1),e.onopen=()=>{y.current=!1,d(!0),u(!1),h(null),g.current=0,i(e=>[...e,{id:rK(),timestamp:Date.now(),content:"Connected to ".concat(f.current," log stream"),type:"system",agentName:f.current}])},e.onclose=t=>{var r,s;let n=null!==(r=v.current.get(e))&&void 0!==r&&r,l=null!==(s=w.current.get(e))&&void 0!==s&&s;if(y.current=!1,d(!1),u(!1),p.current=null,b.current&&(clearTimeout(b.current),b.current=null),!n&&4404!==t.code){if(!t.wasClean&&l){let e=j.current&&a&&g.current<o;i(r=>[...r,{id:rK(),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:f.current}])}if(j.current&&a&&g.current<o){let e=Math.min(1e3*Math.pow(2,g.current),3e4);g.current++,b.current=setTimeout(()=>{N()},e)}}},e.onerror=()=>{y.current=!1,h(Error("WebSocket connection error")),u(!1)},e.onmessage=t=>{try{let s=JSON.parse(t.data);if("error"===s.type){h(Error(s.error||"Failed to stream logs for ".concat(s.agent||f.current))),i(e=>[...e,{id:rK(),timestamp:Date.now(),content:"Error: ".concat(s.error||"Unknown error"),type:"system",agentName:s.agent||f.current}]);return}if("subscribed"===s.type){console.log("[useAgentLogs] Subscribed to ".concat(s.agent));return}if("history"===s.type&&Array.isArray(s.lines)){s.lines.length>0&&w.current.set(e,!0),i(e=>{let t=s.lines.map(e=>({id:rK(),timestamp:Date.now(),content:e,type:"stdout",agentName:s.agent||f.current}));return[...e,...t].slice(-r)});return}"string"==typeof s?(w.current.set(e,!0),i(e=>[...e,{id:rK(),timestamp:Date.now(),content:s,type:"stdout",agentName:f.current}].slice(-r))):"log"===s.type||"output"===s.type?(w.current.set(e,!0),i(e=>{let t="stderr"===s.stream?"stderr":"stdout";return[...e,{id:rK(),timestamp:s.timestamp||Date.now(),content:s.content||s.data||s.message||"",type:t,agentName:s.agentName||f.current}].slice(-r)})):s.lines&&Array.isArray(s.lines)&&(w.current.set(e,!0),i(e=>{let t=s.lines.map(e=>{let t="object"==typeof e&&"stderr"===e.type?"stderr":"stdout";return{id:rK(),timestamp:Date.now(),content:"string"==typeof e?e:e.content,type:t,agentName:f.current}});return[...e,...t].slice(-r)}))}catch(s){"string"==typeof t.data&&(w.current.set(e,!0),i(e=>[...e,{id:rK(),timestamp:Date.now(),content:t.data,type:"stdout",agentName:f.current}].slice(-r)))}}}catch(e){y.current=!1,h(e instanceof Error?e:Error("Failed to create WebSocket")),u(!1)}},[r,a,o]),k=(0,n.useCallback)(()=>{j.current=!1,b.current&&(clearTimeout(b.current),b.current=null),p.current&&(v.current.set(p.current,!0),p.current.close(),p.current=null),y.current=!1,d(!1),u(!1)},[]),C=(0,n.useCallback)(()=>{i([])},[]);return(0,n.useEffect)(()=>(s&&t&&N(),()=>{k()}),[t,s,N,k]),{logs:l,isConnected:c,isConnecting:x,error:m,connect:N,disconnect:k,clear:C}}({agentName:t,autoConnect:!0}),f=(0,a.GW)(t),j=(0,n.useMemo)(()=>p.filter(e=>{let t=st(e.content).trim();return 0!==t.length&&!(t.length<=2&&/^[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⣾⣽⣻⢿⡿⣟⣯⣷◐◓◑◒●○◉◎|\\\/\-*.\u2800-\u28FF]+$/.test(t))}),[p]);(0,n.useEffect)(()=>{if(u&&h.current){let e=h.current;e.scrollTop=e.scrollHeight}},[p,u]);let y=(0,n.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,s.jsxs)("div",{className:"log-viewer-inline rounded-lg overflow-hidden border border-[#2a2d35] ".concat(x),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,s.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,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(sr,{}),(0,s.jsx)("span",{className:"text-xs font-medium",style:{color:f.primary},children:"Live logs"}),(0,s.jsx)(se,{isConnected:g,isConnecting:b})]}),(0,s.jsx)("div",{className:"flex items-center gap-1",children:(0,s.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:d,title:"Expand",children:(0,s.jsx)(ss,{})})})]}),(0,s.jsxs)("div",{className:"font-mono text-xs leading-relaxed p-3 overflow-y-auto",style:{maxHeight:"150px"},ref:h,onScroll:y,children:[j.slice(-20).map(e=>(0,s.jsx)(r7,{log:e,compact:!0},e.id)),0===j.length&&(0,s.jsxs)("div",{className:"text-[#484f58] italic flex items-center gap-2",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58] animate-pulse"}),"Waiting for output..."]})]})]}):(0,s.jsx)(rQ,{agentName:t,maxHeight:o,showHeader:l,onClose:c,className:x})}function r7(e){let{log:t,compact:r=!1}=e,n=st(t.content);return(0,s.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:n})}function se(e){let{isConnected:t,isConnecting:r}=e;return r?(0,s.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,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#d29922] animate-pulse"}),"connecting"]}):t?(0,s.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,s.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,s.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,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58]"}),"offline"]})}function st(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 sr(e){let{size:t=16}=e;return(0,s.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,s.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,s.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function ss(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,s.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,s.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}function sn(e){let{agent:t,position:r="right",isOpen:o,onClose:l,onAgentChange:i,availableAgents:c=[]}=e,d=(0,a.GW)(t.name),[x,u]=(0,n.useState)(!0);return((0,n.useEffect)(()=>{let e=e=>{"Escape"===e.key&&o&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,l]),(0,n.useEffect)(()=>{if(o&&"fullscreen"===r)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[o,r]),o)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 z-[1099] animate-fade-in",onClick:l}),(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[#21262d] transition-all duration-200 ".concat(x?"px-4 py-2":"px-5 py-4"),style:{background:"linear-gradient(180deg, #161b22 0%, #0d1117 100%)"},children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("button",{className:"p-1 rounded-md text-[#8b949e] hover:text-[#c9d1d9] hover:bg-[#21262d] transition-colors",onClick:()=>u(!x),title:x?"Expand header":"Collapse header",children:(0,s.jsx)(su,{collapsed:x})}),(0,s.jsxs)("div",{className:"relative shrink-0 rounded-xl flex items-center justify-center font-bold overflow-hidden transition-all duration-200 ".concat(x?"w-8 h-8 text-xs":"w-11 h-11 text-sm"),style:{backgroundColor:d.primary,color:d.text,boxShadow:x?"0 0 12px ".concat(d.primary,"40"):"0 0 24px ".concat(d.primary,"50, inset 0 1px 0 rgba(255,255,255,0.2)")},children:[(0,s.jsx)("div",{className:"absolute inset-0 opacity-30",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.35) 0%, transparent 50%)"}}),(0,s.jsx)("span",{className:"relative z-10",children:(0,a.hP)(t.name)})]}),x?(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-sm font-semibold",style:{color:d.primary},children:t.name}),(0,s.jsx)("span",{className:"px-2 py-0.5 rounded text-[9px] uppercase tracking-wider font-medium ".concat("online"===t.status?"bg-[#3fb950]/15 text-[#3fb950]":"busy"===t.status?"bg-[#d29922]/15 text-[#d29922]":"bg-[#484f58]/15 text-[#484f58]"),children:t.status})]}):(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold m-0",style:{color:d.primary},children:t.name}),(0,s.jsx)("span",{className:"px-2.5 py-0.5 rounded-md text-[10px] uppercase tracking-wider font-medium ".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,s.jsx)("span",{className:"text-sm text-[#8b949e] truncate max-w-[300px] mt-0.5",children:t.currentTask})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[c.length>1&&i&&(0,s.jsx)(sa,{agents:c,currentAgent:t,onSelect:i}),(0,s.jsxs)("div",{className:"flex items-center gap-1 bg-[#21262d]/80 rounded-lg p-1 border border-[#30363d]/50",children:[(0,s.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,s.jsx)(sl,{})}),(0,s.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,s.jsx)(si,{})}),(0,s.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,s.jsx)(sc,{})})]}),(0,s.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,s.jsx)(so,{})})]})]}),(0,s.jsx)("div",{className:"flex-1 min-h-0",children:(0,s.jsx)(r9,{agentName:t.name,mode:"panel",showHeader:!1,maxHeight:"100%",className:"h-full rounded-none border-none"})})]}),(0,s.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 sa(e){let{agents:t,currentAgent:r,onSelect:o}=e,[l,i]=n.useState(!1),c=n.useRef(null);return(0,n.useEffect)(()=>{let e=e=>{c.current&&!c.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.jsxs)("div",{className:"relative",ref:c,children:[(0,s.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:()=>i(!l),children:[(0,s.jsx)("span",{children:"Switch agent"}),(0,s.jsx)(sd,{})]}),l&&(0,s.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,s.jsx)("div",{className:"max-h-64 overflow-y-auto",children:t.map(e=>{let t=(0,a.GW)(e.name),n=e.name===r.name;return(0,s.jsxs)("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left transition-colors ".concat(n?"bg-[#238636]/20":"hover:bg-[#21262d]"),onClick:()=>{o(e),i(!1)},children:[(0,s.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,a.hP)(e.name)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"text-sm text-[#c9d1d9] truncate",children:e.name}),(0,s.jsx)("div",{className:"text-xs text-[#8b949e]",children:e.status})]}),n&&(0,s.jsx)(sx,{})]},e.name)})})})]})}function so(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function sl(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,s.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})}function si(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,s.jsx)("line",{x1:"3",y1:"15",x2:"21",y2:"15"})]})}function sc(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,s.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,s.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}function sd(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function sx(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3fb950",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function su(e){let{collapsed:t}=e;return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform duration-200 ".concat(t?"":"rotate-90"),children:(0,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function sm(e){let{agentName:t,steps:r,history:a=[],selectedTrajectoryId:o,onSelectTrajectory:l,isLoading:i=!1,onStepClick:c,compact:d=!1}=e,[x,u]=(0,n.useState)(new Set),[m,h]=(0,n.useState)("all"),p=(0,n.useMemo)(()=>"all"===m?r:r.filter(e=>e.type===m),[r,m]),g=e=>{u(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},b=[{value:"all",label:"All",icon:(0,s.jsx)(sb,{})},{value:"tool_call",label:"Tools",icon:(0,s.jsx)(sf,{})},{value:"decision",label:"Decisions",icon:(0,s.jsx)(sj,{})},{value:"message",label:"Messages",icon:(0,s.jsx)(sy,{})},{value:"state_change",label:"State",icon:(0,s.jsx)(sv,{})},{value:"phase_transition",label:"Phases",icon:(0,s.jsx)(sw,{})},{value:"error",label:"Errors",icon:(0,s.jsx)(sN,{})}],f=(0,n.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,s.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,s.jsxs)("div",{className:"relative",children:[(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border/30",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[o&&l&&(0,s.jsxs)("button",{onClick:()=>l(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,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,s.jsx)("path",{d:"M19 12H5M12 19l-7-7 7-7",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,s.jsx)("span",{children:"List"})]}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.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,s.jsx)(sg,{})}),r.some(e=>"running"===e.status)&&(0,s.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,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary tracking-wide",children:"Trajectory"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("span",{className:"text-[11px] text-text-muted font-mono",children:[r.length," ",1===r.length?"step":"steps"]}),t&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-dim",children:"|"}),(0,s.jsx)("span",{className:"text-[11px] text-accent-cyan/80 font-medium truncate max-w-[120px]",children:t})]})]})]})]}),f.total>0&&!d&&(0,s.jsx)("div",{className:"flex items-center gap-1.5",children:["plan","design","execute","review","observe"].map(e=>{let t=f.phases[e]||0,r=sp(e);return t>0?(0,s.jsx)("div",{className:"h-1.5 rounded-full transition-all duration-300",style:{width:"".concat(Math.max(8,t/f.total*48),"px"),backgroundColor:r||"var(--color-border)"},title:"".concat(e,": ").concat(t)},e):null})})]}),!d&&(0,s.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:b.map(e=>(0,s.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,s.jsx)("span",{className:"opacity-70",children:e.icon}),e.label]},e.value))})]}),(0,s.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,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-12 text-text-muted",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(sS,{}),(0,s.jsx)("div",{className:"absolute inset-0 bg-accent-cyan/10 rounded-full blur-xl"})]}),(0,s.jsx)("span",{className:"text-sm font-medium",children:"Loading trajectory..."})]}):0===p.length?(0,s.jsx)("div",{className:"flex flex-col gap-4 py-4 text-text-muted",children:0===r.length&&a.length>0?(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-text-secondary uppercase tracking-wider",children:"Recent Trajectories"}),o&&l&&(0,s.jsx)("button",{onClick:()=>l(null),className:"text-[10px] text-accent-cyan hover:underline",children:"← Back to current"})]}),(0,s.jsx)("div",{className:"flex flex-col gap-1",children:a.slice(0,10).map(e=>(0,s.jsxs)("button",{onClick:()=>null==l?void 0:l(e.id),className:"w-full text-left px-3 py-2.5 rounded-lg transition-all duration-200 border ".concat(o===e.id?"bg-blue-500/15 border-blue-500/40 text-text-primary":"bg-bg-tertiary/50 border-transparent hover:bg-bg-elevated/60 hover:border-border/40"),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)("span",{className:"text-[13px] font-medium text-text-primary truncate flex-1",children:e.title}),(0,s.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,s.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-text-dim",children:function(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),s=Math.floor(r/6e4),n=Math.floor(r/36e5),a=Math.floor(r/864e5);return s<1?"just now":s<60?"".concat(s,"m ago"):n<24?"".concat(n,"h ago"):a<7?"".concat(a,"d ago"):t.toLocaleDateString()}(e.startedAt)}),e.confidence&&(0,s.jsxs)("span",{className:"text-[10px] text-text-dim",children:["• ",Math.round(100*e.confidence),"% confidence"]})]}),e.summary&&(0,s.jsx)("p",{className:"text-[11px] text-text-muted mt-1 line-clamp-2",children:e.summary})]},e.id))})]}):0===r.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-8",children:[(0,s.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-elevated/50 flex items-center justify-center border border-border/30",children:(0,s.jsx)(sC,{})}),(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-secondary",children:"No steps recorded"}),(0,s.jsx)("p",{className:"text-xs text-text-dim mt-1",children:"Steps will appear here as the agent works"})]})]}):(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-8",children:[(0,s.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-elevated/50 flex items-center justify-center border border-border/30",children:(0,s.jsx)(sC,{})}),(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-secondary",children:"No matching steps"}),(0,s.jsx)("p",{className:"text-xs text-text-dim mt-1",children:'Try a different filter or select "All"'})]})]})}):(0,s.jsx)("div",{className:"flex flex-col gap-0.5",children:p.map((e,t)=>(0,s.jsx)(sh,{step:e,isExpanded:x.has(e.id),isLast:t===p.length-1,isFirst:0===t,compact:d,onToggle:()=>g(e.id),onClick:c?()=>c(e):void 0},e.id))})})]})}function sh(e){var t;let{step:r,isExpanded:n,isLast:a,isFirst:o=!1,compact:l=!1,onToggle:i,onClick:c}=e,d=new Date(r.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),x=function(e){switch(e){case"tool_call":return(0,s.jsx)(sf,{});case"decision":return(0,s.jsx)(sj,{});case"message":return(0,s.jsx)(sy,{});case"state_change":return(0,s.jsx)(sv,{});case"phase_transition":return(0,s.jsx)(sw,{});case"error":return(0,s.jsx)(sN,{});default:return null}}(r.type),u=function(e){switch(e){case"running":return"#ff6b35";case"success":return"#00ffc8";case"error":return"#ff4757";default:return null}}(r.status),m=sp(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,s.jsxs)("div",{className:"flex gap-3 group",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center w-7 relative",children:[!o&&(0,s.jsx)("div",{className:"absolute top-0 w-px h-2 transition-colors",style:{backgroundColor:m?"".concat(m,"40"):"var(--color-border)"}}),(0,s.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:u?"linear-gradient(135deg, ".concat(u,"40, ").concat(u,"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:u||m||h||"var(--color-border)",color:u||m||h||"var(--color-text-secondary)"},children:x}),!a&&(0,s.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,s.jsxs)("div",{className:"flex-1 min-w-0 pt-1 ".concat(a?"pb-1":"pb-3"),children:[(0,s.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(n?"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,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-[13px] font-medium text-text-primary truncate",children:r.title}),(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[void 0!==r.duration&&(0,s.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,s.jsx)("span",{className:"text-[10px] text-text-dim",children:d}),!l&&(0,s.jsx)(sk,{isExpanded:n})]})]}),n&&!l&&g&&(0,s.jsxs)("div",{className:"mt-2 ml-1 pl-3 border-l-2 border-border/30",children:[r.description&&(0,s.jsx)("p",{className:"text-[13px] text-text-secondary mb-3 leading-relaxed",children:r.description}),p&&(0,s.jsx)("div",{className:"bg-bg-elevated/50 rounded-lg p-3 mb-3 overflow-x-auto border border-border/20",children:(0,s.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,s.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,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),"View Details"]})]})]})]})}function sp(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 sg(){return(0,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-blue-500",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4",strokeLinecap:"round",strokeLinejoin:"round"})})}function sb(){return(0,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 sf(){return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 sj(){return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 sy(){return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 sv(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,s.jsx)("path",{d:"M9 12h6m-3-3v6"})]})}function sw(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("path",{d:"M12 6v6l4 2"})]})}function sN(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("circle",{cx:"12",cy:"16",r:"0.5",fill:"currentColor"})]})}function sk(e){let{isExpanded:t}=e;return(0,s.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,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function sC(){return(0,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-text-dim",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function sS(){return(0,s.jsx)("svg",{className:"animate-spin",width:"20",height:"20",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round",className:"text-accent"})})}function sL(e){let{decisions:t,onApprove:r,onReject:a,onDismiss:o,isProcessing:l={}}=e,[i,c]=(0,n.useState)(null),[d,x]=(0,n.useState)({}),u=(0,n.useMemo)(()=>{let e={critical:0,high:1,medium:2,low:3};return[...t].sort((t,r)=>{let s=e[t.priority]-e[r.priority];return 0!==s?s:new Date(t.timestamp).getTime()-new Date(r.timestamp).getTime()})},[t]),m=(0,n.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])),x(t=>{let r={...t};return delete r[e.id],r})};return 0===t.length?(0,s.jsxs)("div",{className:"decision-queue decision-queue-empty",children:[(0,s.jsx)(sE,{}),(0,s.jsx)("span",{children:"No pending decisions"})]}):(0,s.jsxs)("div",{className:"decision-queue",children:[(0,s.jsxs)("div",{className:"decision-queue-header",children:[(0,s.jsxs)("div",{className:"decision-queue-title",children:[(0,s.jsx)(sW,{}),(0,s.jsx)("span",{children:"Pending Decisions"}),(0,s.jsx)("span",{className:"decision-queue-count",children:t.length})]}),(0,s.jsxs)("div",{className:"decision-queue-summary",children:[m.critical&&(0,s.jsxs)("span",{className:"decision-priority-badge critical",children:[m.critical," critical"]}),m.high&&(0,s.jsxs)("span",{className:"decision-priority-badge high",children:[m.high," high"]})]})]}),(0,s.jsx)("div",{className:"decision-queue-list",children:u.map(e=>(0,s.jsx)(sA,{decision:e,isExpanded:i===e.id,isProcessing:l[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=>x(r=>({...r,[e.id]:t})),onDismiss:()=>null==o?void 0:o(e.id)},e.id))})]})}function sA(e){let{decision:t,isExpanded:r,isProcessing:n,rejectReason:o,onToggle:l,onApprove:i,onReject:c,onRejectReasonChange:d,onDismiss:x}=e,u=(0,a.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,s=t.getTime()-r.getTime();if(s<=0)return{text:"Expired",urgent:!0};let n=Math.floor(s/6e4);return n<5?{text:"".concat(n,"m left"),urgent:!0}:n<60?{text:"".concat(n,"m left"),urgent:!1}:{text:"".concat(Math.floor(n/60),"h left"),urgent:!1}}(t.expiresAt):null;return(0,s.jsxs)("div",{className:"decision-card ".concat(t.priority),children:[(0,s.jsxs)("div",{className:"decision-card-header",onClick:l,children:[(0,s.jsx)("div",{className:"decision-card-avatar",style:{backgroundColor:u.primary,color:u.text},children:(0,a.hP)(t.agentName)}),(0,s.jsxs)("div",{className:"decision-card-info",children:[(0,s.jsxs)("div",{className:"decision-card-title",children:[(0,s.jsx)("span",{className:"decision-card-agent",children:t.agentName}),(0,s.jsx)("span",{className:"decision-card-type",children:{approval:"Approval",choice:"Choice",confirmation:"Confirm",input:"Input"}[t.type]}),(0,s.jsx)(sM,{priority:t.priority})]}),(0,s.jsx)("div",{className:"decision-card-subtitle",children:t.title})]}),(0,s.jsxs)("div",{className:"decision-card-meta",children:[h&&(0,s.jsx)("span",{className:"decision-card-expires ".concat(h.urgent?"urgent":""),children:h.text}),(0,s.jsx)("span",{className:"decision-card-time",children:m}),(0,s.jsx)(sB,{isExpanded:r})]})]}),r&&(0,s.jsxs)("div",{className:"decision-card-body",children:[(0,s.jsx)("p",{className:"decision-card-desc",children:t.description}),t.context&&Object.keys(t.context).length>0&&(0,s.jsxs)("div",{className:"decision-card-context",children:[(0,s.jsx)("span",{className:"decision-card-context-label",children:"Context"}),(0,s.jsx)("pre",{children:JSON.stringify(t.context,null,2)})]}),"choice"===t.type&&t.options&&(0,s.jsx)("div",{className:"decision-card-options",children:t.options.map(e=>(0,s.jsxs)("button",{className:"decision-card-option",onClick:()=>i(e.id),disabled:n,children:[(0,s.jsx)("span",{className:"decision-option-label",children:e.label}),e.description&&(0,s.jsx)("span",{className:"decision-option-desc",children:e.description})]},e.id))}),"choice"!==t.type&&(0,s.jsxs)("div",{className:"decision-card-actions",children:[(0,s.jsxs)("button",{className:"decision-btn decision-btn-approve",onClick:()=>i(),disabled:n,children:[n?(0,s.jsx)(sT,{}):(0,s.jsx)(sE,{}),"confirmation"===t.type?"Confirm":"Approve"]}),(0,s.jsxs)("div",{className:"decision-reject-group",children:[(0,s.jsx)("input",{type:"text",className:"decision-reject-input",placeholder:"Reason (optional)",value:o,onChange:e=>d(e.target.value),disabled:n}),(0,s.jsxs)("button",{className:"decision-btn decision-btn-reject",onClick:c,disabled:n,children:[(0,s.jsx)(sD,{}),"Reject"]})]})]}),(0,s.jsx)("button",{className:"decision-card-dismiss",onClick:x,disabled:n,children:"Dismiss without action"})]})]})}function sM(e){let{priority:t}=e;return(0,s.jsx)("span",{className:"decision-priority-badge ".concat(t),children:t})}function sW(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function sE(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function sD(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function sB(e){let{isExpanded:t}=e;return(0,s.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,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function sT(){return(0,s.jsx)("svg",{className:"decision-spinner",width:"14",height:"14",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sR(e){var t;let{server:r,isSelected:n=!1,onClick:a,onReconnect:o,compact:l=!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 l?(0,s.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(n?"bg-bg-elevated border-accent-cyan":"","\n ").concat("offline"===r.status?"opacity-70":"","\n "),onClick:a,children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:i}}),(0,s.jsx)("span",{className:"flex-1 text-sm font-medium text-text-primary text-left",children:r.name}),(0,s.jsx)("span",{className:"text-xs text-text-muted bg-bg-tertiary px-1.5 py-0.5 rounded-full",children:r.agentCount})]}):(0,s.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(n?"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,s.jsxs)("div",{className:"flex items-start justify-between mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(sP,{}),(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:r.name}),r.region&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:r.region})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-xs font-medium",style:{color:i},children:[(0,s.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 ".concat("connecting"===r.status?"animate-pulse":""),style:{backgroundColor:i}}),(0,s.jsx)("span",{children:c})]})]}),(0,s.jsxs)("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(60px,1fr))] gap-3 mb-4",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsx)("span",{className:"text-lg font-semibold text-text-primary",children:r.agentCount}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Agents"})]}),void 0!==r.messageRate&&(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsxs)("span",{className:"text-lg font-semibold text-text-primary",children:[r.messageRate,"/s"]}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Messages"})]}),void 0!==r.latency&&(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsxs)("span",{className:"text-lg font-semibold text-text-primary",children:[r.latency,"ms"]}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Latency"})]}),void 0!==r.uptime&&(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.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,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Uptime"})]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between pt-3 border-t border-border-subtle",children:[(0,s.jsx)("span",{className:"text-[11px] text-text-muted font-mono",children:r.url}),r.version&&(0,s.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&&o&&(0,s.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(),o()},children:[(0,s.jsx)(s_,{}),"Reconnect"]})]})}function sP(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),(0,s.jsx)("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]})}function s_(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"23 4 23 10 17 10"}),(0,s.jsx)("polyline",{points:"1 20 1 14 7 14"}),(0,s.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 sI(e){let{servers:t,agents:r,selectedServerId:o,onServerSelect:l,onServerReconnect:i,isLoading:c=!1}=e,[d,x]=(0,n.useState)("grid"),u=(0,n.useMemo)(()=>{let e=t.filter(e=>"online"===e.status).length,r=t.reduce((e,t)=>e+t.agentCount,0),s=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,n=t.reduce((e,t)=>e+(t.messageRate||0),0);return{online:e,total:t.length,totalAgents:r,avgLatency:s,totalMessages:n}},[t]),m=(0,n.useMemo)(()=>{let e={};return t.forEach(t=>{e[t.id]=[]}),r.forEach((r,s)=>{let n=s%t.length;t[n]&&e[t[n].id].push(r)}),e},[t,r]);return c?(0,s.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,s.jsx)(sH,{}),(0,s.jsx)("span",{className:"mt-3 text-sm",children:"Loading fleet data..."})]}):0===t.length?(0,s.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,s.jsx)(sz,{}),(0,s.jsx)("h3",{className:"mt-4 mb-2 text-base font-semibold text-text-primary",children:"No Fleet Servers"}),(0,s.jsx)("p",{className:"text-sm",children:"Connect to peer servers to enable fleet view"})]}):(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg border border-border-subtle overflow-hidden",children:[(0,s.jsxs)("div",{className:"flex items-center gap-6 p-4 border-b border-border-subtle bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 font-semibold text-sm text-text-primary",children:[(0,s.jsx)(sF,{}),(0,s.jsx)("span",{children:"Fleet Overview"})]}),(0,s.jsxs)("div",{className:"flex gap-6 flex-1",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.online,"/",u.total]}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Servers"})]}),(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsx)("span",{className:"text-base font-semibold text-text-primary",children:u.totalAgents}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Agents"})]}),null!==u.avgLatency&&(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.avgLatency,"ms"]}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Avg Latency"})]}),(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.totalMessages,"/s"]}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Messages"})]})]}),(0,s.jsxs)("div",{className:"flex gap-1 bg-bg-tertiary rounded-md p-0.5",children:[(0,s.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"===d?"bg-bg-card text-text-primary shadow-sm":"text-text-muted hover:text-text-secondary"),onClick:()=>x("grid"),title:"Grid view",children:(0,s.jsx)(sU,{})}),(0,s.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"===d?"bg-bg-card text-text-primary shadow-sm":"text-text-muted hover:text-text-secondary"),onClick:()=>x("list"),title:"List view",children:(0,s.jsx)(sO,{})})]})]}),(0,s.jsx)("div",{className:"flex h-1 bg-bg-tertiary",children:t.map(e=>(0,s.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,s.jsx)("div",{className:"p-4 ".concat("grid"===d?"grid grid-cols-[repeat(auto-fill,minmax(280px,1fr))] gap-4":"flex flex-col gap-2"),children:t.map(e=>{var t;return(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)(sR,{server:e,isSelected:e.id===o,onClick:()=>null==l?void 0:l(e.id),onReconnect:()=>null==i?void 0:i(e.id),compact:"list"===d}),"grid"===d&&(null===(t=m[e.id])||void 0===t?void 0:t.length)>0&&(0,s.jsxs)("div",{className:"flex gap-1 px-2",children:[m[e.id].slice(0,5).map((e,t)=>{let r=(0,a.GW)(e.name);return(0,s.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,a.hP)(e.name)},e.name)}),m[e.id].length>5&&(0,s.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 sF(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function sU(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"7",height:"7"}),(0,s.jsx)("rect",{x:"14",y:"3",width:"7",height:"7"}),(0,s.jsx)("rect",{x:"3",y:"14",width:"7",height:"7"}),(0,s.jsx)("rect",{x:"14",y:"14",width:"7",height:"7"})]})}function sO(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"8",y1:"6",x2:"21",y2:"6"}),(0,s.jsx)("line",{x1:"8",y1:"12",x2:"21",y2:"12"}),(0,s.jsx)("line",{x1:"8",y1:"18",x2:"21",y2:"18"}),(0,s.jsx)("line",{x1:"3",y1:"6",x2:"3.01",y2:"6"}),(0,s.jsx)("line",{x1:"3",y1:"12",x2:"3.01",y2:"12"}),(0,s.jsx)("line",{x1:"3",y1:"18",x2:"3.01",y2:"18"})]})}function sz(){return(0,s.jsxs)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,s.jsx)("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),(0,s.jsx)("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]})}function sH(){return(0,s.jsx)("svg",{className:"animate-spin",width:"24",height:"24",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sV(e){let{typingUsers:t}=e;return 0===t.length?null:(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 text-sm text-[#8d8d8e]",children:[(0,s.jsx)("div",{className:"flex -space-x-1.5",children:t.slice(0,3).map(e=>(0,s.jsx)("div",{className:"relative",title:e.username,children:e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-5 h-5 rounded-full border border-[#1a1d21]"}):(0,s.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,s.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,s.jsxs)("span",{className:"flex gap-0.5",children:[(0,s.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"0ms"}}),(0,s.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"150ms"}}),(0,s.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})]})]})}function sG(e){let{onlineUsers:t,onUserClick:r,maxAvatars:a=4}=e,[o,l]=(0,n.useState)(!1),i=(0,n.useRef)(null);if((0,n.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&l(!1)};return o&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[o]),0===t.length)return null;let c=t.slice(0,a),d=Math.max(0,t.length-a);return(0,s.jsxs)("div",{className:"relative",ref:i,children:[(0,s.jsxs)("button",{onClick:()=>l(!o),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,s.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,s.jsxs)("div",{className:"flex -space-x-1.5",children:[c.map(e=>(0,s.jsx)("div",{className:"relative ring-2 ring-[#1a1d21] rounded-full",title:e.username,children:e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-6 h-6 rounded-full object-cover"}):(0,s.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,s.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,s.jsxs)("span",{className:"text-xs text-[#8d8d8e]",children:[t.length," online"]})]}),o&&(0,s.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,s.jsx)("div",{className:"p-2 border-b border-white/10",children:(0,s.jsx)("h3",{className:"text-sm font-medium text-[#d1d2d3]",children:"Online Users"})}),(0,s.jsx)("div",{className:"py-1",children:t.map(e=>(0,s.jsxs)("button",{onClick:()=>{null==r||r(e),l(!1)},className:"w-full flex items-center gap-3 px-3 py-2 hover:bg-white/[0.05] transition-colors text-left",children:[(0,s.jsxs)("div",{className:"relative",children:[e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-8 h-8 rounded-full object-cover"}):(0,s.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,s.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 bg-green-500 rounded-full border-2 border-[#1a1d21]"})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"text-sm font-medium text-[#d1d2d3] truncate",children:e.username}),(0,s.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 sK(e){let{user:t,onClose:r,onMention:a,onSendMessage:o}=e,l=(0,n.useRef)(null);(0,n.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return t&&window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,r]);let i=(0,n.useRef)(!1);if((0,n.useEffect)(()=>{t&&(i.current=!0)},[t]),(0,n.useEffect)(()=>{let e=e=>{if(i.current){i.current=!1;return}l.current&&!l.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,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40"}),(0,s.jsxs)("div",{ref:l,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,s.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-[#d1d2d3]",children:"Profile"}),(0,s.jsx)("button",{onClick:r,className:"p-1 hover:bg-white/10 rounded-md transition-colors",title:"Close",children:(0,s.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),(0,s.jsxs)("div",{className:"flex flex-col items-center p-6 border-b border-white/10",children:[(0,s.jsxs)("div",{className:"relative mb-4",children:[t.avatarUrl?(0,s.jsx)("img",{src:t.avatarUrl,alt:t.username,className:"w-24 h-24 rounded-full object-cover border-4 border-[#a855f7]/30"}):(0,s.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,s.jsx)("div",{className:"absolute bottom-1 right-1 w-5 h-5 bg-green-500 rounded-full border-4 border-[#1a1d21]"})]}),(0,s.jsx)("h3",{className:"text-xl font-semibold text-[#d1d2d3] mb-1",children:t.username}),(0,s.jsxs)("span",{className:"text-sm text-green-400 flex items-center gap-1.5",children:[(0,s.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),"Online"]})]}),(0,s.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Online Since"}),(0,s.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sZ(t.connectedAt)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Last Active"}),(0,s.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sZ(t.lastSeen)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"GitHub"}),(0,s.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,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.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,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14L21 3"})})]})]})]})}),(0,s.jsxs)("div",{className:"p-4 border-t border-white/10 space-y-2",children:[(0,s.jsxs)("button",{onClick:()=>{null==o||o(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,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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,s.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,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,s.jsx)("path",{d:"M16 8v5a3 3 0 006 0v-1a10 10 0 10-3.92 7.94"})]}),"Mention @",t.username]}),(0,s.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,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.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 sZ(e){return new Date(e).toLocaleString([],{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}function sq(e){let{user:t,onClose:r,messages:a,agents:o,humanUsers:l,onSend:i,onTyping:c,isSending:d,sendError:x,currentUser:u}=e,[m,h]=(0,n.useState)(!0),[p,g]=(0,n.useState)([]),[b,f]=(0,n.useState)(""),j=(0,n.useMemo)(()=>{if(null==u?void 0:u.displayName)return u.displayName;if(!t)return null;for(let e of a){if(e.to===t.username&&e.from!==t.username)return e.from;if(e.from===t.username&&e.to&&e.to!==t.username)return e.to}return null},[null==u?void 0:u.displayName,a,t]),y=(0,n.useMemo)(()=>{let e=new Set(o.map(e=>e.name)),r=new Set;for(let t of a)e.has(t.from)&&r.add(t.from),e.has(t.to)&&r.add(t.to);return t&&r.delete(t.username),u&&r.delete(u.displayName),Array.from(r)},[o,a,t,u]);(0,n.useEffect)(()=>{g(e=>Array.from(new Set([...e,...y])))},[y]);let v=(0,n.useMemo)(()=>Array.from(new Set([...p,...y])),[p,y]),w=(0,n.useMemo)(()=>{if(!t)return[];let e=new Set;return e.add(t.username),j&&e.add(j),v.forEach(t=>e.add(t)),a.filter(t=>!!t.from&&!!t.to&&e.has(t.from)&&e.has(t.to))},[a,v,j,t]),N=(0,n.useMemo)(()=>{let e=new Set,t=new Map;return w.filter(r=>{var s,n,a,o,l;let i=new Date(r.timestamp).getTime();if(r.id){if(e.has(r.id))return!1;e.add(r.id)}let c="".concat(null!==(a=null===(s=r.from)||void 0===s?void 0:s.toLowerCase())&&void 0!==a?a:"","::").concat(null!==(o=null===(n=r.to)||void 0===n?void 0:n.toLowerCase())&&void 0!==o?o:"","::").concat(null!==(l=r.thread)&&void 0!==l?l:"","::").concat(r.content),d=t.get(c);return!(void 0!==d&&3e4>Math.abs(i-d))&&(void 0===d&&t.set(c,i),!0)})},[w]),k=(0,n.useMemo)(()=>(null==t?void 0:t.username)||"",[t]),C=(0,n.useCallback)(e=>{g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),S=(0,n.useMemo)(()=>{let e=b.trim().toLowerCase();return o.filter(t=>!!v.includes(t.name)||!e||t.name.toLowerCase().includes(e))},[o,b,v]),L=(0,n.useCallback)(async(e,r)=>{if(p.length>0){for(let e of(await i(t.username,r),p))await i(e,r);return!0}return i(e,r)},[p,t,i]);return t?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 z-50",onClick:r}),(0,s.jsxs)("div",{className:"fixed inset-4 md:inset-x-auto md:inset-y-8 md:left-1/2 md:-translate-x-1/2 md:w-full md:max-w-3xl bg-bg-primary border border-border-subtle rounded-xl shadow-2xl z-50 flex flex-col overflow-hidden",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border-subtle bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[t.avatarUrl?(0,s.jsx)("img",{src:t.avatarUrl,alt:t.username,className:"w-8 h-8 rounded-full object-cover"}):(0,s.jsx)("div",{className:"w-8 h-8 rounded-full bg-accent-purple flex items-center justify-center text-sm text-white font-medium",children:t.username.charAt(0).toUpperCase()}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-base font-semibold text-text-primary",children:p.length>0?"Group Message":"Direct Message"}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:p.length>0?"".concat(t.username,", ").concat(p.join(", ")):t.username})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("button",{onClick:()=>h(!m),className:"px-3 py-1.5 text-xs font-medium rounded-lg transition-colors ".concat(m?"bg-accent-cyan text-bg-deep":"bg-bg-tertiary text-text-secondary hover:bg-bg-tertiary/80"),title:"Invite agents to this conversation",children:[(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"inline mr-1",children:[(0,s.jsx)("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("line",{x1:"19",y1:"8",x2:"19",y2:"14"}),(0,s.jsx)("line",{x1:"22",y1:"11",x2:"16",y2:"11"})]}),p.length>0?"".concat(p.length," Agents"):"Invite Agents"]}),(0,s.jsx)("button",{onClick:r,className:"p-1.5 hover:bg-bg-tertiary rounded-md transition-colors text-text-muted hover:text-text-primary",title:"Close",children:(0,s.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]})]}),m&&(0,s.jsxs)("div",{className:"border-b border-border-subtle bg-bg-secondary p-3 space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("p",{className:"text-xs text-text-muted m-0 flex-1",children:"Invite agents to this conversation"}),(0,s.jsx)("input",{type:"text",value:b,onChange:e=>f(e.target.value),placeholder:"Search agents...",className:"text-xs px-2 py-1 bg-bg-tertiary border border-border-subtle rounded-md text-text-primary flex-1"})]}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[S.map(e=>(0,s.jsxs)("button",{onClick:()=>C(e.name),className:"px-3 py-1.5 text-xs font-medium rounded-lg transition-colors ".concat(p.includes(e.name)?"bg-accent-cyan text-bg-deep":"bg-bg-tertiary text-text-secondary hover:bg-bg-tertiary/80"),title:e.name,children:[p.includes(e.name)?"✓ ":"",e.name]},e.name)),0===S.length&&(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:['No agents match "',b,'"']})]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto min-h-0 p-4 space-y-3",children:N.length>0?N.map(e=>{let t=u&&e.from===u.displayName,r=p.includes(e.from);return(0,s.jsx)("div",{className:"flex ".concat(t?"justify-end":"justify-start"),children:(0,s.jsxs)("div",{className:"max-w-[80%] rounded-lg px-3 py-2 ".concat(t?"bg-accent-cyan text-bg-deep":r?"bg-accent-purple/20 text-text-primary border border-accent-purple/30":"bg-bg-tertiary text-text-primary"),children:[!t&&(0,s.jsx)("div",{className:"text-xs font-medium mb-1 opacity-70",children:e.from}),(0,s.jsx)("div",{className:"text-sm whitespace-pre-wrap break-words",children:e.content}),(0,s.jsx)("div",{className:"text-[10px] mt-1 opacity-60",children:new Date(e.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})},e.id)}):(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted text-center px-4",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"mx-auto mb-3 opacity-40",children:(0,s.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,s.jsx)("p",{className:"text-sm",children:"No messages yet"}),(0,s.jsxs)("p",{className:"text-xs mt-1",children:["Send a message to start the conversation",p.length>0&&" with ".concat(t.username," and ").concat(p.join(", "))]})]})})}),(0,s.jsx)(sJ,{recipient:k,onSend:L,isSending:d,error:x})]})]}):null}function sJ(e){let{recipient:t,onSend:r,isSending:a,error:o}=e,[l,i]=(0,n.useState)(""),c=(0,n.useCallback)(async e=>{e.preventDefault(),l.trim()&&!a&&await r(t,l.trim())&&i("")},[l,t,r,a]);return(0,s.jsxs)("div",{className:"border-t border-border-subtle bg-bg-secondary p-3",children:[o&&(0,s.jsx)("div",{className:"mb-2 text-xs text-error bg-error/10 px-2 py-1 rounded",children:o}),(0,s.jsxs)("form",{onSubmit:c,className:"flex gap-2",children:[(0,s.jsx)("input",{type:"text",value:l,onChange:e=>i(e.target.value),placeholder:"Type a message...",disabled:a,className:"flex-1 bg-bg-tertiary text-text-primary px-3 py-2 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-accent-cyan disabled:opacity-50"}),(0,s.jsx)("button",{type:"submit",disabled:!l.trim()||a,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 disabled:cursor-not-allowed transition-colors",children:a?"Sending...":"Send"})]})]})}function sY(e){let{isOpen:t,onClose:r,projects:a,isCloudMode:o=!1,hasArchitect:l=!1,onArchitectSpawned:i}=e,[c,d]=(0,n.useState)([]),[x,u]=(0,n.useState)([]),[m,h]=(0,n.useState)(!1),[p,g]=(0,n.useState)(null),[b,f]=(0,n.useState)(!1),[j,y]=(0,n.useState)(""),[v,w]=(0,n.useState)(""),[N,k]=(0,n.useState)(new Set),[C,S]=(0,n.useState)(!1),[L,A]=(0,n.useState)("claude"),[M,W]=(0,n.useState)(null),[E,D]=(0,n.useState)(null),[B,T]=(0,n.useState)(new Set);(0,n.useEffect)(()=>{t&&o&&R()},[t,o]);let R=async()=>{h(!0),g(null);try{let e=await fetch("/api/project-groups");if(e.ok){let t=await e.json();d(t.groups||[]),u(t.ungroupedRepositories||[])}else{let t=await e.json().catch(()=>({}));g(t.error||"Failed to load project groups")}}catch(e){g("Failed to load project groups")}finally{h(!1)}},P=async()=>{if(j.trim()&&0!==N.size){h(!0),g(null);try{let e=await fetch("/api/project-groups",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:j.trim(),description:v.trim()||void 0,repositoryIds:Array.from(N)})});if(e.ok){let t=await e.json();t.group&&(d(e=>[...e,t.group]),u(e=>e.filter(e=>!N.has(e.id))),f(!1),y(""),w(""),k(new Set))}else{let t=await e.json().catch(()=>({}));g(t.error||"Failed to create project group")}}catch(e){g("Failed to create project group")}finally{h(!1)}}},_=async(e,t)=>{g(null);try{let r=await fetch("/api/project-groups/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(r.ok){let t=await r.json();t.group&&(d(r=>r.map(r=>r.id===e?{...r,...t.group}:r)),W(null))}else{let e=await r.json().catch(()=>({}));g(e.error||"Failed to update project group")}}catch(e){g("Failed to update project group")}},I=async(e,t)=>{g(null);try{let r="/api/project-groups/".concat(e,"/coordinator/").concat(t?"enable":"disable"),s=await fetch(r,{method:"POST"});if(s.ok){let r=await s.json();d(s=>s.map(s=>{var n,a;return s.id===e?{...s,coordinatorAgent:{...s.coordinatorAgent,enabled:t,name:(null===(n=r.coordinator)||void 0===n?void 0:n.name)||(null===(a=s.coordinatorAgent)||void 0===a?void 0:a.name)}}:s}))}else{let e=await s.json().catch(()=>({}));g(e.error||"Failed to ".concat(t?"enable":"disable"," coordinator"))}}catch(e){g("Failed to ".concat(t?"enable":"disable"," coordinator"))}},F=async e=>{if(window.confirm("Delete this project group? The coordinator will be stopped and repositories will be ungrouped."))try{let t=c.find(t=>t.id===e),r=await fetch("/api/project-groups/".concat(e),{method:"DELETE"});if(r.ok)d(t=>t.filter(t=>t.id!==e)),(null==t?void 0:t.repositories)&&u(e=>[...e,...t.repositories]);else{let e=await r.json().catch(()=>({}));g(e.error||"Failed to delete project group")}}catch(e){g("Failed to delete project group")}},U=async(e,t)=>{try{let r=await fetch("/api/project-groups/".concat(e,"/repositories/").concat(t),{method:"DELETE"});if(r.ok){let r=c.find(t=>t.id===e),s=null==r?void 0:r.repositories.find(e=>e.id===t);d(r=>r.map(r=>r.id===e?{...r,repositories:r.repositories.filter(e=>e.id!==t),repositoryCount:r.repositoryCount-1}:r)),s&&u(e=>[...e,s])}else{let e=await r.json().catch(()=>({}));g(e.error||"Failed to remove repository from group")}}catch(e){g("Failed to remove repository from group")}},O=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"},body:JSON.stringify({repositoryIds:t})});if(r.ok)await R(),D(null),T(new Set);else{let e=await r.json().catch(()=>({}));g(e.error||"Failed to add repositories to group")}}catch(e){g("Failed to add repositories to group")}},z=e=>{T(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},H=e=>{k(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};if(!t)return null;let V=async()=>{S(!0),g(null);try{let e=await fetch("/api/spawn/architect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cli:L})}),t=await e.json();e.ok&&t.success?(null==i||i(),r()):g(t.error||"Failed to spawn Architect")}catch(e){g("Failed to spawn Architect")}finally{S(!1)}};if(!o){let e=a.length>1;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between py-5 px-6 border-b border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(sQ,{}),(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Coordinator Agent"})]}),(0,s.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,s.jsx)(s0,{})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[p&&(0,s.jsx)("div",{className:"bg-error/10 border border-error/30 rounded-lg p-3 mb-4 text-error text-sm",children:p}),e&&(0,s.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,s.jsxs)("h3",{className:"text-sm font-semibold text-text-primary mb-3 flex items-center gap-2",children:[(0,s.jsx)(sQ,{}),"Spawn Architect"]}),l?(0,s.jsxs)("div",{className:"flex items-center gap-2 text-sm text-success",children:[(0,s.jsx)(s3,{}),"Architect is running"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("p",{className:"text-sm text-text-secondary mb-4",children:["Spawn an Architect agent to coordinate across your ",a.length," connected projects."]}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.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:L,onChange:e=>A(e.target.value),children:[(0,s.jsx)("option",{value:"claude",children:"Claude (default)"}),(0,s.jsx)("option",{value:"claude:opus",children:"Claude Opus"}),(0,s.jsx)("option",{value:"claude:sonnet",children:"Claude Sonnet"}),(0,s.jsx)("option",{value:"codex",children:"Codex"})]}),(0,s.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:V,disabled:C,children:C?"Spawning...":"Spawn"})]})]})]}),!e&&(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 mb-4 border border-border-subtle",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-primary mb-2",children:"Not in Bridge Mode"}),(0,s.jsx)("p",{className:"text-sm text-text-secondary",children:"The Architect coordinates multiple projects. Start bridge mode to enable:"}),(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg p-3 font-mono text-sm mt-3",children:[(0,s.jsx)("span",{className:"text-text-muted",children:"$"})," ",(0,s.jsx)("span",{className:"text-accent-cyan",children:"relay bridge"})," ",(0,s.jsx)("span",{className:"text-accent-orange",children:"~/project1 ~/project2"})]})]}),(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 mb-4",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-primary mb-2",children:"CLI Alternative"}),(0,s.jsxs)("p",{className:"text-sm text-text-secondary mb-3",children:["You can also spawn the Architect via CLI with the ",(0,s.jsx)("code",{className:"bg-bg-card px-1.5 py-0.5 rounded text-accent-cyan",children:"--architect"})," flag:"]}),(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg p-3 font-mono text-sm",children:[(0,s.jsx)("span",{className:"text-text-muted",children:"$"})," ",(0,s.jsx)("span",{className:"text-accent-cyan",children:"relay bridge"})," ",(0,s.jsx)("span",{className:"text-accent-orange",children:"~/project1 ~/project2"})," ",(0,s.jsx)("span",{className:"text-accent-purple",children:"--architect"})]})]})]}),(0,s.jsx)("div",{className:"flex justify-end py-4 px-6 border-t border-border-subtle",children:(0,s.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,s.jsx)("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between py-5 px-6 border-b border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(sQ,{}),(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Coordinator Agents"})]}),(0,s.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,s.jsx)(s0,{})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[p&&(0,s.jsx)("div",{className:"bg-error/10 border border-error/30 rounded-lg p-3 mb-4 text-error text-sm",children:p}),m&&0===c.length?(0,s.jsx)("div",{className:"flex items-center justify-center py-12 text-text-muted",children:(0,s.jsx)(sX,{})}):(0,s.jsxs)(s.Fragment,{children:[c.length>0&&(0,s.jsxs)("div",{className:"space-y-3 mb-6",children:[(0,s.jsx)("h4",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Project Groups"}),c.map(e=>{var t,r,n,a;return(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-text-primary",children:e.name}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:[e.repositoryCount," ",1===e.repositoryCount?"repo":"repos"]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{className:"text-text-muted hover:text-accent-cyan transition-colors p-1",onClick:()=>W(e),title:"Edit group",children:(0,s.jsx)(s1,{})}),(0,s.jsx)("button",{className:"text-text-muted hover:text-error transition-colors p-1",onClick:()=>F(e.id),title:"Delete group",children:(0,s.jsx)(s5,{})})]})]}),e.repositories.length>0&&(0,s.jsx)("div",{className:"mb-3 space-y-1",children:e.repositories.map(t=>(0,s.jsxs)("div",{className:"flex items-center justify-between py-1 px-2 bg-bg-card/50 rounded text-xs",children:[(0,s.jsx)("span",{className:"text-text-secondary font-mono",children:t.githubFullName}),(0,s.jsx)("button",{className:"text-text-muted hover:text-error transition-colors p-0.5",onClick:()=>U(e.id,t.id),title:"Remove from group",children:(0,s.jsx)(s0,{size:12})})]},t.id))}),e.description&&(0,s.jsx)("p",{className:"text-xs text-text-muted mb-3",children:e.description}),E===e.id?(0,s.jsxs)("div",{className:"mb-3 p-3 bg-bg-card rounded-lg border border-border-subtle",children:[(0,s.jsx)("div",{className:"text-xs font-medium text-text-muted mb-2",children:"Select repositories to add:"}),(0,s.jsx)("div",{className:"space-y-1 max-h-[150px] overflow-y-auto mb-3",children:x.length>0?x.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-2 p-1.5 rounded cursor-pointer hover:bg-bg-hover",children:[(0,s.jsx)("input",{type:"checkbox",className:"accent-accent-cyan",checked:B.has(e.id),onChange:()=>z(e.id)}),(0,s.jsx)("span",{className:"text-xs text-text-primary font-mono",children:e.githubFullName})]},e.id)):(0,s.jsx)("p",{className:"text-xs text-text-muted py-2 text-center",children:"No ungrouped repositories available"})}),(0,s.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,s.jsx)("button",{className:"py-1 px-3 text-xs bg-transparent border border-border-subtle rounded text-text-secondary hover:bg-bg-hover",onClick:()=>{D(null),T(new Set)},children:"Cancel"}),(0,s.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:()=>O(e.id,Array.from(B)),disabled:0===B.size,children:"Add Selected"})]})]}):x.length>0?(0,s.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:()=>{D(e.id),T(new Set)},children:[(0,s.jsx)(s2,{}),"Add repositories"]}):null,(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(s$,{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,s.jsx)("span",{className:"text-sm text-text-secondary",children:e.coordinatorAgent.name})]}),(0,s.jsxs)("button",{className:"py-1.5 px-3 rounded-md text-xs font-medium transition-colors ".concat((null===(n=e.coordinatorAgent)||void 0===n?void 0:n.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&&I(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)})]}),M&&(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-accent-cyan/30 mb-4",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary mb-4",children:"Edit Project Group"}),(0,s.jsx)(s6,{group:M,onSave:e=>_(M.id,e),onCancel:()=>W(null)})]}),b?(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-accent-cyan/30",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary mb-4",children:"Create Project Group"}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Group Name"}),(0,s.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:j,onChange:e=>y(e.target.value)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Description (optional)"}),(0,s.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:v,onChange:e=>w(e.target.value)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Select Repositories"}),(0,s.jsxs)("div",{className:"space-y-2 max-h-[200px] overflow-y-auto",children:[x.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-2 p-2 bg-bg-card rounded-md cursor-pointer hover:bg-bg-hover",children:[(0,s.jsx)("input",{type:"checkbox",className:"accent-accent-cyan",checked:N.has(e.id),onChange:()=>H(e.id)}),(0,s.jsx)("span",{className:"text-sm text-text-primary font-mono",children:e.githubFullName}),e.isPrivate&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:"\uD83D\uDD12"})]},e.id)),0===x.length&&(0,s.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,s.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,s.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:()=>{f(!1),y(""),w(""),k(new Set)},children:"Cancel"}),(0,s.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:P,disabled:!j.trim()||0===N.size||m,children:m?"Creating...":"Create Group"})]})]})]}):(0,s.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:()=>f(!0),disabled:!!M,children:[(0,s.jsx)(s2,{}),"Create Project Group"]}),(0,s.jsxs)("div",{className:"mt-6 p-4 bg-bg-tertiary/50 rounded-lg border border-border-subtle",children:[(0,s.jsxs)("h4",{className:"text-sm font-semibold text-text-primary mb-2 flex items-center gap-2",children:[(0,s.jsx)(s4,{}),"What is a Coordinator?"]}),(0,s.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 s$(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,s.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium ".concat(r[t]||r.stopped),children:t})}function sX(){return(0,s.jsx)("svg",{className:"animate-spin h-6 w-6 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sQ(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function s0(e){let{size:t=20}=e;return(0,s.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function s1(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.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,s.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 s2(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function s5(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.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 s4(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function s3(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"text-success",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function s6(e){let{group:t,onSave:r,onCancel:a}=e,[o,l]=(0,n.useState)(t.name),[i,c]=(0,n.useState)(t.description||"");return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Group Name"}),(0,s.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:o,onChange:e=>l(e.target.value)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Description"}),(0,s.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,s.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,s.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,s.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={};o.trim()!==t.name&&(e.name=o.trim()),i.trim()!==(t.description||"")&&(e.description=i.trim()),Object.keys(e).length>0?r(e):a()},disabled:!o.trim(),children:"Save Changes"})]})]})}function s8(){let e=(0,n.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,s.jsxs)("div",{className:"fixed inset-0 pointer-events-none overflow-hidden z-50",children:[e.map(e=>(0,s.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,s.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 s9(){return(0,s.jsxs)("div",{className:"relative w-20 h-20",children:[(0,s.jsx)("div",{className:"absolute inset-0 rounded-full bg-gradient-to-r from-emerald-400 to-cyan-400 opacity-20 animate-pulse-slow"}),(0,s.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,s.jsx)("div",{className:"w-full h-full rounded-full bg-bg-primary flex items-center justify-center",children:(0,s.jsxs)("svg",{className:"w-10 h-10",viewBox:"0 0 24 24",fill:"none",children:[(0,s.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,s.jsx)("defs",{children:(0,s.jsxs)("linearGradient",{id:"check-gradient",x1:"5",y1:"12",x2:"19",y2:"7",children:[(0,s.jsx)("stop",{stopColor:"#34d399"}),(0,s.jsx)("stop",{offset:"1",stopColor:"#22d3ee"})]})})]})})}),(0,s.jsx)("div",{className:"absolute -top-1 -right-1 w-3 h-3 bg-yellow-400 rounded-full animate-sparkle",style:{animationDelay:"0.5s"}}),(0,s.jsx)("div",{className:"absolute top-0 -left-2 w-2 h-2 bg-cyan-400 rounded-full animate-sparkle",style:{animationDelay:"0.7s"}}),(0,s.jsx)("div",{className:"absolute -bottom-1 right-2 w-2 h-2 bg-emerald-400 rounded-full animate-sparkle",style:{animationDelay:"0.9s"}}),(0,s.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 s7(){return(0,s.jsxs)("div",{className:"relative w-20 h-20",children:[(0,s.jsx)("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent-cyan border-r-accent-cyan/50 animate-spin"}),(0,s.jsx)("div",{className:"absolute inset-3 rounded-full bg-gradient-to-br from-accent-cyan/20 to-transparent animate-pulse"}),(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)("div",{className:"w-3 h-3 rounded-full bg-accent-cyan animate-ping"})}),(0,s.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"3s"},children:(0,s.jsx)("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 w-2 h-2 rounded-full bg-accent-cyan/80"})}),(0,s.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"4s",animationDirection:"reverse"},children:(0,s.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 ne(e){let{children:t,delay:r}=e;return(0,s.jsxs)("li",{className:"flex items-center gap-3 opacity-0 animate-slide-in-left",style:{animationDelay:"".concat(r,"s"),animationFillMode:"forwards"},children:[(0,s.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,s.jsx)("svg",{className:"w-3 h-3 text-white",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:(0,s.jsx)("path",{d:"M20 6L9 17l-5-5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,s.jsx)("span",{className:"text-text-secondary",children:t}),(0,s.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 nt(e){let{type:t,sessionId:r,onClose:a}=e,[o,l]=(0,n.useState)(null),[i,c]=(0,n.useState)("success"===t),[d,x]=(0,n.useState)(null),[u,m]=(0,n.useState)(!1);(0,n.useEffect)(()=>{"success"===t&&(async()=>{try{await new Promise(e=>setTimeout(e,1500));let r=await ei.xv.getSubscription();if(r.success&&r.data){var e,t;l({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(()=>m(!0),200)}}catch(e){x("Could not verify subscription. Please check your billing settings.")}finally{c(!1)}})()},[t,r]);let h=(null==o?void 0:o.plan)==="pro"?"Pro":(null==o?void 0:o.plan)==="team"?"Team":(null==o?void 0:o.plan)==="enterprise"?"Enterprise":"Premium";return"success"===t?(0,s.jsxs)("div",{className:"min-h-screen bg-bg-deep flex items-center justify-center p-4 overflow-hidden",children:[(0,s.jsxs)("div",{className:"fixed inset-0 overflow-hidden pointer-events-none",children:[(0,s.jsx)("div",{className:"absolute top-1/4 -left-32 w-96 h-96 bg-accent-cyan/10 rounded-full blur-3xl animate-float"}),(0,s.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"}})]}),u&&(0,s.jsx)(s8,{}),(0,s.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,s.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,s.jsxs)("div",{className:"py-8",children:[(0,s.jsx)("div",{className:"flex justify-center mb-8",children:(0,s.jsx)(s7,{})}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3 tracking-tight",children:"Processing your upgrade"}),(0,s.jsx)("p",{className:"text-text-muted",children:"Confirming your subscription..."})]}):d?(0,s.jsxs)("div",{className:"py-4",children:[(0,s.jsx)("div",{className:"w-16 h-16 mx-auto mb-6 rounded-full bg-amber-500/20 flex items-center justify-center",children:(0,s.jsxs)("svg",{className:"w-8 h-8 text-amber-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3",children:"Almost there!"}),(0,s.jsx)("p",{className:"text-text-muted mb-8",children:d}),(0,s.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,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex justify-center mb-6",children:(0,s.jsx)(s9,{})}),(0,s.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 ",h,"!"]}),(0,s.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,s.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,s.jsx)("h3",{className:"text-xs font-bold text-accent-cyan uppercase tracking-wider mb-4",children:"Your new powers"}),(0,s.jsxs)("ul",{className:"space-y-3 text-sm",children:[(0,s.jsx)(ne,{delay:.8,children:"Expanded workspace & repository limits"}),(0,s.jsx)(ne,{delay:.9,children:"More compute hours for your agents"}),(0,s.jsx)(ne,{delay:1,children:"Increased concurrent agent capacity"}),(0,s.jsx)(ne,{delay:1.1,children:"Priority support & faster responses"})]})]}),(0,s.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,s.jsxs)("span",{className:"flex items-center justify-center gap-2",children:["Launch Dashboard",(0,s.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,s.jsx)("path",{d:"M5 12h14M12 5l7 7-7 7",strokeLinecap:"round",strokeLinejoin:"round"})})]})})]})]}),(0,s.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,s.jsxs)("div",{className:"min-h-screen bg-bg-deep flex items-center justify-center p-4",children:[(0,s.jsx)("div",{className:"fixed inset-0 overflow-hidden pointer-events-none",children:(0,s.jsx)("div",{className:"absolute top-1/3 left-1/4 w-64 h-64 bg-text-muted/5 rounded-full blur-3xl"})}),(0,s.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,s.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,s.jsx)("svg",{className:"w-7 h-7 text-text-muted",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3",children:"No problem!"}),(0,s.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,s.jsxs)("div",{className:"space-y-3",children:[(0,s.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,s.jsxs)("span",{className:"flex items-center justify-center gap-2",children:["Return to Dashboard",(0,s.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,s.jsx)("path",{d:"M5 12h14M12 5l7 7-7 7",strokeLinecap:"round",strokeLinejoin:"round"})})]})}),(0,s.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,s.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 nr(e){let{apiBaseUrl:t="",onUpgradeClick:r}=e,[a,o]=(0,n.useState)(null),[l,i]=(0,n.useState)(!0),[c,d]=(0,n.useState)(null),[x,u]=(0,n.useState)(!1);if((0,n.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();o(r)}catch(e){d(e instanceof Error?e.message:"Unknown error")}finally{i(!1)}}e();let r=setInterval(e,3e5);return()=>clearInterval(r)},[t]),l||c||!a||"free"!==a.plan||x)return null;let{computeHoursThisMonth:m}=a.usage,{computeHoursPerMonth:h}=a.limits,p=a.percentUsed.computeHours,g=Math.max(0,h-m),b=g<=0,f=p>=80&&!b,j=a.introBonus,y=(null==j?void 0:j.isActive)&&j.daysRemaining>0,v=new Date().toLocaleDateString("en-US",{month:"long"}),w="bg-bg-tertiary border-border-subtle",N="text-text-secondary",k="text-accent-cyan";return b?(w="bg-error/10 border-error/30",N="text-error",k="text-error"):f?(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,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b ".concat(w),children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[y?(0,s.jsx)(na,{className:k}):(0,s.jsx)(ns,{className:k}),(0,s.jsx)("span",{className:"text-sm ".concat(N),children:b?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("strong",{children:"Compute limit reached"})," — Your free tier compute hours for ",v," have been used. Workspaces are paused until next month."]}):f?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("strong",{children:[g.toFixed(1),"h remaining"]})," — You've used ",p,"% of your free tier compute hours for ",v,"."]}):y?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("strong",{children:"Intro Bonus Active"})," — ",j.resources.cpus," CPU / ",j.resources.memoryGb,"GB RAM."," ",(0,s.jsxs)("span",{className:"text-text-secondary",children:[j.daysRemaining," day",1!==j.daysRemaining?"s":""," remaining before auto-resize to 1 CPU / 2GB."]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("strong",{children:[g.toFixed(1)," of ",h,"h"]})," compute hours remaining this month"]})})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(b||f||y)&&(0,s.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"}),!b&&(0,s.jsx)("button",{onClick:()=>u(!0),className:"p-1 text-text-muted hover:text-text-primary transition-colors","aria-label":"Dismiss",children:(0,s.jsx)(nn,{})})]})]})}function ns(e){let{className:t}=e;return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function nn(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function na(e){let{className:t}=e;return(0,s.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,s.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,s.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,s.jsx)("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),(0,s.jsx)("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}let no={url:"",autoConnect:!0,reconnect:!0,maxReconnectAttempts:10,reconnectDelay:1e3},nl="relay:recentRepos";function ni(e){try{localStorage.setItem(nl,JSON.stringify(e))}catch(e){}}var nc=r(5372);function nd(e){var t,r,l,i,d,u;let{wsUrl:m,orchestratorUrl:h}=e,{data:p,isConnected:g,error:b}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={...no,...e},[r,s]=(0,n.useState)(null),[a,o]=(0,n.useState)(!1),[l,i]=(0,n.useState)(null),c=(0,n.useRef)(null),d=(0,n.useRef)(0),x=(0,n.useRef)(null),u=(0,n.useCallback)(()=>{var e;if((null===(e=c.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN)return;let r=t.url||function(){let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws")}();try{let e=new WebSocket(r);e.onopen=()=>{o(!0),i(null),d.current=0},e.onclose=()=>{if(o(!1),c.current=null,t.reconnect&&d.current<t.maxReconnectAttempts){let e=Math.min(t.reconnectDelay*Math.pow(2,d.current),3e4);d.current++,x.current=setTimeout(()=>{u()},e)}},e.onerror=e=>{i(Error("WebSocket connection error")),console.error("[useWebSocket] Error:",e)},e.onmessage=e=>{try{let t=JSON.parse(e.data);s(t)}catch(e){console.error("[useWebSocket] Failed to parse message:",e)}},c.current=e}catch(e){i(e instanceof Error?e:Error("Failed to create WebSocket"))}},[t.url,t.reconnect,t.maxReconnectAttempts,t.reconnectDelay]),m=(0,n.useCallback)(()=>{x.current&&(clearTimeout(x.current),x.current=null),c.current&&(c.current.close(),c.current=null),o(!1)},[]);return(0,n.useEffect)(()=>(t.autoConnect&&u(),()=>{m()}),[t.autoConnect,u,m]),{data:r,isConnected:a,error:l,connect:u,disconnect:m}}({url:m}),{workspaces:f,activeWorkspaceId:j,agents:y,isConnected:v,isLoading:w,error:N,switchWorkspace:k,addWorkspace:C,removeWorkspace:S,spawnAgent:L,stopAgent:A}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{apiUrl:t="http://localhost:3456",enabled:r=!1}=e,[s,a]=(0,n.useState)([]),[o,l]=(0,n.useState)(),[i,c]=(0,n.useState)([]),[d,x]=(0,n.useState)(!1),[u,m]=(0,n.useState)(r),[h,p]=(0,n.useState)(null),g=(0,n.useRef)(null),b=(0,n.useRef)(),f=t.replace(/^http/,"ws"),j=(0,n.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)}))),l(r.activeWorkspaceId),r.activeWorkspaceId){let e=await fetch("".concat(t,"/workspaces/").concat(r.activeWorkspaceId,"/agents"));if(e.ok){let t=await e.json();c(t.agents.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))}}}catch(e){p(e instanceof Error?e:Error(String(e)))}finally{m(!1)}},[t,r]);(0,n.useEffect)(()=>{if(!r)return;let e=()=>{try{let t=new WebSocket(f);t.onopen=()=>{x(!0),p(null)},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)}))),l(r.data.activeWorkspaceId),c((null===(t=r.data.agents)||void 0===t?void 0:t.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))||[]),m(!1)}else"event"===r.type&&y(r.data)}catch(e){console.error("Failed to parse WebSocket message:",e)}},t.onclose=()=>{x(!1),g.current=null,b.current=setTimeout(e,3e3)},t.onerror=e=>{console.error("WebSocket error:",e),t.close()},g.current=t}catch(t){p(t instanceof Error?t:Error(String(t))),b.current=setTimeout(e,3e3)}};return j().then(e),()=>{b.current&&clearTimeout(b.current),g.current&&g.current.close()}},[f,j,r]);let y=(0,n.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":l(e.data.currentId);break;case"agent:spawned":c(t=>[...t,e.data]);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))}},[]),v=(0,n.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 s=await fetch("".concat(t,"/workspaces/").concat(e,"/agents"));s.ok&&c((await s.json()).agents.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))},[t]),w=(0,n.useCallback)(async(e,r)=>{let s=await fetch("".concat(t,"/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,name:r})});if(!s.ok)throw Error((await s.json()).error||"Failed to add workspace");return s.json()},[t]),N=(0,n.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]),k=(0,n.useCallback)(async(e,r,s)=>{if(!o)throw Error("No active workspace");let n=await fetch("".concat(t,"/workspaces/").concat(o,"/agents"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,task:r,provider:s})});if(!n.ok)throw Error((await n.json()).error||"Failed to spawn agent");return n.json()},[t,o]),C=(0,n.useCallback)(async e=>{if(!o)throw Error("No active workspace");let r=await fetch("".concat(t,"/workspaces/").concat(o,"/agents/").concat(e),{method:"DELETE"});if(!r.ok)throw Error("Failed to stop agent: ".concat(r.statusText))},[t,o]);return{workspaces:s,activeWorkspaceId:o,agents:i,isConnected:d,isLoading:u,error:h,switchWorkspace:v,addWorkspace:w,removeWorkspace:N,spawnAgent:k,stopAgent:C,refresh:j}}({apiUrl:h}),M=(0,nc.uo)(),W=(null==M?void 0:M.user)?{displayName:M.user.githubUsername,avatarUrl:M.user.avatarUrl}:void 0,[E,D]=(0,n.useState)([]),[B,T]=(0,n.useState)(null),[R,P]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(!(null==M?void 0:M.user))return;let e=async()=>{P(!0);try{let e=await ei.xv.getWorkspaceSummary();e.success&&e.data.workspaces&&(D(e.data.workspaces),!B&&e.data.workspaces.length>0&&T(e.data.workspaces[0].id))}catch(e){console.error("Failed to fetch cloud workspaces:",e)}finally{P(!1)}};e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[null==M?void 0:M.user,B]);let _=!!(null==M?void 0:M.user),I=(0,n.useMemo)(()=>_&&E.length>0?E.map(e=>({id:e.id,name:e.name,path:e.path||"/workspace/".concat(e.name),status:"running"===e.status?"active":"inactive",provider:"claude",lastActiveAt:new Date})):f,[_,E,f]),F=_?B:j,U=_?R:w;(0,n.useEffect)(()=>{_&&B?(0,rf.hc)(B):_||(0,rf.hc)(null)},[_,B]);let O=(0,n.useCallback)(async e=>{_?T(e.id):await k(e.id)},[_,k]),{onlineUsers:z,typingUsers:V,sendTyping:G,isConnected:K}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{currentUser:t,wsUrl:r,autoConnect:s=!0}=e,[a,o]=(0,n.useState)([]),[l,i]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),x=(0,n.useRef)(null),u=(0,n.useRef)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(!1),p=(0,n.useRef)(t);p.current=t,(0,n.useEffect)(()=>{let e=setInterval(()=>{let e=Date.now();i(t=>t.filter(t=>e-t.startedAt<3e3))},1e3);return()=>clearInterval(e)},[]);let g=(0,n.useCallback)(()=>{var e;if(!p.current||(null===(e=x.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN||h.current)return;h.current=!0;let t=r||function(){let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws/presence")}();try{let e=new WebSocket(t);e.onopen=()=>{h.current=!1,d(!0);let t=p.current;t&&e.send(JSON.stringify({type:"presence",action:"join",user:{username:t.username,avatarUrl:t.avatarUrl}}))},e.onclose=()=>{h.current=!1,d(!1),x.current=null,p.current&&(u.current=setTimeout(()=>{g()},2e3))},e.onerror=e=>{console.error("[usePresence] Error:",e)},e.onmessage=e=>{try{let r=JSON.parse(e.data);switch(r.type){case"presence_list":o(r.users||[]);break;case"presence_join":o(e=>[...e.filter(e=>e.username!==r.user.username),r.user]);break;case"presence_leave":o(e=>e.filter(e=>e.username!==r.username)),i(e=>e.filter(e=>e.username!==r.username));break;case"typing":var t;if(r.username===(null===(t=p.current)||void 0===t?void 0:t.username))break;r.isTyping?i(e=>[...e.filter(e=>e.username!==r.username),{username:r.username,avatarUrl:r.avatarUrl,startedAt:Date.now()}]):i(e=>e.filter(e=>e.username!==r.username))}}catch(e){console.error("[usePresence] Failed to parse message:",e)}},x.current=e}catch(e){console.error("[usePresence] Failed to create WebSocket:",e)}},[r]),b=(0,n.useCallback)(()=>{if(u.current&&(clearTimeout(u.current),u.current=null),h.current=!1,x.current){let e=x.current;e.onclose=null,e.onerror=null;let t=p.current;e.readyState===WebSocket.OPEN&&t&&e.send(JSON.stringify({type:"presence",action:"leave",username:t.username})),e.close(),x.current=null}d(!1)},[]),f=(0,n.useCallback)(e=>{if(!x.current||x.current.readyState!==WebSocket.OPEN)return;let t=p.current;t&&(m.current&&(clearTimeout(m.current),m.current=null),x.current.send(JSON.stringify({type:"typing",isTyping:e,username:t.username,avatarUrl:t.avatarUrl})),e&&(m.current=setTimeout(()=>{m.current=null,f(!1)},3e3)))},[]);return(0,n.useEffect)(()=>{if(s&&p.current&&(!x.current||x.current.readyState===WebSocket.CLOSED))return g(),()=>{b()}},[s,null==t?void 0:t.username,g,b]),(0,n.useEffect)(()=>{let e=()=>{var e;let t=p.current;(null===(e=x.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN&&t&&x.current.send(JSON.stringify({type:"presence",action:"leave",username:t.username}))};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]),{onlineUsers:a,typingUsers:l,sendTyping:f,isConnected:c}}({currentUser:(0,n.useMemo)(()=>W?{username:W.displayName,avatarUrl:W.avatarUrl}:void 0,[null==W?void 0:W.displayName,null==W?void 0:W.avatarUrl])}),[Z,q]=(0,n.useState)(null),[J,Y]=(0,n.useState)(null),[$,X]=(0,n.useState)("local"),[Q,ee]=(0,n.useState)([]),[et,er]=(0,n.useState)(),[es,en]=(0,n.useState)(!1),[ea,eo]=(0,n.useState)(!1),[el,ec]=(0,n.useState)(null),[ed,ex]=(0,n.useState)(!1),[eu,em]=(0,n.useState)(!1),[eh,ep]=(0,n.useState)(null),[eg,ef]=(0,n.useState)(!1),[ej,ey]=(0,n.useState)(rb),[ev,ew]=(0,n.useState)(!1),[eN,ek]=(0,n.useState)("dashboard"),[eC,eS]=(0,n.useState)(!1),[eL,eA]=(0,n.useState)(!1),[eM,eW]=(0,n.useState)(null),[eE,eD]=(0,n.useState)(!1),{steps:eB,status:eT,history:eR,isLoading:eP,selectTrajectory:e_,selectedTrajectoryId:eI}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{pollInterval:t=2e3,autoPoll:r=!0,trajectoryId:s,apiBaseUrl:a=""}=e,[o,l]=(0,n.useState)([]),[i,c]=(0,n.useState)(null),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!0),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(s||null),f=(0,n.useRef)(null),j=(0,n.useCallback)(async()=>{try{let e=a?"".concat(a,"/api/trajectory"):(0,rf.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]),y=(0,n.useCallback)(async()=>{try{let e=a?"".concat(a,"/api/trajectory/history"):(0,rf.kG)("/api/trajectory/history"),t=await fetch(e,{credentials:"include"}),r=await t.json();r.success&&x(r.trajectories||[])}catch(e){console.error("[useTrajectory] History fetch error:",e)}},[a]),v=(0,n.useCallback)(async()=>{try{let e=g?"/api/trajectory/steps?trajectoryId=".concat(encodeURIComponent(g)):"/api/trajectory/steps",t=a?"".concat(a).concat(e):(0,rf.kG)(e),r=await fetch(t,{credentials:"include"}),s=await r.json();s.success?(l(s.steps||[]),p(null)):p(s.error||"Failed to fetch trajectory steps")}catch(e){console.error("[useTrajectory] Steps fetch error:",e),p(e.message)}},[a,g]),w=(0,n.useCallback)(e=>{b(e)},[]),N=(0,n.useCallback)(async()=>{m(!0),await Promise.all([j(),v(),y()]),m(!1)},[j,v,y]);return(0,n.useEffect)(()=>{N()},[N]),(0,n.useEffect)(()=>{v()},[g,v]),(0,n.useEffect)(()=>{if(!r)return;f.current=setInterval(()=>{v(),j()},t);let e=setInterval(y,1e4);return()=>{f.current&&clearInterval(f.current),clearInterval(e)}},[r,t,v,j,y]),{steps:o,status:i,history:d,isLoading:u,error:h,refresh:N,selectTrajectory:w,selectedTrajectoryId:g}}({autoPoll:eE}),{recentRepos:eF,addRecentRepo:eU,getRecentProjects:eO}=function(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=null!==(e=t.maxRecent)&&void 0!==e?e:5,[s,a]=(0,n.useState)([]);(0,n.useEffect)(()=>{a(function(){try{let e=localStorage.getItem(nl);if(!e)return[];let t=JSON.parse(e);if(!Array.isArray(t))return[];return t}catch(e){return[]}}())},[]);let o=(0,n.useCallback)(e=>{a(t=>{let s=t.filter(t=>t.id!==e.id),n=[{id:e.id,path:e.path,name:e.name,lastAccessed:Date.now()},...s].slice(0,r);return ni(n),n})},[r]),l=(0,n.useCallback)(e=>{a(t=>{let r=t.filter(t=>t.id!==e);return ni(r),r})},[]),i=(0,n.useCallback)(()=>{a([]),ni([])},[]),c=(0,n.useCallback)(e=>{let t=new Map(e.map(e=>[e.id,e]));return s.map(e=>t.get(e.id)).filter(e=>void 0!==e)},[s]);return{recentRepos:s,addRecentRepo:o,removeRecentRepo:l,clearRecentRepos:i,getRecentProjects:c}}(),{repos:ez,refetch:eH}=function(e){let{workspaceId:t,apiBaseUrl:r="/api",enabled:s=!0}=e,[a,o]=(0,n.useState)([]),[l,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(null),x=(0,n.useCallback)(async()=>{if(t&&s){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 s=await e.json();o(s.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,s]);return(0,n.useEffect)(()=>{x()},[x]),{repos:a,isLoading:l,error:c,refetch:x}}({workspaceId:null!=F?F:void 0,apiBaseUrl:"/api",enabled:_&&!!F}),[eV,eG]=(0,n.useState)(!1),[eK,eZ]=(0,n.useState)(!1),[eJ,eY]=(0,n.useState)([]),[e$,eX]=(0,n.useState)({}),[eQ,e0]=(0,n.useState)(!1),[e1,e2]=(0,n.useState)([]),[e4,e3]=(0,n.useState)(),[e6,e8]=(0,n.useState)(!1),[e9,tt]=(0,n.useState)(!1),[tr,ts]=(0,n.useState)(!1),tn=(0,n.useRef)(0),ta=(0,n.useRef)(!0),[to,tl]=(0,n.useState)(new Map),ti=(0,n.useCallback)(()=>{window.innerWidth<=768&&tt(!1)},[]),tc=(0,n.useMemo)(()=>{var e,t;let r=[...null!==(e=null==p?void 0:p.agents)&&void 0!==e?e:[],...null!==(t=null==p?void 0:p.users)&&void 0!==t?t:[]],s=new Map;for(let e of r){let t=e.name.toLowerCase(),r=s.get(t);s.set(t,r?{...r,...e}:e)}return Array.from(s.values())},[null==p?void 0:p.agents,null==p?void 0:p.users]),td=(0,n.useCallback)(e=>{tl(t=>{let r=new Map(t);return r.set(e.toLowerCase(),Date.now()),r})},[]),{agents:tx,groups:tu,selectedAgent:tm,selectAgent:tp,searchQuery:tg,setSearchQuery:tb,totalCount:tf,onlineCount:ty,needsAttentionCount:tv}=function(e){let{agents:t,initialSelected:r,initialSearchQuery:s=""}=e,[l,i]=(0,n.useState)(null!=r?r:null),[d,u]=(0,n.useState)(s),m=(0,n.useMemo)(()=>c(t,d),[t,d]),h=(0,n.useMemo)(()=>o(m),[m]),p=(0,n.useMemo)(()=>[...m].sort((e,t)=>e.name.localeCompare(t.name)),[m]),g=(0,n.useMemo)(()=>{var e;return null!==(e=t.find(e=>e.name===l))&&void 0!==e?e:null},[t,l]),b=(0,n.useMemo)(()=>{let e=x(t);return{totalCount:e.total,onlineCount:e.online,needsAttentionCount:e.needsAttention}},[t]),f=(0,n.useCallback)(e=>{i(e)},[]),j=(0,n.useCallback)(e=>t.find(t=>t.name===e),[t]),y=(0,n.useCallback)(e=>({...e,color:(0,a.GW)(e.name)}),[]);return{agents:m,groups:h,sortedAgents:p,selectedAgent:g,selectAgent:f,searchQuery:d,setSearchQuery:u,...b,getAgentByName:j,getAgentWithColor:y}}({agents:tc}),{messages:tw,threadMessages:tN,currentChannel:tk,setCurrentChannel:tC,currentThread:tS,setCurrentThread:tL,activeThreads:tA,totalUnreadThreadCount:tM,sendMessage:tW,isSending:tE,sendError:tD}=function(e){let{messages:t,currentChannel:r="general",senderName:s}=e,[a,o]=(0,n.useState)(r),[l,i]=(0,n.useState)(null),[c,d]=(0,n.useState)(!1),[x,u]=(0,n.useState)(null),[m,h]=(0,n.useState)(new Map),p=s||"Dashboard",[g,b]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(0===g.length)return;let e=new Set(t.slice(-50).map(e=>"".concat(e.from,":").concat(e.to,":").concat(e.content.slice(0,100))));b(t=>t.filter(t=>{let r="".concat(t.from,":").concat(t.to,":").concat(t.content.slice(0,100));return!e.has(r)}))},[t,g.length]);let f=(0,n.useMemo)(()=>0===g.length?t:[...t,...g],[t,g]),j=(0,n.useMemo)(()=>{let e=new Set(f.map(e=>e.id)),t=f.filter(t=>!t.thread||!e.has(t.thread));return"general"===a?t:t.filter(e=>e.from===a||e.to===a)},[f,a]),y=(0,n.useCallback)(e=>f.filter(t=>t.thread===e),[f]),v=(0,n.useMemo)(()=>{let e=new Map,t=new Set(f.map(e=>e.id));for(let t of f)if(t.thread){let r=e.get(t.thread)||[];r.push(t),e.set(t.thread,r)}let r=[];for(let[s,n]of e.entries()){let e=[...n].sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime()),a=[...new Set(n.flatMap(e=>[e.from,e.to]))].filter(e=>"*"!==e),o=m.get(s),l=n.filter(e=>e.from!==p&&!e.isRead&&(!o||new Date(e.timestamp).getTime()>o)).length,i=s;if(t.has(s)){let e=f.find(e=>e.id===s);if(e){let t=e.content.split("\n")[0];i=t.length>30?t.substring(0,30)+"...":t}}r.push({id:s,name:i,lastMessage:e[0],messageCount:n.length,unreadCount:l,participants:a})}return r.sort((e,t)=>new Date(t.lastMessage.timestamp).getTime()-new Date(e.lastMessage.timestamp).getTime())},[f,m]),w=(0,n.useCallback)(e=>{i(e),e&&h(t=>{let r=new Map(t);return r.set(e,Date.now()),r})},[]),N=(0,n.useMemo)(()=>v.filter(e=>e.unreadCount>0).length,[v]),k=(0,n.useMemo)(()=>{let e=f.filter(e=>!e.isRead).length;return{totalCount:f.length,unreadCount:e}},[f]);return{messages:j,threadMessages:y,currentChannel:a,setCurrentChannel:o,currentThread:l,setCurrentThread:w,activeThreads:v,totalUnreadThreadCount:N,sendMessage:(0,n.useCallback)(async(e,t,r,n)=>{d(!0),u(null);let a="optimistic-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,9)),o={id:a,from:p,to:e,content:t,timestamp:new Date().toISOString(),status:"sending",thread:r,isRead:!0};b(e=>[...e,o]);try{let o={to:e,message:t,thread:r,attachments:n};s&&(o.from=s);let l=await rf.hi.sendMessage(o);if(l.success)return!0;return b(e=>e.filter(e=>e.id!==a)),u(l.error||"Failed to send message"),!1}catch(e){return b(e=>e.filter(e=>e.id!==a)),u("Network error"),!1}finally{d(!1)}},[p,s]),isSending:c,sendError:x,...k}}({messages:null!==(d=null==p?void 0:p.messages)&&void 0!==d?d:[],senderName:null==W?void 0:W.displayName}),tB=(0,n.useMemo)(()=>{var e;let t=new Set(tx.map(e=>e.name.toLowerCase())),r=new Map;for(let s of(W&&r.set(W.displayName.toLowerCase(),{username:W.displayName,avatarUrl:W.avatarUrl}),null!==(e=null==p?void 0:p.messages)&&void 0!==e?e:[])){let e=s.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==p?void 0:p.messages,tx,W]),tT=(0,n.useMemo)(()=>{var e,t;if(!W)return{};let r={},s=new Set(tc.filter(e=>e.isHuman).map(e=>e.name.toLowerCase()));for(let n of null!==(e=null==p?void 0:p.messages)&&void 0!==e?e:[]){let e=n.from,a=n.to;if(!e||!a)continue;let o=a===W.displayName,l=s.has(e.toLowerCase());if(!o||!l)continue;let i=null!==(t=to.get(e.toLowerCase()))&&void 0!==t?t:0;new Date(n.timestamp).getTime()>i&&(r[e]=(r[e]||0)+1)}return r},[tc,W,null==p?void 0:p.messages,to]);(0,n.useEffect)(()=>{(null==J?void 0:J.username)&&td(J.username)},[null==J?void 0:J.username,td]),(0,n.useEffect)(()=>{if(!(window.innerWidth<=768)){ts(!1);return}let e=tw.length;!e9&&e>tn.current&&ts(!0),ta.current=!e9},[tw.length,e9]),(0,n.useEffect)(()=>{e9&&(ts(!1),tn.current=tw.length)},[e9,tw.length]),(0,n.useEffect)(()=>{tn.current=tw.length},[]);let tR=!!(null==p?void 0:null===(r=p.fleet)||void 0===r?void 0:null===(t=r.servers)||void 0===t?void 0:t.length)||f.length>0;(0,n.useEffect)(()=>{if(f.length>0){if(ez.length>1&&F){let t=ez.map(e=>({id:e.id,path:e.githubFullName,name:e.githubFullName.split("/").pop()||e.githubFullName,agents:y.filter(e=>e.workspaceId===F).map(e=>({name:e.name,status:"running"===e.status?"online":"offline",isSpawned:!0,cli:e.provider})),lead:void 0}));if(ee(t),!et||!t.find(e=>e.id===et)){var e;er(null===(e=t[0])||void 0===e?void 0:e.id)}}else ee(f.map(e=>({id:e.id,path:e.path,name:e.name,agents:y.filter(t=>t.workspaceId===e.id).map(e=>({name:e.name,status:"running"===e.status?"online":"offline",isSpawned:!0,cli:e.provider})),lead:void 0}))),er(j)}},[f,y,j,ez,F,et]),(0,n.useEffect)(()=>{if(f.length>0)return;let e=async()=>{let e=await rf.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||[]).map(e=>({name:e.name,status:"online"===e.status||"active"===e.status?"online":"offline",currentTask:e.task,cli:e.cli})),lead:e.lead}));ee(e),!et&&e.length>0&&er(e[0].id)}}};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[f.length,et]);let tP=["architect"],{bridgeAgents:t_,projectAgents:tI}=(0,n.useMemo)(()=>{let e=[],t=[];for(let r of tx)tP.includes(r.name.toLowerCase())?e.push(r):t.push(r);return{bridgeAgents:e,projectAgents:t}},[tx]),tF=(0,n.useMemo)(()=>0===Q.length||0===new Set(tI.map(e=>e.name.toLowerCase())).size?Q:Q.map((e,t)=>{if(0===t||e.id===et){let t=new Set(e.agents.map(e=>e.name.toLowerCase())),r=tI.filter(e=>!t.has(e.name.toLowerCase()));return{...e,agents:[...e.agents,...r]}}return e}),[Q,tI,et]),tU=(0,n.useMemo)(()=>tF.length>0?[]:tI,[tF,tI]);(0,n.useCallback)(async e=>{try{await k(e.id)}catch(e){console.error("Failed to switch workspace:",e)}},[k]);let tO=(0,n.useCallback)(async(e,t)=>{em(!0),ep(null);try{await C(e,t),ex(!1)}catch(e){throw ep(e instanceof Error?e.message:"Failed to add workspace"),e}finally{em(!1)}},[C]),tz=(0,n.useCallback)(e=>{er(e.id),eU(e),f.length>0&&k(e.id).catch(e=>{console.error("Failed to switch workspace:",e)}),e.agents.length>0&&(tp(e.agents[0].name),tC(e.agents[0].name)),ti()},[tp,tC,ti,f.length,k,eU]),tH=(0,n.useCallback)(e=>{tp(e.name),tC(e.name),ti()},[tp,tC,ti]),tV=(0,n.useCallback)(()=>{ec(null),en(!0)},[]),tG=(0,n.useCallback)(()=>{ek("dashboard"),ew(!0)},[]),tK=(0,n.useCallback)(()=>{ek("workspace"),ew(!0)},[]),tZ=(0,n.useCallback)(()=>{ek("billing"),ew(!0)},[]),tq=(0,n.useCallback)(()=>{eS(!0)},[]),tJ=(0,n.useCallback)(()=>{eA(!0)},[]),tY=(0,n.useCallback)(()=>{eG(!0)},[]),t$=(0,n.useCallback)(e=>{Y({username:e.name,avatarUrl:e.avatarUrl,connectedAt:new Date().toISOString(),lastSeen:new Date().toISOString()}),td(e.name),ti()},[ti,td]),tX=(0,n.useCallback)(async(e,t)=>{let r=await tW(e,t);if(r){if("*"===e)tp(null),tC("general");else{let t=tx.find(t=>t.name===e);t?(tp(t.name),tC(t.name)):tC(e)}}return r},[tW,tp,tC,tx]),tQ=(0,n.useCallback)(async e=>{eo(!0),ec(null);try{if(f.length>0&&j)return await L(e.name,void 0,e.command),!0;let t=await rf.hi.spawnAgent({name:e.name,cli:e.command,team:e.team,shadowMode:e.shadowMode,shadowOf:e.shadowOf,shadowAgent:e.shadowAgent,shadowTriggers:e.shadowTriggers,shadowSpeakOn:e.shadowSpeakOn});if(!t.success)return ec(t.error||"Failed to spawn agent"),!1;return!0}catch(e){return ec(e instanceof Error?e.message:"Failed to spawn agent"),!1}finally{eo(!1)}},[f.length,j,L]),t0=(0,n.useCallback)(async e=>{if(e.isSpawned&&window.confirm('Are you sure you want to release agent "'.concat(e.name,'"?')))try{if(f.length>0&&j){await A(e.name);return}let t=await rf.hi.releaseAgent(e.name);t.success||console.error("Failed to release agent:",t.error)}catch(e){console.error("Failed to release agent:",e)}},[f.length,j,A]),t1=(0,n.useCallback)(e=>{eW(e)},[]);(0,n.useEffect)(()=>{if(!eQ)return;let e=async()=>{let e=await rf.hi.getFleetServers();e.success&&e.data&&e2(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)},[eQ]),(0,n.useEffect)(()=>{if(!eK)return;let e=async()=>{let e=await rf.hi.getDecisions();e.success&&e.data&&eY(e.data.decisions.map(rf.XP))};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[eK]);let t2=(0,n.useCallback)(async(e,t)=>{eX(t=>({...t,[e]:!0}));try{let r=await rf.hi.approveDecision(e,t);r.success?eY(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{eX(t=>({...t,[e]:!1}))}},[]),t5=(0,n.useCallback)(async(e,t)=>{eX(t=>({...t,[e]:!0}));try{let r=await rf.hi.rejectDecision(e,t);r.success?eY(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{eX(t=>({...t,[e]:!1}))}},[]),t4=(0,n.useCallback)(async e=>{(await rf.hi.dismissDecision(e)).success&&eY(t=>t.filter(t=>t.id!==e))},[]),t3=(0,n.useCallback)(async e=>{e8(!0);try{var t;let r=e7[e.priority].beadsPriority,s=await rf.hi.createBead({title:e.title,assignee:e.agentName,priority:r,type:"task"});if(s.success&&(null===(t=s.data)||void 0===t?void 0:t.bead))await rf.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:",s.data.bead.id);else throw console.error("Failed to create task bead:",s.error),Error(s.error||"Failed to create task")}catch(e){throw console.error("Failed to create task:",e),e}finally{e8(!1)}},[]),t6=(0,n.useCallback)(()=>{ef(!0)},[]),t8=(0,n.useCallback)(()=>{ef(!1)},[]);n.useEffect(()=>{let e=e=>{let t;t="system"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e,document.documentElement.setAttribute("data-theme",t)};if(e(ej.theme),"system"===ej.theme){let t=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>e("system");return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}},[ej.theme]),n.useEffect(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),ef(!0)),(e.metaKey||e.ctrlKey)&&e.shiftKey&&"s"===e.key&&(e.preventDefault(),tV()),(e.metaKey||e.ctrlKey)&&"n"===e.key&&(e.preventDefault(),tJ()),"Escape"===e.key&&(ef(!1),en(!1),eA(!1),eD(!1),ew(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[tV,tJ]);let t9=window.location.pathname,t7=new URLSearchParams(window.location.search);return"/billing/success"===t9?(0,s.jsx)(nt,{type:"success",sessionId:t7.get("session_id")||void 0,onClose:()=>{window.location.href="/"}}):"/billing/canceled"===t9?(0,s.jsx)(nt,{type:"canceled",onClose:()=>{window.location.href="/"}}):(0,s.jsx)(r$,{wsUrl:m,children:(0,s.jsxs)("div",{className:"flex h-screen bg-bg-deep font-sans text-text-primary",children:[(0,s.jsx)("div",{className:"\n fixed inset-0 bg-black/60 backdrop-blur-sm z-[999] transition-opacity duration-200\n md:hidden\n ".concat(e9?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none","\n "),onClick:()=>tt(!1)}),(0,s.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(e9?"translate-x-0":"-translate-x-full","\n "),children:[(0,s.jsx)("div",{className:"p-3 border-b border-sidebar-border",children:(0,s.jsx)(rP,{workspaces:I,activeWorkspaceId:null!=F?F:void 0,onSelect:O,onAddWorkspace:()=>ex(!0),onWorkspaceSettings:tK,isLoading:U})}),(0,s.jsx)(H,{agents:tU,bridgeAgents:t_,projects:tF,currentUserName:null==W?void 0:W.displayName,humanUnreadCounts:tT,currentProject:et,selectedAgent:null==tm?void 0:tm.name,viewMode:$,isFleetAvailable:tR,isConnected:g||v,isOpen:e9,activeThreads:tA,currentThread:tS,totalUnreadThreadCount:tM,onAgentSelect:tH,onHumanSelect:t$,onProjectSelect:tz,onViewModeChange:X,onSpawnClick:tV,onReleaseClick:t0,onLogsClick:t1,onThreadSelect:tL,onClose:()=>tt(!1),onSettingsClick:tG,onTrajectoryClick:()=>eD(!0),hasActiveTrajectory:null==eT?void 0:eT.active,onFleetClick:()=>e0(!eQ),isFleetViewActive:eQ,onCoordinatorClick:tY,hasMultipleProjects:tF.length>1})]}),(0,s.jsxs)("main",{className:"flex-1 flex flex-col min-w-0 bg-bg-secondary/50 overflow-hidden",children:[(0,s.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,s.jsx)(eb,{currentChannel:tk,selectedAgent:tm,projects:tF,currentProject:tF.find(e=>e.id===et)||null,recentProjects:eO(tF),onProjectChange:tz,onCommandPaletteOpen:t6,onSettingsClick:tG,onHistoryClick:tq,onNewConversationClick:tJ,onCoordinatorClick:tY,onFleetClick:()=>e0(!eQ),isFleetViewActive:eQ,onTrajectoryClick:()=>eD(!0),hasActiveTrajectory:null==eT?void 0:eT.active,onMenuClick:()=>tt(!0),hasUnreadNotifications:tr}),(0,s.jsx)(nr,{onUpgradeClick:tZ})]}),(0,s.jsx)("div",{className:"h-[52px] flex-shrink-0 md:hidden"}),W&&z.length>0&&(0,s.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,s.jsx)(sG,{onlineUsers:z,onUserClick:q})}),(0,s.jsxs)("div",{className:"flex-1 flex overflow-hidden min-h-0",children:[(0,s.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto ".concat(tS?"hidden md:block md:flex-[2]":""),children:b?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center px-4",children:[(0,s.jsx)(nm,{}),(0,s.jsx)("h2",{className:"m-0 mb-2 font-display text-text-primary",children:"Connection Error"}),(0,s.jsx)("p",{className:"text-text-secondary",children:b.message}),(0,s.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"})]}):p?eQ?(0,s.jsx)("div",{className:"p-4 h-full overflow-y-auto",children:(0,s.jsx)(sI,{servers:e1,agents:tx,selectedServerId:e4,onServerSelect:e3,onServerReconnect:e=>{console.log("Reconnecting to server:",e)},isLoading:!p})}):(0,s.jsx)(eq,{messages:tw,currentChannel:tk,currentThread:tS,onThreadClick:e=>tL(e),highlightedMessageId:null!=tS?tS:void 0,agents:tc,currentUser:W}):(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center",children:[(0,s.jsx)(nu,{}),(0,s.jsx)("p",{className:"font-display text-text-secondary",children:"Connecting to dashboard..."})]})}),tS&&(()=>{let e=tw.find(e=>e.id===tS),t=!e;if(!e){var r;e=null!==(r=tw.filter(e=>e.thread===tS).sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())[0])&&void 0!==r?r:null}return(0,s.jsx)("div",{className:"w-full md:w-[400px] md:min-w-[320px] md:max-w-[500px] flex-shrink-0",children:(0,s.jsx)(e5,{originalMessage:null!=e?e:null,replies:tN(tS),onClose:()=>tL(null),onReply:async r=>{let s="*";return!t&&e&&(s="Dashboard"===e.from||W&&e.from===W.displayName?e.to:e.from),tW(s,r,tS)},isSending:tE,currentUser:W})})})()]}),V.length>0&&(0,s.jsx)("div",{className:"px-4 bg-bg-tertiary border-t border-border-subtle",children:(0,s.jsx)(sV,{typingUsers:V})}),(0,s.jsx)("div",{className:"p-2 sm:p-4 bg-bg-tertiary border-t border-border-subtle",children:(0,s.jsx)(nx,{recipient:"general"===tk?"*":tk,agents:tx,humanUsers:tB,onSend:tW,onTyping:G,isSending:tE,error:tD})})]}),(0,s.jsx)(te,{isOpen:eg,onClose:t8,agents:tx,projects:Q,currentProject:et,onAgentSelect:tH,onProjectSelect:tz,onSpawnClick:tV,onTaskCreate:t3,onGeneralClick:()=>{tp(null),tC("general")}}),(0,s.jsx)(th,{isOpen:es,onClose:()=>en(!1),onSpawn:tQ,existingAgents:tx.map(e=>e.name),isSpawning:ea,error:el}),(0,s.jsx)(rH,{isOpen:ed,onClose:()=>{ex(!1),ep(null)},onAdd:tO,isAdding:eu,error:eh}),(0,s.jsx)(rj,{isOpen:eC,onClose:()=>eS(!1)}),(0,s.jsx)(tj,{isOpen:eL,onClose:()=>eA(!1),onSend:tX,agents:tx,isSending:tE,error:tD}),eM&&(0,s.jsx)(sn,{agent:eM,isOpen:!0,onClose:()=>eW(null),availableAgents:tx,onAgentChange:eW}),eE&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex bg-black/50 backdrop-blur-sm",onClick:()=>eD(!1),children:(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.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,s.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-blue-500",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-text-primary m-0",children:"Trajectory Viewer"}),(0,s.jsx)("p",{className:"text-xs text-text-muted m-0",children:(null==eT?void 0:eT.active)?"Active: ".concat(eT.task||"Working..."):"Browse past trajectories"})]})]}),(0,s.jsx)("button",{onClick:()=>eD(!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,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),(0,s.jsx)("div",{className:"flex-1 overflow-hidden p-6",children:(0,s.jsx)(sm,{agentName:(null==eT?void 0:null===(l=eT.task)||void 0===l?void 0:l.slice(0,30))||"Current",steps:eB,history:eR,selectedTrajectoryId:eI,onSelectTrajectory:e_,isLoading:eP})})]})}),eK&&(0,s.jsx)("div",{className:"fixed left-4 bottom-4 w-[400px] max-h-[500px] z-50 shadow-modal",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("button",{onClick:()=>eZ(!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,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})}),(0,s.jsx)(sL,{decisions:eJ,onApprove:t2,onReject:t5,onDismiss:t4,isProcessing:e$})]})}),!eK&&eJ.length>0&&(0,s.jsxs)("button",{onClick:()=>eZ(!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(eJ.length," pending decision").concat(eJ.length>1?"s":""),children:[(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),eJ.length>0&&(0,s.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:eJ.length})]}),(0,s.jsx)(sK,{user:Z,onClose:()=>q(null),onMention:e=>{q(null)},onSendMessage:e=>{Y(e)}}),(0,s.jsx)(sq,{user:J,onClose:()=>Y(null),messages:null!==(u=null==p?void 0:p.messages)&&void 0!==u?u:[],agents:tx,humanUsers:tB,onSend:tW,onTyping:G,isSending:tE,sendError:tD,currentUser:W}),(0,s.jsx)(sY,{isOpen:eV,onClose:()=>eG(!1),projects:tF,isCloudMode:!!W,hasArchitect:t_.some(e=>"architect"===e.name.toLowerCase()),onArchitectSpawned:()=>{eG(!1)}}),ev&&(0,s.jsx)(rs,{currentUserId:null==M?void 0:null===(i=M.user)||void 0===i?void 0:i.id,initialTab:eN,onClose:()=>ew(!1)})]})})}function nx(e){let{recipient:t,agents:r,humanUsers:a,onSend:o,onTyping:l,isSending:i,error:c}=e,[d,x]=(0,n.useState)(""),[u,m]=(0,n.useState)(0),[h,p]=(0,n.useState)(!1),[g,b]=(0,n.useState)(!1),[f,j]=(0,n.useState)([]),y=(0,n.useRef)(null),v=(0,n.useRef)(null),w=(0,n.useCallback)(async e=>{for(let t of e){let e=crypto.randomUUID(),r=URL.createObjectURL(t);j(s=>[...s,{id:e,file:t,preview:r,isUploading:!0}]);try{let r=await rf.hi.uploadAttachment(t);r.success&&r.data?j(t=>t.map(t=>t.id===e?{...t,isUploading:!1,uploadedId:r.data.attachment.id}:t)):j(t=>t.map(t=>t.id===e?{...t,isUploading:!1,error:r.error||"Upload failed"}:t))}catch(t){j(t=>t.map(t=>t.id===e?{...t,isUploading:!1,error:"Upload failed"}:t))}}},[]),N=(0,n.useCallback)(e=>{if(!e||0===e.length)return;let t=Array.from(e).filter(e=>e.type.startsWith("image/"));t.length>0&&w(t)},[w]),k=(0,n.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(),w(r))},[w]),C=(0,n.useCallback)(e=>{j(t=>{let r=t.find(t=>t.id===e);return r&&URL.revokeObjectURL(r.preview),t.filter(t=>t.id!==e)})},[]),S=async e=>{let r,s;e.preventDefault();let n=d.trim().length>0,a=f.length>0;if(!n&&!a||i||f.some(e=>e.isUploading))return;let l=f.filter(e=>e.uploadedId).map(e=>e.uploadedId),c=d.match(/^@(\S+)\s*([\s\S]*)/);if(c){let e=c[1];s=c[2]||"","*"===e||"everyone"===e.toLowerCase()||"all"===e.toLowerCase()?r="*":e.toLowerCase().startsWith("team:")?r=e:e.includes("/")||/\.(ts|tsx|js|jsx|json|md|py|go|rs|java|c|cpp|h|css|html|yaml|yml|toml)$/i.test(e)?(r=t,s=d):r=e}else r=t,s=d;!s.trim()&&l.length>0&&(s="[Screenshot attached]"),await o(r,s||d,void 0,l.length>0?l:void 0)&&(f.forEach(e=>URL.revokeObjectURL(e.preview)),x(""),j([]),p(!1),b(!1))},L=(d.trim()||f.length>0)&&!i&&!f.some(e=>e.isUploading);return(0,s.jsxs)("form",{className:"flex flex-col gap-1.5 sm:gap-2",onSubmit:S,children:[f.length>0&&(0,s.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:f.map(e=>(0,s.jsxs)("div",{className:"relative group",children:[(0,s.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,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}),e.error&&(0,s.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,s.jsx)("button",{type:"button",onClick:()=>C(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,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},e.id))}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5 sm:gap-3",children:[(0,s.jsx)("input",{ref:v,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>N(e.target.files)}),(0,s.jsx)("button",{type:"button",onClick:()=>{var e;return null===(e=v.current)||void 0===e?void 0:e.click()},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",title:"Attach screenshot (or paste from clipboard)",children:(0,s.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,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,s.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,s.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),(0,s.jsxs)("div",{className:"flex-1 relative min-w-0",children:[(0,s.jsx)(rE,{agents:r,humanUsers:a,inputValue:d,cursorPosition:u,onSelect:(e,t)=>{x(t),p(!1),b(!1),setTimeout(()=>{if(y.current){y.current.focus();let e=t.indexOf(" ")+1;y.current.setSelectionRange(e,e)}},0)},onClose:()=>p(!1),isVisible:h}),(0,s.jsx)(rR,{inputValue:d,cursorPosition:u,onSelect:(e,t)=>{x(t),b(!1),p(!1),setTimeout(()=>{if(y.current){y.current.focus();let e=t.indexOf(" ",1)+1;y.current.setSelectionRange(e,e)}},0)},onClose:()=>b(!1),isVisible:g}),(0,s.jsx)("textarea",{ref:y,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",placeholder:"Message ".concat("*"===t?"everyone":"@"+t,"..."),value:d,onChange:e=>{let t=e.target.value,r=e.target.selectionStart||0;if(x(t),m(r),null==l||l(t.trim().length>0),null!==rD(t,r)){b(!0),p(!1);return}if(null!==rM(t,r)){p(!0),b(!1);return}p(!1),b(!1)},onKeyDown:e=>{(!h&&!g||"ArrowDown"!==e.key&&"ArrowUp"!==e.key&&"Tab"!==e.key)&&("Enter"!==e.key||e.shiftKey||h||g||(e.preventDefault(),(d.trim()||f.length>0)&&!i&&S(e)))},onPaste:k,onSelect:e=>m(e.target.selectionStart||0),disabled:i,rows:1})]}),(0,s.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:!L,title:i?"Sending...":f.some(e=>e.isUploading)?"Uploading...":"Send message",children:i?(0,s.jsx)("span",{className:"hidden sm:inline",children:"Sending..."}):f.some(e=>e.isUploading)?(0,s.jsx)("span",{className:"hidden sm:inline",children:"Uploading..."}):(0,s.jsxs)("span",{className:"flex items-center gap-1 sm:gap-2",children:[(0,s.jsx)("span",{className:"hidden sm:inline",children:"Send"}),(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,s.jsx)("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})]})}),c&&(0,s.jsx)("span",{className:"text-error text-xs ml-2",children:c})]})]})}function nu(){return(0,s.jsx)("svg",{className:"animate-spin mb-4 text-accent-cyan",width:"28",height:"28",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function nm(){return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}},5372:function(e,t,r){r.d(t,{TI:function(){return c},uo:function(){return d}});var s=r(7437),n=r(2265),a=r(9165);let o={checkOnMount:!0,checkInterval:6e4,onExpired:()=>{}};function l(e){let{isOpen:t,error:r,onLogin:n,onDismiss:a}=e;return t?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[9998]",onClick:a,"aria-hidden":"true"}),(0,s.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,s.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,s.jsx)("div",{className:"flex justify-center mb-4",children:(0,s.jsx)("div",{className:"w-16 h-16 rounded-full bg-warning/10 flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-8 h-8 text-warning",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,s.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,s.jsx)("h2",{id:"session-expired-title",className:"text-xl font-semibold text-text-primary text-center mb-2",children:"Session Expired"}),(0,s.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,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("button",{onClick:n,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,s.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,s.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,n.createContext)(void 0);function c(e){let{children:t,cloudMode:r,checkInterval:c=6e4,onSessionExpired:d}=e,x=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")}(),u=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={...o,...e},[r,s]=(0,n.useState)(null),[l,i]=(0,n.useState)(!0),[c,d]=(0,n.useState)(!1),[x,u]=(0,n.useState)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(!0),p=(0,n.useCallback)(async()=>{try{let e=await a.xv.checkSession();if(!h.current)return e;if(!e.authenticated&&(s(null),e.code)){let r={error:"Session expired",code:e.code,message:e.message||"Your session has expired. Please log in again."};u(r),d(!0),t.onExpired(r)}return e}catch(e){return{authenticated:!1,code:"SESSION_ERROR",message:"Failed to check session"}}},[t]),g=(0,n.useCallback)(async()=>{i(!0);try{let e=await a.xv.getMe();if(!h.current)return;e.success?(s(e.data),d(!1),u(null)):e.sessionExpired?(s(null),d(!0)):u({error:e.error,code:"SESSION_ERROR",message:e.error})}finally{h.current&&i(!1)}},[]);(0,n.useEffect)(()=>(0,a.Zk)(e=>{h.current&&(s(null),d(!0),u(e),t.onExpired(e))}),[t]),(0,n.useEffect)(()=>(h.current=!0,t.checkOnMount&&g(),()=>{h.current=!1}),[t.checkOnMount,g]),(0,n.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 b=(0,n.useCallback)(()=>{d(!1),u(null)},[]),f=(0,n.useCallback)(()=>{let e=encodeURIComponent(window.location.pathname+window.location.search);window.location.href="/login?returnTo=".concat(e)},[]),j=(0,n.useCallback)(async()=>{await a.xv.logout(),s(null),d(!1),u(null),window.location.href="/login"},[]);return{user:r,isLoading:l,isAuthenticated:null!==r,isExpired:c,error:x,csrfToken:(0,a._V)(),checkSession:p,clearExpired:b,redirectToLogin:f,logout:j}}({checkOnMount:x,checkInterval:x?c:0,onExpired:d}),m=(0,n.useCallback)(()=>{u.redirectToLogin()},[u]),h=(0,n.useCallback)(()=>{u.clearExpired()},[u]),p={...u,isCloudMode:x};return(0,s.jsxs)(i.Provider,{value:p,children:[t,x&&(0,s.jsx)(l,{isOpen:u.isExpired,error:u.error,onLogin:m,onDismiss:h})]})}function d(){return(0,n.useContext)(i)}}}]);
|
|
1
|
+
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[899],{9165:function(e,t,r){r.d(t,{Zk:function(){return i},_V:function(){return o},xv:function(){return d}});var s=r(9116);let n=new Set,a=null;function o(){return a}function l(e){let t=e.headers.get("X-CSRF-Token");t&&(a=t,(0,s.aM)(t))}function i(e){return n.add(e),()=>n.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 s=await fetch(e,{...t,credentials:"include",headers:r});l(s);let o=await s.json();if(401===s.status||"object"==typeof o&&null!==o&&("SESSION_EXPIRED"===o.code||"USER_NOT_FOUND"===o.code)){let e={error:o.error||"Session expired",code:o.code||"SESSION_EXPIRED",message:o.message||"Your session has expired. Please log in again."};return!function(e){for(let t of n)try{t(e)}catch(e){console.error("[cloudApi] Session expired listener error:",e)}}(e),{success:!1,error:e.message,sessionExpired:!0}}if(!s.ok)return{success:!1,error:o.error||"Request failed with status ".concat(s.status)};return{success:!0,data:o}}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"});l(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"});l(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 l(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"),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"}),getProviders:async()=>c("/api/providers"),disconnectProvider:async e=>c("/api/providers/".concat(encodeURIComponent(e)),{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"})}},637:function(e,t,r){r.d(t,{GW:function(){return i},hP:function(){return c},oU:function(){return l},yh:function(){return a}});let s={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"}},n=[{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 o(e){return e.toLowerCase().split("-").filter(Boolean)}function l(e){return o(e)[0]||e.toLowerCase()}function i(e){let t=l(e);return t in s?s[t]:n[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)%n.length]}function c(e){let t=o(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()}},5899:function(e,t,r){r.d(t,{g:function(){return nd}});var s=r(7437),n=r(2265),a=r(637);function o(e){let t=new Map;for(let r of e){let e=r.team||(0,a.oU)(r.name),s=(0,a.GW)(r.name),n=t.get(e);n||(n={prefix:e,displayName:d(e),color:s,agents:[],isExpanded:!0},t.set(e,n)),n.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 l(e){let t=e.split("-").filter(Boolean);return 0===t.length?e:d(t[t.length-1])}function i(e){return e.split("-").filter(Boolean).map(d).join(" > ")}function c(e,t){return t?e.filter(e=>(function(e,t){if(!t)return!0;let r=t.toLowerCase(),s=e.toLowerCase();return!!s.includes(r)||s.split("-").some(e=>e.includes(r))})(e.name,t)):e}function d(e){return e?e.charAt(0).toUpperCase()+e.slice(1):e}function x(e){let t=0,r=0,s=0;for(let n of e)"online"===n.status?t++:"offline"===n.status&&r++,n.needsAttention&&s++;return{total:e.length,online:t,offline:r,needsAttention:s}}function u(e){let{isProcessing:t,processingStartedAt:r,size:a="medium",showElapsed:o=!1,showLabel:l=!1}=e,[i,c]=(0,n.useState)(0);if((0,n.useEffect)(()=>{if(!t||!r){c(0);return}let e=()=>{c(Date.now()-r)};e();let s=setInterval(e,1e3);return()=>clearInterval(s)},[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,s.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-accent-purple",title:"Processing...",children:[(0,s.jsxs)("span",{className:"inline-flex items-center ".concat({small:"gap-0.5",medium:"gap-1",large:"gap-1.5"}[a]),children:[(0,s.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"0ms",animationDuration:"800ms"}}),(0,s.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"150ms",animationDuration:"800ms"}}),(0,s.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"300ms",animationDuration:"800ms"}})]}),l&&(0,s.jsx)("span",{className:"text-xs font-medium text-accent-purple",children:"thinking"}),o&&i>0&&(0,s.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 m(e){let{isProcessing:t}=e;return t?(0,s.jsx)("span",{className:"thinking-dot-inline",title:"Processing...",children:(0,s.jsx)("span",{className:"thinking-dot-pulse"})}):null}function h(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),s=t%60;return 0===s?"".concat(r,"h"):"".concat(r,"h ").concat(s,"m")}function p(e){let{agent:t,isSelected:r=!1,showBreadcrumb:n=!1,compact:o=!1,displayNameOverride:c,onClick:d,onMessageClick:x,onReleaseClick:p,onLogsClick:v,onProfileClick:w}=e,N=(0,a.GW)(t.name),k=(0,a.hP)(t.name),C=c||l(t.name),S=!t.lastMessageReceivedAt||t.lastOutputAt&&t.lastOutputAt>=t.lastMessageReceivedAt?0:Date.now()-t.lastMessageReceivedAt,L=t.isStuck||S>0,A=L?a.yh.stuck:a.yh[t.status]||a.yh.offline,M="online"===t.status,W=function(e,t,r,s){if(r&&s)return"Stuck - Agent received message ".concat(h(s)," 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)}}(t.status,t.isProcessing,L,S),E=()=>{null==d||d(t)},D=e=>{e.stopPropagation(),null==p||p(t)},B=e=>{e.stopPropagation(),null==v||v(t)},T=e=>{e.stopPropagation(),null==w||w(t)};return o?(0,s.jsxs)("div",{className:"\n group relative flex items-center gap-3 py-2.5 px-3 rounded-lg cursor-pointer\n transition-all duration-300 ease-out\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":"","\n "),onClick:E,style:{borderLeft:r?"2px solid ".concat(N.primary):"2px solid transparent",boxShadow:r?"inset 4px 0 12px -4px ".concat(N.primary,"40"):"none"},children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.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(M?"shadow-lg":"opacity-60","\n "),style:{background:"linear-gradient(135deg, ".concat(N.primary,", ").concat(N.primary,"99)"),boxShadow:M?"0 2px 12px ".concat(N.primary,"50"):"none"},children:[(0,s.jsx)("div",{className:"absolute inset-0 opacity-30",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.3) 0%, transparent 50%)"}}),(0,s.jsx)("span",{className:"relative z-10",style:{color:N.text},children:k})]}),M&&(0,s.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-bg-primary",style:{backgroundColor:A,boxShadow:"0 0 8px ".concat(A)},title:W})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"\n text-[13px] font-semibold tracking-tight truncate transition-colors duration-200\n ".concat(M?"text-text-primary":"text-text-secondary","\n "),children:C}),!c&&(0,s.jsx)("span",{className:"text-[10px] text-text-muted truncate font-mono opacity-70",children:i(t.name)})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[w&&(0,s.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 md:opacity-0 md:group-hover:opacity-100 hover:bg-[#a855f7]/10 hover:border-[#a855f7]/30 hover:text-[#a855f7] hover:shadow-[0_0_12px_rgba(168,85,247,0.25)]",onClick:T,title:"View profile",children:(0,s.jsx)(y,{})}),t.isSpawned&&v&&(0,s.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 md:opacity-0 md:group-hover:opacity-100 hover:bg-accent-cyan/10 hover:border-accent-cyan/30 hover:text-accent-cyan hover:shadow-[0_0_12px_rgba(0,217,255,0.25)]",onClick:B,title:"View logs",children:(0,s.jsx)(f,{})}),t.isSpawned&&p&&(0,s.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 md:opacity-0 md:group-hover:opacity-100 hover:bg-error/10 hover:border-error/30 hover:text-error hover:shadow-[0_0_12px_rgba(255,68,68,0.25)]",onClick:D,title:"Kill agent",children:(0,s.jsx)(b,{})}),t.isProcessing?(0,s.jsx)("div",{title:W,children:(0,s.jsx)(m,{isProcessing:!0})}):(0,s.jsx)("div",{className:"\n w-2 h-2 rounded-full transition-all duration-300\n ".concat(M?"animate-pulse":"","\n "),style:{backgroundColor:A,boxShadow:M?"0 0 6px ".concat(A):"none"},title:W}),t.needsAttention&&(0,s.jsx)("div",{className:"w-2 h-2 rounded-full bg-warning animate-pulse shadow-[0_0_8px_rgba(255,107,53,0.5)]",title:"Needs Attention - Agent requires user input or has pending decisions"}),L&&(0,s.jsxs)("div",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded bg-[#f97316]/20 text-[#f97316] text-[10px] font-medium animate-pulse",title:W,children:[(0,s.jsx)(j,{}),(0,s.jsx)("span",{children:h(S)})]})]})]}):(0,s.jsxs)("div",{className:"\n rounded-lg p-3 cursor-pointer transition-all duration-200\n hover:shadow-md hover:-translate-y-px\n ".concat(r?"border-2 shadow-[0_0_0_2px_rgba(74,158,255,0.15)]":"border","\n "),onClick:E,style:{backgroundColor:N.light,borderColor:N.primary},children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center font-semibold text-sm relative",style:{backgroundColor:N.primary},children:[(0,s.jsx)("span",{style:{color:N.text},children:k}),(0,s.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-white",style:{backgroundColor:A},title:W})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:C}),t.needsAttention&&(0,s.jsx)("span",{className:"bg-red-500 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:"!"}),L&&(0,s.jsxs)("span",{className:"bg-[#f97316] text-white text-[10px] font-bold px-1.5 py-0.5 rounded flex items-center gap-1",title:W,children:[(0,s.jsx)(j,{})," ",h(S)]})]}),n?(0,s.jsx)("span",{className:"text-xs text-text-muted truncate block",children:i(t.name)}):(0,s.jsx)("span",{className:"text-xs text-text-muted truncate block",children:t.name}),t.agentId&&(0,s.jsxs)("span",{className:"text-[10px] text-text-muted font-mono opacity-70",title:"Agent ID (use to resume)",children:["ID: ",t.agentId]})]})]}),t.isProcessing&&(0,s.jsxs)("div",{className:"mt-2 p-2 bg-indigo-50 rounded flex items-center gap-2 border border-indigo-200",children:[(0,s.jsx)(u,{isProcessing:!0,processingStartedAt:t.processingStartedAt,size:"medium",showElapsed:!0}),(0,s.jsx)("span",{className:"text-xs text-indigo-500 font-medium",children:"Thinking..."})]}),t.currentTask&&!t.isProcessing&&(0,s.jsxs)("div",{className:"mt-2 p-2 bg-bg-hover rounded text-xs",children:[(0,s.jsx)("span",{className:"text-text-muted mr-1",children:"Working on:"}),(0,s.jsx)("span",{className:"text-text-primary line-clamp-2",title:t.currentTask,children:t.currentTask})]}),(0,s.jsxs)("div",{className:"mt-3 flex justify-between items-center",children:[(0,s.jsxs)("div",{className:"flex gap-2 text-xs text-text-muted",children:[t.cli&&(0,s.jsx)("span",{className:"bg-bg-hover py-0.5 px-1.5 rounded",children:t.cli}),void 0!==t.messageCount&&t.messageCount>0&&(0,s.jsxs)("span",{style:{color:N.primary},children:[t.messageCount," msgs"]}),t.isSpawned&&(0,s.jsx)("span",{className:"bg-accent-light text-accent text-[10px] py-0.5 px-1.5 rounded uppercase font-medium",children:"spawned"})]}),(0,s.jsxs)("div",{className:"flex gap-1.5",children:[w&&(0,s.jsx)("button",{className:"relative bg-gradient-to-b from-[#2a1a3a] to-[#1a0f2a] text-[#a855f7] border border-[#402060] rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 shadow-[inset_0_1px_0_rgba(168,85,247,0.1),0_2px_4px_rgba(0,0,0,0.3)] overflow-hidden hover:bg-gradient-to-b hover:from-[#402060] hover:to-[#301a50] hover:border-[#a855f7] hover:shadow-[inset_0_1px_0_rgba(168,85,247,0.2),0_0_12px_rgba(168,85,247,0.4),0_2px_8px_rgba(0,0,0,0.4)] hover:scale-105 active:scale-[0.98]",onClick:T,title:"View profile",children:(0,s.jsx)(y,{})}),t.isSpawned&&v&&(0,s.jsx)("button",{className:"relative bg-gradient-to-b from-[#1a2a3a] to-[#0f1a2a] text-accent-cyan border border-[#204060] rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 shadow-[inset_0_1px_0_rgba(0,217,255,0.1),0_2px_4px_rgba(0,0,0,0.3)] overflow-hidden hover:bg-gradient-to-b hover:from-[#204060] hover:to-[#1a3a50] hover:border-accent-cyan hover:shadow-[inset_0_1px_0_rgba(0,217,255,0.2),0_0_12px_rgba(0,217,255,0.4),0_2px_8px_rgba(0,0,0,0.4)] hover:scale-105 active:scale-[0.98]",onClick:B,title:"View logs",children:(0,s.jsx)(f,{})}),t.isSpawned&&p&&(0,s.jsx)("button",{className:"relative bg-gradient-to-b from-[#3a1a1a] to-[#2a0f0f] text-[#ff6b6b] border border-[#4a2020] rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 shadow-[inset_0_1px_0_rgba(255,107,107,0.1),0_2px_4px_rgba(0,0,0,0.3)] overflow-hidden hover:bg-gradient-to-b hover:from-[#4a2020] hover:to-[#3a1515] hover:border-[#ff4444] hover:text-[#ff4444] hover:shadow-[inset_0_1px_0_rgba(255,68,68,0.2),0_0_12px_rgba(255,68,68,0.4),0_2px_8px_rgba(0,0,0,0.4)] hover:scale-105 active:scale-[0.98]",onClick:D,title:"Release agent",children:(0,s.jsx)(b,{})}),x&&(0,s.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:N.primary},onClick:e=>{e.stopPropagation(),null==x||x(t)},title:"Send message",children:(0,s.jsx)(g,{})})]})]})]})}function g(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.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 b(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",className:"release-icon",children:[(0,s.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,s.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,s.jsx)("line",{x1:"12",y1:"2",x2:"12",y2:"12",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"})]})}function f(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,s.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function j(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function y(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"12",cy:"7",r:"4"})]})}function v(e){let{agents:t,selectedAgent:r,searchQuery:a="",onAgentSelect:l,onAgentMessage:i,onReleaseClick:d,onLogsClick:x,compact:u=!1,showGroupStats:m=!0}=e,[h,p]=(0,n.useState)(new Set),[g,b]=(0,n.useState)(!0),f=(0,n.useMemo)(()=>c(t.filter(e=>!e.name.startsWith("__setup__")),a),[t,a]),j=(0,n.useMemo)(()=>o(f),[f]);(0,n.useMemo)(()=>{0===h.size&&j.length>0&&p(new Set(j.map(e=>e.prefix)))},[j]);let y=e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};return 0===t.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,s.jsx)(k,{}),(0,s.jsx)("p",{children:"No agents connected"})]}):0===f.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,s.jsx)(C,{}),(0,s.jsxs)("p",{children:['No agents match "',a,'"']})]}):(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[j.length>1&&(0,s.jsxs)("div",{className:"flex justify-between items-center py-2 px-3 text-xs text-text-muted",children:[(0,s.jsxs)("span",{children:[f.length," agents"]}),(0,s.jsx)("button",{className:"bg-transparent border-none text-accent cursor-pointer text-xs hover:underline",onClick:()=>{g?p(new Set):p(new Set(j.map(e=>e.prefix))),b(!g)},children:g?"Collapse all":"Expand all"})]}),j.map(e=>(0,s.jsx)(w,{group:e,isExpanded:h.has(e.prefix),selectedAgent:r,compact:u,showStats:m,onToggle:()=>y(e.prefix),onAgentSelect:l,onAgentMessage:i,onReleaseClick:d,onLogsClick:x},e.prefix))]})}function w(e){let{group:t,isExpanded:r,selectedAgent:n,compact:o,showStats:i,onToggle:c,onAgentSelect:d,onAgentMessage:u,onReleaseClick:m,onLogsClick:h}=e,g=i?x(t.agents):null;if(1===t.agents.length&&t.agents[0].name.toLowerCase()===t.prefix.toLowerCase()){let e=t.agents[0];return(0,s.jsx)("div",{className:"mb-1 py-1 px-2",children:(0,s.jsx)(p,{agent:e,isSelected:e.name===n,compact:o,onClick:d,onMessageClick:u,onReleaseClick:m,onLogsClick:h},e.name)})}return(0,s.jsxs)("div",{className:"mb-1",children:[(0,s.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,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{backgroundColor:t.color.primary}}),(0,s.jsx)(N,{expanded:r}),(0,s.jsx)("span",{className:"font-semibold text-text-primary",children:t.displayName}),(0,s.jsxs)("span",{className:"text-text-muted font-normal",children:["(",t.agents.length,")"]}),i&&g&&(0,s.jsxs)("div",{className:"ml-auto flex gap-2",children:[g.online>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-text-muted",title:"".concat(g.online," agent").concat(g.online>1?"s":""," online"),children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.online}}),g.online]}),g.needsAttention>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-text-muted",title:"".concat(g.needsAttention," agent").concat(g.needsAttention>1?"s":""," need").concat(1===g.needsAttention?"s":""," attention"),children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.attention}}),g.needsAttention]})]})]}),r&&(0,s.jsx)("div",{className:"py-1 pl-4 flex flex-col gap-1",children:t.agents.map(e=>(0,s.jsx)(p,{agent:e,isSelected:e.name===n,compact:o,displayNameOverride:l(e.name),onClick:d,onMessageClick:u,onReleaseClick:m,onLogsClick:h},e.name))})]})}function N(e){let{expanded:t}=e;return(0,s.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,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function k(){return(0,s.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,s.jsx)("circle",{cx:"12",cy:"8",r:"5"}),(0,s.jsx)("path",{d:"M20 21a8 8 0 1 0-16 0"})]})}function C(){return(0,s.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function S(e){return e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ")}function L(e){let{projects:t,localAgents:r=[],bridgeAgents:a=[],currentProject:o,selectedAgent:l,searchQuery:i="",onProjectSelect:c,onAgentSelect:d,onReleaseClick:x,onLogsClick:u,compact:m=!1}=e,[h,p]=(0,n.useState)(()=>new Set(t.map(e=>e.id))),g=(0,n.useMemo)(()=>{let e=i.toLowerCase().trim();if(!e)return{projects:t,localAgents:r,bridgeAgents:a};let s=r.filter(t=>{var r;return t.name.toLowerCase().includes(e)||(null===(r=t.currentTask)||void 0===r?void 0:r.toLowerCase().includes(e))}),n=a.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:t.map(t=>{var r;let s=(null===(r=t.name)||void 0===r?void 0:r.toLowerCase().includes(e))||t.path.toLowerCase().includes(e),n=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 s||n.length>0?{...t,agents:s?t.agents:n}:null}).filter(Boolean),localAgents:s,bridgeAgents:n}},[t,r,a,i]),b=e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},f=g.localAgents.length+g.projects.reduce((e,t)=>e+t.agents.length,0);if(0===f&&0===t.length&&0===r.length)return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-[#888] text-center",children:[(0,s.jsx)(T,{}),(0,s.jsx)("p",{children:"No projects or agents"})]});if(0===f&&i)return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-[#888] text-center",children:[(0,s.jsx)(R,{}),(0,s.jsxs)("p",{children:['No results for "',i,'"']})]});let j=g.projects.length>1;return(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[j&&g.bridgeAgents.length>0&&(0,s.jsx)(M,{agents:g.bridgeAgents,selectedAgent:l,compact:m,onAgentSelect:e=>null==d?void 0:d(e),onReleaseClick:x,onLogsClick:u}),!j&&g.localAgents.length>0&&(0,s.jsx)(A,{project:{id:"__local__",path:"",name:"Local",agents:g.localAgents},isExpanded:h.has("__local__"),isCurrentProject:!0,selectedAgent:l,compact:m,onToggle:()=>b("__local__"),onAgentSelect:e=>null==d?void 0:d(e),onReleaseClick:x,onLogsClick:u}),g.projects.map(e=>(0,s.jsx)(A,{project:e,isExpanded:h.has(e.id),isCurrentProject:e.id===o,selectedAgent:l,compact:m,isBridgeMode:j,onToggle:()=>b(e.id),onProjectSelect:()=>null==c?void 0:c(e),onAgentSelect:t=>null==d?void 0:d(t,e),onReleaseClick:x,onLogsClick:u},e.id))]})}function A(e){var t;let{project:r,isExpanded:o,isCurrentProject:l,selectedAgent:i,compact:c,isBridgeMode:d=!1,onToggle:x,onProjectSelect:u,onAgentSelect:m,onReleaseClick:h,onLogsClick:g}=e,[b,f]=(0,n.useState)(new Set),j=(0,n.useMemo)(()=>{let e=0,t=0;for(let s of r.agents)"online"===s.status&&e++,s.needsAttention&&t++;return{online:e,needsAttention:t,total:r.agents.length}},[r.agents]),{teams:y,ungroupedAgents:v}=(0,n.useMemo)(()=>{let e=new Map,t=[];for(let s of r.agents)if(s.team){let t=e.get(s.team)||[];t.push(s),e.set(s.team,t)}else t.push(s);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]),w=e=>{f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};(0,n.useEffect)(()=>{o&&0===b.size&&y.length>0&&f(new Set(y.map(e=>e.name)))},[o,y,b]);let N=(0,a.GW)(r.name||r.id),k=r.name||r.path.split("/").pop()||r.id;return(0,s.jsxs)("div",{className:"mb-1",children:[(0,s.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-[#e8e8e8] hover:bg-[var(--project-light)] ".concat(l?"bg-[rgba(0,255,200,0.08)]":""),onClick:x,onDoubleClick:u,style:{"--project-color":N.primary,"--project-light":N.light},children:[(0,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{background:N.primary}}),(0,s.jsx)(E,{expanded:o}),(0,s.jsx)(D,{color:N.primary}),(0,s.jsx)("span",{className:"font-semibold text-[#e8e8e8] whitespace-nowrap overflow-hidden text-ellipsis",children:k}),(0,s.jsxs)("span",{className:"text-[#888] font-normal flex-shrink-0",children:["(",j.total,")"]}),(0,s.jsxs)("div",{className:"ml-auto flex gap-2 flex-shrink-0",children:[j.online>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-[11px] text-[#666]",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.online}}),j.online]}),j.needsAttention>0&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-[11px] text-[#666]",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:a.yh.attention}}),j.needsAttention]})]}),(null===(t=r.lead)||void 0===t?void 0:t.connected)&&(0,s.jsx)("span",{className:"text-[#ffd700] text-xs ml-1",title:"Lead: ".concat(r.lead.name),children:"★"}),d&&!l&&u&&(0,s.jsx)("button",{className:"ml-2 py-1 px-2 text-[10px] font-medium bg-accent-cyan/20 text-accent-cyan rounded border-none cursor-pointer opacity-0 group-hover:opacity-100 transition-opacity hover:bg-accent-cyan/30",onClick:e=>{e.stopPropagation(),u()},title:"Switch to this project",children:"Switch"})]}),o&&(0,s.jsxs)("div",{className:"py-1 pl-5 flex flex-col gap-1",children:[y.map(e=>(0,s.jsxs)("div",{className:"mb-0.5",children:[(0,s.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-[#b8b8b8] hover:bg-white/5",onClick:()=>w(e.name),children:[(0,s.jsx)(E,{expanded:b.has(e.name)}),(0,s.jsx)(B,{}),(0,s.jsx)("span",{className:"font-medium text-[#b8b8b8]",children:e.name}),(0,s.jsxs)("span",{className:"text-[#666] font-normal",children:["(",e.agents.length,")"]})]}),b.has(e.name)&&(0,s.jsx)("div",{className:"py-0.5 pl-4 flex flex-col gap-1",children:e.agents.map(t=>(0,s.jsx)(p,{agent:t,isSelected:t.name===i,compact:c,displayNameOverride:function(e,t){let r=e.toLowerCase(),s=t.toLowerCase().replace(/-?team$/i,"");if(s&&r.startsWith(s+"-")||s&&r.startsWith(s+"_"))return S(e.substring(s.length+1));let n=e.split("-");return n.length>1?S(n[n.length-1]):S(e)}(t.name,e.name),onClick:m,onReleaseClick:h,onLogsClick:g},t.name))})]},e.name)),v.map(e=>(0,s.jsx)(p,{agent:e,isSelected:e.name===i,compact:c,onClick:m,onReleaseClick:h,onLogsClick:g},e.name))]})]})}function M(e){let{agents:t,selectedAgent:r,compact:a,onAgentSelect:o,onReleaseClick:l,onLogsClick:i}=e,[c,d]=(0,n.useState)(!0);return(0,s.jsxs)("div",{className:"mb-2",children:[(0,s.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-[#e8e8e8] hover:bg-[rgba(168,85,247,0.1)]",onClick:()=>d(!c),children:[(0,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{background:"#a855f7"}}),(0,s.jsx)(E,{expanded:c}),(0,s.jsx)(W,{}),(0,s.jsx)("span",{className:"font-semibold text-[#e8e8e8]",children:"Bridge"}),(0,s.jsxs)("span",{className:"text-[#888] font-normal flex-shrink-0",children:["(",t.length,")"]})]}),c&&(0,s.jsx)("div",{className:"py-1 pl-5 flex flex-col gap-1",children:t.map(e=>(0,s.jsx)(p,{agent:e,isSelected:e.name===r,compact:a,onClick:o,onReleaseClick:l,onLogsClick:i},e.name))})]})}function W(){return(0,s.jsxs)("svg",{className:"flex-shrink-0 text-[#a855f7]",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function E(e){let{expanded:t}=e;return(0,s.jsx)("svg",{className:"transition-transform duration-200 text-[#888] flex-shrink-0 ".concat(t?"rotate-90":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function D(e){let{color:t}=e;return(0,s.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,s.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 B(){return(0,s.jsxs)("svg",{className:"text-[#888] flex-shrink-0",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function T(){return(0,s.jsx)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,s.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 R(){return(0,s.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function P(e){let{threads:t,currentThread:r,onThreadSelect:n,totalUnreadCount:a=0,isCollapsed:o=!1,onToggleCollapse:l}=e;return 0===t.length?null:(0,s.jsxs)("div",{className:"px-2 py-2",children:[(0,s.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:l,"aria-expanded":!o,"aria-label":o?"Expand threads":"Collapse threads",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(F,{isCollapsed:o}),(0,s.jsx)("span",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Threads"}),(0,s.jsxs)("span",{className:"text-xs text-text-dim font-mono",children:["(",t.length,")"]})]}),a>0&&(0,s.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})]}),!o&&(0,s.jsx)("div",{className:"space-y-1",children:t.map(e=>(0,s.jsx)(_,{thread:e,isSelected:r===e.id,onClick:()=>n(e.id)},e.id))})]})}function _(e){let{thread:t,isSelected:r,onClick:n}=e,a=t.unreadCount>0,o=function(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),s=Math.floor(r/6e4),n=Math.floor(r/36e5),a=Math.floor(r/864e5);return s<1?"now":s<60?"".concat(s,"m"):n<24?"".concat(n,"h"):a<7?"".concat(a,"d"):t.toLocaleDateString([],{month:"short",day:"numeric"})}(t.lastMessage.timestamp);return(0,s.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:n,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,s.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,s.jsx)("div",{className:"absolute inset-0 opacity-20",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%)"}}),(0,s.jsx)(I,{})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-text-muted font-mono",children:[(0,s.jsx)("span",{className:"truncate",children:t.participants.slice(0,2).join(", ")}),t.participants.length>2&&(0,s.jsxs)("span",{className:"text-text-dim",children:["+",t.participants.length-2]}),(0,s.jsx)("span",{className:"text-text-dim opacity-50",children:"\xb7"}),(0,s.jsx)("span",{className:"text-text-dim",children:o})]})]})]})}function I(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 F(e){let{isCollapsed:t}=e;return(0,s.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,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}var U=r(6272);let O="agent-relay-threads-collapsed",z="agent-relay-sidebar-tab";function H(e){let{agents:t,bridgeAgents:r=[],projects:a=[],currentUserName:o,humanUnreadCounts:l={},currentProject:i,selectedAgent:c,viewMode:d,isFleetAvailable:x,isConnected:u,isOpen:m=!1,activeThreads:h=[],currentThread:p,totalUnreadThreadCount:g=0,onAgentSelect:b,onHumanSelect:f,onProjectSelect:j,onViewModeChange:y,onSpawnClick:w,onReleaseClick:N,onLogsClick:k,onThreadSelect:C,onClose:S,onSettingsClick:A,onTrajectoryClick:M,hasActiveTrajectory:W,onFleetClick:E,isFleetViewActive:D,onCoordinatorClick:B,hasMultipleProjects:T}=e,[R,_]=(0,n.useState)(""),[I,F]=(0,n.useState)(()=>{try{let e=localStorage.getItem(z);return"team"===e?"team":"agents"}catch(e){return"agents"}}),[H,er]=(0,n.useState)(()=>{try{let e=localStorage.getItem(O);return"true"===e}catch(e){return!1}});(0,n.useEffect)(()=>{try{localStorage.setItem(z,I)}catch(e){}},[I]),(0,n.useEffect)(()=>{try{localStorage.setItem(O,String(H))}catch(e){}},[H]);let es=t.filter(e=>!e.isHuman),en=t.filter(e=>e.isHuman&&(!o||e.name.toLowerCase()!==o.toLowerCase())),ea=en.filter(e=>!R||e.name.toLowerCase().includes(R.toLowerCase())),eo=a.length>0;return(0,s.jsxs)("aside",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)("div",{className:"p-3 sm:p-4 border-b border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 mb-3",children:[(0,s.jsx)(U.K7,{size:24,withGlow:!0}),(0,s.jsx)("h1",{className:"text-base sm:text-lg font-display font-semibold m-0 text-text-primary",children:"Agent Relay"}),(0,s.jsx)(V,{isConnected:u}),(0,s.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:S,"aria-label":"Close sidebar",children:(0,s.jsx)(q,{})})]}),x&&(0,s.jsxs)("div",{className:"flex bg-bg-tertiary rounded-lg p-1",children:[(0,s.jsx)("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\n ".concat("local"===d?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>null==y?void 0:y("local"),children:"Local"}),(0,s.jsx)("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\n ".concat("fleet"===d?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>null==y?void 0:y("fleet"),children:"Fleet"})]})]}),en.length>0&&(0,s.jsxs)("div",{className:"flex bg-bg-tertiary rounded-lg p-1 mx-3 mt-3",children:[(0,s.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"===I?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>F("agents"),children:[(0,s.jsx)(Y,{}),"Agents",es.length>0&&(0,s.jsxs)("span",{className:"text-[10px] opacity-70",children:["(",es.length,")"]})]}),(0,s.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"===I?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>F("team"),children:[(0,s.jsx)($,{}),"Team",en.length>0&&(0,s.jsxs)("span",{className:"text-[10px] opacity-70",children:["(",en.length,")"]})]})]}),(0,s.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,s.jsx)(G,{}),(0,s.jsx)("input",{type:"text",placeholder:"agents"===I?"Search agents...":"Search team...",value:R,onChange:e=>_(e.target.value),className:"flex-1 bg-transparent border-none text-text-primary text-sm outline-none placeholder:text-text-muted"}),R&&(0,s.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:()=>_(""),children:(0,s.jsx)(K,{})})]}),h.length>0&&(0,s.jsx)("div",{className:"border-b border-border-subtle",children:(0,s.jsx)(P,{threads:h,currentThread:p,onThreadSelect:e=>null==C?void 0:C(e),totalUnreadCount:g,isCollapsed:H,onToggleCollapse:()=>er(!H)})}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto px-2",children:["team"===I&&en.length>0?(0,s.jsxs)("div",{className:"flex flex-col gap-1 py-2",children:[ea.map(e=>(0,s.jsxs)("button",{onClick:()=>f?f(e):null==b?void 0:b(e),className:"\n flex items-center gap-3 p-3 rounded-lg border transition-all duration-150 text-left w-full\n ".concat(c===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,s.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-9 h-9 rounded-full object-cover"}):(0,s.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,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.name}),(0,s.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.role||"Team Member"})]}),l[e.name]>0&&(0,s.jsx)("span",{className:"text-[11px] font-semibold px-2 py-0.5 rounded-full bg-accent-cyan/20 text-accent-cyan",children:l[e.name]}),(0,s.jsx)("div",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-dim")})]},e.name)),0===ea.length&&(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,s.jsx)(G,{}),(0,s.jsxs)("p",{className:"mt-3",children:['No team members match "',R,'"']})]})]}):eo?(0,s.jsx)(L,{projects:a,localAgents:es,bridgeAgents:r,currentProject:i,selectedAgent:c,searchQuery:R,onProjectSelect:j,onAgentSelect:b,onReleaseClick:N,onLogsClick:k,compact:!0}):(0,s.jsx)(v,{agents:es,selectedAgent:c,searchQuery:R,onAgentSelect:e=>null==b?void 0:b(e),onReleaseClick:N,onLogsClick:k,compact:!0,showGroupStats:!0}),"agents"===I&&en.length>0&&(0,s.jsxs)("div",{className:"mt-4 mb-2 pt-3 border-t border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-1 pb-2",children:[(0,s.jsx)("p",{className:"text-xs uppercase tracking-wide text-text-muted font-semibold m-0",children:"Direct messages"}),(0,s.jsxs)("span",{className:"text-[11px] text-text-muted",children:[ea.length," member",1===ea.length?"":"s"]})]}),(0,s.jsx)("div",{className:"flex flex-col gap-1",children:ea.length>0?ea.map(e=>(0,s.jsxs)("button",{onClick:()=>f?f(e):null==b?void 0:b(e),className:"\n flex items-center gap-3 p-2.5 rounded-lg border transition-all duration-150 text-left w-full\n ".concat(c===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,s.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-8 h-8 rounded-full object-cover"}):(0,s.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,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.name}),(0,s.jsx)("p",{className:"text-[11px] text-text-muted truncate",children:e.role||"Team Member"})]}),l[e.name]>0&&(0,s.jsx)("span",{className:"text-[11px] font-semibold px-2 py-0.5 rounded-full bg-accent-cyan/20 text-accent-cyan",children:l[e.name]}),(0,s.jsx)("div",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-dim")})]},e.name)):(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-6 px-3 text-text-muted text-center",children:[(0,s.jsx)(G,{}),(0,s.jsxs)("p",{className:"mt-2 text-xs",children:['No team members match "',R,'"']})]})})]})]}),(0,s.jsxs)("div",{className:"md:hidden border-t border-border-subtle p-3",children:[(0,s.jsx)("p",{className:"text-xs text-text-muted font-medium mb-2 px-1",children:"Quick Actions"}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[E&&(0,s.jsxs)("button",{className:"flex items-center gap-2 p-2.5 rounded-lg border text-sm transition-all duration-150 ".concat(D?"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:()=>{E(),null==S||S()},children:[(0,s.jsx)(X,{}),(0,s.jsx)("span",{children:"Fleet"})]}),M&&(0,s.jsxs)("button",{className:"flex items-center gap-2 p-2.5 rounded-lg border text-sm transition-all duration-150 relative ".concat(W?"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:()=>{M(),null==S||S()},children:[(0,s.jsx)(Q,{}),(0,s.jsx)("span",{children:"Trajectory"}),W&&(0,s.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 bg-accent-cyan rounded-full animate-pulse"})]}),T&&B&&(0,s.jsxs)("button",{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-purple",onClick:()=>{B(),null==S||S()},children:[(0,s.jsx)(ee,{}),(0,s.jsx)("span",{children:"Coordinator"})]}),(0,s.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==S?void 0:S(),children:[(0,s.jsx)(et,{}),(0,s.jsx)("span",{children:"Metrics"})]})]})]}),(0,s.jsxs)("div",{className:"p-3 sm:p-4 border-t border-border-subtle space-y-2",children:[(0,s.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:w,children:[(0,s.jsx)(Z,{}),"Spawn Agent"]}),(0,s.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:A,children:[(0,s.jsx)(J,{}),"Settings"]})]})]})}function V(e){let{isConnected:t}=e;return(0,s.jsxs)("div",{className:"flex items-center gap-1.5 ml-auto",children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(t?"bg-success animate-pulse-glow":"bg-text-dim")}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:t?"Live":"Offline"})]})}function G(){return(0,s.jsxs)("svg",{className:"text-text-muted",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function K(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Z(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function q(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function J(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 Y(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),(0,s.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,s.jsx)("path",{d:"M12 7v4"}),(0,s.jsx)("line",{x1:"8",y1:"16",x2:"8",y2:"16"}),(0,s.jsx)("line",{x1:"16",y1:"16",x2:"16",y2:"16"})]})}function $(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function X(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Q(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4"})})}function ee(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function et(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M3 3v18h18"}),(0,s.jsx)("path",{d:"M18 17V9"}),(0,s.jsx)("path",{d:"M13 17V5"}),(0,s.jsx)("path",{d:"M8 17v-3"})]})}function er(e){let{projects:t,recentProjects:r=[],currentProject:a,onProjectChange:o}=e,[l,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(-1),x=(0,n.useRef)(null),u=(0,n.useRef)([]),m=t.length>1,h=new Set(r.map(e=>e.id)),p=t.filter(e=>!h.has(e.id)),g=[...r,...p],b=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,n.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=e=>{if(l)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=u.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=u.current[r])||void 0===t||t.focus(),r});break;case"Enter":c>=0&&c<g.length&&(o(g[c]),i(!1),d(-1))}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,c,g,o]),(0,n.useEffect)(()=>{if(l){let e=g.findIndex(e=>e.id===(null==a?void 0:a.id));d(e>=0?e:0)}else d(-1)},[l,g,a]),0===t.length)?null:(0,s.jsxs)("div",{className:"relative",ref:x,children:[(0,s.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(!l),disabled:!m,"aria-expanded":l,"aria-haspopup":"listbox",children:[(0,s.jsx)(ea,{}),(0,s.jsx)("span",{className:"text-text-primary truncate max-w-[200px]",children:b(a)}),m&&(0,s.jsx)(eo,{isOpen:l})]}),l&&m&&(0,s.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,s.jsx)("div",{className:"px-3 py-2 border-b border-border-subtle",children:(0,s.jsx)("span",{className:"text-xs font-medium text-text-muted uppercase tracking-wider",children:"Switch Project"})}),(0,s.jsxs)("div",{className:"max-h-[300px] overflow-y-auto",role:"listbox",children:[r.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"px-3 py-1.5 bg-bg-tertiary/50",children:(0,s.jsxs)("span",{className:"text-[10px] font-medium text-text-muted uppercase tracking-wider flex items-center gap-1.5",children:[(0,s.jsx)(en,{}),"Recent"]})}),(0,s.jsx)("div",{className:"py-1",children:r.map((e,t)=>(0,s.jsx)(es,{project:e,index:t,isActive:(null==a?void 0:a.id)===e.id,isFocused:c===t,formatProjectName:b,buttonRefs:u,onSelect:()=>{o(e),i(!1)}},e.id))})]}),p.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"px-3 py-1.5 bg-bg-tertiary/50",children:(0,s.jsx)("span",{className:"text-[10px] font-medium text-text-muted uppercase tracking-wider",children:r.length>0?"All Projects":"Projects"})}),(0,s.jsx)("div",{className:"py-1",children:p.map((e,t)=>{let n=r.length+t;return(0,s.jsx)(es,{project:e,index:n,isActive:(null==a?void 0:a.id)===e.id,isFocused:c===n,formatProjectName:b,buttonRefs:u,onSelect:()=>{o(e),i(!1)}},e.id)})})]})]})]})]})}function es(e){var t,r;let{project:n,index:a,isActive:o,isFocused:l,formatProjectName:i,buttonRefs:c,onSelect:d}=e,x=i(n),u=(null===(t=n.agents)||void 0===t?void 0:t.length)||0;return(0,s.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(o?"bg-accent-cyan/10 text-accent-cyan":l?"bg-bg-hover text-text-primary":"bg-transparent text-text-primary hover:bg-bg-hover"),onClick:d,role:"option","aria-selected":o,tabIndex:l?0:-1,children:[(0,s.jsx)(ea,{className:o?"text-accent-cyan":"text-text-muted"}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-medium text-sm truncate",children:x}),(0,s.jsx)("div",{className:"text-xs text-text-muted truncate",children:n.path})]}),(0,s.jsxs)("span",{className:"text-xs px-2 py-0.5 rounded-full ".concat(o?"bg-accent-cyan/20 text-accent-cyan":"bg-bg-tertiary text-text-muted"),children:[u," ",1===u?"agent":"agents"]}),(null===(r=n.lead)||void 0===r?void 0:r.connected)&&(0,s.jsx)("span",{className:"w-2 h-2 rounded-full bg-success animate-pulse",title:"Lead: ".concat(n.lead.name)}),o&&(0,s.jsx)(el,{})]})}function en(){return(0,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function ea(e){let{className:t="text-text-muted"}=e;return(0,s.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,s.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 eo(e){let{isOpen:t}=e;return(0,s.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,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function el(){return(0,s.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,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}var ei=r(9165);let ec={autoRefresh:!0,refreshInterval:3e4,autoWakeup:!1,onStatusChange:()=>{}};function ed(e){let{expanded:t=!1,autoWakeup:r=!1,onWakeup:a,onStatusChange:o,className:l=""}=e,[i,c]=(0,n.useState)(!1),[d,x]=(0,n.useState)(""),{workspace:u,exists:m,isLoading:h,isWakingUp:p,statusMessage:g,actionNeeded:b,wakeup:f}=function(){var e,t,r,s,a;let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l=null!==(e=o.autoRefresh)&&void 0!==e?e:ec.autoRefresh,i=null!==(t=o.refreshInterval)&&void 0!==t?t:ec.refreshInterval,c=null!==(r=o.autoWakeup)&&void 0!==r?r:ec.autoWakeup,d=(0,n.useRef)(null!==(s=o.onStatusChange)&&void 0!==s?s:ec.onStatusChange);d.current=null!==(a=o.onStatusChange)&&void 0!==a?a:ec.onStatusChange;let[x,u]=(0,n.useState)(null),[m,h]=(0,n.useState)(!1),[p,g]=(0,n.useState)(!0),[b,f]=(0,n.useState)(!1),[j,y]=(0,n.useState)(""),[v,w]=(0,n.useState)(null),[N,k]=(0,n.useState)(null),C=(0,n.useRef)(null),S=(0,n.useRef)(!0),L=(0,n.useRef)(null),A=(0,n.useCallback)(async()=>{try{g(!0),k(null);let e=await ei.xv.getPrimaryWorkspace();if(!S.current)return;if(e.success){if(h(e.data.exists),y(e.data.statusMessage),w(e.data.actionNeeded||null),e.data.workspace){let t=e.data.workspace;u(t),L.current&&L.current!==t.status&&d.current(t.status,!1),L.current=t.status}else u(null)}else k(e.error)}catch(e){S.current&&k("Failed to fetch workspace status")}finally{S.current&&g(!1)}},[]),M=(0,n.useRef)(i);M.current=i;let W=(0,n.useRef)(l);W.current=l;let E=(0,n.useCallback)(async()=>{if(!(null==x?void 0:x.id))return{success:!1,message:"No workspace to wake up"};try{f(!0),k(null);let e=await ei.xv.wakeupWorkspace(x.id);if(!S.current)return{success:!1,message:"Component unmounted"};if(e.success)return e.data.wasRestarted&&(y(e.data.message),w(null),d.current("starting",!0),C.current&&clearInterval(C.current),C.current=setInterval(A,5e3),setTimeout(()=>{S.current&&C.current&&(clearInterval(C.current),W.current&&(C.current=setInterval(A,M.current)))},12e4)),{success:!0,message:e.data.message};return k(e.error),{success:!1,message:e.error}}catch(t){let e=t instanceof Error?t.message:"Failed to wake up workspace";return S.current&&k(e),{success:!1,message:e}}finally{S.current&&f(!1)}},[null==x?void 0:x.id,A]);return(0,n.useEffect)(()=>(S.current=!0,A(),()=>{S.current=!1}),[A]),(0,n.useEffect)(()=>{if(l)return C.current=setInterval(A,i),()=>{C.current&&(clearInterval(C.current),C.current=null)}},[l,i,A]),(0,n.useEffect)(()=>{c&&(null==x?void 0:x.isStopped)&&!b&&E()},[c,null==x?void 0:x.isStopped,b,E]),{workspace:x,exists:m,isLoading:p,isWakingUp:b,statusMessage:j,actionNeeded:v,error:N,refresh:A,wakeup:E}}({autoWakeup:r,onStatusChange:(e,t)=>{null==o||o(e),t?(x("Workspace is starting up..."),c(!0),setTimeout(()=>c(!1),5e3)):"running"===e&&(x("Workspace is ready!"),c(!0),setTimeout(()=>c(!1),3e3))}}),j=(0,n.useCallback)(async()=>{let e=await f();e.success&&(null==a||a(),x(e.message),c(!0),setTimeout(()=>c(!1),5e3))},[f,a]),y=m?h&&!u?{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,s.jsx)(eg,{}),label:"Loading...",pulseColor:null}:(null==u?void 0:u.isRunning)?{color:"text-success",bgColor:"bg-success/10",borderColor:"border-success/30",icon:(0,s.jsx)(ex,{}),label:"Running",pulseColor:"bg-success"}:(null==u?void 0:u.isStopped)?{color:"text-amber-400",bgColor:"bg-amber-400/10",borderColor:"border-amber-400/30",icon:(0,s.jsx)(eu,{}),label:"Stopped",pulseColor:null}:(null==u?void 0:u.isProvisioning)||p?{color:"text-accent-cyan",bgColor:"bg-accent-cyan/10",borderColor:"border-accent-cyan/30",icon:(0,s.jsx)(em,{}),label:p?"Starting...":"Provisioning",pulseColor:"bg-accent-cyan"}:(null==u?void 0:u.hasError)?{color:"text-error",bgColor:"bg-error/10",borderColor:"border-error/30",icon:(0,s.jsx)(eh,{}),label:"Error",pulseColor:null}:{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,s.jsx)(ep,{}),label:"Unknown",pulseColor:null}:{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,s.jsx)(ep,{}),label:"No workspace",pulseColor:null};return t?(0,s.jsxs)("div",{className:"rounded-lg border ".concat(y.borderColor," ").concat(y.bgColor," p-4 ").concat(l),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:y.color,children:y.icon}),(0,s.jsx)("span",{className:"text-sm font-semibold ".concat(y.color),children:"Workspace Status"})]}),y.pulseColor&&(0,s.jsx)("span",{className:"w-2.5 h-2.5 rounded-full ".concat(y.pulseColor," animate-pulse")})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted",children:"Name"}),(0,s.jsx)("span",{className:"text-sm text-text-primary font-medium truncate max-w-[150px]",children:(null==u?void 0:u.name)||"None"})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted",children:"Status"}),(0,s.jsx)("span",{className:"text-sm font-medium ".concat(y.color),children:y.label})]}),g&&(0,s.jsx)("p",{className:"text-xs text-text-muted mt-2",children:g}),"wakeup"===b&&!p&&(0,s.jsx)("button",{onClick:j,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"===b&&(0,s.jsx)("a",{href:"/workspaces/".concat(null==u?void 0:u.id),className:"block w-full mt-3 px-3 py-2 text-sm font-medium text-center text-error bg-error/10 border border-error/30 rounded-lg hover:bg-error/20 transition-colors no-underline",children:"View error details"})]}),i&&(0,s.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:d})]}):(0,s.jsxs)("div",{className:"relative ".concat(l),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 rounded-lg border ".concat(y.bgColor," ").concat(y.borderColor," cursor-default"),title:g||y.label,children:[(0,s.jsx)("span",{className:y.color,children:y.icon}),(0,s.jsx)("span",{className:"text-xs font-medium ".concat(y.color," truncate max-w-[100px]"),title:g||y.label,children:y.label}),y.pulseColor&&(0,s.jsx)("span",{className:"w-2 h-2 rounded-full ".concat(y.pulseColor," animate-pulse")})]}),"wakeup"===b&&!p&&(0,s.jsx)("button",{onClick:j,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,s.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:d})]})}function ex(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function eu(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("rect",{x:"6",y:"6",width:"12",height:"12"})})}function em(){return(0,s.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,s.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function eh(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,s.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}function ep(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),(0,s.jsx)("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function eg(){return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeOpacity:"0.25"}),(0,s.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10"})]})}function eb(e){let{currentChannel:t,selectedAgent:r,projects:n=[],currentProject:o,recentProjects:l=[],onProjectChange:c,onCommandPaletteOpen:d,onSettingsClick:x,onHistoryClick:u,onNewConversationClick:m,onCoordinatorClick:h,onFleetClick:p,isFleetViewActive:g,onTrajectoryClick:b,hasActiveTrajectory:f,onMenuClick:j,hasUnreadNotifications:y}=e,v="general"===t,w=r?(0,a.GW)(r.name):null,N=n.length>1;return(0,s.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,s.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:j,"aria-label":"Open menu",children:[(0,s.jsx)(eC,{}),y&&(0,s.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)]"})]}),n.length>0&&c&&(0,s.jsx)("div",{className:"max-md:hidden mr-3",children:(0,s.jsx)(er,{projects:n,recentProjects:l,currentProject:null!=o?o:null,onProjectChange:c})}),n.length>0&&c&&(0,s.jsx)("div",{className:"w-px h-6 bg-border-subtle mr-3 max-md:hidden"}),(0,s.jsx)(ed,{className:"max-md:hidden mr-3"}),(0,s.jsx)("div",{className:"w-px h-6 bg-border-subtle mr-3 max-md:hidden"}),(0,s.jsx)("div",{className:"flex items-center gap-2 sm:gap-3 flex-1 min-w-0",children:v?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-accent-cyan text-base sm:text-lg font-mono",children:"#"}),(0,s.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate max-w-[100px] sm:max-w-none",children:"general"}),(0,s.jsx)("span",{className:"text-text-muted text-sm ml-2 pl-3 border-l border-border-subtle hidden md:inline",children:"All agent communications"})]}):r?(0,s.jsxs)(s.Fragment,{children:[(0,s.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,s.jsx)("span",{style:{color:null==w?void 0:w.text},children:(0,a.hP)(r.name)})}),(0,s.jsxs)("div",{className:"flex flex-col min-w-0",children:[(0,s.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate",children:r.name}),(0,s.jsx)("span",{className:"text-text-muted text-xs font-mono hidden md:block truncate",children:i(r.name)})]}),r.status&&(0,s.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})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-accent-cyan text-base sm:text-lg font-mono",children:"@"}),(0,s.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate",children:t})]})}),(0,s.jsxs)("div",{className:"flex items-center gap-1 sm:gap-2",children:[(0,s.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:m,title:"Start new conversation (⌘N)",children:[(0,s.jsx)(ef,{}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"New"}),(0,s.jsx)("span",{className:"hidden md:inline",children:"Message"})]}),(0,s.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,s.jsx)(ej,{}),(0,s.jsx)("span",{className:"hidden md:inline",children:"Search"}),(0,s.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,s.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:u,title:"Message History",children:(0,s.jsx)(ey,{})}),N&&(0,s.jsx)("button",{className:"hidden md:flex items-center justify-center 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:h,title:"Coordinator Agent",children:(0,s.jsx)(eS,{})}),p&&(0,s.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(g?"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:p,title:g?"Back to Chat":"Fleet Overview",children:(0,s.jsx)(ew,{})}),b&&(0,s.jsxs)("button",{className:"hidden md:flex items-center justify-center p-2 border rounded-lg cursor-pointer transition-all duration-150 relative ".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:b,title:"Trajectory Viewer",children:[(0,s.jsx)(eN,{}),f&&(0,s.jsx)("span",{className:"absolute -top-1 -right-1 w-2 h-2 bg-accent-cyan rounded-full animate-pulse"})]}),(0,s.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,s.jsx)(ev,{})}),(0,s.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:x,title:"Settings",children:(0,s.jsx)(ek,{})})]})]})}function ef(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("path",{d:"M12 20h9"}),(0,s.jsx)("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}function ej(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function ey(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function ev(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M3 3v18h18"}),(0,s.jsx)("path",{d:"M18 17V9"}),(0,s.jsx)("path",{d:"M13 17V5"}),(0,s.jsx)("path",{d:"M8 17v-3"})]})}function ew(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function eN(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4"})})}function ek(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 eC(){return(0,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,s.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,s.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}function eS(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}var eL=r(3225),eA=r(9880),eM=r(454),eW=r(1999),eE=r(290),eD=r(4327),eB=r(1202),eT=r(3706),eR=r(6011),eP=r(1801),e_=r(754),eI=r(3871),eF=r(5482),eU=r(5210),eO=r(963),ez=r(7711);function eH(e){let{status:t,size:r="small"}=e;if(!t)return null;let n={small:"w-3.5 h-3.5",medium:"w-4 h-4"}[r];return"sending"===t||"unread"===t?(0,s.jsx)("span",{className:"inline-flex items-center justify-center ".concat(n," text-text-muted"),title:"Sending...",children:(0,s.jsx)(eV,{className:n})}):"acked"===t||"read"===t?(0,s.jsx)("span",{className:"inline-flex items-center justify-center ".concat(n," text-success"),title:"Delivered",children:(0,s.jsx)(eG,{className:n})}):"failed"===t?(0,s.jsx)("span",{className:"inline-flex items-center justify-center ".concat(n," text-error"),title:"Delivery failed",children:(0,s.jsx)(eK,{className:n})}):null}function eV(e){let{className:t}=e;return(0,s.jsxs)("svg",{className:"animate-pulse ".concat(t),viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,s.jsx)("circle",{cx:"8",cy:"8",r:"6"}),(0,s.jsx)("path",{d:"M8 5v3l2 1",strokeLinecap:"round",strokeLinejoin:"round"})]})}function eG(e){let{className:t}=e;return(0,s.jsx)("svg",{className:t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M3 8l3 3 7-7",strokeLinecap:"round",strokeLinejoin:"round"})})}function eK(e){let{className:t}=e;return(0,s.jsxs)("svg",{className:t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"8",cy:"8",r:"6"}),(0,s.jsx)("line",{x1:"8",y1:"5",x2:"8",y2:"8",strokeLinecap:"round"}),(0,s.jsx)("circle",{cx:"8",cy:"11",r:"0.5",fill:"currentColor",stroke:"none"})]})}eL.Z.registerLanguage("javascript",eM.Z),eL.Z.registerLanguage("typescript",eW.Z),eL.Z.registerLanguage("python",eE.Z),eL.Z.registerLanguage("bash",eD.Z),eL.Z.registerLanguage("shell",eD.Z),eL.Z.registerLanguage("json",eB.Z),eL.Z.registerLanguage("markdown",eT.Z),eL.Z.registerLanguage("yaml",eR.Z),eL.Z.registerLanguage("css",eP.Z),eL.Z.registerLanguage("go",e_.Z),eL.Z.registerLanguage("rust",eI.Z),eL.Z.registerLanguage("sql",eF.Z),eL.Z.registerLanguage("ruby",eU.Z),eL.Z.registerLanguage("java",eO.Z),eL.Z.registerLanguage("docker",ez.Z),eL.Z.registerLanguage("dockerfile",ez.Z);let eZ={claude:{icon:"◈",color:"#00d9ff"},codex:{icon:"⬡",color:"#ff6b35"},gemini:{icon:"◇",color:"#a855f7"},openai:{icon:"◆",color:"#10a37f"},default:{icon:"●",color:"#00d9ff"}};function eq(e){let{messages:t,currentChannel:r,onThreadClick:a,highlightedMessageId:o,currentThread:l,agents:i=[],currentUser:c}=e,d=new Map;for(let e of i)e.isProcessing&&d.set(e.name,{isProcessing:!0,processingStartedAt:e.processingStartedAt});let x=new Map,u=(0,n.useRef)(null),[m,h]=(0,n.useState)(!0),p=(0,n.useRef)(0),g=(0,n.useRef)(r),b=(0,n.useRef)(!1),f=(0,n.useRef)(!1),j=t.filter(e=>l?e.id===l||e.thread===l:"general"===r?"*"===e.to||e.isBroadcast||"general"===e.channel:e.from===r||e.to===r);for(let e of j)("Dashboard"===e.from||c&&e.from===c.displayName)&&"*"!==e.to&&x.set(e.to,e.id);let y=j.length;if(y>p.current){let e=j[j.length-1],t=(null==e?void 0:e.from)==="Dashboard"||c&&(null==e?void 0:e.from)===c.displayName;(t||m)&&(b.current=!0,t&&!m&&h(!0))}p.current=y;let v=(0,n.useCallback)(()=>{if(!u.current||f.current)return;let e=u.current,t=e.scrollHeight-e.scrollTop-e.clientHeight;t<50&&!m?h(!0):t>150&&m&&h(!1)},[m]);return((0,n.useLayoutEffect)(()=>{if(b.current&&u.current){b.current=!1,f.current=!0;let e=u.current;e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{setTimeout(()=>{f.current=!1},50)})}},[j.length]),(0,n.useLayoutEffect)(()=>{if(r!==g.current&&(g.current=r,p.current=j.length,h(!0),u.current)){f.current=!0;let e=u.current;e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{setTimeout(()=>{f.current=!1},50)})}},[r,j.length]),0===j.length)?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center",children:[(0,s.jsx)(e1,{}),(0,s.jsx)("h3",{className:"m-0 mb-2 text-base font-display text-text-secondary",children:"No messages yet"}),(0,s.jsx)("p",{className:"m-0 text-sm",children:"general"===r?"Broadcast messages will appear here":"Messages with ".concat(r," will appear here")})]}):(0,s.jsx)("div",{className:"flex flex-col gap-1 p-2 sm:p-4 bg-bg-secondary h-full overflow-y-auto",ref:u,onScroll:v,children:j.map(e=>{let t=("Dashboard"===e.from||c&&e.from===c.displayName)&&"*"!==e.to&&x.get(e.to)===e.id?d.get(e.to):void 0;return(0,s.jsx)(eJ,{message:e,isHighlighted:e.id===o,onThreadClick:a,recipientProcessing:t,currentUser:c},e.id)})})}function eJ(e){let{message:t,isHighlighted:r,onThreadClick:a,recipientProcessing:o,currentUser:l}=e,i=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 s=new Date(r);return(s.setDate(s.getDate()-1),t.toDateString()===s.toDateString())?"Yesterday ".concat(t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(t.timestamp),c="Dashboard"===t.from||l&&t.from===l.displayName,d=c&&l?{icon:"",color:"#a855f7"}:function(e){let t=e.toLowerCase();if(t.includes("claude")||t.includes("anthropic"))return eZ.claude;if(t.includes("codex")||t.includes("openai")||t.includes("gpt"))return eZ.codex;if(t.includes("gemini")||t.includes("google")||t.includes("bard"))return eZ.gemini;let r=e.split("").reduce((e,t)=>e+t.charCodeAt(0),0),s=Object.keys(eZ).filter(e=>"default"!==e);return eZ[s[r%s.length]]}(t.from),x=c&&l?l.displayName:t.from,m=t.replyCount&&t.replyCount>0,h=c&&("acked"===t.status||"read"===t.status)&&(null==o?void 0:o.isProcessing);return(0,s.jsxs)("div",{className:"\n group flex gap-2 sm:gap-3 py-2 sm:py-3 px-2 sm:px-4 rounded-xl transition-all duration-150\n hover:bg-bg-card/50\n ".concat(r?"bg-warning-light/20 border-l-2 border-l-warning pl-2 sm:pl-3":"","\n "),children:[c&&(null==l?void 0:l.avatarUrl)?(0,s.jsx)("img",{src:l.avatarUrl,alt:x,className:"shrink-0 w-8 h-8 sm:w-10 sm:h-10 rounded-lg sm:rounded-xl border-2 object-cover",style:{borderColor:d.color,boxShadow:"0 0 16px ".concat(d.color,"30")}}):(0,s.jsx)("div",{className:"shrink-0 w-8 h-8 sm:w-10 sm:h-10 rounded-lg sm:rounded-xl flex items-center justify-center text-base sm:text-lg font-medium border-2",style:{backgroundColor:"".concat(d.color,"15"),borderColor:d.color,color:d.color,boxShadow:"0 0 16px ".concat(d.color,"30")},children:d.icon}),(0,s.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-1.5 flex-wrap",children:[(0,s.jsx)("span",{className:"font-display font-semibold text-sm",style:{color:d.color},children:x}),"*"!==t.to&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-dim text-xs",children:"→"}),(0,s.jsx)("span",{className:"font-medium text-sm text-accent-cyan",children:t.to})]}),t.thread&&(0,s.jsx)("span",{className:"text-xs py-0.5 px-2 rounded-full font-mono font-medium bg-accent-purple/20 text-accent-purple",children:t.thread}),"*"===t.to&&(0,s.jsx)("span",{className:"text-xs py-0.5 px-2 rounded-full uppercase font-medium bg-warning/20 text-warning",children:"broadcast"}),(0,s.jsx)("span",{className:"text-text-dim text-xs ml-auto font-mono",children:i}),c&&(0,s.jsx)(eH,{status:t.status,size:"small"}),h&&(0,s.jsx)(u,{isProcessing:!0,processingStartedAt:null==o?void 0:o.processingStartedAt,size:"small",showLabel:!0}),(0,s.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(m||t.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==a?void 0:a(t.thread||t.id),title:t.thread?"View thread: ".concat(t.thread):m?"".concat(t.replyCount," ").concat(1===t.replyCount?"reply":"replies"):"Reply in thread",children:[(0,s.jsx)(e2,{}),m&&(0,s.jsx)("span",{className:"text-xs font-medium",children:t.replyCount})]})]}),(0,s.jsx)("div",{className:"text-sm leading-relaxed text-text-primary whitespace-pre-wrap break-words",children:function(e){let t=e.replace(/\\n/g,"\n").replace(/\r\n/g,"\n").replace(/\r/g,"\n"),r=function(e){let t;let r=[],s=/```(\w*)\n([\s\S]*?)```/g,n=0;for(;null!==(t=s.exec(e));){if(t.index>n){let s=eQ(e.slice(n,t.index));r.push(...s)}r.push({type:"code",language:t[1]||"text",content:t[2]}),n=t.index+t[0].length}if(n<e.length){let t=eQ(e.slice(n));r.push(...t)}return 0===r.length?eQ(e):r}(t);return 1===r.length&&"text"===r[0].type?t.split("\n").map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[t>0&&(0,s.jsx)("br",{}),e0(e)]},t)):r.map((e,t)=>{if("code"===e.type)return(0,s.jsx)(eX,{code:e.content,language:e.language||"text"},t);if("table"===e.type)return(0,s.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},t);let r=e.content.split("\n");return(0,s.jsx)("span",{children:r.map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[t>0&&(0,s.jsx)("br",{}),e0(e)]},t))},t)})}(t.content)}),t.attachments&&t.attachments.length>0&&(0,s.jsx)(eY,{attachments:t.attachments})]})]})}function eY(e){let{attachments:t}=e,[r,a]=(0,n.useState)(null),o=t.filter(e=>e.mimeType.startsWith("image/"));return 0===o.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:o.map(e=>(0,s.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,s.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,s.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,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",className:"drop-shadow-lg",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),(0,s.jsx)("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),(0,s.jsx)("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})})]},e.id))}),r&&(0,s.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>a(null),children:(0,s.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,s.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,s.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,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,s.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,s.jsx)("p",{className:"text-white text-sm truncate",children:r.filename})})]})})]})}let e$={...eA.Z,'pre[class*="language-"]':{...eA.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-"]':{...eA.Z['code[class*="language-"]'],background:"transparent",fontSize:"0.75rem"}};function eX(e){let{code:t,language:r}=e,[a,o]=(0,n.useState)(!1),l=(0,n.useCallback)(async()=>{try{await navigator.clipboard.writeText(t),o(!0),setTimeout(()=>o(!1),2e3)}catch(e){console.error("Failed to copy:",e)}},[t]),i=r.toLowerCase().replace(/^(js|jsx)$/,"javascript").replace(/^(ts|tsx)$/,"typescript").replace(/^(py)$/,"python").replace(/^(rb)$/,"ruby").replace(/^(sh|shell|zsh)$/,"bash");return(0,s.jsxs)("div",{className:"relative group my-2",children:[(0,s.jsxs)("div",{className:"absolute top-2 right-2 flex items-center gap-2 z-10",children:[r&&"text"!==r&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-accent-cyan/20 text-accent-cyan font-mono",children:r}),(0,s.jsx)("button",{onClick:l,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:a?"✓ Copied":"Copy"})]}),(0,s.jsx)(eL.Z,{language:i,style:e$,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 eQ(e){let t=e.split("\n"),r=[],s=null;for(let e of t){let t=(e.match(/\|/g)||[]).length>=2||e.trim().startsWith("|")&&e.trim().endsWith("|")||/^[\s|:-]+$/.test(e)&&e.includes("-")&&e.includes("|")?"table":"text";s&&s.type===t?s.content+="\n"+e:(s&&r.push(s),s={type:t,content:e})}return s&&r.push(s),r}function e0(e){return e.split(/(`[^`]+`|https?:\/\/[^\s]+)/g).map((e,t)=>{if(!e)return null;if(e.startsWith("`")&&e.endsWith("`")&&e.length>2){let r=e.slice(1,-1);return(0,s.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:r},t)}return/^https?:\/\//.test(e)?(0,s.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan no-underline hover:underline",children:e},t):e})}function e1(){return(0,s.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,s.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 e2(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 e5(e){let{originalMessage:t,replies:r,onClose:a,onReply:o,isSending:l=!1,currentUser:i}=e,[c,d]=(0,n.useState)(""),x=(0,n.useRef)(null),u=(0,n.useRef)(null);(0,n.useEffect)(()=>{requestAnimationFrame(()=>{var e;null===(e=x.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})})},[r.length]),(0,n.useEffect)(()=>{var e;null===(e=u.current)||void 0===e||e.focus()},[null==t?void 0:t.id]);let m=async e=>{e.preventDefault(),c.trim()&&!l&&await o(c.trim())&&d("")};return t?(0,s.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary border-l border-border",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(e6,{}),(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:"Thread"}),(0,s.jsxs)("span",{className:"text-text-muted text-xs",children:[r.length," ",1===r.length?"reply":"replies"]})]}),(0,s.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,s.jsx)(e8,{})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,s.jsx)("div",{className:"p-4 border-b border-border",children:(0,s.jsx)(e4,{message:t,isOriginal:!0,currentUser:i})}),(0,s.jsxs)("div",{className:"p-4 space-y-3",children:[0===r.length?(0,s.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,s.jsx)(e4,{message:e,currentUser:i},e.id)),(0,s.jsx)("div",{ref:x})]})]}),(0,s.jsx)("div",{className:"p-4 border-t border-border bg-bg-secondary",children:(0,s.jsxs)("form",{onSubmit:m,className:"flex gap-2",children:[(0,s.jsx)("textarea",{ref:u,value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),m(e))},placeholder:"Reply to thread...",disabled:l,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,s.jsx)("button",{type:"submit",disabled:!c.trim()||l,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:l?"Sending...":"Reply"})]})})]}):null}function e4(e){let{message:t,isOriginal:r,currentUser:o}=e,l=(0,a.GW)(t.from),i=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),c="Dashboard"===t.from||o&&t.from===o.displayName,d=c&&o?o.displayName:t.from;return(0,s.jsxs)("div",{className:"flex gap-3 ".concat(r?"":"pl-2"),children:[c&&(null==o?void 0:o.avatarUrl)?(0,s.jsx)("img",{src:o.avatarUrl,alt:d,className:"shrink-0 w-8 h-8 rounded-lg object-cover"}):(0,s.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,a.hP)(t.from)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:d}),"*"!==t.to&&!r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-muted text-xs",children:"→"}),(0,s.jsx)("span",{className:"text-sm text-accent",children:t.to})]}),(0,s.jsx)("span",{className:"text-text-muted text-xs",children:i}),r&&(0,s.jsx)("span",{className:"text-[10px] py-0.5 px-1.5 rounded bg-accent-light text-accent font-medium",children:"Original"})]}),(0,s.jsx)("div",{className:"text-sm leading-relaxed text-text-primary whitespace-pre-wrap break-words",children:t.content.replace(/\\n/g,"\n").replace(/\r\n/g,"\n").replace(/\r/g,"\n").split("\n").map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[t>0&&(0,s.jsx)("br",{}),function(e){let t=/(https?:\/\/[^\s]+)/g;return e.split(t).map((e,r)=>t.test(e)?(0,s.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:e},r):e)}(e)]},t))}),t.attachments&&t.attachments.length>0&&(0,s.jsx)(e3,{attachments:t.attachments})]})]})}function e3(e){let{attachments:t}=e,[r,a]=(0,n.useState)(null),o=t.filter(e=>e.mimeType.startsWith("image/"));return 0===o.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:o.map(e=>(0,s.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,s.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,s.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,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",className:"drop-shadow-lg",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),(0,s.jsx)("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),(0,s.jsx)("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})})]},e.id))}),r&&(0,s.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>a(null),children:(0,s.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,s.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,s.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,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,s.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,s.jsx)("p",{className:"text-white text-sm truncate",children:r.filename})})]})})]})}function e6(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-primary",children:(0,s.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 e8(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}let e9=["projects","agents","actions","navigation","settings"],e7={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 te(e){return e.isOpen?(0,s.jsx)(tt,{...e}):null}function tt(e){let{onClose:t,agents:r,projects:o=[],currentProject:l,onAgentSelect:i,onProjectSelect:c,onSpawnClick:d,onTaskCreate:x,onSettingsClick:u,onGeneralClick:m,customCommands:h=[]}=e,[p,g]=(0,n.useState)(""),[b,f]=(0,n.useState)(0),[j,y]=(0,n.useState)(null),v=(0,n.useRef)(b),w=(0,n.useRef)(null),N=(0,n.useRef)(null),k=(0,n.useRef)([]),[C,S]=(0,n.useState)("search"),[L,A]=(0,n.useState)(null),[M,W]=(0,n.useState)(""),[E,D]=(0,n.useState)("medium"),[B,T]=(0,n.useState)(!1),R=(0,n.useMemo)(()=>r.filter(e=>"offline"!==e.status&&"error"!==e.status),[r]),P=(0,n.useMemo)(()=>{if(!p.trim())return R;let e=p.toLowerCase();return R.filter(t=>t.name.toLowerCase().includes(e))},[R,p]),_=(0,n.useCallback)(()=>{S("task-select-agent"),g(""),f(0),A(null),W(""),D("medium")},[]),I=(0,n.useCallback)(async()=>{if(L&&M.trim()&&x){T(!0);try{await x({agentName:L.name,title:M.trim(),priority:E}),t()}catch(e){console.error("Failed to create task:",e)}finally{T(!1)}}},[L,M,E,x,t]);(0,n.useEffect)(()=>{v.current=b},[b]);let F=(0,n.useMemo)(()=>[...[...o].sort((e,t)=>{let r=e.id===l,s=t.id===l;if(r&&!s)return -1;if(!r&&s)return 1;let n=e.name||e.path.split("/").pop()||e.id,a=t.name||t.path.split("/").pop()||t.id;return n.localeCompare(a)}).map(e=>{let r=e.name||e.path.split("/").pop()||e.id,n=e.id===l;return{id:"project-".concat(e.id),label:r,description:n?"Current project • ".concat(e.agents.length," agents"):"".concat(e.agents.length," agents"),category:"projects",icon:n?(0,s.jsx)(tc,{}):(0,s.jsx)(ti,{}),action:()=>{null==c||c(e),t()}}}),...r.map(e=>({id:"agent-".concat(e.name),label:e.name,description:e.currentTask||e.status,category:"agents",icon:(0,s.jsx)(tr,{name:e.name}),action:()=>{i(e),t()}})),{id:"spawn-agent",label:"Spawn Agent",description:"Launch a new agent instance",category:"actions",icon:(0,s.jsx)(tn,{}),shortcut:"⌘⇧S",action:()=>{d(),t()}},{id:"broadcast",label:"Broadcast Message",description:"Send message to all agents",category:"actions",icon:(0,s.jsx)(ta,{}),action:()=>{t()}},...x?[{id:"assign-task",label:"Assign Task",description:"Create a task for an agent (creates bead)",category:"actions",icon:(0,s.jsx)(td,{}),shortcut:"⌘⇧T",action:()=>{_()}}]:[],{id:"nav-general",label:"Go to #general",description:"View all broadcast messages",category:"navigation",icon:(0,s.jsx)(to,{}),action:()=>{null==m||m(),t()}},...u?[{id:"settings",label:"Settings",description:"Configure dashboard preferences",category:"settings",icon:(0,s.jsx)(tl,{}),shortcut:"⌘,",action:()=>{u(),t()}}]:[],...h],[r,o,l,i,c,d,u,m,t,h]),U=(0,n.useMemo)(()=>{let e=F;if(j&&(e=e.filter(e=>e.category===j)),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},[F,p,j]),O=(0,n.useMemo)(()=>{let e={};for(let t of U)e[t.category]||(e[t.category]=[]),e[t.category].push(t);return e},[U]),z=(0,n.useMemo)(()=>e9.flatMap(e=>O[e]||[]),[O]);(0,n.useEffect)(()=>{f(0)},[p]),(0,n.useEffect)(()=>{g(""),f(0),y(null),S("search"),A(null),W(""),D("medium")},[]),(0,n.useEffect)(()=>{let e=k.current[b];e&&e.scrollIntoView({block:"nearest",behavior:"smooth"})},[b]),(0,n.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(),I());return}if("task-select-agent"===C){switch(e.key){case"ArrowDown":e.preventDefault(),f(e=>Math.min(e+1,P.length-1));break;case"ArrowUp":e.preventDefault(),f(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),P[v.current]&&(A(P[v.current]),S("task-details"),g(""));break;case"Escape":e.preventDefault(),S("search"),g("")}return}switch(e.key){case"ArrowDown":e.preventDefault(),f(e=>Math.min(e+1,z.length-1));break;case"ArrowUp":e.preventDefault(),f(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),z[v.current]&&z[v.current].action();break;case"Tab":e.preventDefault(),y(t=>{if(null===t)return e9[0];let r=e9.indexOf(t);return e.shiftKey?0===r?null:e9[r-1]:r===e9.length-1?null:e9[r+1]}),f(0);break;case"Escape":e.preventDefault(),j?(y(null),f(0)):t()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[z,P,C,b,j,t,I]);let H={projects:"Projects",agents:"Agents",actions:"Actions",navigation:"Navigation",settings:"Settings"},V=0;if("task-select-agent"===C)return(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,s.jsx)("button",{className:"p-1 rounded hover:bg-sidebar-border text-text-muted",onClick:()=>{S("search"),g("")},children:(0,s.jsx)(tx,{})}),(0,s.jsx)(td,{}),(0,s.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),f(0)}}),(0,s.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,s.jsx)("div",{className:"flex-1 overflow-y-auto p-2",ref:N,children:0===P.length?(0,s.jsx)("div",{className:"py-8 text-center text-text-muted text-sm",children:p?'No agents matching "'.concat(p,'"'):"No available agents"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider py-2 px-3",children:"Select Agent"}),P.map((e,t)=>{let r=(0,a.GW)(e.name);return(0,s.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===b?"bg-accent-light border border-accent/30":"bg-transparent hover:bg-sidebar-border","\n "),onClick:()=>{A(e),S("task-details"),g("")},onMouseEnter:()=>f(t),children:[(0,s.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,a.hP)(e.name)}),(0,s.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-text-muted truncate",children:e.currentTask||e.status})]})]},e.name)})]})})]})});if("task-details"===C&&L){let e=(0,a.GW)(L.name);return(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,s.jsx)("button",{className:"p-1 rounded hover:bg-sidebar-border text-text-muted",onClick:()=>{S("task-select-agent"),g("")},children:(0,s.jsx)(tx,{})}),(0,s.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,a.hP)(L.name)}),(0,s.jsxs)("span",{className:"text-base font-medium text-text-primary",children:["Assign task to ",L.name]})]}),(0,s.jsxs)("div",{className:"p-4 flex flex-col gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Task Title"}),(0,s.jsx)("input",{autoFocus:!0,type:"text",value:M,onChange:e=>W(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,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Priority"}),(0,s.jsx)("div",{className:"flex gap-2",children:Object.keys(e7).map(e=>{let t=e7[e],r=E===e;return(0,s.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:()=>D(e),children:t.label},e)})}),(0,s.jsxs)("p",{className:"text-xs text-text-dim mt-1.5",children:["Maps to beads priority P",e7[E].beadsPriority]})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2 border-t border-sidebar-border",children:[(0,s.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,s.jsx)("button",{type:"button",disabled:!M.trim()||B,onClick:I,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:B?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tu,{}),"Creating..."]}):(0,s.jsxs)(s.Fragment,{children:["Create Task",(0,s.jsx)("kbd",{className:"bg-black/20 rounded px-1 py-0.5 text-[10px]",children:"⌘↵"})]})})]})]})]})})}return(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,s.jsx)(ts,{}),j&&(0,s.jsxs)("button",{onClick:()=>{y(null),f(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:[H[j],(0,s.jsx)("span",{className:"text-accent-cyan/60",children:"\xd7"})]}),(0,s.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:j?"Search ".concat(H[j].toLowerCase(),"..."):"Search commands, agents...",value:p,onChange:e=>g(e.target.value)}),(0,s.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,s.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,s.jsx)("div",{className:"flex-1 overflow-y-auto p-2",ref:N,children:0===z.length?(0,s.jsxs)("div",{className:"py-8 text-center text-text-muted text-sm",children:['No results for "',p,'"']}):e9.map(e=>{let t=O[e];return(null==t?void 0:t.length)?(0,s.jsxs)("div",{className:"mb-2",children:[(0,s.jsx)("div",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider py-2 px-3",children:H[e]||e}),t.map(e=>{let t=V++;return(0,s.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===b?"bg-accent-light border border-accent/30":"bg-transparent hover:bg-sidebar-border","\n "),onClick:e.action,onMouseEnter:()=>f(t),children:[(0,s.jsx)("span",{className:"flex items-center justify-center w-7 h-7 text-text-muted",children:e.icon}),(0,s.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.label}),e.description&&(0,s.jsx)("span",{className:"text-xs text-text-muted truncate",children:e.description})]}),e.shortcut&&(0,s.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 tr(e){let{name:t}=e,r=(0,a.GW)(t);return(0,s.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,a.hP)(t)})}function ts(){return(0,s.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,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tn(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function ta(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,s.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 to(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),(0,s.jsx)("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),(0,s.jsx)("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),(0,s.jsx)("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}function tl(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 ti(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 tc(){return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:(0,s.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,s.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,s.jsx)("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})})]})}function td(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-muted",children:[(0,s.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,s.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}function tx(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"15 18 9 12 15 6"})})}function tu(){return(0,s.jsx)("svg",{className:"animate-spin",width:"14",height:"14",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}let tm=[{id:"claude",name:"Claude",command:"claude",description:"Claude Code CLI agent",icon:"\uD83E\uDD16"},{id:"codex",name:"Codex",command:"codex",description:"OpenAI Codex agent",icon:"⚡"},{id:"gemini",name:"Gemini",command:"gemini",description:"Google Gemini CLI agent",icon:"\uD83D\uDC8E"},{id:"opencode",name:"OpenCode",command:"opencode",description:"OpenCode AI agent",icon:"\uD83D\uDD37"},{id:"droid",name:"Droid",command:"droid",description:"Factory Droid agent",icon:"\uD83E\uDD16"},{id:"custom",name:"Custom",command:"",description:"Custom command",icon:"\uD83D\uDD27"}];function th(e){let{isOpen:t,onClose:r,onSpawn:o,existingAgents:l,isSpawning:i=!1,error:c}=e,[d,x]=(0,n.useState)(tm[0]),[u,m]=(0,n.useState)(""),[h,p]=(0,n.useState)(""),[g,b]=(0,n.useState)(""),[f,j]=(0,n.useState)(""),[y,v]=(0,n.useState)(!1),[w,N]=(0,n.useState)(""),[k,C]=(0,n.useState)(""),[S,L]=(0,n.useState)(["EXPLICIT_ASK"]),[A,M]=(0,n.useState)(null),W=(0,n.useRef)(null),E="custom"===d.id?h:d.command,D=(0,n.useMemo)(()=>(function(e){let t=e.trim().split(" ")[0].toLowerCase();return t.startsWith("claude")||"codex"===t||"opencode"===t||"gemini"===t||"droid"===t?"subagent":"process"})(E),[E]),B=(0,n.useCallback)(()=>{let e="claude"===d.id?"claude":d.id,t=1;for(;l.includes("".concat(e,"-").concat(t));)t++;return"".concat(e,"-").concat(t)},[d,l]);(0,n.useEffect)(()=>{t&&(x(tm[0]),m(""),p(""),b(""),j(""),v(!1),N(""),C(""),L(["EXPLICIT_ASK"]),M(null),setTimeout(()=>{var e;return null===(e=W.current)||void 0===e?void 0:e.focus()},100))},[t]);let T=(0,n.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]),R=async e=>{e.preventDefault();let t=u.trim()||B(),s=T(t);if(s){M(s);return}if(!E.trim()){M("Command is required");return}if(y&&!w){M("Please select an agent to shadow");return}M(null),await o({name:t,command:E.trim(),cwd:g.trim()||void 0,team:f.trim()||void 0,shadowMode:D,shadowOf:y?w:void 0,shadowAgent:k.trim()||void 0,shadowTriggers:y?S:void 0,shadowSpeakOn:y?S:void 0})&&r()};if(!t)return null;let P=u?(0,a.GW)(u):(0,a.GW)(B()),_=c||A;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.jsxs)("div",{className:"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:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-5 border-b border-border",children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Spawn New Agent"}),(0,s.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,s.jsx)(tp,{})})]}),(0,s.jsxs)("form",{onSubmit:R,className:"p-6",children:[(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",children:"Agent Type"}),(0,s.jsx)("div",{className:"grid grid-cols-3 gap-2",children:tm.map(e=>(0,s.jsxs)("button",{type:"button",className:"\n flex flex-col items-center gap-1 py-3 px-2 border-2 rounded-lg cursor-pointer font-sans transition-all duration-150\n ".concat(d.id===e.id?"bg-accent/10 border-accent":"bg-bg-hover border-transparent hover:bg-bg-active","\n "),onClick:()=>x(e),children:[(0,s.jsx)("span",{className:"text-2xl",children:e.icon}),(0,s.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-text-muted text-center",children:e.description})]},e.id))})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-name",children:"Agent Name"}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"shrink-0 w-10 h-10 rounded-lg flex items-center justify-center text-sm font-semibold",style:{backgroundColor:P.primary,color:P.text},children:(0,a.hP)(u||B())}),(0,s.jsx)("input",{ref:W,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:B(),value:u,onChange:e=>{m(e.target.value),M(null)},disabled:i})]})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsxs)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-team",children:["Team ",(0,s.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,s.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:f,onChange:e=>j(e.target.value),disabled:i})]}),"custom"===d.id&&(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-command",children:"Command"}),(0,s.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:h,onChange:e=>p(e.target.value),disabled:i})]}),(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsxs)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-cwd",children:["Working Directory ",(0,s.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,s.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:g,onChange:e=>b(e.target.value),disabled:i})]}),(0,s.jsxs)("div",{className:"mb-5 p-4 border border-border rounded-lg bg-bg-hover/50",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary",children:"Shadow Mode"}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:["Shadow execution: ","subagent"===D?"Subagent (in-process)":"Process (separate)"]})]}),(0,s.jsx)("button",{type:"button",className:"\n relative w-11 h-6 rounded-full transition-colors duration-200\n ".concat(y?"bg-accent":"bg-bg-active","\n "),onClick:()=>v(!y),disabled:i,"aria-pressed":y,children:(0,s.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(y?"translate-x-5":"translate-x-0","\n ")})})]}),y&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-text-secondary mb-2",htmlFor:"shadow-of",children:"Shadow Agent"}),(0,s.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:w,onChange:e=>N(e.target.value),disabled:i,children:[(0,s.jsx)("option",{value:"",children:"Select an agent to shadow..."}),l.map(e=>(0,s.jsx)("option",{value:e,children:e},e))]})]}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsxs)("label",{className:"block text-sm font-medium text-text-secondary mb-2",htmlFor:"shadow-agent",children:["Shadow Agent Profile ",(0,s.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,s.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:k,onChange:e=>C(e.target.value),disabled:i})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-text-secondary mb-2",children:"Speak When"}),(0,s.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,s.jsx)("button",{type:"button",className:"\n py-1.5 px-3 rounded-md text-xs font-medium transition-all duration-150 border\n ".concat(S.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:()=>{S.includes(e.value)?L(S.filter(t=>t!==e.value)):L([...S,e.value])},disabled:i,title:e.description,children:e.label},e.value))})]})]})]}),_&&(0,s.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,s.jsx)(tg,{}),(0,s.jsx)("span",{children:_})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2 border-t border-border",children:[(0,s.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:i,children:"Cancel"}),(0,s.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:i,children:i?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tf,{}),"Spawning..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tb,{}),"Spawn Agent"]})})]})]})]})})}function tp(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tg(){return(0,s.jsxs)("svg",{className:"shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function tb(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.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,s.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,s.jsx)("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),(0,s.jsx)("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}function tf(){return(0,s.jsx)("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function tj(e){let{isOpen:t,onClose:r,onSend:o,agents:l,isSending:i=!1,error:c,preselectedAgent:d}=e,[x,u]=(0,n.useState)(""),[m,h]=(0,n.useState)(""),[p,g]=(0,n.useState)(""),[b,f]=(0,n.useState)(null),j=(0,n.useRef)(null),y=(0,n.useRef)(null),v=(0,n.useMemo)(()=>{if(!p.trim())return l;let e=p.toLowerCase();return l.filter(t=>{var r,s;return t.name.toLowerCase().includes(e)||(null===(r=t.role)||void 0===r?void 0:r.toLowerCase().includes(e))||(null===(s=t.team)||void 0===s?void 0:s.toLowerCase().includes(e))})},[l,p]);(0,n.useEffect)(()=>{t&&(u(d||""),h(""),g(""),f(null),setTimeout(()=>{var e,t;d?null===(e=j.current)||void 0===e||e.focus():null===(t=y.current)||void 0===t||t.focus()},100))},[t,d]);let w=async e=>{if(e.preventDefault(),!x){f("Please select an agent");return}if(!m.trim()){f("Please enter a message");return}f(null),await o(x,m.trim())&&r()},N=(0,n.useCallback)(e=>{u(e),f(null),setTimeout(()=>{var e;return null===(e=j.current)||void 0===e?void 0:e.focus()},50)},[]);if(!t)return null;let k=c||b,C=l.find(e=>e.name===x),S=C?(0,a.GW)(C.name):null;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between p-5 border-b border-border shrink-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center",children:(0,s.jsx)(ty,{})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"New Conversation"}),(0,s.jsx)("p",{className:"m-0 text-xs text-text-muted",children:"Start a direct message with an agent"})]})]}),(0,s.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,s.jsx)(tv,{})})]}),(0,s.jsxs)("form",{onSubmit:w,className:"flex flex-col flex-1 overflow-hidden",children:[(0,s.jsxs)("div",{className:"p-5 border-b border-border",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",children:"To"}),x?(0,s.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-bg-hover rounded-lg",children:[(0,s.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,a.hP)(x)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-semibold text-text-primary",children:x}),(null==C?void 0:C.role)&&(0,s.jsx)("div",{className:"text-xs text-text-muted truncate",children:C.role})]}),(0,s.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,s.jsx)(tN,{})})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"relative mb-3",children:[(0,s.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-muted",children:(0,s.jsx)(tw,{})}),(0,s.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,s.jsx)("div",{className:"max-h-[200px] overflow-y-auto border border-border rounded-lg",children:0===v.length?(0,s.jsx)("div",{className:"p-4 text-center text-text-muted text-sm",children:p?"No agents found":"No agents available"}):(0,s.jsxs)("div",{className:"divide-y divide-border",children:[(0,s.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,s.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg bg-warning/20 flex items-center justify-center",children:(0,s.jsx)(tk,{})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"font-semibold text-text-primary",children:"Everyone"}),(0,s.jsx)("div",{className:"text-xs text-text-muted",children:"Broadcast to all agents"})]})]}),v.map(e=>{let t=(0,a.GW)(e.name);return(0,s.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,s.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,a.hP)(e.name)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-text-primary",children:e.name}),(0,s.jsx)("span",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-muted")})]}),(e.role||e.team)&&(0,s.jsxs)("div",{className:"text-xs text-text-muted truncate",children:[e.role,e.role&&e.team&&" - ",e.team]})]})]},e.name)})]})})]})]}),(0,s.jsxs)("div",{className:"p-5 flex-1 overflow-hidden flex flex-col",children:[(0,s.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"message",children:"Message"}),(0,s.jsx)("textarea",{ref:j,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:"*"===x?"Write a message to all agents...":x?"Write a message to ".concat(x,"..."):"Select an agent first...",value:m,onChange:e=>{h(e.target.value),f(null)},disabled:i||!x})]}),k&&(0,s.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,s.jsx)(tS,{}),(0,s.jsx)("span",{children:k})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 p-5 pt-0 border-t border-border",children:[(0,s.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:i,children:"Cancel"}),(0,s.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:i||!x||!m.trim(),children:i?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tL,{}),"Sending..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tC,{}),"Send Message"]})})]})]})]})})}function ty(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent",children:[(0,s.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,s.jsx)("line",{x1:"9",y1:"10",x2:"15",y2:"10"})]})}function tv(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tw(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tN(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"1 4 1 10 7 10"}),(0,s.jsx)("path",{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"})]})}function tk(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-warning",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,s.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 tC(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,s.jsx)("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function tS(){return(0,s.jsxs)("svg",{className:"shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function tL(){return(0,s.jsx)("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}var tA=r(3083),tM=r(4736);function tW(e){let{workspaces:t=[],onWorkspaceCreated:r,onOpenWorkspace:a,csrfToken:o,className:l=""}=e,[i,c]=(0,n.useState)([]),[d,x]=(0,n.useState)("idle"),[u,m]=(0,n.useState)(null),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(""),[f,j]=(0,n.useState)("all"),y=new Map;t.forEach(e=>{e.repositoryFullName&&y.set(e.repositoryFullName,e)});let v=(0,n.useCallback)(async()=>{x("loading"),m(null);try{let e=await fetch("/api/repos/accessible?perPage=100",{credentials:"include"});if(!e.ok){let t=await e.json();if("NANGO_NOT_CONNECTED"===t.code)throw Error("GitHub not connected. Please reconnect your GitHub account.");throw Error(t.error||"Failed to fetch repositories")}let t=await e.json();c(t.repositories||[]),x("loaded")}catch(e){console.error("Error fetching accessible repos:",e),m(e instanceof Error?e.message:"Failed to load repositories"),x("error")}},[]);(0,n.useEffect)(()=>{v()},[v]);let w=(0,n.useCallback)(async e=>{p(e),m(null);try{let t={"Content-Type":"application/json"};o&&(t["X-CSRF-Token"]=o);let s=await fetch("/api/workspaces/quick",{method:"POST",credentials:"include",headers:t,body:JSON.stringify({repositoryFullName:e})}),n=await s.json();if(!s.ok)throw Error(n.error||"Failed to create workspace");null==r||r(n.workspaceId,e)}catch(e){console.error("Error creating workspace:",e),m(e instanceof Error?e.message:"Failed to create workspace")}finally{p(null)}},[o,r]),N=i.filter(e=>{if(g&&!e.fullName.toLowerCase().includes(g.toLowerCase()))return!1;let t=y.has(e.fullName);return("with-workspace"!==f||!!t)&&("without-workspace"!==f||!t)});return"loading"===d?(0,s.jsx)("div",{className:"flex items-center justify-center py-12 ".concat(l),children:(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsxs)("svg",{className:"w-8 h-8 text-accent-cyan animate-spin mx-auto",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,s.jsx)("p",{className:"mt-4 text-text-muted",children:"Loading repositories..."})]})}):"error"===d?(0,s.jsx)("div",{className:"p-6 ".concat(l),children:(0,s.jsxs)("div",{className:"bg-error/10 border border-error/20 rounded-xl p-4 text-center",children:[(0,s.jsx)("div",{className:"w-12 h-12 mx-auto mb-3 bg-error/20 rounded-full flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-6 h-6 text-error",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,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,s.jsx)("p",{className:"text-error mb-4",children:u}),(0,s.jsx)("button",{onClick:v,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"})]})}):(0,s.jsxs)("div",{className:l,children:[(0,s.jsxs)("div",{className:"p-4 border-b border-border-subtle",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-text-primary mb-1",children:"Repository Access"}),(0,s.jsx)("p",{className:"text-sm text-text-muted",children:"Repositories you have access to on GitHub. Create workspaces to enable dashboard and chat access."})]}),u&&(0,s.jsx)("div",{className:"mx-4 mt-4 p-3 bg-error/10 border border-error/20 rounded-lg",children:(0,s.jsx)("p",{className:"text-error text-sm",children:u})}),(0,s.jsx)("div",{className:"p-4 border-b border-border-subtle",children:(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,s.jsxs)("div",{className:"flex-1 relative",children:[(0,s.jsx)(tE,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-muted"}),(0,s.jsx)("input",{type:"text",placeholder:"Search repositories...",value:g,onChange:e=>b(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"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("button",{onClick:()=>j("all"),className:"px-3 py-2 text-sm rounded-lg border transition-colors ".concat("all"===f?"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-muted hover:text-text-primary"),children:["All (",i.length,")"]}),(0,s.jsx)("button",{onClick:()=>j("with-workspace"),className:"px-3 py-2 text-sm rounded-lg border transition-colors ".concat("with-workspace"===f?"bg-success/10 border-success/30 text-success":"bg-bg-tertiary border-border-subtle text-text-muted hover:text-text-primary"),children:"With Access"}),(0,s.jsx)("button",{onClick:()=>j("without-workspace"),className:"px-3 py-2 text-sm rounded-lg border transition-colors ".concat("without-workspace"===f?"bg-warning/10 border-warning/30 text-warning":"bg-bg-tertiary border-border-subtle text-text-muted hover:text-text-primary"),children:"No Access"})]})]})}),(0,s.jsx)("div",{className:"max-h-[500px] overflow-y-auto",children:0===N.length?(0,s.jsx)("div",{className:"py-12 text-center text-text-muted",children:g?(0,s.jsxs)("p",{children:['No repositories match "',g,'"']}):"all"!==f?(0,s.jsx)("p",{children:"No repositories in this category"}):(0,s.jsx)("p",{children:"No repositories found. Connect your GitHub account to see your repos."})}):(0,s.jsx)("div",{className:"divide-y divide-border-subtle",children:N.map(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"},n=y.get(e.fullName),o=h===e.fullName;return(0,s.jsxs)("div",{className:"flex items-center gap-4 p-4 hover:bg-bg-hover/50 transition-colors",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-bg-tertiary border border-border-subtle flex items-center justify-center flex-shrink-0",children:(0,s.jsx)(tD,{className:"text-text-muted"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,s.jsx)("p",{className:"font-medium text-text-primary truncate",children:e.fullName}),e.isPrivate&&(0,s.jsx)("span",{className:"px-1.5 py-0.5 text-xs bg-bg-tertiary border border-border-subtle rounded text-text-muted",children:"Private"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"px-2 py-0.5 text-xs rounded-full border ".concat(r.color),children:r.label}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:e.defaultBranch})]})]}),(0,s.jsx)("div",{className:"flex-shrink-0",children:n?(0,s.jsx)("button",{onClick:()=>null==a?void 0:a(n.id),className:"px-4 py-2 text-sm rounded-lg border transition-colors ".concat("running"===n.status?"bg-success/10 border-success/30 text-success hover:bg-success/20":"provisioning"===n.status?"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-muted hover:bg-bg-hover"),children:"running"===n.status?"Open Dashboard":"provisioning"===n.status?"Starting...":"stopped"===n.status?"Start":"View"}):(0,s.jsx)("button",{onClick:()=>w(e.fullName),disabled:o,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:o?(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsxs)("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,s.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,s.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Creating..."]}):"Enable Access"})})]},e.id)})})}),(0,s.jsx)("div",{className:"p-4 border-t border-border-subtle bg-bg-tertiary/50",children:(0,s.jsxs)("p",{className:"text-xs text-text-muted text-center",children:["Showing ",N.length," of ",i.length," repositories you have GitHub access to.",(0,s.jsx)("button",{onClick:v,className:"ml-2 text-accent-cyan hover:underline",children:"Refresh"})]})})]})}function tE(e){let{className:t=""}=e;return(0,s.jsxs)("svg",{className:t,width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tD(e){let{className:t=""}=e;return(0,s.jsx)("svg",{className:t,width:"18",height:"18",viewBox:"0 0 16 16",fill:"currentColor",children:(0,s.jsx)("path",{d:"M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8z"})})}let tB=[{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:"OpenAI",displayName:"Codex",description:"Codex - OpenAI coding assistant",color:"#10A37F",cliCommand:"codex login",apiKeyUrl:"https://platform.openai.com/api-keys",apiKeyName:"API key",supportsOAuth:!0,supportsDeviceFlow:!0},{id:"google",name:"Google",displayName:"Gemini",description:"Gemini - Google AI coding assistant",color:"#4285F4",cliCommand:"gemini",apiKeyUrl:"https://aistudio.google.com/app/apikey",apiKeyName:"API key",supportsOAuth:!0},{id:"opencode",name:"OpenCode",displayName:"OpenCode",description:"OpenCode - AI coding assistant",color:"#00D4AA",cliCommand:"opencode",supportsOAuth:!0},{id:"droid",name:"Factory",displayName:"Droid",description:"Droid - Factory AI coding agent",color:"#6366F1",cliCommand:"droid",supportsOAuth:!0}];function tT(e){var t;let{workspaceId:r,csrfToken:a,onClose:o}=e,[l,i]=(0,n.useState)(null),[c,d]=(0,n.useState)([]),[x,u]=(0,n.useState)(!0),[m,h]=(0,n.useState)(null),[p,g]=(0,n.useState)("general"),[b,f]=(0,n.useState)({}),[j,y]=(0,n.useState)(null),[v,w]=(0,n.useState)(""),[N,k]=(0,n.useState)(null),[C,S]=(0,n.useState)({}),[L,A]=(0,n.useState)({}),[M,W]=(0,n.useState)({anthropic:!0}),[E,D]=(0,n.useState)(null),[B,T]=(0,n.useState)(""),[R,P]=(0,n.useState)(!1),[_,I]=(0,n.useState)(null),[F,U]=(0,n.useState)(null);(0,n.useEffect)(()=>{!async function(){u(!0),h(null);let[e,t,s]=await Promise.all([ei.xv.getWorkspaceDetails(r),ei.xv.getRepos(),ei.xv.getMe()]);if(e.success?(i(e.data),e.data.customDomain&&T(e.data.customDomain)):h(e.error),t.success&&d(t.data.repositories),s.success){let e={openai:"codex"},t={};s.data.connectedProviders.forEach(r=>{t[r.provider]=!0;let s=e[r.provider];s&&(t[s]=!0)}),f(t)}u(!1)}()},[r]);let O=e=>{k(null),y(e.id)},z=async e=>{if(!v.trim()){k("Please enter an API key");return}k(null),y(e.id);try{let t={"Content-Type":"application/json"};a&&(t["X-CSRF-Token"]=a);let r=await fetch("/api/onboarding/token/".concat(e.id),{method:"POST",credentials:"include",headers:t,body:JSON.stringify({token:v.trim()})});if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to connect")}f(t=>({...t,[e.id]:!0})),w(""),y(null),S(t=>({...t,[e.id]:!1}))}catch(e){k(e instanceof Error?e.message:"Failed to connect"),y(null)}},H=(0,n.useCallback)(async()=>{if(!l||!window.confirm("Are you sure you want to restart this workspace?"))return;let e=await ei.xv.restartWorkspace(l.id);if(e.success){let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else h(e.error)},[l,r]),V=(0,n.useCallback)(async()=>{if(!l||!window.confirm("Are you sure you want to stop this workspace?"))return;let e=await ei.xv.stopWorkspace(l.id);if(e.success){let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else h(e.error)},[l,r]),G=(0,n.useCallback)(async e=>{if(!l)return;let t=await ei.xv.addReposToWorkspace(l.id,[e]);if(t.success){let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else h(t.error)},[l,r]),K=(0,n.useCallback)(async e=>{if(!l)return;D(e),h(null);let t=await ei.xv.syncRepo(e);if(t.success){let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else h(t.error);D(null)},[l,r]),Z=(0,n.useCallback)(async()=>{if(!l||!B.trim())return;P(!0),I(null),U(null);let e=await ei.xv.setCustomDomain(l.id,B.trim());if(e.success){U(e.data.instructions);let t=await ei.xv.getWorkspaceDetails(r);t.success&&i(t.data)}else I(e.error);P(!1)},[l,B,r]),q=(0,n.useCallback)(async()=>{if(!l)return;P(!0),I(null);let e=await ei.xv.verifyCustomDomain(l.id);if(e.success){let t=await ei.xv.getWorkspaceDetails(r);t.success&&i(t.data),"active"===e.data.status&&U(null)}else I(e.error);P(!1)},[l,r]),J=(0,n.useCallback)(async()=>{if(!l||!window.confirm("Are you sure you want to remove the custom domain?"))return;P(!0);let e=await ei.xv.removeCustomDomain(l.id);if(e.success){T(""),U(null);let e=await ei.xv.getWorkspaceDetails(r);e.success&&i(e.data)}else I(e.error);P(!1)},[l,r]),Y=(0,n.useCallback)(async()=>{if(!l||!window.confirm('Are you sure you want to delete "'.concat(l.name,'"? This action cannot be undone.'))||!window.confirm("This will permanently delete all workspace data. Are you absolutely sure?"))return;let e=await ei.xv.deleteWorkspace(l.id);e.success?window.location.href="/app/onboarding?reason=deleted":h(e.error)},[l]);if(x)return(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"w-12 h-12 rounded-full border-2 border-accent-cyan/20 border-t-accent-cyan animate-spin"}),(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)("div",{className:"w-4 h-4 rounded-full bg-accent-cyan/40 animate-pulse"})})]}),(0,s.jsx)("span",{className:"ml-4 text-text-muted font-mono text-sm tracking-wide",children:"LOADING WORKSPACE CONFIG..."})]});if(m&&!l)return(0,s.jsx)("div",{className:"p-6",children:(0,s.jsxs)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error flex items-center gap-3",children:[(0,s.jsx)(tG,{}),(0,s.jsx)("span",{children:m})]})});if(!l)return null;let $=c.filter(e=>!l.repositories.some(t=>t.id===e.id)),X=[{id:"general",label:"General",icon:(0,s.jsx)(tU,{})},{id:"providers",label:"AI Providers",icon:(0,s.jsx)(tO,{})},{id:"repos",label:"Repositories",icon:(0,s.jsx)(tz,{})},{id:"github-access",label:"GitHub Access",icon:(0,s.jsx)(tV,{})},{id:"domain",label:"Domain",icon:(0,s.jsx)(tH,{})},{id:"danger",label:"Danger",icon:(0,s.jsx)(tG,{})}];return(0,s.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary",children:[(0,s.jsx)("div",{className:"flex gap-1 p-3 border-b border-border-subtle bg-gradient-to-b from-bg-tertiary to-bg-primary",children:X.map(e=>(0,s.jsxs)("button",{onClick:()=>g(e.id),className:"flex items-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium transition-all duration-200 ".concat(p===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,s.jsx)("span",{className:p===e.id?"text-accent-cyan":"text-text-muted",children:e.icon}),e.label]},e.id))}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[m&&(0,s.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,s.jsx)(tG,{}),(0,s.jsx)("span",{className:"flex-1",children:m}),(0,s.jsx)("button",{onClick:()=>h(null),className:"text-error/60 hover:text-error",children:(0,s.jsx)(t$,{})})]}),"general"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"Workspace Overview",subtitle:"Core configuration and status"}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsx)(tP,{label:"Name",value:l.name}),(0,s.jsx)(tP,{label:"Status",value:l.status.charAt(0).toUpperCase()+l.status.slice(1),valueColor:"running"===l.status?"text-success":"stopped"===l.status?"text-amber-400":"error"===l.status?"text-error":"text-text-muted",indicator:"running"===l.status}),(0,s.jsx)(tP,{label:"Public URL",value:l.publicUrl||"Not available",mono:!0}),(0,s.jsx)(tP,{label:"Compute Provider",value:l.computeProvider.charAt(0).toUpperCase()+l.computeProvider.slice(1)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)(tR,{title:"Actions",subtitle:"Manage workspace state"}),(0,s.jsxs)("div",{className:"flex gap-3 mt-4",children:["running"===l.status&&(0,s.jsx)(t_,{onClick:V,variant:"warning",icon:(0,s.jsx)(tZ,{}),children:"Stop Workspace"}),(0,s.jsx)(t_,{onClick:H,variant:"primary",icon:(0,s.jsx)(tq,{}),children:"Restart Workspace"})]})]})]}),"providers"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"AI Providers",subtitle:"Connect AI providers to spawn agents in this workspace"}),N&&(0,s.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,s.jsx)(tG,{}),(0,s.jsx)("span",{children:N})]}),(0,s.jsx)("div",{className:"space-y-4",children:tB.map(e=>(0,s.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle hover:border-border-medium transition-all duration-200",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-4",children:[(0,s.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center text-white font-bold text-lg shadow-lg",style:{backgroundColor:e.color,boxShadow:"0 4px 20px ".concat(e.color,"40")},children:e.displayName[0]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-base font-semibold text-text-primary",children:e.displayName}),(0,s.jsx)("p",{className:"text-sm text-text-muted",children:e.description})]})]}),b[e.id]?(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 bg-success/15 rounded-full border border-success/30",children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full bg-success animate-pulse"}),(0,s.jsx)("span",{className:"text-sm font-medium text-success",children:"Connected"})]}):null]}),!b[e.id]&&(0,s.jsx)("div",{className:"mt-5 pt-5 border-t border-border-subtle",children:j===e.id?M[e.id]?(0,s.jsx)(tM.$,{provider:{id:e.id,name:e.name,displayName:e.displayName,color:e.color},workspaceId:r,csrfToken:a,maxHeight:"350px",onSuccess:()=>{f(t=>({...t,[e.id]:!0})),y(null)},onCancel:()=>{y(null)},onError:e=>{k(e),y(null)},onConnectAnother:()=>{f(t=>({...t,[e.id]:!0})),y(null)}}):(0,s.jsx)(tA.j,{provider:{id:e.id,name:e.name,displayName:e.displayName,color:e.color,requiresUrlCopy:"codex"===e.id,supportsDeviceFlow:e.supportsDeviceFlow},workspaceId:r,csrfToken:a,useDeviceFlow:L[e.id]||!1,onSuccess:()=>{f(t=>({...t,[e.id]:!0})),y(null)},onCancel:()=>{y(null)},onError:e=>{k(e),y(null)}}):C[e.id]?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)("input",{type:"password",placeholder:"Enter ".concat(e.displayName," ").concat(e.apiKeyName||"API key"),value:j===e.id?v:"",onChange:t=>{y(e.id),w(t.target.value)},onFocus:()=>y(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,s.jsx)("button",{onClick:()=>z(e),disabled:j!==e.id||!v.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,s.jsxs)("p",{className:"text-xs text-text-muted",children:["Get your API key from"," ",(0,s.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,s.jsx)("button",{onClick:()=>S(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,s.jsxs)("div",{className:"space-y-3",children:["codex"===e.id&&(0,s.jsxs)("div",{className:"p-3 bg-accent-cyan/10 border border-accent-cyan/30 rounded-lg",children:[(0,s.jsx)("p",{className:"text-sm text-accent-cyan font-medium mb-1",children:"CLI-assisted authentication"}),(0,s.jsx)("p",{className:"text-xs text-accent-cyan/80",children:"Codex auth uses a CLI command to capture the OAuth callback locally. Click the button below and we'll show you a command with a unique session token to run in your terminal before signing in with OpenAI."})]}),e.supportsDeviceFlow&&(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs text-text-secondary cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:L[e.id]||!1,onChange:t=>A(r=>({...r,[e.id]:t.target.checked})),className:"w-4 h-4 rounded border-border-subtle bg-bg-card text-accent-cyan focus:ring-accent-cyan/30 cursor-pointer"}),"Use device flow (easier for containers/headless)"]}),(0,s.jsxs)("button",{onClick:()=>O(e),disabled:null!==j,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,s.jsx)(tK,{}),"Connect with ",e.displayName]}),e.apiKeyUrl&&(0,s.jsx)("button",{onClick:()=>S(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,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsx)("input",{type:"password",placeholder:"Enter ".concat(e.displayName," ").concat(e.apiKeyName||"API key"),value:j===e.id?v:"",onChange:t=>{y(e.id),w(t.target.value)},onFocus:()=>y(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,s.jsx)("button",{onClick:()=>z(e),disabled:j!==e.id||!v.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,s.jsxs)("p",{className:"text-xs text-text-muted",children:["Get your API key from"," ",(0,s.jsx)("a",{href:e.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan hover:underline",children:new URL(e.apiKeyUrl).hostname})]}),(0,s.jsxs)("p",{className:"text-xs text-amber-400/80",children:["OAuth not available for ",e.displayName," in container environments"]})]})}),(0,s.jsx)("div",{className:"mt-4 pt-4 border-t border-border-subtle",children:(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:["CLI: ",(0,s.jsx)("code",{className:"px-2 py-1 bg-bg-card rounded font-mono",children:e.cliCommand})]})})]},e.id))})]}),"repos"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"Connected Repositories",subtitle:"Repositories linked to this workspace"}),(0,s.jsx)("div",{className:"space-y-3",children:l.repositories.length>0?l.repositories.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-bg-card flex items-center justify-center",children:(0,s.jsx)(tz,{})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.fullName}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:e.lastSyncedAt?"Synced ".concat(new Date(e.lastSyncedAt).toLocaleDateString()):"Not synced"})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("button",{onClick:()=>K(e.id),disabled:E===e.id||"running"!==l.status,className:"px-3 py-1.5 bg-accent-cyan/10 border border-accent-cyan/30 text-accent-cyan rounded-lg text-xs font-semibold hover:bg-accent-cyan/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center gap-1.5",title:"running"!==l.status?"Workspace must be running to sync":"Sync repository",children:E===e.id?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tQ,{spinning:!0}),"Syncing..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tQ,{}),"Sync"]})}),(0,s.jsx)(tI,{status:e.syncStatus})]})]},e.id)):(0,s.jsxs)("div",{className:"p-6 bg-bg-tertiary rounded-lg border border-border-subtle border-dashed text-center",children:[(0,s.jsx)(tz,{className:"w-8 h-8 mx-auto mb-3 text-text-muted"}),(0,s.jsx)("p",{className:"text-sm text-text-muted",children:"No repositories connected"})]})}),$.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tR,{title:"Available Repositories",subtitle:"Add more repositories to this workspace"}),(0,s.jsx)("div",{className:"space-y-3",children:$.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-border-subtle hover:border-accent-cyan/30 transition-colors",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-bg-card flex items-center justify-center",children:(0,s.jsx)(tz,{})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.fullName}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:e.isPrivate?"Private":"Public"})]})]}),(0,s.jsx)("button",{onClick:()=>G(e.id),className:"px-4 py-2 bg-accent-cyan/10 border border-accent-cyan/30 text-accent-cyan rounded-lg text-xs font-semibold hover:bg-accent-cyan/20 transition-colors",children:"Add to Workspace"})]},e.id))})]})]}),"github-access"===p&&(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsx)(tR,{title:"GitHub Repository Access",subtitle:"Repositories you have access to via your GitHub account"}),(0,s.jsx)(tW,{workspaces:l&&(null===(t=l.repositories)||void 0===t?void 0:t.length)>0?[{id:l.id,name:l.name,repositoryFullName:l.repositories[0].fullName,status:l.status}]:[],onWorkspaceCreated:(e,t)=>{ei.xv.getWorkspaceDetails(e).then(e=>{e.success&&i(e.data)})},onOpenWorkspace:e=>{o&&o()},csrfToken:a,className:"bg-bg-tertiary rounded-xl border border-border-subtle overflow-hidden"})]}),"domain"===p&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(tR,{title:"Custom Domain",subtitle:"Connect your own domain to this workspace"}),(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-accent-purple/20 flex items-center justify-center",children:(0,s.jsx)(tH,{className:"text-accent-purple"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:"Premium Feature"}),(0,s.jsx)("p",{className:"text-xs text-text-secondary",children:"Requires Team or Enterprise plan"})]})]})}),l.customDomain?(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide font-semibold",children:"Current Domain"}),(0,s.jsx)(tI,{status:l.customDomainStatus||"pending"})]}),(0,s.jsx)("p",{className:"text-lg font-mono text-text-primary",children:l.customDomain})]}),"pending"===l.customDomainStatus&&(0,s.jsx)(t_,{onClick:q,disabled:R,variant:"primary",icon:(0,s.jsx)(tJ,{}),fullWidth:!0,children:R?"Verifying...":"Verify DNS Configuration"}),(0,s.jsx)(t_,{onClick:J,disabled:R,variant:"danger",icon:(0,s.jsx)(tY,{}),fullWidth:!0,children:"Remove Custom Domain"})]}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-2 block",children:"Domain Name"}),(0,s.jsx)("input",{type:"text",value:B,onChange:e=>T(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,s.jsx)(t_,{onClick:Z,disabled:R||!B.trim(),variant:"primary",icon:(0,s.jsx)(tH,{}),fullWidth:!0,children:R?"Setting up...":"Set Custom Domain"})]}),_&&(0,s.jsx)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:_}),F&&(0,s.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle space-y-4",children:[(0,s.jsxs)("h4",{className:"text-sm font-semibold text-text-primary flex items-center gap-2",children:[(0,s.jsx)(tX,{}),"DNS Configuration Required"]}),(0,s.jsx)("p",{className:"text-xs text-text-secondary",children:"Add the following DNS record to your domain provider:"}),(0,s.jsxs)("div",{className:"grid grid-cols-3 gap-3",children:[(0,s.jsx)(tF,{label:"Type",value:F.type}),(0,s.jsx)(tF,{label:"Name",value:F.name}),(0,s.jsx)(tF,{label:"Value",value:F.value})]})]})]}),"danger"===p&&(0,s.jsx)("div",{className:"space-y-8",children:(0,s.jsxs)("div",{className:"p-6 bg-error/5 border-2 border-error/20 rounded-xl",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,s.jsx)("div",{className:"w-10 h-10 rounded-lg bg-error/20 flex items-center justify-center",children:(0,s.jsx)(tG,{className:"text-error"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-base font-semibold text-error",children:"Danger Zone"}),(0,s.jsx)("p",{className:"text-xs text-text-secondary",children:"These actions are destructive and cannot be undone"})]})]}),(0,s.jsx)("div",{className:"p-5 border border-error/30 rounded-lg bg-bg-primary",children:(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:"Delete Workspace"}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-1",children:"Permanently delete this workspace and all its data"})]}),(0,s.jsx)("button",{onClick:Y,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 tR(e){let{title:t,subtitle:r}=e;return(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:t}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-1",children:r})]})}function tP(e){let{label:t,value:r,valueColor:n="text-text-primary",mono:a=!1,indicator:o=!1}=e;return(0,s.jsxs)("div",{className:"p-4 bg-bg-tertiary rounded-lg border border-border-subtle",children:[(0,s.jsx)("label",{className:"text-xs text-text-muted uppercase tracking-wide font-medium",children:t}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[o&&(0,s.jsx)("div",{className:"w-2 h-2 rounded-full bg-success animate-pulse"}),(0,s.jsx)("p",{className:"text-sm font-medium ".concat(n," ").concat(a?"font-mono":""," break-all"),children:r})]})]})}function t_(e){let{children:t,onClick:r,disabled:n,variant:a,icon:o,fullWidth:l}=e;return(0,s.jsxs)("button",{onClick:r,disabled:n,className:"".concat(l?"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:[o,t]})}function tI(e){let{status:t}=e;return(0,s.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 tF(e){let{label:t,value:r}=e;return(0,s.jsxs)("div",{className:"p-3 bg-bg-card rounded-lg",children:[(0,s.jsx)("label",{className:"text-xs text-text-muted block mb-1",children:t}),(0,s.jsx)("p",{className:"font-mono text-sm text-text-primary break-all",children:r})]})}function tU(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 tO(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,s.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,s.jsx)("path",{d:"M2 12l10 5 10-5"})]})}function tz(e){let{className:t=""}=e;return(0,s.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,s.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 tH(e){let{className:t=""}=e;return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),(0,s.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 tV(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.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"})})}function tG(e){let{className:t=""}=e;return(0,s.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,s.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,s.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function tK(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,s.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function tZ(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("rect",{x:"6",y:"6",width:"12",height:"12"})})}function tq(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M23 4v6h-6"}),(0,s.jsx)("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function tJ(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function tY(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.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 t$(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tX(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function tQ(){let{spinning:e=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:e?"animate-spin":"",children:[(0,s.jsx)("path",{d:"M23 4v6h-6"}),(0,s.jsx)("path",{d:"M1 20v-6h6"}),(0,s.jsx)("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10"}),(0,s.jsx)("path",{d:"M20.49 15a9 9 0 0 1-14.85 3.36L1 14"})]})}let t0={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"},t1={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 t2(e){var t;let{workspaceId:r,currentUserId:a}=e,[o,l]=(0,n.useState)([]),[i,c]=(0,n.useState)([]),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!0),[h,p]=(0,n.useState)(!0),[g,b]=(0,n.useState)(null),[f,j]=(0,n.useState)(null),[y,v]=(0,n.useState)(!1),[w,N]=(0,n.useState)(""),[k,C]=(0,n.useState)("member"),[S,L]=(0,n.useState)(!1),[A,M]=(0,n.useState)(null),[W,E]=(0,n.useState)(null);(0,n.useEffect)(()=>{(async function(){m(!0),b(null);let[e,t]=await Promise.all([ei.xv.getWorkspaceMembers(r),ei.xv.getPendingInvites()]);e.success?l(e.data.members):b(e.error),t.success&&c(t.data.invites.filter(e=>e.workspaceId===r)),m(!1)})()},[r]),(0,n.useEffect)(()=>{(async function(){p(!0);let e=await ei.xv.getRepoCollaborators(r);e.success&&x(e.data.collaborators||[]),p(!1)})()},[r]);let D=(0,n.useCallback)(async()=>{if(!w.trim()){M("Please enter a GitHub username");return}L(!0),M(null);let e=await ei.xv.inviteMember(r,w.trim(),k);if(e.success){let e=await ei.xv.getWorkspaceMembers(r);e.success&&l(e.data.members),N(""),v(!1),j("Invitation sent to ".concat(w)),setTimeout(()=>j(null),3e3)}else M(e.error);L(!1)},[r,w,k]),B=(0,n.useCallback)(async(e,t)=>{E(e);let s=await ei.xv.updateMemberRole(r,e,t);s.success?(l(r=>r.map(r=>r.id===e?{...r,role:t}:r)),j("Role updated successfully"),setTimeout(()=>j(null),3e3)):b(s.error),E(null)},[r]),T=(0,n.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 s=await ei.xv.removeMember(r,e.id);s.success?(l(t=>t.filter(t=>t.id!==e.id)),j("Member removed successfully"),setTimeout(()=>j(null),3e3)):b(s.error)},[r]),R=null===(t=o.find(e=>e.userId===a))||void 0===t?void 0:t.role,P="owner"===R||"admin"===R;return u?(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsx)(t5,{}),(0,s.jsx)("span",{className:"ml-3 text-text-muted",children:"Loading team members..."})]}):(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:"Team Members"}),(0,s.jsxs)("p",{className:"text-xs text-text-muted mt-1",children:[o.length," member",1!==o.length?"s":""]})]}),P&&(0,s.jsxs)("button",{onClick:()=>v(!y),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,s.jsx)(t4,{}),"Invite Member"]})]}),g&&(0,s.jsxs)("div",{className:"p-3 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:[g,(0,s.jsx)("button",{onClick:()=>b(null),className:"ml-2 text-error/70 hover:text-error",children:"\xd7"})]}),f&&(0,s.jsx)("div",{className:"p-3 bg-success/10 border border-success/30 rounded-lg text-success text-sm",children:f}),y&&(0,s.jsxs)("div",{className:"p-4 bg-bg-tertiary rounded-lg border border-border-subtle space-y-4",children:[(0,s.jsx)("h4",{className:"text-sm font-medium text-text-primary",children:"Invite New Member"}),A&&(0,s.jsx)("div",{className:"p-2 bg-error/10 border border-error/30 rounded text-error text-xs",children:A}),(0,s.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"GitHub Username"}),(0,s.jsx)("input",{type:"text",value:w,onChange:e=>N(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,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Role"}),(0,s.jsxs)("select",{value:k,onChange:e=>C(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,s.jsx)("option",{value:"admin",children:"Admin"}),(0,s.jsx)("option",{value:"member",children:"Member"}),(0,s.jsx)("option",{value:"viewer",children:"Viewer"})]})]})]}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:t1[k]}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-2",children:[(0,s.jsx)("button",{onClick:D,disabled:S||!w.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:S?"Sending...":"Send Invitation"}),(0,s.jsx)("button",{onClick:()=>{v(!1),N(""),M(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,s.jsx)("div",{className:"space-y-2",children:o.map(e=>{var t,r,n,o,l,i;return(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3",children:[(null===(t=e.user)||void 0===t?void 0:t.avatarUrl)?(0,s.jsx)("img",{src:e.user.avatarUrl,alt:e.user.githubUsername,className:"w-9 h-9 md:w-10 md:h-10 rounded-full"}):(0,s.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===(o=e.user)||void 0===o?void 0:null===(n=o.githubUsername)||void 0===n?void 0:null===(r=n[0])||void 0===r?void 0:r.toUpperCase())||"?"}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:(null===(l=e.user)||void 0===l?void 0:l.githubUsername)||"Unknown User"}),e.isPending&&(0,s.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,s.jsx)("span",{className:"text-xs text-text-muted",children:"(you)"})]}),(null===(i=e.user)||void 0===i?void 0:i.email)&&(0,s.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.user.email})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 ml-12 sm:ml-0",children:[P&&"owner"!==e.role&&e.userId!==a?(0,s.jsxs)("select",{value:e.role,onChange:t=>B(e.id,t.target.value),disabled:W===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(t0[e.role]," focus:outline-none"),children:[(0,s.jsx)("option",{value:"admin",children:"Admin"}),(0,s.jsx)("option",{value:"member",children:"Member"}),(0,s.jsx)("option",{value:"viewer",children:"Viewer"})]}):(0,s.jsx)("span",{className:"px-2 md:px-3 py-1 md:py-1.5 rounded-full text-[10px] md:text-xs font-medium ".concat(t0[e.role]),children:e.role.charAt(0).toUpperCase()+e.role.slice(1)}),P&&"owner"!==e.role&&e.userId!==a&&(0,s.jsx)("button",{onClick:()=>T(e),className:"p-1.5 text-text-muted hover:text-error rounded transition-colors",title:"Remove member",children:(0,s.jsx)(t3,{})})]})]},e.id)})}),(d.length>0||h)&&(0,s.jsxs)("div",{className:"mt-8",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:"Repo Collaborators"}),(0,s.jsx)("span",{className:"px-2 py-0.5 bg-accent-purple/10 text-accent-purple text-[10px] rounded-full",children:"GitHub Access"})]}),(0,s.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."}),h?(0,s.jsxs)("div",{className:"flex items-center gap-2 py-4",children:[(0,s.jsx)(t5,{}),(0,s.jsx)("span",{className:"text-sm text-text-muted",children:"Loading collaborators..."})]}):(0,s.jsx)("div",{className:"space-y-2",children:d.map(e=>{var t;return(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3",children:[e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.login,className:"w-9 h-9 md:w-10 md:h-10 rounded-full"}):(0,s.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,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.login}),(0,s.jsx)("span",{className:"text-[10px] px-2 py-0.5 bg-accent-purple/10 text-accent-purple rounded-full",children:"via GitHub"})]}),(0,s.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,s.jsx)("div",{className:"flex items-center gap-2 sm:gap-3 ml-12 sm:ml-0",children:(0,s.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,s.jsxs)("div",{className:"mt-8",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Your Pending Invitations"}),(0,s.jsx)("div",{className:"space-y-2",children:i.map(e=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-accent-cyan/30",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.workspaceName}),(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:["Invited by ",e.invitedBy," as ",e.role]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("button",{onClick:async()=>{(await ei.xv.acceptInvite(e.id)).success&&(c(t=>t.filter(t=>t.id!==e.id)),j("Invitation accepted!"),setTimeout(()=>j(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,s.jsx)("button",{onClick:async()=>{(await ei.xv.declineInvite(e.id)).success&&c(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,s.jsxs)("div",{className:"mt-8 p-4 bg-bg-tertiary/50 rounded-lg",children:[(0,s.jsx)("h4",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-3",children:"Role Permissions"}),(0,s.jsx)("div",{className:"space-y-2",children:Object.entries(t1).map(e=>{let[t,r]=e;return(0,s.jsxs)("div",{className:"flex items-start gap-2",children:[(0,s.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium ".concat(t0[t]," shrink-0"),children:t.charAt(0).toUpperCase()+t.slice(1)}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:r})]},t)})})]})]})}function t5(){return(0,s.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function t4(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function t3(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.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 t6={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"},t8={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"},t9={free:0,pro:1,team:2,enterprise:3};function t7(e){let{onUpgrade:t}=e,[r,a]=(0,n.useState)([]),[o,l]=(0,n.useState)("free"),[i,c]=(0,n.useState)(null),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!0),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(null),[f,j]=(0,n.useState)("month"),[y,v]=(0,n.useState)(null),[w,N]=(0,n.useState)(!1),[k,C]=(0,n.useState)(!1),[S,L]=(0,n.useState)(!1);(0,n.useEffect)(()=>{!async function(){m(!0),p(null);let[e,t,r]=await Promise.all([ei.xv.getBillingPlans(),ei.xv.getSubscription(),ei.xv.getInvoices()]);if(e.success&&a(e.data.plans),t.success){var s;l(t.data.tier),c(t.data.subscription),(null===(s=t.data.subscription)||void 0===s?void 0:s.interval)&&j(t.data.subscription.interval)}r.success&&x(r.data.invoices),e.success||p(e.error),m(!1)}()},[]);let A=(0,n.useCallback)(async e=>{v(e);let t=await ei.xv.createCheckoutSession(e,f);t.success&&t.data.checkoutUrl?window.location.href=t.data.checkoutUrl:t.success||(p(t.error),v(null))},[f]),M=(0,n.useCallback)(async()=>{N(!0);let e=await ei.xv.createBillingPortal();e.success&&e.data.portalUrl?window.location.href=e.data.portalUrl:e.success||p(e.error),N(!1)},[]),W=(0,n.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;C(!0);let e=await ei.xv.cancelSubscription();e.success?(c(e=>e?{...e,cancelAtPeriodEnd:!0}:null),b(e.data.message),setTimeout(()=>b(null),5e3)):p(e.error),C(!1)},[]),E=(0,n.useCallback)(async()=>{L(!0);let e=await ei.xv.resumeSubscription();e.success?(c(e=>e?{...e,cancelAtPeriodEnd:!1}:null),b(e.data.message),setTimeout(()=>b(null),3e3)):p(e.error),L(!1)},[]);return u?(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsx)(re,{}),(0,s.jsx)("span",{className:"ml-3 text-text-muted",children:"Loading billing information..."})]}):(0,s.jsxs)("div",{className:"space-y-8",children:[h&&(0,s.jsxs)("div",{className:"p-3 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:[h,(0,s.jsx)("button",{onClick:()=>p(null),className:"ml-2 text-error/70 hover:text-error",children:"\xd7"})]}),g&&(0,s.jsx)("div",{className:"p-3 bg-success/10 border border-success/30 rounded-lg text-success text-sm",children:g}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Current Plan"}),(0,s.jsx)("div",{className:"p-4 md:p-6 rounded-lg border-2 ".concat(t6[o]),children:(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("h4",{className:"text-lg md:text-xl font-bold text-text-primary capitalize",children:[o," Plan"]}),i?(0,s.jsx)("p",{className:"text-xs md:text-sm text-text-secondary mt-1",children:i.cancelAtPeriodEnd?(0,s.jsxs)("span",{className:"text-amber-400",children:["Cancels on ",new Date(i.currentPeriodEnd).toLocaleDateString()]}):(0,s.jsxs)(s.Fragment,{children:["Renews on ",new Date(i.currentPeriodEnd).toLocaleDateString(),(0,s.jsxs)("span",{className:"text-text-muted ml-2",children:["(","year"===i.interval?"Yearly":"Monthly",")"]})]})}):(0,s.jsx)("p",{className:"text-xs md:text-sm text-text-muted mt-1",children:t8[o]||t8.free})]}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[i&&!i.cancelAtPeriodEnd&&(0,s.jsx)("button",{onClick:W,disabled:k,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:k?"Canceling...":"Cancel Plan"}),(null==i?void 0:i.cancelAtPeriodEnd)&&(0,s.jsx)("button",{onClick:E,disabled:S,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:S?"Resuming...":"Resume Plan"}),i&&(0,s.jsx)("button",{onClick:M,disabled:w,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:w?"Opening...":"Manage Billing"})]})]})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-center gap-4",children:[(0,s.jsx)("span",{className:"text-sm font-medium ".concat("month"===f?"text-text-primary":"text-text-muted"),children:"Monthly"}),(0,s.jsx)("button",{onClick:()=>j(e=>"month"===e?"year":"month"),className:"relative w-14 h-7 bg-bg-tertiary rounded-full transition-colors",children:(0,s.jsx)("span",{className:"absolute top-1 w-5 h-5 bg-accent-cyan rounded-full transition-transform ".concat("year"===f?"translate-x-8":"translate-x-1")})}),(0,s.jsxs)("span",{className:"text-sm font-medium ".concat("year"===f?"text-text-primary":"text-text-muted"),children:["Yearly",(0,s.jsx)("span",{className:"ml-1 text-xs text-success",children:"(Save 20%)"})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Available Plans"}),(0,s.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=(t9[e.tier]||0)>(t9[o]||0),r=e.recommended&&t,n=(t9[e.tier]||0)<(t9[o]||0);return(0,s.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,s.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,s.jsx)("h4",{className:"text-lg font-bold text-text-primary",children:e.name}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-1 mb-4",children:e.description}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsxs)("span",{className:"text-3xl font-bold text-text-primary",children:["$","year"===f?e.price.yearly:e.price.monthly]}),(0,s.jsxs)("span",{className:"text-text-muted",children:["/","year"===f?"year":"month"]})]}),(0,s.jsx)("ul",{className:"space-y-2 mb-6",children:e.features.slice(0,5).map((e,t)=>(0,s.jsxs)("li",{className:"flex items-start gap-2 text-sm text-text-secondary",children:[(0,s.jsx)(rt,{className:"text-success shrink-0 mt-0.5"}),e]},t))}),o===e.tier?(0,s.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,s.jsx)("button",{onClick:()=>A(e.tier),disabled:null!==y,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:y===e.tier?"Loading...":n?"Downgrade":"Upgrade"})]},e.tier)})})]}),(0,s.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,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-base md:text-lg font-bold text-text-primary",children:"Enterprise"}),(0,s.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,s.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"})]})}),d.length>0&&(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Billing History"}),(0,s.jsx)("div",{className:"hidden md:block bg-bg-tertiary rounded-lg overflow-hidden",children:(0,s.jsxs)("table",{className:"w-full",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"border-b border-border-subtle",children:[(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Invoice"}),(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Date"}),(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Amount"}),(0,s.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Status"}),(0,s.jsx)("th",{className:"text-right px-4 py-3 text-xs font-semibold text-text-muted uppercase"})]})}),(0,s.jsx)("tbody",{children:d.map(e=>(0,s.jsxs)("tr",{className:"border-b border-border-subtle last:border-0",children:[(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-text-primary font-medium",children:e.number}),(0,s.jsx)("td",{className:"px-4 py-3 text-sm text-text-secondary",children:new Date(e.date).toLocaleDateString()}),(0,s.jsxs)("td",{className:"px-4 py-3 text-sm text-text-primary",children:["$",(e.amount/100).toFixed(2)]}),(0,s.jsx)("td",{className:"px-4 py-3",children:(0,s.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,s.jsx)("td",{className:"px-4 py-3 text-right",children:e.pdfUrl&&(0,s.jsx)("a",{href:e.pdfUrl,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-accent-cyan hover:underline",children:"Download"})})]},e.id))})]})}),(0,s.jsx)("div",{className:"md:hidden space-y-3",children:d.map(e=>(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.number}),(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"text-text-muted",children:new Date(e.date).toLocaleDateString()}),(0,s.jsxs)("span",{className:"text-text-primary font-medium",children:["$",(e.amount/100).toFixed(2)]})]}),e.pdfUrl&&(0,s.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 re(){return(0,s.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function rt(e){let{className:t=""}=e;return(0,s.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,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}let rr={theme:"dark",compactMode:!1,showTimestamps:!0,soundEnabled:!0,notificationsEnabled:!0,autoScrollMessages:!0};function rs(e){var t,r;let{currentUserId:a,initialTab:o="dashboard",onClose:l}=e,[i,c]=(0,n.useState)(o),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(null),[h,p]=(0,n.useState)(!0),[g,b]=(0,n.useState)(rr);(0,n.useEffect)(()=>{(async function(){p(!0);let e=await ei.xv.getWorkspaceSummary();e.success&&e.data.workspaces.length>0&&(x(e.data.workspaces),m(e.data.workspaces[0].id)),p(!1)})()},[]),(0,n.useEffect)(()=>{let e=localStorage.getItem("dashboard-settings");if(e)try{b({...rr,...JSON.parse(e)})}catch(e){}},[]);let f=(e,t)=>{let r={...g,[e]:t};b(r),localStorage.setItem("dashboard-settings",JSON.stringify(r)),"theme"===e&&document.documentElement.setAttribute("data-theme",t)},j=[{id:"dashboard",label:"Dashboard",icon:(0,s.jsx)(rd,{})},{id:"workspace",label:"Workspace",icon:(0,s.jsx)(rx,{})},{id:"team",label:"Team",icon:(0,s.jsx)(ru,{})},{id:"billing",label:"Billing",icon:(0,s.jsx)(rm,{})}];return(0,s.jsxs)("div",{className:"fixed inset-0 z-50 bg-bg-deep",children:[(0,s.jsxs)("div",{className:"absolute inset-0 opacity-30",children:[(0,s.jsx)("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top_right,_rgba(0,217,255,0.08)_0%,_transparent_50%)]"}),(0,s.jsx)("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_bottom_left,_rgba(168,85,247,0.06)_0%,_transparent_50%)]"})]}),(0,s.jsxs)("div",{className:"relative h-full flex flex-col",children:[(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3 md:gap-4",children:[(0,s.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,s.jsx)(rc,{className:"text-white w-4 h-4 md:w-[18px] md:h-[18px]"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{className:"text-base md:text-lg font-bold text-text-primary tracking-tight",children:"Settings"}),(0,s.jsx)("p",{className:"text-[10px] md:text-xs text-text-muted hidden sm:block",children:"Manage your workspace and preferences"})]})]}),(0,s.jsx)("button",{onClick:l,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,s.jsx)(rh,{})})]}),(0,s.jsx)("div",{className:"border-b border-border-subtle bg-bg-secondary/50",children:(0,s.jsx)("div",{className:"flex justify-center overflow-x-auto scrollbar-hide",children:j.map(e=>(0,s.jsxs)("button",{onClick:()=>c(e.id),className:"flex items-center gap-2 px-6 py-3 text-sm font-medium transition-all whitespace-nowrap ".concat(i===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,s.jsx)("span",{className:i===e.id?"text-accent-cyan":"text-text-muted",children:e.icon}),e.label]},e.id))})}),("workspace"===i||"team"===i)&&d.length>0&&(0,s.jsx)("div",{className:"px-4 py-2 border-b border-border-subtle bg-bg-tertiary/50",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full shrink-0 ".concat((null===(t=d.find(e=>e.id===u))||void 0===t?void 0:t.status)==="running"?"bg-success":(null===(r=d.find(e=>e.id===u))||void 0===r?void 0:r.status)==="stopped"?"bg-amber-400":"bg-text-muted")}),1===d.length?(0,s.jsx)("span",{className:"text-sm text-text-primary",children:d[0].name}):(0,s.jsx)("select",{value:u||"",onChange:e=>m(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,s.jsx)("option",{value:e.id,children:e.name},e.id))})]})}),(0,s.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,s.jsx)("main",{className:"h-full overflow-y-auto",children:(0,s.jsxs)("div",{className:"max-w-4xl mx-auto p-4 md:p-8",children:["dashboard"===i&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(rn,{title:"Dashboard Settings",subtitle:"Customize your dashboard experience"}),(0,s.jsxs)(ra,{title:"Appearance",icon:(0,s.jsx)(rp,{}),children:[(0,s.jsx)(ro,{label:"Theme",description:"Choose your preferred color scheme",children:(0,s.jsxs)("select",{value:g.theme,onChange:e=>f("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,s.jsx)("option",{value:"dark",children:"Dark"}),(0,s.jsx)("option",{value:"light",children:"Light"}),(0,s.jsx)("option",{value:"system",children:"System"})]})}),(0,s.jsx)(ro,{label:"Compact Mode",description:"Reduce spacing and show more content",children:(0,s.jsx)(rl,{checked:g.compactMode,onChange:e=>f("compactMode",e)})}),(0,s.jsx)(ro,{label:"Show Timestamps",description:"Display timestamps on messages",children:(0,s.jsx)(rl,{checked:g.showTimestamps,onChange:e=>f("showTimestamps",e)})})]}),(0,s.jsxs)(ra,{title:"Notifications",icon:(0,s.jsx)(rg,{}),children:[(0,s.jsx)(ro,{label:"Sound Effects",description:"Play sounds for new messages",children:(0,s.jsx)(rl,{checked:g.soundEnabled,onChange:e=>f("soundEnabled",e)})}),(0,s.jsx)(ro,{label:"Browser Notifications",description:"Show desktop notifications",children:(0,s.jsx)(rl,{checked:g.notificationsEnabled,onChange:e=>f("notificationsEnabled",e)})})]}),(0,s.jsx)(ra,{title:"Behavior",icon:(0,s.jsx)(rc,{}),children:(0,s.jsx)(ro,{label:"Auto-scroll Messages",description:"Automatically scroll to new messages",children:(0,s.jsx)(rl,{checked:g.autoScrollMessages,onChange:e=>f("autoScrollMessages",e)})})})]}),"workspace"===i&&(0,s.jsx)(s.Fragment,{children:h?(0,s.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,s.jsx)("div",{className:"relative",children:(0,s.jsx)("div",{className:"w-12 h-12 rounded-full border-2 border-accent-cyan/20 border-t-accent-cyan animate-spin"})}),(0,s.jsx)("span",{className:"ml-4 text-text-muted",children:"Loading workspaces..."})]}):u?(0,s.jsx)(tT,{workspaceId:u,csrfToken:(0,ei._V)()||void 0,onClose:l}):(0,s.jsx)(ri,{icon:(0,s.jsx)(rx,{}),title:"No Workspace",description:"Create a workspace to get started with Agent Relay.",action:(0,s.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"===i&&(0,s.jsx)(s.Fragment,{children:u?(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(rn,{title:"Team Settings",subtitle:"Manage workspace members and permissions"}),(0,s.jsx)(t2,{workspaceId:u,currentUserId:a})]}):(0,s.jsx)(ri,{icon:(0,s.jsx)(ru,{}),title:"No Workspace Selected",description:"Select a workspace to manage team members."})}),"billing"===i&&(0,s.jsxs)("div",{className:"space-y-8",children:[(0,s.jsx)(rn,{title:"Billing & Subscription",subtitle:"Manage your plan and payment methods"}),(0,s.jsx)(t7,{})]})]})})})]})]})}function rn(e){let{title:t,subtitle:r}=e;return(0,s.jsxs)("div",{className:"mb-8",children:[(0,s.jsx)("h2",{className:"text-2xl font-bold text-text-primary",children:t}),(0,s.jsx)("p",{className:"text-sm text-text-muted mt-1",children:r})]})}function ra(e){let{title:t,icon:r,children:n}=e;return(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-xl border border-border-subtle overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-6 py-4 border-b border-border-subtle bg-bg-secondary/50 flex items-center gap-3",children:[(0,s.jsx)("span",{className:"text-accent-cyan",children:r}),(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-primary uppercase tracking-wide",children:t})]}),(0,s.jsx)("div",{className:"divide-y divide-border-subtle",children:n})]})}function ro(e){let{label:t,description:r,children:n}=e;return(0,s.jsxs)("div",{className:"px-6 py-4 flex items-center justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-primary",children:t}),(0,s.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:r})]}),n]})}function rl(e){let{checked:t,onChange:r}=e;return(0,s.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,s.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 ri(e){let{icon:t,title:r,description:n,action:a}=e;return(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[(0,s.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,s.jsx)("h3",{className:"text-lg font-semibold text-text-primary mb-2",children:r}),(0,s.jsx)("p",{className:"text-sm text-text-muted max-w-sm mb-6",children:n}),a]})}function rc(e){let{className:t=""}=e;return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 rd(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"7",height:"9"}),(0,s.jsx)("rect",{x:"14",y:"3",width:"7",height:"5"}),(0,s.jsx)("rect",{x:"14",y:"12",width:"7",height:"9"}),(0,s.jsx)("rect",{x:"3",y:"16",width:"7",height:"5"})]})}function rx(){return(0,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.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 ru(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function rm(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("rect",{x:"1",y:"4",width:"22",height:"16",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"1",y1:"10",x2:"23",y2:"10"})]})}function rh(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rp(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"13.5",cy:"6.5",r:"2.5"}),(0,s.jsx)("circle",{cx:"19",cy:"13.5",r:"2.5"}),(0,s.jsx)("circle",{cx:"6",cy:"12",r:"2.5"}),(0,s.jsx)("circle",{cx:"11",cy:"19",r:"2.5"}),(0,s.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 rg(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),(0,s.jsx)("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}let rb={theme:"system",notifications:{enabled:!0,sound:!0,desktop:!1,mentionsOnly:!1},display:{compactMode:!1,showTimestamps:!0,showAvatars:!0,animationsEnabled:!0},connection:{autoReconnect:!0,reconnectDelay:3e3,keepAliveInterval:3e4}};var rf=r(9116);function rj(e){let{isOpen:t,onClose:r}=e,[a,o]=(0,n.useState)("conversations"),[l,i]=(0,n.useState)([]),[c,d]=(0,n.useState)([]),[x,u]=(0,n.useState)([]),[m,h]=(0,n.useState)(null),[p,g]=(0,n.useState)(!1),[b,f]=(0,n.useState)(null),[j,y]=(0,n.useState)(""),[v,w]=(0,n.useState)(""),[N,k]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&(async()=>{let e=await rf.hi.getHistoryStats();e.success&&e.data&&h(e.data)})()},[t]),(0,n.useEffect)(()=>{t&&(async()=>{g(!0),f(null);try{if("conversations"===a){let e=await rf.hi.getHistoryConversations();e.success&&e.data?i(e.data.conversations):f(e.error||"Failed to fetch conversations")}else if("sessions"===a){let e=await rf.hi.getHistorySessions({agent:v||void 0,limit:50});e.success&&e.data?d(e.data.sessions):f(e.error||"Failed to fetch sessions")}else if("messages"===a){let r={limit:100,order:"desc"};if(j&&(r.search=j),N){let[s,n]=N.participants,a=await rf.hi.getHistoryMessages({...r,from:s,to:n}),o=await rf.hi.getHistoryMessages({...r,from:n,to:s});if(a.success&&o.success){var e,t;let r=[...(null===(e=a.data)||void 0===e?void 0:e.messages)||[],...(null===(t=o.data)||void 0===t?void 0:t.messages)||[]].sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime());u(r)}}else{let e=await rf.hi.getHistoryMessages(r);e.success&&e.data?u(e.data.messages):f(e.error||"Failed to fetch messages")}}}catch(e){f("Failed to load data")}finally{g(!1)}})()},[t,a,v,j,N]);let C=(0,n.useCallback)(e=>{k(e),o("messages")},[]),S=(0,n.useCallback)(()=>{k(null),o("conversations")},[]);return t?(0,s.jsx)("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center bg-black/50",children:(0,s.jsxs)("div",{className:"bg-bg-primary rounded-lg shadow-xl w-[90vw] max-w-4xl h-[80vh] flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,s.jsxs)("div",{className:"flex items-center gap-4",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-text-primary",children:"Conversation History"}),m&&(0,s.jsxs)("div",{className:"flex gap-4 text-sm text-text-muted",children:[(0,s.jsxs)("span",{children:[m.messageCount," messages"]}),(0,s.jsxs)("span",{children:[m.sessionCount," sessions"]}),(0,s.jsxs)("span",{children:[m.uniqueAgents," agents"]})]})]}),(0,s.jsx)("button",{onClick:r,className:"p-2 text-text-muted hover:text-text-primary rounded transition-colors","aria-label":"Close",children:(0,s.jsx)(rS,{})})]}),(0,s.jsxs)("div",{className:"flex items-center gap-4 p-4 border-b border-border",children:[(0,s.jsxs)("div",{className:"flex gap-1 bg-bg-secondary rounded-md p-1",children:[(0,s.jsx)(ry,{active:"conversations"===a,onClick:()=>{k(null),o("conversations")},children:"Conversations"}),(0,s.jsx)(ry,{active:"sessions"===a,onClick:()=>o("sessions"),children:"Sessions"}),(0,s.jsx)(ry,{active:"messages"===a,onClick:()=>o("messages"),children:"Messages"})]}),"messages"===a&&(0,s.jsx)("div",{className:"flex-1 max-w-xs",children:(0,s.jsx)("input",{type:"text",placeholder:"Search messages...",value:j,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,s.jsx)("div",{className:"flex-1 max-w-xs",children:(0,s.jsx)("input",{type:"text",placeholder:"Filter by agent...",value:v,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,s.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,s.jsx)(rL,{})," Back to conversations"]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:p?(0,s.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,s.jsx)(rA,{})}):b?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-error",children:b}):"conversations"===a?(0,s.jsx)(rv,{conversations:l,onConversationClick:C}):"sessions"===a?(0,s.jsx)(rw,{sessions:c}):(0,s.jsx)(rk,{messages:x,conversationTitle:N?"".concat(N.participants[0]," & ").concat(N.participants[1]):void 0})})]})}):null}function ry(e){let{active:t,onClick:r,children:n}=e;return(0,s.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:n})}function rv(e){let{conversations:t,onConversationClick:r}=e;return 0===t.length?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No conversations found"}):(0,s.jsx)("div",{className:"space-y-2",children:t.map((e,t)=>(0,s.jsxs)("div",{onClick:()=>r(e),className:"p-4 bg-bg-secondary rounded-lg cursor-pointer hover:bg-bg-tertiary transition-colors",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-text-primary",children:e.participants.join(" & ")}),(0,s.jsxs)("span",{className:"text-xs px-2 py-0.5 bg-accent/10 text-accent rounded-full",children:[e.messageCount," messages"]})]}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:rC(e.lastTimestamp)})]}),(0,s.jsx)("p",{className:"text-sm text-text-muted truncate",children:e.lastMessage})]},t))})}function rw(e){let{sessions:t}=e;return 0===t.length?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No sessions found"}):(0,s.jsx)("div",{className:"space-y-2",children:t.map(e=>(0,s.jsxs)("div",{className:"p-4 bg-bg-secondary rounded-lg",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-text-primary",children:e.agentName}),e.cli&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-bg-tertiary text-text-muted rounded",children:e.cli}),(0,s.jsx)(rN,{isActive:e.isActive,closedBy:e.closedBy})]}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:e.duration})]}),(0,s.jsxs)("div",{className:"flex items-center gap-4 text-sm text-text-muted",children:[(0,s.jsx)("span",{children:new Date(e.startedAt).toLocaleString()}),(0,s.jsxs)("span",{children:[e.messageCount," messages"]})]}),e.summary&&(0,s.jsx)("p",{className:"mt-2 text-sm text-text-muted truncate",children:e.summary})]},e.id))})}function rN(e){let{isActive:t,closedBy:r}=e;if(t)return(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-success/10 text-success rounded-full",children:"Active"});let n={agent:"bg-text-muted/10 text-text-muted",disconnect:"bg-warning/10 text-warning",error:"bg-error/10 text-error"},a=r?n[r]:n.agent;return(0,s.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,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No messages found"}):(0,s.jsxs)("div",{className:"space-y-4",children:[r&&(0,s.jsx)("h3",{className:"text-lg font-medium text-text-primary mb-4",children:r}),t.map(e=>(0,s.jsxs)("div",{className:"p-4 bg-bg-secondary rounded-lg",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-medium text-accent",children:e.from}),(0,s.jsx)("span",{className:"text-text-muted",children:"to"}),(0,s.jsx)("span",{className:"font-medium text-text-primary",children:"*"===e.to?"Everyone":e.to}),e.isBroadcast&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-accent/10 text-accent rounded-full",children:"Broadcast"}),e.isUrgent&&(0,s.jsx)("span",{className:"text-xs px-2 py-0.5 bg-error/10 text-error rounded-full",children:"Urgent"})]}),(0,s.jsx)("span",{className:"text-xs text-text-muted",children:rC(e.timestamp)})]}),(0,s.jsx)("p",{className:"text-sm text-text-primary whitespace-pre-wrap",children:e.content}),e.thread&&(0,s.jsxs)("div",{className:"mt-2 text-xs text-text-muted",children:["Thread: ",e.thread.slice(0,8),"..."]})]},e.id))]})}function rC(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),s=Math.floor(r/6e4),n=Math.floor(r/36e5),a=Math.floor(r/864e5);return s<1?"just now":s<60?"".concat(s,"m ago"):n<24?"".concat(n,"h ago"):a<7?"".concat(a,"d ago"):t.toLocaleDateString()}function rS(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rL(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"15 18 9 12 15 6"})})}function rA(){return(0,s.jsx)("svg",{className:"animate-spin text-accent",width:"24",height:"24",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function rM(e,t){let r=e.substring(0,t).match(/(?:^|[\s(])@(\S*)$/);return r?r[1]:null}function rW(e,t,r){let s=e.substring(0,r),n=e.substring(r),a=s.match(/(?:^|[\s(])@(\S*)$/);if(a){let r=a.index||0,s=a[0].charAt(0),o=e.substring(0,"@"===s?r:r+1),l="@".concat(t," "),i=o.length+l.length;return{value:o+l+n,cursorPosition:i}}return{value:e,cursorPosition:r}}function rE(e){let{agents:t,humanUsers:r=[],inputValue:o,cursorPosition:l,onSelect:i,onClose:c,isVisible:d}=e,[x,u]=(0,n.useState)(0),m=(0,n.useRef)(null),h=(0,n.useMemo)(()=>rM(o,l),[o,l]),p=(0,n.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,n.useMemo)(()=>{if(null===h)return[];let e=h.toLowerCase(),s=[];("*".includes(e)||"everyone".includes(e)||"all".includes(e)||"broadcast".includes(e)||""===e)&&s.push({name:"*",displayName:"@everyone",description:"Broadcast to all agents",isBroadcast:!0});let n=e.startsWith("team:")||e.startsWith("team"),a=e.startsWith("team:")?e.substring(5):e.replace(/^team/,"");(n||""===e)&&p.forEach((t,r)=>{let n=r.toLowerCase();(""===a||n.includes(a)||"team:".concat(n).includes(e))&&s.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 o=new Set(t.map(e=>e.name.toLowerCase()));return r.filter(t=>{let r=t.username.toLowerCase();return r.includes(e)&&!o.has(r)}).forEach(e=>{s.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=>{s.push({name:e.name,displayName:"@".concat(e.name),description:e.team?"".concat(e.status||"Agent"," \xb7 ").concat(e.team):e.status||"Agent"})}),s},[h,t,r,p]);(0,n.useEffect)(()=>{u(0)},[g.length]),(0,n.useEffect)(()=>{if(!m.current)return;let e=m.current.querySelector('[data-selected="true"]');e&&e.scrollIntoView({block:"nearest"})},[x]);let b=(0,n.useCallback)(e=>{if(d&&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[x];if(t){let e=rW(o,t.name,l);i(t.name,e.value)}break;case"Escape":e.preventDefault(),c()}},[d,g,x,o,l,i,c]);(0,n.useEffect)(()=>{if(d)return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[d,b]);let f=(0,n.useCallback)(e=>{let t=rW(o,e.name,l);i(e.name,t.value)},[o,l,i]);return d&&0!==g.length?(0,s.jsx)("div",{className:"absolute bottom-full left-0 right-0 max-h-[200px] overflow-y-auto bg-[#1a1d21] border border-white/10 rounded-lg shadow-[0_-4px_20px_rgba(0,0,0,0.4)] z-[100] mb-1",ref:m,children:g.map((e,t)=>(0,s.jsxs)("div",{"data-selected":t===x,className:"flex items-center gap-2.5 py-2 px-3 cursor-pointer transition-colors duration-150 ".concat(t===x?"bg-white/[0.08]":"hover:bg-white/[0.08]"),onClick:()=>f(e),onMouseEnter:()=>u(t),children:[e.isHuman&&e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-7 h-7 rounded-md object-cover"}):(0,s.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,a.GW)(e.name).primary},children:e.isBroadcast?"*":e.isTeam?(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,s.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}):e.isHuman?(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"12",cy:"7",r:"4"})]}):(0,a.hP)(e.name)}),(0,s.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-[#d1d2d3]",children:e.displayName}),(0,s.jsx)("span",{className:"text-xs text-[#8d8d8e] truncate",children:e.description})]})]},e.name))}):null}function rD(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 rB(e,t,r){let s=e.substring(0,r),n=e.substring(r),a=s.match(/(?:^|[\s(])@(\S*)$/);if(a){let r=a.index||0,s=a[0].charAt(0);return e.substring(0,"@"===s?r:r+1)+"@".concat(t," ")+n}return e}let rT=new Map;function rR(e){let{inputValue:t,cursorPosition:r,onSelect:a,onClose:o,isVisible:l,apiBase:i=""}=e,[c,d]=(0,n.useState)(0),[x,u]=(0,n.useState)([]),[m,h]=(0,n.useState)(!1),[p,g]=(0,n.useState)(null),b=(0,n.useRef)(null),f=(0,n.useRef)(null),j=(0,n.useMemo)(()=>rD(t,r),[t,r]);(0,n.useEffect)(()=>{if(!l||null===j){u([]);return}let e=j||"__root__",t=rT.get(e);if(t&&Date.now()-t.timestamp<3e4){u(t.files),g(null);return}f.current&&f.current.abort();let r=new AbortController;f.current=r;let s=setTimeout(async()=>{h(!0),g(null);try{let t=j||"",s=await fetch("".concat(i,"/api/files?q=").concat(encodeURIComponent(t),"&limit=15"),{signal:r.signal});if(!s.ok)throw Error("Failed to fetch files");let n=((await s.json()).files||[]).map(e=>({path:e.path,name:e.name,isDirectory:e.isDirectory||!1}));rT.set(e,{files:n,timestamp:Date.now()}),u(n)}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;g("Failed to load files"),u([])}finally{h(!1)}},150);return()=>{clearTimeout(s),r.abort()}},[l,j,i]),(0,n.useEffect)(()=>{d(0)},[x.length]),(0,n.useEffect)(()=>{if(!b.current)return;let e=b.current.querySelector('[data-selected="true"]');e&&e.scrollIntoView({block:"nearest"})},[c]);let y=(0,n.useCallback)(e=>{if(l&&0!==x.length)switch(e.key){case"ArrowDown":e.preventDefault(),d(e=>(e+1)%x.length);break;case"ArrowUp":e.preventDefault(),d(e=>(e-1+x.length)%x.length);break;case"Enter":case"Tab":e.preventDefault();let s=x[c];if(s){let e=rB(t,s.path,r);a(s.path,e)}break;case"Escape":e.preventDefault(),o()}},[l,x,c,t,r,a,o]);(0,n.useEffect)(()=>{if(l)return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[l,y]);let v=(0,n.useCallback)(e=>{let s=rB(t,e.path,r);a(e.path,s)},[t,r,a]);return l&&(0!==x.length||m||p)?(0,s.jsxs)("div",{className:"absolute bottom-full left-0 right-0 max-h-[240px] overflow-y-auto bg-[#1a1d21] border border-white/10 rounded-lg shadow-[0_-4px_20px_rgba(0,0,0,0.4)] z-[100] mb-1",ref:b,children:[(0,s.jsxs)("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wider text-[#8d8d8e] border-b border-white/5 flex items-center gap-2",children:[(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,s.jsx)("polyline",{points:"13 2 13 9 20 9"})]}),"Files ",j&&(0,s.jsxs)("span",{className:"text-[#6b6b6c]",children:['matching "',j,'"']})]}),m&&0===x.length&&(0,s.jsxs)("div",{className:"px-3 py-4 text-sm text-[#8d8d8e] text-center",children:[(0,s.jsx)("svg",{className:"animate-spin mx-auto mb-2",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})}),"Searching files..."]}),p&&(0,s.jsx)("div",{className:"px-3 py-4 text-sm text-red-400 text-center",children:p}),x.map((e,t)=>(0,s.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-white/[0.08]":"hover:bg-white/[0.08]"),onClick:()=>v(e),onMouseEnter:()=>d(t),children:[(0,s.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-[#8d8d8e]",style:{background:e.isDirectory?"rgba(251, 191, 36, 0.15)":"rgba(96, 165, 250, 0.15)"},children:e.isDirectory?(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#fbbf24",strokeWidth:"2",children:(0,s.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,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#60a5fa",strokeWidth:"2",children:[(0,s.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,s.jsx)("polyline",{points:"13 2 13 9 20 9"})]})}),(0,s.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-[#d1d2d3] truncate",children:e.name}),(0,s.jsx)("span",{className:"text-xs text-[#6b6b6c] truncate",children:e.path})]})]},e.path)),!m&&!p&&0===x.length&&j&&(0,s.jsxs)("div",{className:"px-3 py-4 text-sm text-[#8d8d8e] text-center",children:['No files found matching "',j,'"']})]}):null}function rP(e){let{workspaces:t,activeWorkspaceId:r,onSelect:a,onAddWorkspace:o,onWorkspaceSettings:l,isLoading:i=!1}=e,[c,d]=(0,n.useState)(!1),x=(0,n.useRef)(null),u=t.find(e=>e.id===r);return(0,n.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=e=>{"Escape"===e.key&&d(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[]),(0,s.jsxs)("div",{className:"relative w-full",ref:x,children:[(0,s.jsxs)("button",{className:"w-full flex items-center gap-2 px-3 py-2.5 bg-[#2a2a3e] border border-[#3a3a4e] rounded-lg text-[#e8e8e8] text-sm cursor-pointer transition-all hover:bg-[#3a3a4e] hover:border-[#4a4a5e] disabled:opacity-60 disabled:cursor-not-allowed",onClick:()=>d(!c),disabled:i,children:[i?(0,s.jsx)("span",{className:"flex-1 text-left text-[#666]",children:"Loading..."}):u?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r_,{provider:u.provider}),(0,s.jsx)("span",{className:"flex-1 text-left font-medium",children:u.name}),u.gitBranch&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-xs text-[#888] bg-white/5 px-1.5 py-0.5 rounded",children:[(0,s.jsx)(rU,{}),u.gitBranch]})]}):(0,s.jsx)("span",{className:"flex-1 text-left text-[#666]",children:"Select workspace..."}),(0,s.jsx)(rF,{isOpen:c})]}),c&&(0,s.jsxs)("div",{className:"absolute top-[calc(100%+4px)] left-0 right-0 bg-[#1a1a2e] border border-[#3a3a4e] rounded-lg shadow-[0_10px_40px_rgba(0,0,0,0.4)] z-[1000] overflow-hidden",children:[(0,s.jsx)("div",{className:"max-h-[300px] overflow-y-auto",children:0===t.length?(0,s.jsxs)("div",{className:"py-6 px-4 text-center text-[#666] text-[13px] leading-relaxed",children:["No workspaces added yet.",(0,s.jsx)("br",{}),"Add a repository to get started."]}):t.map(e=>(0,s.jsxs)("button",{className:"w-full flex items-center gap-2.5 px-3 py-2.5 bg-transparent border-none text-[#e8e8e8] text-sm cursor-pointer transition-colors text-left hover:bg-white/5 ".concat(e.id===r?"bg-[rgba(0,200,150,0.1)]":""),onClick:()=>{a(e),d(!1)},children:[(0,s.jsx)(r_,{provider:e.provider}),(0,s.jsxs)("div",{className:"flex-1 flex flex-col gap-0.5 min-w-0",children:[(0,s.jsx)("span",{className:"font-medium",children:e.name}),(0,s.jsx)("span",{className:"text-[11px] text-[#666] overflow-hidden text-ellipsis whitespace-nowrap",children:e.path})]}),(0,s.jsx)(rI,{status:e.status})]},e.id))}),(0,s.jsxs)("div",{className:"p-2 border-t border-[#3a3a4e] space-y-1.5",children:[l&&u&&(0,s.jsxs)("button",{className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-transparent border border-[#3a3a4e] rounded-md text-[#888] text-[13px] cursor-pointer transition-all hover:bg-white/5 hover:border-[#4a4a5e] hover:text-[#e8e8e8]",onClick:()=>{l(),d(!1)},children:[(0,s.jsx)(rz,{}),"Workspace Settings"]}),(0,s.jsxs)("button",{className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-transparent border border-dashed border-[#3a3a4e] rounded-md text-[#888] text-[13px] cursor-pointer transition-all hover:bg-white/5 hover:border-[#4a4a5e] hover:text-[#e8e8e8]",onClick:o,children:[(0,s.jsx)(rO,{}),"Add Workspace"]})]})]})]})}function r_(e){let{provider:t}=e,r={claude:"\uD83E\uDD16",codex:"\uD83E\uDDE0",gemini:"✨",generic:"\uD83D\uDCC1"};return(0,s.jsx)("span",{className:"text-base",title:t,children:r[t]||r.generic})}function rI(e){let{status:t}=e,r={active:"bg-green-500",inactive:"bg-gray-500",error:"bg-red-500"};return(0,s.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 ".concat(r[t]||r.inactive),title:t})}function rF(e){let{isOpen:t}=e;return(0,s.jsx)("svg",{className:"text-[#666] transition-transform ".concat(t?"rotate-180":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function rU(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,s.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,s.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,s.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})}function rO(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function rz(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 rH(e){let{isOpen:t,onClose:r,onAdd:a,isAdding:o=!1,error:l}=e,[i,c]=(0,n.useState)(""),[d,x]=(0,n.useState)(""),[u,m]=(0,n.useState)(null),h=(0,n.useRef)(null);(0,n.useEffect)(()=>{t&&h.current&&h.current.focus()},[t]),(0,n.useEffect)(()=>{t||(c(""),x(""),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=l||u;return(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-[#e8e8e8]",children:"Add Workspace"}),(0,s.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,s.jsx)(rV,{})})]}),(0,s.jsxs)("form",{onSubmit:p,children:[(0,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{htmlFor:"workspace-path",className:"block mb-2 text-[13px] font-medium text-[#e8e8e8]",children:"Repository Path"}),(0,s.jsx)("input",{ref:h,id:"workspace-path",type:"text",value:i,onChange:e=>{c(e.target.value),m(null)},placeholder:"/path/to/repository",disabled:o,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,s.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,s.jsxs)("div",{className:"mb-5",children:[(0,s.jsx)("label",{htmlFor:"workspace-name",className:"block mb-2 text-[13px] font-medium text-[#e8e8e8]",children:"Display Name (optional)"}),(0,s.jsx)("input",{id:"workspace-name",type:"text",value:d,onChange:e=>x(e.target.value),placeholder:"My Project",disabled:o,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,s.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,s.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,s.jsxs)("div",{className:"flex gap-3 justify-end mt-6",children:[(0,s.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:o,children:"Cancel"}),(0,s.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:o||!i.trim(),children:o?"Adding...":"Add Workspace"})]})]})]})})}function rV(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}let rG=0;function rK(){return"log-".concat(Date.now(),"-").concat(++rG)}var rZ=r(9540),rq=r(1561),rJ=r(7418);let rY=(0,n.createContext)({wsBaseUrl:null,isCloudMode:!1});function r$(e){let{children:t,wsUrl:r}=e,a=(0,n.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,s.jsx)(rY.Provider,{value:a,children:t})}let rX={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 rQ(e){let{agentName:t,maxHeight:r="500px",showHeader:o=!0,onClose:l,className:i=""}=e,c=(0,n.useRef)(null),d=(0,n.useRef)(null),x=(0,n.useRef)(null),u=(0,n.useRef)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(null),p=(0,n.useRef)(0),[g,b]=(0,n.useState)(!1),[f,j]=(0,n.useState)(!1),[y,v]=(0,n.useState)(null),[w,N]=(0,n.useState)(!1),[k,C]=(0,n.useState)(""),[S,L]=(0,n.useState)(0),A=(0,n.useRef)(null),M=(0,a.GW)(t),W=function(e){let{wsBaseUrl:t}=(0,n.useContext)(rY);return(0,n.useMemo)(()=>{if(t)return"".concat(t).concat(e);let r="https:"===window.location.protocol?"wss:":"ws:",{hostname:s,port:n}=window.location;return"".concat(r,"//").concat(window.location.host).concat(e)},[t,e])}("/ws/logs/".concat(encodeURIComponent(t)));(0,n.useEffect)(()=>{if(!c.current)return;let e=new rZ.o({theme:rX,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 rq.X,r=new rJ.Z;e.loadAddon(t),e.loadAddon(r),e.open(c.current),t.fit(),d.current=e,x.current=t,u.current=r;let s=new ResizeObserver(()=>{t.fit()});return s.observe(c.current),()=>{s.disconnect(),e.dispose(),d.current=null,x.current=null,u.current=null}},[]);let E=(0,n.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;j(!0),v(null);let s=new WebSocket(W);m.current=s,s.onopen=()=>{var e;b(!0),j(!1),v(null),p.current=0,null===(e=d.current)||void 0===e||e.writeln("\x1b[90m[Connected to ".concat(t," log stream]\x1b[0m"))},s.onclose=e=>{var t,r;if(b(!1),j(!1),m.current=null,h.current&&(clearTimeout(h.current),h.current=null),4404===e.code){null===(r=d.current)||void 0===r||r.writeln("\x1b[31m[Agent not found]\x1b[0m");return}let s=Math.min(1e3*Math.pow(2,p.current),3e4);p.current++,null===(t=d.current)||void 0===t||t.writeln("\x1b[90m[Disconnected. Reconnecting in ".concat(s/1e3,"s...]\x1b[0m")),h.current=setTimeout(()=>{E()},s)},s.onerror=()=>{v(Error("WebSocket connection error")),j(!1)},s.onmessage=e=>{var t,r,s;try{let s=JSON.parse(e.data);if("error"===s.type){null===(t=d.current)||void 0===t||t.writeln("\x1b[31mError: ".concat(s.error,"\x1b[0m"));return}if("subscribed"===s.type)return;if("history"===s.type&&Array.isArray(s.lines)){s.lines.forEach(e=>{var t;null===(t=d.current)||void 0===t||t.writeln(e),L(e=>e+1)});return}if("log"===s.type||"output"===s.type){let e=s.content||s.data||s.message||"";if(e){null===(r=d.current)||void 0===r||r.write(e);let t=(e.match(/\n/g)||[]).length;t>0&&L(e=>e+t)}return}s.lines&&Array.isArray(s.lines)&&s.lines.forEach(e=>{var t;let r="string"==typeof e?e:e.content;null===(t=d.current)||void 0===t||t.writeln(r),L(e=>e+1)})}catch(t){if("string"==typeof e.data){null===(s=d.current)||void 0===s||s.write(e.data);let t=(e.data.match(/\n/g)||[]).length;t>0&&L(e=>e+t)}}}},[W,t]),D=(0,n.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null),m.current&&(m.current.close(),m.current=null),b(!1),j(!1)},[]),B=(0,n.useCallback)(()=>{var e;null===(e=d.current)||void 0===e||e.clear(),L(0)},[]),T=(0,n.useCallback)(e=>{C(e),e&&u.current&&u.current.findNext(e,{caseSensitive:!1})},[]),R=(0,n.useCallback)(()=>{k&&u.current&&u.current.findNext(k,{caseSensitive:!1})},[k]),P=(0,n.useCallback)(()=>{k&&u.current&&u.current.findPrevious(k,{caseSensitive:!1})},[k]);return(0,n.useEffect)(()=>(E(),()=>{D()}),[E,D]),(0,n.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?P():R())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[w,R,P]),(0,s.jsxs)("div",{className:"xterm-log-viewer flex flex-col rounded-xl overflow-hidden border border-[#2a2d35] shadow-2xl ".concat(i),style:{background:"linear-gradient(180deg, #0d0f14 0%, #0a0c10 100%)",boxShadow:"0 0 60px -15px ".concat(M.primary,"25, 0 25px 50px -12px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255,255,255,0.02)")},children:[o&&(0,s.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,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("div",{className:"flex items-center gap-2",children:(0,s.jsxs)("div",{className:"flex gap-1.5",children:[(0,s.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,s.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,s.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,s.jsx)("div",{className:"w-px h-4 bg-[#30363d]"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(r0,{}),(0,s.jsx)("span",{className:"text-sm font-semibold",style:{color:M.primary},children:t}),(0,s.jsx)(r8,{isConnected:g,isConnecting:f})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.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,s.jsx)(r1,{})}),(0,s.jsx)("button",{className:"p-1.5 rounded-lg hover:bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-all duration-200",onClick:B,title:"Clear logs",children:(0,s.jsx)(r2,{})}),(0,s.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?D:E,title:g?"Disconnect":"Connect",children:g?(0,s.jsx)(r3,{}):(0,s.jsx)(r4,{})}),l&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"w-px h-4 bg-[#30363d] mx-1"}),(0,s.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,s.jsx)(r5,{})})]})]})]}),w&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-[#21262d] bg-[#161b22]",children:[(0,s.jsx)(r1,{}),(0,s.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=>T(e.target.value)}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{className:"px-2 py-0.5 text-xs rounded bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-colors",onClick:P,title:"Previous (Shift+Enter)",children:"↑"}),(0,s.jsx)("button",{className:"px-2 py-0.5 text-xs rounded bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-colors",onClick:R,title:"Next (Enter)",children:"↓"})]})]}),y&&(0,s.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,s.jsx)(r6,{}),(0,s.jsx)("span",{children:y.message}),(0,s.jsx)("button",{className:"ml-auto text-xs px-2 py-0.5 rounded bg-[#f85149]/20 hover:bg-[#f85149]/30 transition-colors",onClick:E,children:"Retry"})]}),(0,s.jsx)("div",{ref:c,className:"flex-1 overflow-hidden",style:{maxHeight:r,minHeight:"200px"}}),(0,s.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,s.jsx)("div",{className:"flex items-center gap-3",children:(0,s.jsxs)("span",{className:"tabular-nums font-mono text-[#6e7681]",children:[S," lines"]})}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-[#6e7681] font-mono uppercase tracking-wider text-[10px]",children:"PTY stream"}),(0,s.jsx)("div",{className:"w-2 h-2 rounded-full transition-all duration-300 ".concat(g?"bg-[#3fb950]":f?"bg-[#d29922] animate-pulse":"bg-[#484f58]"),style:{boxShadow:g?"0 0 8px rgba(63,185,80,0.6)":"none"}})]})]})]})}function r0(){return(0,s.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,s.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,s.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function r1(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-[#8b949e]",children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,s.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function r2(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.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 r5(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function r4(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function r3(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,s.jsx)("rect",{x:"6",y:"4",width:"4",height:"16"}),(0,s.jsx)("rect",{x:"14",y:"4",width:"4",height:"16"})]})}function r6(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function r8(e){let{isConnected:t,isConnecting:r}=e;return r?(0,s.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,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#d29922] animate-pulse"}),"connecting"]}):t?(0,s.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,s.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,s.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,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58]"}),"offline"]})}function r9(e){let{agentName:t,mode:r="panel",maxHeight:o="500px",showHeader:l=!0,autoScrollDefault:i=!0,onClose:c,onExpand:d,className:x=""}=e,[u,m]=(0,n.useState)(i),h=(0,n.useRef)(null),{logs:p,isConnected:g,isConnecting:b}=function(e){let{agentName:t,maxLines:r=5e3,autoConnect:s=!0,reconnect:a=!0,maxReconnectAttempts:o=1/0}=e,[l,i]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),[x,u]=(0,n.useState)(!1),[m,h]=(0,n.useState)(null),p=(0,n.useRef)(null),g=(0,n.useRef)(0),b=(0,n.useRef)(null),f=(0,n.useRef)(t),j=(0,n.useRef)(!0),y=(0,n.useRef)(!1),v=(0,n.useRef)(new WeakMap),w=(0,n.useRef)(new WeakMap);f.current=t;let N=(0,n.useCallback)(()=>{var e,t;if(j.current=!0,(null===(e=p.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN||(null===(t=p.current)||void 0===t?void 0:t.readyState)===WebSocket.CONNECTING||y.current)return;y.current=!0,u(!0),h(null);let s=function(e){let t="/ws/logs/".concat(encodeURIComponent(e)),r="https:"===window.location.protocol?"wss:":"ws:",{hostname:s,port:n}=window.location;return"".concat(r,"//").concat(window.location.host).concat(t)}(f.current);try{let e=new WebSocket(s);p.current=e,v.current.set(e,!1),w.current.set(e,!1),e.onopen=()=>{y.current=!1,d(!0),u(!1),h(null),g.current=0,i(e=>[...e,{id:rK(),timestamp:Date.now(),content:"Connected to ".concat(f.current," log stream"),type:"system",agentName:f.current}])},e.onclose=t=>{var r,s;let n=null!==(r=v.current.get(e))&&void 0!==r&&r,l=null!==(s=w.current.get(e))&&void 0!==s&&s;if(y.current=!1,d(!1),u(!1),p.current=null,b.current&&(clearTimeout(b.current),b.current=null),!n&&4404!==t.code){if(!t.wasClean&&l){let e=j.current&&a&&g.current<o;i(r=>[...r,{id:rK(),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:f.current}])}if(j.current&&a&&g.current<o){let e=Math.min(1e3*Math.pow(2,g.current),3e4);g.current++,b.current=setTimeout(()=>{N()},e)}}},e.onerror=()=>{y.current=!1,h(Error("WebSocket connection error")),u(!1)},e.onmessage=t=>{try{let s=JSON.parse(t.data);if("error"===s.type){h(Error(s.error||"Failed to stream logs for ".concat(s.agent||f.current))),i(e=>[...e,{id:rK(),timestamp:Date.now(),content:"Error: ".concat(s.error||"Unknown error"),type:"system",agentName:s.agent||f.current}]);return}if("subscribed"===s.type){console.log("[useAgentLogs] Subscribed to ".concat(s.agent));return}if("history"===s.type&&Array.isArray(s.lines)){s.lines.length>0&&w.current.set(e,!0),i(e=>{let t=s.lines.map(e=>({id:rK(),timestamp:Date.now(),content:e,type:"stdout",agentName:s.agent||f.current}));return[...e,...t].slice(-r)});return}"string"==typeof s?(w.current.set(e,!0),i(e=>[...e,{id:rK(),timestamp:Date.now(),content:s,type:"stdout",agentName:f.current}].slice(-r))):"log"===s.type||"output"===s.type?(w.current.set(e,!0),i(e=>{let t="stderr"===s.stream?"stderr":"stdout";return[...e,{id:rK(),timestamp:s.timestamp||Date.now(),content:s.content||s.data||s.message||"",type:t,agentName:s.agentName||f.current}].slice(-r)})):s.lines&&Array.isArray(s.lines)&&(w.current.set(e,!0),i(e=>{let t=s.lines.map(e=>{let t="object"==typeof e&&"stderr"===e.type?"stderr":"stdout";return{id:rK(),timestamp:Date.now(),content:"string"==typeof e?e:e.content,type:t,agentName:f.current}});return[...e,...t].slice(-r)}))}catch(s){"string"==typeof t.data&&(w.current.set(e,!0),i(e=>[...e,{id:rK(),timestamp:Date.now(),content:t.data,type:"stdout",agentName:f.current}].slice(-r)))}}}catch(e){y.current=!1,h(e instanceof Error?e:Error("Failed to create WebSocket")),u(!1)}},[r,a,o]),k=(0,n.useCallback)(()=>{j.current=!1,b.current&&(clearTimeout(b.current),b.current=null),p.current&&(v.current.set(p.current,!0),p.current.close(),p.current=null),y.current=!1,d(!1),u(!1)},[]),C=(0,n.useCallback)(()=>{i([])},[]);return(0,n.useEffect)(()=>(s&&t&&N(),()=>{k()}),[t,s,N,k]),{logs:l,isConnected:c,isConnecting:x,error:m,connect:N,disconnect:k,clear:C}}({agentName:t,autoConnect:!0}),f=(0,a.GW)(t),j=(0,n.useMemo)(()=>p.filter(e=>{let t=st(e.content).trim();return 0!==t.length&&!(t.length<=2&&/^[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⣾⣽⣻⢿⡿⣟⣯⣷◐◓◑◒●○◉◎|\\\/\-*.\u2800-\u28FF]+$/.test(t))}),[p]);(0,n.useEffect)(()=>{if(u&&h.current){let e=h.current;e.scrollTop=e.scrollHeight}},[p,u]);let y=(0,n.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,s.jsxs)("div",{className:"log-viewer-inline rounded-lg overflow-hidden border border-[#2a2d35] ".concat(x),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,s.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,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(sr,{}),(0,s.jsx)("span",{className:"text-xs font-medium",style:{color:f.primary},children:"Live logs"}),(0,s.jsx)(se,{isConnected:g,isConnecting:b})]}),(0,s.jsx)("div",{className:"flex items-center gap-1",children:(0,s.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:d,title:"Expand",children:(0,s.jsx)(ss,{})})})]}),(0,s.jsxs)("div",{className:"font-mono text-xs leading-relaxed p-3 overflow-y-auto",style:{maxHeight:"150px"},ref:h,onScroll:y,children:[j.slice(-20).map(e=>(0,s.jsx)(r7,{log:e,compact:!0},e.id)),0===j.length&&(0,s.jsxs)("div",{className:"text-[#484f58] italic flex items-center gap-2",children:[(0,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58] animate-pulse"}),"Waiting for output..."]})]})]}):(0,s.jsx)(rQ,{agentName:t,maxHeight:o,showHeader:l,onClose:c,className:x})}function r7(e){let{log:t,compact:r=!1}=e,n=st(t.content);return(0,s.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:n})}function se(e){let{isConnected:t,isConnecting:r}=e;return r?(0,s.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,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#d29922] animate-pulse"}),"connecting"]}):t?(0,s.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,s.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,s.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,s.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58]"}),"offline"]})}function st(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 sr(e){let{size:t=16}=e;return(0,s.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,s.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,s.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function ss(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,s.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,s.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}function sn(e){let{agent:t,position:r="right",isOpen:o,onClose:l,onAgentChange:i,availableAgents:c=[]}=e,d=(0,a.GW)(t.name),[x,u]=(0,n.useState)(!0);return((0,n.useEffect)(()=>{let e=e=>{"Escape"===e.key&&o&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,l]),(0,n.useEffect)(()=>{if(o&&"fullscreen"===r)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[o,r]),o)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 z-[1099] animate-fade-in",onClick:l}),(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[#21262d] transition-all duration-200 ".concat(x?"px-4 py-2":"px-5 py-4"),style:{background:"linear-gradient(180deg, #161b22 0%, #0d1117 100%)"},children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("button",{className:"p-1 rounded-md text-[#8b949e] hover:text-[#c9d1d9] hover:bg-[#21262d] transition-colors",onClick:()=>u(!x),title:x?"Expand header":"Collapse header",children:(0,s.jsx)(su,{collapsed:x})}),(0,s.jsxs)("div",{className:"relative shrink-0 rounded-xl flex items-center justify-center font-bold overflow-hidden transition-all duration-200 ".concat(x?"w-8 h-8 text-xs":"w-11 h-11 text-sm"),style:{backgroundColor:d.primary,color:d.text,boxShadow:x?"0 0 12px ".concat(d.primary,"40"):"0 0 24px ".concat(d.primary,"50, inset 0 1px 0 rgba(255,255,255,0.2)")},children:[(0,s.jsx)("div",{className:"absolute inset-0 opacity-30",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.35) 0%, transparent 50%)"}}),(0,s.jsx)("span",{className:"relative z-10",children:(0,a.hP)(t.name)})]}),x?(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-sm font-semibold",style:{color:d.primary},children:t.name}),(0,s.jsx)("span",{className:"px-2 py-0.5 rounded text-[9px] uppercase tracking-wider font-medium ".concat("online"===t.status?"bg-[#3fb950]/15 text-[#3fb950]":"busy"===t.status?"bg-[#d29922]/15 text-[#d29922]":"bg-[#484f58]/15 text-[#484f58]"),children:t.status})]}):(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold m-0",style:{color:d.primary},children:t.name}),(0,s.jsx)("span",{className:"px-2.5 py-0.5 rounded-md text-[10px] uppercase tracking-wider font-medium ".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,s.jsx)("span",{className:"text-sm text-[#8b949e] truncate max-w-[300px] mt-0.5",children:t.currentTask})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[c.length>1&&i&&(0,s.jsx)(sa,{agents:c,currentAgent:t,onSelect:i}),(0,s.jsxs)("div",{className:"flex items-center gap-1 bg-[#21262d]/80 rounded-lg p-1 border border-[#30363d]/50",children:[(0,s.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,s.jsx)(sl,{})}),(0,s.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,s.jsx)(si,{})}),(0,s.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,s.jsx)(sc,{})})]}),(0,s.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,s.jsx)(so,{})})]})]}),(0,s.jsx)("div",{className:"flex-1 min-h-0",children:(0,s.jsx)(r9,{agentName:t.name,mode:"panel",showHeader:!1,maxHeight:"100%",className:"h-full rounded-none border-none"})})]}),(0,s.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 sa(e){let{agents:t,currentAgent:r,onSelect:o}=e,[l,i]=n.useState(!1),c=n.useRef(null);return(0,n.useEffect)(()=>{let e=e=>{c.current&&!c.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.jsxs)("div",{className:"relative",ref:c,children:[(0,s.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:()=>i(!l),children:[(0,s.jsx)("span",{children:"Switch agent"}),(0,s.jsx)(sd,{})]}),l&&(0,s.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,s.jsx)("div",{className:"max-h-64 overflow-y-auto",children:t.map(e=>{let t=(0,a.GW)(e.name),n=e.name===r.name;return(0,s.jsxs)("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left transition-colors ".concat(n?"bg-[#238636]/20":"hover:bg-[#21262d]"),onClick:()=>{o(e),i(!1)},children:[(0,s.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,a.hP)(e.name)}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"text-sm text-[#c9d1d9] truncate",children:e.name}),(0,s.jsx)("div",{className:"text-xs text-[#8b949e]",children:e.status})]}),n&&(0,s.jsx)(sx,{})]},e.name)})})})]})}function so(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function sl(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,s.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})}function si(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,s.jsx)("line",{x1:"3",y1:"15",x2:"21",y2:"15"})]})}function sc(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,s.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,s.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}function sd(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function sx(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3fb950",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function su(e){let{collapsed:t}=e;return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform duration-200 ".concat(t?"":"rotate-90"),children:(0,s.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function sm(e){let{agentName:t,steps:r,history:a=[],selectedTrajectoryId:o,onSelectTrajectory:l,isLoading:i=!1,onStepClick:c,compact:d=!1}=e,[x,u]=(0,n.useState)(new Set),[m,h]=(0,n.useState)("all"),p=(0,n.useMemo)(()=>"all"===m?r:r.filter(e=>e.type===m),[r,m]),g=e=>{u(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},b=[{value:"all",label:"All",icon:(0,s.jsx)(sb,{})},{value:"tool_call",label:"Tools",icon:(0,s.jsx)(sf,{})},{value:"decision",label:"Decisions",icon:(0,s.jsx)(sj,{})},{value:"message",label:"Messages",icon:(0,s.jsx)(sy,{})},{value:"state_change",label:"State",icon:(0,s.jsx)(sv,{})},{value:"phase_transition",label:"Phases",icon:(0,s.jsx)(sw,{})},{value:"error",label:"Errors",icon:(0,s.jsx)(sN,{})}],f=(0,n.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,s.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,s.jsxs)("div",{className:"relative",children:[(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border/30",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[o&&l&&(0,s.jsxs)("button",{onClick:()=>l(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,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,s.jsx)("path",{d:"M19 12H5M12 19l-7-7 7-7",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,s.jsx)("span",{children:"List"})]}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.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,s.jsx)(sg,{})}),r.some(e=>"running"===e.status)&&(0,s.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,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary tracking-wide",children:"Trajectory"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("span",{className:"text-[11px] text-text-muted font-mono",children:[r.length," ",1===r.length?"step":"steps"]}),t&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-text-dim",children:"|"}),(0,s.jsx)("span",{className:"text-[11px] text-accent-cyan/80 font-medium truncate max-w-[120px]",children:t})]})]})]})]}),f.total>0&&!d&&(0,s.jsx)("div",{className:"flex items-center gap-1.5",children:["plan","design","execute","review","observe"].map(e=>{let t=f.phases[e]||0,r=sp(e);return t>0?(0,s.jsx)("div",{className:"h-1.5 rounded-full transition-all duration-300",style:{width:"".concat(Math.max(8,t/f.total*48),"px"),backgroundColor:r||"var(--color-border)"},title:"".concat(e,": ").concat(t)},e):null})})]}),!d&&(0,s.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:b.map(e=>(0,s.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,s.jsx)("span",{className:"opacity-70",children:e.icon}),e.label]},e.value))})]}),(0,s.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,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-12 text-text-muted",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(sS,{}),(0,s.jsx)("div",{className:"absolute inset-0 bg-accent-cyan/10 rounded-full blur-xl"})]}),(0,s.jsx)("span",{className:"text-sm font-medium",children:"Loading trajectory..."})]}):0===p.length?(0,s.jsx)("div",{className:"flex flex-col gap-4 py-4 text-text-muted",children:0===r.length&&a.length>0?(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-text-secondary uppercase tracking-wider",children:"Recent Trajectories"}),o&&l&&(0,s.jsx)("button",{onClick:()=>l(null),className:"text-[10px] text-accent-cyan hover:underline",children:"← Back to current"})]}),(0,s.jsx)("div",{className:"flex flex-col gap-1",children:a.slice(0,10).map(e=>(0,s.jsxs)("button",{onClick:()=>null==l?void 0:l(e.id),className:"w-full text-left px-3 py-2.5 rounded-lg transition-all duration-200 border ".concat(o===e.id?"bg-blue-500/15 border-blue-500/40 text-text-primary":"bg-bg-tertiary/50 border-transparent hover:bg-bg-elevated/60 hover:border-border/40"),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)("span",{className:"text-[13px] font-medium text-text-primary truncate flex-1",children:e.title}),(0,s.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,s.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-text-dim",children:function(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),s=Math.floor(r/6e4),n=Math.floor(r/36e5),a=Math.floor(r/864e5);return s<1?"just now":s<60?"".concat(s,"m ago"):n<24?"".concat(n,"h ago"):a<7?"".concat(a,"d ago"):t.toLocaleDateString()}(e.startedAt)}),e.confidence&&(0,s.jsxs)("span",{className:"text-[10px] text-text-dim",children:["• ",Math.round(100*e.confidence),"% confidence"]})]}),e.summary&&(0,s.jsx)("p",{className:"text-[11px] text-text-muted mt-1 line-clamp-2",children:e.summary})]},e.id))})]}):0===r.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-8",children:[(0,s.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-elevated/50 flex items-center justify-center border border-border/30",children:(0,s.jsx)(sC,{})}),(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-secondary",children:"No steps recorded"}),(0,s.jsx)("p",{className:"text-xs text-text-dim mt-1",children:"Steps will appear here as the agent works"})]})]}):(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-8",children:[(0,s.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-elevated/50 flex items-center justify-center border border-border/30",children:(0,s.jsx)(sC,{})}),(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-text-secondary",children:"No matching steps"}),(0,s.jsx)("p",{className:"text-xs text-text-dim mt-1",children:'Try a different filter or select "All"'})]})]})}):(0,s.jsx)("div",{className:"flex flex-col gap-0.5",children:p.map((e,t)=>(0,s.jsx)(sh,{step:e,isExpanded:x.has(e.id),isLast:t===p.length-1,isFirst:0===t,compact:d,onToggle:()=>g(e.id),onClick:c?()=>c(e):void 0},e.id))})})]})}function sh(e){var t;let{step:r,isExpanded:n,isLast:a,isFirst:o=!1,compact:l=!1,onToggle:i,onClick:c}=e,d=new Date(r.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),x=function(e){switch(e){case"tool_call":return(0,s.jsx)(sf,{});case"decision":return(0,s.jsx)(sj,{});case"message":return(0,s.jsx)(sy,{});case"state_change":return(0,s.jsx)(sv,{});case"phase_transition":return(0,s.jsx)(sw,{});case"error":return(0,s.jsx)(sN,{});default:return null}}(r.type),u=function(e){switch(e){case"running":return"#ff6b35";case"success":return"#00ffc8";case"error":return"#ff4757";default:return null}}(r.status),m=sp(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,s.jsxs)("div",{className:"flex gap-3 group",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center w-7 relative",children:[!o&&(0,s.jsx)("div",{className:"absolute top-0 w-px h-2 transition-colors",style:{backgroundColor:m?"".concat(m,"40"):"var(--color-border)"}}),(0,s.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:u?"linear-gradient(135deg, ".concat(u,"40, ").concat(u,"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:u||m||h||"var(--color-border)",color:u||m||h||"var(--color-text-secondary)"},children:x}),!a&&(0,s.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,s.jsxs)("div",{className:"flex-1 min-w-0 pt-1 ".concat(a?"pb-1":"pb-3"),children:[(0,s.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(n?"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,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,s.jsx)("span",{className:"text-[13px] font-medium text-text-primary truncate",children:r.title}),(0,s.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,s.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,s.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[void 0!==r.duration&&(0,s.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,s.jsx)("span",{className:"text-[10px] text-text-dim",children:d}),!l&&(0,s.jsx)(sk,{isExpanded:n})]})]}),n&&!l&&g&&(0,s.jsxs)("div",{className:"mt-2 ml-1 pl-3 border-l-2 border-border/30",children:[r.description&&(0,s.jsx)("p",{className:"text-[13px] text-text-secondary mb-3 leading-relaxed",children:r.description}),p&&(0,s.jsx)("div",{className:"bg-bg-elevated/50 rounded-lg p-3 mb-3 overflow-x-auto border border-border/20",children:(0,s.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,s.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,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,s.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,s.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),"View Details"]})]})]})]})}function sp(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 sg(){return(0,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-blue-500",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4",strokeLinecap:"round",strokeLinejoin:"round"})})}function sb(){return(0,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.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 sf(){return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 sj(){return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 sy(){return(0,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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 sv(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,s.jsx)("path",{d:"M9 12h6m-3-3v6"})]})}function sw(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("path",{d:"M12 6v6l4 2"})]})}function sN(){return(0,s.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("circle",{cx:"12",cy:"16",r:"0.5",fill:"currentColor"})]})}function sk(e){let{isExpanded:t}=e;return(0,s.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,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function sC(){return(0,s.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-text-dim",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function sS(){return(0,s.jsx)("svg",{className:"animate-spin",width:"20",height:"20",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round",className:"text-accent"})})}function sL(e){let{decisions:t,onApprove:r,onReject:a,onDismiss:o,isProcessing:l={}}=e,[i,c]=(0,n.useState)(null),[d,x]=(0,n.useState)({}),u=(0,n.useMemo)(()=>{let e={critical:0,high:1,medium:2,low:3};return[...t].sort((t,r)=>{let s=e[t.priority]-e[r.priority];return 0!==s?s:new Date(t.timestamp).getTime()-new Date(r.timestamp).getTime()})},[t]),m=(0,n.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])),x(t=>{let r={...t};return delete r[e.id],r})};return 0===t.length?(0,s.jsxs)("div",{className:"decision-queue decision-queue-empty",children:[(0,s.jsx)(sE,{}),(0,s.jsx)("span",{children:"No pending decisions"})]}):(0,s.jsxs)("div",{className:"decision-queue",children:[(0,s.jsxs)("div",{className:"decision-queue-header",children:[(0,s.jsxs)("div",{className:"decision-queue-title",children:[(0,s.jsx)(sW,{}),(0,s.jsx)("span",{children:"Pending Decisions"}),(0,s.jsx)("span",{className:"decision-queue-count",children:t.length})]}),(0,s.jsxs)("div",{className:"decision-queue-summary",children:[m.critical&&(0,s.jsxs)("span",{className:"decision-priority-badge critical",children:[m.critical," critical"]}),m.high&&(0,s.jsxs)("span",{className:"decision-priority-badge high",children:[m.high," high"]})]})]}),(0,s.jsx)("div",{className:"decision-queue-list",children:u.map(e=>(0,s.jsx)(sA,{decision:e,isExpanded:i===e.id,isProcessing:l[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=>x(r=>({...r,[e.id]:t})),onDismiss:()=>null==o?void 0:o(e.id)},e.id))})]})}function sA(e){let{decision:t,isExpanded:r,isProcessing:n,rejectReason:o,onToggle:l,onApprove:i,onReject:c,onRejectReasonChange:d,onDismiss:x}=e,u=(0,a.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,s=t.getTime()-r.getTime();if(s<=0)return{text:"Expired",urgent:!0};let n=Math.floor(s/6e4);return n<5?{text:"".concat(n,"m left"),urgent:!0}:n<60?{text:"".concat(n,"m left"),urgent:!1}:{text:"".concat(Math.floor(n/60),"h left"),urgent:!1}}(t.expiresAt):null;return(0,s.jsxs)("div",{className:"decision-card ".concat(t.priority),children:[(0,s.jsxs)("div",{className:"decision-card-header",onClick:l,children:[(0,s.jsx)("div",{className:"decision-card-avatar",style:{backgroundColor:u.primary,color:u.text},children:(0,a.hP)(t.agentName)}),(0,s.jsxs)("div",{className:"decision-card-info",children:[(0,s.jsxs)("div",{className:"decision-card-title",children:[(0,s.jsx)("span",{className:"decision-card-agent",children:t.agentName}),(0,s.jsx)("span",{className:"decision-card-type",children:{approval:"Approval",choice:"Choice",confirmation:"Confirm",input:"Input"}[t.type]}),(0,s.jsx)(sM,{priority:t.priority})]}),(0,s.jsx)("div",{className:"decision-card-subtitle",children:t.title})]}),(0,s.jsxs)("div",{className:"decision-card-meta",children:[h&&(0,s.jsx)("span",{className:"decision-card-expires ".concat(h.urgent?"urgent":""),children:h.text}),(0,s.jsx)("span",{className:"decision-card-time",children:m}),(0,s.jsx)(sB,{isExpanded:r})]})]}),r&&(0,s.jsxs)("div",{className:"decision-card-body",children:[(0,s.jsx)("p",{className:"decision-card-desc",children:t.description}),t.context&&Object.keys(t.context).length>0&&(0,s.jsxs)("div",{className:"decision-card-context",children:[(0,s.jsx)("span",{className:"decision-card-context-label",children:"Context"}),(0,s.jsx)("pre",{children:JSON.stringify(t.context,null,2)})]}),"choice"===t.type&&t.options&&(0,s.jsx)("div",{className:"decision-card-options",children:t.options.map(e=>(0,s.jsxs)("button",{className:"decision-card-option",onClick:()=>i(e.id),disabled:n,children:[(0,s.jsx)("span",{className:"decision-option-label",children:e.label}),e.description&&(0,s.jsx)("span",{className:"decision-option-desc",children:e.description})]},e.id))}),"choice"!==t.type&&(0,s.jsxs)("div",{className:"decision-card-actions",children:[(0,s.jsxs)("button",{className:"decision-btn decision-btn-approve",onClick:()=>i(),disabled:n,children:[n?(0,s.jsx)(sT,{}):(0,s.jsx)(sE,{}),"confirmation"===t.type?"Confirm":"Approve"]}),(0,s.jsxs)("div",{className:"decision-reject-group",children:[(0,s.jsx)("input",{type:"text",className:"decision-reject-input",placeholder:"Reason (optional)",value:o,onChange:e=>d(e.target.value),disabled:n}),(0,s.jsxs)("button",{className:"decision-btn decision-btn-reject",onClick:c,disabled:n,children:[(0,s.jsx)(sD,{}),"Reject"]})]})]}),(0,s.jsx)("button",{className:"decision-card-dismiss",onClick:x,disabled:n,children:"Dismiss without action"})]})]})}function sM(e){let{priority:t}=e;return(0,s.jsx)("span",{className:"decision-priority-badge ".concat(t),children:t})}function sW(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function sE(){return(0,s.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function sD(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function sB(e){let{isExpanded:t}=e;return(0,s.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,s.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function sT(){return(0,s.jsx)("svg",{className:"decision-spinner",width:"14",height:"14",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sR(e){var t;let{server:r,isSelected:n=!1,onClick:a,onReconnect:o,compact:l=!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 l?(0,s.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(n?"bg-bg-elevated border-accent-cyan":"","\n ").concat("offline"===r.status?"opacity-70":"","\n "),onClick:a,children:[(0,s.jsx)("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:i}}),(0,s.jsx)("span",{className:"flex-1 text-sm font-medium text-text-primary text-left",children:r.name}),(0,s.jsx)("span",{className:"text-xs text-text-muted bg-bg-tertiary px-1.5 py-0.5 rounded-full",children:r.agentCount})]}):(0,s.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(n?"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,s.jsxs)("div",{className:"flex items-start justify-between mb-4",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(sP,{}),(0,s.jsxs)("div",{className:"flex flex-col",children:[(0,s.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:r.name}),r.region&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:r.region})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-xs font-medium",style:{color:i},children:[(0,s.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 ".concat("connecting"===r.status?"animate-pulse":""),style:{backgroundColor:i}}),(0,s.jsx)("span",{children:c})]})]}),(0,s.jsxs)("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(60px,1fr))] gap-3 mb-4",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsx)("span",{className:"text-lg font-semibold text-text-primary",children:r.agentCount}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Agents"})]}),void 0!==r.messageRate&&(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsxs)("span",{className:"text-lg font-semibold text-text-primary",children:[r.messageRate,"/s"]}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Messages"})]}),void 0!==r.latency&&(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.jsxs)("span",{className:"text-lg font-semibold text-text-primary",children:[r.latency,"ms"]}),(0,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Latency"})]}),void 0!==r.uptime&&(0,s.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,s.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,s.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Uptime"})]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between pt-3 border-t border-border-subtle",children:[(0,s.jsx)("span",{className:"text-[11px] text-text-muted font-mono",children:r.url}),r.version&&(0,s.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&&o&&(0,s.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(),o()},children:[(0,s.jsx)(s_,{}),"Reconnect"]})]})}function sP(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),(0,s.jsx)("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]})}function s_(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"23 4 23 10 17 10"}),(0,s.jsx)("polyline",{points:"1 20 1 14 7 14"}),(0,s.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 sI(e){let{servers:t,agents:r,selectedServerId:o,onServerSelect:l,onServerReconnect:i,isLoading:c=!1}=e,[d,x]=(0,n.useState)("grid"),u=(0,n.useMemo)(()=>{let e=t.filter(e=>"online"===e.status).length,r=t.reduce((e,t)=>e+t.agentCount,0),s=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,n=t.reduce((e,t)=>e+(t.messageRate||0),0);return{online:e,total:t.length,totalAgents:r,avgLatency:s,totalMessages:n}},[t]),m=(0,n.useMemo)(()=>{let e={};return t.forEach(t=>{e[t.id]=[]}),r.forEach((r,s)=>{let n=s%t.length;t[n]&&e[t[n].id].push(r)}),e},[t,r]);return c?(0,s.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,s.jsx)(sH,{}),(0,s.jsx)("span",{className:"mt-3 text-sm",children:"Loading fleet data..."})]}):0===t.length?(0,s.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,s.jsx)(sz,{}),(0,s.jsx)("h3",{className:"mt-4 mb-2 text-base font-semibold text-text-primary",children:"No Fleet Servers"}),(0,s.jsx)("p",{className:"text-sm",children:"Connect to peer servers to enable fleet view"})]}):(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg border border-border-subtle overflow-hidden",children:[(0,s.jsxs)("div",{className:"flex items-center gap-6 p-4 border-b border-border-subtle bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 font-semibold text-sm text-text-primary",children:[(0,s.jsx)(sF,{}),(0,s.jsx)("span",{children:"Fleet Overview"})]}),(0,s.jsxs)("div",{className:"flex gap-6 flex-1",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.online,"/",u.total]}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Servers"})]}),(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsx)("span",{className:"text-base font-semibold text-text-primary",children:u.totalAgents}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Agents"})]}),null!==u.avgLatency&&(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.avgLatency,"ms"]}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Avg Latency"})]}),(0,s.jsxs)("div",{className:"flex flex-col items-center",children:[(0,s.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.totalMessages,"/s"]}),(0,s.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Messages"})]})]}),(0,s.jsxs)("div",{className:"flex gap-1 bg-bg-tertiary rounded-md p-0.5",children:[(0,s.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"===d?"bg-bg-card text-text-primary shadow-sm":"text-text-muted hover:text-text-secondary"),onClick:()=>x("grid"),title:"Grid view",children:(0,s.jsx)(sU,{})}),(0,s.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"===d?"bg-bg-card text-text-primary shadow-sm":"text-text-muted hover:text-text-secondary"),onClick:()=>x("list"),title:"List view",children:(0,s.jsx)(sO,{})})]})]}),(0,s.jsx)("div",{className:"flex h-1 bg-bg-tertiary",children:t.map(e=>(0,s.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,s.jsx)("div",{className:"p-4 ".concat("grid"===d?"grid grid-cols-[repeat(auto-fill,minmax(280px,1fr))] gap-4":"flex flex-col gap-2"),children:t.map(e=>{var t;return(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)(sR,{server:e,isSelected:e.id===o,onClick:()=>null==l?void 0:l(e.id),onReconnect:()=>null==i?void 0:i(e.id),compact:"list"===d}),"grid"===d&&(null===(t=m[e.id])||void 0===t?void 0:t.length)>0&&(0,s.jsxs)("div",{className:"flex gap-1 px-2",children:[m[e.id].slice(0,5).map((e,t)=>{let r=(0,a.GW)(e.name);return(0,s.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,a.hP)(e.name)},e.name)}),m[e.id].length>5&&(0,s.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 sF(){return(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,s.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function sU(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"7",height:"7"}),(0,s.jsx)("rect",{x:"14",y:"3",width:"7",height:"7"}),(0,s.jsx)("rect",{x:"3",y:"14",width:"7",height:"7"}),(0,s.jsx)("rect",{x:"14",y:"14",width:"7",height:"7"})]})}function sO(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"8",y1:"6",x2:"21",y2:"6"}),(0,s.jsx)("line",{x1:"8",y1:"12",x2:"21",y2:"12"}),(0,s.jsx)("line",{x1:"8",y1:"18",x2:"21",y2:"18"}),(0,s.jsx)("line",{x1:"3",y1:"6",x2:"3.01",y2:"6"}),(0,s.jsx)("line",{x1:"3",y1:"12",x2:"3.01",y2:"12"}),(0,s.jsx)("line",{x1:"3",y1:"18",x2:"3.01",y2:"18"})]})}function sz(){return(0,s.jsxs)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,s.jsx)("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),(0,s.jsx)("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]})}function sH(){return(0,s.jsx)("svg",{className:"animate-spin",width:"24",height:"24",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sV(e){let{typingUsers:t}=e;return 0===t.length?null:(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 text-sm text-[#8d8d8e]",children:[(0,s.jsx)("div",{className:"flex -space-x-1.5",children:t.slice(0,3).map(e=>(0,s.jsx)("div",{className:"relative",title:e.username,children:e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-5 h-5 rounded-full border border-[#1a1d21]"}):(0,s.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,s.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,s.jsxs)("span",{className:"flex gap-0.5",children:[(0,s.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"0ms"}}),(0,s.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"150ms"}}),(0,s.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})]})]})}function sG(e){let{onlineUsers:t,onUserClick:r,maxAvatars:a=4}=e,[o,l]=(0,n.useState)(!1),i=(0,n.useRef)(null);if((0,n.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&l(!1)};return o&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[o]),0===t.length)return null;let c=t.slice(0,a),d=Math.max(0,t.length-a);return(0,s.jsxs)("div",{className:"relative",ref:i,children:[(0,s.jsxs)("button",{onClick:()=>l(!o),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,s.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,s.jsxs)("div",{className:"flex -space-x-1.5",children:[c.map(e=>(0,s.jsx)("div",{className:"relative ring-2 ring-[#1a1d21] rounded-full",title:e.username,children:e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-6 h-6 rounded-full object-cover"}):(0,s.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,s.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,s.jsxs)("span",{className:"text-xs text-[#8d8d8e]",children:[t.length," online"]})]}),o&&(0,s.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,s.jsx)("div",{className:"p-2 border-b border-white/10",children:(0,s.jsx)("h3",{className:"text-sm font-medium text-[#d1d2d3]",children:"Online Users"})}),(0,s.jsx)("div",{className:"py-1",children:t.map(e=>(0,s.jsxs)("button",{onClick:()=>{null==r||r(e),l(!1)},className:"w-full flex items-center gap-3 px-3 py-2 hover:bg-white/[0.05] transition-colors text-left",children:[(0,s.jsxs)("div",{className:"relative",children:[e.avatarUrl?(0,s.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-8 h-8 rounded-full object-cover"}):(0,s.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,s.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 bg-green-500 rounded-full border-2 border-[#1a1d21]"})]}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"text-sm font-medium text-[#d1d2d3] truncate",children:e.username}),(0,s.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 sK(e){let{user:t,onClose:r,onMention:a,onSendMessage:o}=e,l=(0,n.useRef)(null);(0,n.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return t&&window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,r]);let i=(0,n.useRef)(!1);if((0,n.useEffect)(()=>{t&&(i.current=!0)},[t]),(0,n.useEffect)(()=>{let e=e=>{if(i.current){i.current=!1;return}l.current&&!l.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,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40"}),(0,s.jsxs)("div",{ref:l,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,s.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-[#d1d2d3]",children:"Profile"}),(0,s.jsx)("button",{onClick:r,className:"p-1 hover:bg-white/10 rounded-md transition-colors",title:"Close",children:(0,s.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),(0,s.jsxs)("div",{className:"flex flex-col items-center p-6 border-b border-white/10",children:[(0,s.jsxs)("div",{className:"relative mb-4",children:[t.avatarUrl?(0,s.jsx)("img",{src:t.avatarUrl,alt:t.username,className:"w-24 h-24 rounded-full object-cover border-4 border-[#a855f7]/30"}):(0,s.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,s.jsx)("div",{className:"absolute bottom-1 right-1 w-5 h-5 bg-green-500 rounded-full border-4 border-[#1a1d21]"})]}),(0,s.jsx)("h3",{className:"text-xl font-semibold text-[#d1d2d3] mb-1",children:t.username}),(0,s.jsxs)("span",{className:"text-sm text-green-400 flex items-center gap-1.5",children:[(0,s.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),"Online"]})]}),(0,s.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Online Since"}),(0,s.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sZ(t.connectedAt)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Last Active"}),(0,s.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sZ(t.lastSeen)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"GitHub"}),(0,s.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,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.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,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14L21 3"})})]})]})]})}),(0,s.jsxs)("div",{className:"p-4 border-t border-white/10 space-y-2",children:[(0,s.jsxs)("button",{onClick:()=>{null==o||o(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,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.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,s.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,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,s.jsx)("path",{d:"M16 8v5a3 3 0 006 0v-1a10 10 0 10-3.92 7.94"})]}),"Mention @",t.username]}),(0,s.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,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:(0,s.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 sZ(e){return new Date(e).toLocaleString([],{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}function sq(e){let{user:t,onClose:r,messages:a,agents:o,humanUsers:l,onSend:i,onTyping:c,isSending:d,sendError:x,currentUser:u}=e,[m,h]=(0,n.useState)(!0),[p,g]=(0,n.useState)([]),[b,f]=(0,n.useState)(""),j=(0,n.useMemo)(()=>{if(null==u?void 0:u.displayName)return u.displayName;if(!t)return null;for(let e of a){if(e.to===t.username&&e.from!==t.username)return e.from;if(e.from===t.username&&e.to&&e.to!==t.username)return e.to}return null},[null==u?void 0:u.displayName,a,t]),y=(0,n.useMemo)(()=>{let e=new Set(o.map(e=>e.name)),r=new Set;for(let t of a)e.has(t.from)&&r.add(t.from),e.has(t.to)&&r.add(t.to);return t&&r.delete(t.username),u&&r.delete(u.displayName),Array.from(r)},[o,a,t,u]);(0,n.useEffect)(()=>{g(e=>Array.from(new Set([...e,...y])))},[y]);let v=(0,n.useMemo)(()=>Array.from(new Set([...p,...y])),[p,y]),w=(0,n.useMemo)(()=>{if(!t)return[];let e=new Set;return e.add(t.username),j&&e.add(j),v.forEach(t=>e.add(t)),a.filter(t=>!!t.from&&!!t.to&&e.has(t.from)&&e.has(t.to))},[a,v,j,t]),N=(0,n.useMemo)(()=>{var e,t,r,s;let n=e=>(null!=e?e:"").trim().replace(/\s+/g," "),a=e=>"sending"===e.status?1:0,o=(e,t)=>{let r=a(e),s=a(t),n=new Date(e.timestamp).getTime(),o=new Date(t.timestamp).getTime();return s<r?t:s>r?e:o>=n?t:e},l=[...w].sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),i=new Map,c=new Map;for(let r of l){if(r.id){let e=i.get(r.id);i.set(r.id,e?o(e,r):r);continue}let s=null!==(t=null===(e=r.from)||void 0===e?void 0:e.toLowerCase())&&void 0!==t?t:"",a=Math.floor(new Date(r.timestamp).getTime()/5e3),l="".concat(s,"|").concat(a,"|").concat(n(r.content)),d=c.get(l);c.set(l,d?o(d,r):r)}let d=[...i.values(),...c.values()],x=new Map;for(let e of d){let t=null!==(s=null===(r=e.from)||void 0===r?void 0:r.toLowerCase())&&void 0!==s?s:"",a=Math.floor(new Date(e.timestamp).getTime()/5e3),l="".concat(t,"|").concat(a,"|").concat(n(e.content)),i=x.get(l);x.set(l,i?o(i,e):e)}return Array.from(x.values()).sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())},[w]),k=(0,n.useMemo)(()=>(null==t?void 0:t.username)||"",[t]),C=(0,n.useCallback)(e=>{g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),S=(0,n.useMemo)(()=>{let e=b.trim().toLowerCase();return o.filter(t=>!!v.includes(t.name)||!e||t.name.toLowerCase().includes(e))},[o,b,v]),L=(0,n.useCallback)(async(e,r)=>{if(p.length>0){for(let e of(await i(t.username,r),p))await i(e,r);return!0}return i(e,r)},[p,t,i]);return t?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 z-50",onClick:r}),(0,s.jsxs)("div",{className:"fixed inset-4 md:inset-x-auto md:inset-y-8 md:left-1/2 md:-translate-x-1/2 md:w-full md:max-w-3xl bg-bg-primary border border-border-subtle rounded-xl shadow-2xl z-50 flex flex-col overflow-hidden",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border-subtle bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[t.avatarUrl?(0,s.jsx)("img",{src:t.avatarUrl,alt:t.username,className:"w-8 h-8 rounded-full object-cover"}):(0,s.jsx)("div",{className:"w-8 h-8 rounded-full bg-accent-purple flex items-center justify-center text-sm text-white font-medium",children:t.username.charAt(0).toUpperCase()}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-base font-semibold text-text-primary",children:p.length>0?"Group Message":"Direct Message"}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:p.length>0?"".concat(t.username,", ").concat(p.join(", ")):t.username})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("button",{onClick:()=>h(!m),className:"px-3 py-1.5 text-xs font-medium rounded-lg transition-colors ".concat(m?"bg-accent-cyan text-bg-deep":"bg-bg-tertiary text-text-secondary hover:bg-bg-tertiary/80"),title:"Invite agents to this conversation",children:[(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"inline mr-1",children:[(0,s.jsx)("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),(0,s.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,s.jsx)("line",{x1:"19",y1:"8",x2:"19",y2:"14"}),(0,s.jsx)("line",{x1:"22",y1:"11",x2:"16",y2:"11"})]}),p.length>0?"".concat(p.length," Agents"):"Invite Agents"]}),(0,s.jsx)("button",{onClick:r,className:"p-1.5 hover:bg-bg-tertiary rounded-md transition-colors text-text-muted hover:text-text-primary",title:"Close",children:(0,s.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]})]}),m&&(0,s.jsxs)("div",{className:"border-b border-border-subtle bg-bg-secondary p-3 space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("p",{className:"text-xs text-text-muted m-0 flex-1",children:"Invite agents to this conversation"}),(0,s.jsx)("input",{type:"text",value:b,onChange:e=>f(e.target.value),placeholder:"Search agents...",className:"text-xs px-2 py-1 bg-bg-tertiary border border-border-subtle rounded-md text-text-primary flex-1"})]}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[S.map(e=>(0,s.jsxs)("button",{onClick:()=>C(e.name),className:"px-3 py-1.5 text-xs font-medium rounded-lg transition-colors ".concat(p.includes(e.name)?"bg-accent-cyan text-bg-deep":"bg-bg-tertiary text-text-secondary hover:bg-bg-tertiary/80"),title:e.name,children:[p.includes(e.name)?"✓ ":"",e.name]},e.name)),0===S.length&&(0,s.jsxs)("p",{className:"text-xs text-text-muted",children:['No agents match "',b,'"']})]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto min-h-0 p-4 space-y-3",children:N.length>0?N.map(e=>{let t=u&&e.from===u.displayName,r=p.includes(e.from);return(0,s.jsx)("div",{className:"flex ".concat(t?"justify-end":"justify-start"),children:(0,s.jsxs)("div",{className:"max-w-[80%] rounded-lg px-3 py-2 ".concat(t?"bg-accent-cyan text-bg-deep":r?"bg-accent-purple/20 text-text-primary border border-accent-purple/30":"bg-bg-tertiary text-text-primary"),children:[!t&&(0,s.jsx)("div",{className:"text-xs font-medium mb-1 opacity-70",children:e.from}),(0,s.jsx)("div",{className:"text-sm whitespace-pre-wrap break-words",children:e.content}),(0,s.jsx)("div",{className:"text-[10px] mt-1 opacity-60",children:new Date(e.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})},e.id)}):(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted text-center px-4",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"mx-auto mb-3 opacity-40",children:(0,s.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,s.jsx)("p",{className:"text-sm",children:"No messages yet"}),(0,s.jsxs)("p",{className:"text-xs mt-1",children:["Send a message to start the conversation",p.length>0&&" with ".concat(t.username," and ").concat(p.join(", "))]})]})})}),(0,s.jsx)(sJ,{recipient:k,onSend:L,isSending:d,error:x})]})]}):null}function sJ(e){let{recipient:t,onSend:r,isSending:a,error:o}=e,[l,i]=(0,n.useState)(""),c=(0,n.useCallback)(async e=>{e.preventDefault(),l.trim()&&!a&&await r(t,l.trim())&&i("")},[l,t,r,a]);return(0,s.jsxs)("div",{className:"border-t border-border-subtle bg-bg-secondary p-3",children:[o&&(0,s.jsx)("div",{className:"mb-2 text-xs text-error bg-error/10 px-2 py-1 rounded",children:o}),(0,s.jsxs)("form",{onSubmit:c,className:"flex gap-2",children:[(0,s.jsx)("input",{type:"text",value:l,onChange:e=>i(e.target.value),placeholder:"Type a message...",disabled:a,className:"flex-1 bg-bg-tertiary text-text-primary px-3 py-2 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-accent-cyan disabled:opacity-50"}),(0,s.jsx)("button",{type:"submit",disabled:!l.trim()||a,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 disabled:cursor-not-allowed transition-colors",children:a?"Sending...":"Send"})]})]})}function sY(e){let{isOpen:t,onClose:r,projects:a,isCloudMode:o=!1,hasArchitect:l=!1,onArchitectSpawned:i}=e,[c,d]=(0,n.useState)([]),[x,u]=(0,n.useState)([]),[m,h]=(0,n.useState)(!1),[p,g]=(0,n.useState)(null),[b,f]=(0,n.useState)(!1),[j,y]=(0,n.useState)(""),[v,w]=(0,n.useState)(""),[N,k]=(0,n.useState)(new Set),[C,S]=(0,n.useState)(!1),[L,A]=(0,n.useState)("claude"),[M,W]=(0,n.useState)(null),[E,D]=(0,n.useState)(null),[B,T]=(0,n.useState)(new Set);(0,n.useEffect)(()=>{t&&o&&R()},[t,o]);let R=async()=>{h(!0),g(null);try{let e=await fetch("/api/project-groups");if(e.ok){let t=await e.json();d(t.groups||[]),u(t.ungroupedRepositories||[])}else{let t=await e.json().catch(()=>({}));g(t.error||"Failed to load project groups")}}catch(e){g("Failed to load project groups")}finally{h(!1)}},P=async()=>{if(j.trim()&&0!==N.size){h(!0),g(null);try{let e=await fetch("/api/project-groups",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:j.trim(),description:v.trim()||void 0,repositoryIds:Array.from(N)})});if(e.ok){let t=await e.json();t.group&&(d(e=>[...e,t.group]),u(e=>e.filter(e=>!N.has(e.id))),f(!1),y(""),w(""),k(new Set))}else{let t=await e.json().catch(()=>({}));g(t.error||"Failed to create project group")}}catch(e){g("Failed to create project group")}finally{h(!1)}}},_=async(e,t)=>{g(null);try{let r=await fetch("/api/project-groups/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(r.ok){let t=await r.json();t.group&&(d(r=>r.map(r=>r.id===e?{...r,...t.group}:r)),W(null))}else{let e=await r.json().catch(()=>({}));g(e.error||"Failed to update project group")}}catch(e){g("Failed to update project group")}},I=async(e,t)=>{g(null);try{let r="/api/project-groups/".concat(e,"/coordinator/").concat(t?"enable":"disable"),s=await fetch(r,{method:"POST"});if(s.ok){let r=await s.json();d(s=>s.map(s=>{var n,a;return s.id===e?{...s,coordinatorAgent:{...s.coordinatorAgent,enabled:t,name:(null===(n=r.coordinator)||void 0===n?void 0:n.name)||(null===(a=s.coordinatorAgent)||void 0===a?void 0:a.name)}}:s}))}else{let e=await s.json().catch(()=>({}));g(e.error||"Failed to ".concat(t?"enable":"disable"," coordinator"))}}catch(e){g("Failed to ".concat(t?"enable":"disable"," coordinator"))}},F=async e=>{if(window.confirm("Delete this project group? The coordinator will be stopped and repositories will be ungrouped."))try{let t=c.find(t=>t.id===e),r=await fetch("/api/project-groups/".concat(e),{method:"DELETE"});if(r.ok)d(t=>t.filter(t=>t.id!==e)),(null==t?void 0:t.repositories)&&u(e=>[...e,...t.repositories]);else{let e=await r.json().catch(()=>({}));g(e.error||"Failed to delete project group")}}catch(e){g("Failed to delete project group")}},U=async(e,t)=>{try{let r=await fetch("/api/project-groups/".concat(e,"/repositories/").concat(t),{method:"DELETE"});if(r.ok){let r=c.find(t=>t.id===e),s=null==r?void 0:r.repositories.find(e=>e.id===t);d(r=>r.map(r=>r.id===e?{...r,repositories:r.repositories.filter(e=>e.id!==t),repositoryCount:r.repositoryCount-1}:r)),s&&u(e=>[...e,s])}else{let e=await r.json().catch(()=>({}));g(e.error||"Failed to remove repository from group")}}catch(e){g("Failed to remove repository from group")}},O=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"},body:JSON.stringify({repositoryIds:t})});if(r.ok)await R(),D(null),T(new Set);else{let e=await r.json().catch(()=>({}));g(e.error||"Failed to add repositories to group")}}catch(e){g("Failed to add repositories to group")}},z=e=>{T(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},H=e=>{k(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};if(!t)return null;let V=async()=>{S(!0),g(null);try{let e=await fetch("/api/spawn/architect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cli:L})}),t=await e.json();e.ok&&t.success?(null==i||i(),r()):g(t.error||"Failed to spawn Architect")}catch(e){g("Failed to spawn Architect")}finally{S(!1)}};if(!o){let e=a.length>1;return(0,s.jsx)("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between py-5 px-6 border-b border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(sQ,{}),(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Coordinator Agent"})]}),(0,s.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,s.jsx)(s0,{})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[p&&(0,s.jsx)("div",{className:"bg-error/10 border border-error/30 rounded-lg p-3 mb-4 text-error text-sm",children:p}),e&&(0,s.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,s.jsxs)("h3",{className:"text-sm font-semibold text-text-primary mb-3 flex items-center gap-2",children:[(0,s.jsx)(sQ,{}),"Spawn Architect"]}),l?(0,s.jsxs)("div",{className:"flex items-center gap-2 text-sm text-success",children:[(0,s.jsx)(s3,{}),"Architect is running"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("p",{className:"text-sm text-text-secondary mb-4",children:["Spawn an Architect agent to coordinate across your ",a.length," connected projects."]}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.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:L,onChange:e=>A(e.target.value),children:[(0,s.jsx)("option",{value:"claude",children:"Claude (default)"}),(0,s.jsx)("option",{value:"claude:opus",children:"Claude Opus"}),(0,s.jsx)("option",{value:"claude:sonnet",children:"Claude Sonnet"}),(0,s.jsx)("option",{value:"codex",children:"Codex"})]}),(0,s.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:V,disabled:C,children:C?"Spawning...":"Spawn"})]})]})]}),!e&&(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 mb-4 border border-border-subtle",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-primary mb-2",children:"Not in Bridge Mode"}),(0,s.jsx)("p",{className:"text-sm text-text-secondary",children:"The Architect coordinates multiple projects. Start bridge mode to enable:"}),(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg p-3 font-mono text-sm mt-3",children:[(0,s.jsx)("span",{className:"text-text-muted",children:"$"})," ",(0,s.jsx)("span",{className:"text-accent-cyan",children:"relay bridge"})," ",(0,s.jsx)("span",{className:"text-accent-orange",children:"~/project1 ~/project2"})]})]}),(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 mb-4",children:[(0,s.jsx)("h3",{className:"text-sm font-semibold text-text-primary mb-2",children:"CLI Alternative"}),(0,s.jsxs)("p",{className:"text-sm text-text-secondary mb-3",children:["You can also spawn the Architect via CLI with the ",(0,s.jsx)("code",{className:"bg-bg-card px-1.5 py-0.5 rounded text-accent-cyan",children:"--architect"})," flag:"]}),(0,s.jsxs)("div",{className:"bg-bg-card rounded-lg p-3 font-mono text-sm",children:[(0,s.jsx)("span",{className:"text-text-muted",children:"$"})," ",(0,s.jsx)("span",{className:"text-accent-cyan",children:"relay bridge"})," ",(0,s.jsx)("span",{className:"text-accent-orange",children:"~/project1 ~/project2"})," ",(0,s.jsx)("span",{className:"text-accent-purple",children:"--architect"})]})]})]}),(0,s.jsx)("div",{className:"flex justify-end py-4 px-6 border-t border-border-subtle",children:(0,s.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,s.jsx)("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between py-5 px-6 border-b border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(sQ,{}),(0,s.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Coordinator Agents"})]}),(0,s.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,s.jsx)(s0,{})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[p&&(0,s.jsx)("div",{className:"bg-error/10 border border-error/30 rounded-lg p-3 mb-4 text-error text-sm",children:p}),m&&0===c.length?(0,s.jsx)("div",{className:"flex items-center justify-center py-12 text-text-muted",children:(0,s.jsx)(sX,{})}):(0,s.jsxs)(s.Fragment,{children:[c.length>0&&(0,s.jsxs)("div",{className:"space-y-3 mb-6",children:[(0,s.jsx)("h4",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Project Groups"}),c.map(e=>{var t,r,n,a;return(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-border-subtle",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"font-semibold text-text-primary",children:e.name}),(0,s.jsxs)("span",{className:"text-xs text-text-muted",children:[e.repositoryCount," ",1===e.repositoryCount?"repo":"repos"]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{className:"text-text-muted hover:text-accent-cyan transition-colors p-1",onClick:()=>W(e),title:"Edit group",children:(0,s.jsx)(s1,{})}),(0,s.jsx)("button",{className:"text-text-muted hover:text-error transition-colors p-1",onClick:()=>F(e.id),title:"Delete group",children:(0,s.jsx)(s5,{})})]})]}),e.repositories.length>0&&(0,s.jsx)("div",{className:"mb-3 space-y-1",children:e.repositories.map(t=>(0,s.jsxs)("div",{className:"flex items-center justify-between py-1 px-2 bg-bg-card/50 rounded text-xs",children:[(0,s.jsx)("span",{className:"text-text-secondary font-mono",children:t.githubFullName}),(0,s.jsx)("button",{className:"text-text-muted hover:text-error transition-colors p-0.5",onClick:()=>U(e.id,t.id),title:"Remove from group",children:(0,s.jsx)(s0,{size:12})})]},t.id))}),e.description&&(0,s.jsx)("p",{className:"text-xs text-text-muted mb-3",children:e.description}),E===e.id?(0,s.jsxs)("div",{className:"mb-3 p-3 bg-bg-card rounded-lg border border-border-subtle",children:[(0,s.jsx)("div",{className:"text-xs font-medium text-text-muted mb-2",children:"Select repositories to add:"}),(0,s.jsx)("div",{className:"space-y-1 max-h-[150px] overflow-y-auto mb-3",children:x.length>0?x.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-2 p-1.5 rounded cursor-pointer hover:bg-bg-hover",children:[(0,s.jsx)("input",{type:"checkbox",className:"accent-accent-cyan",checked:B.has(e.id),onChange:()=>z(e.id)}),(0,s.jsx)("span",{className:"text-xs text-text-primary font-mono",children:e.githubFullName})]},e.id)):(0,s.jsx)("p",{className:"text-xs text-text-muted py-2 text-center",children:"No ungrouped repositories available"})}),(0,s.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,s.jsx)("button",{className:"py-1 px-3 text-xs bg-transparent border border-border-subtle rounded text-text-secondary hover:bg-bg-hover",onClick:()=>{D(null),T(new Set)},children:"Cancel"}),(0,s.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:()=>O(e.id,Array.from(B)),disabled:0===B.size,children:"Add Selected"})]})]}):x.length>0?(0,s.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:()=>{D(e.id),T(new Set)},children:[(0,s.jsx)(s2,{}),"Add repositories"]}):null,(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(s$,{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,s.jsx)("span",{className:"text-sm text-text-secondary",children:e.coordinatorAgent.name})]}),(0,s.jsxs)("button",{className:"py-1.5 px-3 rounded-md text-xs font-medium transition-colors ".concat((null===(n=e.coordinatorAgent)||void 0===n?void 0:n.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&&I(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)})]}),M&&(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-accent-cyan/30 mb-4",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary mb-4",children:"Edit Project Group"}),(0,s.jsx)(s6,{group:M,onSave:e=>_(M.id,e),onCancel:()=>W(null)})]}),b?(0,s.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-accent-cyan/30",children:[(0,s.jsx)("h4",{className:"text-sm font-semibold text-text-primary mb-4",children:"Create Project Group"}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Group Name"}),(0,s.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:j,onChange:e=>y(e.target.value)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Description (optional)"}),(0,s.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:v,onChange:e=>w(e.target.value)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Select Repositories"}),(0,s.jsxs)("div",{className:"space-y-2 max-h-[200px] overflow-y-auto",children:[x.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-2 p-2 bg-bg-card rounded-md cursor-pointer hover:bg-bg-hover",children:[(0,s.jsx)("input",{type:"checkbox",className:"accent-accent-cyan",checked:N.has(e.id),onChange:()=>H(e.id)}),(0,s.jsx)("span",{className:"text-sm text-text-primary font-mono",children:e.githubFullName}),e.isPrivate&&(0,s.jsx)("span",{className:"text-xs text-text-muted",children:"\uD83D\uDD12"})]},e.id)),0===x.length&&(0,s.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,s.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,s.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:()=>{f(!1),y(""),w(""),k(new Set)},children:"Cancel"}),(0,s.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:P,disabled:!j.trim()||0===N.size||m,children:m?"Creating...":"Create Group"})]})]})]}):(0,s.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:()=>f(!0),disabled:!!M,children:[(0,s.jsx)(s2,{}),"Create Project Group"]}),(0,s.jsxs)("div",{className:"mt-6 p-4 bg-bg-tertiary/50 rounded-lg border border-border-subtle",children:[(0,s.jsxs)("h4",{className:"text-sm font-semibold text-text-primary mb-2 flex items-center gap-2",children:[(0,s.jsx)(s4,{}),"What is a Coordinator?"]}),(0,s.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 s$(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,s.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium ".concat(r[t]||r.stopped),children:t})}function sX(){return(0,s.jsx)("svg",{className:"animate-spin h-6 w-6 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sQ(){return(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,s.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,s.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,s.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,s.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,s.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,s.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function s0(e){let{size:t=20}=e;return(0,s.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function s1(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.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,s.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 s2(){return(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,s.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function s5(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,s.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 s4(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function s3(){return(0,s.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"text-success",children:(0,s.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function s6(e){let{group:t,onSave:r,onCancel:a}=e,[o,l]=(0,n.useState)(t.name),[i,c]=(0,n.useState)(t.description||"");return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Group Name"}),(0,s.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:o,onChange:e=>l(e.target.value)})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Description"}),(0,s.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,s.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,s.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,s.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={};o.trim()!==t.name&&(e.name=o.trim()),i.trim()!==(t.description||"")&&(e.description=i.trim()),Object.keys(e).length>0?r(e):a()},disabled:!o.trim(),children:"Save Changes"})]})]})}function s8(){let e=(0,n.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,s.jsxs)("div",{className:"fixed inset-0 pointer-events-none overflow-hidden z-50",children:[e.map(e=>(0,s.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,s.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 s9(){return(0,s.jsxs)("div",{className:"relative w-20 h-20",children:[(0,s.jsx)("div",{className:"absolute inset-0 rounded-full bg-gradient-to-r from-emerald-400 to-cyan-400 opacity-20 animate-pulse-slow"}),(0,s.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,s.jsx)("div",{className:"w-full h-full rounded-full bg-bg-primary flex items-center justify-center",children:(0,s.jsxs)("svg",{className:"w-10 h-10",viewBox:"0 0 24 24",fill:"none",children:[(0,s.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,s.jsx)("defs",{children:(0,s.jsxs)("linearGradient",{id:"check-gradient",x1:"5",y1:"12",x2:"19",y2:"7",children:[(0,s.jsx)("stop",{stopColor:"#34d399"}),(0,s.jsx)("stop",{offset:"1",stopColor:"#22d3ee"})]})})]})})}),(0,s.jsx)("div",{className:"absolute -top-1 -right-1 w-3 h-3 bg-yellow-400 rounded-full animate-sparkle",style:{animationDelay:"0.5s"}}),(0,s.jsx)("div",{className:"absolute top-0 -left-2 w-2 h-2 bg-cyan-400 rounded-full animate-sparkle",style:{animationDelay:"0.7s"}}),(0,s.jsx)("div",{className:"absolute -bottom-1 right-2 w-2 h-2 bg-emerald-400 rounded-full animate-sparkle",style:{animationDelay:"0.9s"}}),(0,s.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 s7(){return(0,s.jsxs)("div",{className:"relative w-20 h-20",children:[(0,s.jsx)("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent-cyan border-r-accent-cyan/50 animate-spin"}),(0,s.jsx)("div",{className:"absolute inset-3 rounded-full bg-gradient-to-br from-accent-cyan/20 to-transparent animate-pulse"}),(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)("div",{className:"w-3 h-3 rounded-full bg-accent-cyan animate-ping"})}),(0,s.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"3s"},children:(0,s.jsx)("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 w-2 h-2 rounded-full bg-accent-cyan/80"})}),(0,s.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"4s",animationDirection:"reverse"},children:(0,s.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 ne(e){let{children:t,delay:r}=e;return(0,s.jsxs)("li",{className:"flex items-center gap-3 opacity-0 animate-slide-in-left",style:{animationDelay:"".concat(r,"s"),animationFillMode:"forwards"},children:[(0,s.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,s.jsx)("svg",{className:"w-3 h-3 text-white",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:(0,s.jsx)("path",{d:"M20 6L9 17l-5-5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,s.jsx)("span",{className:"text-text-secondary",children:t}),(0,s.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 nt(e){let{type:t,sessionId:r,onClose:a}=e,[o,l]=(0,n.useState)(null),[i,c]=(0,n.useState)("success"===t),[d,x]=(0,n.useState)(null),[u,m]=(0,n.useState)(!1);(0,n.useEffect)(()=>{"success"===t&&(async()=>{try{await new Promise(e=>setTimeout(e,1500));let r=await ei.xv.getSubscription();if(r.success&&r.data){var e,t;l({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(()=>m(!0),200)}}catch(e){x("Could not verify subscription. Please check your billing settings.")}finally{c(!1)}})()},[t,r]);let h=(null==o?void 0:o.plan)==="pro"?"Pro":(null==o?void 0:o.plan)==="team"?"Team":(null==o?void 0:o.plan)==="enterprise"?"Enterprise":"Premium";return"success"===t?(0,s.jsxs)("div",{className:"min-h-screen bg-bg-deep flex items-center justify-center p-4 overflow-hidden",children:[(0,s.jsxs)("div",{className:"fixed inset-0 overflow-hidden pointer-events-none",children:[(0,s.jsx)("div",{className:"absolute top-1/4 -left-32 w-96 h-96 bg-accent-cyan/10 rounded-full blur-3xl animate-float"}),(0,s.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"}})]}),u&&(0,s.jsx)(s8,{}),(0,s.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,s.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,s.jsxs)("div",{className:"py-8",children:[(0,s.jsx)("div",{className:"flex justify-center mb-8",children:(0,s.jsx)(s7,{})}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3 tracking-tight",children:"Processing your upgrade"}),(0,s.jsx)("p",{className:"text-text-muted",children:"Confirming your subscription..."})]}):d?(0,s.jsxs)("div",{className:"py-4",children:[(0,s.jsx)("div",{className:"w-16 h-16 mx-auto mb-6 rounded-full bg-amber-500/20 flex items-center justify-center",children:(0,s.jsxs)("svg",{className:"w-8 h-8 text-amber-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3",children:"Almost there!"}),(0,s.jsx)("p",{className:"text-text-muted mb-8",children:d}),(0,s.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,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"flex justify-center mb-6",children:(0,s.jsx)(s9,{})}),(0,s.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 ",h,"!"]}),(0,s.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,s.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,s.jsx)("h3",{className:"text-xs font-bold text-accent-cyan uppercase tracking-wider mb-4",children:"Your new powers"}),(0,s.jsxs)("ul",{className:"space-y-3 text-sm",children:[(0,s.jsx)(ne,{delay:.8,children:"Expanded workspace & repository limits"}),(0,s.jsx)(ne,{delay:.9,children:"More compute hours for your agents"}),(0,s.jsx)(ne,{delay:1,children:"Increased concurrent agent capacity"}),(0,s.jsx)(ne,{delay:1.1,children:"Priority support & faster responses"})]})]}),(0,s.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,s.jsxs)("span",{className:"flex items-center justify-center gap-2",children:["Launch Dashboard",(0,s.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,s.jsx)("path",{d:"M5 12h14M12 5l7 7-7 7",strokeLinecap:"round",strokeLinejoin:"round"})})]})})]})]}),(0,s.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,s.jsxs)("div",{className:"min-h-screen bg-bg-deep flex items-center justify-center p-4",children:[(0,s.jsx)("div",{className:"fixed inset-0 overflow-hidden pointer-events-none",children:(0,s.jsx)("div",{className:"absolute top-1/3 left-1/4 w-64 h-64 bg-text-muted/5 rounded-full blur-3xl"})}),(0,s.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,s.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,s.jsx)("svg",{className:"w-7 h-7 text-text-muted",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3",children:"No problem!"}),(0,s.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,s.jsxs)("div",{className:"space-y-3",children:[(0,s.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,s.jsxs)("span",{className:"flex items-center justify-center gap-2",children:["Return to Dashboard",(0,s.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,s.jsx)("path",{d:"M5 12h14M12 5l7 7-7 7",strokeLinecap:"round",strokeLinejoin:"round"})})]})}),(0,s.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,s.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 nr(e){let{apiBaseUrl:t="",onUpgradeClick:r}=e,[a,o]=(0,n.useState)(null),[l,i]=(0,n.useState)(!0),[c,d]=(0,n.useState)(null),[x,u]=(0,n.useState)(!1);if((0,n.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();o(r)}catch(e){d(e instanceof Error?e.message:"Unknown error")}finally{i(!1)}}e();let r=setInterval(e,3e5);return()=>clearInterval(r)},[t]),l||c||!a||"free"!==a.plan||x)return null;let{computeHoursThisMonth:m}=a.usage,{computeHoursPerMonth:h}=a.limits,p=a.percentUsed.computeHours,g=Math.max(0,h-m),b=g<=0,f=p>=80&&!b,j=a.introBonus,y=(null==j?void 0:j.isActive)&&j.daysRemaining>0,v=new Date().toLocaleDateString("en-US",{month:"long"}),w="bg-bg-tertiary border-border-subtle",N="text-text-secondary",k="text-accent-cyan";return b?(w="bg-error/10 border-error/30",N="text-error",k="text-error"):f?(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,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b ".concat(w),children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[y?(0,s.jsx)(na,{className:k}):(0,s.jsx)(ns,{className:k}),(0,s.jsx)("span",{className:"text-sm ".concat(N),children:b?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("strong",{children:"Compute limit reached"})," — Your free tier compute hours for ",v," have been used. Workspaces are paused until next month."]}):f?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("strong",{children:[g.toFixed(1),"h remaining"]})," — You've used ",p,"% of your free tier compute hours for ",v,"."]}):y?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("strong",{children:"Intro Bonus Active"})," — ",j.resources.cpus," CPU / ",j.resources.memoryGb,"GB RAM."," ",(0,s.jsxs)("span",{className:"text-text-secondary",children:[j.daysRemaining," day",1!==j.daysRemaining?"s":""," remaining before auto-resize to 1 CPU / 2GB."]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("strong",{children:[g.toFixed(1)," of ",h,"h"]})," compute hours remaining this month"]})})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(b||f||y)&&(0,s.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"}),!b&&(0,s.jsx)("button",{onClick:()=>u(!0),className:"p-1 text-text-muted hover:text-text-primary transition-colors","aria-label":"Dismiss",children:(0,s.jsx)(nn,{})})]})]})}function ns(e){let{className:t}=e;return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function nn(){return(0,s.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function na(e){let{className:t}=e;return(0,s.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,s.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,s.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,s.jsx)("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),(0,s.jsx)("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}let no={url:"",autoConnect:!0,reconnect:!0,maxReconnectAttempts:10,reconnectDelay:1e3},nl="relay:recentRepos";function ni(e){try{localStorage.setItem(nl,JSON.stringify(e))}catch(e){}}var nc=r(5372);function nd(e){var t,r,l,i,d,u;let{wsUrl:m,orchestratorUrl:h}=e,{data:p,isConnected:g,error:b}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={...no,...e},[r,s]=(0,n.useState)(null),[a,o]=(0,n.useState)(!1),[l,i]=(0,n.useState)(null),c=(0,n.useRef)(null),d=(0,n.useRef)(0),x=(0,n.useRef)(null),u=(0,n.useCallback)(()=>{var e;if((null===(e=c.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN)return;let r=t.url||function(){let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws")}();try{let e=new WebSocket(r);e.onopen=()=>{o(!0),i(null),d.current=0},e.onclose=()=>{if(o(!1),c.current=null,t.reconnect&&d.current<t.maxReconnectAttempts){let e=Math.min(t.reconnectDelay*Math.pow(2,d.current),3e4);d.current++,x.current=setTimeout(()=>{u()},e)}},e.onerror=e=>{i(Error("WebSocket connection error")),console.error("[useWebSocket] Error:",e)},e.onmessage=e=>{try{let t=JSON.parse(e.data);s(t)}catch(e){console.error("[useWebSocket] Failed to parse message:",e)}},c.current=e}catch(e){i(e instanceof Error?e:Error("Failed to create WebSocket"))}},[t.url,t.reconnect,t.maxReconnectAttempts,t.reconnectDelay]),m=(0,n.useCallback)(()=>{x.current&&(clearTimeout(x.current),x.current=null),c.current&&(c.current.close(),c.current=null),o(!1)},[]);return(0,n.useEffect)(()=>(t.autoConnect&&u(),()=>{m()}),[t.autoConnect,u,m]),{data:r,isConnected:a,error:l,connect:u,disconnect:m}}({url:m}),{workspaces:f,activeWorkspaceId:j,agents:y,isConnected:v,isLoading:w,error:N,switchWorkspace:k,addWorkspace:C,removeWorkspace:S,spawnAgent:L,stopAgent:A}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{apiUrl:t="http://localhost:3456",enabled:r=!1}=e,[s,a]=(0,n.useState)([]),[o,l]=(0,n.useState)(),[i,c]=(0,n.useState)([]),[d,x]=(0,n.useState)(!1),[u,m]=(0,n.useState)(r),[h,p]=(0,n.useState)(null),g=(0,n.useRef)(null),b=(0,n.useRef)(),f=t.replace(/^http/,"ws"),j=(0,n.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)}))),l(r.activeWorkspaceId),r.activeWorkspaceId){let e=await fetch("".concat(t,"/workspaces/").concat(r.activeWorkspaceId,"/agents"));if(e.ok){let t=await e.json();c(t.agents.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))}}}catch(e){p(e instanceof Error?e:Error(String(e)))}finally{m(!1)}},[t,r]);(0,n.useEffect)(()=>{if(!r)return;let e=()=>{try{let t=new WebSocket(f);t.onopen=()=>{x(!0),p(null)},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)}))),l(r.data.activeWorkspaceId),c((null===(t=r.data.agents)||void 0===t?void 0:t.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))||[]),m(!1)}else"event"===r.type&&y(r.data)}catch(e){console.error("Failed to parse WebSocket message:",e)}},t.onclose=()=>{x(!1),g.current=null,b.current=setTimeout(e,3e3)},t.onerror=e=>{console.error("WebSocket error:",e),t.close()},g.current=t}catch(t){p(t instanceof Error?t:Error(String(t))),b.current=setTimeout(e,3e3)}};return j().then(e),()=>{b.current&&clearTimeout(b.current),g.current&&g.current.close()}},[f,j,r]);let y=(0,n.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":l(e.data.currentId);break;case"agent:spawned":c(t=>[...t,e.data]);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))}},[]),v=(0,n.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 s=await fetch("".concat(t,"/workspaces/").concat(e,"/agents"));s.ok&&c((await s.json()).agents.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))},[t]),w=(0,n.useCallback)(async(e,r)=>{let s=await fetch("".concat(t,"/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,name:r})});if(!s.ok)throw Error((await s.json()).error||"Failed to add workspace");return s.json()},[t]),N=(0,n.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]),k=(0,n.useCallback)(async(e,r,s)=>{if(!o)throw Error("No active workspace");let n=await fetch("".concat(t,"/workspaces/").concat(o,"/agents"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,task:r,provider:s})});if(!n.ok)throw Error((await n.json()).error||"Failed to spawn agent");return n.json()},[t,o]),C=(0,n.useCallback)(async e=>{if(!o)throw Error("No active workspace");let r=await fetch("".concat(t,"/workspaces/").concat(o,"/agents/").concat(e),{method:"DELETE"});if(!r.ok)throw Error("Failed to stop agent: ".concat(r.statusText))},[t,o]);return{workspaces:s,activeWorkspaceId:o,agents:i,isConnected:d,isLoading:u,error:h,switchWorkspace:v,addWorkspace:w,removeWorkspace:N,spawnAgent:k,stopAgent:C,refresh:j}}({apiUrl:h}),M=(0,nc.uo)(),W=(null==M?void 0:M.user)?{displayName:M.user.githubUsername,avatarUrl:M.user.avatarUrl}:void 0,[E,D]=(0,n.useState)([]),[B,T]=(0,n.useState)(null),[R,P]=(0,n.useState)(!1);(0,n.useEffect)(()=>{if(!(null==M?void 0:M.user))return;let e=async()=>{P(!0);try{let e=await ei.xv.getWorkspaceSummary();e.success&&e.data.workspaces&&(D(e.data.workspaces),!B&&e.data.workspaces.length>0&&T(e.data.workspaces[0].id))}catch(e){console.error("Failed to fetch cloud workspaces:",e)}finally{P(!1)}};e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[null==M?void 0:M.user,B]);let _=!!(null==M?void 0:M.user),I=(0,n.useMemo)(()=>_&&E.length>0?E.map(e=>({id:e.id,name:e.name,path:e.path||"/workspace/".concat(e.name),status:"running"===e.status?"active":"inactive",provider:"claude",lastActiveAt:new Date})):f,[_,E,f]),F=_?B:j,U=_?R:w;(0,n.useEffect)(()=>{_&&B?(0,rf.hc)(B):_||(0,rf.hc)(null)},[_,B]);let O=(0,n.useCallback)(async e=>{_?T(e.id):await k(e.id)},[_,k]),{onlineUsers:z,typingUsers:V,sendTyping:G,isConnected:K}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{currentUser:t,wsUrl:r,autoConnect:s=!0}=e,[a,o]=(0,n.useState)([]),[l,i]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),x=(0,n.useRef)(null),u=(0,n.useRef)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(!1),p=(0,n.useRef)(t);p.current=t,(0,n.useEffect)(()=>{let e=setInterval(()=>{let e=Date.now();i(t=>t.filter(t=>e-t.startedAt<3e3))},1e3);return()=>clearInterval(e)},[]);let g=(0,n.useCallback)(()=>{var e;if(!p.current||(null===(e=x.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN||h.current)return;h.current=!0;let t=r||function(){let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws/presence")}();try{let e=new WebSocket(t);e.onopen=()=>{h.current=!1,d(!0);let t=p.current;t&&e.send(JSON.stringify({type:"presence",action:"join",user:{username:t.username,avatarUrl:t.avatarUrl}}))},e.onclose=()=>{h.current=!1,d(!1),x.current=null,p.current&&(u.current=setTimeout(()=>{g()},2e3))},e.onerror=e=>{console.error("[usePresence] Error:",e)},e.onmessage=e=>{try{let r=JSON.parse(e.data);switch(r.type){case"presence_list":o(r.users||[]);break;case"presence_join":o(e=>[...e.filter(e=>e.username!==r.user.username),r.user]);break;case"presence_leave":o(e=>e.filter(e=>e.username!==r.username)),i(e=>e.filter(e=>e.username!==r.username));break;case"typing":var t;if(r.username===(null===(t=p.current)||void 0===t?void 0:t.username))break;r.isTyping?i(e=>[...e.filter(e=>e.username!==r.username),{username:r.username,avatarUrl:r.avatarUrl,startedAt:Date.now()}]):i(e=>e.filter(e=>e.username!==r.username))}}catch(e){console.error("[usePresence] Failed to parse message:",e)}},x.current=e}catch(e){console.error("[usePresence] Failed to create WebSocket:",e)}},[r]),b=(0,n.useCallback)(()=>{if(u.current&&(clearTimeout(u.current),u.current=null),h.current=!1,x.current){let e=x.current;e.onclose=null,e.onerror=null;let t=p.current;e.readyState===WebSocket.OPEN&&t&&e.send(JSON.stringify({type:"presence",action:"leave",username:t.username})),e.close(),x.current=null}d(!1)},[]),f=(0,n.useCallback)(e=>{if(!x.current||x.current.readyState!==WebSocket.OPEN)return;let t=p.current;t&&(m.current&&(clearTimeout(m.current),m.current=null),x.current.send(JSON.stringify({type:"typing",isTyping:e,username:t.username,avatarUrl:t.avatarUrl})),e&&(m.current=setTimeout(()=>{m.current=null,f(!1)},3e3)))},[]);return(0,n.useEffect)(()=>{if(s&&p.current&&(!x.current||x.current.readyState===WebSocket.CLOSED))return g(),()=>{b()}},[s,null==t?void 0:t.username,g,b]),(0,n.useEffect)(()=>{let e=()=>{var e;let t=p.current;(null===(e=x.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN&&t&&x.current.send(JSON.stringify({type:"presence",action:"leave",username:t.username}))};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]),{onlineUsers:a,typingUsers:l,sendTyping:f,isConnected:c}}({currentUser:(0,n.useMemo)(()=>W?{username:W.displayName,avatarUrl:W.avatarUrl}:void 0,[null==W?void 0:W.displayName,null==W?void 0:W.avatarUrl])}),[Z,q]=(0,n.useState)(null),[J,Y]=(0,n.useState)(null),[$,X]=(0,n.useState)("local"),[Q,ee]=(0,n.useState)([]),[et,er]=(0,n.useState)(),[es,en]=(0,n.useState)(!1),[ea,eo]=(0,n.useState)(!1),[el,ec]=(0,n.useState)(null),[ed,ex]=(0,n.useState)(!1),[eu,em]=(0,n.useState)(!1),[eh,ep]=(0,n.useState)(null),[eg,ef]=(0,n.useState)(!1),[ej,ey]=(0,n.useState)(rb),[ev,ew]=(0,n.useState)(!1),[eN,ek]=(0,n.useState)("dashboard"),[eC,eS]=(0,n.useState)(!1),[eL,eA]=(0,n.useState)(!1),[eM,eW]=(0,n.useState)(null),[eE,eD]=(0,n.useState)(!1),{steps:eB,status:eT,history:eR,isLoading:eP,selectTrajectory:e_,selectedTrajectoryId:eI}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{pollInterval:t=2e3,autoPoll:r=!0,trajectoryId:s,apiBaseUrl:a=""}=e,[o,l]=(0,n.useState)([]),[i,c]=(0,n.useState)(null),[d,x]=(0,n.useState)([]),[u,m]=(0,n.useState)(!0),[h,p]=(0,n.useState)(null),[g,b]=(0,n.useState)(s||null),f=(0,n.useRef)(null),j=(0,n.useCallback)(async()=>{try{let e=a?"".concat(a,"/api/trajectory"):(0,rf.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]),y=(0,n.useCallback)(async()=>{try{let e=a?"".concat(a,"/api/trajectory/history"):(0,rf.kG)("/api/trajectory/history"),t=await fetch(e,{credentials:"include"}),r=await t.json();r.success&&x(r.trajectories||[])}catch(e){console.error("[useTrajectory] History fetch error:",e)}},[a]),v=(0,n.useCallback)(async()=>{try{let e=g?"/api/trajectory/steps?trajectoryId=".concat(encodeURIComponent(g)):"/api/trajectory/steps",t=a?"".concat(a).concat(e):(0,rf.kG)(e),r=await fetch(t,{credentials:"include"}),s=await r.json();s.success?(l(s.steps||[]),p(null)):p(s.error||"Failed to fetch trajectory steps")}catch(e){console.error("[useTrajectory] Steps fetch error:",e),p(e.message)}},[a,g]),w=(0,n.useCallback)(e=>{b(e)},[]),N=(0,n.useCallback)(async()=>{m(!0),await Promise.all([j(),v(),y()]),m(!1)},[j,v,y]);return(0,n.useEffect)(()=>{N()},[N]),(0,n.useEffect)(()=>{v()},[g,v]),(0,n.useEffect)(()=>{if(!r)return;f.current=setInterval(()=>{v(),j()},t);let e=setInterval(y,1e4);return()=>{f.current&&clearInterval(f.current),clearInterval(e)}},[r,t,v,j,y]),{steps:o,status:i,history:d,isLoading:u,error:h,refresh:N,selectTrajectory:w,selectedTrajectoryId:g}}({autoPoll:eE}),{recentRepos:eF,addRecentRepo:eU,getRecentProjects:eO}=function(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=null!==(e=t.maxRecent)&&void 0!==e?e:5,[s,a]=(0,n.useState)([]);(0,n.useEffect)(()=>{a(function(){try{let e=localStorage.getItem(nl);if(!e)return[];let t=JSON.parse(e);if(!Array.isArray(t))return[];return t}catch(e){return[]}}())},[]);let o=(0,n.useCallback)(e=>{a(t=>{let s=t.filter(t=>t.id!==e.id),n=[{id:e.id,path:e.path,name:e.name,lastAccessed:Date.now()},...s].slice(0,r);return ni(n),n})},[r]),l=(0,n.useCallback)(e=>{a(t=>{let r=t.filter(t=>t.id!==e);return ni(r),r})},[]),i=(0,n.useCallback)(()=>{a([]),ni([])},[]),c=(0,n.useCallback)(e=>{let t=new Map(e.map(e=>[e.id,e]));return s.map(e=>t.get(e.id)).filter(e=>void 0!==e)},[s]);return{recentRepos:s,addRecentRepo:o,removeRecentRepo:l,clearRecentRepos:i,getRecentProjects:c}}(),{repos:ez,refetch:eH}=function(e){let{workspaceId:t,apiBaseUrl:r="/api",enabled:s=!0}=e,[a,o]=(0,n.useState)([]),[l,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(null),x=(0,n.useCallback)(async()=>{if(t&&s){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 s=await e.json();o(s.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,s]);return(0,n.useEffect)(()=>{x()},[x]),{repos:a,isLoading:l,error:c,refetch:x}}({workspaceId:null!=F?F:void 0,apiBaseUrl:"/api",enabled:_&&!!F}),[eV,eG]=(0,n.useState)(!1),[eK,eZ]=(0,n.useState)(!1),[eJ,eY]=(0,n.useState)([]),[e$,eX]=(0,n.useState)({}),[eQ,e0]=(0,n.useState)(!1),[e1,e2]=(0,n.useState)([]),[e4,e3]=(0,n.useState)(),[e6,e8]=(0,n.useState)(!1),[e9,tt]=(0,n.useState)(!1),[tr,ts]=(0,n.useState)(!1),tn=(0,n.useRef)(0),ta=(0,n.useRef)(!0),[to,tl]=(0,n.useState)(new Map),ti=(0,n.useCallback)(()=>{window.innerWidth<=768&&tt(!1)},[]),tc=(0,n.useMemo)(()=>{var e,t;let r=[...null!==(e=null==p?void 0:p.agents)&&void 0!==e?e:[],...null!==(t=null==p?void 0:p.users)&&void 0!==t?t:[]],s=new Map;for(let e of r){let t=e.name.toLowerCase(),r=s.get(t);s.set(t,r?{...r,...e}:e)}return Array.from(s.values())},[null==p?void 0:p.agents,null==p?void 0:p.users]),td=(0,n.useCallback)(e=>{tl(t=>{let r=new Map(t);return r.set(e.toLowerCase(),Date.now()),r})},[]),{agents:tx,groups:tu,selectedAgent:tm,selectAgent:tp,searchQuery:tg,setSearchQuery:tb,totalCount:tf,onlineCount:ty,needsAttentionCount:tv}=function(e){let{agents:t,initialSelected:r,initialSearchQuery:s=""}=e,[l,i]=(0,n.useState)(null!=r?r:null),[d,u]=(0,n.useState)(s),m=(0,n.useMemo)(()=>c(t,d),[t,d]),h=(0,n.useMemo)(()=>o(m),[m]),p=(0,n.useMemo)(()=>[...m].sort((e,t)=>e.name.localeCompare(t.name)),[m]),g=(0,n.useMemo)(()=>{var e;return null!==(e=t.find(e=>e.name===l))&&void 0!==e?e:null},[t,l]),b=(0,n.useMemo)(()=>{let e=x(t);return{totalCount:e.total,onlineCount:e.online,needsAttentionCount:e.needsAttention}},[t]),f=(0,n.useCallback)(e=>{i(e)},[]),j=(0,n.useCallback)(e=>t.find(t=>t.name===e),[t]),y=(0,n.useCallback)(e=>({...e,color:(0,a.GW)(e.name)}),[]);return{agents:m,groups:h,sortedAgents:p,selectedAgent:g,selectAgent:f,searchQuery:d,setSearchQuery:u,...b,getAgentByName:j,getAgentWithColor:y}}({agents:tc}),{messages:tw,threadMessages:tN,currentChannel:tk,setCurrentChannel:tC,currentThread:tS,setCurrentThread:tL,activeThreads:tA,totalUnreadThreadCount:tM,sendMessage:tW,isSending:tE,sendError:tD}=function(e){let{messages:t,currentChannel:r="general",senderName:s}=e,[a,o]=(0,n.useState)(r),[l,i]=(0,n.useState)(null),[c,d]=(0,n.useState)(!1),[x,u]=(0,n.useState)(null),[m,h]=(0,n.useState)(new Map),p=s||"Dashboard",[g,b]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(0===g.length)return;let e=new Set(t.slice(-50).map(e=>"".concat(e.from,":").concat(e.to,":").concat(e.content.slice(0,100))));b(t=>t.filter(t=>{let r="".concat(t.from,":").concat(t.to,":").concat(t.content.slice(0,100));return!e.has(r)}))},[t,g.length]);let f=(0,n.useMemo)(()=>0===g.length?t:[...t,...g],[t,g]),j=(0,n.useMemo)(()=>{let e=new Set(f.map(e=>e.id)),t=f.filter(t=>!t.thread||!e.has(t.thread));return"general"===a?t:t.filter(e=>e.from===a||e.to===a)},[f,a]),y=(0,n.useCallback)(e=>f.filter(t=>t.thread===e),[f]),v=(0,n.useMemo)(()=>{let e=new Map,t=new Set(f.map(e=>e.id));for(let t of f)if(t.thread){let r=e.get(t.thread)||[];r.push(t),e.set(t.thread,r)}let r=[];for(let[s,n]of e.entries()){let e=[...n].sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime()),a=[...new Set(n.flatMap(e=>[e.from,e.to]))].filter(e=>"*"!==e),o=m.get(s),l=n.filter(e=>e.from!==p&&!e.isRead&&(!o||new Date(e.timestamp).getTime()>o)).length,i=s;if(t.has(s)){let e=f.find(e=>e.id===s);if(e){let t=e.content.split("\n")[0];i=t.length>30?t.substring(0,30)+"...":t}}r.push({id:s,name:i,lastMessage:e[0],messageCount:n.length,unreadCount:l,participants:a})}return r.sort((e,t)=>new Date(t.lastMessage.timestamp).getTime()-new Date(e.lastMessage.timestamp).getTime())},[f,m]),w=(0,n.useCallback)(e=>{i(e),e&&h(t=>{let r=new Map(t);return r.set(e,Date.now()),r})},[]),N=(0,n.useMemo)(()=>v.filter(e=>e.unreadCount>0).length,[v]),k=(0,n.useMemo)(()=>{let e=f.filter(e=>!e.isRead).length;return{totalCount:f.length,unreadCount:e}},[f]);return{messages:j,threadMessages:y,currentChannel:a,setCurrentChannel:o,currentThread:l,setCurrentThread:w,activeThreads:v,totalUnreadThreadCount:N,sendMessage:(0,n.useCallback)(async(e,t,r,n)=>{d(!0),u(null);let a="optimistic-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,9)),o={id:a,from:p,to:e,content:t,timestamp:new Date().toISOString(),status:"sending",thread:r,isRead:!0};b(e=>[...e,o]);try{let o={to:e,message:t,thread:r,attachments:n};s&&(o.from=s);let l=await rf.hi.sendMessage(o);if(l.success)return!0;return b(e=>e.filter(e=>e.id!==a)),u(l.error||"Failed to send message"),!1}catch(e){return b(e=>e.filter(e=>e.id!==a)),u("Network error"),!1}finally{d(!1)}},[p,s]),isSending:c,sendError:x,...k}}({messages:null!==(d=null==p?void 0:p.messages)&&void 0!==d?d:[],senderName:null==W?void 0:W.displayName}),tB=(0,n.useMemo)(()=>{var e;let t=new Set(tx.map(e=>e.name.toLowerCase())),r=new Map;for(let s of(W&&r.set(W.displayName.toLowerCase(),{username:W.displayName,avatarUrl:W.avatarUrl}),null!==(e=null==p?void 0:p.messages)&&void 0!==e?e:[])){let e=s.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==p?void 0:p.messages,tx,W]),tT=(0,n.useMemo)(()=>{var e,t;if(!W)return{};let r={},s=new Set(tc.filter(e=>e.isHuman).map(e=>e.name.toLowerCase()));for(let n of null!==(e=null==p?void 0:p.messages)&&void 0!==e?e:[]){let e=n.from,a=n.to;if(!e||!a)continue;let o=a===W.displayName,l=s.has(e.toLowerCase());if(!o||!l)continue;let i=null!==(t=to.get(e.toLowerCase()))&&void 0!==t?t:0;new Date(n.timestamp).getTime()>i&&(r[e]=(r[e]||0)+1)}return r},[tc,W,null==p?void 0:p.messages,to]);(0,n.useEffect)(()=>{(null==J?void 0:J.username)&&td(J.username)},[null==J?void 0:J.username,td]),(0,n.useEffect)(()=>{if(!(window.innerWidth<=768)){ts(!1);return}let e=tw.length;!e9&&e>tn.current&&ts(!0),ta.current=!e9},[tw.length,e9]),(0,n.useEffect)(()=>{e9&&(ts(!1),tn.current=tw.length)},[e9,tw.length]),(0,n.useEffect)(()=>{tn.current=tw.length},[]);let tR=!!(null==p?void 0:null===(r=p.fleet)||void 0===r?void 0:null===(t=r.servers)||void 0===t?void 0:t.length)||f.length>0;(0,n.useEffect)(()=>{if(f.length>0){if(ez.length>1&&F){let t=ez.map(e=>({id:e.id,path:e.githubFullName,name:e.githubFullName.split("/").pop()||e.githubFullName,agents:y.filter(e=>e.workspaceId===F).map(e=>({name:e.name,status:"running"===e.status?"online":"offline",isSpawned:!0,cli:e.provider})),lead:void 0}));if(ee(t),!et||!t.find(e=>e.id===et)){var e;er(null===(e=t[0])||void 0===e?void 0:e.id)}}else ee(f.map(e=>({id:e.id,path:e.path,name:e.name,agents:y.filter(t=>t.workspaceId===e.id).map(e=>({name:e.name,status:"running"===e.status?"online":"offline",isSpawned:!0,cli:e.provider})),lead:void 0}))),er(j)}},[f,y,j,ez,F,et]),(0,n.useEffect)(()=>{if(f.length>0)return;let e=async()=>{let e=await rf.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||[]).map(e=>({name:e.name,status:"online"===e.status||"active"===e.status?"online":"offline",currentTask:e.task,cli:e.cli})),lead:e.lead}));ee(e),!et&&e.length>0&&er(e[0].id)}}};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[f.length,et]);let tP=["architect"],{bridgeAgents:t_,projectAgents:tI}=(0,n.useMemo)(()=>{let e=[],t=[];for(let r of tx)tP.includes(r.name.toLowerCase())?e.push(r):t.push(r);return{bridgeAgents:e,projectAgents:t}},[tx]),tF=(0,n.useMemo)(()=>0===Q.length||0===new Set(tI.map(e=>e.name.toLowerCase())).size?Q:Q.map((e,t)=>{if(0===t||e.id===et){let t=new Set(e.agents.map(e=>e.name.toLowerCase())),r=tI.filter(e=>!t.has(e.name.toLowerCase()));return{...e,agents:[...e.agents,...r]}}return e}),[Q,tI,et]),tU=(0,n.useMemo)(()=>tF.length>0?[]:tI,[tF,tI]);(0,n.useCallback)(async e=>{try{await k(e.id)}catch(e){console.error("Failed to switch workspace:",e)}},[k]);let tO=(0,n.useCallback)(async(e,t)=>{em(!0),ep(null);try{await C(e,t),ex(!1)}catch(e){throw ep(e instanceof Error?e.message:"Failed to add workspace"),e}finally{em(!1)}},[C]),tz=(0,n.useCallback)(e=>{er(e.id),eU(e),f.length>0&&k(e.id).catch(e=>{console.error("Failed to switch workspace:",e)}),e.agents.length>0&&(tp(e.agents[0].name),tC(e.agents[0].name)),ti()},[tp,tC,ti,f.length,k,eU]),tH=(0,n.useCallback)(e=>{tp(e.name),tC(e.name),ti()},[tp,tC,ti]),tV=(0,n.useCallback)(()=>{ec(null),en(!0)},[]),tG=(0,n.useCallback)(()=>{ek("dashboard"),ew(!0)},[]),tK=(0,n.useCallback)(()=>{ek("workspace"),ew(!0)},[]),tZ=(0,n.useCallback)(()=>{ek("billing"),ew(!0)},[]),tq=(0,n.useCallback)(()=>{eS(!0)},[]),tJ=(0,n.useCallback)(()=>{eA(!0)},[]),tY=(0,n.useCallback)(()=>{eG(!0)},[]),t$=(0,n.useCallback)(e=>{Y({username:e.name,avatarUrl:e.avatarUrl,connectedAt:new Date().toISOString(),lastSeen:new Date().toISOString()}),td(e.name),ti()},[ti,td]),tX=(0,n.useCallback)(async(e,t)=>{let r=await tW(e,t);if(r){if("*"===e)tp(null),tC("general");else{let t=tx.find(t=>t.name===e);t?(tp(t.name),tC(t.name)):tC(e)}}return r},[tW,tp,tC,tx]),tQ=(0,n.useCallback)(async e=>{eo(!0),ec(null);try{if(f.length>0&&j)return await L(e.name,void 0,e.command),!0;let t=await rf.hi.spawnAgent({name:e.name,cli:e.command,team:e.team,shadowMode:e.shadowMode,shadowOf:e.shadowOf,shadowAgent:e.shadowAgent,shadowTriggers:e.shadowTriggers,shadowSpeakOn:e.shadowSpeakOn});if(!t.success)return ec(t.error||"Failed to spawn agent"),!1;return!0}catch(e){return ec(e instanceof Error?e.message:"Failed to spawn agent"),!1}finally{eo(!1)}},[f.length,j,L]),t0=(0,n.useCallback)(async e=>{if(e.isSpawned&&window.confirm('Are you sure you want to release agent "'.concat(e.name,'"?')))try{if(f.length>0&&j){await A(e.name);return}let t=await rf.hi.releaseAgent(e.name);t.success||console.error("Failed to release agent:",t.error)}catch(e){console.error("Failed to release agent:",e)}},[f.length,j,A]),t1=(0,n.useCallback)(e=>{eW(e)},[]);(0,n.useEffect)(()=>{if(!eQ)return;let e=async()=>{let e=await rf.hi.getFleetServers();e.success&&e.data&&e2(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)},[eQ]),(0,n.useEffect)(()=>{if(!eK)return;let e=async()=>{let e=await rf.hi.getDecisions();e.success&&e.data&&eY(e.data.decisions.map(rf.XP))};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[eK]);let t2=(0,n.useCallback)(async(e,t)=>{eX(t=>({...t,[e]:!0}));try{let r=await rf.hi.approveDecision(e,t);r.success?eY(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{eX(t=>({...t,[e]:!1}))}},[]),t5=(0,n.useCallback)(async(e,t)=>{eX(t=>({...t,[e]:!0}));try{let r=await rf.hi.rejectDecision(e,t);r.success?eY(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{eX(t=>({...t,[e]:!1}))}},[]),t4=(0,n.useCallback)(async e=>{(await rf.hi.dismissDecision(e)).success&&eY(t=>t.filter(t=>t.id!==e))},[]),t3=(0,n.useCallback)(async e=>{e8(!0);try{var t;let r=e7[e.priority].beadsPriority,s=await rf.hi.createBead({title:e.title,assignee:e.agentName,priority:r,type:"task"});if(s.success&&(null===(t=s.data)||void 0===t?void 0:t.bead))await rf.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:",s.data.bead.id);else throw console.error("Failed to create task bead:",s.error),Error(s.error||"Failed to create task")}catch(e){throw console.error("Failed to create task:",e),e}finally{e8(!1)}},[]),t6=(0,n.useCallback)(()=>{ef(!0)},[]),t8=(0,n.useCallback)(()=>{ef(!1)},[]);n.useEffect(()=>{let e=e=>{let t;t="system"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e,document.documentElement.setAttribute("data-theme",t)};if(e(ej.theme),"system"===ej.theme){let t=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>e("system");return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}},[ej.theme]),n.useEffect(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),ef(!0)),(e.metaKey||e.ctrlKey)&&e.shiftKey&&"s"===e.key&&(e.preventDefault(),tV()),(e.metaKey||e.ctrlKey)&&"n"===e.key&&(e.preventDefault(),tJ()),"Escape"===e.key&&(ef(!1),en(!1),eA(!1),eD(!1),ew(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[tV,tJ]);let t9=window.location.pathname,t7=new URLSearchParams(window.location.search);return"/billing/success"===t9?(0,s.jsx)(nt,{type:"success",sessionId:t7.get("session_id")||void 0,onClose:()=>{window.location.href="/"}}):"/billing/canceled"===t9?(0,s.jsx)(nt,{type:"canceled",onClose:()=>{window.location.href="/"}}):(0,s.jsx)(r$,{wsUrl:m,children:(0,s.jsxs)("div",{className:"flex h-screen bg-bg-deep font-sans text-text-primary",children:[(0,s.jsx)("div",{className:"\n fixed inset-0 bg-black/60 backdrop-blur-sm z-[999] transition-opacity duration-200\n md:hidden\n ".concat(e9?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none","\n "),onClick:()=>tt(!1)}),(0,s.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(e9?"translate-x-0":"-translate-x-full","\n "),children:[(0,s.jsx)("div",{className:"p-3 border-b border-sidebar-border",children:(0,s.jsx)(rP,{workspaces:I,activeWorkspaceId:null!=F?F:void 0,onSelect:O,onAddWorkspace:()=>ex(!0),onWorkspaceSettings:tK,isLoading:U})}),(0,s.jsx)(H,{agents:tU,bridgeAgents:t_,projects:tF,currentUserName:null==W?void 0:W.displayName,humanUnreadCounts:tT,currentProject:et,selectedAgent:null==tm?void 0:tm.name,viewMode:$,isFleetAvailable:tR,isConnected:g||v,isOpen:e9,activeThreads:tA,currentThread:tS,totalUnreadThreadCount:tM,onAgentSelect:tH,onHumanSelect:t$,onProjectSelect:tz,onViewModeChange:X,onSpawnClick:tV,onReleaseClick:t0,onLogsClick:t1,onThreadSelect:tL,onClose:()=>tt(!1),onSettingsClick:tG,onTrajectoryClick:()=>eD(!0),hasActiveTrajectory:null==eT?void 0:eT.active,onFleetClick:()=>e0(!eQ),isFleetViewActive:eQ,onCoordinatorClick:tY,hasMultipleProjects:tF.length>1})]}),(0,s.jsxs)("main",{className:"flex-1 flex flex-col min-w-0 bg-bg-secondary/50 overflow-hidden",children:[(0,s.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,s.jsx)(eb,{currentChannel:tk,selectedAgent:tm,projects:tF,currentProject:tF.find(e=>e.id===et)||null,recentProjects:eO(tF),onProjectChange:tz,onCommandPaletteOpen:t6,onSettingsClick:tG,onHistoryClick:tq,onNewConversationClick:tJ,onCoordinatorClick:tY,onFleetClick:()=>e0(!eQ),isFleetViewActive:eQ,onTrajectoryClick:()=>eD(!0),hasActiveTrajectory:null==eT?void 0:eT.active,onMenuClick:()=>tt(!0),hasUnreadNotifications:tr}),(0,s.jsx)(nr,{onUpgradeClick:tZ})]}),(0,s.jsx)("div",{className:"h-[52px] flex-shrink-0 md:hidden"}),W&&z.length>0&&(0,s.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,s.jsx)(sG,{onlineUsers:z,onUserClick:q})}),(0,s.jsxs)("div",{className:"flex-1 flex overflow-hidden min-h-0",children:[(0,s.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto ".concat(tS?"hidden md:block md:flex-[2]":""),children:b?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center px-4",children:[(0,s.jsx)(nm,{}),(0,s.jsx)("h2",{className:"m-0 mb-2 font-display text-text-primary",children:"Connection Error"}),(0,s.jsx)("p",{className:"text-text-secondary",children:b.message}),(0,s.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"})]}):p?eQ?(0,s.jsx)("div",{className:"p-4 h-full overflow-y-auto",children:(0,s.jsx)(sI,{servers:e1,agents:tx,selectedServerId:e4,onServerSelect:e3,onServerReconnect:e=>{console.log("Reconnecting to server:",e)},isLoading:!p})}):(0,s.jsx)(eq,{messages:tw,currentChannel:tk,currentThread:tS,onThreadClick:e=>tL(e),highlightedMessageId:null!=tS?tS:void 0,agents:tc,currentUser:W}):(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center",children:[(0,s.jsx)(nu,{}),(0,s.jsx)("p",{className:"font-display text-text-secondary",children:"Connecting to dashboard..."})]})}),tS&&(()=>{let e=tw.find(e=>e.id===tS),t=!e;if(!e){var r;e=null!==(r=tw.filter(e=>e.thread===tS).sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())[0])&&void 0!==r?r:null}return(0,s.jsx)("div",{className:"w-full md:w-[400px] md:min-w-[320px] md:max-w-[500px] flex-shrink-0",children:(0,s.jsx)(e5,{originalMessage:null!=e?e:null,replies:tN(tS),onClose:()=>tL(null),onReply:async r=>{let s="*";return!t&&e&&(s="Dashboard"===e.from||W&&e.from===W.displayName?e.to:e.from),tW(s,r,tS)},isSending:tE,currentUser:W})})})()]}),V.length>0&&(0,s.jsx)("div",{className:"px-4 bg-bg-tertiary border-t border-border-subtle",children:(0,s.jsx)(sV,{typingUsers:V})}),(0,s.jsx)("div",{className:"p-2 sm:p-4 bg-bg-tertiary border-t border-border-subtle",children:(0,s.jsx)(nx,{recipient:"general"===tk?"*":tk,agents:tx,humanUsers:tB,onSend:tW,onTyping:G,isSending:tE,error:tD})})]}),(0,s.jsx)(te,{isOpen:eg,onClose:t8,agents:tx,projects:Q,currentProject:et,onAgentSelect:tH,onProjectSelect:tz,onSpawnClick:tV,onTaskCreate:t3,onGeneralClick:()=>{tp(null),tC("general")}}),(0,s.jsx)(th,{isOpen:es,onClose:()=>en(!1),onSpawn:tQ,existingAgents:tx.map(e=>e.name),isSpawning:ea,error:el}),(0,s.jsx)(rH,{isOpen:ed,onClose:()=>{ex(!1),ep(null)},onAdd:tO,isAdding:eu,error:eh}),(0,s.jsx)(rj,{isOpen:eC,onClose:()=>eS(!1)}),(0,s.jsx)(tj,{isOpen:eL,onClose:()=>eA(!1),onSend:tX,agents:tx,isSending:tE,error:tD}),eM&&(0,s.jsx)(sn,{agent:eM,isOpen:!0,onClose:()=>eW(null),availableAgents:tx,onAgentChange:eW}),eE&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex bg-black/50 backdrop-blur-sm",onClick:()=>eD(!1),children:(0,s.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,s.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle bg-bg-secondary",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.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,s.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-blue-500",children:(0,s.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-text-primary m-0",children:"Trajectory Viewer"}),(0,s.jsx)("p",{className:"text-xs text-text-muted m-0",children:(null==eT?void 0:eT.active)?"Active: ".concat(eT.task||"Working..."):"Browse past trajectories"})]})]}),(0,s.jsx)("button",{onClick:()=>eD(!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,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),(0,s.jsx)("div",{className:"flex-1 overflow-hidden p-6",children:(0,s.jsx)(sm,{agentName:(null==eT?void 0:null===(l=eT.task)||void 0===l?void 0:l.slice(0,30))||"Current",steps:eB,history:eR,selectedTrajectoryId:eI,onSelectTrajectory:e_,isLoading:eP})})]})}),eK&&(0,s.jsx)("div",{className:"fixed left-4 bottom-4 w-[400px] max-h-[500px] z-50 shadow-modal",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("button",{onClick:()=>eZ(!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,s.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,s.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})}),(0,s.jsx)(sL,{decisions:eJ,onApprove:t2,onReject:t5,onDismiss:t4,isProcessing:e$})]})}),!eK&&eJ.length>0&&(0,s.jsxs)("button",{onClick:()=>eZ(!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(eJ.length," pending decision").concat(eJ.length>1?"s":""),children:[(0,s.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),eJ.length>0&&(0,s.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:eJ.length})]}),(0,s.jsx)(sK,{user:Z,onClose:()=>q(null),onMention:e=>{q(null)},onSendMessage:e=>{Y(e)}}),(0,s.jsx)(sq,{user:J,onClose:()=>Y(null),messages:null!==(u=null==p?void 0:p.messages)&&void 0!==u?u:[],agents:tx,humanUsers:tB,onSend:tW,onTyping:G,isSending:tE,sendError:tD,currentUser:W}),(0,s.jsx)(sY,{isOpen:eV,onClose:()=>eG(!1),projects:tF,isCloudMode:!!W,hasArchitect:t_.some(e=>"architect"===e.name.toLowerCase()),onArchitectSpawned:()=>{eG(!1)}}),ev&&(0,s.jsx)(rs,{currentUserId:null==M?void 0:null===(i=M.user)||void 0===i?void 0:i.id,initialTab:eN,onClose:()=>ew(!1)})]})})}function nx(e){let{recipient:t,agents:r,humanUsers:a,onSend:o,onTyping:l,isSending:i,error:c}=e,[d,x]=(0,n.useState)(""),[u,m]=(0,n.useState)(0),[h,p]=(0,n.useState)(!1),[g,b]=(0,n.useState)(!1),[f,j]=(0,n.useState)([]),y=(0,n.useRef)(null),v=(0,n.useRef)(null),w=(0,n.useCallback)(async e=>{for(let t of e){let e=crypto.randomUUID(),r=URL.createObjectURL(t);j(s=>[...s,{id:e,file:t,preview:r,isUploading:!0}]);try{let r=await rf.hi.uploadAttachment(t);r.success&&r.data?j(t=>t.map(t=>t.id===e?{...t,isUploading:!1,uploadedId:r.data.attachment.id}:t)):j(t=>t.map(t=>t.id===e?{...t,isUploading:!1,error:r.error||"Upload failed"}:t))}catch(t){j(t=>t.map(t=>t.id===e?{...t,isUploading:!1,error:"Upload failed"}:t))}}},[]),N=(0,n.useCallback)(e=>{if(!e||0===e.length)return;let t=Array.from(e).filter(e=>e.type.startsWith("image/"));t.length>0&&w(t)},[w]),k=(0,n.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(),w(r))},[w]),C=(0,n.useCallback)(e=>{j(t=>{let r=t.find(t=>t.id===e);return r&&URL.revokeObjectURL(r.preview),t.filter(t=>t.id!==e)})},[]),S=async e=>{let r,s;e.preventDefault();let n=d.trim().length>0,a=f.length>0;if(!n&&!a||i||f.some(e=>e.isUploading))return;let l=f.filter(e=>e.uploadedId).map(e=>e.uploadedId),c=d.match(/^@(\S+)\s*([\s\S]*)/);if(c){let e=c[1];s=c[2]||"","*"===e||"everyone"===e.toLowerCase()||"all"===e.toLowerCase()?r="*":e.toLowerCase().startsWith("team:")?r=e:e.includes("/")||/\.(ts|tsx|js|jsx|json|md|py|go|rs|java|c|cpp|h|css|html|yaml|yml|toml)$/i.test(e)?(r=t,s=d):r=e}else r=t,s=d;!s.trim()&&l.length>0&&(s="[Screenshot attached]"),await o(r,s||d,void 0,l.length>0?l:void 0)&&(f.forEach(e=>URL.revokeObjectURL(e.preview)),x(""),j([]),p(!1),b(!1))},L=(d.trim()||f.length>0)&&!i&&!f.some(e=>e.isUploading);return(0,s.jsxs)("form",{className:"flex flex-col gap-1.5 sm:gap-2",onSubmit:S,children:[f.length>0&&(0,s.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:f.map(e=>(0,s.jsxs)("div",{className:"relative group",children:[(0,s.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,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,s.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}),e.error&&(0,s.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,s.jsx)("button",{type:"button",onClick:()=>C(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,s.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[(0,s.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,s.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},e.id))}),(0,s.jsxs)("div",{className:"flex items-center gap-1.5 sm:gap-3",children:[(0,s.jsx)("input",{ref:v,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>N(e.target.files)}),(0,s.jsx)("button",{type:"button",onClick:()=>{var e;return null===(e=v.current)||void 0===e?void 0:e.click()},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",title:"Attach screenshot (or paste from clipboard)",children:(0,s.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,s.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,s.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,s.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),(0,s.jsxs)("div",{className:"flex-1 relative min-w-0",children:[(0,s.jsx)(rE,{agents:r,humanUsers:a,inputValue:d,cursorPosition:u,onSelect:(e,t)=>{x(t),p(!1),b(!1),setTimeout(()=>{if(y.current){y.current.focus();let e=t.indexOf(" ")+1;y.current.setSelectionRange(e,e)}},0)},onClose:()=>p(!1),isVisible:h}),(0,s.jsx)(rR,{inputValue:d,cursorPosition:u,onSelect:(e,t)=>{x(t),b(!1),p(!1),setTimeout(()=>{if(y.current){y.current.focus();let e=t.indexOf(" ",1)+1;y.current.setSelectionRange(e,e)}},0)},onClose:()=>b(!1),isVisible:g}),(0,s.jsx)("textarea",{ref:y,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",placeholder:"Message ".concat("*"===t?"everyone":"@"+t,"..."),value:d,onChange:e=>{let t=e.target.value,r=e.target.selectionStart||0;if(x(t),m(r),null==l||l(t.trim().length>0),null!==rD(t,r)){b(!0),p(!1);return}if(null!==rM(t,r)){p(!0),b(!1);return}p(!1),b(!1)},onKeyDown:e=>{(!h&&!g||"ArrowDown"!==e.key&&"ArrowUp"!==e.key&&"Tab"!==e.key)&&("Enter"!==e.key||e.shiftKey||h||g||(e.preventDefault(),(d.trim()||f.length>0)&&!i&&S(e)))},onPaste:k,onSelect:e=>m(e.target.selectionStart||0),disabled:i,rows:1})]}),(0,s.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:!L,title:i?"Sending...":f.some(e=>e.isUploading)?"Uploading...":"Send message",children:i?(0,s.jsx)("span",{className:"hidden sm:inline",children:"Sending..."}):f.some(e=>e.isUploading)?(0,s.jsx)("span",{className:"hidden sm:inline",children:"Uploading..."}):(0,s.jsxs)("span",{className:"flex items-center gap-1 sm:gap-2",children:[(0,s.jsx)("span",{className:"hidden sm:inline",children:"Send"}),(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,s.jsx)("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})]})}),c&&(0,s.jsx)("span",{className:"text-error text-xs ml-2",children:c})]})]})}function nu(){return(0,s.jsx)("svg",{className:"animate-spin mb-4 text-accent-cyan",width:"28",height:"28",viewBox:"0 0 24 24",children:(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function nm(){return(0,s.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,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}},5372:function(e,t,r){r.d(t,{TI:function(){return c},uo:function(){return d}});var s=r(7437),n=r(2265),a=r(9165);let o={checkOnMount:!0,checkInterval:6e4,onExpired:()=>{}};function l(e){let{isOpen:t,error:r,onLogin:n,onDismiss:a}=e;return t?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[9998]",onClick:a,"aria-hidden":"true"}),(0,s.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,s.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,s.jsx)("div",{className:"flex justify-center mb-4",children:(0,s.jsx)("div",{className:"w-16 h-16 rounded-full bg-warning/10 flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-8 h-8 text-warning",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,s.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,s.jsx)("h2",{id:"session-expired-title",className:"text-xl font-semibold text-text-primary text-center mb-2",children:"Session Expired"}),(0,s.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,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("button",{onClick:n,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,s.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,s.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,n.createContext)(void 0);function c(e){let{children:t,cloudMode:r,checkInterval:c=6e4,onSessionExpired:d}=e,x=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")}(),u=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={...o,...e},[r,s]=(0,n.useState)(null),[l,i]=(0,n.useState)(!0),[c,d]=(0,n.useState)(!1),[x,u]=(0,n.useState)(null),m=(0,n.useRef)(null),h=(0,n.useRef)(!0),p=(0,n.useCallback)(async()=>{try{let e=await a.xv.checkSession();if(!h.current)return e;if(!e.authenticated&&(s(null),e.code)){let r={error:"Session expired",code:e.code,message:e.message||"Your session has expired. Please log in again."};u(r),d(!0),t.onExpired(r)}return e}catch(e){return{authenticated:!1,code:"SESSION_ERROR",message:"Failed to check session"}}},[t]),g=(0,n.useCallback)(async()=>{i(!0);try{let e=await a.xv.getMe();if(!h.current)return;e.success?(s(e.data),d(!1),u(null)):e.sessionExpired?(s(null),d(!0)):u({error:e.error,code:"SESSION_ERROR",message:e.error})}finally{h.current&&i(!1)}},[]);(0,n.useEffect)(()=>(0,a.Zk)(e=>{h.current&&(s(null),d(!0),u(e),t.onExpired(e))}),[t]),(0,n.useEffect)(()=>(h.current=!0,t.checkOnMount&&g(),()=>{h.current=!1}),[t.checkOnMount,g]),(0,n.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 b=(0,n.useCallback)(()=>{d(!1),u(null)},[]),f=(0,n.useCallback)(()=>{let e=encodeURIComponent(window.location.pathname+window.location.search);window.location.href="/login?returnTo=".concat(e)},[]),j=(0,n.useCallback)(async()=>{await a.xv.logout(),s(null),d(!1),u(null),window.location.href="/login"},[]);return{user:r,isLoading:l,isAuthenticated:null!==r,isExpired:c,error:x,csrfToken:(0,a._V)(),checkSession:p,clearExpired:b,redirectToLogin:f,logout:j}}({checkOnMount:x,checkInterval:x?c:0,onExpired:d}),m=(0,n.useCallback)(()=>{u.redirectToLogin()},[u]),h=(0,n.useCallback)(()=>{u.clearExpired()},[u]),p={...u,isCloudMode:x};return(0,s.jsxs)(i.Provider,{value:p,children:[t,x&&(0,s.jsx)(l,{isOpen:u.isExpired,error:u.error,onLogin:m,onDismiss:h})]})}function d(){return(0,n.useContext)(i)}}}]);
|