groove-dev 0.27.189 → 0.27.191

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.
@@ -41,7 +41,7 @@ ${typeof C.result=="string"?C.result.slice(0,500):JSON.stringify(C.result).slice
41
41
 
42
42
  `:" ";P[P.length-1]={...T,text:T.text+R+C,timestamp:Date.now()}}else P.push({from:"agent",text:C,timestamp:Date.now()});U[b]=P.slice(-100),t({chatHistory:U}),$A(U)}const M=s().conversations.find(R=>R.agentId===b);if(M){const R={...s().conversationMessages};R[M.id]||(R[M.id]=[]);const Y=[...R[M.id]],W=Y[Y.length-1],ee=W&&W.from==="assistant"&&Date.now()-W.timestamp<8e3;if(!(ee&&(W.text===C||W.text.endsWith(C)))){if(ee){const _=v.subtype==="assistant"?`
43
43
 
44
- `:" ";Y[Y.length-1]={...W,text:W.text+_+C,timestamp:Date.now()}}else Y.push({from:"assistant",text:C,timestamp:Date.now()});R[M.id]=Y.slice(-200),t({conversationMessages:R,streamingConversationId:M.id}),ft("groove:conversationMessages",R)}}}if(S&&S.trim()){const C={...s().activityLog};C[b]||(C[b]=[]),C[b]=[...C[b].slice(-200),{timestamp:Date.now(),text:S.trim(),type:v.type,subtype:"tool"}],t({activityLog:C}),ft("groove:activityLog",C)}if(s().workspaceMode&&Array.isArray(v.data)){const C=new Set(["Write","Edit","write_file","edit_file","create_file"]);for(const U of v.data){if(U.type!=="tool_use"||!C.has(U.name))continue;const P=((l=U.input)==null?void 0:l.file_path)||((c=U.input)==null?void 0:c.path);if(P&&b===s().workspaceAgentId){const T=P.replace(/^\/[^/]+.*?\/groove\//,"");s().editorActiveFile?t(F=>({editorOpenTabs:F.editorOpenTabs.includes(T)?F.editorOpenTabs:[...F.editorOpenTabs,T]})):s().openFile(T)}}}break}case"agent:exit":{if(r.status==="waiting_for_input"){const C=s().agents.find(U=>U.id===r.agentId);s().addToast("info",`${(C==null?void 0:C.name)||r.agentId.slice(0,8)} needs your input`,"Check the question popup below");break}const b=s().agents.find(C=>C.id===r.agentId),v=(b==null?void 0:b.name)||r.agentId,y=r.status==="killed"||r.code===143||r.code===137,S=r.status==="completed"?`${v} completed`:y?`${v} stopped`:`${v} crashed (exit ${r.code})`,j=r.status==="completed"?"success":y?"info":"warning";s().addToast(j,S,r.error?r.error.slice(0,200):void 0),s().thinkingAgents.has(r.agentId)&&t(C=>{const U=new Set(C.thinkingAgents);return U.delete(r.agentId),{thinkingAgents:U}});const N=s().conversations.find(C=>C.agentId===r.agentId);if(N&&s().streamingConversationId===N.id&&t({sendingMessage:!1,streamingConversationId:null}),r.error&&r.agentId&&s().addChatMessage(r.agentId,"system",`Crashed: ${r.error}`),s().workspaceAgentId===r.agentId){const C=s().agents.filter(P=>P.id!==r.agentId&&P.teamId===s().activeTeamId),U=C.find(P=>P.status==="running")||C[0];t({workspaceAgentId:(U==null?void 0:U.id)||null})}(b==null?void 0:b.role)==="planner"&&r.status==="completed"&&setTimeout(()=>s().checkRecommendedTeam(),1e3);break}case"innerchat:turn":{const{thread:b,turn:v}=r.data;if(v.status==="failed"){s().addToast("error",`InnerChat to ${v.to.name} failed`,v.error);break}t(y=>{const S={...y.chatHistory},j=(P,T)=>({from:"innerchat",text:v.text,timestamp:v.timestamp,isQuery:!1,innerchat:{turnId:v.id,threadId:b.id,kind:v.kind,peer:P,direction:T}}),N=(P,T)=>{S[P]=[...S[P]||[],T].slice(-100)};v.kind==="ask"&&N(v.from.id,j(v.to,"out")),N(v.to.id,j(v.from,"in")),$A(S);const C={...y.innerchatAnswers};v.kind==="answer"&&(C[v.from.id]={...C[v.from.id]||{},[v.text.trim()]:{peer:v.to,threadId:b.id}});const U={...y.innerchatThreads,[b.id]:b};return ft("groove:innerchatThreads",U),{chatHistory:S,innerchatThreads:U,innerchatAnswers:C}});break}case"recommended-team:ready":s().recommendedTeam||s().checkRecommendedTeam();break;case"phase2:spawned":s().addToast("info",`QC agent ${r.name} auto-spawned`,"Auditing phase 1 work");break;case"preview:ready":{const b=r.teamId?`/api/preview/${r.teamId}/proxy/`:r.url;t(v=>({teamPreviews:{...v.teamPreviews,[r.teamId]:{url:b,kind:r.kind,active:!0}}})),s().addToast("success","Project ready to preview",r.url,{label:"Open Preview",onClick:()=>s().openPreview(b,r.teamId,r.kind)},{persistent:!0,actions:[{label:"View in Browser",url:r.url}]});break}case"preview:failed":{const b=r.kind||"";b!=="no_preview"&&b!=="cli"&&b!=="none"&&s().addToast("warning","Preview could not launch",r.reason?String(r.reason).slice(0,200):"Unknown error");break}case"preview:stopped":{const b=s().teamPreviews[r.teamId];b&&t(v=>({teamPreviews:{...v.teamPreviews,[r.teamId]:{...b,active:!1}}}));break}case"agent:stalled":{const b=r.agentName||r.agentId,v=Math.round((r.silentMs||0)/1e3);s().addToast("warning",`${b} may be stalled`,`No output for ${v}s — API stream may be hung`);break}case"knock:denied":{const b=r.agentName||r.agentId;s().addToast("warning",`${b} blocked`,`${r.toolName} on ${r.target} — ${r.reason||"scope conflict"}`);break}case"phase2:failed":s().addToast("error","QC agent failed to spawn",r.error||"Unknown error");break;case"agent:message_queued":s().addChatMessage(r.agentId,"system","Agent is working — message will be delivered when it finishes.");break;case"agent:question":t(b=>({pendingQuestions:[...b.pendingQuestions,r.data]}));break;case"agent:question:resolved":t(b=>({pendingQuestions:b.pendingQuestions.filter(v=>v.agentId!==r.agentId)}));break;case"ollama:pull:progress":t({ollamaPullProgress:{...s().ollamaPullProgress,[r.model]:{status:"pulling",progress:r.progress}}});break;case"ollama:pull:complete":{const b={...s().ollamaPullProgress};delete b[r.model],t({ollamaPullProgress:b}),s().fetchOllamaStatus();break}case"ollama:pull:error":{const b={...s().ollamaPullProgress};delete b[r.model],t({ollamaPullProgress:b}),s().addToast("error",`Model pull failed: ${r.error}`);break}case"ollama:model:loaded":s().fetchOllamaStatus();break;case"ollama:model:unloaded":s().fetchOllamaStatus();break;case"ollama:model:imported":s().fetchOllamaStatus();break;case"lab:runtime:added":case"lab:runtime:updated":case"lab:runtime:removed":case"lab:runtime:started":case"lab:runtime:stopped":case"llama:server:stopped":s().fetchLabRuntimes();break;case"lab:preset:created":case"lab:preset:updated":case"lab:preset:deleted":break;case"rotation:start":break;case"rotation:complete":{const b=r.agentId,v=r.oldAgentId;if(!b||!v)break;t(y=>{var F,M,R;const S={...y.chatHistory},j={...y.tokenTimeline},N={...y.activityLog},C={...y.chatInputs};(F=S[v])!=null&&F.length&&(S[b]=[...S[v]],delete S[v]),(M=j[v])!=null&&M.length&&(j[b]=[...j[v]],delete j[v]),(R=N[v])!=null&&R.length&&(N[b]=[...N[v]],delete N[v]),C[v]&&(C[b]=C[v],delete C[v]);const U=y.detailPanel;let P=U,T=y.teamDetailPanels;if((U==null?void 0:U.type)==="agent"&&U.agentId===v){const Y={type:"agent",agentId:b};P=Y;const W=s().activeTeamId;T={...y.teamDetailPanels,[W]:Y}}let B=y.fleetSelectedAgents;(B[0]===v||B[1]===v)&&(B=[B[0]===v?b:B[0],B[1]===v?b:B[1]]);try{localStorage.setItem("groove:chatHistory",JSON.stringify(S))}catch{}return{chatHistory:S,tokenTimeline:j,activityLog:N,chatInputs:C,detailPanel:P,teamDetailPanels:T,fleetSelectedAgents:B}});break}case"rotation:failed":s().addToast("error","Rotation failed",r.error);break;case"file:changed":{const b=s().editorRecentSaves[r.path];if(b&&Date.now()-b<2e3)break;if(s().workspaceMode&&r.path&&!s().workspaceSnapshots[r.path]){const v=s().editorFiles[r.path];v!=null&&v.content&&s().captureSnapshot(r.path,v.content)}s().editorFiles[r.path]&&s().reloadFile(r.path);break}case"file:tree-changed":{s().fetchTreeDir(r.path||"");break}case"team:created":case"team:deleted":case"team:updated":s().fetchTeams();break;case"teams:reordered":r.teams&&t({teams:r.teams});break;case"approval:request":t(b=>({pendingApprovals:[...b.pendingApprovals,r.data]}));break;case"approval:resolved":{const b=r.data;t(v=>({pendingApprovals:v.pendingApprovals.filter(y=>y.id!==b.id),resolvedApprovals:[b,...v.resolvedApprovals].slice(0,200)}));break}case"conflict:detected":s().addToast("error",`Scope conflict: ${r.agentName||"agent"}`,r.filePath?`File: ${r.filePath}`:void 0);break;case"qc:activated":s().addToast("info","QC agent activated",`${r.agentCount||"4+"} agents running`);break;case"journalist:cycle":t({journalistStatus:r.data||null});break;case"schedule:execute":s().addToast("info",`Scheduled agent spawned: ${r.name||r.role||"agent"}`),s().fetchAutomations();break;case"schedule:created":case"schedule:updated":case"schedule:deleted":s().fetchAutomations();break;case"auto-agent:created":case"auto-agent:updated":case"auto-agent:deleted":case"auto-agent:paused":case"auto-agent:resumed":case"auto-agent:cycle-complete":case"auto-agent:auto-paused":case"auto-agent:state-updated":case"auto-agent:iteration-started":s().fetchAutoAgents();break;case"gateway:status":t({gateways:r.data||[]});break;case"provider:status-changed":t({_providerRefreshTick:Date.now()});break;case"federation:whitelist":t(b=>({federation:{...b.federation,whitelist:r.data||[]}}));break;case"federation:connection":t(b=>{const v=[...b.federation.connections],y=v.findIndex(S=>{var j;return S.ip===((j=r.data)==null?void 0:j.ip)});return y>=0?v[y]={...v[y],...r.data}:v.push(r.data),{federation:{...b.federation,connections:v}}});break;case"federation:pouch":case"federation:pouch-log":t(b=>({federation:{...b.federation,pouchLog:[...b.federation.pouchLog,r.data].slice(-200)}}));break;case"project-dir:changed":t({projectDir:(A=r.data)==null?void 0:A.projectDir,showProjectPicker:!1});break;case"tunnel.connected":s().fetchTunnels(),t({tunnelConnectStep:null});break;case"tunnel.status":{t({tunnelConnectStep:r.data});break}case"tunnel.disconnected":s().fetchTunnels();break;case"tunnel.health":{const b=s().savedTunnels.map(v=>{var y;return v.id===((y=r.data)==null?void 0:y.id)?{...v,latencyMs:r.data.latencyMs,healthy:r.data.healthy}:v});t({savedTunnels:b});break}case"tunnel.version-info":{const b=s().savedTunnels.map(v=>v.id===r.data.id?{...v,localVersion:r.data.localVersion,remoteVersion:r.data.remoteVersion,versionMatch:r.data.match}:v);t({savedTunnels:b});break}case"tunnel.version-mismatch":{const b=s().savedTunnels.map(v=>v.id===r.data.id?{...v,localVersion:r.data.localVersion,remoteVersion:r.data.remoteVersion,versionMatch:!1}:v);t({savedTunnels:b}),s().addToast("warning","Version mismatch",`Remote v${r.data.remoteVersion} — local v${r.data.localVersion}. ${r.data.message||""}`);break}case"tunnel.upgrade-failed":{s().addToast("error","Remote upgrade failed",r.data.error||"Unknown error");break}case"subscription:updated":{const b={subscription:r.data};((f=r.data)==null?void 0:f.active)===!0&&!s().marketplaceAuthenticated&&(b.marketplaceAuthenticated=!0),t(b),G.get("/edition").then(v=>{t({edition:v.edition||"community",subscription:{plan:v.plan||"community",status:v.status||(v.subscriptionActive?"active":"none"),active:v.subscriptionActive===!0,features:v.features||[],seats:v.seats||1,periodEnd:v.periodEnd||null,cancelAtPeriodEnd:v.cancelAtPeriodEnd||!1}})}).catch(()=>{}),s().fetchTunnels();break}case"auth:expired":t({marketplaceAuthenticated:!1,marketplaceUser:null}),s().addToast("warning","Session expired","Please sign in again");break;case"network:node:status":{const{__proto__:b,constructor:v,prototype:y,...S}=r.data||{};t({networkNode:{...s().networkNode,...S}});break}case"network:node:event":{const b=r.data||{};t(v=>({networkEvents:[...v.networkEvents,{...b,timestamp:b.timestamp||Date.now()}].slice(-100)}));break}case"signal_connected":{const b=r.data||{};t(v=>({networkEvents:[...v.networkEvents,{level:"connected",msg:String(b.msg||b.message||"Connected to signal").slice(0,500),detail:b.detail||b.url||void 0,timestamp:b.timestamp||Date.now()}].slice(-100)}));break}case"matched":{const b=r.data||{};t(v=>({networkEvents:[...v.networkEvents,{level:"session",msg:String(b.msg||b.message||"Session matched").slice(0,500),detail:b.detail||b.peer||b.nodeId||void 0,timestamp:b.timestamp||Date.now()}].slice(-100)}));break}case"network:status":{const b=r.data||{},v={networkStatus:{...s().networkStatus,...b}};if(b.compute){const P=b.compute;v.networkCompute={totalRamMb:P.totalRamMb??P.total_ram_mb??0,totalVramMb:P.totalVramMb??P.total_vram_mb??0,totalCpuCores:P.totalCpuCores??P.total_cpu_cores??0,totalBandwidthMbps:P.totalBandwidthMbps??P.total_bandwidth_mbps??0,activeNodes:P.activeNodes??P.active_nodes??0,totalNodes:P.totalNodes??P.total_nodes??0,avgLoad:P.avgLoad??P.avg_load??0}}else if(Array.isArray(b.nodes)&&b.nodes.length>0){const P=b.nodes,T=P.filter(B=>B.status==="active");v.networkCompute={totalRamMb:P.reduce((B,F)=>B+(F.ram_mb||0),0),totalVramMb:P.reduce((B,F)=>B+(F.vram_mb||0),0),totalCpuCores:P.reduce((B,F)=>B+(F.cpu_cores||0),0),totalBandwidthMbps:P.reduce((B,F)=>B+(F.bandwidth_mbps||0),0),activeNodes:T.length,totalNodes:P.length,avgLoad:T.length>0?T.reduce((B,F)=>B+(F.load||0),0)/T.length:0}}t(v);const y=b.nodes||[],S=s().networkNode.nodeId,j=S?y.find(P=>(P.node_id||P.nodeId)===S):null,N=y.filter(P=>P.status==="active"),C={t:Date.now(),globalSessions:b.activeSessions||0,mySessions:(j==null?void 0:j.active_sessions)??(j==null?void 0:j.sessions)??0,nodeCount:N.length,avgLoad:N.length>0?N.reduce((P,T)=>P+(T.load||0),0)/N.length:0,myLoad:(j==null?void 0:j.load)??0,totalVramMb:y.reduce((P,T)=>P+(T.vram_mb||0),0),totalRamMb:y.reduce((P,T)=>P+(T.ram_mb||0),0)};let U=[...s().networkSnapshots,C];U.length>100&&(U=U.slice(-100)),t({networkSnapshots:U});break}case"network:install:progress":{const{step:b,message:v,percent:y}=r.data||{};b==="done"?(t({networkInstalled:!0,networkInstallProgress:{installing:!1,step:null,message:null,percent:0,error:null}}),s().addToast("success","Network package installed")):t(b==="error"?{networkInstallProgress:{installing:!1,step:"error",message:v||"Install failed",percent:0,error:v||"Install failed"}}:{networkInstallProgress:{installing:!0,step:b||"progress",message:v||"",percent:Number.isFinite(y)?Math.max(0,Math.min(100,y)):s().networkInstallProgress.percent,error:null}});break}case"network:update:available":{const{installed:b,latest:v,updateAvailable:y}=r.data||{};t({networkVersion:{installed:b??s().networkVersion.installed,latest:v??s().networkVersion.latest,updateAvailable:!!y}});break}case"network:update:progress":{const{step:b,message:v,percent:y,version:S,error:j}=r.data||{};b==="done"?(t({networkUpdateProgress:{updating:!1,step:null,message:null,percent:0,error:null},networkVersion:{...s().networkVersion,installed:S||s().networkVersion.latest||s().networkVersion.installed,updateAvailable:!1}}),s().addToast("success","Network package updated")):b==="error"?(t({networkUpdateProgress:{updating:!1,step:"error",message:v||j||"Update failed",percent:0,error:v||j||"Update failed"}}),s().addToast("error","Network update failed",v||j)):t({networkUpdateProgress:{updating:!0,step:b||"progress",message:v||"",percent:Number.isFinite(y)?Math.max(0,Math.min(100,y)):s().networkUpdateProgress.percent,error:null}});break}case"training:status":{const b={trainingOptIn:((x=r.data)==null?void 0:x.optedIn)??!1,trainingStats:r.data};(h=r.data)!=null&&h.optedIn&&(b.dataSharingModalOpen=!1),t(b);break}case"config:updated":s().fetchBetaStatus(),s().fetchNetworkInstallStatus();break;case"conversation:created":{const b=r.data;b&&t(v=>({conversations:[b,...v.conversations.filter(y=>y.id!==b.id)]}));break}case"conversation:updated":{const b=r.data;b&&t(v=>({conversations:v.conversations.map(y=>y.id===b.id?{...y,...b}:y)}));break}case"conversation:deleted":{const b=((g=r.data)==null?void 0:g.id)||r.id;b&&t(v=>{const y=v.conversations.filter(N=>N.id!==b),S={...v.conversationMessages};delete S[b];const j=v.activeConversationId===b?null:v.activeConversationId;return j!==v.activeConversationId&&localStorage.setItem("groove:activeConversationId",""),{conversations:y,conversationMessages:S,activeConversationId:j}});break}case"conversation:tool":{const{conversationId:b,name:v,summary:y}=r.data||r;if(!b)break;t(S=>{const j={...S.conversationActiveTools};return j[b]={name:v||"Tool",summary:y||null,timestamp:Date.now()},{conversationActiveTools:j}});break}case"conversation:chunk":{const{conversationId:b,text:v}=r.data||r;if(!b||!v)break;t(y=>{const S={...y.conversationMessages};S[b]||(S[b]=[]);const j=[...S[b]],N=j[j.length-1];N&&N.from==="assistant"&&Date.now()-N.timestamp<3e4?j[j.length-1]={...N,text:N.text+v,timestamp:Date.now()}:j.push({from:"assistant",text:v,timestamp:Date.now()}),S[b]=j.slice(-200);const C={...y.conversationActiveTools};return delete C[b],{conversationMessages:S,streamingConversationId:b,conversationActiveTools:C}});break}case"conversation:complete":{const{conversationId:b}=r.data||r;if(b&&s().streamingConversationId===b){const v={...s().conversationActiveTools};delete v[b],t({sendingMessage:!1,streamingConversationId:null,conversationActiveTools:v})}b&&ft("groove:conversationMessages",s().conversationMessages);break}case"conversation:image":{const{conversationId:b,prompt:v,url:y,b64_json:S,mimeType:j,model:N,provider:C}=r.data||r;if(!b)break;const U=y||(S?`data:${j||"image/png"};base64,${S}`:null);t(P=>{const T={...P.conversationMessages};T[b]||(T[b]=[]);const B=[...T[b]],F=B.findLastIndex(R=>R.type==="image-loading"&&R.prompt===v);F>=0?B[F]={from:"assistant",type:"image",imageUrl:U,prompt:v,model:N,provider:C,timestamp:Date.now()}:B.push({from:"assistant",type:"image",imageUrl:U,prompt:v,model:N,provider:C,timestamp:Date.now()}),T[b]=B.slice(-200),ft("groove:conversationMessages",T);const M=P.streamingConversationId===b;return{conversationMessages:T,sendingMessage:M?!1:P.sendingMessage,streamingConversationId:M?null:P.streamingConversationId}});break}case"conversation:image-progress":{const{conversationId:b,status:v,prompt:y,error:S}=r.data||r;if(!b)break;v==="generating"?t(j=>{const N={...j.conversationMessages};return N[b]||(N[b]=[]),N[b]=[...N[b],{from:"assistant",type:"image-loading",prompt:y,timestamp:Date.now()}],{conversationMessages:N,streamingConversationId:b}}):v==="error"&&t(j=>{const N={...j.conversationMessages};N[b]||(N[b]=[]);const C=[...N[b]],U=C.findLastIndex(T=>T.type==="image-loading");U>=0&&C.splice(U,1),C.push({from:"system",text:`Image generation failed: ${S||"Unknown error"}`,timestamp:Date.now()}),N[b]=C,ft("groove:conversationMessages",N);const P=j.streamingConversationId===b;return{conversationMessages:N,sendingMessage:P?!1:j.sendingMessage,streamingConversationId:P?null:j.streamingConversationId}});break}case"conversation:error":{const{conversationId:b,error:v}=r.data||r;b&&t(y=>{const S={...y.conversationMessages};S[b]||(S[b]=[]),S[b]=[...S[b],{from:"system",text:`Error: ${v||"Unknown error"}`,timestamp:Date.now()}],ft("groove:conversationMessages",S);const j=y.streamingConversationId===b;return{conversationMessages:S,sendingMessage:j?!1:y.sendingMessage,streamingConversationId:j?null:y.streamingConversationId}});break}case"network:token:timing":{const{__proto__:b,constructor:v,prototype:y,...S}=r.data||{},j={networkTokenTiming:S,networkPerfSnapshots:[...s().networkPerfSnapshots,{t:Date.now(),tps:S.tps||0}].slice(-100)};if(Array.isArray(S.stages)){const N={...s().networkNodeTelemetry},C=new Set(["__proto__","constructor","prototype"]);for(const U of S.stages){const P=(O=U.node_telemetry)==null?void 0:O.node_id;P&&typeof P=="string"&&!C.has(P)&&(N[P]={...U.node_telemetry,forward_ms:U.forward_ms,updatedAt:Date.now()})}j.networkNodeTelemetry=N}t(j);break}case"network:timing:summary":{const{__proto__:b,constructor:v,prototype:y,...S}=r.data||{};t(j=>({networkBenchmarks:[...j.networkBenchmarks,S].slice(-100)}));break}case"keeper:saved":case"keeper:updated":case"keeper:deleted":s().fetchKeeperItems();break}},n.onclose=()=>{za&&(clearInterval(za),za=null),t({connected:!1,hydrated:!1,ws:null,daemonHost:null,tunneled:!1,remoteHomedir:null}),setTimeout(()=>s().connect(),2e3)},n.onerror=()=>n.close()}}));if(typeof window<"u"){const t=()=>{const s=k.getState();s.ws||s.connect()};window.addEventListener("online",t),window.addEventListener("focus",t),document.addEventListener("visibilitychange",()=>{document.hidden||t()})}function pN(t){p.useEffect(()=>{function s(n){for(const a of t){const r=a.meta?n.metaKey||n.ctrlKey:!0,l=a.shift?n.shiftKey:!n.shiftKey;if(n.key.toLowerCase()===a.key.toLowerCase()&&r&&l){n.preventDefault(),a.handler();return}}}return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[t])}function cd(){return!!(window.groove||navigator.userAgent.includes("Electron"))}function gN(){var t;return((t=window.groove)==null?void 0:t.platform)||"browser"}function sO(t){window.groove?window.groove.openExternal(t):window.open(t,"_blank")}async function wE(t={}){var s,n;return(n=(s=window.groove)==null?void 0:s.folders)!=null&&n.select?window.groove.folders.select(t):null}async function ON(t){var s,n;if((n=(s=window.groove)==null?void 0:s.integrations)!=null&&n.oauthStart)return window.groove.integrations.oauthStart(t);window.open(t,"_blank","noopener")}function bN(t){var s,n,a="";if(typeof t=="string"||typeof t=="number")a+=t;else if(typeof t=="object")if(Array.isArray(t)){var r=t.length;for(s=0;s<r;s++)t[s]&&(n=bN(t[s]))&&(a&&(a+=" "),a+=n)}else for(n in t)t[n]&&(a&&(a+=" "),a+=n);return a}function jE(){for(var t,s,n=0,a="",r=arguments.length;n<r;n++)(t=arguments[n])&&(s=bN(t))&&(a&&(a+=" "),a+=s);return a}const QE=(t,s)=>{const n=new Array(t.length+s.length);for(let a=0;a<t.length;a++)n[a]=t[a];for(let a=0;a<s.length;a++)n[t.length+a]=s[a];return n},NE=(t,s)=>({classGroupId:t,validator:s}),vN=(t=new Map,s=null,n)=>({nextPart:t,validators:s,classGroupId:n}),ex="-",Dw=[],SE="arbitrary..",CE=t=>{const s=kE(t),{conflictingClassGroups:n,conflictingClassGroupModifiers:a}=t;return{getClassGroupId:c=>{if(c.startsWith("[")&&c.endsWith("]"))return BE(c);const A=c.split(ex),f=A[0]===""&&A.length>1?1:0;return yN(A,f,s)},getConflictingClassGroupIds:(c,A)=>{if(A){const f=a[c],x=n[c];return f?x?QE(x,f):f:x||Dw}return n[c]||Dw}}},yN=(t,s,n)=>{if(t.length-s===0)return n.classGroupId;const r=t[s],l=n.nextPart.get(r);if(l){const x=yN(t,s+1,l);if(x)return x}const c=n.validators;if(c===null)return;const A=s===0?t.join(ex):t.slice(s).join(ex),f=c.length;for(let x=0;x<f;x++){const h=c[x];if(h.validator(A))return h.classGroupId}},BE=t=>t.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const s=t.slice(1,-1),n=s.indexOf(":"),a=s.slice(0,n);return a?SE+a:void 0})(),kE=t=>{const{theme:s,classGroups:n}=t;return TE(n,s)},TE=(t,s)=>{const n=vN();for(const a in t){const r=t[a];fb(r,n,a,s)}return n},fb=(t,s,n,a)=>{const r=t.length;for(let l=0;l<r;l++){const c=t[l];UE(c,s,n,a)}},UE=(t,s,n,a)=>{if(typeof t=="string"){EE(t,s,n);return}if(typeof t=="function"){PE(t,s,n,a);return}FE(t,s,n,a)},EE=(t,s,n)=>{const a=t===""?s:wN(s,t);a.classGroupId=n},PE=(t,s,n,a)=>{if($E(t)){fb(t(a),s,n,a);return}s.validators===null&&(s.validators=[]),s.validators.push(NE(n,t))},FE=(t,s,n,a)=>{const r=Object.entries(t),l=r.length;for(let c=0;c<l;c++){const[A,f]=r[c];fb(f,wN(s,A),n,a)}},wN=(t,s)=>{let n=t;const a=s.split(ex),r=a.length;for(let l=0;l<r;l++){const c=a[l];let A=n.nextPart.get(c);A||(A=vN(),n.nextPart.set(c,A)),n=A}return n},$E=t=>"isThemeGetter"in t&&t.isThemeGetter===!0,RE=t=>{if(t<1)return{get:()=>{},set:()=>{}};let s=0,n=Object.create(null),a=Object.create(null);const r=(l,c)=>{n[l]=c,s++,s>t&&(s=0,a=n,n=Object.create(null))};return{get(l){let c=n[l];if(c!==void 0)return c;if((c=a[l])!==void 0)return r(l,c),c},set(l,c){l in n?n[l]=c:r(l,c)}}},nO="!",Lw=":",ME=[],Hw=(t,s,n,a,r)=>({modifiers:t,hasImportantModifier:s,baseClassName:n,maybePostfixModifierPosition:a,isExternal:r}),IE=t=>{const{prefix:s,experimentalParseClassName:n}=t;let a=r=>{const l=[];let c=0,A=0,f=0,x;const h=r.length;for(let y=0;y<h;y++){const S=r[y];if(c===0&&A===0){if(S===Lw){l.push(r.slice(f,y)),f=y+1;continue}if(S==="/"){x=y;continue}}S==="["?c++:S==="]"?c--:S==="("?A++:S===")"&&A--}const g=l.length===0?r:r.slice(f);let O=g,b=!1;g.endsWith(nO)?(O=g.slice(0,-1),b=!0):g.startsWith(nO)&&(O=g.slice(1),b=!0);const v=x&&x>f?x-f:void 0;return Hw(l,b,O,v)};if(s){const r=s+Lw,l=a;a=c=>c.startsWith(r)?l(c.slice(r.length)):Hw(ME,!1,c,void 0,!0)}if(n){const r=a;a=l=>n({className:l,parseClassName:r})}return a},zE=t=>{const s=new Map;return t.orderSensitiveModifiers.forEach((n,a)=>{s.set(n,1e6+a)}),n=>{const a=[];let r=[];for(let l=0;l<n.length;l++){const c=n[l],A=c[0]==="[",f=s.has(c);A||f?(r.length>0&&(r.sort(),a.push(...r),r=[]),a.push(c)):r.push(c)}return r.length>0&&(r.sort(),a.push(...r)),a}},_E=t=>({cache:RE(t.cacheSize),parseClassName:IE(t),sortModifiers:zE(t),...CE(t)}),DE=/\s+/,LE=(t,s)=>{const{parseClassName:n,getClassGroupId:a,getConflictingClassGroupIds:r,sortModifiers:l}=s,c=[],A=t.trim().split(DE);let f="";for(let x=A.length-1;x>=0;x-=1){const h=A[x],{isExternal:g,modifiers:O,hasImportantModifier:b,baseClassName:v,maybePostfixModifierPosition:y}=n(h);if(g){f=h+(f.length>0?" "+f:f);continue}let S=!!y,j=a(S?v.substring(0,y):v);if(!j){if(!S){f=h+(f.length>0?" "+f:f);continue}if(j=a(v),!j){f=h+(f.length>0?" "+f:f);continue}S=!1}const N=O.length===0?"":O.length===1?O[0]:l(O).join(":"),C=b?N+nO:N,U=C+j;if(c.indexOf(U)>-1)continue;c.push(U);const P=r(j,S);for(let T=0;T<P.length;++T){const B=P[T];c.push(C+B)}f=h+(f.length>0?" "+f:f)}return f},HE=(...t)=>{let s=0,n,a,r="";for(;s<t.length;)(n=t[s++])&&(a=jN(n))&&(r&&(r+=" "),r+=a);return r},jN=t=>{if(typeof t=="string")return t;let s,n="";for(let a=0;a<t.length;a++)t[a]&&(s=jN(t[a]))&&(n&&(n+=" "),n+=s);return n},XE=(t,...s)=>{let n,a,r,l;const c=f=>{const x=s.reduce((h,g)=>g(h),t());return n=_E(x),a=n.cache.get,r=n.cache.set,l=A,A(f)},A=f=>{const x=a(f);if(x)return x;const h=LE(f,n);return r(f,h),h};return l=c,(...f)=>l(HE(...f))},GE=[],js=t=>{const s=n=>n[t]||GE;return s.isThemeGetter=!0,s},QN=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,NN=/^\((?:(\w[\w-]*):)?(.+)\)$/i,ZE=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,VE=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,KE=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,qE=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,WE=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,YE=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,xo=t=>ZE.test(t),at=t=>!!t&&!Number.isNaN(Number(t)),mo=t=>!!t&&Number.isInteger(Number(t)),Mp=t=>t.endsWith("%")&&at(t.slice(0,-1)),Sr=t=>VE.test(t),SN=()=>!0,JE=t=>KE.test(t)&&!qE.test(t),xb=()=>!1,eP=t=>WE.test(t),tP=t=>YE.test(t),sP=t=>!Me(t)&&!Ie(t),nP=t=>Do(t,kN,xb),Me=t=>QN.test(t),mi=t=>Do(t,TN,JE),Xw=t=>Do(t,dP,at),aP=t=>Do(t,EN,SN),rP=t=>Do(t,UN,xb),Gw=t=>Do(t,CN,xb),oP=t=>Do(t,BN,tP),Mu=t=>Do(t,PN,eP),Ie=t=>NN.test(t),fA=t=>_i(t,TN),iP=t=>_i(t,UN),Zw=t=>_i(t,CN),lP=t=>_i(t,kN),cP=t=>_i(t,BN),Iu=t=>_i(t,PN,!0),AP=t=>_i(t,EN,!0),Do=(t,s,n)=>{const a=QN.exec(t);return a?a[1]?s(a[1]):n(a[2]):!1},_i=(t,s,n=!1)=>{const a=NN.exec(t);return a?a[1]?s(a[1]):n:!1},CN=t=>t==="position"||t==="percentage",BN=t=>t==="image"||t==="url",kN=t=>t==="length"||t==="size"||t==="bg-size",TN=t=>t==="length",dP=t=>t==="number",UN=t=>t==="family-name",EN=t=>t==="number"||t==="weight",PN=t=>t==="shadow",uP=()=>{const t=js("color"),s=js("font"),n=js("text"),a=js("font-weight"),r=js("tracking"),l=js("leading"),c=js("breakpoint"),A=js("container"),f=js("spacing"),x=js("radius"),h=js("shadow"),g=js("inset-shadow"),O=js("text-shadow"),b=js("drop-shadow"),v=js("blur"),y=js("perspective"),S=js("aspect"),j=js("ease"),N=js("animate"),C=()=>["auto","avoid","all","avoid-page","page","left","right","column"],U=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],P=()=>[...U(),Ie,Me],T=()=>["auto","hidden","clip","visible","scroll"],B=()=>["auto","contain","none"],F=()=>[Ie,Me,f],M=()=>[xo,"full","auto",...F()],R=()=>[mo,"none","subgrid",Ie,Me],Y=()=>["auto",{span:["full",mo,Ie,Me]},mo,Ie,Me],W=()=>[mo,"auto",Ie,Me],ee=()=>["auto","min","max","fr",Ie,Me],K=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],_=()=>["start","end","center","stretch","center-safe","end-safe"],E=()=>["auto",...F()],q=()=>[xo,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...F()],H=()=>[xo,"screen","full","dvw","lvw","svw","min","max","fit",...F()],I=()=>[xo,"screen","full","lh","dvh","lvh","svh","min","max","fit",...F()],L=()=>[t,Ie,Me],J=()=>[...U(),Zw,Gw,{position:[Ie,Me]}],D=()=>["no-repeat",{repeat:["","x","y","space","round"]}],se=()=>["auto","cover","contain",lP,nP,{size:[Ie,Me]}],le=()=>[Mp,fA,mi],V=()=>["","none","full",x,Ie,Me],te=()=>["",at,fA,mi],ae=()=>["solid","dashed","dotted","double"],be=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],z=()=>[at,Mp,Zw,Gw],oe=()=>["","none",v,Ie,Me],ue=()=>["none",at,Ie,Me],ve=()=>["none",at,Ie,Me],Ce=()=>[at,Ie,Me],Ne=()=>[xo,"full",...F()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[Sr],breakpoint:[Sr],color:[SN],container:[Sr],"drop-shadow":[Sr],ease:["in","out","in-out"],font:[sP],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[Sr],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[Sr],shadow:[Sr],spacing:["px",at],text:[Sr],"text-shadow":[Sr],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",xo,Me,Ie,S]}],container:["container"],columns:[{columns:[at,Me,Ie,A]}],"break-after":[{"break-after":C()}],"break-before":[{"break-before":C()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:P()}],overflow:[{overflow:T()}],"overflow-x":[{"overflow-x":T()}],"overflow-y":[{"overflow-y":T()}],overscroll:[{overscroll:B()}],"overscroll-x":[{"overscroll-x":B()}],"overscroll-y":[{"overscroll-y":B()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:M()}],"inset-x":[{"inset-x":M()}],"inset-y":[{"inset-y":M()}],start:[{"inset-s":M(),start:M()}],end:[{"inset-e":M(),end:M()}],"inset-bs":[{"inset-bs":M()}],"inset-be":[{"inset-be":M()}],top:[{top:M()}],right:[{right:M()}],bottom:[{bottom:M()}],left:[{left:M()}],visibility:["visible","invisible","collapse"],z:[{z:[mo,"auto",Ie,Me]}],basis:[{basis:[xo,"full","auto",A,...F()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[at,xo,"auto","initial","none",Me]}],grow:[{grow:["",at,Ie,Me]}],shrink:[{shrink:["",at,Ie,Me]}],order:[{order:[mo,"first","last","none",Ie,Me]}],"grid-cols":[{"grid-cols":R()}],"col-start-end":[{col:Y()}],"col-start":[{"col-start":W()}],"col-end":[{"col-end":W()}],"grid-rows":[{"grid-rows":R()}],"row-start-end":[{row:Y()}],"row-start":[{"row-start":W()}],"row-end":[{"row-end":W()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":ee()}],"auto-rows":[{"auto-rows":ee()}],gap:[{gap:F()}],"gap-x":[{"gap-x":F()}],"gap-y":[{"gap-y":F()}],"justify-content":[{justify:[...K(),"normal"]}],"justify-items":[{"justify-items":[..._(),"normal"]}],"justify-self":[{"justify-self":["auto",..._()]}],"align-content":[{content:["normal",...K()]}],"align-items":[{items:[..._(),{baseline:["","last"]}]}],"align-self":[{self:["auto",..._(),{baseline:["","last"]}]}],"place-content":[{"place-content":K()}],"place-items":[{"place-items":[..._(),"baseline"]}],"place-self":[{"place-self":["auto",..._()]}],p:[{p:F()}],px:[{px:F()}],py:[{py:F()}],ps:[{ps:F()}],pe:[{pe:F()}],pbs:[{pbs:F()}],pbe:[{pbe:F()}],pt:[{pt:F()}],pr:[{pr:F()}],pb:[{pb:F()}],pl:[{pl:F()}],m:[{m:E()}],mx:[{mx:E()}],my:[{my:E()}],ms:[{ms:E()}],me:[{me:E()}],mbs:[{mbs:E()}],mbe:[{mbe:E()}],mt:[{mt:E()}],mr:[{mr:E()}],mb:[{mb:E()}],ml:[{ml:E()}],"space-x":[{"space-x":F()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":F()}],"space-y-reverse":["space-y-reverse"],size:[{size:q()}],"inline-size":[{inline:["auto",...H()]}],"min-inline-size":[{"min-inline":["auto",...H()]}],"max-inline-size":[{"max-inline":["none",...H()]}],"block-size":[{block:["auto",...I()]}],"min-block-size":[{"min-block":["auto",...I()]}],"max-block-size":[{"max-block":["none",...I()]}],w:[{w:[A,"screen",...q()]}],"min-w":[{"min-w":[A,"screen","none",...q()]}],"max-w":[{"max-w":[A,"screen","none","prose",{screen:[c]},...q()]}],h:[{h:["screen","lh",...q()]}],"min-h":[{"min-h":["screen","lh","none",...q()]}],"max-h":[{"max-h":["screen","lh",...q()]}],"font-size":[{text:["base",n,fA,mi]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[a,AP,aP]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",Mp,Me]}],"font-family":[{font:[iP,rP,s]}],"font-features":[{"font-features":[Me]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[r,Ie,Me]}],"line-clamp":[{"line-clamp":[at,"none",Ie,Xw]}],leading:[{leading:[l,...F()]}],"list-image":[{"list-image":["none",Ie,Me]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",Ie,Me]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:L()}],"text-color":[{text:L()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...ae(),"wavy"]}],"text-decoration-thickness":[{decoration:[at,"from-font","auto",Ie,mi]}],"text-decoration-color":[{decoration:L()}],"underline-offset":[{"underline-offset":[at,"auto",Ie,Me]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:F()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",Ie,Me]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",Ie,Me]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:J()}],"bg-repeat":[{bg:D()}],"bg-size":[{bg:se()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},mo,Ie,Me],radial:["",Ie,Me],conic:[mo,Ie,Me]},cP,oP]}],"bg-color":[{bg:L()}],"gradient-from-pos":[{from:le()}],"gradient-via-pos":[{via:le()}],"gradient-to-pos":[{to:le()}],"gradient-from":[{from:L()}],"gradient-via":[{via:L()}],"gradient-to":[{to:L()}],rounded:[{rounded:V()}],"rounded-s":[{"rounded-s":V()}],"rounded-e":[{"rounded-e":V()}],"rounded-t":[{"rounded-t":V()}],"rounded-r":[{"rounded-r":V()}],"rounded-b":[{"rounded-b":V()}],"rounded-l":[{"rounded-l":V()}],"rounded-ss":[{"rounded-ss":V()}],"rounded-se":[{"rounded-se":V()}],"rounded-ee":[{"rounded-ee":V()}],"rounded-es":[{"rounded-es":V()}],"rounded-tl":[{"rounded-tl":V()}],"rounded-tr":[{"rounded-tr":V()}],"rounded-br":[{"rounded-br":V()}],"rounded-bl":[{"rounded-bl":V()}],"border-w":[{border:te()}],"border-w-x":[{"border-x":te()}],"border-w-y":[{"border-y":te()}],"border-w-s":[{"border-s":te()}],"border-w-e":[{"border-e":te()}],"border-w-bs":[{"border-bs":te()}],"border-w-be":[{"border-be":te()}],"border-w-t":[{"border-t":te()}],"border-w-r":[{"border-r":te()}],"border-w-b":[{"border-b":te()}],"border-w-l":[{"border-l":te()}],"divide-x":[{"divide-x":te()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":te()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...ae(),"hidden","none"]}],"divide-style":[{divide:[...ae(),"hidden","none"]}],"border-color":[{border:L()}],"border-color-x":[{"border-x":L()}],"border-color-y":[{"border-y":L()}],"border-color-s":[{"border-s":L()}],"border-color-e":[{"border-e":L()}],"border-color-bs":[{"border-bs":L()}],"border-color-be":[{"border-be":L()}],"border-color-t":[{"border-t":L()}],"border-color-r":[{"border-r":L()}],"border-color-b":[{"border-b":L()}],"border-color-l":[{"border-l":L()}],"divide-color":[{divide:L()}],"outline-style":[{outline:[...ae(),"none","hidden"]}],"outline-offset":[{"outline-offset":[at,Ie,Me]}],"outline-w":[{outline:["",at,fA,mi]}],"outline-color":[{outline:L()}],shadow:[{shadow:["","none",h,Iu,Mu]}],"shadow-color":[{shadow:L()}],"inset-shadow":[{"inset-shadow":["none",g,Iu,Mu]}],"inset-shadow-color":[{"inset-shadow":L()}],"ring-w":[{ring:te()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:L()}],"ring-offset-w":[{"ring-offset":[at,mi]}],"ring-offset-color":[{"ring-offset":L()}],"inset-ring-w":[{"inset-ring":te()}],"inset-ring-color":[{"inset-ring":L()}],"text-shadow":[{"text-shadow":["none",O,Iu,Mu]}],"text-shadow-color":[{"text-shadow":L()}],opacity:[{opacity:[at,Ie,Me]}],"mix-blend":[{"mix-blend":[...be(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":be()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[at]}],"mask-image-linear-from-pos":[{"mask-linear-from":z()}],"mask-image-linear-to-pos":[{"mask-linear-to":z()}],"mask-image-linear-from-color":[{"mask-linear-from":L()}],"mask-image-linear-to-color":[{"mask-linear-to":L()}],"mask-image-t-from-pos":[{"mask-t-from":z()}],"mask-image-t-to-pos":[{"mask-t-to":z()}],"mask-image-t-from-color":[{"mask-t-from":L()}],"mask-image-t-to-color":[{"mask-t-to":L()}],"mask-image-r-from-pos":[{"mask-r-from":z()}],"mask-image-r-to-pos":[{"mask-r-to":z()}],"mask-image-r-from-color":[{"mask-r-from":L()}],"mask-image-r-to-color":[{"mask-r-to":L()}],"mask-image-b-from-pos":[{"mask-b-from":z()}],"mask-image-b-to-pos":[{"mask-b-to":z()}],"mask-image-b-from-color":[{"mask-b-from":L()}],"mask-image-b-to-color":[{"mask-b-to":L()}],"mask-image-l-from-pos":[{"mask-l-from":z()}],"mask-image-l-to-pos":[{"mask-l-to":z()}],"mask-image-l-from-color":[{"mask-l-from":L()}],"mask-image-l-to-color":[{"mask-l-to":L()}],"mask-image-x-from-pos":[{"mask-x-from":z()}],"mask-image-x-to-pos":[{"mask-x-to":z()}],"mask-image-x-from-color":[{"mask-x-from":L()}],"mask-image-x-to-color":[{"mask-x-to":L()}],"mask-image-y-from-pos":[{"mask-y-from":z()}],"mask-image-y-to-pos":[{"mask-y-to":z()}],"mask-image-y-from-color":[{"mask-y-from":L()}],"mask-image-y-to-color":[{"mask-y-to":L()}],"mask-image-radial":[{"mask-radial":[Ie,Me]}],"mask-image-radial-from-pos":[{"mask-radial-from":z()}],"mask-image-radial-to-pos":[{"mask-radial-to":z()}],"mask-image-radial-from-color":[{"mask-radial-from":L()}],"mask-image-radial-to-color":[{"mask-radial-to":L()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":U()}],"mask-image-conic-pos":[{"mask-conic":[at]}],"mask-image-conic-from-pos":[{"mask-conic-from":z()}],"mask-image-conic-to-pos":[{"mask-conic-to":z()}],"mask-image-conic-from-color":[{"mask-conic-from":L()}],"mask-image-conic-to-color":[{"mask-conic-to":L()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:J()}],"mask-repeat":[{mask:D()}],"mask-size":[{mask:se()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",Ie,Me]}],filter:[{filter:["","none",Ie,Me]}],blur:[{blur:oe()}],brightness:[{brightness:[at,Ie,Me]}],contrast:[{contrast:[at,Ie,Me]}],"drop-shadow":[{"drop-shadow":["","none",b,Iu,Mu]}],"drop-shadow-color":[{"drop-shadow":L()}],grayscale:[{grayscale:["",at,Ie,Me]}],"hue-rotate":[{"hue-rotate":[at,Ie,Me]}],invert:[{invert:["",at,Ie,Me]}],saturate:[{saturate:[at,Ie,Me]}],sepia:[{sepia:["",at,Ie,Me]}],"backdrop-filter":[{"backdrop-filter":["","none",Ie,Me]}],"backdrop-blur":[{"backdrop-blur":oe()}],"backdrop-brightness":[{"backdrop-brightness":[at,Ie,Me]}],"backdrop-contrast":[{"backdrop-contrast":[at,Ie,Me]}],"backdrop-grayscale":[{"backdrop-grayscale":["",at,Ie,Me]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[at,Ie,Me]}],"backdrop-invert":[{"backdrop-invert":["",at,Ie,Me]}],"backdrop-opacity":[{"backdrop-opacity":[at,Ie,Me]}],"backdrop-saturate":[{"backdrop-saturate":[at,Ie,Me]}],"backdrop-sepia":[{"backdrop-sepia":["",at,Ie,Me]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":F()}],"border-spacing-x":[{"border-spacing-x":F()}],"border-spacing-y":[{"border-spacing-y":F()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",Ie,Me]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[at,"initial",Ie,Me]}],ease:[{ease:["linear","initial",j,Ie,Me]}],delay:[{delay:[at,Ie,Me]}],animate:[{animate:["none",N,Ie,Me]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[y,Ie,Me]}],"perspective-origin":[{"perspective-origin":P()}],rotate:[{rotate:ue()}],"rotate-x":[{"rotate-x":ue()}],"rotate-y":[{"rotate-y":ue()}],"rotate-z":[{"rotate-z":ue()}],scale:[{scale:ve()}],"scale-x":[{"scale-x":ve()}],"scale-y":[{"scale-y":ve()}],"scale-z":[{"scale-z":ve()}],"scale-3d":["scale-3d"],skew:[{skew:Ce()}],"skew-x":[{"skew-x":Ce()}],"skew-y":[{"skew-y":Ce()}],transform:[{transform:[Ie,Me,"","none","gpu","cpu"]}],"transform-origin":[{origin:P()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:Ne()}],"translate-x":[{"translate-x":Ne()}],"translate-y":[{"translate-y":Ne()}],"translate-z":[{"translate-z":Ne()}],"translate-none":["translate-none"],accent:[{accent:L()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:L()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",Ie,Me]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":F()}],"scroll-mx":[{"scroll-mx":F()}],"scroll-my":[{"scroll-my":F()}],"scroll-ms":[{"scroll-ms":F()}],"scroll-me":[{"scroll-me":F()}],"scroll-mbs":[{"scroll-mbs":F()}],"scroll-mbe":[{"scroll-mbe":F()}],"scroll-mt":[{"scroll-mt":F()}],"scroll-mr":[{"scroll-mr":F()}],"scroll-mb":[{"scroll-mb":F()}],"scroll-ml":[{"scroll-ml":F()}],"scroll-p":[{"scroll-p":F()}],"scroll-px":[{"scroll-px":F()}],"scroll-py":[{"scroll-py":F()}],"scroll-ps":[{"scroll-ps":F()}],"scroll-pe":[{"scroll-pe":F()}],"scroll-pbs":[{"scroll-pbs":F()}],"scroll-pbe":[{"scroll-pbe":F()}],"scroll-pt":[{"scroll-pt":F()}],"scroll-pr":[{"scroll-pr":F()}],"scroll-pb":[{"scroll-pb":F()}],"scroll-pl":[{"scroll-pl":F()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",Ie,Me]}],fill:[{fill:["none",...L()]}],"stroke-w":[{stroke:[at,fA,mi,Xw]}],stroke:[{stroke:["none",...L()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}},fP=XE(uP);function Z(...t){return fP(jE(t))}function Ue(t,s,{checkForDefaultPrevented:n=!0}={}){return function(r){if(t==null||t(r),n===!1||!r.defaultPrevented)return s==null?void 0:s(r)}}function Vw(t,s){if(typeof t=="function")return t(s);t!=null&&(t.current=s)}function mb(...t){return s=>{let n=!1;const a=t.map(r=>{const l=Vw(r,s);return!n&&typeof l=="function"&&(n=!0),l});if(n)return()=>{for(let r=0;r<a.length;r++){const l=a[r];typeof l=="function"?l():Vw(t[r],null)}}}}function mt(...t){return p.useCallback(mb(...t),t)}function xP(t,s){const n=p.createContext(s),a=l=>{const{children:c,...A}=l,f=p.useMemo(()=>A,Object.values(A));return e.jsx(n.Provider,{value:f,children:c})};a.displayName=t+"Provider";function r(l){const c=p.useContext(n);if(c)return c;if(s!==void 0)return s;throw new Error(`\`${l}\` must be used within \`${t}\``)}return[a,r]}function Ya(t,s=[]){let n=[];function a(l,c){const A=p.createContext(c),f=n.length;n=[...n,c];const x=g=>{var j;const{scope:O,children:b,...v}=g,y=((j=O==null?void 0:O[t])==null?void 0:j[f])||A,S=p.useMemo(()=>v,Object.values(v));return e.jsx(y.Provider,{value:S,children:b})};x.displayName=l+"Provider";function h(g,O){var y;const b=((y=O==null?void 0:O[t])==null?void 0:y[f])||A,v=p.useContext(b);if(v)return v;if(c!==void 0)return c;throw new Error(`\`${g}\` must be used within \`${l}\``)}return[x,h]}const r=()=>{const l=n.map(c=>p.createContext(c));return function(A){const f=(A==null?void 0:A[t])||l;return p.useMemo(()=>({[`__scope${t}`]:{...A,[t]:f}}),[A,f])}};return r.scopeName=t,[a,mP(r,...s)]}function mP(...t){const s=t[0];if(t.length===1)return s;const n=()=>{const a=t.map(r=>({useScope:r(),scopeName:r.scopeName}));return function(l){const c=a.reduce((A,{useScope:f,scopeName:x})=>{const g=f(l)[`__scope${x}`];return{...A,...g}},{});return p.useMemo(()=>({[`__scope${s.scopeName}`]:c}),[c])}};return n.scopeName=s.scopeName,n}function ec(t){const s=hP(t),n=p.forwardRef((a,r)=>{const{children:l,...c}=a,A=p.Children.toArray(l),f=A.find(gP);if(f){const x=f.props.children,h=A.map(g=>g===f?p.Children.count(x)>1?p.Children.only(null):p.isValidElement(x)?x.props.children:null:g);return e.jsx(s,{...c,ref:r,children:p.isValidElement(x)?p.cloneElement(x,void 0,h):null})}return e.jsx(s,{...c,ref:r,children:l})});return n.displayName=`${t}.Slot`,n}function hP(t){const s=p.forwardRef((n,a)=>{const{children:r,...l}=n;if(p.isValidElement(r)){const c=bP(r),A=OP(l,r.props);return r.type!==p.Fragment&&(A.ref=a?mb(a,c):c),p.cloneElement(r,A)}return p.Children.count(r)>1?p.Children.only(null):null});return s.displayName=`${t}.SlotClone`,s}var FN=Symbol("radix.slottable");function pP(t){const s=({children:n})=>e.jsx(e.Fragment,{children:n});return s.displayName=`${t}.Slottable`,s.__radixId=FN,s}function gP(t){return p.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===FN}function OP(t,s){const n={...s};for(const a in s){const r=t[a],l=s[a];/^on[A-Z]/.test(a)?r&&l?n[a]=(...A)=>{const f=l(...A);return r(...A),f}:r&&(n[a]=r):a==="style"?n[a]={...r,...l}:a==="className"&&(n[a]=[r,l].filter(Boolean).join(" "))}return{...t,...n}}function bP(t){var a,r;let s=(a=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:a.get,n=s&&"isReactWarning"in s&&s.isReactWarning;return n?t.ref:(s=(r=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:r.get,n=s&&"isReactWarning"in s&&s.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var vP=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],et=vP.reduce((t,s)=>{const n=ec(`Primitive.${s}`),a=p.forwardRef((r,l)=>{const{asChild:c,...A}=r,f=c?n:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(f,{...A,ref:l})});return a.displayName=`Primitive.${s}`,{...t,[s]:a}},{});function $N(t,s){t&&Px.flushSync(()=>t.dispatchEvent(s))}function Us(t){const s=p.useRef(t);return p.useEffect(()=>{s.current=t}),p.useMemo(()=>(...n)=>{var a;return(a=s.current)==null?void 0:a.call(s,...n)},[])}function yP(t,s=globalThis==null?void 0:globalThis.document){const n=Us(t);p.useEffect(()=>{const a=r=>{r.key==="Escape"&&n(r)};return s.addEventListener("keydown",a,{capture:!0}),()=>s.removeEventListener("keydown",a,{capture:!0})},[n,s])}var wP="DismissableLayer",aO="dismissableLayer.update",jP="dismissableLayer.pointerDownOutside",QP="dismissableLayer.focusOutside",Kw,RN=p.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ad=p.forwardRef((t,s)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:a,onPointerDownOutside:r,onFocusOutside:l,onInteractOutside:c,onDismiss:A,...f}=t,x=p.useContext(RN),[h,g]=p.useState(null),O=(h==null?void 0:h.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,b]=p.useState({}),v=mt(s,B=>g(B)),y=Array.from(x.layers),[S]=[...x.layersWithOutsidePointerEventsDisabled].slice(-1),j=y.indexOf(S),N=h?y.indexOf(h):-1,C=x.layersWithOutsidePointerEventsDisabled.size>0,U=N>=j,P=CP(B=>{const F=B.target,M=[...x.branches].some(R=>R.contains(F));!U||M||(r==null||r(B),c==null||c(B),B.defaultPrevented||A==null||A())},O),T=BP(B=>{const F=B.target;[...x.branches].some(R=>R.contains(F))||(l==null||l(B),c==null||c(B),B.defaultPrevented||A==null||A())},O);return yP(B=>{N===x.layers.size-1&&(a==null||a(B),!B.defaultPrevented&&A&&(B.preventDefault(),A()))},O),p.useEffect(()=>{if(h)return n&&(x.layersWithOutsidePointerEventsDisabled.size===0&&(Kw=O.body.style.pointerEvents,O.body.style.pointerEvents="none"),x.layersWithOutsidePointerEventsDisabled.add(h)),x.layers.add(h),qw(),()=>{n&&x.layersWithOutsidePointerEventsDisabled.size===1&&(O.body.style.pointerEvents=Kw)}},[h,O,n,x]),p.useEffect(()=>()=>{h&&(x.layers.delete(h),x.layersWithOutsidePointerEventsDisabled.delete(h),qw())},[h,x]),p.useEffect(()=>{const B=()=>b({});return document.addEventListener(aO,B),()=>document.removeEventListener(aO,B)},[]),e.jsx(et.div,{...f,ref:v,style:{pointerEvents:C?U?"auto":"none":void 0,...t.style},onFocusCapture:Ue(t.onFocusCapture,T.onFocusCapture),onBlurCapture:Ue(t.onBlurCapture,T.onBlurCapture),onPointerDownCapture:Ue(t.onPointerDownCapture,P.onPointerDownCapture)})});Ad.displayName=wP;var NP="DismissableLayerBranch",SP=p.forwardRef((t,s)=>{const n=p.useContext(RN),a=p.useRef(null),r=mt(s,a);return p.useEffect(()=>{const l=a.current;if(l)return n.branches.add(l),()=>{n.branches.delete(l)}},[n.branches]),e.jsx(et.div,{...t,ref:r})});SP.displayName=NP;function CP(t,s=globalThis==null?void 0:globalThis.document){const n=Us(t),a=p.useRef(!1),r=p.useRef(()=>{});return p.useEffect(()=>{const l=A=>{if(A.target&&!a.current){let f=function(){MN(jP,n,x,{discrete:!0})};const x={originalEvent:A};A.pointerType==="touch"?(s.removeEventListener("click",r.current),r.current=f,s.addEventListener("click",r.current,{once:!0})):f()}else s.removeEventListener("click",r.current);a.current=!1},c=window.setTimeout(()=>{s.addEventListener("pointerdown",l)},0);return()=>{window.clearTimeout(c),s.removeEventListener("pointerdown",l),s.removeEventListener("click",r.current)}},[s,n]),{onPointerDownCapture:()=>a.current=!0}}function BP(t,s=globalThis==null?void 0:globalThis.document){const n=Us(t),a=p.useRef(!1);return p.useEffect(()=>{const r=l=>{l.target&&!a.current&&MN(QP,n,{originalEvent:l},{discrete:!1})};return s.addEventListener("focusin",r),()=>s.removeEventListener("focusin",r)},[s,n]),{onFocusCapture:()=>a.current=!0,onBlurCapture:()=>a.current=!1}}function qw(){const t=new CustomEvent(aO);document.dispatchEvent(t)}function MN(t,s,n,{discrete:a}){const r=n.originalEvent.target,l=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});s&&r.addEventListener(t,s,{once:!0}),a?$N(r,l):r.dispatchEvent(l)}var Ds=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},kP=oN[" useId ".trim().toString()]||(()=>{}),TP=0;function $r(t){const[s,n]=p.useState(kP());return Ds(()=>{n(a=>a??String(TP++))},[t]),s?`radix-${s}`:""}const UP=["top","right","bottom","left"],Fo=Math.min,$n=Math.max,tx=Math.round,zu=Math.floor,Xa=t=>({x:t,y:t}),EP={left:"right",right:"left",bottom:"top",top:"bottom"};function rO(t,s,n){return $n(t,Fo(s,n))}function Ir(t,s){return typeof t=="function"?t(s):t}function zr(t){return t.split("-")[0]}function xc(t){return t.split("-")[1]}function hb(t){return t==="x"?"y":"x"}function pb(t){return t==="y"?"height":"width"}function La(t){const s=t[0];return s==="t"||s==="b"?"y":"x"}function gb(t){return hb(La(t))}function PP(t,s,n){n===void 0&&(n=!1);const a=xc(t),r=gb(t),l=pb(r);let c=r==="x"?a===(n?"end":"start")?"right":"left":a==="start"?"bottom":"top";return s.reference[l]>s.floating[l]&&(c=sx(c)),[c,sx(c)]}function FP(t){const s=sx(t);return[oO(t),s,oO(s)]}function oO(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const Ww=["left","right"],Yw=["right","left"],$P=["top","bottom"],RP=["bottom","top"];function MP(t,s,n){switch(t){case"top":case"bottom":return n?s?Yw:Ww:s?Ww:Yw;case"left":case"right":return s?$P:RP;default:return[]}}function IP(t,s,n,a){const r=xc(t);let l=MP(zr(t),n==="start",a);return r&&(l=l.map(c=>c+"-"+r),s&&(l=l.concat(l.map(oO)))),l}function sx(t){const s=zr(t);return EP[s]+t.slice(s.length)}function zP(t){return{top:0,right:0,bottom:0,left:0,...t}}function IN(t){return typeof t!="number"?zP(t):{top:t,right:t,bottom:t,left:t}}function nx(t){const{x:s,y:n,width:a,height:r}=t;return{width:a,height:r,top:n,left:s,right:s+a,bottom:n+r,x:s,y:n}}function Jw(t,s,n){let{reference:a,floating:r}=t;const l=La(s),c=gb(s),A=pb(c),f=zr(s),x=l==="y",h=a.x+a.width/2-r.width/2,g=a.y+a.height/2-r.height/2,O=a[A]/2-r[A]/2;let b;switch(f){case"top":b={x:h,y:a.y-r.height};break;case"bottom":b={x:h,y:a.y+a.height};break;case"right":b={x:a.x+a.width,y:g};break;case"left":b={x:a.x-r.width,y:g};break;default:b={x:a.x,y:a.y}}switch(xc(s)){case"start":b[c]-=O*(n&&x?-1:1);break;case"end":b[c]+=O*(n&&x?-1:1);break}return b}async function _P(t,s){var n;s===void 0&&(s={});const{x:a,y:r,platform:l,rects:c,elements:A,strategy:f}=t,{boundary:x="clippingAncestors",rootBoundary:h="viewport",elementContext:g="floating",altBoundary:O=!1,padding:b=0}=Ir(s,t),v=IN(b),S=A[O?g==="floating"?"reference":"floating":g],j=nx(await l.getClippingRect({element:(n=await(l.isElement==null?void 0:l.isElement(S)))==null||n?S:S.contextElement||await(l.getDocumentElement==null?void 0:l.getDocumentElement(A.floating)),boundary:x,rootBoundary:h,strategy:f})),N=g==="floating"?{x:a,y:r,width:c.floating.width,height:c.floating.height}:c.reference,C=await(l.getOffsetParent==null?void 0:l.getOffsetParent(A.floating)),U=await(l.isElement==null?void 0:l.isElement(C))?await(l.getScale==null?void 0:l.getScale(C))||{x:1,y:1}:{x:1,y:1},P=nx(l.convertOffsetParentRelativeRectToViewportRelativeRect?await l.convertOffsetParentRelativeRectToViewportRelativeRect({elements:A,rect:N,offsetParent:C,strategy:f}):N);return{top:(j.top-P.top+v.top)/U.y,bottom:(P.bottom-j.bottom+v.bottom)/U.y,left:(j.left-P.left+v.left)/U.x,right:(P.right-j.right+v.right)/U.x}}const DP=50,LP=async(t,s,n)=>{const{placement:a="bottom",strategy:r="absolute",middleware:l=[],platform:c}=n,A=c.detectOverflow?c:{...c,detectOverflow:_P},f=await(c.isRTL==null?void 0:c.isRTL(s));let x=await c.getElementRects({reference:t,floating:s,strategy:r}),{x:h,y:g}=Jw(x,a,f),O=a,b=0;const v={};for(let y=0;y<l.length;y++){const S=l[y];if(!S)continue;const{name:j,fn:N}=S,{x:C,y:U,data:P,reset:T}=await N({x:h,y:g,initialPlacement:a,placement:O,strategy:r,middlewareData:v,rects:x,platform:A,elements:{reference:t,floating:s}});h=C??h,g=U??g,v[j]={...v[j],...P},T&&b<DP&&(b++,typeof T=="object"&&(T.placement&&(O=T.placement),T.rects&&(x=T.rects===!0?await c.getElementRects({reference:t,floating:s,strategy:r}):T.rects),{x:h,y:g}=Jw(x,O,f)),y=-1)}return{x:h,y:g,placement:O,strategy:r,middlewareData:v}},HP=t=>({name:"arrow",options:t,async fn(s){const{x:n,y:a,placement:r,rects:l,platform:c,elements:A,middlewareData:f}=s,{element:x,padding:h=0}=Ir(t,s)||{};if(x==null)return{};const g=IN(h),O={x:n,y:a},b=gb(r),v=pb(b),y=await c.getDimensions(x),S=b==="y",j=S?"top":"left",N=S?"bottom":"right",C=S?"clientHeight":"clientWidth",U=l.reference[v]+l.reference[b]-O[b]-l.floating[v],P=O[b]-l.reference[b],T=await(c.getOffsetParent==null?void 0:c.getOffsetParent(x));let B=T?T[C]:0;(!B||!await(c.isElement==null?void 0:c.isElement(T)))&&(B=A.floating[C]||l.floating[v]);const F=U/2-P/2,M=B/2-y[v]/2-1,R=Fo(g[j],M),Y=Fo(g[N],M),W=R,ee=B-y[v]-Y,K=B/2-y[v]/2+F,_=rO(W,K,ee),E=!f.arrow&&xc(r)!=null&&K!==_&&l.reference[v]/2-(K<W?R:Y)-y[v]/2<0,q=E?K<W?K-W:K-ee:0;return{[b]:O[b]+q,data:{[b]:_,centerOffset:K-_-q,...E&&{alignmentOffset:q}},reset:E}}}),XP=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(s){var n,a;const{placement:r,middlewareData:l,rects:c,initialPlacement:A,platform:f,elements:x}=s,{mainAxis:h=!0,crossAxis:g=!0,fallbackPlacements:O,fallbackStrategy:b="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:y=!0,...S}=Ir(t,s);if((n=l.arrow)!=null&&n.alignmentOffset)return{};const j=zr(r),N=La(A),C=zr(A)===A,U=await(f.isRTL==null?void 0:f.isRTL(x.floating)),P=O||(C||!y?[sx(A)]:FP(A)),T=v!=="none";!O&&T&&P.push(...IP(A,y,v,U));const B=[A,...P],F=await f.detectOverflow(s,S),M=[];let R=((a=l.flip)==null?void 0:a.overflows)||[];if(h&&M.push(F[j]),g){const K=PP(r,c,U);M.push(F[K[0]],F[K[1]])}if(R=[...R,{placement:r,overflows:M}],!M.every(K=>K<=0)){var Y,W;const K=(((Y=l.flip)==null?void 0:Y.index)||0)+1,_=B[K];if(_&&(!(g==="alignment"?N!==La(_):!1)||R.every(H=>La(H.placement)===N?H.overflows[0]>0:!0)))return{data:{index:K,overflows:R},reset:{placement:_}};let E=(W=R.filter(q=>q.overflows[0]<=0).sort((q,H)=>q.overflows[1]-H.overflows[1])[0])==null?void 0:W.placement;if(!E)switch(b){case"bestFit":{var ee;const q=(ee=R.filter(H=>{if(T){const I=La(H.placement);return I===N||I==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(I=>I>0).reduce((I,L)=>I+L,0)]).sort((H,I)=>H[1]-I[1])[0])==null?void 0:ee[0];q&&(E=q);break}case"initialPlacement":E=A;break}if(r!==E)return{reset:{placement:E}}}return{}}}};function ej(t,s){return{top:t.top-s.height,right:t.right-s.width,bottom:t.bottom-s.height,left:t.left-s.width}}function tj(t){return UP.some(s=>t[s]>=0)}const GP=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(s){const{rects:n,platform:a}=s,{strategy:r="referenceHidden",...l}=Ir(t,s);switch(r){case"referenceHidden":{const c=await a.detectOverflow(s,{...l,elementContext:"reference"}),A=ej(c,n.reference);return{data:{referenceHiddenOffsets:A,referenceHidden:tj(A)}}}case"escaped":{const c=await a.detectOverflow(s,{...l,altBoundary:!0}),A=ej(c,n.floating);return{data:{escapedOffsets:A,escaped:tj(A)}}}default:return{}}}}},zN=new Set(["left","top"]);async function ZP(t,s){const{placement:n,platform:a,elements:r}=t,l=await(a.isRTL==null?void 0:a.isRTL(r.floating)),c=zr(n),A=xc(n),f=La(n)==="y",x=zN.has(c)?-1:1,h=l&&f?-1:1,g=Ir(s,t);let{mainAxis:O,crossAxis:b,alignmentAxis:v}=typeof g=="number"?{mainAxis:g,crossAxis:0,alignmentAxis:null}:{mainAxis:g.mainAxis||0,crossAxis:g.crossAxis||0,alignmentAxis:g.alignmentAxis};return A&&typeof v=="number"&&(b=A==="end"?v*-1:v),f?{x:b*h,y:O*x}:{x:O*x,y:b*h}}const VP=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(s){var n,a;const{x:r,y:l,placement:c,middlewareData:A}=s,f=await ZP(s,t);return c===((n=A.offset)==null?void 0:n.placement)&&(a=A.arrow)!=null&&a.alignmentOffset?{}:{x:r+f.x,y:l+f.y,data:{...f,placement:c}}}}},KP=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(s){const{x:n,y:a,placement:r,platform:l}=s,{mainAxis:c=!0,crossAxis:A=!1,limiter:f={fn:j=>{let{x:N,y:C}=j;return{x:N,y:C}}},...x}=Ir(t,s),h={x:n,y:a},g=await l.detectOverflow(s,x),O=La(zr(r)),b=hb(O);let v=h[b],y=h[O];if(c){const j=b==="y"?"top":"left",N=b==="y"?"bottom":"right",C=v+g[j],U=v-g[N];v=rO(C,v,U)}if(A){const j=O==="y"?"top":"left",N=O==="y"?"bottom":"right",C=y+g[j],U=y-g[N];y=rO(C,y,U)}const S=f.fn({...s,[b]:v,[O]:y});return{...S,data:{x:S.x-n,y:S.y-a,enabled:{[b]:c,[O]:A}}}}}},qP=function(t){return t===void 0&&(t={}),{options:t,fn(s){const{x:n,y:a,placement:r,rects:l,middlewareData:c}=s,{offset:A=0,mainAxis:f=!0,crossAxis:x=!0}=Ir(t,s),h={x:n,y:a},g=La(r),O=hb(g);let b=h[O],v=h[g];const y=Ir(A,s),S=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(f){const C=O==="y"?"height":"width",U=l.reference[O]-l.floating[C]+S.mainAxis,P=l.reference[O]+l.reference[C]-S.mainAxis;b<U?b=U:b>P&&(b=P)}if(x){var j,N;const C=O==="y"?"width":"height",U=zN.has(zr(r)),P=l.reference[g]-l.floating[C]+(U&&((j=c.offset)==null?void 0:j[g])||0)+(U?0:S.crossAxis),T=l.reference[g]+l.reference[C]+(U?0:((N=c.offset)==null?void 0:N[g])||0)-(U?S.crossAxis:0);v<P?v=P:v>T&&(v=T)}return{[O]:b,[g]:v}}}},WP=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(s){var n,a;const{placement:r,rects:l,platform:c,elements:A}=s,{apply:f=()=>{},...x}=Ir(t,s),h=await c.detectOverflow(s,x),g=zr(r),O=xc(r),b=La(r)==="y",{width:v,height:y}=l.floating;let S,j;g==="top"||g==="bottom"?(S=g,j=O===(await(c.isRTL==null?void 0:c.isRTL(A.floating))?"start":"end")?"left":"right"):(j=g,S=O==="end"?"top":"bottom");const N=y-h.top-h.bottom,C=v-h.left-h.right,U=Fo(y-h[S],N),P=Fo(v-h[j],C),T=!s.middlewareData.shift;let B=U,F=P;if((n=s.middlewareData.shift)!=null&&n.enabled.x&&(F=C),(a=s.middlewareData.shift)!=null&&a.enabled.y&&(B=N),T&&!O){const R=$n(h.left,0),Y=$n(h.right,0),W=$n(h.top,0),ee=$n(h.bottom,0);b?F=v-2*(R!==0||Y!==0?R+Y:$n(h.left,h.right)):B=y-2*(W!==0||ee!==0?W+ee:$n(h.top,h.bottom))}await f({...s,availableWidth:F,availableHeight:B});const M=await c.getDimensions(A.floating);return v!==M.width||y!==M.height?{reset:{rects:!0}}:{}}}};function Rx(){return typeof window<"u"}function mc(t){return _N(t)?(t.nodeName||"").toLowerCase():"#document"}function zn(t){var s;return(t==null||(s=t.ownerDocument)==null?void 0:s.defaultView)||window}function Ja(t){var s;return(s=(_N(t)?t.ownerDocument:t.document)||window.document)==null?void 0:s.documentElement}function _N(t){return Rx()?t instanceof Node||t instanceof zn(t).Node:!1}function Sa(t){return Rx()?t instanceof Element||t instanceof zn(t).Element:!1}function Lr(t){return Rx()?t instanceof HTMLElement||t instanceof zn(t).HTMLElement:!1}function sj(t){return!Rx()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof zn(t).ShadowRoot}function dd(t){const{overflow:s,overflowX:n,overflowY:a,display:r}=Ca(t);return/auto|scroll|overlay|hidden|clip/.test(s+a+n)&&r!=="inline"&&r!=="contents"}function YP(t){return/^(table|td|th)$/.test(mc(t))}function Mx(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}const JP=/transform|translate|scale|rotate|perspective|filter/,eF=/paint|layout|strict|content/,hi=t=>!!t&&t!=="none";let Ip;function Ob(t){const s=Sa(t)?Ca(t):t;return hi(s.transform)||hi(s.translate)||hi(s.scale)||hi(s.rotate)||hi(s.perspective)||!bb()&&(hi(s.backdropFilter)||hi(s.filter))||JP.test(s.willChange||"")||eF.test(s.contain||"")}function tF(t){let s=$o(t);for(;Lr(s)&&!tc(s);){if(Ob(s))return s;if(Mx(s))return null;s=$o(s)}return null}function bb(){return Ip==null&&(Ip=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Ip}function tc(t){return/^(html|body|#document)$/.test(mc(t))}function Ca(t){return zn(t).getComputedStyle(t)}function Ix(t){return Sa(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function $o(t){if(mc(t)==="html")return t;const s=t.assignedSlot||t.parentNode||sj(t)&&t.host||Ja(t);return sj(s)?s.host:s}function DN(t){const s=$o(t);return tc(s)?t.ownerDocument?t.ownerDocument.body:t.body:Lr(s)&&dd(s)?s:DN(s)}function ZA(t,s,n){var a;s===void 0&&(s=[]),n===void 0&&(n=!0);const r=DN(t),l=r===((a=t.ownerDocument)==null?void 0:a.body),c=zn(r);if(l){const A=iO(c);return s.concat(c,c.visualViewport||[],dd(r)?r:[],A&&n?ZA(A):[])}else return s.concat(r,ZA(r,[],n))}function iO(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function LN(t){const s=Ca(t);let n=parseFloat(s.width)||0,a=parseFloat(s.height)||0;const r=Lr(t),l=r?t.offsetWidth:n,c=r?t.offsetHeight:a,A=tx(n)!==l||tx(a)!==c;return A&&(n=l,a=c),{width:n,height:a,$:A}}function vb(t){return Sa(t)?t:t.contextElement}function Zl(t){const s=vb(t);if(!Lr(s))return Xa(1);const n=s.getBoundingClientRect(),{width:a,height:r,$:l}=LN(s);let c=(l?tx(n.width):n.width)/a,A=(l?tx(n.height):n.height)/r;return(!c||!Number.isFinite(c))&&(c=1),(!A||!Number.isFinite(A))&&(A=1),{x:c,y:A}}const sF=Xa(0);function HN(t){const s=zn(t);return!bb()||!s.visualViewport?sF:{x:s.visualViewport.offsetLeft,y:s.visualViewport.offsetTop}}function nF(t,s,n){return s===void 0&&(s=!1),!n||s&&n!==zn(t)?!1:s}function Ci(t,s,n,a){s===void 0&&(s=!1),n===void 0&&(n=!1);const r=t.getBoundingClientRect(),l=vb(t);let c=Xa(1);s&&(a?Sa(a)&&(c=Zl(a)):c=Zl(t));const A=nF(l,n,a)?HN(l):Xa(0);let f=(r.left+A.x)/c.x,x=(r.top+A.y)/c.y,h=r.width/c.x,g=r.height/c.y;if(l){const O=zn(l),b=a&&Sa(a)?zn(a):a;let v=O,y=iO(v);for(;y&&a&&b!==v;){const S=Zl(y),j=y.getBoundingClientRect(),N=Ca(y),C=j.left+(y.clientLeft+parseFloat(N.paddingLeft))*S.x,U=j.top+(y.clientTop+parseFloat(N.paddingTop))*S.y;f*=S.x,x*=S.y,h*=S.x,g*=S.y,f+=C,x+=U,v=zn(y),y=iO(v)}}return nx({width:h,height:g,x:f,y:x})}function zx(t,s){const n=Ix(t).scrollLeft;return s?s.left+n:Ci(Ja(t)).left+n}function XN(t,s){const n=t.getBoundingClientRect(),a=n.left+s.scrollLeft-zx(t,n),r=n.top+s.scrollTop;return{x:a,y:r}}function aF(t){let{elements:s,rect:n,offsetParent:a,strategy:r}=t;const l=r==="fixed",c=Ja(a),A=s?Mx(s.floating):!1;if(a===c||A&&l)return n;let f={scrollLeft:0,scrollTop:0},x=Xa(1);const h=Xa(0),g=Lr(a);if((g||!g&&!l)&&((mc(a)!=="body"||dd(c))&&(f=Ix(a)),g)){const b=Ci(a);x=Zl(a),h.x=b.x+a.clientLeft,h.y=b.y+a.clientTop}const O=c&&!g&&!l?XN(c,f):Xa(0);return{width:n.width*x.x,height:n.height*x.y,x:n.x*x.x-f.scrollLeft*x.x+h.x+O.x,y:n.y*x.y-f.scrollTop*x.y+h.y+O.y}}function rF(t){return Array.from(t.getClientRects())}function oF(t){const s=Ja(t),n=Ix(t),a=t.ownerDocument.body,r=$n(s.scrollWidth,s.clientWidth,a.scrollWidth,a.clientWidth),l=$n(s.scrollHeight,s.clientHeight,a.scrollHeight,a.clientHeight);let c=-n.scrollLeft+zx(t);const A=-n.scrollTop;return Ca(a).direction==="rtl"&&(c+=$n(s.clientWidth,a.clientWidth)-r),{width:r,height:l,x:c,y:A}}const nj=25;function iF(t,s){const n=zn(t),a=Ja(t),r=n.visualViewport;let l=a.clientWidth,c=a.clientHeight,A=0,f=0;if(r){l=r.width,c=r.height;const h=bb();(!h||h&&s==="fixed")&&(A=r.offsetLeft,f=r.offsetTop)}const x=zx(a);if(x<=0){const h=a.ownerDocument,g=h.body,O=getComputedStyle(g),b=h.compatMode==="CSS1Compat"&&parseFloat(O.marginLeft)+parseFloat(O.marginRight)||0,v=Math.abs(a.clientWidth-g.clientWidth-b);v<=nj&&(l-=v)}else x<=nj&&(l+=x);return{width:l,height:c,x:A,y:f}}function lF(t,s){const n=Ci(t,!0,s==="fixed"),a=n.top+t.clientTop,r=n.left+t.clientLeft,l=Lr(t)?Zl(t):Xa(1),c=t.clientWidth*l.x,A=t.clientHeight*l.y,f=r*l.x,x=a*l.y;return{width:c,height:A,x:f,y:x}}function aj(t,s,n){let a;if(s==="viewport")a=iF(t,n);else if(s==="document")a=oF(Ja(t));else if(Sa(s))a=lF(s,n);else{const r=HN(t);a={x:s.x-r.x,y:s.y-r.y,width:s.width,height:s.height}}return nx(a)}function GN(t,s){const n=$o(t);return n===s||!Sa(n)||tc(n)?!1:Ca(n).position==="fixed"||GN(n,s)}function cF(t,s){const n=s.get(t);if(n)return n;let a=ZA(t,[],!1).filter(A=>Sa(A)&&mc(A)!=="body"),r=null;const l=Ca(t).position==="fixed";let c=l?$o(t):t;for(;Sa(c)&&!tc(c);){const A=Ca(c),f=Ob(c);!f&&A.position==="fixed"&&(r=null),(l?!f&&!r:!f&&A.position==="static"&&!!r&&(r.position==="absolute"||r.position==="fixed")||dd(c)&&!f&&GN(t,c))?a=a.filter(h=>h!==c):r=A,c=$o(c)}return s.set(t,a),a}function AF(t){let{element:s,boundary:n,rootBoundary:a,strategy:r}=t;const c=[...n==="clippingAncestors"?Mx(s)?[]:cF(s,this._c):[].concat(n),a],A=aj(s,c[0],r);let f=A.top,x=A.right,h=A.bottom,g=A.left;for(let O=1;O<c.length;O++){const b=aj(s,c[O],r);f=$n(b.top,f),x=Fo(b.right,x),h=Fo(b.bottom,h),g=$n(b.left,g)}return{width:x-g,height:h-f,x:g,y:f}}function dF(t){const{width:s,height:n}=LN(t);return{width:s,height:n}}function uF(t,s,n){const a=Lr(s),r=Ja(s),l=n==="fixed",c=Ci(t,!0,l,s);let A={scrollLeft:0,scrollTop:0};const f=Xa(0);function x(){f.x=zx(r)}if(a||!a&&!l)if((mc(s)!=="body"||dd(r))&&(A=Ix(s)),a){const b=Ci(s,!0,l,s);f.x=b.x+s.clientLeft,f.y=b.y+s.clientTop}else r&&x();l&&!a&&r&&x();const h=r&&!a&&!l?XN(r,A):Xa(0),g=c.left+A.scrollLeft-f.x-h.x,O=c.top+A.scrollTop-f.y-h.y;return{x:g,y:O,width:c.width,height:c.height}}function zp(t){return Ca(t).position==="static"}function rj(t,s){if(!Lr(t)||Ca(t).position==="fixed")return null;if(s)return s(t);let n=t.offsetParent;return Ja(t)===n&&(n=n.ownerDocument.body),n}function ZN(t,s){const n=zn(t);if(Mx(t))return n;if(!Lr(t)){let r=$o(t);for(;r&&!tc(r);){if(Sa(r)&&!zp(r))return r;r=$o(r)}return n}let a=rj(t,s);for(;a&&YP(a)&&zp(a);)a=rj(a,s);return a&&tc(a)&&zp(a)&&!Ob(a)?n:a||tF(t)||n}const fF=async function(t){const s=this.getOffsetParent||ZN,n=this.getDimensions,a=await n(t.floating);return{reference:uF(t.reference,await s(t.floating),t.strategy),floating:{x:0,y:0,width:a.width,height:a.height}}};function xF(t){return Ca(t).direction==="rtl"}const mF={convertOffsetParentRelativeRectToViewportRelativeRect:aF,getDocumentElement:Ja,getClippingRect:AF,getOffsetParent:ZN,getElementRects:fF,getClientRects:rF,getDimensions:dF,getScale:Zl,isElement:Sa,isRTL:xF};function VN(t,s){return t.x===s.x&&t.y===s.y&&t.width===s.width&&t.height===s.height}function hF(t,s){let n=null,a;const r=Ja(t);function l(){var A;clearTimeout(a),(A=n)==null||A.disconnect(),n=null}function c(A,f){A===void 0&&(A=!1),f===void 0&&(f=1),l();const x=t.getBoundingClientRect(),{left:h,top:g,width:O,height:b}=x;if(A||s(),!O||!b)return;const v=zu(g),y=zu(r.clientWidth-(h+O)),S=zu(r.clientHeight-(g+b)),j=zu(h),C={rootMargin:-v+"px "+-y+"px "+-S+"px "+-j+"px",threshold:$n(0,Fo(1,f))||1};let U=!0;function P(T){const B=T[0].intersectionRatio;if(B!==f){if(!U)return c();B?c(!1,B):a=setTimeout(()=>{c(!1,1e-7)},1e3)}B===1&&!VN(x,t.getBoundingClientRect())&&c(),U=!1}try{n=new IntersectionObserver(P,{...C,root:r.ownerDocument})}catch{n=new IntersectionObserver(P,C)}n.observe(t)}return c(!0),l}function pF(t,s,n,a){a===void 0&&(a={});const{ancestorScroll:r=!0,ancestorResize:l=!0,elementResize:c=typeof ResizeObserver=="function",layoutShift:A=typeof IntersectionObserver=="function",animationFrame:f=!1}=a,x=vb(t),h=r||l?[...x?ZA(x):[],...s?ZA(s):[]]:[];h.forEach(j=>{r&&j.addEventListener("scroll",n,{passive:!0}),l&&j.addEventListener("resize",n)});const g=x&&A?hF(x,n):null;let O=-1,b=null;c&&(b=new ResizeObserver(j=>{let[N]=j;N&&N.target===x&&b&&s&&(b.unobserve(s),cancelAnimationFrame(O),O=requestAnimationFrame(()=>{var C;(C=b)==null||C.observe(s)})),n()}),x&&!f&&b.observe(x),s&&b.observe(s));let v,y=f?Ci(t):null;f&&S();function S(){const j=Ci(t);y&&!VN(y,j)&&n(),y=j,v=requestAnimationFrame(S)}return n(),()=>{var j;h.forEach(N=>{r&&N.removeEventListener("scroll",n),l&&N.removeEventListener("resize",n)}),g==null||g(),(j=b)==null||j.disconnect(),b=null,f&&cancelAnimationFrame(v)}}const gF=VP,OF=KP,bF=XP,vF=WP,yF=GP,oj=HP,wF=qP,jF=(t,s,n)=>{const a=new Map,r={platform:mF,...n},l={...r.platform,_c:a};return LP(t,s,{...r,platform:l})};var QF=typeof document<"u",NF=function(){},Rf=QF?p.useLayoutEffect:NF;function ax(t,s){if(t===s)return!0;if(typeof t!=typeof s)return!1;if(typeof t=="function"&&t.toString()===s.toString())return!0;let n,a,r;if(t&&s&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==s.length)return!1;for(a=n;a--!==0;)if(!ax(t[a],s[a]))return!1;return!0}if(r=Object.keys(t),n=r.length,n!==Object.keys(s).length)return!1;for(a=n;a--!==0;)if(!{}.hasOwnProperty.call(s,r[a]))return!1;for(a=n;a--!==0;){const l=r[a];if(!(l==="_owner"&&t.$$typeof)&&!ax(t[l],s[l]))return!1}return!0}return t!==t&&s!==s}function KN(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function ij(t,s){const n=KN(t);return Math.round(s*n)/n}function _p(t){const s=p.useRef(t);return Rf(()=>{s.current=t}),s}function SF(t){t===void 0&&(t={});const{placement:s="bottom",strategy:n="absolute",middleware:a=[],platform:r,elements:{reference:l,floating:c}={},transform:A=!0,whileElementsMounted:f,open:x}=t,[h,g]=p.useState({x:0,y:0,strategy:n,placement:s,middlewareData:{},isPositioned:!1}),[O,b]=p.useState(a);ax(O,a)||b(a);const[v,y]=p.useState(null),[S,j]=p.useState(null),N=p.useCallback(H=>{H!==T.current&&(T.current=H,y(H))},[]),C=p.useCallback(H=>{H!==B.current&&(B.current=H,j(H))},[]),U=l||v,P=c||S,T=p.useRef(null),B=p.useRef(null),F=p.useRef(h),M=f!=null,R=_p(f),Y=_p(r),W=_p(x),ee=p.useCallback(()=>{if(!T.current||!B.current)return;const H={placement:s,strategy:n,middleware:O};Y.current&&(H.platform=Y.current),jF(T.current,B.current,H).then(I=>{const L={...I,isPositioned:W.current!==!1};K.current&&!ax(F.current,L)&&(F.current=L,Px.flushSync(()=>{g(L)}))})},[O,s,n,Y,W]);Rf(()=>{x===!1&&F.current.isPositioned&&(F.current.isPositioned=!1,g(H=>({...H,isPositioned:!1})))},[x]);const K=p.useRef(!1);Rf(()=>(K.current=!0,()=>{K.current=!1}),[]),Rf(()=>{if(U&&(T.current=U),P&&(B.current=P),U&&P){if(R.current)return R.current(U,P,ee);ee()}},[U,P,ee,R,M]);const _=p.useMemo(()=>({reference:T,floating:B,setReference:N,setFloating:C}),[N,C]),E=p.useMemo(()=>({reference:U,floating:P}),[U,P]),q=p.useMemo(()=>{const H={position:n,left:0,top:0};if(!E.floating)return H;const I=ij(E.floating,h.x),L=ij(E.floating,h.y);return A?{...H,transform:"translate("+I+"px, "+L+"px)",...KN(E.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:I,top:L}},[n,A,E.floating,h.x,h.y]);return p.useMemo(()=>({...h,update:ee,refs:_,elements:E,floatingStyles:q}),[h,ee,_,E,q])}const CF=t=>{function s(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:a,padding:r}=typeof t=="function"?t(n):t;return a&&s(a)?a.current!=null?oj({element:a.current,padding:r}).fn(n):{}:a?oj({element:a,padding:r}).fn(n):{}}}},BF=(t,s)=>{const n=gF(t);return{name:n.name,fn:n.fn,options:[t,s]}},kF=(t,s)=>{const n=OF(t);return{name:n.name,fn:n.fn,options:[t,s]}},TF=(t,s)=>({fn:wF(t).fn,options:[t,s]}),UF=(t,s)=>{const n=bF(t);return{name:n.name,fn:n.fn,options:[t,s]}},EF=(t,s)=>{const n=vF(t);return{name:n.name,fn:n.fn,options:[t,s]}},PF=(t,s)=>{const n=yF(t);return{name:n.name,fn:n.fn,options:[t,s]}},FF=(t,s)=>{const n=CF(t);return{name:n.name,fn:n.fn,options:[t,s]}};var $F="Arrow",qN=p.forwardRef((t,s)=>{const{children:n,width:a=10,height:r=5,...l}=t;return e.jsx(et.svg,{...l,ref:s,width:a,height:r,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:e.jsx("polygon",{points:"0,0 30,0 15,10"})})});qN.displayName=$F;var RF=qN;function MF(t){const[s,n]=p.useState(void 0);return Ds(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const a=new ResizeObserver(r=>{if(!Array.isArray(r)||!r.length)return;const l=r[0];let c,A;if("borderBoxSize"in l){const f=l.borderBoxSize,x=Array.isArray(f)?f[0]:f;c=x.inlineSize,A=x.blockSize}else c=t.offsetWidth,A=t.offsetHeight;n({width:c,height:A})});return a.observe(t,{box:"border-box"}),()=>a.unobserve(t)}else n(void 0)},[t]),s}var yb="Popper",[WN,hc]=Ya(yb),[IF,YN]=WN(yb),JN=t=>{const{__scopePopper:s,children:n}=t,[a,r]=p.useState(null);return e.jsx(IF,{scope:s,anchor:a,onAnchorChange:r,children:n})};JN.displayName=yb;var eS="PopperAnchor",tS=p.forwardRef((t,s)=>{const{__scopePopper:n,virtualRef:a,...r}=t,l=YN(eS,n),c=p.useRef(null),A=mt(s,c),f=p.useRef(null);return p.useEffect(()=>{const x=f.current;f.current=(a==null?void 0:a.current)||c.current,x!==f.current&&l.onAnchorChange(f.current)}),a?null:e.jsx(et.div,{...r,ref:A})});tS.displayName=eS;var wb="PopperContent",[zF,_F]=WN(wb),sS=p.forwardRef((t,s)=>{var ae,be,z,oe,ue,ve;const{__scopePopper:n,side:a="bottom",sideOffset:r=0,align:l="center",alignOffset:c=0,arrowPadding:A=0,avoidCollisions:f=!0,collisionBoundary:x=[],collisionPadding:h=0,sticky:g="partial",hideWhenDetached:O=!1,updatePositionStrategy:b="optimized",onPlaced:v,...y}=t,S=YN(wb,n),[j,N]=p.useState(null),C=mt(s,Ce=>N(Ce)),[U,P]=p.useState(null),T=MF(U),B=(T==null?void 0:T.width)??0,F=(T==null?void 0:T.height)??0,M=a+(l!=="center"?"-"+l:""),R=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},Y=Array.isArray(x)?x:[x],W=Y.length>0,ee={padding:R,boundary:Y.filter(LF),altBoundary:W},{refs:K,floatingStyles:_,placement:E,isPositioned:q,middlewareData:H}=SF({strategy:"fixed",placement:M,whileElementsMounted:(...Ce)=>pF(...Ce,{animationFrame:b==="always"}),elements:{reference:S.anchor},middleware:[BF({mainAxis:r+F,alignmentAxis:c}),f&&kF({mainAxis:!0,crossAxis:!1,limiter:g==="partial"?TF():void 0,...ee}),f&&UF({...ee}),EF({...ee,apply:({elements:Ce,rects:Ne,availableWidth:Xe,availableHeight:Fe})=>{const{width:Ae,height:ke}=Ne.reference,Re=Ce.floating.style;Re.setProperty("--radix-popper-available-width",`${Xe}px`),Re.setProperty("--radix-popper-available-height",`${Fe}px`),Re.setProperty("--radix-popper-anchor-width",`${Ae}px`),Re.setProperty("--radix-popper-anchor-height",`${ke}px`)}}),U&&FF({element:U,padding:A}),HF({arrowWidth:B,arrowHeight:F}),O&&PF({strategy:"referenceHidden",...ee})]}),[I,L]=rS(E),J=Us(v);Ds(()=>{q&&(J==null||J())},[q,J]);const D=(ae=H.arrow)==null?void 0:ae.x,se=(be=H.arrow)==null?void 0:be.y,le=((z=H.arrow)==null?void 0:z.centerOffset)!==0,[V,te]=p.useState();return Ds(()=>{j&&te(window.getComputedStyle(j).zIndex)},[j]),e.jsx("div",{ref:K.setFloating,"data-radix-popper-content-wrapper":"",style:{..._,transform:q?_.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:V,"--radix-popper-transform-origin":[(oe=H.transformOrigin)==null?void 0:oe.x,(ue=H.transformOrigin)==null?void 0:ue.y].join(" "),...((ve=H.hide)==null?void 0:ve.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:e.jsx(zF,{scope:n,placedSide:I,onArrowChange:P,arrowX:D,arrowY:se,shouldHideArrow:le,children:e.jsx(et.div,{"data-side":I,"data-align":L,...y,ref:C,style:{...y.style,animation:q?void 0:"none"}})})})});sS.displayName=wb;var nS="PopperArrow",DF={top:"bottom",right:"left",bottom:"top",left:"right"},aS=p.forwardRef(function(s,n){const{__scopePopper:a,...r}=s,l=_F(nS,a),c=DF[l.placedSide];return e.jsx("span",{ref:l.onArrowChange,style:{position:"absolute",left:l.arrowX,top:l.arrowY,[c]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[l.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[l.placedSide],visibility:l.shouldHideArrow?"hidden":void 0},children:e.jsx(RF,{...r,ref:n,style:{...r.style,display:"block"}})})});aS.displayName=nS;function LF(t){return t!==null}var HF=t=>({name:"transformOrigin",options:t,fn(s){var S,j,N;const{placement:n,rects:a,middlewareData:r}=s,c=((S=r.arrow)==null?void 0:S.centerOffset)!==0,A=c?0:t.arrowWidth,f=c?0:t.arrowHeight,[x,h]=rS(n),g={start:"0%",center:"50%",end:"100%"}[h],O=(((j=r.arrow)==null?void 0:j.x)??0)+A/2,b=(((N=r.arrow)==null?void 0:N.y)??0)+f/2;let v="",y="";return x==="bottom"?(v=c?g:`${O}px`,y=`${-f}px`):x==="top"?(v=c?g:`${O}px`,y=`${a.floating.height+f}px`):x==="right"?(v=`${-f}px`,y=c?g:`${b}px`):x==="left"&&(v=`${a.floating.width+f}px`,y=c?g:`${b}px`),{data:{x:v,y}}}});function rS(t){const[s,n="center"]=t.split("-");return[s,n]}var jb=JN,Qb=tS,Nb=sS,Sb=aS,XF="Portal",ud=p.forwardRef((t,s)=>{var A;const{container:n,...a}=t,[r,l]=p.useState(!1);Ds(()=>l(!0),[]);const c=n||r&&((A=globalThis==null?void 0:globalThis.document)==null?void 0:A.body);return c?SU.createPortal(e.jsx(et.div,{...a,ref:s}),c):null});ud.displayName=XF;function GF(t,s){return p.useReducer((n,a)=>s[n][a]??n,t)}var ln=t=>{const{present:s,children:n}=t,a=ZF(s),r=typeof n=="function"?n({present:a.isPresent}):p.Children.only(n),l=mt(a.ref,VF(r));return typeof n=="function"||a.isPresent?p.cloneElement(r,{ref:l}):null};ln.displayName="Presence";function ZF(t){const[s,n]=p.useState(),a=p.useRef(null),r=p.useRef(t),l=p.useRef("none"),c=t?"mounted":"unmounted",[A,f]=GF(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const x=_u(a.current);l.current=A==="mounted"?x:"none"},[A]),Ds(()=>{const x=a.current,h=r.current;if(h!==t){const O=l.current,b=_u(x);t?f("MOUNT"):b==="none"||(x==null?void 0:x.display)==="none"?f("UNMOUNT"):f(h&&O!==b?"ANIMATION_OUT":"UNMOUNT"),r.current=t}},[t,f]),Ds(()=>{if(s){let x;const h=s.ownerDocument.defaultView??window,g=b=>{const y=_u(a.current).includes(CSS.escape(b.animationName));if(b.target===s&&y&&(f("ANIMATION_END"),!r.current)){const S=s.style.animationFillMode;s.style.animationFillMode="forwards",x=h.setTimeout(()=>{s.style.animationFillMode==="forwards"&&(s.style.animationFillMode=S)})}},O=b=>{b.target===s&&(l.current=_u(a.current))};return s.addEventListener("animationstart",O),s.addEventListener("animationcancel",g),s.addEventListener("animationend",g),()=>{h.clearTimeout(x),s.removeEventListener("animationstart",O),s.removeEventListener("animationcancel",g),s.removeEventListener("animationend",g)}}else f("ANIMATION_END")},[s,f]),{isPresent:["mounted","unmountSuspended"].includes(A),ref:p.useCallback(x=>{a.current=x?getComputedStyle(x):null,n(x)},[])}}function _u(t){return(t==null?void 0:t.animationName)||"none"}function VF(t){var a,r;let s=(a=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:a.get,n=s&&"isReactWarning"in s&&s.isReactWarning;return n?t.ref:(s=(r=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:r.get,n=s&&"isReactWarning"in s&&s.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var KF=oN[" useInsertionEffect ".trim().toString()]||Ds;function sc({prop:t,defaultProp:s,onChange:n=()=>{},caller:a}){const[r,l,c]=qF({defaultProp:s,onChange:n}),A=t!==void 0,f=A?t:r;{const h=p.useRef(t!==void 0);p.useEffect(()=>{const g=h.current;g!==A&&console.warn(`${a} is changing from ${g?"controlled":"uncontrolled"} to ${A?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),h.current=A},[A,a])}const x=p.useCallback(h=>{var g;if(A){const O=WF(h)?h(t):h;O!==t&&((g=c.current)==null||g.call(c,O))}else l(h)},[A,t,l,c]);return[f,x]}function qF({defaultProp:t,onChange:s}){const[n,a]=p.useState(t),r=p.useRef(n),l=p.useRef(s);return KF(()=>{l.current=s},[s]),p.useEffect(()=>{var c;r.current!==n&&((c=l.current)==null||c.call(l,n),r.current=n)},[n,r]),[n,a,l]}function WF(t){return typeof t=="function"}var oS=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),YF="VisuallyHidden",iS=p.forwardRef((t,s)=>e.jsx(et.span,{...t,ref:s,style:{...oS,...t.style}}));iS.displayName=YF;var JF=iS,[_x]=Ya("Tooltip",[hc]),Dx=hc(),lS="TooltipProvider",e$=700,lO="tooltip.open",[t$,Cb]=_x(lS),cS=t=>{const{__scopeTooltip:s,delayDuration:n=e$,skipDelayDuration:a=300,disableHoverableContent:r=!1,children:l}=t,c=p.useRef(!0),A=p.useRef(!1),f=p.useRef(0);return p.useEffect(()=>{const x=f.current;return()=>window.clearTimeout(x)},[]),e.jsx(t$,{scope:s,isOpenDelayedRef:c,delayDuration:n,onOpen:p.useCallback(()=>{window.clearTimeout(f.current),c.current=!1},[]),onClose:p.useCallback(()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>c.current=!0,a)},[a]),isPointerInTransitRef:A,onPointerInTransitChange:p.useCallback(x=>{A.current=x},[]),disableHoverableContent:r,children:l})};cS.displayName=lS;var VA="Tooltip",[s$,fd]=_x(VA),AS=t=>{const{__scopeTooltip:s,children:n,open:a,defaultOpen:r,onOpenChange:l,disableHoverableContent:c,delayDuration:A}=t,f=Cb(VA,t.__scopeTooltip),x=Dx(s),[h,g]=p.useState(null),O=$r(),b=p.useRef(0),v=c??f.disableHoverableContent,y=A??f.delayDuration,S=p.useRef(!1),[j,N]=sc({prop:a,defaultProp:r??!1,onChange:B=>{B?(f.onOpen(),document.dispatchEvent(new CustomEvent(lO))):f.onClose(),l==null||l(B)},caller:VA}),C=p.useMemo(()=>j?S.current?"delayed-open":"instant-open":"closed",[j]),U=p.useCallback(()=>{window.clearTimeout(b.current),b.current=0,S.current=!1,N(!0)},[N]),P=p.useCallback(()=>{window.clearTimeout(b.current),b.current=0,N(!1)},[N]),T=p.useCallback(()=>{window.clearTimeout(b.current),b.current=window.setTimeout(()=>{S.current=!0,N(!0),b.current=0},y)},[y,N]);return p.useEffect(()=>()=>{b.current&&(window.clearTimeout(b.current),b.current=0)},[]),e.jsx(jb,{...x,children:e.jsx(s$,{scope:s,contentId:O,open:j,stateAttribute:C,trigger:h,onTriggerChange:g,onTriggerEnter:p.useCallback(()=>{f.isOpenDelayedRef.current?T():U()},[f.isOpenDelayedRef,T,U]),onTriggerLeave:p.useCallback(()=>{v?P():(window.clearTimeout(b.current),b.current=0)},[P,v]),onOpen:U,onClose:P,disableHoverableContent:v,children:n})})};AS.displayName=VA;var cO="TooltipTrigger",dS=p.forwardRef((t,s)=>{const{__scopeTooltip:n,...a}=t,r=fd(cO,n),l=Cb(cO,n),c=Dx(n),A=p.useRef(null),f=mt(s,A,r.onTriggerChange),x=p.useRef(!1),h=p.useRef(!1),g=p.useCallback(()=>x.current=!1,[]);return p.useEffect(()=>()=>document.removeEventListener("pointerup",g),[g]),e.jsx(Qb,{asChild:!0,...c,children:e.jsx(et.button,{"aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute,...a,ref:f,onPointerMove:Ue(t.onPointerMove,O=>{O.pointerType!=="touch"&&!h.current&&!l.isPointerInTransitRef.current&&(r.onTriggerEnter(),h.current=!0)}),onPointerLeave:Ue(t.onPointerLeave,()=>{r.onTriggerLeave(),h.current=!1}),onPointerDown:Ue(t.onPointerDown,()=>{r.open&&r.onClose(),x.current=!0,document.addEventListener("pointerup",g,{once:!0})}),onFocus:Ue(t.onFocus,()=>{x.current||r.onOpen()}),onBlur:Ue(t.onBlur,r.onClose),onClick:Ue(t.onClick,r.onClose)})})});dS.displayName=cO;var Bb="TooltipPortal",[n$,a$]=_x(Bb,{forceMount:void 0}),uS=t=>{const{__scopeTooltip:s,forceMount:n,children:a,container:r}=t,l=fd(Bb,s);return e.jsx(n$,{scope:s,forceMount:n,children:e.jsx(ln,{present:n||l.open,children:e.jsx(ud,{asChild:!0,container:r,children:a})})})};uS.displayName=Bb;var nc="TooltipContent",fS=p.forwardRef((t,s)=>{const n=a$(nc,t.__scopeTooltip),{forceMount:a=n.forceMount,side:r="top",...l}=t,c=fd(nc,t.__scopeTooltip);return e.jsx(ln,{present:a||c.open,children:c.disableHoverableContent?e.jsx(xS,{side:r,...l,ref:s}):e.jsx(r$,{side:r,...l,ref:s})})}),r$=p.forwardRef((t,s)=>{const n=fd(nc,t.__scopeTooltip),a=Cb(nc,t.__scopeTooltip),r=p.useRef(null),l=mt(s,r),[c,A]=p.useState(null),{trigger:f,onClose:x}=n,h=r.current,{onPointerInTransitChange:g}=a,O=p.useCallback(()=>{A(null),g(!1)},[g]),b=p.useCallback((v,y)=>{const S=v.currentTarget,j={x:v.clientX,y:v.clientY},N=c$(j,S.getBoundingClientRect()),C=A$(j,N),U=d$(y.getBoundingClientRect()),P=f$([...C,...U]);A(P),g(!0)},[g]);return p.useEffect(()=>()=>O(),[O]),p.useEffect(()=>{if(f&&h){const v=S=>b(S,h),y=S=>b(S,f);return f.addEventListener("pointerleave",v),h.addEventListener("pointerleave",y),()=>{f.removeEventListener("pointerleave",v),h.removeEventListener("pointerleave",y)}}},[f,h,b,O]),p.useEffect(()=>{if(c){const v=y=>{const S=y.target,j={x:y.clientX,y:y.clientY},N=(f==null?void 0:f.contains(S))||(h==null?void 0:h.contains(S)),C=!u$(j,c);N?O():C&&(O(),x())};return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[f,h,c,x,O]),e.jsx(xS,{...t,ref:l})}),[o$,i$]=_x(VA,{isInside:!1}),l$=pP("TooltipContent"),xS=p.forwardRef((t,s)=>{const{__scopeTooltip:n,children:a,"aria-label":r,onEscapeKeyDown:l,onPointerDownOutside:c,...A}=t,f=fd(nc,n),x=Dx(n),{onClose:h}=f;return p.useEffect(()=>(document.addEventListener(lO,h),()=>document.removeEventListener(lO,h)),[h]),p.useEffect(()=>{if(f.trigger){const g=O=>{const b=O.target;b!=null&&b.contains(f.trigger)&&h()};return window.addEventListener("scroll",g,{capture:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})}},[f.trigger,h]),e.jsx(Ad,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:h,children:e.jsxs(Nb,{"data-state":f.stateAttribute,...x,...A,ref:s,style:{...A.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[e.jsx(l$,{children:a}),e.jsx(o$,{scope:n,isInside:!0,children:e.jsx(JF,{id:f.contentId,role:"tooltip",children:r||a})})]})})});fS.displayName=nc;var mS="TooltipArrow",hS=p.forwardRef((t,s)=>{const{__scopeTooltip:n,...a}=t,r=Dx(n);return i$(mS,n).isInside?null:e.jsx(Sb,{...r,...a,ref:s})});hS.displayName=mS;function c$(t,s){const n=Math.abs(s.top-t.y),a=Math.abs(s.bottom-t.y),r=Math.abs(s.right-t.x),l=Math.abs(s.left-t.x);switch(Math.min(n,a,r,l)){case l:return"left";case r:return"right";case n:return"top";case a:return"bottom";default:throw new Error("unreachable")}}function A$(t,s,n=5){const a=[];switch(s){case"top":a.push({x:t.x-n,y:t.y+n},{x:t.x+n,y:t.y+n});break;case"bottom":a.push({x:t.x-n,y:t.y-n},{x:t.x+n,y:t.y-n});break;case"left":a.push({x:t.x+n,y:t.y-n},{x:t.x+n,y:t.y+n});break;case"right":a.push({x:t.x-n,y:t.y-n},{x:t.x-n,y:t.y+n});break}return a}function d$(t){const{top:s,right:n,bottom:a,left:r}=t;return[{x:r,y:s},{x:n,y:s},{x:n,y:a},{x:r,y:a}]}function u$(t,s){const{x:n,y:a}=t;let r=!1;for(let l=0,c=s.length-1;l<s.length;c=l++){const A=s[l],f=s[c],x=A.x,h=A.y,g=f.x,O=f.y;h>a!=O>a&&n<(g-x)*(a-h)/(O-h)+x&&(r=!r)}return r}function f$(t){const s=t.slice();return s.sort((n,a)=>n.x<a.x?-1:n.x>a.x?1:n.y<a.y?-1:n.y>a.y?1:0),x$(s)}function x$(t){if(t.length<=1)return t.slice();const s=[];for(let a=0;a<t.length;a++){const r=t[a];for(;s.length>=2;){const l=s[s.length-1],c=s[s.length-2];if((l.x-c.x)*(r.y-c.y)>=(l.y-c.y)*(r.x-c.x))s.pop();else break}s.push(r)}s.pop();const n=[];for(let a=t.length-1;a>=0;a--){const r=t[a];for(;n.length>=2;){const l=n[n.length-1],c=n[n.length-2];if((l.x-c.x)*(r.y-c.y)>=(l.y-c.y)*(r.x-c.x))n.pop();else break}n.push(r)}return n.pop(),s.length===1&&n.length===1&&s[0].x===n[0].x&&s[0].y===n[0].y?s:s.concat(n)}var m$=cS,h$=AS,p$=dS,g$=uS,O$=fS,b$=hS;function v$({children:t}){return e.jsx(m$,{delayDuration:300,children:t})}function dt({children:t,content:s,side:n="top",className:a}){return s?e.jsxs(h$,{children:[e.jsx(p$,{asChild:!0,children:t}),e.jsx(g$,{children:e.jsxs(O$,{side:n,sideOffset:6,className:Z("z-50 px-2.5 py-1.5 text-xs font-sans","bg-surface-4 text-text-0 border border-border rounded-md shadow-lg","animate-in fade-in-0 zoom-in-95",a),children:[s,e.jsx(b$,{className:"fill-surface-4"})]})})]}):t}/**
44
+ `:" ";Y[Y.length-1]={...W,text:W.text+_+C,timestamp:Date.now()}}else Y.push({from:"assistant",text:C,timestamp:Date.now()});R[M.id]=Y.slice(-200),t({conversationMessages:R,streamingConversationId:M.id}),ft("groove:conversationMessages",R)}}}if(S&&S.trim()){const C={...s().activityLog};C[b]||(C[b]=[]),C[b]=[...C[b].slice(-200),{timestamp:Date.now(),text:S.trim(),type:v.type,subtype:"tool"}],t({activityLog:C}),ft("groove:activityLog",C)}if(s().workspaceMode&&Array.isArray(v.data)){const C=new Set(["Write","Edit","write_file","edit_file","create_file"]);for(const U of v.data){if(U.type!=="tool_use"||!C.has(U.name))continue;const P=((l=U.input)==null?void 0:l.file_path)||((c=U.input)==null?void 0:c.path);if(P&&b===s().workspaceAgentId){const T=P.replace(/^\/[^/]+.*?\/groove\//,"");s().editorActiveFile?t(F=>({editorOpenTabs:F.editorOpenTabs.includes(T)?F.editorOpenTabs:[...F.editorOpenTabs,T]})):s().openFile(T)}}}break}case"agent:exit":{if(r.status==="waiting_for_input"){const C=s().agents.find(U=>U.id===r.agentId);s().addToast("info",`${(C==null?void 0:C.name)||r.agentId.slice(0,8)} needs your input`,"Check the question popup below");break}const b=s().agents.find(C=>C.id===r.agentId),v=(b==null?void 0:b.name)||r.agentId,y=r.status==="killed"||r.code===143||r.code===137,S=r.status==="completed"?`${v} completed`:y?`${v} stopped`:`${v} crashed (exit ${r.code})`,j=r.status==="completed"?"success":y?"info":"warning";s().addToast(j,S,r.error?r.error.slice(0,200):void 0),s().thinkingAgents.has(r.agentId)&&t(C=>{const U=new Set(C.thinkingAgents);return U.delete(r.agentId),{thinkingAgents:U}});const N=s().conversations.find(C=>C.agentId===r.agentId);if(N&&s().streamingConversationId===N.id&&t({sendingMessage:!1,streamingConversationId:null}),r.error&&r.agentId&&s().addChatMessage(r.agentId,"system",`Crashed: ${r.error}`),s().workspaceAgentId===r.agentId){const C=s().agents.filter(P=>P.id!==r.agentId&&P.teamId===s().activeTeamId),U=C.find(P=>P.status==="running")||C[0];t({workspaceAgentId:(U==null?void 0:U.id)||null})}(b==null?void 0:b.role)==="planner"&&r.status==="completed"&&setTimeout(()=>s().checkRecommendedTeam(),1e3);break}case"innerchat:turn":{const{thread:b,turn:v}=r.data;if(v.status==="failed"){s().addToast("error",`InnerChat to ${v.to.name} failed`,v.error);break}t(y=>{const S={...y.chatHistory},j=(P,T)=>({from:"innerchat",text:v.text,timestamp:v.timestamp,isQuery:!1,innerchat:{turnId:v.id,threadId:b.id,kind:v.kind,peer:P,direction:T}}),N=(P,T)=>{S[P]=[...S[P]||[],T].slice(-100)};v.kind==="ask"&&N(v.from.id,j(v.to,"out")),N(v.to.id,j(v.from,"in")),$A(S);const C={...y.innerchatAnswers};v.kind==="answer"&&(C[v.from.id]={...C[v.from.id]||{},[v.text.trim()]:{peer:v.to,threadId:b.id}});const U={...y.innerchatThreads,[b.id]:b};return ft("groove:innerchatThreads",U),{chatHistory:S,innerchatThreads:U,innerchatAnswers:C}});break}case"recommended-team:ready":s().recommendedTeam||s().checkRecommendedTeam();break;case"phase2:spawned":s().addToast("info",`QC agent ${r.name} auto-spawned`,"Auditing phase 1 work");break;case"preview:ready":{const b=r.teamId?`/api/preview/${r.teamId}/proxy/`:r.url;t(v=>({teamPreviews:{...v.teamPreviews,[r.teamId]:{url:b,kind:r.kind,active:!0}}})),s().addToast("success","Project ready to preview",r.url,{label:"Open Preview",onClick:()=>s().openPreview(b,r.teamId,r.kind)},{persistent:!0,actions:[{label:"View in Browser",url:r.url}]});break}case"preview:failed":{const b=r.kind||"";b!=="no_preview"&&b!=="cli"&&b!=="none"&&s().addToast("warning","Preview could not launch",r.reason?String(r.reason).slice(0,200):"Unknown error");break}case"preview:stopped":{const b=s().teamPreviews[r.teamId];b&&t(v=>({teamPreviews:{...v.teamPreviews,[r.teamId]:{...b,active:!1}}}));break}case"agent:stalled":{const b=r.agentName||r.agentId,v=Math.round((r.silentMs||0)/1e3);s().addToast("warning",`${b} may be stalled`,`No output for ${v}s — API stream may be hung`);break}case"knock:denied":{const b=r.agentName||r.agentId;s().addToast("warning",`${b} blocked`,`${r.toolName} on ${r.target} — ${r.reason||"scope conflict"}`);break}case"phase2:failed":s().addToast("error","QC agent failed to spawn",r.error||"Unknown error");break;case"agent:message_queued":s().addChatMessage(r.agentId,"system","Agent is working — message will be delivered when it finishes.");break;case"agent:question":t(b=>({pendingQuestions:[...b.pendingQuestions,r.data]}));break;case"agent:question:resolved":t(b=>({pendingQuestions:b.pendingQuestions.filter(v=>v.agentId!==r.agentId)}));break;case"ollama:pull:progress":t({ollamaPullProgress:{...s().ollamaPullProgress,[r.model]:{status:"pulling",progress:r.progress}}});break;case"ollama:pull:complete":{const b={...s().ollamaPullProgress};delete b[r.model],t({ollamaPullProgress:b}),s().fetchOllamaStatus();break}case"ollama:pull:error":{const b={...s().ollamaPullProgress};delete b[r.model],t({ollamaPullProgress:b}),s().addToast("error",`Model pull failed: ${r.error}`);break}case"ollama:model:loaded":s().fetchOllamaStatus();break;case"ollama:model:unloaded":s().fetchOllamaStatus();break;case"ollama:model:imported":s().fetchOllamaStatus();break;case"lab:runtime:added":case"lab:runtime:updated":case"lab:runtime:removed":case"lab:runtime:started":case"lab:runtime:stopped":case"llama:server:stopped":s().fetchLabRuntimes();break;case"lab:preset:created":case"lab:preset:updated":case"lab:preset:deleted":break;case"rotation:start":break;case"rotation:complete":{const b=r.agentId,v=r.oldAgentId;if(!b||!v)break;t(y=>{var F,M,R;const S={...y.chatHistory},j={...y.tokenTimeline},N={...y.activityLog},C={...y.chatInputs};(F=S[v])!=null&&F.length&&(S[b]=[...S[v]],delete S[v]),(M=j[v])!=null&&M.length&&(j[b]=[...j[v]],delete j[v]),(R=N[v])!=null&&R.length&&(N[b]=[...N[v]],delete N[v]),C[v]&&(C[b]=C[v],delete C[v]);const U=y.detailPanel;let P=U,T=y.teamDetailPanels;if((U==null?void 0:U.type)==="agent"&&U.agentId===v){const Y={type:"agent",agentId:b};P=Y;const W=s().activeTeamId;T={...y.teamDetailPanels,[W]:Y}}let B=y.fleetSelectedAgents;(B[0]===v||B[1]===v)&&(B=[B[0]===v?b:B[0],B[1]===v?b:B[1]]);try{localStorage.setItem("groove:chatHistory",JSON.stringify(S))}catch{}return{chatHistory:S,tokenTimeline:j,activityLog:N,chatInputs:C,detailPanel:P,teamDetailPanels:T,fleetSelectedAgents:B}});break}case"rotation:failed":s().addToast("error","Rotation failed",r.error);break;case"file:changed":{const b=s().editorRecentSaves[r.path];if(b&&Date.now()-b<2e3)break;if(s().workspaceMode&&r.path&&!s().workspaceSnapshots[r.path]){const v=s().editorFiles[r.path];v!=null&&v.content&&s().captureSnapshot(r.path,v.content)}s().editorFiles[r.path]&&s().reloadFile(r.path);break}case"file:tree-changed":{s().fetchTreeDir(r.path||"");break}case"team:created":case"team:deleted":case"team:updated":s().fetchTeams();break;case"teams:reordered":r.teams&&t({teams:r.teams});break;case"approval:request":t(b=>({pendingApprovals:[...b.pendingApprovals,r.data]}));break;case"approval:resolved":{const b=r.data;t(v=>({pendingApprovals:v.pendingApprovals.filter(y=>y.id!==b.id),resolvedApprovals:[b,...v.resolvedApprovals].slice(0,200)}));break}case"conflict:detected":s().addToast("error",`Scope conflict: ${r.agentName||"agent"}`,r.filePath?`File: ${r.filePath}`:void 0);break;case"qc:activated":s().addToast("info","QC agent activated",`${r.agentCount||"4+"} agents running`);break;case"journalist:cycle":t({journalistStatus:r.data||null});break;case"schedule:execute":s().addToast("info",`Scheduled agent spawned: ${r.name||r.role||"agent"}`),s().fetchAutomations();break;case"schedule:created":case"schedule:updated":case"schedule:deleted":s().fetchAutomations();break;case"auto-agent:created":case"auto-agent:updated":case"auto-agent:deleted":case"auto-agent:paused":case"auto-agent:resumed":case"auto-agent:cycle-complete":case"auto-agent:auto-paused":case"auto-agent:state-updated":case"auto-agent:iteration-started":s().fetchAutoAgents();break;case"gateway:status":t({gateways:r.data||[]});break;case"provider:status-changed":t({_providerRefreshTick:Date.now()});break;case"federation:whitelist":t(b=>({federation:{...b.federation,whitelist:r.data||[]}}));break;case"federation:connection":t(b=>{const v=[...b.federation.connections],y=v.findIndex(S=>{var j;return S.ip===((j=r.data)==null?void 0:j.ip)});return y>=0?v[y]={...v[y],...r.data}:v.push(r.data),{federation:{...b.federation,connections:v}}});break;case"federation:pouch":case"federation:pouch-log":t(b=>({federation:{...b.federation,pouchLog:[...b.federation.pouchLog,r.data].slice(-200)}}));break;case"project-dir:changed":t({projectDir:(A=r.data)==null?void 0:A.projectDir,showProjectPicker:!1});break;case"tunnel.connected":s().fetchTunnels(),t({tunnelConnectStep:null});break;case"tunnel.status":{t({tunnelConnectStep:r.data});break}case"tunnel.disconnected":s().fetchTunnels();break;case"tunnel.health":{const b=s().savedTunnels.map(v=>{var y;return v.id===((y=r.data)==null?void 0:y.id)?{...v,latencyMs:r.data.latencyMs,healthy:r.data.healthy}:v});t({savedTunnels:b});break}case"tunnel.version-info":{const b=s().savedTunnels.map(v=>v.id===r.data.id?{...v,localVersion:r.data.localVersion,remoteVersion:r.data.remoteVersion,versionMatch:r.data.match}:v);t({savedTunnels:b});break}case"tunnel.version-mismatch":{const b=s().savedTunnels.map(v=>v.id===r.data.id?{...v,localVersion:r.data.localVersion,remoteVersion:r.data.remoteVersion,versionMatch:!1}:v);t({savedTunnels:b}),s().addToast("warning","Version mismatch",`Remote v${r.data.remoteVersion} — local v${r.data.localVersion}. ${r.data.message||""}`);break}case"tunnel.upgrade-failed":{s().addToast("error","Remote upgrade failed",r.data.error||"Unknown error");break}case"subscription:updated":{const b={subscription:r.data};((f=r.data)==null?void 0:f.active)===!0&&!s().marketplaceAuthenticated&&(b.marketplaceAuthenticated=!0),t(b),G.get("/edition").then(v=>{t({edition:v.edition||"community",subscription:{plan:v.plan||"community",status:v.status||(v.subscriptionActive?"active":"none"),active:v.subscriptionActive===!0,features:v.features||[],seats:v.seats||1,periodEnd:v.periodEnd||null,cancelAtPeriodEnd:v.cancelAtPeriodEnd||!1}})}).catch(()=>{}),s().fetchTunnels();break}case"auth:expired":t({marketplaceAuthenticated:!1,marketplaceUser:null});break;case"network:node:status":{const{__proto__:b,constructor:v,prototype:y,...S}=r.data||{};t({networkNode:{...s().networkNode,...S}});break}case"network:node:event":{const b=r.data||{};t(v=>({networkEvents:[...v.networkEvents,{...b,timestamp:b.timestamp||Date.now()}].slice(-100)}));break}case"signal_connected":{const b=r.data||{};t(v=>({networkEvents:[...v.networkEvents,{level:"connected",msg:String(b.msg||b.message||"Connected to signal").slice(0,500),detail:b.detail||b.url||void 0,timestamp:b.timestamp||Date.now()}].slice(-100)}));break}case"matched":{const b=r.data||{};t(v=>({networkEvents:[...v.networkEvents,{level:"session",msg:String(b.msg||b.message||"Session matched").slice(0,500),detail:b.detail||b.peer||b.nodeId||void 0,timestamp:b.timestamp||Date.now()}].slice(-100)}));break}case"network:status":{const b=r.data||{},v={networkStatus:{...s().networkStatus,...b}};if(b.compute){const P=b.compute;v.networkCompute={totalRamMb:P.totalRamMb??P.total_ram_mb??0,totalVramMb:P.totalVramMb??P.total_vram_mb??0,totalCpuCores:P.totalCpuCores??P.total_cpu_cores??0,totalBandwidthMbps:P.totalBandwidthMbps??P.total_bandwidth_mbps??0,activeNodes:P.activeNodes??P.active_nodes??0,totalNodes:P.totalNodes??P.total_nodes??0,avgLoad:P.avgLoad??P.avg_load??0}}else if(Array.isArray(b.nodes)&&b.nodes.length>0){const P=b.nodes,T=P.filter(B=>B.status==="active");v.networkCompute={totalRamMb:P.reduce((B,F)=>B+(F.ram_mb||0),0),totalVramMb:P.reduce((B,F)=>B+(F.vram_mb||0),0),totalCpuCores:P.reduce((B,F)=>B+(F.cpu_cores||0),0),totalBandwidthMbps:P.reduce((B,F)=>B+(F.bandwidth_mbps||0),0),activeNodes:T.length,totalNodes:P.length,avgLoad:T.length>0?T.reduce((B,F)=>B+(F.load||0),0)/T.length:0}}t(v);const y=b.nodes||[],S=s().networkNode.nodeId,j=S?y.find(P=>(P.node_id||P.nodeId)===S):null,N=y.filter(P=>P.status==="active"),C={t:Date.now(),globalSessions:b.activeSessions||0,mySessions:(j==null?void 0:j.active_sessions)??(j==null?void 0:j.sessions)??0,nodeCount:N.length,avgLoad:N.length>0?N.reduce((P,T)=>P+(T.load||0),0)/N.length:0,myLoad:(j==null?void 0:j.load)??0,totalVramMb:y.reduce((P,T)=>P+(T.vram_mb||0),0),totalRamMb:y.reduce((P,T)=>P+(T.ram_mb||0),0)};let U=[...s().networkSnapshots,C];U.length>100&&(U=U.slice(-100)),t({networkSnapshots:U});break}case"network:install:progress":{const{step:b,message:v,percent:y}=r.data||{};b==="done"?(t({networkInstalled:!0,networkInstallProgress:{installing:!1,step:null,message:null,percent:0,error:null}}),s().addToast("success","Network package installed")):t(b==="error"?{networkInstallProgress:{installing:!1,step:"error",message:v||"Install failed",percent:0,error:v||"Install failed"}}:{networkInstallProgress:{installing:!0,step:b||"progress",message:v||"",percent:Number.isFinite(y)?Math.max(0,Math.min(100,y)):s().networkInstallProgress.percent,error:null}});break}case"network:update:available":{const{installed:b,latest:v,updateAvailable:y}=r.data||{};t({networkVersion:{installed:b??s().networkVersion.installed,latest:v??s().networkVersion.latest,updateAvailable:!!y}});break}case"network:update:progress":{const{step:b,message:v,percent:y,version:S,error:j}=r.data||{};b==="done"?(t({networkUpdateProgress:{updating:!1,step:null,message:null,percent:0,error:null},networkVersion:{...s().networkVersion,installed:S||s().networkVersion.latest||s().networkVersion.installed,updateAvailable:!1}}),s().addToast("success","Network package updated")):b==="error"?(t({networkUpdateProgress:{updating:!1,step:"error",message:v||j||"Update failed",percent:0,error:v||j||"Update failed"}}),s().addToast("error","Network update failed",v||j)):t({networkUpdateProgress:{updating:!0,step:b||"progress",message:v||"",percent:Number.isFinite(y)?Math.max(0,Math.min(100,y)):s().networkUpdateProgress.percent,error:null}});break}case"training:status":{const b={trainingOptIn:((x=r.data)==null?void 0:x.optedIn)??!1,trainingStats:r.data};(h=r.data)!=null&&h.optedIn&&(b.dataSharingModalOpen=!1),t(b);break}case"config:updated":s().fetchBetaStatus(),s().fetchNetworkInstallStatus();break;case"conversation:created":{const b=r.data;b&&t(v=>({conversations:[b,...v.conversations.filter(y=>y.id!==b.id)]}));break}case"conversation:updated":{const b=r.data;b&&t(v=>({conversations:v.conversations.map(y=>y.id===b.id?{...y,...b}:y)}));break}case"conversation:deleted":{const b=((g=r.data)==null?void 0:g.id)||r.id;b&&t(v=>{const y=v.conversations.filter(N=>N.id!==b),S={...v.conversationMessages};delete S[b];const j=v.activeConversationId===b?null:v.activeConversationId;return j!==v.activeConversationId&&localStorage.setItem("groove:activeConversationId",""),{conversations:y,conversationMessages:S,activeConversationId:j}});break}case"conversation:tool":{const{conversationId:b,name:v,summary:y}=r.data||r;if(!b)break;t(S=>{const j={...S.conversationActiveTools};return j[b]={name:v||"Tool",summary:y||null,timestamp:Date.now()},{conversationActiveTools:j}});break}case"conversation:chunk":{const{conversationId:b,text:v}=r.data||r;if(!b||!v)break;t(y=>{const S={...y.conversationMessages};S[b]||(S[b]=[]);const j=[...S[b]],N=j[j.length-1];N&&N.from==="assistant"&&Date.now()-N.timestamp<3e4?j[j.length-1]={...N,text:N.text+v,timestamp:Date.now()}:j.push({from:"assistant",text:v,timestamp:Date.now()}),S[b]=j.slice(-200);const C={...y.conversationActiveTools};return delete C[b],{conversationMessages:S,streamingConversationId:b,conversationActiveTools:C}});break}case"conversation:complete":{const{conversationId:b}=r.data||r;if(b&&s().streamingConversationId===b){const v={...s().conversationActiveTools};delete v[b],t({sendingMessage:!1,streamingConversationId:null,conversationActiveTools:v})}b&&ft("groove:conversationMessages",s().conversationMessages);break}case"conversation:image":{const{conversationId:b,prompt:v,url:y,b64_json:S,mimeType:j,model:N,provider:C}=r.data||r;if(!b)break;const U=y||(S?`data:${j||"image/png"};base64,${S}`:null);t(P=>{const T={...P.conversationMessages};T[b]||(T[b]=[]);const B=[...T[b]],F=B.findLastIndex(R=>R.type==="image-loading"&&R.prompt===v);F>=0?B[F]={from:"assistant",type:"image",imageUrl:U,prompt:v,model:N,provider:C,timestamp:Date.now()}:B.push({from:"assistant",type:"image",imageUrl:U,prompt:v,model:N,provider:C,timestamp:Date.now()}),T[b]=B.slice(-200),ft("groove:conversationMessages",T);const M=P.streamingConversationId===b;return{conversationMessages:T,sendingMessage:M?!1:P.sendingMessage,streamingConversationId:M?null:P.streamingConversationId}});break}case"conversation:image-progress":{const{conversationId:b,status:v,prompt:y,error:S}=r.data||r;if(!b)break;v==="generating"?t(j=>{const N={...j.conversationMessages};return N[b]||(N[b]=[]),N[b]=[...N[b],{from:"assistant",type:"image-loading",prompt:y,timestamp:Date.now()}],{conversationMessages:N,streamingConversationId:b}}):v==="error"&&t(j=>{const N={...j.conversationMessages};N[b]||(N[b]=[]);const C=[...N[b]],U=C.findLastIndex(T=>T.type==="image-loading");U>=0&&C.splice(U,1),C.push({from:"system",text:`Image generation failed: ${S||"Unknown error"}`,timestamp:Date.now()}),N[b]=C,ft("groove:conversationMessages",N);const P=j.streamingConversationId===b;return{conversationMessages:N,sendingMessage:P?!1:j.sendingMessage,streamingConversationId:P?null:j.streamingConversationId}});break}case"conversation:error":{const{conversationId:b,error:v}=r.data||r;b&&t(y=>{const S={...y.conversationMessages};S[b]||(S[b]=[]),S[b]=[...S[b],{from:"system",text:`Error: ${v||"Unknown error"}`,timestamp:Date.now()}],ft("groove:conversationMessages",S);const j=y.streamingConversationId===b;return{conversationMessages:S,sendingMessage:j?!1:y.sendingMessage,streamingConversationId:j?null:y.streamingConversationId}});break}case"network:token:timing":{const{__proto__:b,constructor:v,prototype:y,...S}=r.data||{},j={networkTokenTiming:S,networkPerfSnapshots:[...s().networkPerfSnapshots,{t:Date.now(),tps:S.tps||0}].slice(-100)};if(Array.isArray(S.stages)){const N={...s().networkNodeTelemetry},C=new Set(["__proto__","constructor","prototype"]);for(const U of S.stages){const P=(O=U.node_telemetry)==null?void 0:O.node_id;P&&typeof P=="string"&&!C.has(P)&&(N[P]={...U.node_telemetry,forward_ms:U.forward_ms,updatedAt:Date.now()})}j.networkNodeTelemetry=N}t(j);break}case"network:timing:summary":{const{__proto__:b,constructor:v,prototype:y,...S}=r.data||{};t(j=>({networkBenchmarks:[...j.networkBenchmarks,S].slice(-100)}));break}case"keeper:saved":case"keeper:updated":case"keeper:deleted":s().fetchKeeperItems();break}},n.onclose=()=>{za&&(clearInterval(za),za=null),t({connected:!1,hydrated:!1,ws:null,daemonHost:null,tunneled:!1,remoteHomedir:null}),setTimeout(()=>s().connect(),2e3)},n.onerror=()=>n.close()}}));if(typeof window<"u"){const t=()=>{const s=k.getState();s.ws||s.connect()};window.addEventListener("online",t),window.addEventListener("focus",t),document.addEventListener("visibilitychange",()=>{document.hidden||t()})}function pN(t){p.useEffect(()=>{function s(n){for(const a of t){const r=a.meta?n.metaKey||n.ctrlKey:!0,l=a.shift?n.shiftKey:!n.shiftKey;if(n.key.toLowerCase()===a.key.toLowerCase()&&r&&l){n.preventDefault(),a.handler();return}}}return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[t])}function cd(){return!!(window.groove||navigator.userAgent.includes("Electron"))}function gN(){var t;return((t=window.groove)==null?void 0:t.platform)||"browser"}function sO(t){window.groove?window.groove.openExternal(t):window.open(t,"_blank")}async function wE(t={}){var s,n;return(n=(s=window.groove)==null?void 0:s.folders)!=null&&n.select?window.groove.folders.select(t):null}async function ON(t){var s,n;if((n=(s=window.groove)==null?void 0:s.integrations)!=null&&n.oauthStart)return window.groove.integrations.oauthStart(t);window.open(t,"_blank","noopener")}function bN(t){var s,n,a="";if(typeof t=="string"||typeof t=="number")a+=t;else if(typeof t=="object")if(Array.isArray(t)){var r=t.length;for(s=0;s<r;s++)t[s]&&(n=bN(t[s]))&&(a&&(a+=" "),a+=n)}else for(n in t)t[n]&&(a&&(a+=" "),a+=n);return a}function jE(){for(var t,s,n=0,a="",r=arguments.length;n<r;n++)(t=arguments[n])&&(s=bN(t))&&(a&&(a+=" "),a+=s);return a}const QE=(t,s)=>{const n=new Array(t.length+s.length);for(let a=0;a<t.length;a++)n[a]=t[a];for(let a=0;a<s.length;a++)n[t.length+a]=s[a];return n},NE=(t,s)=>({classGroupId:t,validator:s}),vN=(t=new Map,s=null,n)=>({nextPart:t,validators:s,classGroupId:n}),ex="-",Dw=[],SE="arbitrary..",CE=t=>{const s=kE(t),{conflictingClassGroups:n,conflictingClassGroupModifiers:a}=t;return{getClassGroupId:c=>{if(c.startsWith("[")&&c.endsWith("]"))return BE(c);const A=c.split(ex),f=A[0]===""&&A.length>1?1:0;return yN(A,f,s)},getConflictingClassGroupIds:(c,A)=>{if(A){const f=a[c],x=n[c];return f?x?QE(x,f):f:x||Dw}return n[c]||Dw}}},yN=(t,s,n)=>{if(t.length-s===0)return n.classGroupId;const r=t[s],l=n.nextPart.get(r);if(l){const x=yN(t,s+1,l);if(x)return x}const c=n.validators;if(c===null)return;const A=s===0?t.join(ex):t.slice(s).join(ex),f=c.length;for(let x=0;x<f;x++){const h=c[x];if(h.validator(A))return h.classGroupId}},BE=t=>t.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const s=t.slice(1,-1),n=s.indexOf(":"),a=s.slice(0,n);return a?SE+a:void 0})(),kE=t=>{const{theme:s,classGroups:n}=t;return TE(n,s)},TE=(t,s)=>{const n=vN();for(const a in t){const r=t[a];fb(r,n,a,s)}return n},fb=(t,s,n,a)=>{const r=t.length;for(let l=0;l<r;l++){const c=t[l];UE(c,s,n,a)}},UE=(t,s,n,a)=>{if(typeof t=="string"){EE(t,s,n);return}if(typeof t=="function"){PE(t,s,n,a);return}FE(t,s,n,a)},EE=(t,s,n)=>{const a=t===""?s:wN(s,t);a.classGroupId=n},PE=(t,s,n,a)=>{if($E(t)){fb(t(a),s,n,a);return}s.validators===null&&(s.validators=[]),s.validators.push(NE(n,t))},FE=(t,s,n,a)=>{const r=Object.entries(t),l=r.length;for(let c=0;c<l;c++){const[A,f]=r[c];fb(f,wN(s,A),n,a)}},wN=(t,s)=>{let n=t;const a=s.split(ex),r=a.length;for(let l=0;l<r;l++){const c=a[l];let A=n.nextPart.get(c);A||(A=vN(),n.nextPart.set(c,A)),n=A}return n},$E=t=>"isThemeGetter"in t&&t.isThemeGetter===!0,RE=t=>{if(t<1)return{get:()=>{},set:()=>{}};let s=0,n=Object.create(null),a=Object.create(null);const r=(l,c)=>{n[l]=c,s++,s>t&&(s=0,a=n,n=Object.create(null))};return{get(l){let c=n[l];if(c!==void 0)return c;if((c=a[l])!==void 0)return r(l,c),c},set(l,c){l in n?n[l]=c:r(l,c)}}},nO="!",Lw=":",ME=[],Hw=(t,s,n,a,r)=>({modifiers:t,hasImportantModifier:s,baseClassName:n,maybePostfixModifierPosition:a,isExternal:r}),IE=t=>{const{prefix:s,experimentalParseClassName:n}=t;let a=r=>{const l=[];let c=0,A=0,f=0,x;const h=r.length;for(let y=0;y<h;y++){const S=r[y];if(c===0&&A===0){if(S===Lw){l.push(r.slice(f,y)),f=y+1;continue}if(S==="/"){x=y;continue}}S==="["?c++:S==="]"?c--:S==="("?A++:S===")"&&A--}const g=l.length===0?r:r.slice(f);let O=g,b=!1;g.endsWith(nO)?(O=g.slice(0,-1),b=!0):g.startsWith(nO)&&(O=g.slice(1),b=!0);const v=x&&x>f?x-f:void 0;return Hw(l,b,O,v)};if(s){const r=s+Lw,l=a;a=c=>c.startsWith(r)?l(c.slice(r.length)):Hw(ME,!1,c,void 0,!0)}if(n){const r=a;a=l=>n({className:l,parseClassName:r})}return a},zE=t=>{const s=new Map;return t.orderSensitiveModifiers.forEach((n,a)=>{s.set(n,1e6+a)}),n=>{const a=[];let r=[];for(let l=0;l<n.length;l++){const c=n[l],A=c[0]==="[",f=s.has(c);A||f?(r.length>0&&(r.sort(),a.push(...r),r=[]),a.push(c)):r.push(c)}return r.length>0&&(r.sort(),a.push(...r)),a}},_E=t=>({cache:RE(t.cacheSize),parseClassName:IE(t),sortModifiers:zE(t),...CE(t)}),DE=/\s+/,LE=(t,s)=>{const{parseClassName:n,getClassGroupId:a,getConflictingClassGroupIds:r,sortModifiers:l}=s,c=[],A=t.trim().split(DE);let f="";for(let x=A.length-1;x>=0;x-=1){const h=A[x],{isExternal:g,modifiers:O,hasImportantModifier:b,baseClassName:v,maybePostfixModifierPosition:y}=n(h);if(g){f=h+(f.length>0?" "+f:f);continue}let S=!!y,j=a(S?v.substring(0,y):v);if(!j){if(!S){f=h+(f.length>0?" "+f:f);continue}if(j=a(v),!j){f=h+(f.length>0?" "+f:f);continue}S=!1}const N=O.length===0?"":O.length===1?O[0]:l(O).join(":"),C=b?N+nO:N,U=C+j;if(c.indexOf(U)>-1)continue;c.push(U);const P=r(j,S);for(let T=0;T<P.length;++T){const B=P[T];c.push(C+B)}f=h+(f.length>0?" "+f:f)}return f},HE=(...t)=>{let s=0,n,a,r="";for(;s<t.length;)(n=t[s++])&&(a=jN(n))&&(r&&(r+=" "),r+=a);return r},jN=t=>{if(typeof t=="string")return t;let s,n="";for(let a=0;a<t.length;a++)t[a]&&(s=jN(t[a]))&&(n&&(n+=" "),n+=s);return n},XE=(t,...s)=>{let n,a,r,l;const c=f=>{const x=s.reduce((h,g)=>g(h),t());return n=_E(x),a=n.cache.get,r=n.cache.set,l=A,A(f)},A=f=>{const x=a(f);if(x)return x;const h=LE(f,n);return r(f,h),h};return l=c,(...f)=>l(HE(...f))},GE=[],js=t=>{const s=n=>n[t]||GE;return s.isThemeGetter=!0,s},QN=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,NN=/^\((?:(\w[\w-]*):)?(.+)\)$/i,ZE=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,VE=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,KE=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,qE=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,WE=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,YE=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,xo=t=>ZE.test(t),at=t=>!!t&&!Number.isNaN(Number(t)),mo=t=>!!t&&Number.isInteger(Number(t)),Mp=t=>t.endsWith("%")&&at(t.slice(0,-1)),Sr=t=>VE.test(t),SN=()=>!0,JE=t=>KE.test(t)&&!qE.test(t),xb=()=>!1,eP=t=>WE.test(t),tP=t=>YE.test(t),sP=t=>!Me(t)&&!Ie(t),nP=t=>Do(t,kN,xb),Me=t=>QN.test(t),mi=t=>Do(t,TN,JE),Xw=t=>Do(t,dP,at),aP=t=>Do(t,EN,SN),rP=t=>Do(t,UN,xb),Gw=t=>Do(t,CN,xb),oP=t=>Do(t,BN,tP),Mu=t=>Do(t,PN,eP),Ie=t=>NN.test(t),fA=t=>_i(t,TN),iP=t=>_i(t,UN),Zw=t=>_i(t,CN),lP=t=>_i(t,kN),cP=t=>_i(t,BN),Iu=t=>_i(t,PN,!0),AP=t=>_i(t,EN,!0),Do=(t,s,n)=>{const a=QN.exec(t);return a?a[1]?s(a[1]):n(a[2]):!1},_i=(t,s,n=!1)=>{const a=NN.exec(t);return a?a[1]?s(a[1]):n:!1},CN=t=>t==="position"||t==="percentage",BN=t=>t==="image"||t==="url",kN=t=>t==="length"||t==="size"||t==="bg-size",TN=t=>t==="length",dP=t=>t==="number",UN=t=>t==="family-name",EN=t=>t==="number"||t==="weight",PN=t=>t==="shadow",uP=()=>{const t=js("color"),s=js("font"),n=js("text"),a=js("font-weight"),r=js("tracking"),l=js("leading"),c=js("breakpoint"),A=js("container"),f=js("spacing"),x=js("radius"),h=js("shadow"),g=js("inset-shadow"),O=js("text-shadow"),b=js("drop-shadow"),v=js("blur"),y=js("perspective"),S=js("aspect"),j=js("ease"),N=js("animate"),C=()=>["auto","avoid","all","avoid-page","page","left","right","column"],U=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],P=()=>[...U(),Ie,Me],T=()=>["auto","hidden","clip","visible","scroll"],B=()=>["auto","contain","none"],F=()=>[Ie,Me,f],M=()=>[xo,"full","auto",...F()],R=()=>[mo,"none","subgrid",Ie,Me],Y=()=>["auto",{span:["full",mo,Ie,Me]},mo,Ie,Me],W=()=>[mo,"auto",Ie,Me],ee=()=>["auto","min","max","fr",Ie,Me],K=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],_=()=>["start","end","center","stretch","center-safe","end-safe"],E=()=>["auto",...F()],q=()=>[xo,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...F()],H=()=>[xo,"screen","full","dvw","lvw","svw","min","max","fit",...F()],I=()=>[xo,"screen","full","lh","dvh","lvh","svh","min","max","fit",...F()],L=()=>[t,Ie,Me],J=()=>[...U(),Zw,Gw,{position:[Ie,Me]}],D=()=>["no-repeat",{repeat:["","x","y","space","round"]}],se=()=>["auto","cover","contain",lP,nP,{size:[Ie,Me]}],le=()=>[Mp,fA,mi],V=()=>["","none","full",x,Ie,Me],te=()=>["",at,fA,mi],ae=()=>["solid","dashed","dotted","double"],be=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],z=()=>[at,Mp,Zw,Gw],oe=()=>["","none",v,Ie,Me],ue=()=>["none",at,Ie,Me],ve=()=>["none",at,Ie,Me],Ce=()=>[at,Ie,Me],Ne=()=>[xo,"full",...F()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[Sr],breakpoint:[Sr],color:[SN],container:[Sr],"drop-shadow":[Sr],ease:["in","out","in-out"],font:[sP],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[Sr],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[Sr],shadow:[Sr],spacing:["px",at],text:[Sr],"text-shadow":[Sr],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",xo,Me,Ie,S]}],container:["container"],columns:[{columns:[at,Me,Ie,A]}],"break-after":[{"break-after":C()}],"break-before":[{"break-before":C()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:P()}],overflow:[{overflow:T()}],"overflow-x":[{"overflow-x":T()}],"overflow-y":[{"overflow-y":T()}],overscroll:[{overscroll:B()}],"overscroll-x":[{"overscroll-x":B()}],"overscroll-y":[{"overscroll-y":B()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:M()}],"inset-x":[{"inset-x":M()}],"inset-y":[{"inset-y":M()}],start:[{"inset-s":M(),start:M()}],end:[{"inset-e":M(),end:M()}],"inset-bs":[{"inset-bs":M()}],"inset-be":[{"inset-be":M()}],top:[{top:M()}],right:[{right:M()}],bottom:[{bottom:M()}],left:[{left:M()}],visibility:["visible","invisible","collapse"],z:[{z:[mo,"auto",Ie,Me]}],basis:[{basis:[xo,"full","auto",A,...F()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[at,xo,"auto","initial","none",Me]}],grow:[{grow:["",at,Ie,Me]}],shrink:[{shrink:["",at,Ie,Me]}],order:[{order:[mo,"first","last","none",Ie,Me]}],"grid-cols":[{"grid-cols":R()}],"col-start-end":[{col:Y()}],"col-start":[{"col-start":W()}],"col-end":[{"col-end":W()}],"grid-rows":[{"grid-rows":R()}],"row-start-end":[{row:Y()}],"row-start":[{"row-start":W()}],"row-end":[{"row-end":W()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":ee()}],"auto-rows":[{"auto-rows":ee()}],gap:[{gap:F()}],"gap-x":[{"gap-x":F()}],"gap-y":[{"gap-y":F()}],"justify-content":[{justify:[...K(),"normal"]}],"justify-items":[{"justify-items":[..._(),"normal"]}],"justify-self":[{"justify-self":["auto",..._()]}],"align-content":[{content:["normal",...K()]}],"align-items":[{items:[..._(),{baseline:["","last"]}]}],"align-self":[{self:["auto",..._(),{baseline:["","last"]}]}],"place-content":[{"place-content":K()}],"place-items":[{"place-items":[..._(),"baseline"]}],"place-self":[{"place-self":["auto",..._()]}],p:[{p:F()}],px:[{px:F()}],py:[{py:F()}],ps:[{ps:F()}],pe:[{pe:F()}],pbs:[{pbs:F()}],pbe:[{pbe:F()}],pt:[{pt:F()}],pr:[{pr:F()}],pb:[{pb:F()}],pl:[{pl:F()}],m:[{m:E()}],mx:[{mx:E()}],my:[{my:E()}],ms:[{ms:E()}],me:[{me:E()}],mbs:[{mbs:E()}],mbe:[{mbe:E()}],mt:[{mt:E()}],mr:[{mr:E()}],mb:[{mb:E()}],ml:[{ml:E()}],"space-x":[{"space-x":F()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":F()}],"space-y-reverse":["space-y-reverse"],size:[{size:q()}],"inline-size":[{inline:["auto",...H()]}],"min-inline-size":[{"min-inline":["auto",...H()]}],"max-inline-size":[{"max-inline":["none",...H()]}],"block-size":[{block:["auto",...I()]}],"min-block-size":[{"min-block":["auto",...I()]}],"max-block-size":[{"max-block":["none",...I()]}],w:[{w:[A,"screen",...q()]}],"min-w":[{"min-w":[A,"screen","none",...q()]}],"max-w":[{"max-w":[A,"screen","none","prose",{screen:[c]},...q()]}],h:[{h:["screen","lh",...q()]}],"min-h":[{"min-h":["screen","lh","none",...q()]}],"max-h":[{"max-h":["screen","lh",...q()]}],"font-size":[{text:["base",n,fA,mi]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[a,AP,aP]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",Mp,Me]}],"font-family":[{font:[iP,rP,s]}],"font-features":[{"font-features":[Me]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[r,Ie,Me]}],"line-clamp":[{"line-clamp":[at,"none",Ie,Xw]}],leading:[{leading:[l,...F()]}],"list-image":[{"list-image":["none",Ie,Me]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",Ie,Me]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:L()}],"text-color":[{text:L()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...ae(),"wavy"]}],"text-decoration-thickness":[{decoration:[at,"from-font","auto",Ie,mi]}],"text-decoration-color":[{decoration:L()}],"underline-offset":[{"underline-offset":[at,"auto",Ie,Me]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:F()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",Ie,Me]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",Ie,Me]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:J()}],"bg-repeat":[{bg:D()}],"bg-size":[{bg:se()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},mo,Ie,Me],radial:["",Ie,Me],conic:[mo,Ie,Me]},cP,oP]}],"bg-color":[{bg:L()}],"gradient-from-pos":[{from:le()}],"gradient-via-pos":[{via:le()}],"gradient-to-pos":[{to:le()}],"gradient-from":[{from:L()}],"gradient-via":[{via:L()}],"gradient-to":[{to:L()}],rounded:[{rounded:V()}],"rounded-s":[{"rounded-s":V()}],"rounded-e":[{"rounded-e":V()}],"rounded-t":[{"rounded-t":V()}],"rounded-r":[{"rounded-r":V()}],"rounded-b":[{"rounded-b":V()}],"rounded-l":[{"rounded-l":V()}],"rounded-ss":[{"rounded-ss":V()}],"rounded-se":[{"rounded-se":V()}],"rounded-ee":[{"rounded-ee":V()}],"rounded-es":[{"rounded-es":V()}],"rounded-tl":[{"rounded-tl":V()}],"rounded-tr":[{"rounded-tr":V()}],"rounded-br":[{"rounded-br":V()}],"rounded-bl":[{"rounded-bl":V()}],"border-w":[{border:te()}],"border-w-x":[{"border-x":te()}],"border-w-y":[{"border-y":te()}],"border-w-s":[{"border-s":te()}],"border-w-e":[{"border-e":te()}],"border-w-bs":[{"border-bs":te()}],"border-w-be":[{"border-be":te()}],"border-w-t":[{"border-t":te()}],"border-w-r":[{"border-r":te()}],"border-w-b":[{"border-b":te()}],"border-w-l":[{"border-l":te()}],"divide-x":[{"divide-x":te()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":te()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...ae(),"hidden","none"]}],"divide-style":[{divide:[...ae(),"hidden","none"]}],"border-color":[{border:L()}],"border-color-x":[{"border-x":L()}],"border-color-y":[{"border-y":L()}],"border-color-s":[{"border-s":L()}],"border-color-e":[{"border-e":L()}],"border-color-bs":[{"border-bs":L()}],"border-color-be":[{"border-be":L()}],"border-color-t":[{"border-t":L()}],"border-color-r":[{"border-r":L()}],"border-color-b":[{"border-b":L()}],"border-color-l":[{"border-l":L()}],"divide-color":[{divide:L()}],"outline-style":[{outline:[...ae(),"none","hidden"]}],"outline-offset":[{"outline-offset":[at,Ie,Me]}],"outline-w":[{outline:["",at,fA,mi]}],"outline-color":[{outline:L()}],shadow:[{shadow:["","none",h,Iu,Mu]}],"shadow-color":[{shadow:L()}],"inset-shadow":[{"inset-shadow":["none",g,Iu,Mu]}],"inset-shadow-color":[{"inset-shadow":L()}],"ring-w":[{ring:te()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:L()}],"ring-offset-w":[{"ring-offset":[at,mi]}],"ring-offset-color":[{"ring-offset":L()}],"inset-ring-w":[{"inset-ring":te()}],"inset-ring-color":[{"inset-ring":L()}],"text-shadow":[{"text-shadow":["none",O,Iu,Mu]}],"text-shadow-color":[{"text-shadow":L()}],opacity:[{opacity:[at,Ie,Me]}],"mix-blend":[{"mix-blend":[...be(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":be()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[at]}],"mask-image-linear-from-pos":[{"mask-linear-from":z()}],"mask-image-linear-to-pos":[{"mask-linear-to":z()}],"mask-image-linear-from-color":[{"mask-linear-from":L()}],"mask-image-linear-to-color":[{"mask-linear-to":L()}],"mask-image-t-from-pos":[{"mask-t-from":z()}],"mask-image-t-to-pos":[{"mask-t-to":z()}],"mask-image-t-from-color":[{"mask-t-from":L()}],"mask-image-t-to-color":[{"mask-t-to":L()}],"mask-image-r-from-pos":[{"mask-r-from":z()}],"mask-image-r-to-pos":[{"mask-r-to":z()}],"mask-image-r-from-color":[{"mask-r-from":L()}],"mask-image-r-to-color":[{"mask-r-to":L()}],"mask-image-b-from-pos":[{"mask-b-from":z()}],"mask-image-b-to-pos":[{"mask-b-to":z()}],"mask-image-b-from-color":[{"mask-b-from":L()}],"mask-image-b-to-color":[{"mask-b-to":L()}],"mask-image-l-from-pos":[{"mask-l-from":z()}],"mask-image-l-to-pos":[{"mask-l-to":z()}],"mask-image-l-from-color":[{"mask-l-from":L()}],"mask-image-l-to-color":[{"mask-l-to":L()}],"mask-image-x-from-pos":[{"mask-x-from":z()}],"mask-image-x-to-pos":[{"mask-x-to":z()}],"mask-image-x-from-color":[{"mask-x-from":L()}],"mask-image-x-to-color":[{"mask-x-to":L()}],"mask-image-y-from-pos":[{"mask-y-from":z()}],"mask-image-y-to-pos":[{"mask-y-to":z()}],"mask-image-y-from-color":[{"mask-y-from":L()}],"mask-image-y-to-color":[{"mask-y-to":L()}],"mask-image-radial":[{"mask-radial":[Ie,Me]}],"mask-image-radial-from-pos":[{"mask-radial-from":z()}],"mask-image-radial-to-pos":[{"mask-radial-to":z()}],"mask-image-radial-from-color":[{"mask-radial-from":L()}],"mask-image-radial-to-color":[{"mask-radial-to":L()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":U()}],"mask-image-conic-pos":[{"mask-conic":[at]}],"mask-image-conic-from-pos":[{"mask-conic-from":z()}],"mask-image-conic-to-pos":[{"mask-conic-to":z()}],"mask-image-conic-from-color":[{"mask-conic-from":L()}],"mask-image-conic-to-color":[{"mask-conic-to":L()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:J()}],"mask-repeat":[{mask:D()}],"mask-size":[{mask:se()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",Ie,Me]}],filter:[{filter:["","none",Ie,Me]}],blur:[{blur:oe()}],brightness:[{brightness:[at,Ie,Me]}],contrast:[{contrast:[at,Ie,Me]}],"drop-shadow":[{"drop-shadow":["","none",b,Iu,Mu]}],"drop-shadow-color":[{"drop-shadow":L()}],grayscale:[{grayscale:["",at,Ie,Me]}],"hue-rotate":[{"hue-rotate":[at,Ie,Me]}],invert:[{invert:["",at,Ie,Me]}],saturate:[{saturate:[at,Ie,Me]}],sepia:[{sepia:["",at,Ie,Me]}],"backdrop-filter":[{"backdrop-filter":["","none",Ie,Me]}],"backdrop-blur":[{"backdrop-blur":oe()}],"backdrop-brightness":[{"backdrop-brightness":[at,Ie,Me]}],"backdrop-contrast":[{"backdrop-contrast":[at,Ie,Me]}],"backdrop-grayscale":[{"backdrop-grayscale":["",at,Ie,Me]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[at,Ie,Me]}],"backdrop-invert":[{"backdrop-invert":["",at,Ie,Me]}],"backdrop-opacity":[{"backdrop-opacity":[at,Ie,Me]}],"backdrop-saturate":[{"backdrop-saturate":[at,Ie,Me]}],"backdrop-sepia":[{"backdrop-sepia":["",at,Ie,Me]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":F()}],"border-spacing-x":[{"border-spacing-x":F()}],"border-spacing-y":[{"border-spacing-y":F()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",Ie,Me]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[at,"initial",Ie,Me]}],ease:[{ease:["linear","initial",j,Ie,Me]}],delay:[{delay:[at,Ie,Me]}],animate:[{animate:["none",N,Ie,Me]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[y,Ie,Me]}],"perspective-origin":[{"perspective-origin":P()}],rotate:[{rotate:ue()}],"rotate-x":[{"rotate-x":ue()}],"rotate-y":[{"rotate-y":ue()}],"rotate-z":[{"rotate-z":ue()}],scale:[{scale:ve()}],"scale-x":[{"scale-x":ve()}],"scale-y":[{"scale-y":ve()}],"scale-z":[{"scale-z":ve()}],"scale-3d":["scale-3d"],skew:[{skew:Ce()}],"skew-x":[{"skew-x":Ce()}],"skew-y":[{"skew-y":Ce()}],transform:[{transform:[Ie,Me,"","none","gpu","cpu"]}],"transform-origin":[{origin:P()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:Ne()}],"translate-x":[{"translate-x":Ne()}],"translate-y":[{"translate-y":Ne()}],"translate-z":[{"translate-z":Ne()}],"translate-none":["translate-none"],accent:[{accent:L()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:L()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",Ie,Me]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":F()}],"scroll-mx":[{"scroll-mx":F()}],"scroll-my":[{"scroll-my":F()}],"scroll-ms":[{"scroll-ms":F()}],"scroll-me":[{"scroll-me":F()}],"scroll-mbs":[{"scroll-mbs":F()}],"scroll-mbe":[{"scroll-mbe":F()}],"scroll-mt":[{"scroll-mt":F()}],"scroll-mr":[{"scroll-mr":F()}],"scroll-mb":[{"scroll-mb":F()}],"scroll-ml":[{"scroll-ml":F()}],"scroll-p":[{"scroll-p":F()}],"scroll-px":[{"scroll-px":F()}],"scroll-py":[{"scroll-py":F()}],"scroll-ps":[{"scroll-ps":F()}],"scroll-pe":[{"scroll-pe":F()}],"scroll-pbs":[{"scroll-pbs":F()}],"scroll-pbe":[{"scroll-pbe":F()}],"scroll-pt":[{"scroll-pt":F()}],"scroll-pr":[{"scroll-pr":F()}],"scroll-pb":[{"scroll-pb":F()}],"scroll-pl":[{"scroll-pl":F()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",Ie,Me]}],fill:[{fill:["none",...L()]}],"stroke-w":[{stroke:[at,fA,mi,Xw]}],stroke:[{stroke:["none",...L()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}},fP=XE(uP);function Z(...t){return fP(jE(t))}function Ue(t,s,{checkForDefaultPrevented:n=!0}={}){return function(r){if(t==null||t(r),n===!1||!r.defaultPrevented)return s==null?void 0:s(r)}}function Vw(t,s){if(typeof t=="function")return t(s);t!=null&&(t.current=s)}function mb(...t){return s=>{let n=!1;const a=t.map(r=>{const l=Vw(r,s);return!n&&typeof l=="function"&&(n=!0),l});if(n)return()=>{for(let r=0;r<a.length;r++){const l=a[r];typeof l=="function"?l():Vw(t[r],null)}}}}function mt(...t){return p.useCallback(mb(...t),t)}function xP(t,s){const n=p.createContext(s),a=l=>{const{children:c,...A}=l,f=p.useMemo(()=>A,Object.values(A));return e.jsx(n.Provider,{value:f,children:c})};a.displayName=t+"Provider";function r(l){const c=p.useContext(n);if(c)return c;if(s!==void 0)return s;throw new Error(`\`${l}\` must be used within \`${t}\``)}return[a,r]}function Ya(t,s=[]){let n=[];function a(l,c){const A=p.createContext(c),f=n.length;n=[...n,c];const x=g=>{var j;const{scope:O,children:b,...v}=g,y=((j=O==null?void 0:O[t])==null?void 0:j[f])||A,S=p.useMemo(()=>v,Object.values(v));return e.jsx(y.Provider,{value:S,children:b})};x.displayName=l+"Provider";function h(g,O){var y;const b=((y=O==null?void 0:O[t])==null?void 0:y[f])||A,v=p.useContext(b);if(v)return v;if(c!==void 0)return c;throw new Error(`\`${g}\` must be used within \`${l}\``)}return[x,h]}const r=()=>{const l=n.map(c=>p.createContext(c));return function(A){const f=(A==null?void 0:A[t])||l;return p.useMemo(()=>({[`__scope${t}`]:{...A,[t]:f}}),[A,f])}};return r.scopeName=t,[a,mP(r,...s)]}function mP(...t){const s=t[0];if(t.length===1)return s;const n=()=>{const a=t.map(r=>({useScope:r(),scopeName:r.scopeName}));return function(l){const c=a.reduce((A,{useScope:f,scopeName:x})=>{const g=f(l)[`__scope${x}`];return{...A,...g}},{});return p.useMemo(()=>({[`__scope${s.scopeName}`]:c}),[c])}};return n.scopeName=s.scopeName,n}function ec(t){const s=hP(t),n=p.forwardRef((a,r)=>{const{children:l,...c}=a,A=p.Children.toArray(l),f=A.find(gP);if(f){const x=f.props.children,h=A.map(g=>g===f?p.Children.count(x)>1?p.Children.only(null):p.isValidElement(x)?x.props.children:null:g);return e.jsx(s,{...c,ref:r,children:p.isValidElement(x)?p.cloneElement(x,void 0,h):null})}return e.jsx(s,{...c,ref:r,children:l})});return n.displayName=`${t}.Slot`,n}function hP(t){const s=p.forwardRef((n,a)=>{const{children:r,...l}=n;if(p.isValidElement(r)){const c=bP(r),A=OP(l,r.props);return r.type!==p.Fragment&&(A.ref=a?mb(a,c):c),p.cloneElement(r,A)}return p.Children.count(r)>1?p.Children.only(null):null});return s.displayName=`${t}.SlotClone`,s}var FN=Symbol("radix.slottable");function pP(t){const s=({children:n})=>e.jsx(e.Fragment,{children:n});return s.displayName=`${t}.Slottable`,s.__radixId=FN,s}function gP(t){return p.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===FN}function OP(t,s){const n={...s};for(const a in s){const r=t[a],l=s[a];/^on[A-Z]/.test(a)?r&&l?n[a]=(...A)=>{const f=l(...A);return r(...A),f}:r&&(n[a]=r):a==="style"?n[a]={...r,...l}:a==="className"&&(n[a]=[r,l].filter(Boolean).join(" "))}return{...t,...n}}function bP(t){var a,r;let s=(a=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:a.get,n=s&&"isReactWarning"in s&&s.isReactWarning;return n?t.ref:(s=(r=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:r.get,n=s&&"isReactWarning"in s&&s.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var vP=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],et=vP.reduce((t,s)=>{const n=ec(`Primitive.${s}`),a=p.forwardRef((r,l)=>{const{asChild:c,...A}=r,f=c?n:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(f,{...A,ref:l})});return a.displayName=`Primitive.${s}`,{...t,[s]:a}},{});function $N(t,s){t&&Px.flushSync(()=>t.dispatchEvent(s))}function Us(t){const s=p.useRef(t);return p.useEffect(()=>{s.current=t}),p.useMemo(()=>(...n)=>{var a;return(a=s.current)==null?void 0:a.call(s,...n)},[])}function yP(t,s=globalThis==null?void 0:globalThis.document){const n=Us(t);p.useEffect(()=>{const a=r=>{r.key==="Escape"&&n(r)};return s.addEventListener("keydown",a,{capture:!0}),()=>s.removeEventListener("keydown",a,{capture:!0})},[n,s])}var wP="DismissableLayer",aO="dismissableLayer.update",jP="dismissableLayer.pointerDownOutside",QP="dismissableLayer.focusOutside",Kw,RN=p.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ad=p.forwardRef((t,s)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:a,onPointerDownOutside:r,onFocusOutside:l,onInteractOutside:c,onDismiss:A,...f}=t,x=p.useContext(RN),[h,g]=p.useState(null),O=(h==null?void 0:h.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,b]=p.useState({}),v=mt(s,B=>g(B)),y=Array.from(x.layers),[S]=[...x.layersWithOutsidePointerEventsDisabled].slice(-1),j=y.indexOf(S),N=h?y.indexOf(h):-1,C=x.layersWithOutsidePointerEventsDisabled.size>0,U=N>=j,P=CP(B=>{const F=B.target,M=[...x.branches].some(R=>R.contains(F));!U||M||(r==null||r(B),c==null||c(B),B.defaultPrevented||A==null||A())},O),T=BP(B=>{const F=B.target;[...x.branches].some(R=>R.contains(F))||(l==null||l(B),c==null||c(B),B.defaultPrevented||A==null||A())},O);return yP(B=>{N===x.layers.size-1&&(a==null||a(B),!B.defaultPrevented&&A&&(B.preventDefault(),A()))},O),p.useEffect(()=>{if(h)return n&&(x.layersWithOutsidePointerEventsDisabled.size===0&&(Kw=O.body.style.pointerEvents,O.body.style.pointerEvents="none"),x.layersWithOutsidePointerEventsDisabled.add(h)),x.layers.add(h),qw(),()=>{n&&x.layersWithOutsidePointerEventsDisabled.size===1&&(O.body.style.pointerEvents=Kw)}},[h,O,n,x]),p.useEffect(()=>()=>{h&&(x.layers.delete(h),x.layersWithOutsidePointerEventsDisabled.delete(h),qw())},[h,x]),p.useEffect(()=>{const B=()=>b({});return document.addEventListener(aO,B),()=>document.removeEventListener(aO,B)},[]),e.jsx(et.div,{...f,ref:v,style:{pointerEvents:C?U?"auto":"none":void 0,...t.style},onFocusCapture:Ue(t.onFocusCapture,T.onFocusCapture),onBlurCapture:Ue(t.onBlurCapture,T.onBlurCapture),onPointerDownCapture:Ue(t.onPointerDownCapture,P.onPointerDownCapture)})});Ad.displayName=wP;var NP="DismissableLayerBranch",SP=p.forwardRef((t,s)=>{const n=p.useContext(RN),a=p.useRef(null),r=mt(s,a);return p.useEffect(()=>{const l=a.current;if(l)return n.branches.add(l),()=>{n.branches.delete(l)}},[n.branches]),e.jsx(et.div,{...t,ref:r})});SP.displayName=NP;function CP(t,s=globalThis==null?void 0:globalThis.document){const n=Us(t),a=p.useRef(!1),r=p.useRef(()=>{});return p.useEffect(()=>{const l=A=>{if(A.target&&!a.current){let f=function(){MN(jP,n,x,{discrete:!0})};const x={originalEvent:A};A.pointerType==="touch"?(s.removeEventListener("click",r.current),r.current=f,s.addEventListener("click",r.current,{once:!0})):f()}else s.removeEventListener("click",r.current);a.current=!1},c=window.setTimeout(()=>{s.addEventListener("pointerdown",l)},0);return()=>{window.clearTimeout(c),s.removeEventListener("pointerdown",l),s.removeEventListener("click",r.current)}},[s,n]),{onPointerDownCapture:()=>a.current=!0}}function BP(t,s=globalThis==null?void 0:globalThis.document){const n=Us(t),a=p.useRef(!1);return p.useEffect(()=>{const r=l=>{l.target&&!a.current&&MN(QP,n,{originalEvent:l},{discrete:!1})};return s.addEventListener("focusin",r),()=>s.removeEventListener("focusin",r)},[s,n]),{onFocusCapture:()=>a.current=!0,onBlurCapture:()=>a.current=!1}}function qw(){const t=new CustomEvent(aO);document.dispatchEvent(t)}function MN(t,s,n,{discrete:a}){const r=n.originalEvent.target,l=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});s&&r.addEventListener(t,s,{once:!0}),a?$N(r,l):r.dispatchEvent(l)}var Ds=globalThis!=null&&globalThis.document?p.useLayoutEffect:()=>{},kP=oN[" useId ".trim().toString()]||(()=>{}),TP=0;function $r(t){const[s,n]=p.useState(kP());return Ds(()=>{n(a=>a??String(TP++))},[t]),s?`radix-${s}`:""}const UP=["top","right","bottom","left"],Fo=Math.min,$n=Math.max,tx=Math.round,zu=Math.floor,Xa=t=>({x:t,y:t}),EP={left:"right",right:"left",bottom:"top",top:"bottom"};function rO(t,s,n){return $n(t,Fo(s,n))}function Ir(t,s){return typeof t=="function"?t(s):t}function zr(t){return t.split("-")[0]}function xc(t){return t.split("-")[1]}function hb(t){return t==="x"?"y":"x"}function pb(t){return t==="y"?"height":"width"}function La(t){const s=t[0];return s==="t"||s==="b"?"y":"x"}function gb(t){return hb(La(t))}function PP(t,s,n){n===void 0&&(n=!1);const a=xc(t),r=gb(t),l=pb(r);let c=r==="x"?a===(n?"end":"start")?"right":"left":a==="start"?"bottom":"top";return s.reference[l]>s.floating[l]&&(c=sx(c)),[c,sx(c)]}function FP(t){const s=sx(t);return[oO(t),s,oO(s)]}function oO(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const Ww=["left","right"],Yw=["right","left"],$P=["top","bottom"],RP=["bottom","top"];function MP(t,s,n){switch(t){case"top":case"bottom":return n?s?Yw:Ww:s?Ww:Yw;case"left":case"right":return s?$P:RP;default:return[]}}function IP(t,s,n,a){const r=xc(t);let l=MP(zr(t),n==="start",a);return r&&(l=l.map(c=>c+"-"+r),s&&(l=l.concat(l.map(oO)))),l}function sx(t){const s=zr(t);return EP[s]+t.slice(s.length)}function zP(t){return{top:0,right:0,bottom:0,left:0,...t}}function IN(t){return typeof t!="number"?zP(t):{top:t,right:t,bottom:t,left:t}}function nx(t){const{x:s,y:n,width:a,height:r}=t;return{width:a,height:r,top:n,left:s,right:s+a,bottom:n+r,x:s,y:n}}function Jw(t,s,n){let{reference:a,floating:r}=t;const l=La(s),c=gb(s),A=pb(c),f=zr(s),x=l==="y",h=a.x+a.width/2-r.width/2,g=a.y+a.height/2-r.height/2,O=a[A]/2-r[A]/2;let b;switch(f){case"top":b={x:h,y:a.y-r.height};break;case"bottom":b={x:h,y:a.y+a.height};break;case"right":b={x:a.x+a.width,y:g};break;case"left":b={x:a.x-r.width,y:g};break;default:b={x:a.x,y:a.y}}switch(xc(s)){case"start":b[c]-=O*(n&&x?-1:1);break;case"end":b[c]+=O*(n&&x?-1:1);break}return b}async function _P(t,s){var n;s===void 0&&(s={});const{x:a,y:r,platform:l,rects:c,elements:A,strategy:f}=t,{boundary:x="clippingAncestors",rootBoundary:h="viewport",elementContext:g="floating",altBoundary:O=!1,padding:b=0}=Ir(s,t),v=IN(b),S=A[O?g==="floating"?"reference":"floating":g],j=nx(await l.getClippingRect({element:(n=await(l.isElement==null?void 0:l.isElement(S)))==null||n?S:S.contextElement||await(l.getDocumentElement==null?void 0:l.getDocumentElement(A.floating)),boundary:x,rootBoundary:h,strategy:f})),N=g==="floating"?{x:a,y:r,width:c.floating.width,height:c.floating.height}:c.reference,C=await(l.getOffsetParent==null?void 0:l.getOffsetParent(A.floating)),U=await(l.isElement==null?void 0:l.isElement(C))?await(l.getScale==null?void 0:l.getScale(C))||{x:1,y:1}:{x:1,y:1},P=nx(l.convertOffsetParentRelativeRectToViewportRelativeRect?await l.convertOffsetParentRelativeRectToViewportRelativeRect({elements:A,rect:N,offsetParent:C,strategy:f}):N);return{top:(j.top-P.top+v.top)/U.y,bottom:(P.bottom-j.bottom+v.bottom)/U.y,left:(j.left-P.left+v.left)/U.x,right:(P.right-j.right+v.right)/U.x}}const DP=50,LP=async(t,s,n)=>{const{placement:a="bottom",strategy:r="absolute",middleware:l=[],platform:c}=n,A=c.detectOverflow?c:{...c,detectOverflow:_P},f=await(c.isRTL==null?void 0:c.isRTL(s));let x=await c.getElementRects({reference:t,floating:s,strategy:r}),{x:h,y:g}=Jw(x,a,f),O=a,b=0;const v={};for(let y=0;y<l.length;y++){const S=l[y];if(!S)continue;const{name:j,fn:N}=S,{x:C,y:U,data:P,reset:T}=await N({x:h,y:g,initialPlacement:a,placement:O,strategy:r,middlewareData:v,rects:x,platform:A,elements:{reference:t,floating:s}});h=C??h,g=U??g,v[j]={...v[j],...P},T&&b<DP&&(b++,typeof T=="object"&&(T.placement&&(O=T.placement),T.rects&&(x=T.rects===!0?await c.getElementRects({reference:t,floating:s,strategy:r}):T.rects),{x:h,y:g}=Jw(x,O,f)),y=-1)}return{x:h,y:g,placement:O,strategy:r,middlewareData:v}},HP=t=>({name:"arrow",options:t,async fn(s){const{x:n,y:a,placement:r,rects:l,platform:c,elements:A,middlewareData:f}=s,{element:x,padding:h=0}=Ir(t,s)||{};if(x==null)return{};const g=IN(h),O={x:n,y:a},b=gb(r),v=pb(b),y=await c.getDimensions(x),S=b==="y",j=S?"top":"left",N=S?"bottom":"right",C=S?"clientHeight":"clientWidth",U=l.reference[v]+l.reference[b]-O[b]-l.floating[v],P=O[b]-l.reference[b],T=await(c.getOffsetParent==null?void 0:c.getOffsetParent(x));let B=T?T[C]:0;(!B||!await(c.isElement==null?void 0:c.isElement(T)))&&(B=A.floating[C]||l.floating[v]);const F=U/2-P/2,M=B/2-y[v]/2-1,R=Fo(g[j],M),Y=Fo(g[N],M),W=R,ee=B-y[v]-Y,K=B/2-y[v]/2+F,_=rO(W,K,ee),E=!f.arrow&&xc(r)!=null&&K!==_&&l.reference[v]/2-(K<W?R:Y)-y[v]/2<0,q=E?K<W?K-W:K-ee:0;return{[b]:O[b]+q,data:{[b]:_,centerOffset:K-_-q,...E&&{alignmentOffset:q}},reset:E}}}),XP=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(s){var n,a;const{placement:r,middlewareData:l,rects:c,initialPlacement:A,platform:f,elements:x}=s,{mainAxis:h=!0,crossAxis:g=!0,fallbackPlacements:O,fallbackStrategy:b="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:y=!0,...S}=Ir(t,s);if((n=l.arrow)!=null&&n.alignmentOffset)return{};const j=zr(r),N=La(A),C=zr(A)===A,U=await(f.isRTL==null?void 0:f.isRTL(x.floating)),P=O||(C||!y?[sx(A)]:FP(A)),T=v!=="none";!O&&T&&P.push(...IP(A,y,v,U));const B=[A,...P],F=await f.detectOverflow(s,S),M=[];let R=((a=l.flip)==null?void 0:a.overflows)||[];if(h&&M.push(F[j]),g){const K=PP(r,c,U);M.push(F[K[0]],F[K[1]])}if(R=[...R,{placement:r,overflows:M}],!M.every(K=>K<=0)){var Y,W;const K=(((Y=l.flip)==null?void 0:Y.index)||0)+1,_=B[K];if(_&&(!(g==="alignment"?N!==La(_):!1)||R.every(H=>La(H.placement)===N?H.overflows[0]>0:!0)))return{data:{index:K,overflows:R},reset:{placement:_}};let E=(W=R.filter(q=>q.overflows[0]<=0).sort((q,H)=>q.overflows[1]-H.overflows[1])[0])==null?void 0:W.placement;if(!E)switch(b){case"bestFit":{var ee;const q=(ee=R.filter(H=>{if(T){const I=La(H.placement);return I===N||I==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(I=>I>0).reduce((I,L)=>I+L,0)]).sort((H,I)=>H[1]-I[1])[0])==null?void 0:ee[0];q&&(E=q);break}case"initialPlacement":E=A;break}if(r!==E)return{reset:{placement:E}}}return{}}}};function ej(t,s){return{top:t.top-s.height,right:t.right-s.width,bottom:t.bottom-s.height,left:t.left-s.width}}function tj(t){return UP.some(s=>t[s]>=0)}const GP=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(s){const{rects:n,platform:a}=s,{strategy:r="referenceHidden",...l}=Ir(t,s);switch(r){case"referenceHidden":{const c=await a.detectOverflow(s,{...l,elementContext:"reference"}),A=ej(c,n.reference);return{data:{referenceHiddenOffsets:A,referenceHidden:tj(A)}}}case"escaped":{const c=await a.detectOverflow(s,{...l,altBoundary:!0}),A=ej(c,n.floating);return{data:{escapedOffsets:A,escaped:tj(A)}}}default:return{}}}}},zN=new Set(["left","top"]);async function ZP(t,s){const{placement:n,platform:a,elements:r}=t,l=await(a.isRTL==null?void 0:a.isRTL(r.floating)),c=zr(n),A=xc(n),f=La(n)==="y",x=zN.has(c)?-1:1,h=l&&f?-1:1,g=Ir(s,t);let{mainAxis:O,crossAxis:b,alignmentAxis:v}=typeof g=="number"?{mainAxis:g,crossAxis:0,alignmentAxis:null}:{mainAxis:g.mainAxis||0,crossAxis:g.crossAxis||0,alignmentAxis:g.alignmentAxis};return A&&typeof v=="number"&&(b=A==="end"?v*-1:v),f?{x:b*h,y:O*x}:{x:O*x,y:b*h}}const VP=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(s){var n,a;const{x:r,y:l,placement:c,middlewareData:A}=s,f=await ZP(s,t);return c===((n=A.offset)==null?void 0:n.placement)&&(a=A.arrow)!=null&&a.alignmentOffset?{}:{x:r+f.x,y:l+f.y,data:{...f,placement:c}}}}},KP=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(s){const{x:n,y:a,placement:r,platform:l}=s,{mainAxis:c=!0,crossAxis:A=!1,limiter:f={fn:j=>{let{x:N,y:C}=j;return{x:N,y:C}}},...x}=Ir(t,s),h={x:n,y:a},g=await l.detectOverflow(s,x),O=La(zr(r)),b=hb(O);let v=h[b],y=h[O];if(c){const j=b==="y"?"top":"left",N=b==="y"?"bottom":"right",C=v+g[j],U=v-g[N];v=rO(C,v,U)}if(A){const j=O==="y"?"top":"left",N=O==="y"?"bottom":"right",C=y+g[j],U=y-g[N];y=rO(C,y,U)}const S=f.fn({...s,[b]:v,[O]:y});return{...S,data:{x:S.x-n,y:S.y-a,enabled:{[b]:c,[O]:A}}}}}},qP=function(t){return t===void 0&&(t={}),{options:t,fn(s){const{x:n,y:a,placement:r,rects:l,middlewareData:c}=s,{offset:A=0,mainAxis:f=!0,crossAxis:x=!0}=Ir(t,s),h={x:n,y:a},g=La(r),O=hb(g);let b=h[O],v=h[g];const y=Ir(A,s),S=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(f){const C=O==="y"?"height":"width",U=l.reference[O]-l.floating[C]+S.mainAxis,P=l.reference[O]+l.reference[C]-S.mainAxis;b<U?b=U:b>P&&(b=P)}if(x){var j,N;const C=O==="y"?"width":"height",U=zN.has(zr(r)),P=l.reference[g]-l.floating[C]+(U&&((j=c.offset)==null?void 0:j[g])||0)+(U?0:S.crossAxis),T=l.reference[g]+l.reference[C]+(U?0:((N=c.offset)==null?void 0:N[g])||0)-(U?S.crossAxis:0);v<P?v=P:v>T&&(v=T)}return{[O]:b,[g]:v}}}},WP=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(s){var n,a;const{placement:r,rects:l,platform:c,elements:A}=s,{apply:f=()=>{},...x}=Ir(t,s),h=await c.detectOverflow(s,x),g=zr(r),O=xc(r),b=La(r)==="y",{width:v,height:y}=l.floating;let S,j;g==="top"||g==="bottom"?(S=g,j=O===(await(c.isRTL==null?void 0:c.isRTL(A.floating))?"start":"end")?"left":"right"):(j=g,S=O==="end"?"top":"bottom");const N=y-h.top-h.bottom,C=v-h.left-h.right,U=Fo(y-h[S],N),P=Fo(v-h[j],C),T=!s.middlewareData.shift;let B=U,F=P;if((n=s.middlewareData.shift)!=null&&n.enabled.x&&(F=C),(a=s.middlewareData.shift)!=null&&a.enabled.y&&(B=N),T&&!O){const R=$n(h.left,0),Y=$n(h.right,0),W=$n(h.top,0),ee=$n(h.bottom,0);b?F=v-2*(R!==0||Y!==0?R+Y:$n(h.left,h.right)):B=y-2*(W!==0||ee!==0?W+ee:$n(h.top,h.bottom))}await f({...s,availableWidth:F,availableHeight:B});const M=await c.getDimensions(A.floating);return v!==M.width||y!==M.height?{reset:{rects:!0}}:{}}}};function Rx(){return typeof window<"u"}function mc(t){return _N(t)?(t.nodeName||"").toLowerCase():"#document"}function zn(t){var s;return(t==null||(s=t.ownerDocument)==null?void 0:s.defaultView)||window}function Ja(t){var s;return(s=(_N(t)?t.ownerDocument:t.document)||window.document)==null?void 0:s.documentElement}function _N(t){return Rx()?t instanceof Node||t instanceof zn(t).Node:!1}function Sa(t){return Rx()?t instanceof Element||t instanceof zn(t).Element:!1}function Lr(t){return Rx()?t instanceof HTMLElement||t instanceof zn(t).HTMLElement:!1}function sj(t){return!Rx()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof zn(t).ShadowRoot}function dd(t){const{overflow:s,overflowX:n,overflowY:a,display:r}=Ca(t);return/auto|scroll|overlay|hidden|clip/.test(s+a+n)&&r!=="inline"&&r!=="contents"}function YP(t){return/^(table|td|th)$/.test(mc(t))}function Mx(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}const JP=/transform|translate|scale|rotate|perspective|filter/,eF=/paint|layout|strict|content/,hi=t=>!!t&&t!=="none";let Ip;function Ob(t){const s=Sa(t)?Ca(t):t;return hi(s.transform)||hi(s.translate)||hi(s.scale)||hi(s.rotate)||hi(s.perspective)||!bb()&&(hi(s.backdropFilter)||hi(s.filter))||JP.test(s.willChange||"")||eF.test(s.contain||"")}function tF(t){let s=$o(t);for(;Lr(s)&&!tc(s);){if(Ob(s))return s;if(Mx(s))return null;s=$o(s)}return null}function bb(){return Ip==null&&(Ip=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Ip}function tc(t){return/^(html|body|#document)$/.test(mc(t))}function Ca(t){return zn(t).getComputedStyle(t)}function Ix(t){return Sa(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function $o(t){if(mc(t)==="html")return t;const s=t.assignedSlot||t.parentNode||sj(t)&&t.host||Ja(t);return sj(s)?s.host:s}function DN(t){const s=$o(t);return tc(s)?t.ownerDocument?t.ownerDocument.body:t.body:Lr(s)&&dd(s)?s:DN(s)}function ZA(t,s,n){var a;s===void 0&&(s=[]),n===void 0&&(n=!0);const r=DN(t),l=r===((a=t.ownerDocument)==null?void 0:a.body),c=zn(r);if(l){const A=iO(c);return s.concat(c,c.visualViewport||[],dd(r)?r:[],A&&n?ZA(A):[])}else return s.concat(r,ZA(r,[],n))}function iO(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function LN(t){const s=Ca(t);let n=parseFloat(s.width)||0,a=parseFloat(s.height)||0;const r=Lr(t),l=r?t.offsetWidth:n,c=r?t.offsetHeight:a,A=tx(n)!==l||tx(a)!==c;return A&&(n=l,a=c),{width:n,height:a,$:A}}function vb(t){return Sa(t)?t:t.contextElement}function Zl(t){const s=vb(t);if(!Lr(s))return Xa(1);const n=s.getBoundingClientRect(),{width:a,height:r,$:l}=LN(s);let c=(l?tx(n.width):n.width)/a,A=(l?tx(n.height):n.height)/r;return(!c||!Number.isFinite(c))&&(c=1),(!A||!Number.isFinite(A))&&(A=1),{x:c,y:A}}const sF=Xa(0);function HN(t){const s=zn(t);return!bb()||!s.visualViewport?sF:{x:s.visualViewport.offsetLeft,y:s.visualViewport.offsetTop}}function nF(t,s,n){return s===void 0&&(s=!1),!n||s&&n!==zn(t)?!1:s}function Ci(t,s,n,a){s===void 0&&(s=!1),n===void 0&&(n=!1);const r=t.getBoundingClientRect(),l=vb(t);let c=Xa(1);s&&(a?Sa(a)&&(c=Zl(a)):c=Zl(t));const A=nF(l,n,a)?HN(l):Xa(0);let f=(r.left+A.x)/c.x,x=(r.top+A.y)/c.y,h=r.width/c.x,g=r.height/c.y;if(l){const O=zn(l),b=a&&Sa(a)?zn(a):a;let v=O,y=iO(v);for(;y&&a&&b!==v;){const S=Zl(y),j=y.getBoundingClientRect(),N=Ca(y),C=j.left+(y.clientLeft+parseFloat(N.paddingLeft))*S.x,U=j.top+(y.clientTop+parseFloat(N.paddingTop))*S.y;f*=S.x,x*=S.y,h*=S.x,g*=S.y,f+=C,x+=U,v=zn(y),y=iO(v)}}return nx({width:h,height:g,x:f,y:x})}function zx(t,s){const n=Ix(t).scrollLeft;return s?s.left+n:Ci(Ja(t)).left+n}function XN(t,s){const n=t.getBoundingClientRect(),a=n.left+s.scrollLeft-zx(t,n),r=n.top+s.scrollTop;return{x:a,y:r}}function aF(t){let{elements:s,rect:n,offsetParent:a,strategy:r}=t;const l=r==="fixed",c=Ja(a),A=s?Mx(s.floating):!1;if(a===c||A&&l)return n;let f={scrollLeft:0,scrollTop:0},x=Xa(1);const h=Xa(0),g=Lr(a);if((g||!g&&!l)&&((mc(a)!=="body"||dd(c))&&(f=Ix(a)),g)){const b=Ci(a);x=Zl(a),h.x=b.x+a.clientLeft,h.y=b.y+a.clientTop}const O=c&&!g&&!l?XN(c,f):Xa(0);return{width:n.width*x.x,height:n.height*x.y,x:n.x*x.x-f.scrollLeft*x.x+h.x+O.x,y:n.y*x.y-f.scrollTop*x.y+h.y+O.y}}function rF(t){return Array.from(t.getClientRects())}function oF(t){const s=Ja(t),n=Ix(t),a=t.ownerDocument.body,r=$n(s.scrollWidth,s.clientWidth,a.scrollWidth,a.clientWidth),l=$n(s.scrollHeight,s.clientHeight,a.scrollHeight,a.clientHeight);let c=-n.scrollLeft+zx(t);const A=-n.scrollTop;return Ca(a).direction==="rtl"&&(c+=$n(s.clientWidth,a.clientWidth)-r),{width:r,height:l,x:c,y:A}}const nj=25;function iF(t,s){const n=zn(t),a=Ja(t),r=n.visualViewport;let l=a.clientWidth,c=a.clientHeight,A=0,f=0;if(r){l=r.width,c=r.height;const h=bb();(!h||h&&s==="fixed")&&(A=r.offsetLeft,f=r.offsetTop)}const x=zx(a);if(x<=0){const h=a.ownerDocument,g=h.body,O=getComputedStyle(g),b=h.compatMode==="CSS1Compat"&&parseFloat(O.marginLeft)+parseFloat(O.marginRight)||0,v=Math.abs(a.clientWidth-g.clientWidth-b);v<=nj&&(l-=v)}else x<=nj&&(l+=x);return{width:l,height:c,x:A,y:f}}function lF(t,s){const n=Ci(t,!0,s==="fixed"),a=n.top+t.clientTop,r=n.left+t.clientLeft,l=Lr(t)?Zl(t):Xa(1),c=t.clientWidth*l.x,A=t.clientHeight*l.y,f=r*l.x,x=a*l.y;return{width:c,height:A,x:f,y:x}}function aj(t,s,n){let a;if(s==="viewport")a=iF(t,n);else if(s==="document")a=oF(Ja(t));else if(Sa(s))a=lF(s,n);else{const r=HN(t);a={x:s.x-r.x,y:s.y-r.y,width:s.width,height:s.height}}return nx(a)}function GN(t,s){const n=$o(t);return n===s||!Sa(n)||tc(n)?!1:Ca(n).position==="fixed"||GN(n,s)}function cF(t,s){const n=s.get(t);if(n)return n;let a=ZA(t,[],!1).filter(A=>Sa(A)&&mc(A)!=="body"),r=null;const l=Ca(t).position==="fixed";let c=l?$o(t):t;for(;Sa(c)&&!tc(c);){const A=Ca(c),f=Ob(c);!f&&A.position==="fixed"&&(r=null),(l?!f&&!r:!f&&A.position==="static"&&!!r&&(r.position==="absolute"||r.position==="fixed")||dd(c)&&!f&&GN(t,c))?a=a.filter(h=>h!==c):r=A,c=$o(c)}return s.set(t,a),a}function AF(t){let{element:s,boundary:n,rootBoundary:a,strategy:r}=t;const c=[...n==="clippingAncestors"?Mx(s)?[]:cF(s,this._c):[].concat(n),a],A=aj(s,c[0],r);let f=A.top,x=A.right,h=A.bottom,g=A.left;for(let O=1;O<c.length;O++){const b=aj(s,c[O],r);f=$n(b.top,f),x=Fo(b.right,x),h=Fo(b.bottom,h),g=$n(b.left,g)}return{width:x-g,height:h-f,x:g,y:f}}function dF(t){const{width:s,height:n}=LN(t);return{width:s,height:n}}function uF(t,s,n){const a=Lr(s),r=Ja(s),l=n==="fixed",c=Ci(t,!0,l,s);let A={scrollLeft:0,scrollTop:0};const f=Xa(0);function x(){f.x=zx(r)}if(a||!a&&!l)if((mc(s)!=="body"||dd(r))&&(A=Ix(s)),a){const b=Ci(s,!0,l,s);f.x=b.x+s.clientLeft,f.y=b.y+s.clientTop}else r&&x();l&&!a&&r&&x();const h=r&&!a&&!l?XN(r,A):Xa(0),g=c.left+A.scrollLeft-f.x-h.x,O=c.top+A.scrollTop-f.y-h.y;return{x:g,y:O,width:c.width,height:c.height}}function zp(t){return Ca(t).position==="static"}function rj(t,s){if(!Lr(t)||Ca(t).position==="fixed")return null;if(s)return s(t);let n=t.offsetParent;return Ja(t)===n&&(n=n.ownerDocument.body),n}function ZN(t,s){const n=zn(t);if(Mx(t))return n;if(!Lr(t)){let r=$o(t);for(;r&&!tc(r);){if(Sa(r)&&!zp(r))return r;r=$o(r)}return n}let a=rj(t,s);for(;a&&YP(a)&&zp(a);)a=rj(a,s);return a&&tc(a)&&zp(a)&&!Ob(a)?n:a||tF(t)||n}const fF=async function(t){const s=this.getOffsetParent||ZN,n=this.getDimensions,a=await n(t.floating);return{reference:uF(t.reference,await s(t.floating),t.strategy),floating:{x:0,y:0,width:a.width,height:a.height}}};function xF(t){return Ca(t).direction==="rtl"}const mF={convertOffsetParentRelativeRectToViewportRelativeRect:aF,getDocumentElement:Ja,getClippingRect:AF,getOffsetParent:ZN,getElementRects:fF,getClientRects:rF,getDimensions:dF,getScale:Zl,isElement:Sa,isRTL:xF};function VN(t,s){return t.x===s.x&&t.y===s.y&&t.width===s.width&&t.height===s.height}function hF(t,s){let n=null,a;const r=Ja(t);function l(){var A;clearTimeout(a),(A=n)==null||A.disconnect(),n=null}function c(A,f){A===void 0&&(A=!1),f===void 0&&(f=1),l();const x=t.getBoundingClientRect(),{left:h,top:g,width:O,height:b}=x;if(A||s(),!O||!b)return;const v=zu(g),y=zu(r.clientWidth-(h+O)),S=zu(r.clientHeight-(g+b)),j=zu(h),C={rootMargin:-v+"px "+-y+"px "+-S+"px "+-j+"px",threshold:$n(0,Fo(1,f))||1};let U=!0;function P(T){const B=T[0].intersectionRatio;if(B!==f){if(!U)return c();B?c(!1,B):a=setTimeout(()=>{c(!1,1e-7)},1e3)}B===1&&!VN(x,t.getBoundingClientRect())&&c(),U=!1}try{n=new IntersectionObserver(P,{...C,root:r.ownerDocument})}catch{n=new IntersectionObserver(P,C)}n.observe(t)}return c(!0),l}function pF(t,s,n,a){a===void 0&&(a={});const{ancestorScroll:r=!0,ancestorResize:l=!0,elementResize:c=typeof ResizeObserver=="function",layoutShift:A=typeof IntersectionObserver=="function",animationFrame:f=!1}=a,x=vb(t),h=r||l?[...x?ZA(x):[],...s?ZA(s):[]]:[];h.forEach(j=>{r&&j.addEventListener("scroll",n,{passive:!0}),l&&j.addEventListener("resize",n)});const g=x&&A?hF(x,n):null;let O=-1,b=null;c&&(b=new ResizeObserver(j=>{let[N]=j;N&&N.target===x&&b&&s&&(b.unobserve(s),cancelAnimationFrame(O),O=requestAnimationFrame(()=>{var C;(C=b)==null||C.observe(s)})),n()}),x&&!f&&b.observe(x),s&&b.observe(s));let v,y=f?Ci(t):null;f&&S();function S(){const j=Ci(t);y&&!VN(y,j)&&n(),y=j,v=requestAnimationFrame(S)}return n(),()=>{var j;h.forEach(N=>{r&&N.removeEventListener("scroll",n),l&&N.removeEventListener("resize",n)}),g==null||g(),(j=b)==null||j.disconnect(),b=null,f&&cancelAnimationFrame(v)}}const gF=VP,OF=KP,bF=XP,vF=WP,yF=GP,oj=HP,wF=qP,jF=(t,s,n)=>{const a=new Map,r={platform:mF,...n},l={...r.platform,_c:a};return LP(t,s,{...r,platform:l})};var QF=typeof document<"u",NF=function(){},Rf=QF?p.useLayoutEffect:NF;function ax(t,s){if(t===s)return!0;if(typeof t!=typeof s)return!1;if(typeof t=="function"&&t.toString()===s.toString())return!0;let n,a,r;if(t&&s&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==s.length)return!1;for(a=n;a--!==0;)if(!ax(t[a],s[a]))return!1;return!0}if(r=Object.keys(t),n=r.length,n!==Object.keys(s).length)return!1;for(a=n;a--!==0;)if(!{}.hasOwnProperty.call(s,r[a]))return!1;for(a=n;a--!==0;){const l=r[a];if(!(l==="_owner"&&t.$$typeof)&&!ax(t[l],s[l]))return!1}return!0}return t!==t&&s!==s}function KN(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function ij(t,s){const n=KN(t);return Math.round(s*n)/n}function _p(t){const s=p.useRef(t);return Rf(()=>{s.current=t}),s}function SF(t){t===void 0&&(t={});const{placement:s="bottom",strategy:n="absolute",middleware:a=[],platform:r,elements:{reference:l,floating:c}={},transform:A=!0,whileElementsMounted:f,open:x}=t,[h,g]=p.useState({x:0,y:0,strategy:n,placement:s,middlewareData:{},isPositioned:!1}),[O,b]=p.useState(a);ax(O,a)||b(a);const[v,y]=p.useState(null),[S,j]=p.useState(null),N=p.useCallback(H=>{H!==T.current&&(T.current=H,y(H))},[]),C=p.useCallback(H=>{H!==B.current&&(B.current=H,j(H))},[]),U=l||v,P=c||S,T=p.useRef(null),B=p.useRef(null),F=p.useRef(h),M=f!=null,R=_p(f),Y=_p(r),W=_p(x),ee=p.useCallback(()=>{if(!T.current||!B.current)return;const H={placement:s,strategy:n,middleware:O};Y.current&&(H.platform=Y.current),jF(T.current,B.current,H).then(I=>{const L={...I,isPositioned:W.current!==!1};K.current&&!ax(F.current,L)&&(F.current=L,Px.flushSync(()=>{g(L)}))})},[O,s,n,Y,W]);Rf(()=>{x===!1&&F.current.isPositioned&&(F.current.isPositioned=!1,g(H=>({...H,isPositioned:!1})))},[x]);const K=p.useRef(!1);Rf(()=>(K.current=!0,()=>{K.current=!1}),[]),Rf(()=>{if(U&&(T.current=U),P&&(B.current=P),U&&P){if(R.current)return R.current(U,P,ee);ee()}},[U,P,ee,R,M]);const _=p.useMemo(()=>({reference:T,floating:B,setReference:N,setFloating:C}),[N,C]),E=p.useMemo(()=>({reference:U,floating:P}),[U,P]),q=p.useMemo(()=>{const H={position:n,left:0,top:0};if(!E.floating)return H;const I=ij(E.floating,h.x),L=ij(E.floating,h.y);return A?{...H,transform:"translate("+I+"px, "+L+"px)",...KN(E.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:I,top:L}},[n,A,E.floating,h.x,h.y]);return p.useMemo(()=>({...h,update:ee,refs:_,elements:E,floatingStyles:q}),[h,ee,_,E,q])}const CF=t=>{function s(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:a,padding:r}=typeof t=="function"?t(n):t;return a&&s(a)?a.current!=null?oj({element:a.current,padding:r}).fn(n):{}:a?oj({element:a,padding:r}).fn(n):{}}}},BF=(t,s)=>{const n=gF(t);return{name:n.name,fn:n.fn,options:[t,s]}},kF=(t,s)=>{const n=OF(t);return{name:n.name,fn:n.fn,options:[t,s]}},TF=(t,s)=>({fn:wF(t).fn,options:[t,s]}),UF=(t,s)=>{const n=bF(t);return{name:n.name,fn:n.fn,options:[t,s]}},EF=(t,s)=>{const n=vF(t);return{name:n.name,fn:n.fn,options:[t,s]}},PF=(t,s)=>{const n=yF(t);return{name:n.name,fn:n.fn,options:[t,s]}},FF=(t,s)=>{const n=CF(t);return{name:n.name,fn:n.fn,options:[t,s]}};var $F="Arrow",qN=p.forwardRef((t,s)=>{const{children:n,width:a=10,height:r=5,...l}=t;return e.jsx(et.svg,{...l,ref:s,width:a,height:r,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:e.jsx("polygon",{points:"0,0 30,0 15,10"})})});qN.displayName=$F;var RF=qN;function MF(t){const[s,n]=p.useState(void 0);return Ds(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const a=new ResizeObserver(r=>{if(!Array.isArray(r)||!r.length)return;const l=r[0];let c,A;if("borderBoxSize"in l){const f=l.borderBoxSize,x=Array.isArray(f)?f[0]:f;c=x.inlineSize,A=x.blockSize}else c=t.offsetWidth,A=t.offsetHeight;n({width:c,height:A})});return a.observe(t,{box:"border-box"}),()=>a.unobserve(t)}else n(void 0)},[t]),s}var yb="Popper",[WN,hc]=Ya(yb),[IF,YN]=WN(yb),JN=t=>{const{__scopePopper:s,children:n}=t,[a,r]=p.useState(null);return e.jsx(IF,{scope:s,anchor:a,onAnchorChange:r,children:n})};JN.displayName=yb;var eS="PopperAnchor",tS=p.forwardRef((t,s)=>{const{__scopePopper:n,virtualRef:a,...r}=t,l=YN(eS,n),c=p.useRef(null),A=mt(s,c),f=p.useRef(null);return p.useEffect(()=>{const x=f.current;f.current=(a==null?void 0:a.current)||c.current,x!==f.current&&l.onAnchorChange(f.current)}),a?null:e.jsx(et.div,{...r,ref:A})});tS.displayName=eS;var wb="PopperContent",[zF,_F]=WN(wb),sS=p.forwardRef((t,s)=>{var ae,be,z,oe,ue,ve;const{__scopePopper:n,side:a="bottom",sideOffset:r=0,align:l="center",alignOffset:c=0,arrowPadding:A=0,avoidCollisions:f=!0,collisionBoundary:x=[],collisionPadding:h=0,sticky:g="partial",hideWhenDetached:O=!1,updatePositionStrategy:b="optimized",onPlaced:v,...y}=t,S=YN(wb,n),[j,N]=p.useState(null),C=mt(s,Ce=>N(Ce)),[U,P]=p.useState(null),T=MF(U),B=(T==null?void 0:T.width)??0,F=(T==null?void 0:T.height)??0,M=a+(l!=="center"?"-"+l:""),R=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},Y=Array.isArray(x)?x:[x],W=Y.length>0,ee={padding:R,boundary:Y.filter(LF),altBoundary:W},{refs:K,floatingStyles:_,placement:E,isPositioned:q,middlewareData:H}=SF({strategy:"fixed",placement:M,whileElementsMounted:(...Ce)=>pF(...Ce,{animationFrame:b==="always"}),elements:{reference:S.anchor},middleware:[BF({mainAxis:r+F,alignmentAxis:c}),f&&kF({mainAxis:!0,crossAxis:!1,limiter:g==="partial"?TF():void 0,...ee}),f&&UF({...ee}),EF({...ee,apply:({elements:Ce,rects:Ne,availableWidth:Xe,availableHeight:Fe})=>{const{width:Ae,height:ke}=Ne.reference,Re=Ce.floating.style;Re.setProperty("--radix-popper-available-width",`${Xe}px`),Re.setProperty("--radix-popper-available-height",`${Fe}px`),Re.setProperty("--radix-popper-anchor-width",`${Ae}px`),Re.setProperty("--radix-popper-anchor-height",`${ke}px`)}}),U&&FF({element:U,padding:A}),HF({arrowWidth:B,arrowHeight:F}),O&&PF({strategy:"referenceHidden",...ee})]}),[I,L]=rS(E),J=Us(v);Ds(()=>{q&&(J==null||J())},[q,J]);const D=(ae=H.arrow)==null?void 0:ae.x,se=(be=H.arrow)==null?void 0:be.y,le=((z=H.arrow)==null?void 0:z.centerOffset)!==0,[V,te]=p.useState();return Ds(()=>{j&&te(window.getComputedStyle(j).zIndex)},[j]),e.jsx("div",{ref:K.setFloating,"data-radix-popper-content-wrapper":"",style:{..._,transform:q?_.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:V,"--radix-popper-transform-origin":[(oe=H.transformOrigin)==null?void 0:oe.x,(ue=H.transformOrigin)==null?void 0:ue.y].join(" "),...((ve=H.hide)==null?void 0:ve.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:e.jsx(zF,{scope:n,placedSide:I,onArrowChange:P,arrowX:D,arrowY:se,shouldHideArrow:le,children:e.jsx(et.div,{"data-side":I,"data-align":L,...y,ref:C,style:{...y.style,animation:q?void 0:"none"}})})})});sS.displayName=wb;var nS="PopperArrow",DF={top:"bottom",right:"left",bottom:"top",left:"right"},aS=p.forwardRef(function(s,n){const{__scopePopper:a,...r}=s,l=_F(nS,a),c=DF[l.placedSide];return e.jsx("span",{ref:l.onArrowChange,style:{position:"absolute",left:l.arrowX,top:l.arrowY,[c]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[l.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[l.placedSide],visibility:l.shouldHideArrow?"hidden":void 0},children:e.jsx(RF,{...r,ref:n,style:{...r.style,display:"block"}})})});aS.displayName=nS;function LF(t){return t!==null}var HF=t=>({name:"transformOrigin",options:t,fn(s){var S,j,N;const{placement:n,rects:a,middlewareData:r}=s,c=((S=r.arrow)==null?void 0:S.centerOffset)!==0,A=c?0:t.arrowWidth,f=c?0:t.arrowHeight,[x,h]=rS(n),g={start:"0%",center:"50%",end:"100%"}[h],O=(((j=r.arrow)==null?void 0:j.x)??0)+A/2,b=(((N=r.arrow)==null?void 0:N.y)??0)+f/2;let v="",y="";return x==="bottom"?(v=c?g:`${O}px`,y=`${-f}px`):x==="top"?(v=c?g:`${O}px`,y=`${a.floating.height+f}px`):x==="right"?(v=`${-f}px`,y=c?g:`${b}px`):x==="left"&&(v=`${a.floating.width+f}px`,y=c?g:`${b}px`),{data:{x:v,y}}}});function rS(t){const[s,n="center"]=t.split("-");return[s,n]}var jb=JN,Qb=tS,Nb=sS,Sb=aS,XF="Portal",ud=p.forwardRef((t,s)=>{var A;const{container:n,...a}=t,[r,l]=p.useState(!1);Ds(()=>l(!0),[]);const c=n||r&&((A=globalThis==null?void 0:globalThis.document)==null?void 0:A.body);return c?SU.createPortal(e.jsx(et.div,{...a,ref:s}),c):null});ud.displayName=XF;function GF(t,s){return p.useReducer((n,a)=>s[n][a]??n,t)}var ln=t=>{const{present:s,children:n}=t,a=ZF(s),r=typeof n=="function"?n({present:a.isPresent}):p.Children.only(n),l=mt(a.ref,VF(r));return typeof n=="function"||a.isPresent?p.cloneElement(r,{ref:l}):null};ln.displayName="Presence";function ZF(t){const[s,n]=p.useState(),a=p.useRef(null),r=p.useRef(t),l=p.useRef("none"),c=t?"mounted":"unmounted",[A,f]=GF(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return p.useEffect(()=>{const x=_u(a.current);l.current=A==="mounted"?x:"none"},[A]),Ds(()=>{const x=a.current,h=r.current;if(h!==t){const O=l.current,b=_u(x);t?f("MOUNT"):b==="none"||(x==null?void 0:x.display)==="none"?f("UNMOUNT"):f(h&&O!==b?"ANIMATION_OUT":"UNMOUNT"),r.current=t}},[t,f]),Ds(()=>{if(s){let x;const h=s.ownerDocument.defaultView??window,g=b=>{const y=_u(a.current).includes(CSS.escape(b.animationName));if(b.target===s&&y&&(f("ANIMATION_END"),!r.current)){const S=s.style.animationFillMode;s.style.animationFillMode="forwards",x=h.setTimeout(()=>{s.style.animationFillMode==="forwards"&&(s.style.animationFillMode=S)})}},O=b=>{b.target===s&&(l.current=_u(a.current))};return s.addEventListener("animationstart",O),s.addEventListener("animationcancel",g),s.addEventListener("animationend",g),()=>{h.clearTimeout(x),s.removeEventListener("animationstart",O),s.removeEventListener("animationcancel",g),s.removeEventListener("animationend",g)}}else f("ANIMATION_END")},[s,f]),{isPresent:["mounted","unmountSuspended"].includes(A),ref:p.useCallback(x=>{a.current=x?getComputedStyle(x):null,n(x)},[])}}function _u(t){return(t==null?void 0:t.animationName)||"none"}function VF(t){var a,r;let s=(a=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:a.get,n=s&&"isReactWarning"in s&&s.isReactWarning;return n?t.ref:(s=(r=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:r.get,n=s&&"isReactWarning"in s&&s.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var KF=oN[" useInsertionEffect ".trim().toString()]||Ds;function sc({prop:t,defaultProp:s,onChange:n=()=>{},caller:a}){const[r,l,c]=qF({defaultProp:s,onChange:n}),A=t!==void 0,f=A?t:r;{const h=p.useRef(t!==void 0);p.useEffect(()=>{const g=h.current;g!==A&&console.warn(`${a} is changing from ${g?"controlled":"uncontrolled"} to ${A?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),h.current=A},[A,a])}const x=p.useCallback(h=>{var g;if(A){const O=WF(h)?h(t):h;O!==t&&((g=c.current)==null||g.call(c,O))}else l(h)},[A,t,l,c]);return[f,x]}function qF({defaultProp:t,onChange:s}){const[n,a]=p.useState(t),r=p.useRef(n),l=p.useRef(s);return KF(()=>{l.current=s},[s]),p.useEffect(()=>{var c;r.current!==n&&((c=l.current)==null||c.call(l,n),r.current=n)},[n,r]),[n,a,l]}function WF(t){return typeof t=="function"}var oS=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),YF="VisuallyHidden",iS=p.forwardRef((t,s)=>e.jsx(et.span,{...t,ref:s,style:{...oS,...t.style}}));iS.displayName=YF;var JF=iS,[_x]=Ya("Tooltip",[hc]),Dx=hc(),lS="TooltipProvider",e$=700,lO="tooltip.open",[t$,Cb]=_x(lS),cS=t=>{const{__scopeTooltip:s,delayDuration:n=e$,skipDelayDuration:a=300,disableHoverableContent:r=!1,children:l}=t,c=p.useRef(!0),A=p.useRef(!1),f=p.useRef(0);return p.useEffect(()=>{const x=f.current;return()=>window.clearTimeout(x)},[]),e.jsx(t$,{scope:s,isOpenDelayedRef:c,delayDuration:n,onOpen:p.useCallback(()=>{window.clearTimeout(f.current),c.current=!1},[]),onClose:p.useCallback(()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>c.current=!0,a)},[a]),isPointerInTransitRef:A,onPointerInTransitChange:p.useCallback(x=>{A.current=x},[]),disableHoverableContent:r,children:l})};cS.displayName=lS;var VA="Tooltip",[s$,fd]=_x(VA),AS=t=>{const{__scopeTooltip:s,children:n,open:a,defaultOpen:r,onOpenChange:l,disableHoverableContent:c,delayDuration:A}=t,f=Cb(VA,t.__scopeTooltip),x=Dx(s),[h,g]=p.useState(null),O=$r(),b=p.useRef(0),v=c??f.disableHoverableContent,y=A??f.delayDuration,S=p.useRef(!1),[j,N]=sc({prop:a,defaultProp:r??!1,onChange:B=>{B?(f.onOpen(),document.dispatchEvent(new CustomEvent(lO))):f.onClose(),l==null||l(B)},caller:VA}),C=p.useMemo(()=>j?S.current?"delayed-open":"instant-open":"closed",[j]),U=p.useCallback(()=>{window.clearTimeout(b.current),b.current=0,S.current=!1,N(!0)},[N]),P=p.useCallback(()=>{window.clearTimeout(b.current),b.current=0,N(!1)},[N]),T=p.useCallback(()=>{window.clearTimeout(b.current),b.current=window.setTimeout(()=>{S.current=!0,N(!0),b.current=0},y)},[y,N]);return p.useEffect(()=>()=>{b.current&&(window.clearTimeout(b.current),b.current=0)},[]),e.jsx(jb,{...x,children:e.jsx(s$,{scope:s,contentId:O,open:j,stateAttribute:C,trigger:h,onTriggerChange:g,onTriggerEnter:p.useCallback(()=>{f.isOpenDelayedRef.current?T():U()},[f.isOpenDelayedRef,T,U]),onTriggerLeave:p.useCallback(()=>{v?P():(window.clearTimeout(b.current),b.current=0)},[P,v]),onOpen:U,onClose:P,disableHoverableContent:v,children:n})})};AS.displayName=VA;var cO="TooltipTrigger",dS=p.forwardRef((t,s)=>{const{__scopeTooltip:n,...a}=t,r=fd(cO,n),l=Cb(cO,n),c=Dx(n),A=p.useRef(null),f=mt(s,A,r.onTriggerChange),x=p.useRef(!1),h=p.useRef(!1),g=p.useCallback(()=>x.current=!1,[]);return p.useEffect(()=>()=>document.removeEventListener("pointerup",g),[g]),e.jsx(Qb,{asChild:!0,...c,children:e.jsx(et.button,{"aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute,...a,ref:f,onPointerMove:Ue(t.onPointerMove,O=>{O.pointerType!=="touch"&&!h.current&&!l.isPointerInTransitRef.current&&(r.onTriggerEnter(),h.current=!0)}),onPointerLeave:Ue(t.onPointerLeave,()=>{r.onTriggerLeave(),h.current=!1}),onPointerDown:Ue(t.onPointerDown,()=>{r.open&&r.onClose(),x.current=!0,document.addEventListener("pointerup",g,{once:!0})}),onFocus:Ue(t.onFocus,()=>{x.current||r.onOpen()}),onBlur:Ue(t.onBlur,r.onClose),onClick:Ue(t.onClick,r.onClose)})})});dS.displayName=cO;var Bb="TooltipPortal",[n$,a$]=_x(Bb,{forceMount:void 0}),uS=t=>{const{__scopeTooltip:s,forceMount:n,children:a,container:r}=t,l=fd(Bb,s);return e.jsx(n$,{scope:s,forceMount:n,children:e.jsx(ln,{present:n||l.open,children:e.jsx(ud,{asChild:!0,container:r,children:a})})})};uS.displayName=Bb;var nc="TooltipContent",fS=p.forwardRef((t,s)=>{const n=a$(nc,t.__scopeTooltip),{forceMount:a=n.forceMount,side:r="top",...l}=t,c=fd(nc,t.__scopeTooltip);return e.jsx(ln,{present:a||c.open,children:c.disableHoverableContent?e.jsx(xS,{side:r,...l,ref:s}):e.jsx(r$,{side:r,...l,ref:s})})}),r$=p.forwardRef((t,s)=>{const n=fd(nc,t.__scopeTooltip),a=Cb(nc,t.__scopeTooltip),r=p.useRef(null),l=mt(s,r),[c,A]=p.useState(null),{trigger:f,onClose:x}=n,h=r.current,{onPointerInTransitChange:g}=a,O=p.useCallback(()=>{A(null),g(!1)},[g]),b=p.useCallback((v,y)=>{const S=v.currentTarget,j={x:v.clientX,y:v.clientY},N=c$(j,S.getBoundingClientRect()),C=A$(j,N),U=d$(y.getBoundingClientRect()),P=f$([...C,...U]);A(P),g(!0)},[g]);return p.useEffect(()=>()=>O(),[O]),p.useEffect(()=>{if(f&&h){const v=S=>b(S,h),y=S=>b(S,f);return f.addEventListener("pointerleave",v),h.addEventListener("pointerleave",y),()=>{f.removeEventListener("pointerleave",v),h.removeEventListener("pointerleave",y)}}},[f,h,b,O]),p.useEffect(()=>{if(c){const v=y=>{const S=y.target,j={x:y.clientX,y:y.clientY},N=(f==null?void 0:f.contains(S))||(h==null?void 0:h.contains(S)),C=!u$(j,c);N?O():C&&(O(),x())};return document.addEventListener("pointermove",v),()=>document.removeEventListener("pointermove",v)}},[f,h,c,x,O]),e.jsx(xS,{...t,ref:l})}),[o$,i$]=_x(VA,{isInside:!1}),l$=pP("TooltipContent"),xS=p.forwardRef((t,s)=>{const{__scopeTooltip:n,children:a,"aria-label":r,onEscapeKeyDown:l,onPointerDownOutside:c,...A}=t,f=fd(nc,n),x=Dx(n),{onClose:h}=f;return p.useEffect(()=>(document.addEventListener(lO,h),()=>document.removeEventListener(lO,h)),[h]),p.useEffect(()=>{if(f.trigger){const g=O=>{const b=O.target;b!=null&&b.contains(f.trigger)&&h()};return window.addEventListener("scroll",g,{capture:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})}},[f.trigger,h]),e.jsx(Ad,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:h,children:e.jsxs(Nb,{"data-state":f.stateAttribute,...x,...A,ref:s,style:{...A.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[e.jsx(l$,{children:a}),e.jsx(o$,{scope:n,isInside:!0,children:e.jsx(JF,{id:f.contentId,role:"tooltip",children:r||a})})]})})});fS.displayName=nc;var mS="TooltipArrow",hS=p.forwardRef((t,s)=>{const{__scopeTooltip:n,...a}=t,r=Dx(n);return i$(mS,n).isInside?null:e.jsx(Sb,{...r,...a,ref:s})});hS.displayName=mS;function c$(t,s){const n=Math.abs(s.top-t.y),a=Math.abs(s.bottom-t.y),r=Math.abs(s.right-t.x),l=Math.abs(s.left-t.x);switch(Math.min(n,a,r,l)){case l:return"left";case r:return"right";case n:return"top";case a:return"bottom";default:throw new Error("unreachable")}}function A$(t,s,n=5){const a=[];switch(s){case"top":a.push({x:t.x-n,y:t.y+n},{x:t.x+n,y:t.y+n});break;case"bottom":a.push({x:t.x-n,y:t.y-n},{x:t.x+n,y:t.y-n});break;case"left":a.push({x:t.x+n,y:t.y-n},{x:t.x+n,y:t.y+n});break;case"right":a.push({x:t.x-n,y:t.y-n},{x:t.x-n,y:t.y+n});break}return a}function d$(t){const{top:s,right:n,bottom:a,left:r}=t;return[{x:r,y:s},{x:n,y:s},{x:n,y:a},{x:r,y:a}]}function u$(t,s){const{x:n,y:a}=t;let r=!1;for(let l=0,c=s.length-1;l<s.length;c=l++){const A=s[l],f=s[c],x=A.x,h=A.y,g=f.x,O=f.y;h>a!=O>a&&n<(g-x)*(a-h)/(O-h)+x&&(r=!r)}return r}function f$(t){const s=t.slice();return s.sort((n,a)=>n.x<a.x?-1:n.x>a.x?1:n.y<a.y?-1:n.y>a.y?1:0),x$(s)}function x$(t){if(t.length<=1)return t.slice();const s=[];for(let a=0;a<t.length;a++){const r=t[a];for(;s.length>=2;){const l=s[s.length-1],c=s[s.length-2];if((l.x-c.x)*(r.y-c.y)>=(l.y-c.y)*(r.x-c.x))s.pop();else break}s.push(r)}s.pop();const n=[];for(let a=t.length-1;a>=0;a--){const r=t[a];for(;n.length>=2;){const l=n[n.length-1],c=n[n.length-2];if((l.x-c.x)*(r.y-c.y)>=(l.y-c.y)*(r.x-c.x))n.pop();else break}n.push(r)}return n.pop(),s.length===1&&n.length===1&&s[0].x===n[0].x&&s[0].y===n[0].y?s:s.concat(n)}var m$=cS,h$=AS,p$=dS,g$=uS,O$=fS,b$=hS;function v$({children:t}){return e.jsx(m$,{delayDuration:300,children:t})}function dt({children:t,content:s,side:n="top",className:a}){return s?e.jsxs(h$,{children:[e.jsx(p$,{asChild:!0,children:t}),e.jsx(g$,{children:e.jsxs(O$,{side:n,sideOffset:6,className:Z("z-50 px-2.5 py-1.5 text-xs font-sans","bg-surface-4 text-text-0 border border-border rounded-md shadow-lg","animate-in fade-in-0 zoom-in-95",a),children:[s,e.jsx(b$,{className:"fill-surface-4"})]})})]}):t}/**
45
45
  * @license lucide-react v1.11.0 - ISC
46
46
  *
47
47
  * This source code is licensed under the ISC license.
@@ -1009,7 +1009,7 @@ ${I.join(`
1009
1009
  [&::-moz-range-thumb]:bg-accent [&::-moz-range-thumb]:border-none
1010
1010
  [&::-moz-range-thumb]:shadow-[0_0_0_2px_var(--color-surface-1)]
1011
1011
  [&::-moz-range-track]:bg-transparent
1012
- disabled:cursor-not-allowed`})]}),e.jsx("span",{className:"text-[11px] text-accent font-mono font-medium w-9 text-right shrink-0 tabular-nums",children:O})]})}const xee={backend:Ns,frontend:md,fullstack:bn,testing:Wx,security:vn},mee=new Set(["codex","grok","local"]),hee=/^[a-zA-Z0-9_-]{1,64}$/;function pee(t){return t.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,64)}function qf(){var H;const t=k(I=>I.recommendedTeam),s=k(I=>I.launchRecommendedTeam),n=k(I=>I.teamLaunchConfig),a=k(I=>I.fetchProviders),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState([]),[O,b]=p.useState((n==null?void 0:n.provider)||""),[v,y]=p.useState((n==null?void 0:n.model)||""),[S,j]=p.useState((n==null?void 0:n.reasoningEffort)??50),[N,C]=p.useState((n==null?void 0:n.temperature)??.5),[U,P]=p.useState(null);if(p.useEffect(()=>{a().then(I=>{Array.isArray(I)&&g(I.filter(L=>L.installed))}).catch(()=>{})},[]),!((H=t==null?void 0:t.agents)!=null&&H.length))return null;const T=t.agents,B=T.filter(I=>!I.phase||I.phase===1),F=T.filter(I=>I.phase===2),M=c??B.map(I=>({...I,name:I.name||""})),R=h.find(I=>I.id===O),Y=((R==null?void 0:R.models)||[]).filter(I=>I.type!=="image"&&!I.disabled),W=mee.has(O);function ee(I,L){const J=M.map((D,se)=>se===I?{...D,name:pee(L)}:D);A(J)}function K(I,L){if(typeof L=="string"){const[J,D]=[L,arguments[2]];A(se=>(se??M).map((le,V)=>V===I?{...le,[J]:D}:le))}else A(J=>(J??M).map((D,se)=>se===I?{...D,...L}:D))}function _(I){var D;b(I);const L=h.find(se=>se.id===I),J=((L==null?void 0:L.models)||[]).filter(se=>se.type!=="image"&&!se.disabled);y(((D=J[0])==null?void 0:D.id)||"")}async function E(){l(!0),k.setState({teamLaunchConfig:{...O&&{provider:O,model:v},reasoningEffort:S,...W&&{temperature:N}}});try{const I=[...M,...F];await s(I)}catch{}l(!1)}function q(){k.setState({recommendedTeam:null})}return e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 z-50 w-full max-w-lg",children:e.jsxs("div",{className:"mx-4 rounded-lg border border-accent/30 bg-surface-2/95 backdrop-blur-md shadow-xl shadow-accent/5 overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center gap-2",children:[e.jsx(Ei,{size:16,className:"text-accent"}),e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Planner Recommends a Team"}),e.jsx("button",{onClick:q,className:"text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:14})})]}),e.jsxs("div",{className:"border-b border-border-subtle",children:[e.jsxs("button",{onClick:()=>x(!f),className:"w-full flex items-center gap-2 px-4 py-2 text-left cursor-pointer hover:bg-surface-3/50 transition-colors",children:[e.jsx(xt,{size:12,className:Z("text-text-4 transition-transform duration-200",!f&&"-rotate-90")}),e.jsx(DS,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider",children:"Team Settings"}),O&&e.jsxs("span",{className:"ml-auto text-2xs text-accent font-mono",children:[O,v?` / ${v}`:""]})]}),f&&e.jsxs("div",{className:"px-4 pb-3 space-y-3",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:O,onValueChange:_,children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-4 h-7 text-xs"}),e.jsx(In,{children:h.map(I=>e.jsx(ms,{value:I.id,children:I.displayName||I.name||I.id},I.id))})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:v,onValueChange:y,children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-4 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"auto",children:"Auto"}),Y.map(I=>e.jsx(ms,{value:I.id,children:I.name||I.id},I.id))]})]})]})]}),e.jsx(Ka,{label:"Reasoning",value:S,onChange:j,min:0,max:100,step:1}),W&&e.jsx(Ka,{label:"Temperature",value:N,onChange:C,min:0,max:1,step:.01,formatValue:I=>I.toFixed(2)})]})]}),e.jsxs("div",{className:"px-4 py-3 space-y-1.5",children:[M.map((I,L)=>{var te;const J=xee[I.role]||bn,D=!I.name||hee.test(I.name),se=U===L,le=h.find(ae=>ae.id===(I.provider||O)),V=((le==null?void 0:le.models)||[]).filter(ae=>ae.type!=="image"&&!ae.disabled);return e.jsxs("div",{className:"rounded-md bg-surface-4 border border-border-subtle overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 cursor-pointer hover:bg-surface-5/50 transition-colors",onClick:()=>P(se?null:L),children:[e.jsx(J,{size:12,className:"text-text-2 shrink-0"}),e.jsx("input",{type:"text",value:I.name,onChange:ae=>ee(L,ae.target.value),onClick:ae=>ae.stopPropagation(),placeholder:I.role,className:Z("flex-1 min-w-0 bg-transparent text-xs font-mono text-text-0 outline-none placeholder:text-text-4",!D&&"text-red-400"),maxLength:64,spellCheck:!1}),I.provider&&I.provider!==O&&e.jsx("span",{className:"text-2xs text-accent font-mono shrink-0",children:I.provider}),((te=I.scope)==null?void 0:te.length)>0&&e.jsxs("span",{className:"text-2xs text-text-4 font-mono shrink-0 truncate max-w-[120px]",children:[I.scope[0],I.scope.length>1?` +${I.scope.length-1}`:""]}),e.jsx(xt,{size:10,className:Z("text-text-4 shrink-0 transition-transform duration-200",!se&&"-rotate-90")})]}),se&&e.jsxs("div",{className:"px-2.5 pb-2.5 pt-1 space-y-2.5 border-t border-border-subtle",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(ka,{size:10}),"Provider"]}),e.jsxs(Rn,{value:I.provider||"",onValueChange:ae=>{var oe;const be=h.find(ue=>ue.id===ae),z=((be==null?void 0:be.models)||[]).filter(ue=>ue.type!=="image"&&!ue.disabled);K(L,{provider:ae,model:((oe=z[0])==null?void 0:oe.id)||""})},children:[e.jsx(Mn,{placeholder:"Team default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"",children:"Team default"}),h.map(ae=>e.jsx(ms,{value:ae.id,children:ae.displayName||ae.name||ae.id},ae.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:I.model||"",onValueChange:ae=>K(L,"model",ae),children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"",children:"Auto"}),V.map(ae=>e.jsx(ms,{value:ae.id,children:ae.name||ae.id},ae.id))]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(Ro,{size:10}),"Model Routing"]}),e.jsx("div",{className:"flex bg-surface-3 rounded-md p-0.5 border border-border-subtle",children:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}].map(ae=>e.jsx("button",{onClick:()=>K(L,"routingMode",ae.value),className:Z("flex-1 px-2 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(I.routingMode||"auto")===ae.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae.label},ae.value))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(SS,{size:10}),"Effort Level"]}),e.jsx("div",{className:"flex bg-surface-3 rounded-md p-0.5 border border-border-subtle",children:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"},{value:"ultra",label:"Ultra"}].map(ae=>e.jsx("button",{onClick:()=>K(L,"effort",ae.value),className:Z("flex-1 px-1.5 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(I.effort||"default")===ae.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae.label},ae.value))})]})]})]},L)}),t.projectDir&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-2 font-mono pt-0.5",children:[e.jsx("span",{className:"text-text-4",children:"Project:"}),e.jsxs("span",{className:"text-accent",children:[t.projectDir,"/"]})]}),F.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans",children:[e.jsx(vn,{size:10}),e.jsxs("span",{children:[F.length," QC agent",F.length>1?"s":""," will auto-spawn after builders complete"]})]})]}),e.jsx("div",{className:"px-4 py-3 border-t border-border-subtle",children:e.jsxs(pe,{variant:"primary",size:"md",onClick:E,disabled:r,className:"w-full gap-2",children:[e.jsx(qt,{size:14}),r?"Launching...":`Launch ${B.length} Agent${B.length>1?"s":""}`]})})]})})}const gee={agentNode:SC,rootNode:CC},Ig=220,zg=82,wf=260,jf=130,po=4,Xs="__groove_root__";function FA(t){if(!t)return{};try{return JSON.parse(localStorage.getItem(`groove:nodePositions:${t}`)||"{}")}catch{return{}}}function B4(){let t=!1;for(const s of["groove:chatHistory","groove:activityLog"])localStorage.getItem(s)!==null&&(localStorage.removeItem(s),t=!0);return t}function QQ(t,s){if(!t)return;const n=`groove:nodePositions:${t}`,a=JSON.stringify(s);try{localStorage.setItem(n,a);return}catch{}if(B4())try{localStorage.setItem(n,a)}catch{}}function k4(){try{return JSON.parse(localStorage.getItem("groove:roleLayout")||"{}")}catch{return{}}}function Oee(t){const s="groove:roleLayout",n=JSON.stringify(t);try{localStorage.setItem(s,n);return}catch{}if(B4())try{localStorage.setItem(s,n)}catch{}}function T4(){try{return JSON.parse(localStorage.getItem("groove:teamViewports")||"{}")}catch{return{}}}function bee(t,s){try{const n=T4();n[t]=s,localStorage.setItem("groove:teamViewports",JSON.stringify(n))}catch{}}function vee(t,s){const n=t.filter(c=>{var A;return c.teamId===s&&!((A=c.metadata)!=null&&A.scheduled)});return n.length===0?"idle":n.some(c=>c.status==="running"||c.status==="starting")?"working":n.every(c=>c.status==="completed")?"completed":n.some(c=>c.status==="crashed")?"crashed":"idle"}function yee(){const t=k(E=>E.teams),s=k(E=>E.activeTeamId),n=k(E=>E.agents),a=k(E=>E.switchTeam),r=k(E=>E.createTeam),l=k(E=>E.deleteTeamPermanently),c=k(E=>E.renameTeam),A=k(E=>E.cloneTeam),f=k(E=>E.reorderTeams),x=k(E=>E.addToast),[h,g]=p.useState(!1),[O,b]=p.useState(""),[v,y]=p.useState(null),[S,j]=p.useState(""),N=p.useRef(!1),[C,U]=p.useState(null),[P,T]=p.useState(null),B=p.useRef(null),[F,M]=p.useState(!1),[R,Y]=p.useState(!1),W=p.useCallback(()=>{const E=B.current;E&&(M(E.scrollLeft>0),Y(E.scrollLeft+E.clientWidth<E.scrollWidth-1))},[]);p.useEffect(()=>{const E=B.current;if(!E)return;W(),E.addEventListener("scroll",W);const q=new ResizeObserver(W);return q.observe(E),()=>{E.removeEventListener("scroll",W),q.disconnect()}},[W,t.length]);function ee(){const E=O.trim();!E||N.current||(N.current=!0,b(""),g(!1),r(E).finally(()=>{N.current=!1,setTimeout(()=>{B.current&&B.current.scrollTo({left:B.current.scrollWidth,behavior:"smooth"})},100)}))}function K(E){y(E.id),j(E.name)}function _(){const E=S.trim();if(!E||!v){y(null);return}c(v,E),y(null)}return e.jsxs("div",{className:"flex items-end px-0 pt-0 pb-0 bg-surface-1 border-b border-border gap-0 flex-shrink-0 overflow-hidden",children:[F&&e.jsx("button",{onClick:()=>{var E;return(E=B.current)==null?void 0:E.scrollBy({left:-300,behavior:"smooth"})},className:"w-6 h-9 flex items-center justify-center bg-accent/15 text-accent hover:bg-accent/25 transition-colors flex-shrink-0 cursor-pointer",children:e.jsx(Di,{size:14})}),e.jsxs("div",{ref:B,className:"flex items-end flex-1 min-w-0 overflow-x-auto gap-0",style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},children:[t.map(E=>{const q=n.filter(J=>{var D;return J.teamId===E.id&&!((D=J.metadata)!=null&&D.scheduled)}).length,H=E.id===s,I=v===E.id,L=n.filter(J=>{var D;return J.teamId===E.id&&!((D=J.metadata)!=null&&D.scheduled)&&(J.status==="running"||J.status==="starting")}).length;return e.jsxs(Uv,{children:[e.jsx(Ev,{asChild:!0,children:e.jsxs("div",{draggable:!I,onDragStart:J=>{U(E.id),J.dataTransfer.effectAllowed="move",J.dataTransfer.setData("text/plain","")},onDragEnd:()=>{U(null),T(null)},onDragOver:J=>{J.preventDefault(),J.dataTransfer.dropEffect="move",C&&C!==E.id&&T(E.id)},onDragLeave:()=>{P===E.id&&T(null)},onDrop:J=>{if(J.preventDefault(),!C||C===E.id)return;const D=t.findIndex(le=>le.id===C),se=t.findIndex(le=>le.id===E.id);D!==-1&&se!==-1&&f(D,se),U(null),T(null)},onClick:()=>!I&&a(E.id),onDoubleClick:()=>K(E),className:Z("relative flex items-center gap-2 px-3 h-9 text-xs font-sans cursor-pointer select-none transition-colors flex-shrink-0",H?"text-text-0 font-semibold border-x border-x-[#242830] bg-[#242830]":"text-text-3 hover:text-text-1 hover:bg-surface-3/50",C===E.id&&"opacity-40",P===E.id&&C!==E.id&&"border-l-2 !border-l-accent"),children:[H&&e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-accent",style:{height:"0.5px"}}),(()=>{const J=vee(n,E.id),D=J==="working"||J==="completed"?"text-green-400":J==="crashed"?"text-red-400":H?"text-accent":"text-text-4";return e.jsxs("span",{className:"relative flex-shrink-0",children:[e.jsx(yn,{size:13,className:Z(D,J==="working"&&"animate-pulse")}),J==="working"&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 w-1.5 h-1.5 rounded-full bg-green-400 animate-pulse"})]})})(),I?e.jsx("input",{value:S,onChange:J=>j(J.target.value),onKeyDown:J=>{J.key==="Enter"&&_(),J.key==="Escape"&&y(null)},onBlur:_,className:"h-5 w-24 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none",autoFocus:!0,onClick:J=>J.stopPropagation()}):e.jsx("span",{className:"truncate max-w-[120px]",children:E.name}),q>0&&!I&&e.jsx("span",{className:Z("flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-2xs font-mono font-semibold",L>0?"bg-accent/15 text-accent":"bg-surface-4 text-text-3"),children:q}),H&&e.jsx("div",{className:"absolute bottom-[-1px] left-0 right-0 h-px bg-[#242830]"})]})}),e.jsxs(Pv,{children:[e.jsxs(ya,{onSelect:()=>K(E),children:[e.jsx(Ua,{size:12})," Rename"]}),e.jsxs(ya,{onSelect:()=>A(E.id),children:[e.jsx(Ba,{size:12})," Clone"]}),e.jsx(Fv,{}),e.jsxs(ya,{danger:!0,onSelect:()=>{if(n.filter(D=>D.teamId===E.id).some(D=>D.status==="running"||D.status==="starting")){x("error","Stop running agents first");return}l(E.id)},children:[e.jsx(Ft,{size:12})," Delete"]})]})]},E.id)}),h?e.jsxs("div",{className:"flex items-center gap-1.5 px-3 h-9 flex-shrink-0",children:[e.jsx("input",{value:O,onChange:E=>b(E.target.value),onKeyDown:E=>{E.key==="Enter"&&ee(),E.key==="Escape"&&(g(!1),b(""))},placeholder:"Team name...",className:"h-5 w-28 px-1.5 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:ee,disabled:!O.trim(),className:"p-1 rounded text-accent hover:bg-accent/10 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(Je,{size:12})}),e.jsx("button",{onClick:()=>{g(!1),b("")},className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:12})})]}):e.jsx("button",{onClick:()=>g(!0),className:"flex items-center justify-center w-6 h-6 my-auto mx-2 rounded-full bg-accent/15 text-accent hover:bg-accent/25 cursor-pointer transition-colors flex-shrink-0",title:"New team",children:e.jsx(it,{size:12})})]}),R&&e.jsx("button",{onClick:()=>{var E;return(E=B.current)==null?void 0:E.scrollBy({left:300,behavior:"smooth"})},className:"w-6 h-9 flex items-center justify-center bg-accent/15 text-accent hover:bg-accent/25 transition-colors flex-shrink-0 cursor-pointer",children:e.jsx(Tt,{size:14})})]})}function wee(){const t=k(K=>K.agents),s=k(K=>K.activeTeamId),n=k(K=>K.tokenTimeline),a=k(K=>K.selectAgent),r=k(K=>K.closeDetail),l=p.useRef([]),c=p.useMemo(()=>{const K=t.filter(E=>{var q;return E.teamId===s&&!((q=E.metadata)!=null&&q.scheduled)}).sort((E,q)=>(E.name||E.id).localeCompare(q.name||q.id)),_=l.current;return _.length===K.length&&_.every((E,q)=>E.id===K[q].id&&E.status===K[q].status&&E.name===K[q].name&&E.model===K[q].model&&E.tokensUsed===K[q].tokensUsed&&E.contextUsage===K[q].contextUsage)?_:(l.current=K,K)},[t,s]),A=p.useRef(FA(s)),f=p.useRef(s);f.current!==s&&(f.current=s,A.current=FA(s));const{fitView:x,setViewport:h}=BU(),[g,O]=p.useState(0),b=p.useRef(s),v=p.useMemo(()=>{const K=A.current,_=k4(),E=c.filter(se=>se.status==="running").length,q=K[Xs]||_[Xs]||{x:0,y:0},H=[{id:Xs,type:"rootNode",position:q,data:{agentCount:c.length,runningCount:E},draggable:!0,selectable:!1}],I=new Set,L=(se,le)=>`${Math.round(se/100)},${Math.round(le/100)}`;I.add(L(q.x,q.y));const J=[];c.forEach(se=>{const le=se.name||se.id;if(K[le]){const V=K[le];I.add(L(V.x,V.y)),H.push({id:se.id,type:"agentNode",position:V,data:{agent:se,timeline:n[se.id]||[]},draggable:!0,selectable:!0})}else J.push(se)});const D=new Map;return J.forEach((se,le)=>{const V=se.role||"agent",te=D.get(V)||0;D.set(V,te+1);const ae=te===0?V:`${V}-${te}`;let be;if(_[ae])be={..._[ae]};else{const z=Math.floor(le/po),oe=le%po;be={x:-((Math.min(J.length-z*po,po)-1)*wf)/2+oe*wf,y:jf+z*jf}}for(;I.has(L(be.x,be.y));)be={x:be.x,y:be.y+jf};I.add(L(be.x,be.y)),se.name||se.id,H.push({id:se.id,type:"agentNode",position:be,data:{agent:se,timeline:n[se.id]||[]},draggable:!0,selectable:!0})}),H},[c,n,s]);p.useEffect(()=>{const K={};v.forEach(_=>{var q,H;const E=_.id===Xs?Xs:((H=(q=_.data)==null?void 0:q.agent)==null?void 0:H.name)||_.id;A.current[E]||(K[E]=_.position)}),Object.keys(K).length>0&&(Object.assign(A.current,K),QQ(s,A.current))},[v,s]);const y=p.useMemo(()=>{const K=FA(s),_=K[Xs]||{x:0,y:0};return c.map((E,q)=>{const H=E.name||E.id,I=Math.floor(q/po),L=q%po,D=-((Math.min(c.length-I*po,po)-1)*wf)/2,se=K[H]||{x:D+L*wf,y:140+I*jf},le=se.x+Ig/2-_.x,V=se.y+zg/2-_.y;let te,ae;return Math.abs(V)>Math.abs(le)?(te=V>0?"bottom":"top",ae=V>0?"top":"bottom"):(te=le>0?"right":"left",ae=le>0?"left":"right"),{id:`e-${Xs}-${E.id}`,source:Xs,target:E.id,sourceHandle:te,targetHandle:ae,type:"default",animated:E.status==="running"}})},[c,s]),[S,j,N]=kU(v),[C,U,P]=TU(y),T=p.useRef(new Set);p.useEffect(()=>{j(K=>{const _=new Map(K.map(E=>[E.id,E]));return v.map(E=>{const q=_.get(E.id);return q?{...q,data:E.data}:E})})},[v,j]),p.useEffect(()=>{U(()=>{const K=S.find(E=>E.id===Xs);if(!K)return y;const _=K.position;return y.map(E=>{const q=S.find(D=>D.id===E.target);if(!q)return E;const H=q.position.x+Ig/2-_.x,I=q.position.y+zg/2-_.y;let L,J;return Math.abs(I)>Math.abs(H)?(L=I>0?"bottom":"top",J=I>0?"top":"bottom"):(L=H>0?"right":"left",J=H>0?"left":"right"),{...E,sourceHandle:L,targetHandle:J}})})},[y,S,U]);const B=c.map(K=>K.id).join(","),F=p.useRef(null);p.useEffect(()=>{if(b.current!==s){b.current=s,T.current=new Set(c.map(q=>q.id)),O(c.length);const E=T4()[s];E?h(E,{duration:200}):c.length>0&&x({padding:.3,maxZoom:1.2,duration:200});return}const K=new Set(c.map(E=>E.id)),_=c.length>0&&[...K].some(E=>!T.current.has(E));T.current=K,g===0&&c.length>0?x({padding:.3,maxZoom:1.2,duration:0}):_&&(clearTimeout(F.current),F.current=setTimeout(()=>x({padding:.3,maxZoom:1.2,duration:300}),500)),O(c.length)},[B,g,x,s,h]);const M=p.useCallback((K,_)=>{bee(s,_)},[s]),R=p.useCallback((K,_)=>{_.id!==Xs&&a(_.id)},[a]),Y=p.useCallback(()=>{r()},[r]),W=p.useCallback((K,_)=>{const E=S.find(H=>H.id===Xs);if(!E)return;const q=E.position;U(H=>H.map(I=>{const L=I.source===_.id,J=I.target===_.id;if(!L&&!J)return I;const D=_.position,se=D.x+Ig/2-q.x,le=D.y+zg/2-q.y;let V,te;return Math.abs(le)>Math.abs(se)?(V=le>0?"bottom":"top",te=le>0?"top":"bottom"):(V=se>0?"right":"left",te=se>0?"left":"right"),{...I,sourceHandle:V,targetHandle:te}}))},[S,U]),ee=p.useCallback((K,_)=>{var H,I;const E=_.id===Xs?Xs:((I=(H=_.data)==null?void 0:H.agent)==null?void 0:I.name)||_.id;A.current[E]=_.position;const q=FA(s);q[E]=_.position,QQ(s,q)},[s]);return e.jsx(UU,{nodes:S,edges:C,nodeTypes:gee,onNodesChange:N,onEdgesChange:P,onNodeClick:R,onPaneClick:Y,onNodeDrag:W,onNodeDragStop:ee,onMoveEnd:M,defaultViewport:{x:0,y:0,zoom:1.2},proOptions:{hideAttribution:!0},minZoom:.2,maxZoom:1.5,className:"bg-surface-2",children:e.jsx(EU,{color:"rgba(97,175,239,0.03)",gap:24,size:1})})}const U4=new Set(["codex","grok","local"]),jee=new Set(["codex"]);function Qee({open:t,onOpenChange:s,onLaunch:n}){const a=k(T=>T.fetchProviders),[r,l]=p.useState([]),[c,A]=p.useState(""),[f,x]=p.useState(""),[h,g]=p.useState(50),[O,b]=p.useState(.5),[v,y]=p.useState(50);p.useEffect(()=>{t&&a().then(T=>{var F;if(!Array.isArray(T))return;const B=T.filter(M=>M.installed);if(l(B),!c&&B.length>0){const M=B.find(Y=>Y.isDefault)||B[0];A(M.id);const R=((F=M.models)==null?void 0:F.filter(Y=>Y.type!=="image"))||[];R.length>0&&x(R[0].id)}}).catch(()=>{})},[t]);const S=r.find(T=>T.id===c),j=((S==null?void 0:S.models)||[]).filter(T=>T.type!=="image"&&!T.disabled),N=U4.has(c),C=jee.has(c);function U(T){var M;A(T);const B=r.find(R=>R.id===T),F=((B==null?void 0:B.models)||[]).filter(R=>R.type!=="image"&&!R.disabled);x(((M=F[0])==null?void 0:M.id)||"")}function P(){const T={provider:c,model:f,reasoningEffort:h,...N&&{temperature:O},...C&&{verbosity:v}};k.setState({teamLaunchConfig:T}),n(T)}return e.jsx(Vt,{open:t,onOpenChange:s,children:e.jsxs(Kt,{title:"Configure Planner",description:"Set provider, model, and tuning before launching the planner",children:[e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Provider"}),e.jsxs(Rn,{value:c,onValueChange:U,children:[e.jsx(Mn,{placeholder:"Select provider",className:"bg-surface-3"}),e.jsx(In,{children:r.map(T=>e.jsx(ms,{value:T.id,children:T.displayName||T.name||T.id},T.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Model"}),e.jsxs(Rn,{value:f,onValueChange:x,children:[e.jsx(Mn,{placeholder:"Select model",className:"bg-surface-3"}),e.jsxs(In,{children:[e.jsx(ms,{value:"auto",children:"Auto"}),j.map(T=>e.jsx(ms,{value:T.id,children:T.name||T.id},T.id))]})]})]}),e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(Ka,{label:"Reasoning Effort",value:h,onChange:g,min:0,max:100,step:1}),N&&e.jsx(Ka,{label:"Temperature",value:O,onChange:b,min:0,max:1,step:.01,formatValue:T=>T.toFixed(2)}),C&&e.jsx(Ka,{label:"Verbosity",value:v,onChange:y,min:0,max:100,step:1})]})]}),e.jsx("div",{className:"px-5 py-4 border-t border-border-subtle",children:e.jsxs(pe,{variant:"primary",size:"md",onClick:P,className:"w-full gap-2",children:[e.jsx(qt,{size:14}),"Launch Planner"]})})]})})}const NQ={chat:Ho,planner:Ei,backend:Ns,frontend:md,fullstack:bn,testing:Wx,devops:Eb,docs:On,security:vn,database:Pb,cmo:Ib,cfo:bS,ea:LS,support:kS,analyst:Lx,creative:MS,slides:zS,ambassador:ua},_g=[{id:"planner",label:"Planner",desc:"Analyzes tasks and designs team plans"},{id:"frontend",label:"Frontend",desc:"React, UI components, views, styling"},{id:"backend",label:"Backend",desc:"APIs, server logic, database, services"},{id:"fullstack",label:"Fullstack",desc:"Cross-stack work, QC, integration testing"},{id:"testing",label:"Testing",desc:"Test suites, coverage, quality assurance"},{id:"devops",label:"DevOps",desc:"CI/CD, deployment, infrastructure"},{id:"security",label:"Security",desc:"Security audits, vulnerability analysis"},{id:"database",label:"Database",desc:"Schema design, queries, migrations"},{id:"docs",label:"Docs",desc:"Documentation, guides, API docs"},{id:"cmo",label:"CMO",desc:"Marketing strategy, campaigns, content"},{id:"cfo",label:"CFO",desc:"Financial analysis, budgeting, forecasting"},{id:"ea",label:"EA",desc:"Executive assistance, coordination, briefings"},{id:"support",label:"Support",desc:"Customer support, issue triage"},{id:"analyst",label:"Analyst",desc:"Data analysis, research, reporting"},{id:"creative",label:"Writer",desc:"Design, copywriting, visual assets"},{id:"slides",label:"Slides",desc:"Presentations, decks, pitch materials"}],Nee=[{name:"Dev Team",icon:bn,roles:["frontend","backend","testing"],desc:"3 agents"},{name:"Full Stack",icon:rc,roles:["frontend","backend","fullstack","testing","devops"],desc:"5 agents"},{name:"Marketing",icon:Ib,roles:["cmo","creative","analyst"],desc:"3 agents"},{name:"Business",icon:Lx,roles:["cfo","analyst","ea"],desc:"3 agents"},{name:"Security Audit",icon:vn,roles:["security","testing","devops"],desc:"3 agents"},{name:"Docs",icon:On,roles:["docs","frontend","analyst"],desc:"3 agents"}];function See(){const t=k(D=>D.teamBuilderOpen),s=k(D=>D.teamBuilderRoles),n=k(D=>D.teamBuilderSettings),a=k(D=>D.teamBuilderTask),r=k(D=>D.teamTemplates),l=k(D=>D.closeTeamBuilder),c=k(D=>D.addTeamBuilderRole),A=k(D=>D.removeTeamBuilderRole),f=k(D=>D.updateTeamBuilderRole),x=k(D=>D.applyTemplate),h=k(D=>D.setTeamBuilderSettings),g=k(D=>D.setTeamBuilderTask),O=k(D=>D.launchTeamBuilder),b=k(D=>D.saveTeamTemplate),v=k(D=>D.fetchTeamTemplates),y=k(D=>D.fetchProviders),[S,j]=p.useState([]),[N,C]=p.useState(""),[U,P]=p.useState(null),[T,B]=p.useState(!1),[F,M]=p.useState(null),[R,Y]=p.useState(!1),[W,ee]=p.useState("");if(p.useEffect(()=>{t&&(y().then(D=>{Array.isArray(D)&&j(D.filter(se=>se.installed))}).catch(()=>{}),v())},[t]),!t)return null;const K=N?_g.filter(D=>D.label.toLowerCase().includes(N.toLowerCase())||D.desc.toLowerCase().includes(N.toLowerCase())):_g,_=S.find(D=>D.id===n.provider),E=((_==null?void 0:_.models)||[]).filter(D=>D.type!=="image"&&!D.disabled);function q(D){var V;h({provider:D});const se=S.find(te=>te.id===D),le=((se==null?void 0:se.models)||[]).filter(te=>te.type!=="image"&&!te.disabled);h({provider:D,model:((V=le[0])==null?void 0:V.id)||""})}function H(D){x(D),M(D.name)}async function I(){B(!0);try{await O()}catch{}B(!1)}function L(){const D=W.trim();D&&(b(D),Y(!1),ee(""))}const J=[...Nee,...(r.custom||[]).map(D=>{var se;return{...D,icon:rc,desc:`${((se=D.roles)==null?void 0:se.length)||0} agents`,custom:!0}})];return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:[e.jsxs("div",{className:"w-full max-w-5xl max-h-[90vh] bg-surface-1 border border-border rounded-xl shadow-2xl flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-info/15 flex items-center justify-center",children:e.jsx(yn,{size:16,className:"text-info"})}),e.jsx("h2",{className:"text-lg font-bold text-text-0 font-sans",children:"Team Builder"})]}),e.jsx("button",{onClick:l,className:"p-2 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",children:e.jsx(qe,{size:18})})]}),e.jsx("div",{className:"px-6 py-3 border-b border-border-subtle",children:e.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"none"},children:[J.map(D=>{const se=D.icon||rc,le=F===D.name;return e.jsxs("button",{onClick:()=>H(D),className:Z("flex flex-col items-center gap-1.5 px-4 py-2.5 rounded-lg border text-center transition-all cursor-pointer flex-shrink-0 min-w-[100px]",le?"border-accent bg-accent/5":"border-border-subtle bg-surface-3 hover:border-accent/30 hover:bg-surface-4"),children:[e.jsx(se,{size:16,className:le?"text-accent":"text-text-2"}),e.jsx("span",{className:"text-2xs font-semibold text-text-0 font-sans",children:D.name}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:D.desc})]},D.name)}),e.jsx(dt,{content:"Save current roster as template",children:e.jsxs("button",{onClick:()=>{Y(!0),ee("")},disabled:s.length===0,className:"flex flex-col items-center gap-1.5 px-4 py-2.5 rounded-lg border border-dashed border-border-subtle bg-surface-2 hover:border-accent/30 transition-all cursor-pointer flex-shrink-0 min-w-[100px] disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(_r,{size:16,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans",children:"Save"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Template"})]})})]})}),e.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"w-[40%] border-r border-border-subtle flex flex-col",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border-subtle",children:e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"text",value:N,onChange:D=>C(D.target.value),placeholder:"Filter roles...",className:"w-full h-8 pl-8 pr-3 text-xs bg-surface-3 border border-border-subtle rounded-md text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent font-sans"})]})}),e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"p-3 grid grid-cols-2 gap-2",children:K.map(D=>{const se=NQ[D.id]||bn;return e.jsxs("button",{onClick:()=>c(D.id),className:"flex items-start gap-2.5 p-2.5 rounded-lg border border-border-subtle bg-surface-2 hover:border-accent/30 hover:bg-surface-3 transition-all cursor-pointer text-left group",children:[e.jsx("div",{className:"w-7 h-7 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/15 transition-colors",children:e.jsx(se,{size:14,className:"text-text-2 group-hover:text-accent transition-colors"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:D.label}),e.jsx(it,{size:12,className:"text-text-4 group-hover:text-accent transition-colors flex-shrink-0"})]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans leading-tight mt-0.5",children:D.desc})]})]},D.id)})})})]}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center justify-between",children:e.jsxs("span",{className:"text-xs font-semibold text-text-1 font-sans uppercase tracking-wider",children:["Your Team (",s.length,")"]})}),e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"p-3 space-y-1.5",children:s.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx(yn,{size:32,className:"text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans",children:"Add roles from the left or pick a template above"})]}):s.map((D,se)=>{var be;const le=NQ[D.role]||bn,V=U===se,te=D.provider?S.find(z=>z.id===D.provider):null,ae=((te==null?void 0:te.models)||[]).filter(z=>z.type!=="image"&&!z.disabled);return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(BS,{size:12,className:"text-text-4 flex-shrink-0 cursor-grab"}),e.jsx("div",{className:"w-6 h-6 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx(le,{size:12,className:"text-text-1"})}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans flex-1",children:((be=_g.find(z=>z.id===D.role))==null?void 0:be.label)||D.role}),e.jsx("button",{onClick:()=>P(V?null:se),className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(xt,{size:12,className:Z("transition-transform duration-200",V&&"rotate-180")})}),e.jsx("button",{onClick:()=>{A(se),U===se?P(null):U>se&&P(U-1)},className:"p-1 rounded text-text-4 hover:text-danger cursor-pointer",children:e.jsx(qe,{size:12})})]}),V&&e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-3 border-t border-border-subtle bg-surface-1",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Name Override"}),e.jsx("input",{type:"text",value:D.name,onChange:z=>f(se,{name:sanitizeName(z.target.value)}),placeholder:D.role,className:"w-full h-7 px-2.5 text-xs bg-surface-3 border border-border-subtle rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",maxLength:64,spellCheck:!1})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:D.provider||"__default__",onValueChange:z=>{var Ce;const oe=z==="__default__"?null:z,ue=S.find(Ne=>Ne.id===oe),ve=((ue==null?void 0:ue.models)||[]).filter(Ne=>Ne.type!=="image"&&!Ne.disabled);f(se,{provider:oe,model:((Ce=ve[0])==null?void 0:Ce.id)||null})},children:[e.jsx(Mn,{placeholder:"Team Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Team Default"}),S.map(z=>e.jsx(ms,{value:z.id,children:z.displayName||z.name||z.id},z.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:D.model||"__default__",onValueChange:z=>f(se,{model:z==="__default__"?null:z}),children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Default"}),ae.map(z=>e.jsx(ms,{value:z.id,children:z.name||z.id},z.id))]})]})]})]}),e.jsx(Ka,{label:"Reasoning",value:D.reasoningEffort??n.reasoningEffort,onChange:z=>f(se,{reasoningEffort:z}),min:0,max:100,step:1}),U4.has(D.provider||n.provider)&&e.jsx(Ka,{label:"Temperature",value:D.temperature??n.temperature,onChange:z=>f(se,{temperature:z}),min:0,max:1,step:.01,formatValue:z=>z.toFixed(2)})]})]},se)})})})]})]}),e.jsx("div",{className:"border-t border-border-subtle px-6 py-4",children:e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("textarea",{value:a,onChange:D=>g(D.target.value),placeholder:"Describe what you want to build... (optional)",rows:3,className:"w-full px-3 py-2 text-sm bg-surface-3 border border-border-subtle rounded-md text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent resize-none"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans italic",children:"Leave empty to spawn agents awaiting instructions"})]}),e.jsxs("div",{className:"w-64 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-0.5",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:n.provider||"__default__",onValueChange:D=>q(D==="__default__"?"":D),children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Default"}),S.map(D=>e.jsx(ms,{value:D.id,children:D.displayName||D.name||D.id},D.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-0.5",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:n.model||"__default__",onValueChange:D=>h({model:D==="__default__"?"":D}),children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Auto"}),E.map(D=>e.jsx(ms,{value:D.id,children:D.name||D.id},D.id))]})]})]})]}),e.jsxs(pe,{variant:"primary",size:"md",onClick:I,disabled:T||s.length===0,className:"w-full gap-2 mt-1",children:[e.jsx(qt,{size:14}),T?"Launching...":`Plan & Launch (${s.length})`]})]})]})})]}),R&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40",children:e.jsxs("div",{className:"w-full max-w-sm bg-surface-2 border border-border rounded-lg shadow-2xl p-5 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:"Save as Template"}),e.jsx("input",{type:"text",value:W,onChange:D=>ee(D.target.value),placeholder:"Template name...",className:"w-full h-8 px-3 text-sm bg-surface-3 border border-border-subtle rounded-md text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0,onKeyDown:D=>{D.key==="Enter"&&L(),D.key==="Escape"&&Y(!1)}}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>Y(!1),children:"Cancel"}),e.jsx(pe,{variant:"primary",size:"sm",onClick:L,disabled:!W.trim(),children:"Save"})]})]})})]})}function Cee({onPlanner:t,onSpawn:s,onTeamBuilder:n}){var a;return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"max-w-2xl w-full text-center space-y-10 px-8",children:[e.jsxs("div",{className:"relative mx-auto w-20 h-20",children:[e.jsx("div",{className:"absolute inset-0 rounded-full bg-accent/8 animate-pulse"}),e.jsx("div",{className:"absolute inset-1 rounded-full bg-surface-3 border border-border-subtle flex items-center justify-center shadow-lg shadow-accent/5",children:e.jsx("img",{src:"/favicon.png",alt:"Groove",className:"h-10 w-10 rounded-full"})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h1",{className:"text-3xl font-bold text-text-0 font-sans tracking-tight",children:"Welcome to Groove"}),e.jsx("p",{className:"text-base text-text-2 font-sans max-w-md mx-auto leading-relaxed",children:"Your mission control for AI agents. Spawn, orchestrate, and ship faster than ever."})]}),e.jsxs("div",{className:"space-y-3 max-w-xl mx-auto",children:[e.jsxs("button",{onClick:t,className:"w-full flex items-center gap-4 p-5 rounded-lg border border-accent/25 bg-gradient-to-r from-accent/8 to-accent/3 hover:from-accent/14 hover:to-accent/6 hover:border-accent/40 transition-all cursor-pointer group text-left",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/20 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:e.jsx(qt,{size:24,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-base font-semibold text-text-0 font-sans",children:"Start with a Planner"}),e.jsx("div",{className:"text-sm text-text-2 font-sans mt-0.5",children:"Describe what you want to build and let AI plan the perfect team"})]}),e.jsx("div",{className:"text-accent text-xs font-semibold font-sans flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity",children:"Recommended"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:n,className:"flex items-center gap-3 p-4 rounded-lg border border-info/25 bg-gradient-to-r from-info/6 to-info/2 hover:from-info/12 hover:to-info/5 hover:border-info/35 transition-all cursor-pointer group text-left",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-info/15 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:e.jsx(HS,{size:20,className:"text-info"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Build a Team"}),e.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Pick roles and configure"})]})]}),e.jsxs("button",{onClick:s,className:"flex items-center gap-3 p-4 rounded-lg border border-border bg-surface-1 hover:bg-surface-2 hover:border-border transition-all cursor-pointer group text-left",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-surface-4 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:e.jsx(it,{size:20,className:"text-text-1"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn Agent"}),e.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose a role and configure"})]})]})]})]}),((a=window.groove)==null?void 0:a.openFolder)&&e.jsxs("div",{className:"max-w-sm mx-auto",children:[e.jsx("p",{className:"text-xs text-text-3 mb-2",children:"Or open a different project"}),e.jsxs("button",{onClick:()=>window.groove.openFolder(),className:"w-full h-10 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 text-sm text-text-1 font-medium flex items-center justify-center gap-2 cursor-pointer transition-colors",children:[e.jsx(Ys,{size:16,className:"text-accent"}),"Open Folder"]})]}),e.jsxs("p",{className:"text-xs text-text-4 font-sans",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+K"}),e.jsx("span",{className:"mx-1.5",children:"command palette"}),e.jsx("span",{className:"text-text-4 mx-1",children:"·"}),e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+N"}),e.jsx("span",{className:"mx-1.5",children:"spawn"}),e.jsx("span",{className:"text-text-4 mx-1",children:"·"}),e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+J"}),e.jsx("span",{className:"mx-1.5",children:"terminal"})]})]})})}function Dg(){var M;const t=k(R=>R.agents),s=k(R=>R.activeTeamId),n=k(R=>R.openDetail),a=k(R=>R.spawnAgent),r=k(R=>R.selectAgent);k(R=>R.recommendedTeam);const l=k(R=>R.checkRecommendedTeam),c=k(R=>R.addToast),A=k(R=>R.showPreviewInAgents),f=k(R=>R.previewState),x=k(R=>R.togglePreviewInAgents),h=k(R=>R.teamPreviews),g=k(R=>R.relaunchPreview),O=k(R=>R.openPreview),b=k(R=>R.workspaceMode),v=k(R=>R.setWorkspaceMode),y=k(R=>R.openTeamBuilder),[S,j]=p.useState(!1);p.useEffect(()=>{if(!t.some(W=>W.role==="planner"&&(W.status==="running"||W.status==="starting")))return;const Y=setInterval(()=>l(),5e3);return()=>clearInterval(Y)},[t,l]);function N(){j(!0)}async function C(R){j(!1);try{const Y=await a({role:"planner",provider:R.provider,model:R.model,reasoningEffort:R.reasoningEffort,temperature:R.temperature,verbosity:R.verbosity});Y!=null&&Y.id&&r(Y.id)}catch{}}const U=t.filter(R=>{var Y;return R.teamId===s&&!((Y=R.metadata)!=null&&Y.scheduled)}),P=k(R=>R.hydrated),[T,B]=p.useState(!0);p.useEffect(()=>{const R=setTimeout(()=>B(!1),1200);return()=>clearTimeout(R)},[]);const F=T||!P;return e.jsxs("div",{className:"flex flex-col h-full relative",children:[e.jsx("div",{className:"flex-1 min-h-0",children:F?e.jsxs("div",{className:Z("flex flex-col items-center justify-center h-full transition-opacity duration-500",!T&&P?"opacity-0":"opacity-100"),children:[e.jsxs("div",{className:"relative w-12 h-12 mb-5",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-accent/20 animate-ping",style:{animationDuration:"2s"}}),e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent animate-spin",style:{animationDuration:"1s"}}),e.jsx("span",{className:"absolute inset-[6px] rounded-full bg-accent/8 flex items-center justify-center",children:e.jsx(qt,{size:16,className:"text-accent animate-pulse"})})]}),e.jsx("p",{className:"text-sm font-medium text-text-1 font-sans animate-pulse",children:"Connecting to agents"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Syncing with daemon..."})]}):U.length===0?e.jsx(Cee,{onPlanner:N,onSpawn:()=>n({type:"spawn"}),onTeamBuilder:y}):b?e.jsx(nY,{}):A&&f.url&&f.teamId===s&&((M=h[s])!=null&&M.active)?e.jsx(RX,{embedded:!0}):e.jsx(CU,{children:e.jsx(wee,{})},s)}),!b&&e.jsx(qf,{}),!F&&U.length>0&&!b&&e.jsxs("div",{className:"absolute bottom-3 left-3 z-40 flex items-center gap-1.5",children:[e.jsx(dt,{content:"Spawn agent",side:"top",children:e.jsx("button",{onClick:()=>n({type:"spawn"}),className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:e.jsx(it,{size:15})})}),e.jsx(dt,{content:Object.keys(k4()).length>0?"Update layout":"Save layout",side:"top",children:e.jsx("button",{onClick:()=>{const R=FA(s),Y={},W=new Map;[...U].sort((ee,K)=>(ee.name||ee.id).localeCompare(K.name||K.id)).forEach(ee=>{const K=ee.name||ee.id,_=R[K];if(!_)return;const E=ee.role||"agent",q=W.get(E)||0;W.set(E,q+1);const H=q===0?E:`${E}-${q}`;Y[H]=_}),R[Xs]&&(Y[Xs]=R[Xs]),Oee(Y),c("success","Layout saved","Future spawns will use these positions")},className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:e.jsx(yM,{size:15})})}),e.jsx(dt,{content:"Workspace",side:"top",children:e.jsx("button",{onClick:()=>v(!0),className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:e.jsx(bn,{size:15})})}),(()=>{const R=h[s];if(!R)return null;const Y=R.active&&f.url&&f.teamId===s,W=Y&&A,ee=W?"Show team":Y?"Show preview":"Relaunch preview";return e.jsx(dt,{content:ee,side:"top",children:e.jsx("button",{onClick:()=>{Y?A?x():O(R.url,s,R.kind):g(s)},className:Z("flex items-center justify-center w-8 h-8 rounded border bg-surface-2/50 transition-colors cursor-pointer",Y?"border-text-3/25 text-text-3 hover:text-info hover:border-info/40 hover:bg-info/10":"border-text-4/25 text-text-4 hover:text-warning hover:border-warning/40 hover:bg-warning/10"),children:W?e.jsx(yn,{size:15}):e.jsx(Vs,{size:15})})})})()]}),e.jsx(Qee,{open:S,onOpenChange:j,onLaunch:C}),e.jsx(See,{})]})}function Bee({children:t,detailContent:s,terminalContent:n}){const a=k(T=>T.activeView),r=k(T=>T.detailPanel),l=k(T=>T.connected),c=k(T=>T.tunneled),A=k(T=>T.daemonHost),f=k(T=>T.agents),x=k(T=>T.editorActiveFile),h=k(T=>T.detailPanelWidth),g=k(T=>T.terminalVisible),O=k(T=>T.terminalFullHeight),b=k(T=>T.setActiveView),v=k(T=>T.openDetail),y=k(T=>T.closeDetail),S=k(T=>T.setDetailPanelWidth),j=k(T=>T.setTerminalVisible),N=k(T=>T.toggleCommandPalette),C=p.useMemo(()=>f.filter(T=>T.status==="running").length,[f]),U=p.useMemo(()=>[{key:"k",meta:!0,handler:()=>k.getState().toggleCommandPalette()},{key:"p",meta:!0,shift:!0,handler:()=>k.getState().toggleCommandPalette()},{key:"j",meta:!0,handler:()=>{const T=k.getState();T.setTerminalVisible(!T.terminalVisible)}},{key:"n",meta:!0,handler:()=>k.getState().openDetail({type:"spawn"})},{key:"1",meta:!0,handler:()=>k.getState().setActiveView("agents")},{key:"2",meta:!0,handler:()=>k.getState().setActiveView("editor")},{key:"3",meta:!0,handler:()=>k.getState().setActiveView("dashboard")},{key:"4",meta:!0,handler:()=>k.getState().setActiveView("marketplace")},{key:"5",meta:!0,handler:()=>k.getState().setActiveView("teams")},{key:"Escape",handler:()=>{const T=k.getState();T.commandPaletteOpen?T.toggleCommandPalette():T.detailPanel&&T.closeDetail()}}],[]);pN(U);const P=r&&r.type!=="spawn";return e.jsx(v$,{children:e.jsxs("div",{className:Z("w-full h-full flex flex-col bg-surface-2 text-text-1 font-sans",cd()&&"electron-app"),children:[e.jsx(Uz,{activeView:a,connected:l,tunneled:c,daemonHost:A,editorActiveFile:x,onOpenCommandPalette:N}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsx(Cz,{activeView:a,detailPanel:r,onNavigate:b,onTogglePanel:T=>{(r==null?void 0:r.type)===T?y():v({type:T})}}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[a==="agents"&&e.jsx(yee,{}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[!(g&&O)&&e.jsx("main",{className:"flex-1 min-h-0 overflow-hidden relative",children:t}),n]}),P&&e.jsx(D_,{width:h,onWidthChange:S,onClose:y,children:s})]})]})]}),e.jsx(__,{connected:l,agentCount:f.length,runningCount:C,terminalVisible:g,onToggleTerminal:()=>j(!g)}),e.jsx(H_,{}),e.jsx(NC,{}),e.jsx(X_,{}),e.jsx(G_,{}),e.jsx(ZS,{})]})})}function kee({id:t,name:s,subtitle:n,models:a,authType:r,recommended:l,installed:c,installing:A,failed:f,selected:x,onInstall:h,gradientFrom:g,letter:O,statusChecking:b}){return e.jsxs(_n.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.25},className:Z("relative flex flex-col rounded-md border p-6 transition-all duration-200","bg-surface-2 hover:bg-surface-3 hover:shadow-lg hover:shadow-black/20",x?"border-accent ring-1 ring-accent/30 shadow-md shadow-accent/10":"border-border-subtle",A&&"pointer-events-none opacity-70"),children:[x&&e.jsx("div",{className:"absolute top-3 left-3 w-5 h-5 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Je,{className:"w-3 h-3 text-surface-0",strokeWidth:3})}),e.jsxs("div",{className:"flex items-start gap-4 mb-5",children:[e.jsx("div",{className:Z("w-14 h-14 rounded-md flex items-center justify-center text-lg font-bold font-mono shrink-0",g),children:O}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:s}),l&&e.jsx(Te,{variant:"purple",className:"text-2xs",children:"Recommended"})]}),e.jsx("p",{className:"text-xs text-text-2 mt-0.5",children:n})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:a.map(v=>e.jsx("span",{className:"text-xs text-text-2 bg-surface-4 px-2 py-0.5 rounded font-mono",children:v},v))}),e.jsx("p",{className:"text-2xs text-text-3 mb-4",children:r}),e.jsx("div",{className:"mt-auto pt-4 border-t border-border-subtle",children:A?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4 text-accent animate-spin"}),e.jsx("span",{className:"text-xs text-accent font-medium",children:"Installing..."})]}),e.jsx("div",{className:"h-1 bg-surface-4 rounded-full overflow-hidden",children:e.jsx(_n.div,{className:"h-full bg-accent rounded-full",initial:{width:"0%"},animate:{width:"90%"},transition:{duration:15,ease:"easeOut"}})})]}):c?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rx,{className:"w-4 h-4 text-success"}),e.jsx("span",{className:"text-xs text-success font-medium",children:"Ready"})]}):f?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"w-4 h-4 text-danger"}),e.jsx("span",{className:"text-xs text-danger font-medium",children:"Failed"})]}),e.jsxs("button",{type:"button",className:"h-8 px-5 rounded-full text-xs font-medium bg-danger/15 text-danger hover:bg-danger/25 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-danger flex items-center gap-1.5",onClick:v=>{v.stopPropagation(),h==null||h(t)},children:[e.jsx(Io,{className:"w-3 h-3"}),"Retry"]})]}):b?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-3.5 h-3.5 text-text-4 animate-spin"}),e.jsx("span",{className:"text-xs text-text-4",children:"Checking..."})]}):e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs("button",{type:"button",className:"h-8 px-5 rounded-full text-xs font-medium bg-accent text-surface-0 hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent flex items-center gap-1.5",onClick:v=>{v.stopPropagation(),h==null||h(t)},children:[e.jsx(qs,{className:"w-3.5 h-3.5"}),"Install"]})})})]})}const ja=[{id:"claude-code",name:"Claude Code",subtitle:"by Anthropic",models:["Opus 4.6","Sonnet 4.6","Haiku 4.5"],authType:"Subscription or API key",authModes:["subscription","apikey"],recommended:!0,letter:"C",gradientFrom:"bg-purple/20 text-purple",keyPlaceholder:"sk-ant-...",keyLabel:"Anthropic API Key"},{id:"codex",name:"Codex",subtitle:"by OpenAI",models:["GPT-5.4 Pro","Standard","Mini","Nano"],authType:"API key or ChatGPT Plus",authModes:["apikey","chatgpt-plus"],recommended:!1,letter:"X",gradientFrom:"bg-success/20 text-success",keyPlaceholder:"sk-...",keyLabel:"OpenAI API Key"},{id:"gemini",name:"Gemini CLI",subtitle:"by Google",models:["Gemini 3.1 Pro","3 Flash"],authType:"API key",authModes:["apikey"],recommended:!1,letter:"G",gradientFrom:"bg-info/20 text-info",keyPlaceholder:"AIza...",keyLabel:"Gemini API Key"}],Tee={enter:t=>({x:t>0?80:-80,opacity:0}),center:{x:0,opacity:1},exit:t=>({x:t<0?80:-80,opacity:0})},Uee={duration:.25,ease:[.4,0,.2,1]};function Eee({current:t,total:s}){return e.jsx("div",{className:"flex items-center gap-2.5",children:Array.from({length:s},(n,a)=>e.jsx("div",{className:Z("h-2 rounded-full transition-all duration-300",a===t?"w-7 bg-accent":a<t?"w-2 bg-accent/50":"w-2 bg-surface-5")},a))})}function Pee({onNext:t,onSkip:s}){return e.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[e.jsx(_n.img,{src:"/favicon.png",alt:"Groove",className:"w-20 h-20",initial:{scale:.5,opacity:0},animate:{scale:1,opacity:1},transition:{duration:.4,ease:"easeOut"}}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"Welcome to Groove"}),e.jsx("p",{className:"text-sm text-text-2",children:"Your AI coding team, ready in minutes"})]}),e.jsx("p",{className:"text-xs text-text-3 leading-relaxed max-w-sm",children:"Let's set up your AI providers so you can start spawning agents. This only takes a moment."}),e.jsxs("button",{type:"button",onClick:t,className:"mt-4 h-11 px-8 rounded-full bg-accent text-surface-0 font-semibold text-sm hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-0 flex items-center gap-2",autoFocus:!0,children:["Get Started",e.jsx(Mo,{className:"w-4 h-4"})]}),e.jsx("button",{type:"button",onClick:s,className:"text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent rounded px-2 py-1",children:"Skip setup"})]})}function Fee({selectedDir:t,onSelectDir:s}){const n=k(A=>A.remoteHomedir),[a,r]=p.useState(!1),l=new URLSearchParams(window.location.search).has("instance");async function c(){var f,x;if(l){r(!0);return}const A=await wE({title:"Choose your project folder",defaultPath:t||void 0});A?s(A):(x=(f=window.groove)==null?void 0:f.folders)!=null&&x.select||r(!0)}return e.jsxs("div",{className:"flex flex-col items-center max-w-lg mx-auto w-full text-center",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your project folder"}),e.jsx("p",{className:"text-sm text-text-2",children:"Pick the root directory where your code lives. Groove will manage agents from here."})]}),e.jsx("div",{className:"w-full bg-surface-2 border border-border-subtle rounded-lg p-5 mb-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/10 flex items-center justify-center",children:e.jsx(Ys,{className:"w-6 h-6 text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[e.jsx("p",{className:"text-xs text-text-3 mb-0.5",children:"Working directory"}),e.jsx("p",{className:"text-sm font-mono text-text-0 truncate",children:t||"No folder selected"})]})]})}),e.jsxs("button",{type:"button",onClick:c,className:"h-10 px-6 rounded-lg bg-accent text-surface-0 font-medium text-sm hover:bg-accent/80 transition-colors cursor-pointer flex items-center gap-2",children:[e.jsx(Ys,{className:"w-4 h-4"}),t?"Change Folder":"Select Folder"]}),e.jsx("p",{className:"mt-4 text-2xs text-text-4",children:"You can change this anytime in Settings."}),a&&e.jsx(gc,{open:a,onOpenChange:r,currentPath:t||n||"/",homePath:n,onSelect:A=>{s(A),r(!1)}})]})}function $ee({providerStatus:t,selected:s,onInstall:n,installing:a,statusChecking:r}){const l=ja.filter(A=>{var f;return(f=t[A.id])==null?void 0:f.installed}).length,c=l===ja.length;return e.jsxs("div",{className:"flex flex-col items-center max-w-4xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your AI providers"}),e.jsx("p",{className:"text-sm text-text-2",children:"Install the coding tools you want to use. You can always add more later."})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 w-full mb-8",children:ja.map(A=>{var f,x;return e.jsx(kee,{...A,installed:(f=t[A.id])==null?void 0:f.installed,installing:a[A.id],failed:(x=t[A.id])==null?void 0:x.failed,selected:s.includes(A.id),onInstall:n,statusChecking:r},A.id)})}),e.jsx("p",{className:Z("text-xs text-center",c?"text-success":l>0?"text-text-2":"text-text-4"),children:c?"All providers installed — you're ready to go!":l>0?`${l} of ${ja.length} providers installed`:"Click Install to set up a provider"})]})}function Ree({provider:t,providerStatus:s,onSaveKey:n}){const[a,r]=p.useState(t.authModes.includes("subscription")?"subscription":"apikey"),[l,c]=p.useState(""),[A,f]=p.useState(!1),[x,h]=p.useState(!1),[g,O]=p.useState((s==null?void 0:s.authenticated)||!1),b=async()=>{if(l.trim()){h(!0);try{await n(t.id,l.trim()),O(!0)}catch{}finally{h(!1)}}},v=(s==null?void 0:s.maskedKey)||(g&&l?`${l.slice(0,6)}${"•".repeat(20)}`:null);return e.jsxs(_n.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.2},className:"bg-surface-2 border border-border-subtle rounded-md p-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:Z("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono",t.gradientFrom),children:t.letter}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:t.name}),e.jsx("p",{className:"text-2xs text-text-3",children:t.subtitle})]}),(g||(s==null?void 0:s.authenticated))&&e.jsx(Te,{variant:"success",className:"ml-auto",children:"Connected"})]}),t.authModes.length>1&&e.jsx("div",{className:"flex gap-1 mb-4 bg-surface-3 p-0.5 rounded-md",children:t.authModes.map(y=>e.jsx("button",{type:"button",onClick:()=>r(y),className:Z("flex-1 h-7 rounded text-xs font-medium transition-colors duration-100 cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a===y?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:y==="subscription"?"Subscription":y==="chatgpt-plus"?"ChatGPT Plus":"API Key"},y))}),a==="subscription"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-text-2",children:"Sign in via the terminal with your Claude subscription."}),e.jsx("div",{className:"space-y-1.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open a terminal and run: ",e.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"claude"})," — then follow the prompts to sign in."]})}),(s==null?void 0:s.authenticated)&&e.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[e.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="chatgpt-plus"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-xs text-text-2",children:["Run ",e.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"codex login"})," in your terminal to authenticate with ChatGPT Plus."]}),(s==null?void 0:s.authenticated)&&e.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[e.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="apikey"&&e.jsx("div",{className:"space-y-3",children:g||s!=null&&s.authenticated?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md bg-surface-1 border border-border px-3 flex items-center",children:e.jsx("span",{className:"text-xs text-text-3 font-mono truncate",children:v||"••••••••••••••"})}),e.jsx("button",{type:"button",onClick:()=>{O(!1),c("")},className:"h-8 px-3 rounded-md text-xs text-text-3 hover:text-text-1 bg-surface-4 hover:bg-surface-5 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:"Change"})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:A?"text":"password",value:l,onChange:y=>c(y.target.value),placeholder:t.keyPlaceholder,className:"h-8 w-full rounded-md px-3 pr-8 text-sm bg-surface-1 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent transition-colors duration-100 font-mono",onKeyDown:y=>y.key==="Enter"&&b(),"aria-label":t.keyLabel}),e.jsx("button",{type:"button",onClick:()=>f(!A),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer","aria-label":A?"Hide key":"Show key",children:A?e.jsx(To,{className:"w-3.5 h-3.5"}):e.jsx(Vs,{className:"w-3.5 h-3.5"})})]}),e.jsx("button",{type:"button",onClick:b,disabled:!l.trim()||x,className:"h-8 px-4 rounded-md bg-accent text-surface-0 text-xs font-medium hover:bg-accent/80 transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:pointer-events-none focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:x?"Saving...":"Save"})]})})]})}function Mee({providerStatus:t,installedIds:s,onSaveKey:n}){const a=ja.filter(r=>{var l;return s.includes(r.id)||((l=t[r.id])==null?void 0:l.installed)});return a.some(r=>{var l;return(l=t[r.id])==null?void 0:l.authenticated}),e.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Connect your accounts"}),e.jsx("p",{className:"text-sm text-text-2",children:"Add credentials for your installed providers."})]}),e.jsx("div",{className:"flex flex-col gap-4 w-full mb-6",children:a.map(r=>e.jsx(Ree,{provider:r,providerStatus:t[r.id]||{},onSaveKey:n},r.id))}),a.length===0&&e.jsx("p",{className:"text-sm text-text-3 text-center",children:"No providers installed yet. Go back to install one."})]})}function Iee({providerStatus:t,installedIds:s,defaultProvider:n,defaultModel:a,onSetDefault:r}){var c;const l=ja.filter(A=>{var f,x;return(s.includes(A.id)||((f=t[A.id])==null?void 0:f.installed))&&((x=t[A.id])==null?void 0:x.authenticated)});return e.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Set your default"}),e.jsx("p",{className:"text-sm text-text-2",children:"Choose which provider and model to use by default. You can switch per-agent anytime."})]}),e.jsxs("div",{className:"flex flex-col gap-3 w-full max-w-md mb-6",children:[l.map(A=>e.jsxs("button",{type:"button",onClick:()=>r(A.id,A.models[0]),className:Z("flex items-center gap-4 p-4 rounded-md border transition-all duration-200 text-left cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",n===A.id?"bg-accent/8 border-accent ring-1 ring-accent/30":"bg-surface-2 border-border-subtle hover:bg-surface-3"),children:[e.jsx("div",{className:Z("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono shrink-0",A.gradientFrom),children:A.letter}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:A.name}),e.jsx("p",{className:"text-2xs text-text-3",children:A.subtitle})]}),e.jsx("div",{className:Z("w-5 h-5 rounded-full border-2 flex items-center justify-center transition-colors",n===A.id?"border-accent bg-accent":"border-border"),children:n===A.id&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-surface-0"})})]},A.id)),l.length===0&&e.jsx("p",{className:"text-sm text-text-3 text-center",children:"No authenticated providers. Go back to connect one."})]}),n&&e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 mb-2 block",children:"Model"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(c=ja.find(A=>A.id===n))==null?void 0:c.models.map(A=>e.jsx("button",{type:"button",onClick:()=>r(n,A),className:Z("h-7 px-3 rounded-full text-xs font-medium transition-colors duration-100 cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a===A?"bg-accent text-surface-0":"bg-surface-4 text-text-2 hover:bg-surface-5 hover:text-text-0"),children:A},A))})]})]})}function zee({providerStatus:t,defaultProvider:s,defaultModel:n,onFinish:a}){var c;const r=ja.filter(A=>{var f;return(f=t[A.id])==null?void 0:f.installed}).length,l=(c=ja.find(A=>A.id===s))==null?void 0:c.name;return e.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[e.jsx(_n.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",stiffness:300,damping:20},className:"w-20 h-20 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Je,{className:"w-10 h-10 text-success",strokeWidth:2.5})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"You're all set!"}),e.jsxs("p",{className:"text-sm text-text-2",children:[r," provider",r!==1?"s":""," installed",l?`, default: ${l}`:"",n?` (${n})`:""]})]}),e.jsx(_n.div,{className:"flex gap-3 mt-4",initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.3},children:e.jsxs("button",{type:"button",onClick:a,className:"h-11 px-8 rounded-full bg-accent text-surface-0 font-semibold text-sm hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-0 flex items-center gap-2",autoFocus:!0,children:[e.jsx(Js,{className:"w-4 h-4"}),"Start Building"]})})]})}const yA=6;function _ee(){const t=k(H=>H.dismissOnboarding),s=k(H=>H.installProvider),n=k(H=>H.setDefaultProvider),a=k(H=>H.addToast),[r,l]=p.useState(0),[c,A]=p.useState(1),[f,x]=p.useState(["claude-code"]),[h,g]=p.useState({}),[O,b]=p.useState({}),[v,y]=p.useState(null),[S,j]=p.useState(null),[N,C]=p.useState(!0),[U,P]=p.useState(null),T=p.useRef(null);p.useEffect(()=>{let H=!1;async function I(){var J;try{const D=await fetch("/api/onboarding/status").then(se=>se.ok?se.json():null);if(D!=null&&D.providers){const se={},le=[];for(const V of D.providers){const te=V.authStatus==="authenticated"||V.authStatus==="key-set";se[V.id]={installed:V.installed,authenticated:te},V.installed&&le.push(V.id)}return{status:se,installedIds:le,workingDir:((J=D.config)==null?void 0:J.defaultWorkingDir)||null}}}catch{}try{const D=await fetch("/api/providers").then(se=>se.ok?se.json():null);if(D){const se={},le=[],V=Array.isArray(D)?D:D.providers||[];for(const te of V){const ae=te.installed||te.authStatus==="authenticated"||te.authStatus==="key-set"||!1;se[te.id]={installed:ae,authenticated:te.authenticated||!1},ae&&le.push(te.id)}return{status:se,installedIds:le}}}catch{}return null}async function L(){C(!0);let J=await I();if(!H&&J&&J.installedIds.length===0)for(let D=0;D<2;D++){if(await new Promise(se=>setTimeout(se,2e3)),H)return;if(J=await I(),J&&J.installedIds.length>0)break}!H&&J&&(b(J.status),J.installedIds.length>0&&x(D=>[...new Set([...D,...J.installedIds])]),J.workingDir&&!U&&P(J.workingDir)),H||C(!1)}return L(),()=>{H=!0}},[r]);const B=p.useCallback(()=>{r<yA-1&&(A(1),l(H=>H+1))},[r]),F=p.useCallback(()=>{r>0&&(A(-1),l(H=>H-1))},[r]),M=p.useCallback(()=>{t()},[t]),R=p.useCallback(async()=>{if(U)try{await P(U)}catch{a("error","Failed to set project directory")}t()},[t,U,a]),Y=p.useCallback(async H=>{g(I=>({...I,[H]:!0}));try{await s(H),b(I=>({...I,[H]:{...I[H],installed:!0}})),x(I=>I.includes(H)?I:[...I,H])}catch{b(I=>({...I,[H]:{...I[H],failed:!0}}))}finally{g(I=>({...I,[H]:!1}))}},[s]),W=p.useCallback(async(H,I)=>{try{if(!(await fetch(`/api/credentials/${encodeURIComponent(H)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:I})})).ok)throw new Error("Failed to save key");b(J=>({...J,[H]:{...J[H],authenticated:!0,maskedKey:`${I.slice(0,6)}${"•".repeat(20)}`}})),a("success","API key saved")}catch(L){throw a("error","Failed to save key",L.message),L}},[a]),ee=p.useCallback(async(H,I)=>{y(H),j(I);try{await n(H,I)}catch{}},[n]),K=ja.some(H=>{var I;return(I=O[H.id])==null?void 0:I.installed}),_=ja.some(H=>{var I;return(I=O[H.id])==null?void 0:I.authenticated}),E=r===0||r===1?!0:r===2?K:r===3?_:r===4?!!v:!1;p.useEffect(()=>{const H=I=>{I.key==="Enter"&&r<yA-1&&E&&B(),I.key==="Escape"&&M()};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[r,E,B,M]);const q=[e.jsx(Pee,{onNext:B,onSkip:M},"welcome"),e.jsx(Fee,{selectedDir:U,onSelectDir:P},"folder"),e.jsx($ee,{providerStatus:O,selected:f,onInstall:Y,installing:h,statusChecking:N},"install"),e.jsx(Mee,{providerStatus:O,installedIds:f,onSaveKey:W},"auth"),e.jsx(Iee,{providerStatus:O,installedIds:f,defaultProvider:v,defaultModel:S,onSetDefault:ee},"default"),e.jsx(zee,{providerStatus:O,defaultProvider:v,defaultModel:S,onFinish:R},"done")];return e.jsxs("div",{ref:T,className:"fixed inset-0 z-50 bg-gradient-to-b from-surface-0 to-surface-1 flex flex-col font-sans overflow-hidden",children:[cd()&&e.jsx("div",{className:"h-8 w-full electron-drag shrink-0"}),e.jsxs("div",{className:"flex items-center justify-between px-8 py-4 shrink-0",children:[e.jsx(Eee,{current:r,total:yA}),r>0&&r<yA-1&&e.jsx("button",{type:"button",onClick:M,className:"text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent rounded px-2 py-1",children:"Skip setup"})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center px-8 py-4 overflow-y-auto",children:e.jsx(Mi,{mode:"wait",custom:c,children:e.jsx(_n.div,{custom:c,variants:Tee,initial:"enter",animate:"center",exit:"exit",transition:Uee,className:"w-full",children:q[r]},r)})}),r>0&&r<yA-1&&e.jsxs("div",{className:"flex items-center justify-between px-8 py-8 shrink-0",children:[e.jsxs("button",{type:"button",onClick:F,className:"h-10 px-6 rounded-md text-sm text-text-2 hover:text-text-0 bg-surface-3 hover:bg-surface-4 transition-colors duration-100 cursor-pointer flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[e.jsx(Di,{className:"w-4 h-4"}),"Back"]}),e.jsxs("button",{type:"button",onClick:B,disabled:!E,className:"h-10 px-8 rounded-md text-sm font-medium bg-accent text-surface-0 hover:bg-accent/80 transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:pointer-events-none flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[r===4?"Finish Setup":"Continue",e.jsx(Tt,{className:"w-4 h-4"})]})]})]})}const Dee=[{icon:Ns,label:"Federation",desc:"Multi-machine daemon pairing"},{icon:Eb,label:"Cloud Teams",desc:"Coming soon"}];function SQ(){var y;const t=k(S=>S.upgradeModalOpen),s=k(S=>S.setUpgradeModalOpen),n=k(S=>S.marketplaceAuthenticated),a=k(S=>S.marketplaceLogin),r=k(S=>S.startCheckout),l=k(S=>S.addToast),[c,A]=p.useState(null),[f,x]=p.useState("monthly"),[h,g]=p.useState(!1);p.useEffect(()=>{t&&!c&&k.getState().fetchSubscriptionPlans().then(S=>A(S)).catch(()=>{})},[t,c]);const O=(y=c==null?void 0:c.pro)==null?void 0:y[f],b=f==="annual"?`$${Math.round(((O==null?void 0:O.price)||96)/12)}/mo`:`$${(O==null?void 0:O.price)||10}/mo`;async function v(){var S;if(!n){a();return}if(!(O!=null&&O.priceId)){sO("https://groovedev.ai/pro"),s(!1);return}g(!0);try{await r(O.priceId),s(!1)}catch(j){j.status===401||(S=j.message)!=null&&S.includes("Not authenticated")?(l("info","Please sign in first"),a()):j.status===409&&(l("info","You already have a subscription"),s(!1))}finally{g(!1)}}return e.jsx(Vt,{open:t,onOpenChange:s,children:e.jsx(Kt,{title:"Upgrade to Pro",className:"max-w-[440px]",children:e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("div",{className:"mx-auto mb-3 w-12 h-12 rounded-full bg-accent/10 flex items-center justify-center",children:e.jsx(Js,{size:22,className:"text-accent"})}),e.jsx("h2",{className:"text-lg font-bold text-text-0",children:"Upgrade to Groove Pro"}),e.jsx("p",{className:"text-sm text-text-2 mt-1",children:"Unlock powerful features for your AI workflow"})]}),e.jsx("div",{className:"space-y-3 mb-6",children:Dee.map(S=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx(S.icon,{size:15,className:"text-accent"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-text-0",children:S.label}),e.jsx("p",{className:"text-2xs text-text-3",children:S.desc})]}),e.jsx(Je,{size:14,className:"text-success ml-auto flex-shrink-0"})]},S.label))}),e.jsxs("div",{className:"flex gap-1 mb-5 bg-surface-3 p-0.5 rounded-md",children:[e.jsx("button",{type:"button",onClick:()=>x("monthly"),className:Z("flex-1 h-8 rounded text-xs font-medium transition-colors cursor-pointer",f==="monthly"?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:"Monthly"}),e.jsxs("button",{type:"button",onClick:()=>x("annual"),className:Z("flex-1 h-8 rounded text-xs font-medium transition-colors cursor-pointer",f==="annual"?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:["Annual",e.jsx("span",{className:"ml-1 text-success text-2xs",children:"Save 20%"})]})]}),e.jsxs("div",{className:"text-center mb-5",children:[e.jsx("span",{className:"text-3xl font-bold text-text-0",children:b}),f==="annual"&&e.jsxs("p",{className:"text-2xs text-text-3 mt-1",children:["Billed $",(O==null?void 0:O.price)||96,"/year"]})]}),e.jsx("button",{type:"button",onClick:v,disabled:h,className:"w-full h-10 rounded-lg bg-accent text-white font-semibold text-sm hover:bg-accent/90 transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none flex items-center justify-center gap-2",children:h?"Processing...":n?e.jsxs(e.Fragment,{children:[e.jsx(Js,{size:15})," Subscribe — ",b]}):e.jsxs(e.Fragment,{children:[e.jsx(PS,{size:15})," Sign in to subscribe"]})}),e.jsx("button",{type:"button",onClick:()=>s(!1),className:"w-full mt-2 text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer py-1",children:"Maybe later"})]})})})}function Lee(){const t=k(l=>l.dataSharingModalOpen),s=k(l=>l.setTrainingOptIn),n=k(l=>l.dismissDataSharingModal),[a,r]=p.useState(!1);return e.jsx(Vt,{open:t,children:e.jsxs(Kt,{className:"max-w-md",description:"Help improve Groove by sharing usage data",onInteractOutside:l=>l.preventDefault(),onEscapeKeyDown:l=>l.preventDefault(),children:[e.jsxs("div",{className:"relative bg-gradient-to-br from-accent/5 to-transparent px-6 pt-8 pb-6 text-center",children:[e.jsx("div",{className:"flex justify-center mb-3",children:e.jsx("div",{className:"w-14 h-14 rounded-xl bg-accent/10 flex items-center justify-center",children:e.jsx(Js,{size:32,className:"text-accent"})})}),e.jsx(nm,{className:"text-xl font-bold text-text-0 font-sans",children:"Help Build a Better Groove"}),e.jsx("p",{className:"text-sm text-text-2 font-sans mt-2 max-w-md mx-auto",children:"We collect errors and usage reports to improve the quality of Groove for everyone."})]}),e.jsx("div",{className:"px-6 pt-4",children:e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2/30 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx(vn,{size:14,className:"text-text-2"}),e.jsx("span",{className:"text-xs font-semibold uppercase text-text-3 tracking-wider font-sans",children:"What We Never Collect"})]}),e.jsx("div",{className:"space-y-1.5",children:["Your source code or file contents","API keys, passwords, or credentials","Personal information — emails, names, file paths","Anything that could identify you, your IP or projects"].map(l=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{size:12,className:"text-danger flex-shrink-0"}),e.jsx("span",{className:"text-xs text-text-1 font-sans",children:l})]},l))}),e.jsx("p",{className:"text-xs text-text-0 font-sans font-medium mt-3",children:"PII is automatically scrubbed before any data leaves your machine."})]})}),e.jsxs("div",{className:"border-t border-border-subtle mt-5 pt-4 pb-1 px-6",children:[e.jsxs("button",{type:"button",onClick:()=>s(!0),className:"w-full h-10 rounded-lg bg-accent text-white font-semibold text-sm hover:bg-accent/90 transition-colors cursor-pointer flex items-center justify-center gap-2",children:[e.jsx(Js,{size:15}),"Turn On Sharing"]}),e.jsx("div",{className:"text-center mt-2.5",children:e.jsx("button",{type:"button",onClick:()=>n(a),className:"text-xs text-text-3 hover:text-text-1 transition-colors font-sans cursor-pointer",children:"Maybe Later"})}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[e.jsx("input",{type:"checkbox",id:"data-sharing-dismiss",checked:a,onChange:l=>r(l.target.checked),className:"w-3.5 h-3.5 rounded border-border accent-accent cursor-pointer"}),e.jsx("label",{htmlFor:"data-sharing-dismiss",className:"text-2xs text-text-3 font-sans cursor-pointer select-none",children:"Don't show this again"})]}),e.jsx("p",{className:"text-center text-2xs text-text-4 font-sans mt-2 mb-1",children:"You can always enable this later in Settings"})]})]})})}function Hee(){const t=k(P=>P.recentProjects),s=k(P=>P.setProjectDir),n=k(P=>P.removeRecentProject),a=k(P=>P.remoteHomedir),r=k(P=>P.savedTunnels),l=k(P=>P.fetchTunnels),c=k(P=>P.deleteTunnel),A=k(P=>P.connectTunnel),f=k(P=>P.disconnectTunnel),x=k(P=>P.toggleQuickConnect),h=k(P=>P.addToast),g=k(P=>P.tunnelConnectStep),[O,b]=p.useState(!1),[v,y]=p.useState(null);p.useEffect(()=>{l()},[l]);const S=(t||[]).slice(0,8),j=S.length>0,N=r.length>0,C=j||N;async function U(P){var T,B;if(P.active){(B=(T=window.groove)==null?void 0:T.remote)!=null&&B.openWindow?window.groove.remote.openWindow(P.localPort,P.name):window.open(`http://localhost:${P.localPort}?instance=${encodeURIComponent(P.name)}`,"_blank");return}y(P.id);try{await A(P.id)}catch(F){const M=(F==null?void 0:F.message)||"Unknown error";/permission|EACCES|sudo|Node\.js is not installed|npm install failed|write access/i.test(M)?(x(),h("warning","Remote setup needed","Follow the instructions to set up the remote server.")):h("error","Connection failed",M)}y(null)}return e.jsxs("div",{className:"fixed inset-0 z-50 overflow-y-auto welcome-bg",children:[e.jsx("div",{className:"pointer-events-none fixed top-0 left-1/2 -translate-x-1/2 w-[800px] h-[600px] rounded-full bg-accent/[0.03] blur-[120px]"}),e.jsxs("div",{className:"relative min-h-screen flex flex-col items-center px-8 pt-[14vh] pb-12 max-sm:pt-[8vh] max-sm:px-5",children:[e.jsxs("div",{className:"flex flex-col items-center text-center mb-14",children:[e.jsxs("div",{className:"relative mb-8",children:[e.jsx("div",{className:"absolute -inset-10 rounded-full bg-accent/[0.06] blur-3xl animate-welcome-breathe"}),e.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/25 animate-welcome-ring"}),e.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/15 animate-welcome-ring-delayed"}),e.jsx("div",{className:"relative w-[88px] h-[88px] rounded-full bg-accent/[0.07] border border-accent/20 flex items-center justify-center welcome-logo-shadow",children:e.jsx("img",{src:"/favicon.png",className:"w-12 h-12 rounded-full",alt:"Groove"})})]}),e.jsx("h1",{className:"text-4xl font-bold text-text-0 tracking-tight mb-3 font-sans max-sm:text-3xl",children:"Welcome to Groove"}),e.jsxs("p",{className:"text-base text-text-2 font-sans max-w-md leading-relaxed max-sm:text-sm",children:["The most powerful agenticOS ever built.",e.jsx("br",{className:"max-sm:hidden"}),e.jsx("span",{className:"max-sm:hidden",children:" "}),"Spawn fast. Stay aware. Never lose context."]})]}),e.jsxs("div",{className:"w-full max-w-2xl grid grid-cols-2 gap-4 mb-14 max-sm:grid-cols-1 max-sm:max-w-sm",children:[e.jsxs("button",{onClick:()=>b(!0),className:"group relative overflow-hidden rounded-xl border border-accent/20 bg-gradient-to-br from-accent/[0.08] via-accent/[0.03] to-transparent p-6 text-left hover:border-accent/40 hover:from-accent/[0.14] hover:via-accent/[0.06] transition-all duration-300 cursor-pointer",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/15 border border-accent/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300",children:e.jsx(Ys,{size:24,className:"text-accent"})}),e.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Open Project"}),e.jsx("div",{className:"text-sm text-text-2 font-sans",children:"Browse the filesystem to pick a project"}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-accent font-sans mt-4 opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:["Browse files ",e.jsx(Mo,{size:12})]})]}),e.jsxs("button",{onClick:x,className:"group relative overflow-hidden rounded-xl border border-border bg-surface-1 p-6 text-left hover:border-accent/30 hover:bg-surface-2 transition-all duration-300 cursor-pointer",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-surface-4 border border-border-subtle flex items-center justify-center mb-4 group-hover:scale-110 group-hover:bg-accent/10 group-hover:border-accent/20 transition-all duration-300",children:e.jsx(Ui,{size:24,className:"text-text-2 group-hover:text-accent transition-colors duration-300"})}),e.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Connect to Remote"}),e.jsx("div",{className:"text-sm text-text-2 font-sans",children:"SSH tunnel to a server running Groove"}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-accent font-sans mt-4 opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:["Setup connection ",e.jsx(Mo,{size:12})]})]})]}),C&&e.jsxs("div",{className:Z("w-full max-w-4xl gap-6 mb-14 max-sm:flex max-sm:flex-col max-sm:gap-6",j&&N?"grid grid-cols-2":"flex justify-center"),children:[j&&e.jsxs("div",{className:Z(!N&&"w-full max-w-lg"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Dn,{size:13,className:"text-text-3"}),e.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Recent Projects"})]}),e.jsx("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:S.map(P=>e.jsxs("div",{className:"group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-surface-3 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/10 transition-colors",children:e.jsx(Ys,{size:14,className:"text-text-3 group-hover:text-accent transition-colors"})}),e.jsxs("button",{onClick:()=>s(P.path),className:"flex-1 min-w-0 text-left cursor-pointer",children:[e.jsx("div",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:P.name}),e.jsx("div",{className:"text-2xs font-mono text-text-4 truncate",children:P.path})]}),e.jsx("button",{onClick:T=>{T.stopPropagation(),n(P.path)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all flex-shrink-0",title:"Remove from recent",children:e.jsx(qe,{size:14})})]},P.path))})]}),N&&e.jsxs("div",{className:Z(!j&&"w-full max-w-lg"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ns,{size:13,className:"text-text-3"}),e.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"SSH Connections"})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:[r.map(P=>e.jsxs("div",{className:Z("group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",v===P.id&&"opacity-60 pointer-events-none"),children:[e.jsx("div",{className:Z("w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 transition-colors",P.active?"bg-success/10":"bg-surface-3 group-hover:bg-accent/10"),children:e.jsx(Ns,{size:14,className:Z("transition-colors",P.active?"text-success":"text-text-3 group-hover:text-accent")})}),e.jsxs("button",{onClick:()=>U(P),disabled:v===P.id,className:"flex-1 min-w-0 text-left cursor-pointer",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:P.name}),P.active&&e.jsx(Gt,{status:"running",size:"sm"})]}),e.jsxs("div",{className:"text-2xs font-mono text-text-4 truncate",children:[P.user,"@",P.host]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[v===P.id?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(De,{size:14,className:"text-text-3 animate-spin"}),(g==null?void 0:g.id)===P.id&&(g==null?void 0:g.step)&&e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:{testing:"Testing…",installing:"Installing…",checking:"Checking for updates…",upgrading:"Updating remote…",starting:"Starting daemon…",connecting:"Connecting…",forwarding:"Establishing tunnel…"}[g.step]||g.step})]}):P.active?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>U(P),className:"opacity-0 group-hover:opacity-100 flex items-center gap-0.5 text-2xs text-success hover:text-success/80 cursor-pointer transition-all font-sans",children:[e.jsx(Ws,{size:11})," Open"]}),e.jsx("button",{onClick:async()=>{await f(P.id),h("info","Disconnected",P.name)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all",title:"Disconnect",children:e.jsx(Yx,{size:12})})]}):null,e.jsx("button",{onClick:T=>{T.stopPropagation(),c(P.id)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all flex-shrink-0",title:"Remove connection",children:e.jsx(qe,{size:14})})]})]},P.id)),e.jsxs("button",{onClick:x,className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer transition-colors w-full px-4 py-2.5 hover:bg-surface-2/30",children:[e.jsx(it,{size:11})," Add Connection"]})]})]})]}),e.jsx("div",{className:"mt-auto pt-8 flex flex-col items-center gap-4",children:e.jsxs("div",{className:"flex items-center gap-5 text-xs text-text-4 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘K"}),e.jsx("span",{children:"palette"})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘N"}),e.jsx("span",{children:"spawn"})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘J"}),e.jsx("span",{children:"terminal"})]})]})})]}),e.jsx(gc,{open:O,onOpenChange:b,currentPath:a||"/home",homePath:a,onSelect:P=>{b(!1),s(P)}}),e.jsx(NC,{}),e.jsx(ZS,{})]})}const Xee={js:"text-text-2",jsx:"text-text-2",ts:"text-text-2",tsx:"text-text-2",css:"text-text-3",html:"text-text-3",json:"text-text-3",md:"text-text-3",py:"text-text-2",rs:"text-text-3",go:"text-text-2",sh:"text-text-3",yaml:"text-text-3",yml:"text-text-3",sql:"text-text-3",xml:"text-text-3",svg:"text-text-3"};function Gee(t){var n;const s=(n=t.split(".").pop())==null?void 0:n.toLowerCase();return Xee[s]||"text-text-3"}function Zee({x:t,y:s,items:n,onClose:a}){const r=p.useRef(null);return p.useEffect(()=>{function l(c){r.current&&!r.current.contains(c.target)&&a()}return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[a]),e.jsx("div",{ref:r,className:"fixed z-50 min-w-[160px] py-1 bg-surface-2 border border-border rounded-lg shadow-xl",style:{left:t,top:s},children:n.map((l,c)=>l.separator?e.jsx("div",{className:"h-px bg-border-subtle my-1"},c):e.jsxs("button",{onClick:()=>{l.action(),a()},className:Z("w-full flex items-center gap-2.5 px-3 py-1.5 text-xs font-sans text-left cursor-pointer transition-colors",l.danger?"text-danger hover:bg-danger/10":"text-text-1 hover:bg-surface-5"),children:[l.icon&&e.jsx(l.icon,{size:12,className:l.danger?"text-danger":"text-text-3"}),l.label]},c))})}function Tx({defaultValue:t="",placeholder:s,onSubmit:n,onCancel:a,depth:r=0}){const[l,c]=p.useState(t),A=p.useRef(null);p.useEffect(()=>{var x,h;(x=A.current)==null||x.focus(),t&&((h=A.current)==null||h.select())},[t]);function f(x){if(x.key==="Enter"){const h=l.trim();h&&n(h)}x.key==="Escape"&&a()}return e.jsx("div",{className:"flex items-center py-0.5",style:{paddingLeft:r*16+8},children:e.jsx("input",{ref:A,value:l,onChange:x=>c(x.target.value),onKeyDown:f,onBlur:a,placeholder:s,className:"w-full h-5 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none"})})}function Vee({status:t}){if(!t)return null;const s=t==="A"||t==="?"?"bg-success":t==="D"?"bg-danger":"bg-warning";return e.jsx("span",{className:Z("w-1.5 h-1.5 rounded-full flex-shrink-0",s)})}function Kee(t,s){const n=document.createElement("a");n.href=`/api/files/download?path=${encodeURIComponent(t)}`,n.download=s?`${t.split("/").pop()}.zip`:t.split("/").pop(),document.body.appendChild(n),n.click(),n.remove()}function E4({entry:t,depth:s=0,activePath:n,onFileClick:a,onDirToggle:r,expanded:l,onContextMenu:c,dragState:A,onDragStartEntry:f,onDragEndEntry:x,onSetDragOver:h,onDropOnDir:g,gitStatusMap:O}){const b=t.type==="dir",v=n===t.path,y=l.has(t.path),S=s*16+8,j=(A==null?void 0:A.draggingPath)===t.path,N=b&&(A==null?void 0:A.dragOverPath)===t.path,C=b?null:O==null?void 0:O[t.path];function U(P){P.preventDefault(),P.stopPropagation(),c(P,t)}return e.jsxs("button",{draggable:!0,onDragStart:P=>{P.dataTransfer.setData("application/json",JSON.stringify({path:t.path,name:t.name,type:t.type})),P.dataTransfer.effectAllowed="move",f(t.path)},onDragEnd:x,onDragOver:P=>{P.preventDefault(),b&&(P.stopPropagation(),h(t.path))},onDrop:P=>g(b?t.path:t.path.includes("/")?t.path.split("/").slice(0,-1).join("/"):"",P),onClick:()=>b?r(t.path):a(t.path),onDoubleClick:U,onContextMenu:U,className:Z("w-full flex items-center gap-1.5 py-[3px] text-xs font-sans cursor-pointer","hover:bg-surface-5 transition-colors text-left select-none",v&&"bg-accent/10 text-text-0",!v&&"text-text-1",j&&"opacity-50",N&&"bg-accent/15 ring-1 ring-accent/50 rounded"),style:{paddingLeft:S},children:[b?e.jsxs(e.Fragment,{children:[y?e.jsx(xt,{size:12,className:"text-text-4 flex-shrink-0"}):e.jsx(Tt,{size:12,className:"text-text-4 flex-shrink-0"}),y?e.jsx(Ys,{size:14,className:"text-accent flex-shrink-0"}):e.jsx(Li,{size:14,className:"text-text-3 flex-shrink-0"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-3"}),e.jsx(Lo,{size:14,className:Z("flex-shrink-0",Gee(t.name))})]}),e.jsx("span",{className:"truncate flex-1",children:t.name}),C&&e.jsx(Vee,{status:C})]})}function P4({dirPath:t,depth:s,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:x,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y}){const S=c[t]||[];return p.useEffect(()=>{r.has(t)&&!c[t]&&A(t)},[r,t,c,A]),r.has(t)?e.jsxs(e.Fragment,{children:[(x==null?void 0:x.parentPath)===t&&e.jsx(Tx,{placeholder:x.type==="file"?"filename.ext":"folder-name",onSubmit:x.onSubmit,onCancel:x.onCancel,depth:s}),S.map(j=>e.jsxs("div",{children:[(x==null?void 0:x.renamePath)===j.path?e.jsx(Tx,{defaultValue:j.name,onSubmit:x.onSubmit,onCancel:x.onCancel,depth:s}):e.jsx(E4,{entry:j,depth:s,activePath:n,onFileClick:a,onDirToggle:l,expanded:r,onContextMenu:f,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y}),j.type==="dir"&&e.jsx(P4,{dirPath:j.path,depth:s+1,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:x,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y})]},j.path))]}):null}function qee({rootDir:t,onCollapse:s}){const n=k(L=>L.editorTreeCache),a=k(L=>L.editorActiveFile),r=k(L=>L.openFile),l=k(L=>L.fetchTreeDir),c=k(L=>L.addToast),[A,f]=p.useState(new Set([""])),[x,h]=p.useState(""),[g,O]=p.useState(null),[b,v]=p.useState(null),[y,S]=p.useState({draggingPath:null,dragOverPath:null}),[j,N]=p.useState([]);p.useEffect(()=>{l("")},[l,t]),p.useEffect(()=>{G.get("/files/git-status").then(L=>{N(L.entries||[])}).catch(()=>N([]))},[t]);const C={};for(const L of j)C[L.path]=L.status;function U(L){f(J=>{const D=new Set(J);return D.has(L)?D.delete(L):D.add(L),D})}function P(){f(new Set([""]))}function T(L){S({draggingPath:L,dragOverPath:null})}function B(){S({draggingPath:null,dragOverPath:null})}function F(L){S(J=>J.dragOverPath===L?J:{...J,dragOverPath:L})}async function M(L,J){var V,te;if(J.preventDefault(),J.stopPropagation(),S({draggingPath:null,dragOverPath:null}),((te=(V=J.dataTransfer)==null?void 0:V.files)==null?void 0:te.length)>0){q(L,Array.from(J.dataTransfer.files));return}let D;try{D=JSON.parse(J.dataTransfer.getData("application/json"))}catch{return}if(!(D!=null&&D.path))return;if(D.type==="dir"&&(L===D.path||L.startsWith(D.path+"/"))){c("error","Cannot move a folder into itself");return}const se=W(D.path);if(se===L)return;const le=L?`${L}/${D.name}`:D.name;try{await G.post("/files/rename",{oldPath:D.path,newPath:le}),l(se),l(L),c("success",`Moved ${D.name} to ${L||"/"}`)}catch(ae){c("error","Move failed",ae.message)}}function R(L,J){O({x:L.clientX,y:L.clientY,entry:J})}function Y(L){L.preventDefault(),O({x:L.clientX,y:L.clientY,entry:{type:"dir",path:"",name:"root"}})}function W(L){const J=L.split("/");return J.pop(),J.join("/")}async function ee(L){f(J=>new Set([...J,L])),v({type:"file",parentPath:L,onSubmit:async J=>{const D=L?`${L}/${J}`:J;try{await G.post("/files/create",{path:D,content:""}),l(L),r(D),c("success",`Created ${J}`)}catch(se){c("error","Create failed",se.message)}v(null)},onCancel:()=>v(null)})}async function K(L){f(J=>new Set([...J,L])),v({type:"folder",parentPath:L,onSubmit:async J=>{const D=L?`${L}/${J}`:J;try{await G.post("/files/mkdir",{path:D}),l(L),f(se=>new Set([...se,D])),c("success",`Created ${J}/`)}catch(se){c("error","Create folder failed",se.message)}v(null)},onCancel:()=>v(null)})}async function _(L){v({type:"rename",renamePath:L.path,onSubmit:async J=>{const D=W(L.path),se=D?`${D}/${J}`:J;try{await G.post("/files/rename",{oldPath:L.path,newPath:se}),l(D),c("success",`Renamed to ${J}`)}catch(le){c("error","Rename failed",le.message)}v(null)},onCancel:()=>v(null)})}async function E(L){const J=L.type==="dir"?`folder "${L.name}" and all contents`:`"${L.name}"`;if(window.confirm(`Delete ${J}?`))try{await G.delete(`/files/delete?path=${encodeURIComponent(L.path)}`),l(W(L.path)),c("success",`Deleted ${L.name}`)}catch(D){c("error","Delete failed",D.message)}}async function q(L,J){const D=[];for(const se of J){const le=await new Promise((V,te)=>{const ae=new FileReader;ae.onload=()=>V(ae.result.split(",")[1]),ae.onerror=te,ae.readAsDataURL(se)});D.push({name:se.name,content:le})}try{const se=await G.post("/files/upload",{dir:L,files:D});c("success",`Uploaded ${se.total} file${se.total!==1?"s":""}`),l(L)}catch(se){c("error","Upload failed",se.message)}}function H(L){const J=L.type==="dir",D=[];return J&&(D.push({icon:Vl,label:"New File",action:()=>ee(L.path)}),D.push({icon:RA,label:"New Folder",action:()=>K(L.path)})),L.name!=="root"?(D.push({icon:qs,label:J?"Download as ZIP":"Download",action:()=>Kee(L.path,J)}),D.length>0&&D.push({separator:!0}),D.push({icon:Ua,label:"Rename",action:()=>_(L)}),D.push({icon:Ft,label:"Delete",danger:!0,action:()=>E(L)})):(D.length=0,D.push({icon:Vl,label:"New File",action:()=>ee("")}),D.push({icon:RA,label:"New Folder",action:()=>K("")})),D}const I=n[""]||[];return e.jsxs("div",{className:"flex flex-col h-full bg-surface-1",onContextMenu:Y,children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(As,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:x,onChange:L=>h(L.target.value),placeholder:"Filter...",className:"w-full h-6 pl-6 pr-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-1 placeholder:text-text-4 focus:outline-none focus:border-accent font-sans"})]}),e.jsx("button",{onClick:()=>ee(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New file",children:e.jsx(Vl,{size:12})}),e.jsx("button",{onClick:()=>K(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New folder",children:e.jsx(RA,{size:12})}),e.jsx("button",{onClick:()=>l(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Refresh",children:e.jsx(Ls,{size:12})}),e.jsx("button",{onClick:P,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse all",children:e.jsx(wS,{size:12})}),s&&e.jsx("button",{onClick:s,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse sidebar",children:e.jsx(Vx,{size:12})})]}),e.jsx(Qt,{className:"flex-1",children:e.jsxs("div",{className:"py-1 min-h-full",onDragOver:L=>{L.preventDefault(),y.draggingPath&&F(null)},onDrop:L=>M("",L),children:[(b==null?void 0:b.parentPath)===""&&e.jsx(Tx,{placeholder:b.type==="file"?"filename.ext":"folder-name",onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}),I.filter(L=>!x||L.name.toLowerCase().includes(x.toLowerCase())).map(L=>e.jsxs("div",{children:[(b==null?void 0:b.renamePath)===L.path?e.jsx(Tx,{defaultValue:L.name,onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}):e.jsx(E4,{entry:L,depth:0,activePath:a,onFileClick:r,onDirToggle:U,expanded:A,onContextMenu:R,dragState:y,onDragStartEntry:T,onDragEndEntry:B,onSetDragOver:F,onDropOnDir:M,gitStatusMap:C}),L.type==="dir"&&e.jsx(P4,{dirPath:L.path,depth:1,activePath:a,onFileClick:r,expanded:A,onDirToggle:U,treeCache:n,fetchTreeDir:l,onContextMenu:R,inlineInput:b,dragState:y,onDragStartEntry:T,onDragEndEntry:B,onSetDragOver:F,onDropOnDir:M,gitStatusMap:C})]},L.path)),I.length===0&&!x&&e.jsxs("div",{className:"px-3 py-6 text-center",children:[e.jsx("p",{className:"text-xs text-text-4",children:"No files found"}),e.jsx("button",{onClick:()=>l(""),className:"mt-2 text-xs text-accent hover:underline cursor-pointer",children:"Retry"})]})]})}),g&&e.jsx(Zee,{x:g.x,y:g.y,items:H(g.entry),onClose:()=>O(null)})]})}function Wee(){const t=k(y=>y.editorOpenTabs),s=k(y=>y.editorActiveFile),n=k(y=>y.editorFiles),a=k(y=>y.setActiveFile),r=k(y=>y.closeFile),l=p.useRef(null),[c,A]=p.useState(!1),f=p.useCallback(()=>{const y=l.current;y&&A(y.scrollWidth>y.clientWidth)},[]);p.useEffect(()=>{f();const y=l.current;if(!y)return;const S=new ResizeObserver(f);return S.observe(y),()=>S.disconnect()},[f,t.length]);function x(){var y;(y=l.current)==null||y.scrollBy({left:-120,behavior:"smooth"})}function h(){var y;(y=l.current)==null||y.scrollBy({left:120,behavior:"smooth"})}function g(y){t.filter(S=>S!==y).forEach(S=>r(S))}function O(){[...t].forEach(y=>r(y))}function b(y){const S=t.indexOf(y);t.slice(S+1).forEach(j=>r(j))}function v(y){var S;(S=navigator.clipboard)==null||S.writeText(y)}return t.length===0?null:e.jsxs("div",{className:"flex items-stretch h-9 bg-surface-3 border-b border-border-subtle flex-shrink-0",children:[c&&e.jsx("button",{onClick:x,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:e.jsx(Di,{size:14})}),e.jsx("div",{ref:l,className:"flex items-stretch flex-1 min-w-0 overflow-x-auto scrollbar-none scroll-smooth",style:{scrollSnapType:"x mandatory"},children:t.map(y=>{const S=y===s,j=n[y],N=j&&j.content!==j.originalContent,C=y.split("/").pop();return e.jsxs(Uv,{children:[e.jsx(Ev,{asChild:!0,children:e.jsxs("div",{className:Z("flex items-center gap-1.5 px-3 text-xs font-sans cursor-pointer select-none","border-r border-white/5","transition-colors duration-75 flex-shrink-0",S?"bg-surface-0 text-text-0 border-b border-b-accent":"bg-surface-3 text-text-4 hover:text-text-1 hover:bg-surface-4 border-b border-b-transparent"),style:{scrollSnapAlign:"start"},onClick:()=>a(y),onAuxClick:U=>{U.button===1&&(U.preventDefault(),r(y))},children:[e.jsx("span",{className:"truncate max-w-[120px]",children:C}),N&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-warning flex-shrink-0"}),e.jsx("button",{onClick:U=>{U.stopPropagation(),r(y)},className:"p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 transition-colors cursor-pointer ml-0.5",children:e.jsx(qe,{size:12})})]})}),e.jsxs(Pv,{children:[e.jsxs(ya,{onSelect:()=>r(y),children:[e.jsx(qe,{size:12,className:"text-text-3"})," Close"]}),e.jsxs(ya,{onSelect:()=>g(y),children:[e.jsx(AO,{size:12,className:"text-text-3"})," Close Others"]}),e.jsxs(ya,{onSelect:()=>O(),children:[e.jsx(AO,{size:12,className:"text-text-3"})," Close All"]}),e.jsxs(ya,{onSelect:()=>b(y),children:[e.jsx(Tt,{size:12,className:"text-text-3"})," Close to the Right"]}),e.jsx(Fv,{}),e.jsxs(ya,{onSelect:()=>v(y),children:[e.jsx(Ba,{size:12,className:"text-text-3"})," Copy Path"]})]})]},y)})}),c&&e.jsx("button",{onClick:h,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:e.jsx(Tt,{size:14})})]})}const Yee={javascript:"JavaScript",typescript:"TypeScript",css:"CSS",html:"HTML",json:"JSON",markdown:"Markdown",python:"Python"},F4=Object.keys(Po),$4=F4.filter(t=>!["githubLight","vscodeLight","eclipse","xcodeLight","solarizedLight","gruvboxLight","materialLight","duotoneLight","quietlight","bbedit","tokyoNightDay","basicLight"].includes(t)),Jee=F4.filter(t=>!$4.includes(t));function ete({cursorPos:t,language:s}){var A;const n=k(f=>f.editorTheme),a=k(f=>f.setEditorTheme),[r,l]=p.useState(!1),c=p.useRef(null);return p.useEffect(()=>{if(!r)return;function f(x){c.current&&!c.current.contains(x.target)&&l(!1)}return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[r]),e.jsxs("div",{className:"flex items-center justify-between h-6 px-3 bg-surface-1 border-t border-border-subtle text-2xs font-sans text-text-3 flex-shrink-0 select-none",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("span",{children:["Ln ",t.line,", Col ",t.col]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",ref:c,children:[e.jsxs("button",{onClick:()=>l(!r),className:"flex items-center gap-1.5 hover:text-text-0 transition-colors cursor-pointer",children:[e.jsx(YM,{size:10}),e.jsx("span",{children:((A=Po[n])==null?void 0:A.label)||n})]}),r&&e.jsxs("div",{className:"absolute bottom-6 right-0 w-48 max-h-72 overflow-y-auto rounded-md border border-border bg-surface-2 shadow-xl z-50 py-1 scrollbar-thin",children:[e.jsx("div",{className:"px-2 py-1 text-2xs text-text-4 font-semibold uppercase tracking-wider",children:"Dark"}),$4.map(f=>e.jsx("button",{onClick:()=>{a(f),l(!1)},className:Z("w-full text-left px-3 py-1 text-2xs font-sans cursor-pointer transition-colors",f===n?"text-accent bg-accent/10":"text-text-1 hover:bg-surface-4"),children:Po[f].label},f)),e.jsx("div",{className:"px-2 py-1 mt-1 text-2xs text-text-4 font-semibold uppercase tracking-wider border-t border-border-subtle",children:"Light"}),Jee.map(f=>e.jsx("button",{onClick:()=>{a(f),l(!1)},className:Z("w-full text-left px-3 py-1 text-2xs font-sans cursor-pointer transition-colors",f===n?"text-accent bg-accent/10":"text-text-1 hover:bg-surface-4"),children:Po[f].label},f))]})]}),e.jsx("span",{className:"cursor-default",children:Yee[s]||s||"Plain Text"}),e.jsx("span",{children:"Spaces: 2"}),e.jsx("span",{children:"UTF-8"})]})]})}function tte({currentLine:t,onGoto:s,onClose:n}){const[a,r]=p.useState(""),l=p.useRef(null);p.useEffect(()=>{var A;(A=l.current)==null||A.focus()},[]);function c(A){if(A.key==="Enter"){const f=parseInt(a,10);f>0&&s(f),n()}A.key==="Escape"&&n()}return e.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20 flex items-center gap-2 bg-surface-2 border border-border rounded-lg shadow-xl p-2",children:[e.jsx("label",{className:"text-2xs font-sans text-text-3 whitespace-nowrap",children:"Go to Line:"}),e.jsx("input",{ref:l,value:a,onChange:A=>r(A.target.value),onKeyDown:c,onBlur:n,placeholder:String(t),className:"w-20 h-6 px-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-mono focus:outline-none focus:border-accent"})]})}function ste({path:t}){if(!t)return null;const s=t.split("/").filter(Boolean);return e.jsx("div",{className:"flex items-center h-7 px-3 bg-surface-2 border-b border-border-subtle text-2xs font-sans text-text-3 overflow-hidden flex-shrink-0 select-none",children:s.map((n,a)=>{const r=a===s.length-1;return e.jsxs("span",{className:"flex items-center min-w-0",children:[a>0&&e.jsx(Tt,{size:10,className:"mx-0.5 flex-shrink-0 text-text-4"}),e.jsx("span",{className:r?"text-text-1 font-medium truncate":"hover:text-text-1 cursor-pointer truncate transition-colors",children:n})]},a)})})}function nte(t){var n;const s=(n=t==null?void 0:t.split(".").pop())==null?void 0:n.toLowerCase();return s==="html"||s==="htm"}const ate=240,rte=160,ote=400;function ite(){const t=k(J=>J.editorActiveFile),s=k(J=>J.editorFiles),n=k(J=>J.updateFileContent),a=k(J=>J.saveFile),r=k(J=>J.editorSidebarWidth),l=k(J=>J.setEditorSidebarWidth),c=k(J=>J.projectDir),[A,f]=p.useState(""),[x,h]=p.useState(!1),[g,O]=p.useState(0),[b,v]=p.useState({line:1,col:1}),[y,S]=p.useState(!1),[j,N]=p.useState(!1),[C,U]=p.useState(!1),P=p.useRef(0),T=k(J=>J.addToast),B=k(J=>J.fetchTreeDir),F=p.useRef(null),M=p.useRef(!1),R=p.useRef(0),Y=p.useRef(0);p.useEffect(()=>{G.get("/files/root").then(J=>f(J.root||"")).catch(()=>{})},[c]),p.useEffect(()=>{h(!1)},[t]),p.useEffect(()=>{function J(D){(D.metaKey||D.ctrlKey)&&D.key==="g"&&(D.preventDefault(),S(!0))}return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[]);function W(J){var D,se;J.preventDefault(),P.current++,(se=(D=J.dataTransfer)==null?void 0:D.types)!=null&&se.includes("Files")&&U(!0)}function ee(J){J.preventDefault(),P.current--,P.current<=0&&(P.current=0,U(!1))}function K(J){J.preventDefault(),J.dataTransfer.dropEffect="copy"}async function _(J){var le;J.preventDefault(),P.current=0,U(!1);const D=(le=J.dataTransfer)==null?void 0:le.files;if(!(D!=null&&D.length))return;const se=[];for(const V of Array.from(D)){const te=await new Promise((ae,be)=>{const z=new FileReader;z.onload=()=>ae(z.result.split(",")[1]),z.onerror=be,z.readAsDataURL(V)});se.push({name:V.name,content:te})}try{const V=await G.post("/files/upload",{dir:"",files:se});T("success",`Uploaded ${V.total} file${V.total!==1?"s":""}`),B("")}catch(V){T("error","Upload failed",V.message)}}const E=p.useCallback(J=>{J.preventDefault(),M.current=!0,R.current=J.clientX,Y.current=r;function D(le){if(!M.current)return;const V=le.clientX-R.current,te=Math.min(Math.max(Y.current+V,rte),ote);l(te)}function se(){M.current=!1,document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",se)}document.addEventListener("mousemove",D),document.addEventListener("mouseup",se)},[r,l]);function q(J){const D=F.current;if(!D)return;const se=D.state.doc.line(Math.min(J,D.state.doc.lines));D.dispatch({selection:{anchor:se.from},scrollIntoView:!0}),D.focus()}const H=t?s[t]:null,I=t&&g5(t),L=t&&nte(t);return e.jsxs("div",{className:"flex h-full",children:[e.jsxs("div",{className:Z("relative flex-shrink-0 border-r border-border transition-all duration-200 overflow-hidden",j&&"w-0 border-r-0"),style:j?void 0:{width:r},children:[e.jsx(qee,{rootDir:A,onCollapse:()=>N(!0)}),e.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:E,onDoubleClick:()=>l(ate)})]}),j&&e.jsx("button",{onClick:()=>N(!1),className:"flex-shrink-0 w-6 flex items-start justify-center pt-2 border-r border-border bg-surface-2 text-text-4 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",title:"Show sidebar",children:e.jsx(Kx,{size:14})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-surface-1 relative",onDragEnter:W,onDragLeave:ee,onDragOver:K,onDrop:_,children:[C&&e.jsx("div",{className:"absolute inset-0 z-50 bg-accent/8 border-2 border-dashed border-accent/40 rounded-lg flex items-center justify-center pointer-events-none",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 text-accent",children:[e.jsx(Hb,{size:32}),e.jsx("span",{className:"text-sm font-semibold font-sans",children:"Drop files to upload"})]})}),e.jsx(Wee,{}),t&&!I&&e.jsx(ste,{path:t}),e.jsxs("div",{className:"flex-1 relative min-h-0",children:[y&&e.jsx(tte,{currentLine:b.line,onGoto:q,onClose:()=>S(!1)}),!t&&e.jsx("div",{className:"w-full h-full flex items-center justify-center text-text-4 font-sans",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(bn,{size:32,className:"mx-auto"}),e.jsx("p",{className:"text-sm",children:"Open a file from the tree"})]})}),t&&I&&e.jsx(O5,{path:t}),t&&!I&&L&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"absolute top-0 right-4 z-10 flex items-center gap-0.5 mt-2 bg-surface-2 border border-border-subtle rounded-md p-0.5",children:[e.jsxs("button",{onClick:()=>h(!1),className:Z("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",x?"text-text-3 hover:text-text-1":"bg-surface-4 text-text-0 font-medium"),children:[e.jsx(Fb,{size:12})," Code"]}),e.jsxs("button",{onClick:()=>{h(!0),O(J=>J+1)},className:Z("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",x?"bg-surface-4 text-text-0 font-medium":"text-text-3 hover:text-text-1"),children:[e.jsx(Vs,{size:12})," Preview"]})]}),x?e.jsx("iframe",{src:`/api/files/raw?path=${encodeURIComponent(t)}`,className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin",title:"HTML Preview"},g):H&&e.jsx(KO,{content:H.content,language:H.language,onChange:J=>n(t,J),onSave:()=>a(t),onCursorChange:v,viewRef:F})]}),t&&!I&&!L&&H&&e.jsx(KO,{content:H.content,language:H.language,onChange:J=>n(t,J),onSave:()=>a(t),onCursorChange:v,viewRef:F})]}),t&&!I&&e.jsx(ete,{cursorPos:b,language:H==null?void 0:H.language})]})]})}function lte(){var C;const t=k(U=>U.connected),s=k(U=>U.agents),[n,a]=p.useState(null),[r,l]=p.useState([]),[c,A]=p.useState({constraints:[],discoveries:[],roles:[],specializations:null}),[f,x]=p.useState(!0),[h,g]=p.useState({tokens:[],cost:[],saved:[],efficiency:[],cache:[],inputOutput:[],agents:[],turns:[]}),O=p.useRef(0);p.useEffect(()=>{if(!t)return;let U=!0;async function P(){try{const[B,F,M,R,Y,W]=await Promise.all([G.get("/dashboard"),G.get("/tokens/by-team").catch(()=>({teams:[]})),G.get("/memory/constraints").catch(()=>({constraints:[]})),G.get("/memory/discoveries?limit=20").catch(()=>({discoveries:[]})),G.get("/memory/handoff-chain").catch(()=>({roles:[]})),G.get("/memory/specializations").catch(()=>({perAgent:{},perProjectRole:{}}))]);if(!U)return;a(B),l((F==null?void 0:F.teams)||[]),A({constraints:(M==null?void 0:M.constraints)||[],discoveries:(R==null?void 0:R.discoveries)||[],roles:(Y==null?void 0:Y.roles)||[],specializations:W||{perAgent:{},perProjectRole:{}}}),x(!1),O.current=Date.now(),g(ee=>{var D,se,le,V,te,ae,be,z,oe;const K=Date.now(),_=(ue,ve)=>[...ue.slice(-59),{t:K,v:ve||0}],E=((D=B.tokens)==null?void 0:D.totalTokens)||0,q=((se=B.tokens)==null?void 0:se.totalInputTokens)||0,H=((le=B.tokens)==null?void 0:le.totalOutputTokens)||0,L=(((V=B.agents)==null?void 0:V.breakdown)||[]).filter(ue=>{var ve;return((ve=ue.quality)==null?void 0:ve.score)!=null}),J=L.length>0?L.reduce((ue,ve)=>ue+ve.quality.score,0)/L.length:0;return{tokens:_(ee.tokens,E),cost:_(ee.cost,(te=B.tokens)==null?void 0:te.totalCostUsd),saved:_(ee.saved,J),efficiency:_(ee.efficiency,((ae=B.rotation)==null?void 0:ae.totalRotations)||0),cache:_(ee.cache,(be=B.tokens)==null?void 0:be.cacheHitRate),inputOutput:_(ee.inputOutput,H>0?q/H:0),agents:_(ee.agents,((z=B.agents)==null?void 0:z.running)||0),turns:_(ee.turns,(oe=B.tokens)==null?void 0:oe.totalTurns)}})}catch{U&&x(!1)}}P();const T=setInterval(P,4e3);return()=>{U=!1,clearInterval(T)}},[t]);const b=((C=n==null?void 0:n.agents)==null?void 0:C.breakdown)||[],v=(n==null?void 0:n.routing)||null,y=(n==null?void 0:n.rotation)||null,S=(n==null?void 0:n.adaptive)||[],j=(n==null?void 0:n.journalist)||null,N=(y==null?void 0:y.rotating)||[];return{data:n,loading:f,agents:s,connected:t,kpiHistory:h,lastFetch:O.current,agentBreakdown:b,routing:v,rotation:y,adaptive:S,journalist:j,rotating:N,teamBurn:r,memory:c}}const CQ=p.memo(function({connected:s,runningCount:n,totalCount:a,uptime:r,lastFetch:l,activeTeam:c}){return e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border",children:[e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Command Center"}),c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-xs font-mono text-text-2",children:c.name})]}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-text-1",children:n}),e.jsxs("span",{className:"text-text-3",children:["/",a]}),e.jsx("span",{className:"ml-1 text-text-3",children:"agents"})]}),r>0&&e.jsxs("span",{className:"text-text-3",children:["Up ",Xo(r)]}),l>0&&e.jsxs("span",{className:"flex items-center gap-1 text-text-4",children:[e.jsx(Ls,{size:9}),e.jsx("span",{children:$t(l)})]})]}),e.jsx(Gt,{status:s?"running":"crashed",size:"sm"})]})});function nt(t,s){const n=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),r=parseInt(t.slice(5,7),16);return`rgba(${n},${a},${r},${s})`}const ce={surface0:"#1a1e25",surface3:"#282c34",surface4:"#2c313a",surface5:"#333842",text0:"#e6e6e6",text1:"#bcc2cd",text2:"#8b929e",text3:"#6e7681",text4:"#505862",accent:"#33afbc",success:"#4ae168",warning:"#e5c07b",danger:"#e06c75",info:"#61afef",purple:"#c678dd",orange:"#d19a66"};function cte({data:t,color:s=ce.text3,width:n=72,height:a=22}){if(!t||t.length<2)return e.jsx("div",{style:{width:n,height:a}});const r=t.map(h=>h.v),l=Math.min(...r),A=Math.max(...r)-l||1,f=t.map((h,g)=>{const O=g/(t.length-1)*n,b=a-(h.v-l)/A*(a-2)-1;return`${O},${b}`}).join(" "),x=`kpi-${s.replace("#","")}`;return e.jsxs("svg",{width:n,height:a,className:"flex-shrink-0",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:x,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:"0.2"}),e.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:"0"})]})}),e.jsx("polygon",{points:`0,${a} ${f} ${n},${a}`,fill:`url(#${x})`}),e.jsx("polyline",{points:f,fill:"none",stroke:s,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}const Ate=p.memo(function({label:s,value:n,sparkData:a,color:r=ce.text3,hint:l,className:c}){return e.jsxs("div",{className:Z("flex items-center gap-2.5 px-3 py-2.5 min-w-0","bg-surface-1",c),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5 truncate flex items-center gap-1",children:[s,l&&e.jsx(dt,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:l}),side:"bottom",children:e.jsx(ki,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),e.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:n})]}),e.jsx(cte,{data:a,color:r})]})});function dte({kpis:t}){return e.jsx("div",{className:"flex flex-wrap border-b border-border bg-surface-0",children:t.map(s=>e.jsx(Ate,{label:s.label,value:s.value,sparkData:s.sparkData,color:s.color,hint:s.hint,className:Z("flex-1 basis-[12.5%] min-w-[140px]","border-b border-r border-border")},s.label))})}const ute={actual:"ACT",estimated:"EST",local:"LOC"};function fte(t){if(!t||t==="auto"||t==="default")return"default";const s=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gem ").replace("-preview",""):t.length>12?t.slice(0,12)+"...":t}const xte=p.memo(function({agent:s,isRotating:n}){const a=s.status==="running"||s.status==="starting",r=Math.round((s.contextUsage||0)*100),l=n?ce.accent:Gb(s.status),c=s.quality,A=(c==null?void 0:c.toolSuccessRate)!=null?Math.round(c.toolSuccessRate*100):null,f=s.rotationThreshold?Math.round(s.rotationThreshold*100):null,x=Ha(s.role),h=ce.text1;return e.jsxs("div",{className:"px-3 pl-6 py-2 hover:bg-surface-4 transition-colors space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:l}}),a&&e.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:l,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate leading-none flex-shrink-0 max-w-[80px]",children:s.name}),e.jsx("span",{className:"text-2xs font-mono font-semibold px-1.5 py-px rounded-sm flex-shrink-0 capitalize",style:{background:x.bg,color:x.text},children:(s.role||"").toLowerCase()}),e.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1 py-px rounded-sm flex-shrink-0 truncate max-w-[72px]",children:fte(s.model)}),e.jsx("div",{className:"flex-1"}),A!=null&&e.jsxs("span",{className:"text-2xs font-mono font-bold px-1 py-px rounded-sm flex-shrink-0 text-text-1 bg-surface-4",children:[A,"%"]}),s.costSource&&s.costSource!=="actual"&&e.jsx("span",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex-shrink-0",children:ute[s.costSource]||""}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[e.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums leading-none",children:jt(s.tokens||0)}),(s.costUsd||0)>0&&e.jsx("div",{className:"text-2xs font-mono text-text-3 mt-0.5",children:er(s.costUsd)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 h-0.5 rounded-sm overflow-visible",style:{background:nt(ce.text4,.2)},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 rounded-sm transition-all duration-700",style:{width:`${Math.max(r,1)}%`,background:h}}),f&&e.jsx("div",{className:"absolute top-[-1px] w-px h-[4px]",style:{left:`${f}%`,background:ce.text3},title:`Rotation at ${f}%`})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums flex-shrink-0 w-7 text-right",children:[r,"%"]})]})]})});function mte({team:t,members:s,rotatingSet:n}){const[a,r]=p.useState(!0),l=s.filter(x=>x.status==="running"||x.status==="starting").length,c=l>0,A=s.reduce((x,h)=>x+(h.tokens||0),0),f=s.reduce((x,h)=>x+(h.costUsd||0),0);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>r(x=>!x),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-surface-4 bg-surface-3",style:{borderLeft:c?`2px solid ${ce.accent}`:"2px solid transparent"},children:[a?e.jsx(xt,{size:10,className:"text-text-4 flex-shrink-0"}):e.jsx(Tt,{size:10,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-mono font-semibold text-text-2 uppercase tracking-widest flex-1 truncate",children:t}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:jt(A)}),f>0&&e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums ml-1",children:er(f)}),e.jsxs("span",{className:"text-2xs font-mono tabular-nums flex-shrink-0 ml-1.5",style:{color:c?ce.text1:void 0},children:[l,"/",s.length]})]}),a&&s.map(x=>e.jsx(xte,{agent:x,isRotating:n.has(x.id)},x.id))]})}const hte=p.memo(function({agentBreakdown:s,rotating:n=[],teams:a=[]}){if(!(s!=null&&s.length))return e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono p-4",children:"No agents"});const r={};for(const A of a)r[A.id]=A.name;const l={};for(const A of s){const f=A.teamId||"ungrouped";l[f]||(l[f]=[]),l[f].push(A)}const c=new Set(n);return e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"py-1",children:Object.entries(l).map(([A,f])=>e.jsx(mte,{team:r[A]||(A==="ungrouped"?"Ungrouped":A),members:f,rotatingSet:c},A))})})}),Is=36,nb=3,Wf=(Is-nb)/2,Qf=2*Math.PI*Wf,BQ=-90;function pte(){return ce.text1}function gte({name:t,pct:s,threshold:n}){const a=pte(),r=s/100*Qf;return e.jsxs("div",{className:"flex flex-col items-center gap-0.5",title:`${t}: ${s}% context used`,children:[e.jsxs("svg",{width:Is,height:Is,viewBox:`0 0 ${Is} ${Is}`,children:[e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:nb,className:"stroke-surface-4"}),e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:nb,strokeLinecap:"round",style:{stroke:a,strokeDasharray:`${r} ${Qf-r}`,strokeDashoffset:0,transition:"stroke-dasharray 0.5s ease"},transform:`rotate(${BQ} ${Is/2} ${Is/2})`}),n&&e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:1,strokeLinecap:"butt",style:{stroke:ce.text3,strokeDasharray:`1 ${Qf-1}`,strokeDashoffset:-(n/100)*Qf},transform:`rotate(${BQ} ${Is/2} ${Is/2})`}),e.jsx("text",{x:Is/2,y:Is/2+1,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-1 font-mono font-semibold",style:{fontSize:9},children:s})]}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate max-w-[40px] leading-none",children:t})]})}function Ote({zones:t}){return e.jsxs("div",{className:"flex items-center gap-2 text-2xs font-mono",children:[e.jsx("span",{className:"text-text-2",children:t.healthy}),e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-text-2",children:t.warning}),e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-text-2",children:t.critical})]})}const bte=p.memo(function({agentBreakdown:s}){const n=(s||[]).filter(r=>r.status==="running"||r.status==="starting");if(n.length===0)return null;const a={healthy:0,warning:0,critical:0};for(const r of n){const l=Math.round((r.contextUsage||0)*100);l>80?a.critical++:l>60?a.warning++:a.healthy++}return e.jsxs("div",{className:"px-3 py-2 flex-shrink-0 border-b border-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Context Health"}),e.jsx(Ote,{zones:a})]}),e.jsx("div",{className:"flex items-start gap-2 overflow-x-auto",children:n.map(r=>{const l=Math.round((r.contextUsage||0)*100),c=r.rotationThreshold?Math.round(r.rotationThreshold*100):null;return e.jsx(gte,{name:r.name,pct:l,threshold:c},r.id)})})]})}),vte=p.memo(function({data:s}){const n=p.useRef(null),a=p.useRef(null),[r,l]=p.useState({width:0,height:0}),[c,A]=p.useState(null),{width:f,height:x}=r,h={top:28,right:12,bottom:8,left:12},g=Math.max(f-h.left-h.right,0),O=Math.max(x-h.top-h.bottom,0),b=p.useMemo(()=>!s||s.length<2?[]:s.slice(1).map((S,j)=>{const N=s[j],C=(S.t-N.t)/6e4,U=Math.max((S.tokens||0)-(N.tokens||0),0);return{burnRate:C>0?Math.round(U/C):0,cacheHitRate:S.cacheHitRate||0,running:S.running||0,agents:S.agents||0,t:S.t}}),[s]);p.useEffect(()=>{const S=n.current;if(!S)return;const j=new ResizeObserver(N=>{const{width:C,height:U}=N[0].contentRect;C>0&&U>0&&l({width:Math.floor(C),height:Math.floor(U)})});return j.observe(S),()=>j.disconnect()},[]);const v=p.useCallback(S=>{const j=a.current;if(!j||!b.length||g<=0)return;const N=j.getBoundingClientRect(),C=S.clientX-N.left-h.left;if(C<0||C>g){A(null);return}const U=Math.round(C/g*(b.length-1));A({x:h.left+U/Math.max(b.length-1,1)*g,index:U})},[b,g,h.left]),y=p.useCallback(()=>A(null),[]);return p.useEffect(()=>{const S=a.current;if(!S||!b.length||f<=0||x<=0||g<=0||O<=0)return;const j=S.getContext("2d"),N=window.devicePixelRatio||1;S.width=f*N,S.height=x*N,j.scale(N,N),j.clearRect(0,0,f,x);const C=b.map(E=>E.burnRate),U=b.map(E=>E.cacheHitRate),P=b.map(E=>E.running),T=Math.max(...C,100),B=Math.max(...P,1),F=E=>h.left+E/Math.max(b.length-1,1)*g,M=E=>h.top+O-E/T*O,R=E=>h.top+O-E*O,Y=Math.max(g/b.length-1,2);for(let E=0;E<b.length;E++){const q=P[E];if(q<=0)continue;const H=q/B*O*.3,I=F(E)-Y/2,L=h.top+O-H;j.fillStyle=nt(ce.surface5,.5),j.fillRect(I,L,Y,H)}j.setLineDash([2,4]),j.strokeStyle=nt(ce.text4,.2),j.lineWidth=1;for(let E=1;E<=3;E++){const q=h.top+O/4*E;j.beginPath(),j.moveTo(h.left,q),j.lineTo(h.left+g,q),j.stroke()}j.setLineDash([]),j.font="9px 'SF Mono', ui-monospace, Menlo, Consolas, monospace",j.textAlign="left",j.fillStyle=nt(ce.text3,.5),j.fillText(`${jt(T)}/m`,h.left+4,h.top+10),j.fillText(`${jt(Math.round(T/2))}/m`,h.left+4,h.top+O/2+4),j.beginPath(),j.moveTo(h.left,h.top+O);for(let E=0;E<b.length;E++)j.lineTo(F(E),M(C[E]));j.lineTo(F(b.length-1),h.top+O),j.closePath();const W=j.createLinearGradient(0,h.top,0,h.top+O);W.addColorStop(0,nt(ce.accent,.2)),W.addColorStop(.7,nt(ce.accent,.04)),W.addColorStop(1,nt(ce.accent,0)),j.fillStyle=W,j.fill(),j.beginPath(),j.strokeStyle=ce.accent,j.lineWidth=1.5,j.lineJoin="round";for(let E=0;E<b.length;E++){const q=F(E),H=M(C[E]);E===0?j.moveTo(q,H):j.lineTo(q,H)}j.stroke();const ee=U.some(E=>E>0);if(ee){j.beginPath(),j.strokeStyle=nt(ce.text2,.5),j.lineWidth=1,j.lineJoin="round",j.setLineDash([2,3]);for(let E=0;E<b.length;E++){const q=F(E),H=R(U[E]);E===0?j.moveTo(q,H):j.lineTo(q,H)}j.stroke(),j.setLineDash([])}j.font="9px 'Inter Variable', sans-serif",j.textAlign="right";let K=f-h.right-4;const _=14;if(ee&&(j.fillStyle=nt(ce.text2,.5),j.fillText("Cache %",K,_),K-=j.measureText("Cache %").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),K-=14),j.fillStyle=nt(ce.surface5,.7),j.fillText("Agents",K,_),K-=j.measureText("Agents").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),K-=14,j.fillStyle=ce.accent,j.fillText("Burn Rate",K,_),K-=j.measureText("Burn Rate").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),c&&c.index>=0&&c.index<b.length){const E=c.x,q=b[c.index];j.beginPath(),j.moveTo(E,h.top),j.lineTo(E,h.top+O),j.strokeStyle=nt(ce.text1,.15),j.lineWidth=1,j.stroke();const H=M(q.burnRate);j.beginPath(),j.arc(E,H,3,0,Math.PI*2),j.fillStyle=ce.accent,j.fill();const I=[{label:"Burn",value:`${jt(q.burnRate)}/m`,color:ce.accent},{label:"Cache",value:pc(q.cacheHitRate*100),color:ce.text2},{label:"Agents",value:`${q.running}/${q.agents}`,color:ce.text3}],L=104,J=I.length*16+12;let D=E+12;D+L>f-8&&(D=E-L-12);const se=Math.max(h.top,H-J/2);j.fillStyle=nt(ce.surface0,.92),j.beginPath(),j.roundRect(D,se,L,J,4),j.fill(),j.strokeStyle=nt(ce.text4,.2),j.lineWidth=1,j.stroke(),j.textAlign="left",I.forEach((le,V)=>{const te=se+14+V*16;j.beginPath(),j.arc(D+8,te-3,2,0,Math.PI*2),j.fillStyle=le.color,j.fill(),j.font="8px 'Inter Variable', sans-serif",j.fillStyle=ce.text3,j.fillText(le.label,D+14,te),j.font="9px 'SF Mono', ui-monospace, Menlo, Consolas, monospace",j.fillStyle=ce.text0,j.textAlign="right",j.fillText(le.value,D+L-8,te),j.textAlign="left"})}},[b,f,x,c,g,O,h]),e.jsx("div",{ref:n,className:"absolute inset-0",children:f>0&&x>0&&e.jsx("canvas",{ref:a,style:{width:f,height:x},className:"block cursor-crosshair",onMouseMove:v,onMouseLeave:y})})}),yte=p.memo(function({cacheRead:s=0,cacheCreation:n=0,totalInput:a=0,size:r=140}){const l=p.useRef(null),c=s+n,A=c,f=c>0?s/c*100:0;return p.useEffect(()=>{const x=l.current;if(!x)return;const h=window.devicePixelRatio||1;x.width=r*h,x.height=r*h;const g=x.getContext("2d");g.scale(h,h),g.clearRect(0,0,r,r);const O=r/2,b=r/2,v=(r-12)/2,y=5,S=135*Math.PI/180,j=405*Math.PI/180,N=j-S;if(g.beginPath(),g.arc(O,b,v,S,j),g.strokeStyle=ce.surface4,g.lineWidth=y,g.lineCap="round",g.stroke(),A>0){const C=s/A,U=n/A;if(C>0){const P=S+N*C;g.beginPath(),g.arc(O,b,v,S,P),g.strokeStyle=ce.text0,g.lineWidth=y,g.lineCap="round",g.stroke()}if(U>0){const P=S+N*C,T=P+N*U;g.beginPath(),g.arc(O,b,v,P,T),g.strokeStyle=ce.text3,g.lineWidth=y,g.lineCap="butt",g.stroke()}}g.textAlign="center",g.textBaseline="middle",g.font=`600 ${r*.2}px 'SF Mono', ui-monospace, Menlo, Consolas, monospace`,g.fillStyle=ce.text0,g.fillText(`${Math.round(f)}%`,O,b-3),g.font=`500 ${r*.08}px 'SF Mono', ui-monospace, Menlo, Consolas, monospace`,g.fillStyle=ce.text3,g.fillText("CACHE",O,b+r*.13)},[s,n,a,r,A,f]),e.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-3 py-3",children:[e.jsx("canvas",{ref:l,className:"flex-shrink-0",style:{width:r,height:r}}),e.jsxs("div",{className:"w-full mt-3 space-y-1.5 max-w-[160px]",children:[e.jsx(Lg,{color:ce.text0,label:"Read",value:jt(s)}),e.jsx(Lg,{color:ce.text3,label:"Create",value:jt(n)}),e.jsx(Lg,{color:ce.surface5,label:"Miss",value:jt(Math.max(a-s-n,0))})]})]})});function Lg({color:t,label:s,value:n}){return e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:t}}),e.jsx("span",{className:"text-text-3 uppercase tracking-wider flex-1",children:s}),e.jsx("span",{className:"text-text-1 tabular-nums",children:n})]})}const R4={heavy:ce.text0,medium:ce.text2,light:ce.text4},wte={heavy:"Heavy",medium:"Medium",light:"Light"},an=80,ab=6,rb=(an-ab)/2,kQ=2*Math.PI*rb;function jte({byTier:t,total:s,tiers:n}){let a=0;const r=[];for(const l of n){const c=t[l]||0;if(c===0)continue;const f=c/s*kQ;r.push({tier:l,dashLen:f,offset:a}),a+=f}return s>0&&Math.round((t.heavy||0)/s*100),e.jsxs("svg",{width:an,height:an,viewBox:`0 0 ${an} ${an}`,className:"flex-shrink-0",children:[e.jsx("circle",{cx:an/2,cy:an/2,r:rb,fill:"none",strokeWidth:ab,className:"stroke-surface-4"}),r.map(l=>e.jsx("circle",{cx:an/2,cy:an/2,r:rb,fill:"none",strokeWidth:ab,strokeLinecap:"butt",style:{stroke:R4[l.tier],strokeDasharray:`${l.dashLen} ${kQ-l.dashLen}`,strokeDashoffset:-l.offset},transform:`rotate(-90 ${an/2} ${an/2})`},l.tier)),e.jsx("text",{x:an/2,y:an/2-2,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-0 text-sm font-mono font-semibold",children:jt(s)}),e.jsx("text",{x:an/2,y:an/2+11,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-3 font-mono",style:{fontSize:7},children:"decisions"})]})}const Qte=p.memo(function({routing:s,agentBreakdown:n}){if(!s)return null;const{byTier:a={},totalDecisions:r=0,autoRoutedCount:l=0}=s,c=["heavy","medium","light"],A=c.reduce((g,O)=>g+(a[O]||0),0),f={};for(const g of n||[]){const O=g.model||"default";f[O]||(f[O]={tokens:0,agents:0}),f[O].tokens+=g.tokens||0,f[O].agents+=1}const x=Object.entries(f).sort((g,O)=>O[1].tokens-g[1].tokens),h=x.length>0?x[0][1].tokens:0;return e.jsxs("div",{className:"flex flex-col h-full px-3 py-3 overflow-y-auto",children:[A>0&&e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(jte,{byTier:a,total:A,tiers:c}),e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1 min-w-0",children:[c.map(g=>{const O=a[g]||0;if(O===0)return null;const b=O/A*100;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:R4[g]}}),e.jsx("span",{className:"text-2xs font-mono text-text-2 flex-1",children:wte[g]}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums",children:O}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums w-8 text-right",children:pc(b)})]},g)}),l>0&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:[l," auto-routed"]})]})]}),x.length>0&&e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Models in Use"}),e.jsx("div",{className:"space-y-1.5",children:x.map(([g,O])=>{const b=h>0?O.tokens/h*100:0;return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 flex-1 truncate",children:Nte(g)}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[O.agents," agent",O.agents!==1?"s":""]}),e.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:jt(O.tokens)})]}),e.jsx("div",{className:"h-0.5 bg-surface-4 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.max(b,2)}%`,background:ce.text2}})})]},g)})})]}),A===0&&x.length===0&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono",children:"No routing data"})]})});function Nte(t){if(!t||t==="auto"||t==="default")return"Default";const s=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gemini ").replace("-preview",""):t}function M4({text:t}){return e.jsx(dt,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:t}),side:"bottom",children:e.jsx(ki,{size:9,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors ml-0.5"})})}function Ste({children:t,tip:s}){return e.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex items-center gap-0.5",children:[t,s&&e.jsx(M4,{text:s})]})}function Nf({label:t,value:s,tip:n}){return e.jsxs("div",{children:[e.jsx(Ste,{tip:n,children:t}),e.jsx("div",{className:"text-sm font-mono font-semibold text-text-1 tabular-nums leading-snug",children:s})]})}function jd({title:t,children:s,tip:n}){return e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-2 flex items-center gap-0.5",children:[t,n&&e.jsx(M4,{text:n})]}),s]})}function vc(){return e.jsx("div",{className:"h-px bg-border mx-3"})}function Cte({tokens:t,rotation:s,agentBreakdown:n}){const r=(n||[]).filter(c=>{var A;return((A=c.quality)==null?void 0:A.score)!=null}),l=r.length>0?Math.round(r.reduce((c,A)=>c+A.quality.score,0)/r.length):null;return e.jsxs("div",{className:"px-3 py-3 flex items-start gap-5",children:[e.jsx(Nf,{label:"Quality",value:l??"—",tip:"Average session quality (0-100). Below 40 triggers auto-rotation."}),e.jsx(Nf,{label:"Cache",value:pc(((t==null?void 0:t.cacheHitRate)||0)*100),tip:"Prompt cache hit rate. Higher = faster + cheaper."}),e.jsx(Nf,{label:"Rotations",value:(s==null?void 0:s.totalRotations)||0,tip:"Total context rotations this session."}),((t==null?void 0:t.totalCostUsd)||0)>0&&e.jsx(Nf,{label:"Cost",value:er(t.totalCostUsd),tip:"Total cost reported by providers."})]})}function Bte({agentBreakdown:t,rotation:s}){const n=(s==null?void 0:s.liveScores)||{},a=(t||[]).filter(r=>r.status==="running");return a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Live agents",children:e.jsx("div",{className:"space-y-0",children:a.map(r=>{var x;const l=r.quality||{},c=((x=n[r.id])==null?void 0:x.score)??l.score,A=Ha(r.role),f=[l.errorCount>0&&`${l.errorCount} err`,l.repetitions>0&&`${l.repetitions} rep`,l.fileChurn>0&&`${l.fileChurn} churn`].filter(Boolean);return e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[e.jsx("span",{className:"text-2xs font-semibold capitalize px-1 py-px rounded-sm flex-shrink-0",style:{background:A.bg,color:A.text},children:r.role}),e.jsx("span",{className:"text-text-2 truncate flex-1",children:r.name}),f.length>0&&e.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:f.join(" · ")}),e.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0 w-6 text-right",children:c??"—"})]},r.id)})})})]})}function kte({rotation:t}){const s=((t==null?void 0:t.history)||[]).slice(-5).reverse();if(s.length===0)return null;function n(a){return a.reason==="quality_degradation"?`Q:${a.qualityScore}`:a.reason==="token_limit_exceeded"?"tokens":a.reason==="runaway_velocity"?"velocity":a.reason==="natural_compaction"?"compacted":pc((a.contextUsage||0)*100)}return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Recent rotations",children:e.jsx("div",{className:"space-y-0",children:s.map((a,r)=>e.jsxs("div",{className:"flex items-center gap-2 py-0.5 text-xs font-mono",children:[e.jsx("span",{className:"text-text-2 truncate flex-1",children:a.agentName||a.role}),e.jsx("span",{className:"text-text-3 flex-shrink-0",children:n(a)}),e.jsx("span",{className:"text-text-4 flex-shrink-0 w-10 text-right",children:$t(a.timestamp)})]},r))})})]})}function Tte({adaptive:t}){if(!(t!=null&&t.length))return null;function s(n){const a=n.split(":");return{provider:a[0]||n,role:a[1]||""}}return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Adaptive thresholds",tip:"Per-role rotation thresholds. GROOVE learns when each role benefits from rotation and adjusts automatically.",children:e.jsx("div",{className:"space-y-0",children:t.map(n=>{const{provider:a,role:r}=s(n.key),l=r||a,c=Ha(l);return e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[e.jsx("span",{className:"text-2xs font-semibold capitalize px-1 py-px rounded-sm flex-shrink-0",style:{background:c.bg,color:c.text},children:l}),r&&e.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:a}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0",children:pc(n.threshold*100)}),n.converged?e.jsx("span",{className:"text-2xs font-semibold flex-shrink-0",style:{color:ce.accent},children:"Converged"}):e.jsxs("span",{className:"text-2xs text-text-3 flex-shrink-0 flex items-center gap-1",children:[e.jsx("span",{className:"w-1 h-1 rounded-full [animation:node-pulse-bar_1.5s_ease-in-out_infinite]",style:{background:ce.text3}}),"Learning"]})]},n.key)})})})]})}function Ute({journalist:t}){return!t||!((t.cycleCount||0)>0)&&!t.synthesizing?null:e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs(jd,{title:"Journalist",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[e.jsxs("span",{className:"text-text-2",children:[t.cycleCount||0," cycles"]}),t.lastCycleAt&&e.jsx("span",{className:"text-text-4",children:$t(t.lastCycleAt)}),t.synthesizing&&e.jsx("span",{className:"font-semibold text-accent animate-pulse",children:"Synthesizing"})]}),t.lastSummary&&e.jsx("div",{className:"text-xs text-text-3 leading-relaxed mt-1.5 line-clamp-3",children:t.lastSummary})]})]})}function Ete({memory:t}){var f,x;const s=(t==null?void 0:t.constraints)||[],n=(t==null?void 0:t.discoveries)||[],a=(t==null?void 0:t.roles)||[],r=((f=t==null?void 0:t.specializations)==null?void 0:f.perProjectRole)||{},l=Object.keys(((x=t==null?void 0:t.specializations)==null?void 0:x.perAgent)||{}).length;if(s.length+n.length+a.length+l===0)return null;const A=[s.length>0&&`${s.length} constraints`,n.length>0&&`${n.length} discoveries`,a.length>0&&`${a.length} role chains`,l>0&&`${l} specializations`].filter(Boolean);return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs(jd,{title:"Memory",tip:"Persistent knowledge across agent rotations. Constraints, error→fix discoveries, and handoff chains.",children:[e.jsx("div",{className:"text-xs font-mono text-text-3 mb-1.5",children:A.join(" · ")}),s.length>0&&e.jsxs("div",{className:"mt-2 space-y-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Constraints"}),s.slice(0,3).map(h=>e.jsx("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:h.text},h.hash)),s.length>3&&e.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",s.length-3," more"]})]}),n.length>0&&e.jsxs("div",{className:"mt-2 space-y-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Discoveries"}),n.slice(0,3).map((h,g)=>e.jsxs("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:[e.jsx("span",{className:"text-text-4",children:h.trigger})," → ",h.fix]},g)),n.length>3&&e.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",n.length-3," more"]})]}),Object.keys(r).length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Role quality"}),e.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-0.5",children:Object.entries(r).map(([h,g])=>e.jsxs("span",{className:"text-xs font-mono text-text-3",children:[e.jsx("span",{className:"text-text-2 capitalize",children:h})," Q:",g.avgQualityScore," ",e.jsxs("span",{className:"text-text-4",children:["(",g.sessionCount,"s)"]})]},h))})]})]})]})}function Pte({tokens:t}){var r,l;if(!((r=t==null?void 0:t.internalOverhead)!=null&&r.tokens)||!((l=t==null?void 0:t.savings)!=null&&l.total))return null;const s=t.internalOverhead,n=t.savings,a=t.totalTokens>0?Math.round(s.tokens/t.totalTokens*100):0;return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-3 text-xs font-mono",children:[e.jsx("span",{className:"text-text-4",children:"Overhead"}),e.jsxs("span",{className:"text-text-3 tabular-nums",children:[jt(s.tokens)," (",a,"%)"]}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-text-4",children:"Saved"}),e.jsx("span",{className:"text-text-3 tabular-nums",children:jt(n.total)})]})]})}const Fte=p.memo(function({tokens:s,rotation:n,adaptive:a,journalist:r,agentBreakdown:l,memory:c}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-shrink-0 px-3 pt-2.5 pb-1.5",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Intel"})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[e.jsx(Cte,{tokens:s,rotation:n,agentBreakdown:l}),e.jsx(Bte,{agentBreakdown:l,rotation:n}),e.jsx(kte,{rotation:n}),e.jsx(Tte,{adaptive:a}),e.jsx(Ute,{journalist:r}),e.jsx(Ete,{memory:c}),e.jsx(Pte,{tokens:s}),e.jsx("div",{className:"h-3"})]})]})}),$te=p.memo(function({teams:s=[]}){const n=s.reduce((r,l)=>r+(l.totalTokens||0),0),a=s.reduce((r,l)=>Math.max(r,l.totalTokens||0),0);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Team Burn"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:[jt(n)," total"]})]}),e.jsx(Qt,{className:"flex-1 min-h-0",children:s.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-text-3 font-mono",children:"No team activity yet"}):e.jsx("div",{className:"px-3 py-3 space-y-3",children:s.map(r=>{const l=a>0?r.totalTokens/a*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:r.teamName}),r.isDefault&&e.jsx("span",{className:"text-[9px] font-mono text-text-3 uppercase tracking-wider",children:"default"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 flex-shrink-0",children:[r.agentCount," ",r.agentCount===1?"agent":"agents"]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 font-mono text-2xs",children:[e.jsx("span",{className:"text-text-1",children:jt(r.totalTokens)}),e.jsx("span",{className:"text-text-3",children:er(r.totalCostUsd)})]})]}),e.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all",style:{width:`${l}%`,background:ce.text3}})})]},r.teamId)})})})]})}),Rte={spawn:HS,complete:Ga,crash:Aa,kill:AO,rotate:hd,error:Db},Mte={spawn:"text-text-2",complete:"text-text-2",crash:"text-danger",kill:"text-text-3",rotate:"text-text-2",error:"text-danger"};function Ite(t){const s=t.agentName||t.role||"";switch(t.type){case"spawn":return`${s} spawned`;case"complete":return`${s} completed`;case"crash":return`${s} crashed`;case"kill":return`${s} killed`;case"rotate":return`${s} rotated`;default:return t.text||t.type||"event"}}const zte=p.memo(function({events:s=[]}){return s.length?e.jsx("div",{className:"flex items-center gap-3 overflow-x-auto py-2 px-3",children:s.slice(-15).reverse().map((n,a)=>{const r=Rte[n.type]||qt,l=Mte[n.type]||"text-text-3",c=Ite(n);return e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(r,{size:11,className:l}),e.jsx("span",{className:"text-xs font-sans text-text-2 whitespace-nowrap",children:c}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:$t(n.t||n.timestamp)})]},a)})}):e.jsx("div",{className:"text-xs text-text-3 font-mono py-2.5 text-center",children:"No recent activity"})});function ia({className:t,...s}){return e.jsx("div",{className:Z("rounded-md bg-surface-4","bg-gradient-to-r from-surface-4 via-surface-5 to-surface-4","bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]",t),...s})}function _te(){return e.jsxs("div",{className:"flex-1 grid gap-px p-0 bg-surface-3",style:{gridTemplateRows:"auto minmax(0, 1fr) minmax(0, 1fr)",gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[e.jsx("div",{className:"col-span-3",children:e.jsx(ia,{className:"h-[72px] rounded-none"})}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx("div",{className:"col-span-2",children:e.jsx(ia,{className:"h-full rounded-none"})})]})}function Dte(){const{data:t,loading:s,agents:n,connected:a,kpiHistory:r,lastFetch:l,agentBreakdown:c,routing:A,rotation:f,adaptive:x,journalist:h,rotating:g,teamBurn:O,memory:b}=lte(),v=k(R=>R.teams),y=n.filter(R=>R.status==="running").length;if(!a)return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2 text-text-3 font-mono",children:[e.jsx(Lx,{size:28,className:"mx-auto"}),e.jsx("p",{className:"text-xs",children:"Connecting to daemon..."})]})});if(s||!t)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(CQ,{connected:a,runningCount:0,totalCount:0,uptime:0,lastFetch:0}),e.jsx(_te,{})]});const S=t.tokens||{},j={totalTokens:S.totalTokens||0,totalCostUsd:S.totalCostUsd||0,totalInputTokens:S.totalInputTokens||0,totalOutputTokens:S.totalOutputTokens||0,cacheReadTokens:S.cacheReadTokens||0,cacheCreationTokens:S.cacheCreationTokens||0,cacheHitRate:S.cacheHitRate||0,totalTurns:S.totalTurns||0,agentCount:S.agentCount||0,savings:S.savings||{},internalOverhead:S.internalOverhead||{tokens:0,costUsd:0,components:{}}},N=j.totalOutputTokens>0?(j.totalInputTokens/j.totalOutputTokens).toFixed(1):"—",C=(f==null?void 0:f.totalRotations)||0,U=(c||[]).filter(R=>{var Y;return((Y=R.quality)==null?void 0:Y.score)!=null}),P=U.length>0?Math.round(U.reduce((R,Y)=>R+Y.quality.score,0)/U.length):null,T=t.timeline||{},B=T.snapshots||[],F=T.events||t.events||[],M=[{label:"Tokens Used",value:jt(j.totalTokens),sparkData:r.tokens,color:ce.text3,hint:"Total tokens consumed across all agents — input, output, and cache tokens combined."},{label:"Total Cost",value:er(j.totalCostUsd),sparkData:r.cost,color:ce.text3,hint:"Actual cost reported by providers. Claude Code reports real billing; other providers use estimated rates."},{label:"Quality",value:P!=null?`${P}`:"—",sparkData:r.saved,color:ce.text3,hint:"Average session quality score (0-100) across running agents. Based on error rate, repetitions, file churn, and tool success. Below 40 triggers auto-rotation."},{label:"Cache Rate",value:pc(j.cacheHitRate*100),sparkData:r.cache,color:ce.text3,hint:"Percentage of input tokens served from prompt cache. Higher = faster responses and lower cost. Managed by your AI provider."},{label:"Rotations",value:`${C}`,sparkData:r.efficiency,color:ce.text3,hint:"Total context rotations — includes quality-based (auto), context threshold, natural compaction (provider-managed), and manual rotations."},{label:"I/O Ratio",value:`${N}:1`,sparkData:r.inputOutput,color:ce.text3,hint:"Ratio of input to output tokens. High ratios mean agents are reading more than writing — common for analysis tasks."},{label:"Agents",value:`${y}/${n.length}`,sparkData:r.agents,color:ce.text3,hint:"Running agents out of total spawned this session (including completed and crashed)."},{label:"Turns",value:jt(j.totalTurns),sparkData:r.turns,color:ce.text3,hint:"Total conversation turns across all agents. Each turn is one request-response cycle with the AI provider."}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(CQ,{connected:a,runningCount:y,totalCount:n.length,uptime:t.uptime||0,lastFetch:l,activeTeam:t.activeTeam}),e.jsx(dte,{kpis:M}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col bg-surface-3 gap-px",children:[e.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"3fr 1.5fr 1.5fr"},children:[e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 relative",children:e.jsx(vte,{data:B})}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Cache Performance"})}),e.jsx(yte,{cacheRead:j.cacheReadTokens,cacheCreation:j.cacheCreationTokens,totalInput:j.totalInputTokens})]}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Model Routing"})}),e.jsx(Qte,{routing:A,agentBreakdown:c})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Agent Fleet"})}),e.jsx(bte,{agentBreakdown:c}),e.jsx(hte,{agentBreakdown:c,rotating:g,teams:v})]}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx(Fte,{tokens:j,rotation:f,adaptive:x,journalist:h,agentBreakdown:c,memory:b})}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx($te,{teams:O})})]})]}),e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-t border-border",children:e.jsx(zte,{events:F})})]})}const TQ={sm:12,md:16,lg:20};function Lte({fill:t="full",size:s,color:n="#fbbf24",emptyColor:a="rgba(255,255,255,0.4)"}){const r=`star-${Math.random().toString(36).slice(2,8)}`;return e.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",children:[t==="half"&&e.jsx("defs",{children:e.jsxs("linearGradient",{id:r,children:[e.jsx("stop",{offset:"50%",stopColor:n}),e.jsx("stop",{offset:"50%",stopColor:a})]})}),e.jsx("path",{d:"M10 1.5l2.47 5.01 5.53.8-4 3.9.94 5.49L10 14.27 5.06 16.7 6 11.21l-4-3.9 5.53-.8L10 1.5z",fill:t==="full"?n:t==="half"?`url(#${r})`:a})]})}function Hte({rating:t=0,count:s,size:n="sm"}){const a=TQ[n]||TQ.sm,r=[];for(let l=1;l<=5;l++)t>=l?r.push("full"):t>=l-.5?r.push("half"):r.push("empty");return e.jsxs("span",{className:"inline-flex items-center",style:{gap:1},children:[r.map((l,c)=>e.jsx(Lte,{fill:l,size:a},c)),s!=null&&e.jsxs("span",{className:"ml-1 text-[11px] text-[var(--text-dim,#6b7f95)] font-sans",children:["(",s,")"]})]})}const UQ={design:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},quality:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},devtools:{color:"#33afbc",bg:"rgba(51,175,188,0.14)"},workflow:{color:"#fbbf24",bg:"rgba(251,191,36,0.12)"},security:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},specialized:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},verified:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},anthropic:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},published:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},draft:{color:"#6b7f95",bg:"rgba(255,255,255,0.06)"},review:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},rejected:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},free:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"}};function Xte({label:t,variant:s,className:n}){const a=UQ[s]||UQ.draft;return e.jsx("span",{className:Z("inline-flex items-center whitespace-nowrap font-sans select-none",n),style:{padding:"3px 8px",borderRadius:4,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",lineHeight:1.4,color:a.color,background:a.bg},children:t})}function Gte({price:t=0,size:s="sm"}){const n=!t||t===0,a={sm:"text-2xs px-2 py-0.5",md:"text-xs px-2.5 py-0.5",lg:"text-xs px-3 py-1"};return e.jsx("span",{className:`inline-flex items-center font-mono font-semibold rounded whitespace-nowrap ${a[s]||a.sm} ${n?"bg-success/12 text-success":"bg-white/8 text-text-1"}`,children:n?"Free":`$${t.toFixed(2)}`})}function Zte({type:t="verified",size:s=12}){const n=t==="claude-official"||t==="anthropic"?"#f59e0b":"#4ade80";return e.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",className:"inline-block flex-shrink-0",children:[e.jsx("path",{d:"M10 0l2.36 3.15L16.18 2l.68 3.93L20.8 7.1l-1.87 3.52L20.8 14.14l-3.94 1.17-.68 3.93-3.82-1.15L10 21.24l-2.36-3.15-3.82 1.15-.68-3.93-3.94-1.17 1.87-3.52L-.8 7.1l3.94-1.17.68-3.93 3.82 1.15L10 0z",fill:n}),e.jsx("path",{d:"M7 10.5l2 2 4-4.5",fill:"none",stroke:"#24282f",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Vte(){return e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md animate-pulse",style:{padding:20,minHeight:280},children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-surface-4"}),e.jsx("div",{className:"mt-3 h-4 w-[70%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-2 h-3 w-[40%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-3 w-full rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[90%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[60%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-5 w-[50px] rounded bg-surface-4"}),e.jsx("div",{className:"h-px bg-surface-4 my-3"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("div",{className:"h-3 w-16 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-12 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-10 rounded bg-surface-4"})]})]})}const Ni={"google-workspace":"https://cdn.simpleicons.org/google/white",slack:"https://cdn.simpleicons.org/slack/E01E5A",discord:"https://cdn.simpleicons.org/discord/5865F2",github:"https://cdn.simpleicons.org/github/white",stripe:"https://cdn.simpleicons.org/stripe/635BFF",gmail:"https://cdn.simpleicons.org/gmail/EA4335","google-calendar":"https://cdn.simpleicons.org/googlecalendar/4285F4","google-drive":"https://cdn.simpleicons.org/googledrive/4285F4","google-docs":"https://cdn.simpleicons.org/googledocs/4285F4","google-sheets":"https://cdn.simpleicons.org/googlesheets/34A853","google-slides":"https://cdn.simpleicons.org/googleslides/FBBC04","google-maps":"https://cdn.simpleicons.org/googlemaps/4285F4",postgres:"https://cdn.simpleicons.org/postgresql/4169E1",notion:"https://cdn.simpleicons.org/notion/white",linear:"https://cdn.simpleicons.org/linear/5E6AD2","brave-search":"https://cdn.simpleicons.org/brave/FB542B","home-assistant":"https://cdn.simpleicons.org/homeassistant/18BCF2",sentry:"https://cdn.simpleicons.org/sentry/362D59",elevenlabs:"https://cdn.simpleicons.org/elevenlabs/white",hubspot:"https://cdn.simpleicons.org/hubspot/FF7A59",jira:"https://cdn.simpleicons.org/jira/0052CC",sendgrid:"https://cdn.simpleicons.org/sendgrid/1A82E2",resend:"https://cdn.simpleicons.org/resend/white",replicate:"https://cdn.simpleicons.org/replicate/white",vercel:"https://cdn.simpleicons.org/vercel/white",supabase:"https://cdn.simpleicons.org/supabase/3FCF8E",mixpanel:"https://cdn.simpleicons.org/mixpanel/7856FF",datadog:"https://cdn.simpleicons.org/datadog/632CA6",airtable:"https://cdn.simpleicons.org/airtable/18BFFF",zendesk:"https://cdn.simpleicons.org/zendesk/03363D",intercom:"https://cdn.simpleicons.org/intercom/6AFDEF",twilio:"https://cdn.simpleicons.org/twilio/F22F46",telnyx:"https://cdn.simpleicons.org/telnyx/00C08B",aws:"https://cdn.simpleicons.org/amazonaws/FF9900",plaid:"https://cdn.simpleicons.org/plaid/white"};function Kte({item:t,size:s=40}){const n=Ni[t.id];if(n)return e.jsxs("div",{className:"rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:[e.jsx("img",{src:n,alt:t.name,className:"w-5 h-5",onError:l=>{l.target.style.display="none",l.target.nextSibling.style.display="flex"}}),e.jsx("div",{className:"hidden items-center justify-center w-full h-full text-lg font-bold font-sans text-text-1",children:(t.name||"?")[0]})]});const a=(t.name||"?")[0].toUpperCase(),r=t.name?t.name.charCodeAt(0)*37%360:200;return e.jsx("div",{className:"rounded-md flex items-center justify-center flex-shrink-0 text-lg font-bold font-sans",style:{width:s,height:s,background:`hsl(${r}, 40%, 18%)`,color:`hsl(${r}, 60%, 65%)`},children:a})}function Ux({item:t,onClick:s,className:n,statusBadge:a}){var l;const r=t.installed;return e.jsxs("button",{onClick:()=>s(t),className:Z("flex flex-col p-5 rounded-md border border-border-subtle bg-surface-1 text-left","hover:border-accent/30 hover:bg-surface-2","transition-all duration-150 cursor-pointer group",n),style:{minHeight:200},children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(Kte,{item:t,size:36}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-0 font-sans truncate",children:t.name}),(t.verified||t.verified==="mcp-official")&&e.jsx(Ga,{size:11,className:"text-accent flex-shrink-0"})]}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.author||"Community"})]})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans line-clamp-3 mb-3 flex-1 leading-relaxed",children:t.description}),e.jsx("div",{className:"h-px bg-border-subtle my-2"}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(qs,{size:10}),jt(t.downloads||0)]}),(t.rating||0)>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lb,{size:10,className:"text-warning",fill:"currentColor"}),(l=t.rating)==null?void 0:l.toFixed(1)]}),e.jsx("span",{className:"flex-1"}),a||r&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:t._installedCount?`${t._installedCount} active`:"Installed"})]})]})}function I4({value:t,onChange:s,placeholder:n="Search skills, tags, authors...",large:a}){const[r,l]=p.useState(t||""),c=p.useRef(null);p.useEffect(()=>{l(t||"")},[t]);function A(f){const x=f.target.value;l(x),clearTimeout(c.current),c.current=setTimeout(()=>s(x),300)}return e.jsxs("div",{className:"relative w-full",children:[e.jsx(As,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{value:r,onChange:A,placeholder:n,className:Z("w-full font-sans outline-none","bg-surface-0 border border-border text-text-0 placeholder:text-text-4","focus:border-accent/40 transition-colors",a?"py-3 pl-11 pr-12 text-[15px] rounded-lg":"py-2.5 pl-10 pr-3 text-sm rounded-md")}),a&&e.jsx("kbd",{className:"absolute right-3.5 top-1/2 -translate-y-1/2 bg-surface-4 text-text-4 px-2 py-0.5 rounded text-xs font-mono",children:"/"})]})}function Hn(){const t=k(s=>s.addToast);return{success:(s,n)=>t("success",s,n),error:(s,n)=>t("error",s,n),info:(s,n)=>t("info",s,n),warning:(s,n)=>t("warning",s,n)}}const rs=p.forwardRef(({className:t,label:s,error:n,mono:a,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[s&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),e.jsx("input",{ref:l,className:Z("h-8 w-full rounded-md px-3 text-sm","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",a?"font-mono":"font-sans",n&&"border-danger focus:ring-danger",t),...r}),n&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));rs.displayName="Input";const Rv=p.forwardRef(({className:t,label:s,error:n,mono:a,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[s&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),e.jsx("textarea",{ref:l,className:Z("w-full rounded-md px-3 py-2 text-sm resize-none","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",a?"font-mono":"font-sans",n&&"border-danger focus:ring-danger",t),...r}),n&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));Rv.displayName="Textarea";const EQ=["bg-accent/15 text-accent","bg-purple/15 text-purple","bg-success/15 text-success","bg-warning/15 text-warning","bg-danger/15 text-danger","bg-info/15 text-info"];function Jl({item:t,size:s=48}){const n=Ni[t.id];if(n)return e.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:e.jsx("img",{src:n,alt:t.name,className:"w-6 h-6",onError:l=>{l.target.classList.add("hidden")}})});const a=(t.name||"?")[0].toUpperCase(),r=EQ[(t.name||"").charCodeAt(0)%EQ.length];return e.jsx("div",{className:`rounded-lg flex items-center justify-center flex-shrink-0 text-xl font-bold font-sans ${r}`,style:{width:s,height:s},children:a})}function ob({value:t,onChange:s,placeholder:n,disabled:a}){const[r,l]=p.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsx(rs,{type:r?"text":"password",value:t,onChange:c=>s(c.target.value),placeholder:n,disabled:a,mono:!0,className:"pr-9"}),e.jsx("button",{type:"button",onClick:()=>l(c=>!c),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded text-text-4 hover:text-text-1 transition-colors cursor-pointer",tabIndex:-1,children:r?e.jsx(To,{size:14}):e.jsx(Vs,{size:14})})]})}function qte({integrationId:t,envKey:s,onSaved:n}){const a=Hn(),[r,l]=p.useState(""),[c,A]=p.useState(!1),[f,x]=p.useState(s.set),[h,g]=p.useState(!1);async function O(){if(r.trim()){A(!0);try{await G.post(`/integrations/${t}/credentials`,{key:s.key,value:r.trim()}),x(!0),l(""),a.success(`${s.label} saved`),n==null||n()}catch(v){a.error("Failed to save",v.message)}A(!1)}}async function b(){g(!0);try{await G.delete(`/integrations/${t}/credentials/${s.key}`),x(!1),a.success(`${s.label} removed`),n==null||n()}catch(v){a.error("Failed to remove",v.message)}g(!1)}return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),f&&e.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[e.jsx(Je,{size:10})," Set"]})]}),f?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:e.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),e.jsx(pe,{variant:"ghost",size:"sm",onClick:b,disabled:h,className:"text-text-3 hover:text-danger",children:h?e.jsx(De,{size:12,className:"animate-spin"}):e.jsx(Ft,{size:12})})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx(ob,{value:r,onChange:l,placeholder:s.placeholder||`Enter ${s.label.toLowerCase()}...`,disabled:c})}),e.jsx(pe,{variant:"primary",size:"sm",onClick:O,disabled:c||!r.trim(),children:c?e.jsx(De,{size:12,className:"animate-spin"}):"Save"})]})]})}function Wte({item:t,status:s,installing:n,onInstall:a,onUninstall:r,onNext:l}){var A;const c=s==null?void 0:s.installed;return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Jl,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:t.name}),(t.verified==="mcp-official"||t.verified==="verified")&&e.jsxs(Te,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(vn,{size:9})," Verified"]})]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:t.author||"Community"}),t.category&&e.jsx(Te,{variant:"default",className:"text-2xs mt-2",children:t.category})]})]}),e.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((A=t.tags)==null?void 0:A.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map(f=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:f},f))}),e.jsx("div",{className:"h-px bg-border-subtle"}),c?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsx(Ga,{size:16,className:"text-success"}),e.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:r,className:"text-text-3 hover:text-danger gap-1.5",children:[e.jsx(Ft,{size:12})," Uninstall"]}),e.jsxs(pe,{variant:"primary",size:"sm",onClick:l,className:"gap-1",children:["Configure ",e.jsx(Tt,{size:12})]})]}):e.jsx(pe,{variant:"primary",size:"lg",onClick:a,disabled:n,className:"w-full gap-2",children:n?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),n&&e.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}function Yte({item:t,onClose:s}){const n=k(j=>j.agents),a=k(j=>j.teams),r=k(j=>j.installViaExistingAgent),l=k(j=>j.spawnIntegrationTeam),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(null),O=n.filter(j=>j.status==="running"||j.status==="idle"),b={};for(const j of O){const N=j.teamId||"_none";b[N]||(b[N]=[]),b[N].push(j)}const v={};for(const j of a)v[j.id]=j.name;async function y(){h&&(await r(t,h),s())}async function S(){x(!0);try{await l(t),s()}catch{x(!1)}}return c?c==="spawn"?e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Spawn Integration Agent"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Creates a team and planner for ",t.name]})]})]}),e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"What happens next"}),e.jsx("ol",{className:"space-y-1.5",children:[`A new team "${t.name}" will be created`,"A planner agent will spawn with full integration context","The agent will handle installation and configuration"].map((j,N)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono flex-shrink-0 w-4 text-right",children:[N+1,"."]}),e.jsx("span",{children:j})]},N))})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{variant:"secondary",size:"lg",onClick:()=>A(null),className:"flex-1",disabled:f,children:"Back"}),e.jsx(pe,{variant:"primary",size:"lg",onClick:S,disabled:f,className:"flex-1 gap-2",children:f?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Spawning..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ei,{size:14})," Spawn Agent"]})})]})]}):e.jsxs("div",{className:"px-5 py-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Choose an Agent"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Send ",t.name," setup instructions to a running agent"]})]})]}),e.jsx(Qt,{className:"max-h-64",children:e.jsx("div",{className:"space-y-3",children:Object.entries(b).map(([j,N])=>e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5 px-1",children:v[j]||"Unassigned"}),e.jsx("div",{className:"space-y-1",children:N.map(C=>e.jsxs("button",{onClick:()=>g(C.id),className:`w-full text-left px-3 py-2.5 rounded-md border transition-all cursor-pointer flex items-center gap-3 ${h===C.id?"border-accent bg-accent/8":"border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-border"}`,children:[e.jsx(qa,{size:14,className:h===C.id?"text-accent":"text-text-4"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:C.name||C.id}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:C.role})]}),h===C.id&&e.jsx(Je,{size:14,className:"text-accent flex-shrink-0"})]},C.id))})]},j))})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{variant:"secondary",size:"lg",onClick:()=>{A(null),g(null)},className:"flex-1",children:"Back"}),e.jsxs(pe,{variant:"primary",size:"lg",onClick:y,disabled:!h,className:"flex-1 gap-2",children:[e.jsx(qa,{size:14})," Send Instructions"]})]})]}):e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Jl,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("h2",{className:"text-base font-bold text-text-0 font-sans",children:["Install ",t.name]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose how to set up this integration"})]})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("button",{onClick:()=>O.length>0?A("existing"):null,disabled:O.length===0,className:"w-full text-left px-4 py-3.5 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-accent/30 transition-all cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed group",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/15 transition-colors",children:e.jsx(yn,{size:18,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Use Existing Agent"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:O.length>0?`Send setup instructions to one of ${O.length} running agent${O.length!==1?"s":""}`:"No agents running — spawn one first"})]}),O.length>0&&e.jsx(Tt,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})}),e.jsx("button",{onClick:()=>A("spawn"),className:"w-full text-left px-4 py-3.5 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-accent/30 transition-all cursor-pointer group",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-purple/10 flex items-center justify-center flex-shrink-0 group-hover:bg-purple/15 transition-colors",children:e.jsx(Ei,{size:18,className:"text-purple"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn New Agent"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:"Create a dedicated team and planner for this integration"})]}),e.jsx(Tt,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})})]})]})}const Jte={gmail:"Gmail API","google-calendar":"Google Calendar API","google-drive":"Google Drive API","google-docs":"Google Docs API","google-sheets":"Google Sheets API","google-slides":"Google Slides API"};function z4({integrationId:t,onConfigured:s}){const n=Hn(),[a,r]=p.useState(""),[l,c]=p.useState(""),[A,f]=p.useState(!1),x=Jte[t]||"the relevant Google API";async function h(){if(!(!a.trim()||!l.trim())){f(!0);try{await G.post("/integrations/google-oauth/setup",{clientId:a.trim(),clientSecret:l.trim()}),n.success("Google OAuth credentials saved"),s()}catch(O){n.error("Failed to save",O.message)}f(!1)}}const g=[{text:"Go to the Google Cloud Console and sign in with your Google account",link:{url:"https://console.cloud.google.com",label:"Open Google Cloud Console"}},{text:"Create a new project (or select an existing one). Any name is fine — this is just a container for your credentials."},{text:e.jsxs(e.Fragment,{children:["Enable the ",e.jsx("strong",{children:x})," — search for it in the API Library and click ",e.jsx("strong",{children:"Enable"})]}),link:{url:"https://console.cloud.google.com/apis/library",label:"Open API Library"}},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Credentials"})," and click ",e.jsx("strong",{children:"Create Credentials"})," → ",e.jsx("strong",{children:"OAuth client ID"})]}),link:{url:"https://console.cloud.google.com/apis/credentials",label:"Open Credentials page"}},{text:e.jsxs(e.Fragment,{children:["If prompted to configure the consent screen, choose ",e.jsx("strong",{children:"External"}),', fill in an app name (e.g. "Groove"), your email, and save. You can skip optional fields.']})},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Audience"})," and click ",e.jsx("strong",{children:"Publish App"}),". Then scroll down to ",e.jsx("strong",{children:"Test users"}),", click ",e.jsx("strong",{children:"Add Users"}),", enter your Google email address, and save."]})},{text:e.jsxs(e.Fragment,{children:["For Application type, choose ",e.jsx("strong",{children:"Desktop app"})," (not Web application). Give it any name."]})},{text:e.jsxs(e.Fragment,{children:["Click ",e.jsx("strong",{children:"Create"}),", then copy the ",e.jsx("strong",{children:"Client ID"})," and ",e.jsx("strong",{children:"Client Secret"})," and paste them below."]})}];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-3",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"How to get your Google credentials"}),e.jsx("ol",{className:"space-y-2.5",children:g.map((O,b)=>e.jsxs("li",{className:"flex gap-2.5 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono font-bold flex-shrink-0 w-4 text-right",children:[b+1,"."]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{children:O.text}),O.link&&e.jsxs("a",{href:O.link.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-2xs text-accent font-sans hover:underline mt-0.5",children:[e.jsx(Ws,{size:9}),O.link.label]}),O.copyable&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("code",{className:"flex-1 min-w-0 text-2xs font-mono text-accent bg-surface-4 px-2.5 py-1.5 rounded select-all break-all",children:O.copyable}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(O.copyable)},className:"flex-shrink-0 p-1.5 rounded text-text-3 hover:text-accent hover:bg-accent/10 transition-colors cursor-pointer",title:"Copy to clipboard",children:e.jsx(Ba,{size:12})})]})]})]},b))})]}),e.jsx("div",{className:"bg-accent/8 border border-accent/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsx("strong",{className:"text-text-1",children:"One-time setup"})," — these same credentials work for Gmail, Calendar, Drive, Docs, Sheets, and Slides. You only need to do this once. For each integration, just enable the matching API in your Google Cloud project."]})}),e.jsx("div",{className:"bg-warning/8 border border-warning/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsx("strong",{className:"text-text-1",children:'Google "unverified app" warning'})," — when signing in, Google may show a warning that the app isn't verified. This is normal for personal OAuth apps. Click ",e.jsx("strong",{children:"Advanced"}),", then ",e.jsx("strong",{children:"Go to [your app name] (unsafe)"})," to continue. Your credentials stay local and are never sent to Groove servers."]})}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),"Client ID ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(ob,{value:a,onChange:r,placeholder:"123456789.apps.googleusercontent.com",disabled:A})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),"Client Secret ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(ob,{value:l,onChange:c,placeholder:"GOCSPX-...",disabled:A})]})]}),e.jsx(pe,{variant:"primary",size:"lg",onClick:h,disabled:A||!a.trim()||!l.trim(),className:"w-full gap-2",children:A?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Saving..."]}):"Save Credentials"})]})}function ese({item:t,status:s,onDone:n,onRefreshStatus:a}){var S;const r=Hn(),[l,c]=p.useState(!1),[A,f]=p.useState(null),x=t.authType,h=x==="google-autoauth"||x==="oauth-google";p.useEffect(()=>{h&&G.get("/integrations/google-oauth/status").then(j=>f(j.configured)).catch(()=>f(!1))},[h]);const g=p.useRef(null);p.useEffect(()=>()=>{g.current&&clearInterval(g.current)},[]);async function O(){c(!0);try{const j=await G.post(`/integrations/${t.id}/oauth/start`);if(j.url){const N=await ON(j.url);if(N!=null&&N.error){r.error("Sign-in failed",N.error),c(!1);return}r.success("Browser opened — complete sign-in there");let C=0;g.current&&clearInterval(g.current),g.current=setInterval(async()=>{if(C+=2e3,C>6e4){clearInterval(g.current),g.current=null,c(!1);return}try{const U=await G.get(`/integrations/${t.id}/status`);((U==null?void 0:U.envKeys)||[]).some(B=>B.key==="GOOGLE_REFRESH_TOKEN"&&B.set)&&(clearInterval(g.current),g.current=null,r.success("Connected!",`${t.name} is now authenticated`),a(),c(!1))}catch{}},2e3)}}catch(j){r.error("Sign-in failed",j.message),c(!1)}}const b=(s==null?void 0:s.envKeys)||[],v=b.filter(j=>j.required&&!j.hidden),y=v.length===0||v.every(j=>j.set);return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",t.name]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((S=t.setupSteps)==null?void 0:S.length)>0&&!(h&&A===!1)&&e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),e.jsx("ol",{className:"space-y-1.5",children:t.setupSteps.map((j,N)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[N+1,"."]}),e.jsx("span",{children:j})]},N))}),t.setupUrl&&e.jsxs("a",{href:t.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[e.jsx(Ws,{size:11}),new URL(t.setupUrl).hostname]})]}),!(h&&A===!1)&&e.jsx("div",{className:"h-px bg-border-subtle"}),x==="api-key"&&e.jsx("div",{className:"space-y-4",children:b.filter(j=>!j.hidden).map(j=>e.jsx(qte,{integrationId:t.id,envKey:j,onSaved:a},j.key))}),h&&A===!1&&e.jsx(z4,{integrationId:t.id,onConfigured:()=>f(!0)}),h&&A&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(pe,{variant:"primary",size:"lg",onClick:O,disabled:l,className:"w-full gap-2",children:l?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"}),"Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["A browser window will open — sign in and allow access to your ",t.name]}),e.jsx("button",{type:"button",onClick:()=>f(!1),className:"w-full text-2xs text-text-4 font-sans hover:text-text-2 transition-colors cursor-pointer py-1",children:"Reconfigure Google OAuth credentials"})]}),h&&A===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(De,{size:16,className:"animate-spin text-text-4"})}),e.jsx(pe,{variant:y?"primary":"secondary",size:"lg",onClick:n,className:"w-full gap-1.5",children:y?e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:14}),"Done"]}):"Skip for now"})]})}function tse({item:t,onClose:s}){return e.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Ga,{size:28,className:"text-success"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),e.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[t.name," is installed and configured. Agents can now use it."]})]}),e.jsx(pe,{variant:"primary",size:"lg",onClick:s,className:"mt-2",children:"Close"})]})}function _4({integration:t,open:s,onClose:n}){const a=Hn(),[r,l]=p.useState("overview"),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(!0),O=t==null?void 0:t.id,b=p.useCallback(async()=>{if(O){try{const C=await G.get(`/integrations/${O}/status`);A(C)}catch{A(null)}g(!1)}},[O]);p.useEffect(()=>{s&&t&&(l("overview"),g(!0),b())},[s,t,b]);function v(){l("agent-setup")}async function y(){try{await G.delete(`/integrations/${t.id}`),a.success(`${t.name} uninstalled`),await b()}catch(C){a.error("Uninstall failed",C.message)}}function S(){l("configure")}function j(){l("done")}if(!t)return null;const N={overview:t.name,"agent-setup":"Install",configure:"Configure",done:"Complete"};return e.jsx(Vt,{open:s,onOpenChange:C=>{C||n()},children:e.jsx(Kt,{title:N[r]||t.name,description:`Setup wizard for ${t.name}`,className:"max-w-md",children:h?e.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:e.jsx(De,{size:20,className:"animate-spin text-text-4"})}):r==="overview"?e.jsx(Wte,{item:t,status:c,installing:f,onInstall:v,onUninstall:y,onNext:S}):r==="agent-setup"?e.jsx(Yte,{item:t,onClose:n}):r==="configure"?e.jsx(ese,{item:t,status:c,onDone:j,onRefreshStatus:b}):e.jsx(tse,{item:t,onClose:n})})})}const sse=["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"];function nse({item:t,status:s,onInstall:n,onUninstall:a,busy:r}){const l=s==null?void 0:s.installed,c=s==null?void 0:s.authenticated;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-2 border border-border-subtle",children:[e.jsx(Jl,{item:t,size:32}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:t.description})]}),l&&c&&!(s!=null&&s.needsReauth)&&e.jsxs(Te,{variant:"success",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Je,{size:8})," Ready"]}),l&&c&&(s==null?void 0:s.needsReauth)&&e.jsxs(Te,{variant:"warning",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Ls,{size:8})," Update"]}),l&&!c&&e.jsx(Te,{variant:"warning",className:"text-2xs flex-shrink-0",children:"Needs sign-in"}),e.jsx(pe,{variant:l?"ghost":"primary",size:"sm",onClick:()=>l?a(t.id):n(t.id),disabled:r===t.id,className:l?"text-text-3 hover:text-danger":"",children:r===t.id?e.jsx(De,{size:12,className:"animate-spin"}):l?e.jsx(Ft,{size:12}):"Install"})]})}function ase({integrations:t,open:s,onClose:n}){const a=Hn(),[r,l]=p.useState(null),[c,A]=p.useState({}),[f,x]=p.useState(null),[h,g]=p.useState(!1),[O,b]=p.useState(!0),v=p.useRef(null),y=t.filter(B=>sse.includes(B.id)),S=p.useCallback(async()=>{const B={};await Promise.all(y.map(async F=>{try{B[F.id]=await G.get(`/integrations/${F.id}/status`)}catch{B[F.id]=null}})),A(B),b(!1)},[y.map(B=>B.id).join(",")]);p.useEffect(()=>(s&&(b(!0),G.get("/integrations/google-oauth/status").then(B=>l(B.configured)).catch(()=>l(!1)),S()),()=>{v.current&&clearInterval(v.current)}),[s]);const j=Object.entries(c).filter(([,B])=>B==null?void 0:B.installed).map(([B])=>B),N=j.length>0&&j.every(B=>{var F;return(F=c[B])==null?void 0:F.authenticated});j.some(B=>{var F;return!((F=c[B])!=null&&F.authenticated)});const C=N&&j.some(B=>{var F;return(F=c[B])==null?void 0:F.needsReauth});async function U(B){var F;x(B);try{await G.post(`/integrations/${B}/install`),a.success(`${(F=y.find(M=>M.id===B))==null?void 0:F.name} installed`),await S()}catch(M){a.error("Install failed",M.message)}x(null)}async function P(B){var F;x(B);try{await G.delete(`/integrations/${B}`),a.success(`${(F=y.find(M=>M.id===B))==null?void 0:F.name} removed`),await S()}catch(M){a.error("Uninstall failed",M.message)}x(null)}async function T(){if(!j.length){a.error("Install at least one service first");return}g(!0);try{const B=await G.post("/integrations/google-workspace/oauth/start",{integrationIds:j});if(B.url){const F=await ON(B.url);if(F!=null&&F.error){a.error("Sign-in failed",F.error),g(!1);return}a.success("Browser opened — complete sign-in there"),v.current&&clearInterval(v.current),v.current=setInterval(async()=>{await S()},3e3),setTimeout(()=>{v.current&&clearInterval(v.current)},18e4)}}catch(B){a.error("Sign-in failed",B.message)}g(!1)}return p.useEffect(()=>{N&&v.current&&(clearInterval(v.current),v.current=null)},[N]),s?e.jsx(Vt,{open:s,onOpenChange:B=>{B||n()},children:e.jsx(Kt,{title:"Google Workspace",description:"Connect your Google services",className:"max-w-md",children:e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"Google",className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Google Workspace"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"One set of credentials for all Google services"})]})]}),r===!1&&e.jsx(z4,{integrationId:"gmail",onConfigured:()=>l(!0)}),r===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(De,{size:16,className:"animate-spin text-text-4"})}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans",children:"Services"}),e.jsx("div",{className:"space-y-1.5",children:O?Array.from({length:4}).map((B,F)=>e.jsx("div",{className:"h-14 rounded-md bg-surface-2 animate-pulse"},F)):y.map(B=>e.jsx(nse,{item:B,status:c[B.id],onInstall:U,onUninstall:P,busy:f},B.id))})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),j.length>0&&!N&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(pe,{variant:"primary",size:"lg",onClick:T,disabled:h,className:"w-full gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Connects ",j.length," service",j.length!==1?"s":""," with one sign-in"]})]}),N&&j.length>0&&e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Ga,{size:20,className:"text-success"})}),e.jsx("p",{className:"text-sm font-medium text-success font-sans",children:"All services connected"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Your agents can now use these Google integrations."}),C?e.jsxs("div",{className:"w-full space-y-2 pt-2",children:[e.jsx("p",{className:"text-2xs text-warning font-sans",children:"New permissions available — re-authenticate to enable all features."}),e.jsx(pe,{variant:"secondary",size:"sm",onClick:T,disabled:h,className:"w-full gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ls,{size:12})," Re-authenticate"]})})]}):e.jsx("button",{onClick:T,disabled:h,className:"text-2xs text-text-4 hover:text-text-2 font-sans underline underline-offset-2 transition-colors mt-1",children:h?"Opening browser...":"Re-authenticate"})]}),j.length===0&&!O&&e.jsx("p",{className:"text-xs text-text-4 font-sans text-center py-2",children:"Install at least one service above, then connect with Google."})]}),e.jsx(pe,{variant:"secondary",size:"lg",onClick:n,className:"w-full",children:N&&j.length>0?"Done":"Close"})]})})}):null}const Hg=/github\.com\/([^/]+)\/([^/\s#?]+)/;function rse(){const[t,s]=p.useState("input"),[n,a]=p.useState(""),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,x]=p.useState("standalone"),[h,g]=p.useState(""),[O,b]=p.useState(!0),[v,y]=p.useState(""),S=k(B=>B.previewRepo),j=k(B=>B.importRepo),N=k(B=>B.importInProgress),C=Hn(),U=p.useCallback(async B=>{const F=B.match(Hg);if(F){l(!0);try{const M=await S(B);A(M),y(M.name||F[2]),s("preview")}catch(M){C.error("Preview failed",M.message)}finally{l(!1)}}},[S,C]),P=p.useCallback(B=>{const F=B.target.value;a(F),Hg.test(F)&&t==="input"&&U(F)},[t,U]),T=p.useCallback(async()=>{if(!c)return;let B;f==="standalone"?B=`~/Projects/${c.name}`:f==="subdirectory"?B=`./packages/${c.name}`:B=h;try{await j(n,B,O,v),C.success(`Importing ${c.name}`,"Setup agent will handle the rest"),s("input"),a(""),A(null)}catch(F){C.error("Import failed",F.message)}},[c,f,h,n,O,v,j,C]);if(t==="input")return e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{type:"text",value:n,onChange:P,placeholder:"Paste a GitHub URL...",className:Z("w-full h-9 rounded-lg pl-9 pr-20 text-sm font-sans","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors duration-100")}),e.jsx(pe,{variant:"primary",size:"sm",className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:()=>U(n),disabled:!Hg.test(n)||r,children:r?e.jsx(De,{size:12,className:"animate-spin"}):"Preview"})]});if(t==="preview"&&c)return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(Kl,{size:22,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx("span",{className:"text-lg font-bold text-text-0 font-sans",children:c.name}),e.jsx("span",{className:"text-xs text-text-4 font-sans",children:c.owner})]}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[c.language&&e.jsx(Te,{variant:"outline",className:"text-2xs",children:c.language}),c.stars!=null&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lb,{size:10,className:"text-warning",fill:"currentColor"}),jt(c.stars)]}),c.license&&e.jsx("span",{children:c.license})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(pe,{variant:"primary",size:"sm",onClick:()=>s("configure"),className:"h-8 text-xs gap-1.5 px-4",children:[e.jsx(Ys,{size:13}),"Clone & Setup"]}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>{try{const B=n.startsWith("http")?n:`https://${n}`,F=new URL(B);(F.protocol==="https:"||F.protocol==="http:")&&window.open(B,"_blank")}catch{}},className:"h-8 text-xs gap-1.5",children:[e.jsx(Ws,{size:12}),"GitHub"]}),e.jsx("button",{onClick:()=>{s("input"),A(null)},className:"text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 ml-1",children:"Cancel"})]})]})}),c.description&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2",children:"About"}),e.jsx("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:c.description})]}),c.readmePreview&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-3",children:"README"}),e.jsx("div",{className:"text-sm text-text-2 font-sans leading-relaxed whitespace-pre-wrap",children:c.readmePreview})]})]});if(t==="configure"&&c){const B=[{id:"standalone",icon:xd,title:"Standalone project",description:"Clone to its own directory, separate from this workspace",path:`~/Projects/${c.name}`},{id:"subdirectory",icon:zb,title:"Workspace package",description:"Add as a package inside this project's monorepo",path:`./packages/${c.name}`},{id:"custom",icon:RS,title:"Custom location",description:"Choose your own path",path:null}];return e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-border-subtle bg-surface-3/50",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(qs,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:["Clone ",c.name]}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:[c.owner,"/",c.name," — configure where to install"]})]})]})}),e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2.5 block",children:"Install location"}),e.jsx("div",{className:"space-y-2",children:B.map(F=>{const M=F.icon,R=f===F.id;return e.jsx("button",{onClick:()=>x(F.id),className:Z("w-full text-left rounded-lg border p-3.5 transition-all duration-150 cursor-pointer",R?"border-accent bg-accent/5 ring-1 ring-accent/30":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-1/80"),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:Z("w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0 mt-0.5",R?"bg-accent/15 text-accent":"bg-surface-3 text-text-4"),children:e.jsx(M,{size:15})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:Z("text-xs font-semibold font-sans",R?"text-text-0":"text-text-2"),children:F.title}),R&&e.jsx("div",{className:"w-4 h-4 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Je,{size:10,className:"text-white"})})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5 leading-relaxed",children:F.description}),F.path&&R&&e.jsx("code",{className:"text-2xs text-accent/80 font-mono mt-1.5 block truncate",children:F.path})]})]})},F.id)})}),f==="custom"&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:h,onChange:F=>g(F.target.value),placeholder:"/path/to/clone",autoFocus:!0,className:Z("w-full h-9 px-3 text-xs font-mono rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-3 flex items-center justify-center",children:e.jsx(yn,{size:14,className:"text-text-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans block",children:"Create a team"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Organize agents working on this repo into their own team"})]})]}),e.jsx("button",{onClick:()=>b(!O),className:Z("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer flex-shrink-0",O?"bg-accent":"bg-surface-5"),children:e.jsx("div",{className:Z("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",O?"translate-x-4":"translate-x-0")})})]}),O&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:v,onChange:F=>y(F.target.value),placeholder:"Team name",className:Z("w-full h-9 px-3 text-xs font-sans rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle bg-surface-3/30 flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>s("preview"),className:"flex items-center gap-1.5 text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 transition-colors",children:[e.jsx(kb,{size:11}),"Back"]}),e.jsx(pe,{variant:"primary",size:"sm",onClick:T,disabled:N||f==="custom"&&!h.trim(),className:"h-8 text-xs gap-1.5 px-5",children:N?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12,className:"animate-spin"})," Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(qs,{size:12})," Clone & Setup"]})})]})]})}return null}function ose({repo:t,onRemove:s,onNuke:n,onOpen:a}){return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:t.repoName||t.name}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.repoOwner||t.owner})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.language&&e.jsx(Te,{variant:"outline",className:"text-2xs",children:t.language}),e.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-[180px]",children:t.clonedTo||t.path})]}),e.jsx("span",{className:"text-2xs text-text-4 font-sans mt-0.5 block",children:t.clonedAt?`Imported ${$t(t.clonedAt)}`:t.status||""})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a&&e.jsxs("button",{onClick:()=>a(t),className:Z("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-accent bg-accent/10 hover:bg-accent/20 border-0 transition-colors"),children:[e.jsx(Ys,{size:11}),"Open"]}),s&&e.jsxs("button",{onClick:()=>s(t),className:Z("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-text-3 hover:text-text-1 hover:bg-surface-4 bg-transparent border-0 transition-colors"),children:[e.jsx(Ft,{size:11}),"Remove"]}),n&&e.jsxs("button",{onClick:()=>n(t),className:Z("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-danger bg-danger/10 hover:bg-danger/20 border-0 transition-colors"),children:[e.jsx(_$,{size:11}),"Nuke"]})]})]})}function ise({repo:t,open:s,onClose:n,onConfirm:a}){var h,g,O;const[r,l]=p.useState(!0);if(!t)return null;const c=((h=t.agents)==null?void 0:h.length)||0,A=((g=t.processes)==null?void 0:g.length)||0,f=((O=t.credentialKeys)==null?void 0:O.length)||0,x=t.fileCount||0;return e.jsx(Vt,{open:s,onOpenChange:b=>{b||n()},children:e.jsx(Kt,{title:`Nuke ${t.repoName||t.name}?`,description:"Confirm destructive removal of imported repo",children:e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Aa,{size:16,className:"text-danger flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-text-1 font-sans",children:"This cannot be undone."})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-text-2 font-sans",children:[c>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Kill ",c," agent",c!==1?"s":""]}),A>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Stop ",A," process",A!==1?"es":""]}),f>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Remove ",f," credential",f!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"}),' Delete team "',t.teamId||t.repoName||t.name,'"']}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Clean all .groove state"]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:b=>l(b.target.checked),className:"accent-[var(--color-danger)]"}),e.jsxs("span",{className:"text-xs text-text-1 font-sans",children:["Delete repo files",x>0?` (${x} files)`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(pe,{variant:"danger",size:"sm",onClick:()=>a(r),children:"Nuke Everything"}),e.jsx(pe,{variant:"ghost",size:"sm",onClick:n,children:"Cancel"})]})]})})})}function lse({skill:t,onBack:s}){var P,T,B;const n=Hn(),[a,r]=p.useState(""),[l,c]=p.useState(!1),[A,f]=p.useState(!1),[x,h]=p.useState(!1),[g,O]=p.useState(!1),[b,v]=p.useState(t.installed),[y,S]=p.useState(!0);p.useEffect(()=>{S(!0),G.get(`/skills/${t.id}/content`).then(F=>{r(F.content||""),c(F.requiresPurchase||!1)}).catch(()=>{}).finally(()=>S(!1))},[t.id]);async function j(){f(!0);try{await G.post(`/skills/${t.id}/install`),v(!0),n.success(`${t.name} installed`)}catch(F){n.error("Install failed",F.message)}f(!1)}async function N(){h(!0);try{await G.post(`/skills/${t.id}/update`),n.success(`${t.name} updated to latest`);const F=await G.get(`/skills/${t.id}/content`);F.content&&r(F.content)}catch(F){n.error("Update failed",F.message)}h(!1)}async function C(){O(!0);try{await G.delete(`/skills/${t.id}`),v(!1),n.success(`${t.name} uninstalled`)}catch(F){n.error("Uninstall failed",F.message)}O(!1)}async function U(){const{marketplaceAuthenticated:F,marketplaceLogin:M,marketplaceCheckout:R}=k.getState();if(!F){M();return}try{await R(t.id)}catch{}}return e.jsx(Qt,{className:"h-full",children:e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("button",{onClick:s,className:"flex items-center gap-1 text-xs text-text-3 font-sans hover:text-text-0 cursor-pointer bg-transparent border-0 mb-4",children:[e.jsx(Di,{size:14})," Back"]}),e.jsxs("div",{className:"flex gap-8",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-[22px]",children:t.icon||((T=(P=t.name)==null?void 0:P[0])==null?void 0:T.toUpperCase())}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[e.jsx("span",{children:t.author||"Community"}),(t.source==="claude-official"||t.verified)&&e.jsx(Zte,{type:t.source,size:13})]})]})]}),e.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((B=t.tags)==null?void 0:B.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:t.tags.map(F=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:F},F))}),e.jsx("div",{className:"h-px bg-border-subtle my-5"}),y?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):a?e.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:a})]}):l?e.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[e.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):e.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),e.jsx("div",{className:"w-[240px] flex-shrink-0",children:e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[e.jsx(Gte,{price:t.price||0,size:"md"}),l&&!b?e.jsxs("button",{onClick:U,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 flex items-center justify-center gap-2 border bg-warning/15 text-warning border-warning/20 hover:bg-warning/25",children:["Buy $",(t.price||0).toFixed(2)]}):b?e.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[e.jsxs("button",{onClick:N,disabled:x,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:[e.jsx(Ls,{size:12,className:x?"animate-spin":""}),x?"Updating...":"Pull Latest"]}),e.jsxs("button",{onClick:C,disabled:g,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-error/10 text-error border-error/20 hover:bg-error/15",children:[e.jsx(Ft,{size:12}),g?"Removing...":"Uninstall"]})]}):e.jsx("button",{onClick:j,disabled:A,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:A?"Installing...":"Install"}),e.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",e.jsx("span",{className:"font-mono text-text-0",children:jt(t.downloads||0)},"d")],["Rating",e.jsx(Hte,{rating:t.rating||0,count:t.rating_count||t.ratingCount,size:"sm"},"r")],["Version",e.jsx("span",{className:"font-mono text-text-0",children:t.version||"1.0.0"},"v")],["Category",e.jsx(Xte,{label:t.category||"general",variant:t.category||"draft"},"c")],["Source",e.jsx("span",{className:"text-text-0",children:t.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([F,M])=>e.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:F}),M]},F))})]})})]})]})})}function cse({open:t,onClose:s}){const[n,a]=p.useState("new"),[r,l]=p.useState(""),[c,A]=p.useState(""),[f,x]=p.useState(""),[h,g]=p.useState(""),[O,b]=p.useState(""),[v,y]=p.useState(!1),S=k(M=>M.teams),j=k(M=>M.activeTeamId),N=k(M=>M.createTeam),C=k(M=>M.spawnAgent),U=k(M=>M.setActiveView),P=k(M=>M.selectAgent),T=Hn();p.useEffect(()=>{t&&(a("new"),l(""),A(j||""),x(""),g(""),b(""),y(!1))},[t,j]);async function B(){if(f.trim()){y(!0);try{let M;n==="new"?M=(await N(r.trim()||f.trim())).id:M=c;const R=[`The user wants to integrate the **${f.trim()}** API into their project.`,""];h.trim()&&R.push(`**API Documentation:** ${h.trim()}`),O.trim()&&R.push("**API Key:** The user has provided an API key. Store it securely using environment variables — never hardcode it."),R.push("","Start by:","1. Reviewing the API documentation to understand available endpoints and authentication","2. Asking the user what they want to build with this API","3. Setting up the necessary configuration and authentication","4. Building the integration together","","Ask the user about their project and how they'd like to use this API.");const Y=R.join(`
1012
+ disabled:cursor-not-allowed`})]}),e.jsx("span",{className:"text-[11px] text-accent font-mono font-medium w-9 text-right shrink-0 tabular-nums",children:O})]})}const xee={backend:Ns,frontend:md,fullstack:bn,testing:Wx,security:vn},mee=new Set(["codex","grok","local"]),hee=/^[a-zA-Z0-9_-]{1,64}$/;function pee(t){return t.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,64)}function qf(){var H;const t=k(I=>I.recommendedTeam),s=k(I=>I.launchRecommendedTeam),n=k(I=>I.teamLaunchConfig),a=k(I=>I.fetchProviders),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState([]),[O,b]=p.useState((n==null?void 0:n.provider)||""),[v,y]=p.useState((n==null?void 0:n.model)||""),[S,j]=p.useState((n==null?void 0:n.reasoningEffort)??50),[N,C]=p.useState((n==null?void 0:n.temperature)??.5),[U,P]=p.useState(null);if(p.useEffect(()=>{a().then(I=>{Array.isArray(I)&&g(I.filter(L=>L.installed))}).catch(()=>{})},[]),!((H=t==null?void 0:t.agents)!=null&&H.length))return null;const T=t.agents,B=T.filter(I=>!I.phase||I.phase===1),F=T.filter(I=>I.phase===2),M=c??B.map(I=>({...I,name:I.name||""})),R=h.find(I=>I.id===O),Y=((R==null?void 0:R.models)||[]).filter(I=>I.type!=="image"&&!I.disabled),W=mee.has(O);function ee(I,L){const J=M.map((D,se)=>se===I?{...D,name:pee(L)}:D);A(J)}function K(I,L){if(typeof L=="string"){const[J,D]=[L,arguments[2]];A(se=>(se??M).map((le,V)=>V===I?{...le,[J]:D}:le))}else A(J=>(J??M).map((D,se)=>se===I?{...D,...L}:D))}function _(I){var D;b(I);const L=h.find(se=>se.id===I),J=((L==null?void 0:L.models)||[]).filter(se=>se.type!=="image"&&!se.disabled);y(((D=J[0])==null?void 0:D.id)||"")}async function E(){l(!0),k.setState({teamLaunchConfig:{...O&&{provider:O,model:v},reasoningEffort:S,...W&&{temperature:N}}});try{const I=[...M,...F];await s(I)}catch{}l(!1)}function q(){k.setState({recommendedTeam:null})}return e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 z-50 w-full max-w-lg",children:e.jsxs("div",{className:"mx-4 rounded-lg border border-accent/30 bg-surface-2/95 backdrop-blur-md shadow-xl shadow-accent/5 overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center gap-2",children:[e.jsx(Ei,{size:16,className:"text-accent"}),e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Planner Recommends a Team"}),e.jsx("button",{onClick:q,className:"text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:14})})]}),e.jsxs("div",{className:"border-b border-border-subtle",children:[e.jsxs("button",{onClick:()=>x(!f),className:"w-full flex items-center gap-2 px-4 py-2 text-left cursor-pointer hover:bg-surface-3/50 transition-colors",children:[e.jsx(xt,{size:12,className:Z("text-text-4 transition-transform duration-200",!f&&"-rotate-90")}),e.jsx(DS,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider",children:"Team Settings"}),O&&e.jsxs("span",{className:"ml-auto text-2xs text-accent font-mono",children:[O,v?` / ${v}`:""]})]}),f&&e.jsxs("div",{className:"px-4 pb-3 space-y-3",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:O,onValueChange:_,children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-4 h-7 text-xs"}),e.jsx(In,{children:h.map(I=>e.jsx(ms,{value:I.id,children:I.displayName||I.name||I.id},I.id))})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:v,onValueChange:y,children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-4 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"auto",children:"Auto"}),Y.map(I=>e.jsx(ms,{value:I.id,children:I.name||I.id},I.id))]})]})]})]}),e.jsx(Ka,{label:"Reasoning",value:S,onChange:j,min:0,max:100,step:1}),W&&e.jsx(Ka,{label:"Temperature",value:N,onChange:C,min:0,max:1,step:.01,formatValue:I=>I.toFixed(2)})]})]}),e.jsxs("div",{className:"px-4 py-3 space-y-1.5",children:[M.map((I,L)=>{var te;const J=xee[I.role]||bn,D=!I.name||hee.test(I.name),se=U===L,le=h.find(ae=>ae.id===(I.provider||O)),V=((le==null?void 0:le.models)||[]).filter(ae=>ae.type!=="image"&&!ae.disabled);return e.jsxs("div",{className:"rounded-md bg-surface-4 border border-border-subtle overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 cursor-pointer hover:bg-surface-5/50 transition-colors",onClick:()=>P(se?null:L),children:[e.jsx(J,{size:12,className:"text-text-2 shrink-0"}),e.jsx("input",{type:"text",value:I.name,onChange:ae=>ee(L,ae.target.value),onClick:ae=>ae.stopPropagation(),placeholder:I.role,className:Z("flex-1 min-w-0 bg-transparent text-xs font-mono text-text-0 outline-none placeholder:text-text-4",!D&&"text-red-400"),maxLength:64,spellCheck:!1}),I.provider&&I.provider!==O&&e.jsx("span",{className:"text-2xs text-accent font-mono shrink-0",children:I.provider}),((te=I.scope)==null?void 0:te.length)>0&&e.jsxs("span",{className:"text-2xs text-text-4 font-mono shrink-0 truncate max-w-[120px]",children:[I.scope[0],I.scope.length>1?` +${I.scope.length-1}`:""]}),e.jsx(xt,{size:10,className:Z("text-text-4 shrink-0 transition-transform duration-200",!se&&"-rotate-90")})]}),se&&e.jsxs("div",{className:"px-2.5 pb-2.5 pt-1 space-y-2.5 border-t border-border-subtle",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(ka,{size:10}),"Provider"]}),e.jsxs(Rn,{value:I.provider||"",onValueChange:ae=>{var oe;const be=h.find(ue=>ue.id===ae),z=((be==null?void 0:be.models)||[]).filter(ue=>ue.type!=="image"&&!ue.disabled);K(L,{provider:ae,model:((oe=z[0])==null?void 0:oe.id)||""})},children:[e.jsx(Mn,{placeholder:"Team default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"",children:"Team default"}),h.map(ae=>e.jsx(ms,{value:ae.id,children:ae.displayName||ae.name||ae.id},ae.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:I.model||"",onValueChange:ae=>K(L,"model",ae),children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"",children:"Auto"}),V.map(ae=>e.jsx(ms,{value:ae.id,children:ae.name||ae.id},ae.id))]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(Ro,{size:10}),"Model Routing"]}),e.jsx("div",{className:"flex bg-surface-3 rounded-md p-0.5 border border-border-subtle",children:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}].map(ae=>e.jsx("button",{onClick:()=>K(L,"routingMode",ae.value),className:Z("flex-1 px-2 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(I.routingMode||"auto")===ae.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae.label},ae.value))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"flex items-center gap-1 text-2xs text-text-3 font-sans",children:[e.jsx(SS,{size:10}),"Effort Level"]}),e.jsx("div",{className:"flex bg-surface-3 rounded-md p-0.5 border border-border-subtle",children:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"},{value:"ultra",label:"Ultra"}].map(ae=>e.jsx("button",{onClick:()=>K(L,"effort",ae.value),className:Z("flex-1 px-1.5 py-1 text-2xs font-semibold font-sans rounded transition-all cursor-pointer",(I.effort||"default")===ae.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:ae.label},ae.value))})]})]})]},L)}),t.projectDir&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-2 font-mono pt-0.5",children:[e.jsx("span",{className:"text-text-4",children:"Project:"}),e.jsxs("span",{className:"text-accent",children:[t.projectDir,"/"]})]}),F.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans",children:[e.jsx(vn,{size:10}),e.jsxs("span",{children:[F.length," QC agent",F.length>1?"s":""," will auto-spawn after builders complete"]})]})]}),e.jsx("div",{className:"px-4 py-3 border-t border-border-subtle",children:e.jsxs(pe,{variant:"primary",size:"md",onClick:E,disabled:r,className:"w-full gap-2",children:[e.jsx(qt,{size:14}),r?"Launching...":`Launch ${B.length} Agent${B.length>1?"s":""}`]})})]})})}const gee={agentNode:SC,rootNode:CC},Ig=220,zg=82,wf=260,jf=130,po=4,Xs="__groove_root__";function FA(t){if(!t)return{};try{return JSON.parse(localStorage.getItem(`groove:nodePositions:${t}`)||"{}")}catch{return{}}}function B4(){let t=!1;for(const s of["groove:chatHistory","groove:activityLog"])localStorage.getItem(s)!==null&&(localStorage.removeItem(s),t=!0);return t}function QQ(t,s){if(!t)return;const n=`groove:nodePositions:${t}`,a=JSON.stringify(s);try{localStorage.setItem(n,a);return}catch{}if(B4())try{localStorage.setItem(n,a)}catch{}}function k4(){try{return JSON.parse(localStorage.getItem("groove:roleLayout")||"{}")}catch{return{}}}function Oee(t){const s="groove:roleLayout",n=JSON.stringify(t);try{localStorage.setItem(s,n);return}catch{}if(B4())try{localStorage.setItem(s,n)}catch{}}function T4(){try{return JSON.parse(localStorage.getItem("groove:teamViewports")||"{}")}catch{return{}}}function bee(t,s){try{const n=T4();n[t]=s,localStorage.setItem("groove:teamViewports",JSON.stringify(n))}catch{}}function vee(t,s){const n=t.filter(c=>{var A;return c.teamId===s&&!((A=c.metadata)!=null&&A.scheduled)});return n.length===0?"idle":n.some(c=>c.status==="running"||c.status==="starting")?"working":n.every(c=>c.status==="completed")?"completed":n.some(c=>c.status==="crashed")?"crashed":"idle"}function yee(){const t=k(E=>E.teams),s=k(E=>E.activeTeamId),n=k(E=>E.agents),a=k(E=>E.switchTeam),r=k(E=>E.createTeam),l=k(E=>E.deleteTeamPermanently),c=k(E=>E.renameTeam),A=k(E=>E.cloneTeam),f=k(E=>E.reorderTeams),x=k(E=>E.addToast),[h,g]=p.useState(!1),[O,b]=p.useState(""),[v,y]=p.useState(null),[S,j]=p.useState(""),N=p.useRef(!1),[C,U]=p.useState(null),[P,T]=p.useState(null),B=p.useRef(null),[F,M]=p.useState(!1),[R,Y]=p.useState(!1),W=p.useCallback(()=>{const E=B.current;E&&(M(E.scrollLeft>0),Y(E.scrollLeft+E.clientWidth<E.scrollWidth-1))},[]);p.useEffect(()=>{const E=B.current;if(!E)return;W(),E.addEventListener("scroll",W);const q=new ResizeObserver(W);return q.observe(E),()=>{E.removeEventListener("scroll",W),q.disconnect()}},[W,t.length]);function ee(){const E=O.trim();!E||N.current||(N.current=!0,b(""),g(!1),r(E).finally(()=>{N.current=!1,setTimeout(()=>{B.current&&B.current.scrollTo({left:B.current.scrollWidth,behavior:"smooth"})},100)}))}function K(E){y(E.id),j(E.name)}function _(){const E=S.trim();if(!E||!v){y(null);return}c(v,E),y(null)}return e.jsxs("div",{className:"flex items-end px-0 pt-0 pb-0 bg-surface-1 border-b border-border gap-0 flex-shrink-0 overflow-hidden",children:[F&&e.jsx("button",{onClick:()=>{var E;return(E=B.current)==null?void 0:E.scrollBy({left:-300,behavior:"smooth"})},className:"w-6 h-9 flex items-center justify-center bg-accent/15 text-accent hover:bg-accent/25 transition-colors flex-shrink-0 cursor-pointer",children:e.jsx(Di,{size:14})}),e.jsxs("div",{ref:B,className:"flex items-end flex-1 min-w-0 overflow-x-auto gap-0",style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},children:[t.map(E=>{const q=n.filter(J=>{var D;return J.teamId===E.id&&!((D=J.metadata)!=null&&D.scheduled)}).length,H=E.id===s,I=v===E.id,L=n.filter(J=>{var D;return J.teamId===E.id&&!((D=J.metadata)!=null&&D.scheduled)&&(J.status==="running"||J.status==="starting")}).length;return e.jsxs(Uv,{children:[e.jsx(Ev,{asChild:!0,children:e.jsxs("div",{draggable:!I,onDragStart:J=>{U(E.id),J.dataTransfer.effectAllowed="move",J.dataTransfer.setData("text/plain","")},onDragEnd:()=>{U(null),T(null)},onDragOver:J=>{J.preventDefault(),J.dataTransfer.dropEffect="move",C&&C!==E.id&&T(E.id)},onDragLeave:()=>{P===E.id&&T(null)},onDrop:J=>{if(J.preventDefault(),!C||C===E.id)return;const D=t.findIndex(le=>le.id===C),se=t.findIndex(le=>le.id===E.id);D!==-1&&se!==-1&&f(D,se),U(null),T(null)},onClick:()=>!I&&a(E.id),onDoubleClick:()=>K(E),className:Z("relative flex items-center gap-2 px-3 h-9 text-xs font-sans cursor-pointer select-none transition-colors flex-shrink-0",H?"text-text-0 font-semibold border-x border-x-[#242830] bg-[#242830]":"text-text-3 hover:text-text-1 hover:bg-surface-3/50",C===E.id&&"opacity-40",P===E.id&&C!==E.id&&"border-l-2 !border-l-accent"),children:[H&&e.jsx("div",{className:"absolute top-0 left-0 right-0 h-px bg-accent",style:{height:"0.5px"}}),(()=>{const J=vee(n,E.id),D=J==="working"||J==="completed"?"text-green-400":J==="crashed"?"text-red-400":H?"text-accent":"text-text-4";return e.jsxs("span",{className:"relative flex-shrink-0",children:[e.jsx(yn,{size:13,className:Z(D,J==="working"&&"animate-pulse")}),J==="working"&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 w-1.5 h-1.5 rounded-full bg-green-400 animate-pulse"})]})})(),I?e.jsx("input",{value:S,onChange:J=>j(J.target.value),onKeyDown:J=>{J.key==="Enter"&&_(),J.key==="Escape"&&y(null)},onBlur:_,className:"h-5 w-24 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none",autoFocus:!0,onClick:J=>J.stopPropagation()}):e.jsx("span",{className:"truncate max-w-[120px]",children:E.name}),q>0&&!I&&e.jsx("span",{className:Z("flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-2xs font-mono font-semibold",L>0?"bg-accent/15 text-accent":"bg-surface-4 text-text-3"),children:q}),H&&e.jsx("div",{className:"absolute bottom-[-1px] left-0 right-0 h-px bg-[#242830]"})]})}),e.jsxs(Pv,{children:[e.jsxs(ya,{onSelect:()=>K(E),children:[e.jsx(Ua,{size:12})," Rename"]}),e.jsxs(ya,{onSelect:()=>A(E.id),children:[e.jsx(Ba,{size:12})," Clone"]}),e.jsx(Fv,{}),e.jsxs(ya,{danger:!0,onSelect:()=>{if(n.filter(D=>D.teamId===E.id).some(D=>D.status==="running"||D.status==="starting")){x("error","Stop running agents first");return}l(E.id)},children:[e.jsx(Ft,{size:12})," Delete"]})]})]},E.id)}),h?e.jsxs("div",{className:"flex items-center gap-1.5 px-3 h-9 flex-shrink-0",children:[e.jsx("input",{value:O,onChange:E=>b(E.target.value),onKeyDown:E=>{E.key==="Enter"&&ee(),E.key==="Escape"&&(g(!1),b(""))},placeholder:"Team name...",className:"h-5 w-28 px-1.5 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:ee,disabled:!O.trim(),className:"p-1 rounded text-accent hover:bg-accent/10 cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(Je,{size:12})}),e.jsx("button",{onClick:()=>{g(!1),b("")},className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:12})})]}):e.jsx("button",{onClick:()=>g(!0),className:"flex items-center justify-center w-6 h-6 my-auto mx-2 rounded-full bg-accent/15 text-accent hover:bg-accent/25 cursor-pointer transition-colors flex-shrink-0",title:"New team",children:e.jsx(it,{size:12})})]}),R&&e.jsx("button",{onClick:()=>{var E;return(E=B.current)==null?void 0:E.scrollBy({left:300,behavior:"smooth"})},className:"w-6 h-9 flex items-center justify-center bg-accent/15 text-accent hover:bg-accent/25 transition-colors flex-shrink-0 cursor-pointer",children:e.jsx(Tt,{size:14})})]})}function wee(){const t=k(K=>K.agents),s=k(K=>K.activeTeamId),n=k(K=>K.tokenTimeline),a=k(K=>K.selectAgent),r=k(K=>K.closeDetail),l=p.useRef([]),c=p.useMemo(()=>{const K=t.filter(E=>{var q;return E.teamId===s&&!((q=E.metadata)!=null&&q.scheduled)}).sort((E,q)=>(E.name||E.id).localeCompare(q.name||q.id)),_=l.current;return _.length===K.length&&_.every((E,q)=>E.id===K[q].id&&E.status===K[q].status&&E.name===K[q].name&&E.model===K[q].model&&E.tokensUsed===K[q].tokensUsed&&E.contextUsage===K[q].contextUsage)?_:(l.current=K,K)},[t,s]),A=p.useRef(FA(s)),f=p.useRef(s);f.current!==s&&(f.current=s,A.current=FA(s));const{fitView:x,setViewport:h}=BU(),[g,O]=p.useState(0),b=p.useRef(s),v=p.useMemo(()=>{const K=A.current,_=k4(),E=c.filter(se=>se.status==="running").length,q=K[Xs]||_[Xs]||{x:0,y:0},H=[{id:Xs,type:"rootNode",position:q,data:{agentCount:c.length,runningCount:E},draggable:!0,selectable:!1}],I=new Set,L=(se,le)=>`${Math.round(se/100)},${Math.round(le/100)}`;I.add(L(q.x,q.y));const J=[];c.forEach(se=>{const le=se.name||se.id;if(K[le]){const V=K[le];I.add(L(V.x,V.y)),H.push({id:se.id,type:"agentNode",position:V,data:{agent:se,timeline:n[se.id]||[]},draggable:!0,selectable:!0})}else J.push(se)});const D=new Map;return J.forEach((se,le)=>{const V=se.role||"agent",te=D.get(V)||0;D.set(V,te+1);const ae=te===0?V:`${V}-${te}`;let be;if(_[ae])be={..._[ae]};else{const z=Math.floor(le/po),oe=le%po;be={x:-((Math.min(J.length-z*po,po)-1)*wf)/2+oe*wf,y:jf+z*jf}}for(;I.has(L(be.x,be.y));)be={x:be.x,y:be.y+jf};I.add(L(be.x,be.y)),se.name||se.id,H.push({id:se.id,type:"agentNode",position:be,data:{agent:se,timeline:n[se.id]||[]},draggable:!0,selectable:!0})}),H},[c,n,s]);p.useEffect(()=>{const K={};v.forEach(_=>{var q,H;const E=_.id===Xs?Xs:((H=(q=_.data)==null?void 0:q.agent)==null?void 0:H.name)||_.id;A.current[E]||(K[E]=_.position)}),Object.keys(K).length>0&&(Object.assign(A.current,K),QQ(s,A.current))},[v,s]);const y=p.useMemo(()=>{const K=FA(s),_=K[Xs]||{x:0,y:0};return c.map((E,q)=>{const H=E.name||E.id,I=Math.floor(q/po),L=q%po,D=-((Math.min(c.length-I*po,po)-1)*wf)/2,se=K[H]||{x:D+L*wf,y:140+I*jf},le=se.x+Ig/2-_.x,V=se.y+zg/2-_.y;let te,ae;return Math.abs(V)>Math.abs(le)?(te=V>0?"bottom":"top",ae=V>0?"top":"bottom"):(te=le>0?"right":"left",ae=le>0?"left":"right"),{id:`e-${Xs}-${E.id}`,source:Xs,target:E.id,sourceHandle:te,targetHandle:ae,type:"default",animated:E.status==="running"}})},[c,s]),[S,j,N]=kU(v),[C,U,P]=TU(y),T=p.useRef(new Set);p.useEffect(()=>{j(K=>{const _=new Map(K.map(E=>[E.id,E]));return v.map(E=>{const q=_.get(E.id);return q?{...q,data:E.data}:E})})},[v,j]),p.useEffect(()=>{U(()=>{const K=S.find(E=>E.id===Xs);if(!K)return y;const _=K.position;return y.map(E=>{const q=S.find(D=>D.id===E.target);if(!q)return E;const H=q.position.x+Ig/2-_.x,I=q.position.y+zg/2-_.y;let L,J;return Math.abs(I)>Math.abs(H)?(L=I>0?"bottom":"top",J=I>0?"top":"bottom"):(L=H>0?"right":"left",J=H>0?"left":"right"),{...E,sourceHandle:L,targetHandle:J}})})},[y,S,U]);const B=c.map(K=>K.id).join(","),F=p.useRef(null);p.useEffect(()=>{if(b.current!==s){b.current=s,T.current=new Set(c.map(q=>q.id)),O(c.length);const E=T4()[s];E?h(E,{duration:200}):c.length>0&&x({padding:.3,maxZoom:1.2,duration:200});return}const K=new Set(c.map(E=>E.id)),_=c.length>0&&[...K].some(E=>!T.current.has(E));T.current=K,g===0&&c.length>0?x({padding:.3,maxZoom:1.2,duration:0}):_&&(clearTimeout(F.current),F.current=setTimeout(()=>x({padding:.3,maxZoom:1.2,duration:300}),500)),O(c.length)},[B,g,x,s,h]);const M=p.useCallback((K,_)=>{bee(s,_)},[s]),R=p.useCallback((K,_)=>{_.id!==Xs&&a(_.id)},[a]),Y=p.useCallback(()=>{r()},[r]),W=p.useCallback((K,_)=>{const E=S.find(H=>H.id===Xs);if(!E)return;const q=E.position;U(H=>H.map(I=>{const L=I.source===_.id,J=I.target===_.id;if(!L&&!J)return I;const D=_.position,se=D.x+Ig/2-q.x,le=D.y+zg/2-q.y;let V,te;return Math.abs(le)>Math.abs(se)?(V=le>0?"bottom":"top",te=le>0?"top":"bottom"):(V=se>0?"right":"left",te=se>0?"left":"right"),{...I,sourceHandle:V,targetHandle:te}}))},[S,U]),ee=p.useCallback((K,_)=>{var H,I;const E=_.id===Xs?Xs:((I=(H=_.data)==null?void 0:H.agent)==null?void 0:I.name)||_.id;A.current[E]=_.position;const q=FA(s);q[E]=_.position,QQ(s,q)},[s]);return e.jsx(UU,{nodes:S,edges:C,nodeTypes:gee,onNodesChange:N,onEdgesChange:P,onNodeClick:R,onPaneClick:Y,onNodeDrag:W,onNodeDragStop:ee,onMoveEnd:M,defaultViewport:{x:0,y:0,zoom:1.2},proOptions:{hideAttribution:!0},minZoom:.2,maxZoom:1.5,className:"bg-surface-2",children:e.jsx(EU,{color:"rgba(97,175,239,0.03)",gap:24,size:1})})}const U4=new Set(["codex","grok","local"]),jee=new Set(["codex"]);function Qee({open:t,onOpenChange:s,onLaunch:n}){const a=k(T=>T.fetchProviders),[r,l]=p.useState([]),[c,A]=p.useState(""),[f,x]=p.useState(""),[h,g]=p.useState(50),[O,b]=p.useState(.5),[v,y]=p.useState(50);p.useEffect(()=>{t&&a().then(T=>{var F;if(!Array.isArray(T))return;const B=T.filter(M=>M.installed);if(l(B),!c&&B.length>0){const M=B.find(Y=>Y.isDefault)||B[0];A(M.id);const R=((F=M.models)==null?void 0:F.filter(Y=>Y.type!=="image"))||[];R.length>0&&x(R[0].id)}}).catch(()=>{})},[t]);const S=r.find(T=>T.id===c),j=((S==null?void 0:S.models)||[]).filter(T=>T.type!=="image"&&!T.disabled),N=U4.has(c),C=jee.has(c);function U(T){var M;A(T);const B=r.find(R=>R.id===T),F=((B==null?void 0:B.models)||[]).filter(R=>R.type!=="image"&&!R.disabled);x(((M=F[0])==null?void 0:M.id)||"")}function P(){const T={provider:c,model:f,reasoningEffort:h,...N&&{temperature:O},...C&&{verbosity:v}};k.setState({teamLaunchConfig:T}),n(T)}return e.jsx(Vt,{open:t,onOpenChange:s,children:e.jsxs(Kt,{title:"Configure Planner",description:"Set provider, model, and tuning before launching the planner",children:[e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Provider"}),e.jsxs(Rn,{value:c,onValueChange:U,children:[e.jsx(Mn,{placeholder:"Select provider",className:"bg-surface-3"}),e.jsx(In,{children:r.map(T=>e.jsx(ms,{value:T.id,children:T.displayName||T.name||T.id},T.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans",children:"Model"}),e.jsxs(Rn,{value:f,onValueChange:x,children:[e.jsx(Mn,{placeholder:"Select model",className:"bg-surface-3"}),e.jsxs(In,{children:[e.jsx(ms,{value:"auto",children:"Auto"}),j.map(T=>e.jsx(ms,{value:T.id,children:T.name||T.id},T.id))]})]})]}),e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(Ka,{label:"Reasoning Effort",value:h,onChange:g,min:0,max:100,step:1}),N&&e.jsx(Ka,{label:"Temperature",value:O,onChange:b,min:0,max:1,step:.01,formatValue:T=>T.toFixed(2)}),C&&e.jsx(Ka,{label:"Verbosity",value:v,onChange:y,min:0,max:100,step:1})]})]}),e.jsx("div",{className:"px-5 py-4 border-t border-border-subtle",children:e.jsxs(pe,{variant:"primary",size:"md",onClick:P,className:"w-full gap-2",children:[e.jsx(qt,{size:14}),"Launch Planner"]})})]})})}const NQ={chat:Ho,planner:Ei,backend:Ns,frontend:md,fullstack:bn,testing:Wx,devops:Eb,docs:On,security:vn,database:Pb,cmo:Ib,cfo:bS,ea:LS,support:kS,analyst:Lx,creative:MS,slides:zS,ambassador:ua},_g=[{id:"planner",label:"Planner",desc:"Analyzes tasks and designs team plans"},{id:"frontend",label:"Frontend",desc:"React, UI components, views, styling"},{id:"backend",label:"Backend",desc:"APIs, server logic, database, services"},{id:"fullstack",label:"Fullstack",desc:"Cross-stack work, QC, integration testing"},{id:"testing",label:"Testing",desc:"Test suites, coverage, quality assurance"},{id:"devops",label:"DevOps",desc:"CI/CD, deployment, infrastructure"},{id:"security",label:"Security",desc:"Security audits, vulnerability analysis"},{id:"database",label:"Database",desc:"Schema design, queries, migrations"},{id:"docs",label:"Docs",desc:"Documentation, guides, API docs"},{id:"cmo",label:"CMO",desc:"Marketing strategy, campaigns, content"},{id:"cfo",label:"CFO",desc:"Financial analysis, budgeting, forecasting"},{id:"ea",label:"EA",desc:"Executive assistance, coordination, briefings"},{id:"support",label:"Support",desc:"Customer support, issue triage"},{id:"analyst",label:"Analyst",desc:"Data analysis, research, reporting"},{id:"creative",label:"Writer",desc:"Design, copywriting, visual assets"},{id:"slides",label:"Slides",desc:"Presentations, decks, pitch materials"}],Nee=[{name:"Dev Team",icon:bn,roles:["frontend","backend","testing"],desc:"3 agents"},{name:"Full Stack",icon:rc,roles:["frontend","backend","fullstack","testing","devops"],desc:"5 agents"},{name:"Marketing",icon:Ib,roles:["cmo","creative","analyst"],desc:"3 agents"},{name:"Business",icon:Lx,roles:["cfo","analyst","ea"],desc:"3 agents"},{name:"Security Audit",icon:vn,roles:["security","testing","devops"],desc:"3 agents"},{name:"Docs",icon:On,roles:["docs","frontend","analyst"],desc:"3 agents"}];function See(){const t=k(D=>D.teamBuilderOpen),s=k(D=>D.teamBuilderRoles),n=k(D=>D.teamBuilderSettings),a=k(D=>D.teamBuilderTask),r=k(D=>D.teamTemplates),l=k(D=>D.closeTeamBuilder),c=k(D=>D.addTeamBuilderRole),A=k(D=>D.removeTeamBuilderRole),f=k(D=>D.updateTeamBuilderRole),x=k(D=>D.applyTemplate),h=k(D=>D.setTeamBuilderSettings),g=k(D=>D.setTeamBuilderTask),O=k(D=>D.launchTeamBuilder),b=k(D=>D.saveTeamTemplate),v=k(D=>D.fetchTeamTemplates),y=k(D=>D.fetchProviders),[S,j]=p.useState([]),[N,C]=p.useState(""),[U,P]=p.useState(null),[T,B]=p.useState(!1),[F,M]=p.useState(null),[R,Y]=p.useState(!1),[W,ee]=p.useState("");if(p.useEffect(()=>{t&&(y().then(D=>{Array.isArray(D)&&j(D.filter(se=>se.installed))}).catch(()=>{}),v())},[t]),!t)return null;const K=N?_g.filter(D=>D.label.toLowerCase().includes(N.toLowerCase())||D.desc.toLowerCase().includes(N.toLowerCase())):_g,_=S.find(D=>D.id===n.provider),E=((_==null?void 0:_.models)||[]).filter(D=>D.type!=="image"&&!D.disabled);function q(D){var V;h({provider:D});const se=S.find(te=>te.id===D),le=((se==null?void 0:se.models)||[]).filter(te=>te.type!=="image"&&!te.disabled);h({provider:D,model:((V=le[0])==null?void 0:V.id)||""})}function H(D){x(D),M(D.name)}async function I(){B(!0);try{await O()}catch{}B(!1)}function L(){const D=W.trim();D&&(b(D),Y(!1),ee(""))}const J=[...Nee,...(r.custom||[]).map(D=>{var se;return{...D,icon:rc,desc:`${((se=D.roles)==null?void 0:se.length)||0} agents`,custom:!0}})];return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",children:[e.jsxs("div",{className:"w-full max-w-5xl max-h-[90vh] bg-surface-1 border border-border rounded-xl shadow-2xl flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-info/15 flex items-center justify-center",children:e.jsx(yn,{size:16,className:"text-info"})}),e.jsx("h2",{className:"text-lg font-bold text-text-0 font-sans",children:"Team Builder"})]}),e.jsx("button",{onClick:l,className:"p-2 rounded-md text-text-3 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",children:e.jsx(qe,{size:18})})]}),e.jsx("div",{className:"px-6 py-3 border-b border-border-subtle",children:e.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"none"},children:[J.map(D=>{const se=D.icon||rc,le=F===D.name;return e.jsxs("button",{onClick:()=>H(D),className:Z("flex flex-col items-center gap-1.5 px-4 py-2.5 rounded-lg border text-center transition-all cursor-pointer flex-shrink-0 min-w-[100px]",le?"border-accent bg-accent/5":"border-border-subtle bg-surface-3 hover:border-accent/30 hover:bg-surface-4"),children:[e.jsx(se,{size:16,className:le?"text-accent":"text-text-2"}),e.jsx("span",{className:"text-2xs font-semibold text-text-0 font-sans",children:D.name}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:D.desc})]},D.name)}),e.jsx(dt,{content:"Save current roster as template",children:e.jsxs("button",{onClick:()=>{Y(!0),ee("")},disabled:s.length===0,className:"flex flex-col items-center gap-1.5 px-4 py-2.5 rounded-lg border border-dashed border-border-subtle bg-surface-2 hover:border-accent/30 transition-all cursor-pointer flex-shrink-0 min-w-[100px] disabled:opacity-30 disabled:cursor-not-allowed",children:[e.jsx(_r,{size:16,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans",children:"Save"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Template"})]})})]})}),e.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"w-[40%] border-r border-border-subtle flex flex-col",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border-subtle",children:e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{type:"text",value:N,onChange:D=>C(D.target.value),placeholder:"Filter roles...",className:"w-full h-8 pl-8 pr-3 text-xs bg-surface-3 border border-border-subtle rounded-md text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent font-sans"})]})}),e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"p-3 grid grid-cols-2 gap-2",children:K.map(D=>{const se=NQ[D.id]||bn;return e.jsxs("button",{onClick:()=>c(D.id),className:"flex items-start gap-2.5 p-2.5 rounded-lg border border-border-subtle bg-surface-2 hover:border-accent/30 hover:bg-surface-3 transition-all cursor-pointer text-left group",children:[e.jsx("div",{className:"w-7 h-7 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/15 transition-colors",children:e.jsx(se,{size:14,className:"text-text-2 group-hover:text-accent transition-colors"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:D.label}),e.jsx(it,{size:12,className:"text-text-4 group-hover:text-accent transition-colors flex-shrink-0"})]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans leading-tight mt-0.5",children:D.desc})]})]},D.id)})})})]}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center justify-between",children:e.jsxs("span",{className:"text-xs font-semibold text-text-1 font-sans uppercase tracking-wider",children:["Your Team (",s.length,")"]})}),e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"p-3 space-y-1.5",children:s.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx(yn,{size:32,className:"text-text-4 mb-3"}),e.jsx("p",{className:"text-sm text-text-2 font-sans",children:"Add roles from the left or pick a template above"})]}):s.map((D,se)=>{var be;const le=NQ[D.role]||bn,V=U===se,te=D.provider?S.find(z=>z.id===D.provider):null,ae=((te==null?void 0:te.models)||[]).filter(z=>z.type!=="image"&&!z.disabled);return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(BS,{size:12,className:"text-text-4 flex-shrink-0 cursor-grab"}),e.jsx("div",{className:"w-6 h-6 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx(le,{size:12,className:"text-text-1"})}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans flex-1",children:((be=_g.find(z=>z.id===D.role))==null?void 0:be.label)||D.role}),e.jsx("button",{onClick:()=>P(V?null:se),className:"p-1 rounded text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(xt,{size:12,className:Z("transition-transform duration-200",V&&"rotate-180")})}),e.jsx("button",{onClick:()=>{A(se),U===se?P(null):U>se&&P(U-1)},className:"p-1 rounded text-text-4 hover:text-danger cursor-pointer",children:e.jsx(qe,{size:12})})]}),V&&e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-3 border-t border-border-subtle bg-surface-1",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Name Override"}),e.jsx("input",{type:"text",value:D.name,onChange:z=>f(se,{name:sanitizeName(z.target.value)}),placeholder:D.role,className:"w-full h-7 px-2.5 text-xs bg-surface-3 border border-border-subtle rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",maxLength:64,spellCheck:!1})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:D.provider||"__default__",onValueChange:z=>{var Ce;const oe=z==="__default__"?null:z,ue=S.find(Ne=>Ne.id===oe),ve=((ue==null?void 0:ue.models)||[]).filter(Ne=>Ne.type!=="image"&&!Ne.disabled);f(se,{provider:oe,model:((Ce=ve[0])==null?void 0:Ce.id)||null})},children:[e.jsx(Mn,{placeholder:"Team Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Team Default"}),S.map(z=>e.jsx(ms,{value:z.id,children:z.displayName||z.name||z.id},z.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:D.model||"__default__",onValueChange:z=>f(se,{model:z==="__default__"?null:z}),children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Default"}),ae.map(z=>e.jsx(ms,{value:z.id,children:z.name||z.id},z.id))]})]})]})]}),e.jsx(Ka,{label:"Reasoning",value:D.reasoningEffort??n.reasoningEffort,onChange:z=>f(se,{reasoningEffort:z}),min:0,max:100,step:1}),U4.has(D.provider||n.provider)&&e.jsx(Ka,{label:"Temperature",value:D.temperature??n.temperature,onChange:z=>f(se,{temperature:z}),min:0,max:1,step:.01,formatValue:z=>z.toFixed(2)})]})]},se)})})})]})]}),e.jsx("div",{className:"border-t border-border-subtle px-6 py-4",children:e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("textarea",{value:a,onChange:D=>g(D.target.value),placeholder:"Describe what you want to build... (optional)",rows:3,className:"w-full px-3 py-2 text-sm bg-surface-3 border border-border-subtle rounded-md text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent resize-none"}),e.jsx("p",{className:"text-2xs text-text-4 font-sans italic",children:"Leave empty to spawn agents awaiting instructions"})]}),e.jsxs("div",{className:"w-64 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-0.5",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Provider"}),e.jsxs(Rn,{value:n.provider||"__default__",onValueChange:D=>q(D==="__default__"?"":D),children:[e.jsx(Mn,{placeholder:"Default",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Default"}),S.map(D=>e.jsx(ms,{value:D.id,children:D.displayName||D.name||D.id},D.id))]})]})]}),e.jsxs("div",{className:"flex-1 space-y-0.5",children:[e.jsx("label",{className:"text-2xs text-text-3 font-sans",children:"Model"}),e.jsxs(Rn,{value:n.model||"__default__",onValueChange:D=>h({model:D==="__default__"?"":D}),children:[e.jsx(Mn,{placeholder:"Auto",className:"bg-surface-3 h-7 text-xs"}),e.jsxs(In,{children:[e.jsx(ms,{value:"__default__",children:"Auto"}),E.map(D=>e.jsx(ms,{value:D.id,children:D.name||D.id},D.id))]})]})]})]}),e.jsxs(pe,{variant:"primary",size:"md",onClick:I,disabled:T||s.length===0,className:"w-full gap-2 mt-1",children:[e.jsx(qt,{size:14}),T?"Launching...":`Plan & Launch (${s.length})`]})]})]})})]}),R&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/40",children:e.jsxs("div",{className:"w-full max-w-sm bg-surface-2 border border-border rounded-lg shadow-2xl p-5 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:"Save as Template"}),e.jsx("input",{type:"text",value:W,onChange:D=>ee(D.target.value),placeholder:"Template name...",className:"w-full h-8 px-3 text-sm bg-surface-3 border border-border-subtle rounded-md text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0,onKeyDown:D=>{D.key==="Enter"&&L(),D.key==="Escape"&&Y(!1)}}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>Y(!1),children:"Cancel"}),e.jsx(pe,{variant:"primary",size:"sm",onClick:L,disabled:!W.trim(),children:"Save"})]})]})})]})}function Cee({onPlanner:t,onSpawn:s,onTeamBuilder:n}){var a;return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"max-w-2xl w-full text-center space-y-10 px-8",children:[e.jsxs("div",{className:"relative mx-auto w-20 h-20",children:[e.jsx("div",{className:"absolute inset-0 rounded-full bg-accent/8 animate-pulse"}),e.jsx("div",{className:"absolute inset-1 rounded-full bg-surface-3 border border-border-subtle flex items-center justify-center shadow-lg shadow-accent/5",children:e.jsx("img",{src:"/favicon.png",alt:"Groove",className:"h-10 w-10 rounded-full"})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h1",{className:"text-3xl font-bold text-text-0 font-sans tracking-tight",children:"Welcome to Groove"}),e.jsx("p",{className:"text-base text-text-2 font-sans max-w-md mx-auto leading-relaxed",children:"Your mission control for AI agents. Spawn, orchestrate, and ship faster than ever."})]}),e.jsxs("div",{className:"space-y-3 max-w-xl mx-auto",children:[e.jsxs("button",{onClick:t,className:"w-full flex items-center gap-4 p-5 rounded-lg border border-accent/25 bg-gradient-to-r from-accent/8 to-accent/3 hover:from-accent/14 hover:to-accent/6 hover:border-accent/40 transition-all cursor-pointer group text-left",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/20 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:e.jsx(qt,{size:24,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-base font-semibold text-text-0 font-sans",children:"Start with a Planner"}),e.jsx("div",{className:"text-sm text-text-2 font-sans mt-0.5",children:"Describe what you want to build and let AI plan the perfect team"})]}),e.jsx("div",{className:"text-accent text-xs font-semibold font-sans flex-shrink-0 opacity-60 group-hover:opacity-100 transition-opacity",children:"Recommended"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:n,className:"flex items-center gap-3 p-4 rounded-lg border border-info/25 bg-gradient-to-r from-info/6 to-info/2 hover:from-info/12 hover:to-info/5 hover:border-info/35 transition-all cursor-pointer group text-left",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-info/15 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:e.jsx(HS,{size:20,className:"text-info"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Build a Team"}),e.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Pick roles and configure"})]})]}),e.jsxs("button",{onClick:s,className:"flex items-center gap-3 p-4 rounded-lg border border-border bg-surface-1 hover:bg-surface-2 hover:border-border transition-all cursor-pointer group text-left",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-surface-4 flex items-center justify-center group-hover:scale-110 transition-transform flex-shrink-0",children:e.jsx(it,{size:20,className:"text-text-1"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn Agent"}),e.jsx("div",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose a role and configure"})]})]})]})]}),((a=window.groove)==null?void 0:a.openFolder)&&e.jsxs("div",{className:"max-w-sm mx-auto",children:[e.jsx("p",{className:"text-xs text-text-3 mb-2",children:"Or open a different project"}),e.jsxs("button",{onClick:()=>window.groove.openFolder(),className:"w-full h-10 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 text-sm text-text-1 font-medium flex items-center justify-center gap-2 cursor-pointer transition-colors",children:[e.jsx(Ys,{size:16,className:"text-accent"}),"Open Folder"]})]}),e.jsxs("p",{className:"text-xs text-text-4 font-sans",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+K"}),e.jsx("span",{className:"mx-1.5",children:"command palette"}),e.jsx("span",{className:"text-text-4 mx-1",children:"·"}),e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+N"}),e.jsx("span",{className:"mx-1.5",children:"spawn"}),e.jsx("span",{className:"text-text-4 mx-1",children:"·"}),e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3",children:"Cmd+J"}),e.jsx("span",{className:"mx-1.5",children:"terminal"})]})]})})}function Dg(){var M;const t=k(R=>R.agents),s=k(R=>R.activeTeamId),n=k(R=>R.openDetail),a=k(R=>R.spawnAgent),r=k(R=>R.selectAgent);k(R=>R.recommendedTeam);const l=k(R=>R.checkRecommendedTeam),c=k(R=>R.addToast),A=k(R=>R.showPreviewInAgents),f=k(R=>R.previewState),x=k(R=>R.togglePreviewInAgents),h=k(R=>R.teamPreviews),g=k(R=>R.relaunchPreview),O=k(R=>R.openPreview),b=k(R=>R.workspaceMode),v=k(R=>R.setWorkspaceMode),y=k(R=>R.openTeamBuilder),[S,j]=p.useState(!1);p.useEffect(()=>{if(!t.some(W=>W.role==="planner"&&(W.status==="running"||W.status==="starting")))return;const Y=setInterval(()=>l(),5e3);return()=>clearInterval(Y)},[t,l]);function N(){j(!0)}async function C(R){j(!1);try{const Y=await a({role:"planner",provider:R.provider,model:R.model,reasoningEffort:R.reasoningEffort,temperature:R.temperature,verbosity:R.verbosity});Y!=null&&Y.id&&r(Y.id)}catch{}}const U=t.filter(R=>{var Y;return R.teamId===s&&!((Y=R.metadata)!=null&&Y.scheduled)}),P=k(R=>R.hydrated),[T,B]=p.useState(!0);p.useEffect(()=>{const R=setTimeout(()=>B(!1),1200);return()=>clearTimeout(R)},[]);const F=T||!P;return e.jsxs("div",{className:"flex flex-col h-full relative",children:[e.jsx("div",{className:"flex-1 min-h-0",children:F?e.jsxs("div",{className:Z("flex flex-col items-center justify-center h-full transition-opacity duration-500",!T&&P?"opacity-0":"opacity-100"),children:[e.jsxs("div",{className:"relative w-12 h-12 mb-5",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-accent/20 animate-ping",style:{animationDuration:"2s"}}),e.jsx("span",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent animate-spin",style:{animationDuration:"1s"}}),e.jsx("span",{className:"absolute inset-[6px] rounded-full bg-accent/8 flex items-center justify-center",children:e.jsx(qt,{size:16,className:"text-accent animate-pulse"})})]}),e.jsx("p",{className:"text-sm font-medium text-text-1 font-sans animate-pulse",children:"Connecting to agents"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Syncing with daemon..."})]}):U.length===0?e.jsx(Cee,{onPlanner:N,onSpawn:()=>n({type:"spawn"}),onTeamBuilder:y}):b?e.jsx(nY,{}):A&&f.url&&f.teamId===s&&((M=h[s])!=null&&M.active)?e.jsx(RX,{embedded:!0}):e.jsx(CU,{children:e.jsx(wee,{})},s)}),!b&&e.jsx(qf,{}),!F&&U.length>0&&!b&&e.jsxs("div",{className:"absolute bottom-3 left-3 z-40 flex items-center gap-1.5",children:[e.jsx(dt,{content:"Spawn agent",side:"top",children:e.jsx("button",{onClick:()=>n({type:"spawn"}),className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:e.jsx(it,{size:15})})}),e.jsx(dt,{content:Object.keys(k4()).length>0?"Update layout":"Save layout",side:"top",children:e.jsx("button",{onClick:()=>{const R=FA(s),Y={},W=new Map;[...U].sort((ee,K)=>(ee.name||ee.id).localeCompare(K.name||K.id)).forEach(ee=>{const K=ee.name||ee.id,_=R[K];if(!_)return;const E=ee.role||"agent",q=W.get(E)||0;W.set(E,q+1);const H=q===0?E:`${E}-${q}`;Y[H]=_}),R[Xs]&&(Y[Xs]=R[Xs]),Oee(Y),c("success","Layout saved","Future spawns will use these positions")},className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:e.jsx(yM,{size:15})})}),e.jsx(dt,{content:"Workspace",side:"top",children:e.jsx("button",{onClick:()=>v(!0),className:"flex items-center justify-center w-8 h-8 rounded border border-text-3/20 bg-surface-2/50 text-text-3 hover:text-accent hover:border-accent/40 hover:bg-accent/10 transition-colors cursor-pointer",children:e.jsx(bn,{size:15})})}),(()=>{const R=h[s];if(!R)return null;const Y=R.active&&f.url&&f.teamId===s,W=Y&&A,ee=W?"Show team":Y?"Show preview":"Relaunch preview";return e.jsx(dt,{content:ee,side:"top",children:e.jsx("button",{onClick:()=>{Y?A?x():O(R.url,s,R.kind):g(s)},className:Z("flex items-center justify-center w-8 h-8 rounded border bg-surface-2/50 transition-colors cursor-pointer",Y?"border-text-3/25 text-text-3 hover:text-info hover:border-info/40 hover:bg-info/10":"border-text-4/25 text-text-4 hover:text-warning hover:border-warning/40 hover:bg-warning/10"),children:W?e.jsx(yn,{size:15}):e.jsx(Vs,{size:15})})})})()]}),e.jsx(Qee,{open:S,onOpenChange:j,onLaunch:C}),e.jsx(See,{})]})}function Bee({children:t,detailContent:s,terminalContent:n}){const a=k(T=>T.activeView),r=k(T=>T.detailPanel),l=k(T=>T.connected),c=k(T=>T.tunneled),A=k(T=>T.daemonHost),f=k(T=>T.agents),x=k(T=>T.editorActiveFile),h=k(T=>T.detailPanelWidth),g=k(T=>T.terminalVisible),O=k(T=>T.terminalFullHeight),b=k(T=>T.setActiveView),v=k(T=>T.openDetail),y=k(T=>T.closeDetail),S=k(T=>T.setDetailPanelWidth),j=k(T=>T.setTerminalVisible),N=k(T=>T.toggleCommandPalette),C=p.useMemo(()=>f.filter(T=>T.status==="running").length,[f]),U=p.useMemo(()=>[{key:"k",meta:!0,handler:()=>k.getState().toggleCommandPalette()},{key:"p",meta:!0,shift:!0,handler:()=>k.getState().toggleCommandPalette()},{key:"j",meta:!0,handler:()=>{const T=k.getState();T.setTerminalVisible(!T.terminalVisible)}},{key:"n",meta:!0,handler:()=>k.getState().openDetail({type:"spawn"})},{key:"1",meta:!0,handler:()=>k.getState().setActiveView("agents")},{key:"2",meta:!0,handler:()=>k.getState().setActiveView("editor")},{key:"3",meta:!0,handler:()=>k.getState().setActiveView("dashboard")},{key:"4",meta:!0,handler:()=>k.getState().setActiveView("marketplace")},{key:"5",meta:!0,handler:()=>k.getState().setActiveView("teams")},{key:"Escape",handler:()=>{const T=k.getState();T.commandPaletteOpen?T.toggleCommandPalette():T.detailPanel&&T.closeDetail()}}],[]);pN(U);const P=r&&r.type!=="spawn";return e.jsx(v$,{children:e.jsxs("div",{className:Z("w-full h-full flex flex-col bg-surface-2 text-text-1 font-sans",cd()&&"electron-app"),children:[e.jsx(Uz,{activeView:a,connected:l,tunneled:c,daemonHost:A,editorActiveFile:x,onOpenCommandPalette:N}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsx(Cz,{activeView:a,detailPanel:r,onNavigate:b,onTogglePanel:T=>{(r==null?void 0:r.type)===T?y():v({type:T})}}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[a==="agents"&&e.jsx(yee,{}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[!(g&&O)&&e.jsx("main",{className:"flex-1 min-h-0 overflow-hidden relative",children:t}),n]}),P&&e.jsx(D_,{width:h,onWidthChange:S,onClose:y,children:s})]})]})]}),e.jsx(__,{connected:l,agentCount:f.length,runningCount:C,terminalVisible:g,onToggleTerminal:()=>j(!g)}),e.jsx(H_,{}),e.jsx(NC,{}),e.jsx(X_,{}),e.jsx(G_,{}),e.jsx(ZS,{})]})})}function kee({id:t,name:s,subtitle:n,models:a,authType:r,recommended:l,installed:c,installing:A,failed:f,selected:x,onInstall:h,gradientFrom:g,letter:O,statusChecking:b}){return e.jsxs(_n.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.25},className:Z("relative flex flex-col rounded-md border p-6 transition-all duration-200","bg-surface-2 hover:bg-surface-3 hover:shadow-lg hover:shadow-black/20",x?"border-accent ring-1 ring-accent/30 shadow-md shadow-accent/10":"border-border-subtle",A&&"pointer-events-none opacity-70"),children:[x&&e.jsx("div",{className:"absolute top-3 left-3 w-5 h-5 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Je,{className:"w-3 h-3 text-surface-0",strokeWidth:3})}),e.jsxs("div",{className:"flex items-start gap-4 mb-5",children:[e.jsx("div",{className:Z("w-14 h-14 rounded-md flex items-center justify-center text-lg font-bold font-mono shrink-0",g),children:O}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:s}),l&&e.jsx(Te,{variant:"purple",className:"text-2xs",children:"Recommended"})]}),e.jsx("p",{className:"text-xs text-text-2 mt-0.5",children:n})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-4",children:a.map(v=>e.jsx("span",{className:"text-xs text-text-2 bg-surface-4 px-2 py-0.5 rounded font-mono",children:v},v))}),e.jsx("p",{className:"text-2xs text-text-3 mb-4",children:r}),e.jsx("div",{className:"mt-auto pt-4 border-t border-border-subtle",children:A?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4 text-accent animate-spin"}),e.jsx("span",{className:"text-xs text-accent font-medium",children:"Installing..."})]}),e.jsx("div",{className:"h-1 bg-surface-4 rounded-full overflow-hidden",children:e.jsx(_n.div,{className:"h-full bg-accent rounded-full",initial:{width:"0%"},animate:{width:"90%"},transition:{duration:15,ease:"easeOut"}})})]}):c?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rx,{className:"w-4 h-4 text-success"}),e.jsx("span",{className:"text-xs text-success font-medium",children:"Ready"})]}):f?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"w-4 h-4 text-danger"}),e.jsx("span",{className:"text-xs text-danger font-medium",children:"Failed"})]}),e.jsxs("button",{type:"button",className:"h-8 px-5 rounded-full text-xs font-medium bg-danger/15 text-danger hover:bg-danger/25 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-danger flex items-center gap-1.5",onClick:v=>{v.stopPropagation(),h==null||h(t)},children:[e.jsx(Io,{className:"w-3 h-3"}),"Retry"]})]}):b?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"w-3.5 h-3.5 text-text-4 animate-spin"}),e.jsx("span",{className:"text-xs text-text-4",children:"Checking..."})]}):e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs("button",{type:"button",className:"h-8 px-5 rounded-full text-xs font-medium bg-accent text-surface-0 hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent flex items-center gap-1.5",onClick:v=>{v.stopPropagation(),h==null||h(t)},children:[e.jsx(qs,{className:"w-3.5 h-3.5"}),"Install"]})})})]})}const ja=[{id:"claude-code",name:"Claude Code",subtitle:"by Anthropic",models:["Opus 5","Sonnet 4.6","Haiku 4.5"],authType:"Subscription or API key",authModes:["subscription","apikey"],recommended:!0,letter:"C",gradientFrom:"bg-purple/20 text-purple",keyPlaceholder:"sk-ant-...",keyLabel:"Anthropic API Key"},{id:"codex",name:"Codex",subtitle:"by OpenAI",models:["GPT-5.4 Pro","Standard","Mini","Nano"],authType:"API key or ChatGPT Plus",authModes:["apikey","chatgpt-plus"],recommended:!1,letter:"X",gradientFrom:"bg-success/20 text-success",keyPlaceholder:"sk-...",keyLabel:"OpenAI API Key"},{id:"gemini",name:"Gemini CLI",subtitle:"by Google",models:["Gemini 3.1 Pro","3 Flash"],authType:"API key",authModes:["apikey"],recommended:!1,letter:"G",gradientFrom:"bg-info/20 text-info",keyPlaceholder:"AIza...",keyLabel:"Gemini API Key"}],Tee={enter:t=>({x:t>0?80:-80,opacity:0}),center:{x:0,opacity:1},exit:t=>({x:t<0?80:-80,opacity:0})},Uee={duration:.25,ease:[.4,0,.2,1]};function Eee({current:t,total:s}){return e.jsx("div",{className:"flex items-center gap-2.5",children:Array.from({length:s},(n,a)=>e.jsx("div",{className:Z("h-2 rounded-full transition-all duration-300",a===t?"w-7 bg-accent":a<t?"w-2 bg-accent/50":"w-2 bg-surface-5")},a))})}function Pee({onNext:t,onSkip:s}){return e.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[e.jsx(_n.img,{src:"/favicon.png",alt:"Groove",className:"w-20 h-20",initial:{scale:.5,opacity:0},animate:{scale:1,opacity:1},transition:{duration:.4,ease:"easeOut"}}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"Welcome to Groove"}),e.jsx("p",{className:"text-sm text-text-2",children:"Your AI coding team, ready in minutes"})]}),e.jsx("p",{className:"text-xs text-text-3 leading-relaxed max-w-sm",children:"Let's set up your AI providers so you can start spawning agents. This only takes a moment."}),e.jsxs("button",{type:"button",onClick:t,className:"mt-4 h-11 px-8 rounded-full bg-accent text-surface-0 font-semibold text-sm hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-0 flex items-center gap-2",autoFocus:!0,children:["Get Started",e.jsx(Mo,{className:"w-4 h-4"})]}),e.jsx("button",{type:"button",onClick:s,className:"text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent rounded px-2 py-1",children:"Skip setup"})]})}function Fee({selectedDir:t,onSelectDir:s}){const n=k(A=>A.remoteHomedir),[a,r]=p.useState(!1),l=new URLSearchParams(window.location.search).has("instance");async function c(){var f,x;if(l){r(!0);return}const A=await wE({title:"Choose your project folder",defaultPath:t||void 0});A?s(A):(x=(f=window.groove)==null?void 0:f.folders)!=null&&x.select||r(!0)}return e.jsxs("div",{className:"flex flex-col items-center max-w-lg mx-auto w-full text-center",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your project folder"}),e.jsx("p",{className:"text-sm text-text-2",children:"Pick the root directory where your code lives. Groove will manage agents from here."})]}),e.jsx("div",{className:"w-full bg-surface-2 border border-border-subtle rounded-lg p-5 mb-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg bg-accent/10 flex items-center justify-center",children:e.jsx(Ys,{className:"w-6 h-6 text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[e.jsx("p",{className:"text-xs text-text-3 mb-0.5",children:"Working directory"}),e.jsx("p",{className:"text-sm font-mono text-text-0 truncate",children:t||"No folder selected"})]})]})}),e.jsxs("button",{type:"button",onClick:c,className:"h-10 px-6 rounded-lg bg-accent text-surface-0 font-medium text-sm hover:bg-accent/80 transition-colors cursor-pointer flex items-center gap-2",children:[e.jsx(Ys,{className:"w-4 h-4"}),t?"Change Folder":"Select Folder"]}),e.jsx("p",{className:"mt-4 text-2xs text-text-4",children:"You can change this anytime in Settings."}),a&&e.jsx(gc,{open:a,onOpenChange:r,currentPath:t||n||"/",homePath:n,onSelect:A=>{s(A),r(!1)}})]})}function $ee({providerStatus:t,selected:s,onInstall:n,installing:a,statusChecking:r}){const l=ja.filter(A=>{var f;return(f=t[A.id])==null?void 0:f.installed}).length,c=l===ja.length;return e.jsxs("div",{className:"flex flex-col items-center max-w-4xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Choose your AI providers"}),e.jsx("p",{className:"text-sm text-text-2",children:"Install the coding tools you want to use. You can always add more later."})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 w-full mb-8",children:ja.map(A=>{var f,x;return e.jsx(kee,{...A,installed:(f=t[A.id])==null?void 0:f.installed,installing:a[A.id],failed:(x=t[A.id])==null?void 0:x.failed,selected:s.includes(A.id),onInstall:n,statusChecking:r},A.id)})}),e.jsx("p",{className:Z("text-xs text-center",c?"text-success":l>0?"text-text-2":"text-text-4"),children:c?"All providers installed — you're ready to go!":l>0?`${l} of ${ja.length} providers installed`:"Click Install to set up a provider"})]})}function Ree({provider:t,providerStatus:s,onSaveKey:n}){const[a,r]=p.useState(t.authModes.includes("subscription")?"subscription":"apikey"),[l,c]=p.useState(""),[A,f]=p.useState(!1),[x,h]=p.useState(!1),[g,O]=p.useState((s==null?void 0:s.authenticated)||!1),b=async()=>{if(l.trim()){h(!0);try{await n(t.id,l.trim()),O(!0)}catch{}finally{h(!1)}}},v=(s==null?void 0:s.maskedKey)||(g&&l?`${l.slice(0,6)}${"•".repeat(20)}`:null);return e.jsxs(_n.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.2},className:"bg-surface-2 border border-border-subtle rounded-md p-5",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:Z("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono",t.gradientFrom),children:t.letter}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:t.name}),e.jsx("p",{className:"text-2xs text-text-3",children:t.subtitle})]}),(g||(s==null?void 0:s.authenticated))&&e.jsx(Te,{variant:"success",className:"ml-auto",children:"Connected"})]}),t.authModes.length>1&&e.jsx("div",{className:"flex gap-1 mb-4 bg-surface-3 p-0.5 rounded-md",children:t.authModes.map(y=>e.jsx("button",{type:"button",onClick:()=>r(y),className:Z("flex-1 h-7 rounded text-xs font-medium transition-colors duration-100 cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a===y?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:y==="subscription"?"Subscription":y==="chatgpt-plus"?"ChatGPT Plus":"API Key"},y))}),a==="subscription"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-text-2",children:"Sign in via the terminal with your Claude subscription."}),e.jsx("div",{className:"space-y-1.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open a terminal and run: ",e.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"claude"})," — then follow the prompts to sign in."]})}),(s==null?void 0:s.authenticated)&&e.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[e.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="chatgpt-plus"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-xs text-text-2",children:["Run ",e.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"codex login"})," in your terminal to authenticate with ChatGPT Plus."]}),(s==null?void 0:s.authenticated)&&e.jsxs("p",{className:"text-xs text-success flex items-center gap-1.5",children:[e.jsx(Je,{className:"w-3.5 h-3.5"})," Connected"]})]}),a==="apikey"&&e.jsx("div",{className:"space-y-3",children:g||s!=null&&s.authenticated?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md bg-surface-1 border border-border px-3 flex items-center",children:e.jsx("span",{className:"text-xs text-text-3 font-mono truncate",children:v||"••••••••••••••"})}),e.jsx("button",{type:"button",onClick:()=>{O(!1),c("")},className:"h-8 px-3 rounded-md text-xs text-text-3 hover:text-text-1 bg-surface-4 hover:bg-surface-5 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:"Change"})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:A?"text":"password",value:l,onChange:y=>c(y.target.value),placeholder:t.keyPlaceholder,className:"h-8 w-full rounded-md px-3 pr-8 text-sm bg-surface-1 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent transition-colors duration-100 font-mono",onKeyDown:y=>y.key==="Enter"&&b(),"aria-label":t.keyLabel}),e.jsx("button",{type:"button",onClick:()=>f(!A),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer","aria-label":A?"Hide key":"Show key",children:A?e.jsx(To,{className:"w-3.5 h-3.5"}):e.jsx(Vs,{className:"w-3.5 h-3.5"})})]}),e.jsx("button",{type:"button",onClick:b,disabled:!l.trim()||x,className:"h-8 px-4 rounded-md bg-accent text-surface-0 text-xs font-medium hover:bg-accent/80 transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:pointer-events-none focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:x?"Saving...":"Save"})]})})]})}function Mee({providerStatus:t,installedIds:s,onSaveKey:n}){const a=ja.filter(r=>{var l;return s.includes(r.id)||((l=t[r.id])==null?void 0:l.installed)});return a.some(r=>{var l;return(l=t[r.id])==null?void 0:l.authenticated}),e.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Connect your accounts"}),e.jsx("p",{className:"text-sm text-text-2",children:"Add credentials for your installed providers."})]}),e.jsx("div",{className:"flex flex-col gap-4 w-full mb-6",children:a.map(r=>e.jsx(Ree,{provider:r,providerStatus:t[r.id]||{},onSaveKey:n},r.id))}),a.length===0&&e.jsx("p",{className:"text-sm text-text-3 text-center",children:"No providers installed yet. Go back to install one."})]})}function Iee({providerStatus:t,installedIds:s,defaultProvider:n,defaultModel:a,onSetDefault:r}){var c;const l=ja.filter(A=>{var f,x;return(s.includes(A.id)||((f=t[A.id])==null?void 0:f.installed))&&((x=t[A.id])==null?void 0:x.authenticated)});return e.jsxs("div",{className:"flex flex-col items-center max-w-2xl mx-auto w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-text-0 mb-2",children:"Set your default"}),e.jsx("p",{className:"text-sm text-text-2",children:"Choose which provider and model to use by default. You can switch per-agent anytime."})]}),e.jsxs("div",{className:"flex flex-col gap-3 w-full max-w-md mb-6",children:[l.map(A=>e.jsxs("button",{type:"button",onClick:()=>r(A.id,A.models[0]),className:Z("flex items-center gap-4 p-4 rounded-md border transition-all duration-200 text-left cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",n===A.id?"bg-accent/8 border-accent ring-1 ring-accent/30":"bg-surface-2 border-border-subtle hover:bg-surface-3"),children:[e.jsx("div",{className:Z("w-10 h-10 rounded-md flex items-center justify-center text-sm font-bold font-mono shrink-0",A.gradientFrom),children:A.letter}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-text-0",children:A.name}),e.jsx("p",{className:"text-2xs text-text-3",children:A.subtitle})]}),e.jsx("div",{className:Z("w-5 h-5 rounded-full border-2 flex items-center justify-center transition-colors",n===A.id?"border-accent bg-accent":"border-border"),children:n===A.id&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-surface-0"})})]},A.id)),l.length===0&&e.jsx("p",{className:"text-sm text-text-3 text-center",children:"No authenticated providers. Go back to connect one."})]}),n&&e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 mb-2 block",children:"Model"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(c=ja.find(A=>A.id===n))==null?void 0:c.models.map(A=>e.jsx("button",{type:"button",onClick:()=>r(n,A),className:Z("h-7 px-3 rounded-full text-xs font-medium transition-colors duration-100 cursor-pointer","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",a===A?"bg-accent text-surface-0":"bg-surface-4 text-text-2 hover:bg-surface-5 hover:text-text-0"),children:A},A))})]})]})}function zee({providerStatus:t,defaultProvider:s,defaultModel:n,onFinish:a}){var c;const r=ja.filter(A=>{var f;return(f=t[A.id])==null?void 0:f.installed}).length,l=(c=ja.find(A=>A.id===s))==null?void 0:c.name;return e.jsxs("div",{className:"flex flex-col items-center justify-center text-center gap-6 max-w-lg mx-auto",children:[e.jsx(_n.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",stiffness:300,damping:20},className:"w-20 h-20 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Je,{className:"w-10 h-10 text-success",strokeWidth:2.5})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-text-0 font-sans",children:"You're all set!"}),e.jsxs("p",{className:"text-sm text-text-2",children:[r," provider",r!==1?"s":""," installed",l?`, default: ${l}`:"",n?` (${n})`:""]})]}),e.jsx(_n.div,{className:"flex gap-3 mt-4",initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:.3},children:e.jsxs("button",{type:"button",onClick:a,className:"h-11 px-8 rounded-full bg-accent text-surface-0 font-semibold text-sm hover:bg-accent/80 transition-colors duration-100 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-0 flex items-center gap-2",autoFocus:!0,children:[e.jsx(Js,{className:"w-4 h-4"}),"Start Building"]})})]})}const yA=6;function _ee(){const t=k(H=>H.dismissOnboarding),s=k(H=>H.installProvider),n=k(H=>H.setDefaultProvider),a=k(H=>H.addToast),[r,l]=p.useState(0),[c,A]=p.useState(1),[f,x]=p.useState(["claude-code"]),[h,g]=p.useState({}),[O,b]=p.useState({}),[v,y]=p.useState(null),[S,j]=p.useState(null),[N,C]=p.useState(!0),[U,P]=p.useState(null),T=p.useRef(null);p.useEffect(()=>{let H=!1;async function I(){var J;try{const D=await fetch("/api/onboarding/status").then(se=>se.ok?se.json():null);if(D!=null&&D.providers){const se={},le=[];for(const V of D.providers){const te=V.authStatus==="authenticated"||V.authStatus==="key-set";se[V.id]={installed:V.installed,authenticated:te},V.installed&&le.push(V.id)}return{status:se,installedIds:le,workingDir:((J=D.config)==null?void 0:J.defaultWorkingDir)||null}}}catch{}try{const D=await fetch("/api/providers").then(se=>se.ok?se.json():null);if(D){const se={},le=[],V=Array.isArray(D)?D:D.providers||[];for(const te of V){const ae=te.installed||te.authStatus==="authenticated"||te.authStatus==="key-set"||!1;se[te.id]={installed:ae,authenticated:te.authenticated||!1},ae&&le.push(te.id)}return{status:se,installedIds:le}}}catch{}return null}async function L(){C(!0);let J=await I();if(!H&&J&&J.installedIds.length===0)for(let D=0;D<2;D++){if(await new Promise(se=>setTimeout(se,2e3)),H)return;if(J=await I(),J&&J.installedIds.length>0)break}!H&&J&&(b(J.status),J.installedIds.length>0&&x(D=>[...new Set([...D,...J.installedIds])]),J.workingDir&&!U&&P(J.workingDir)),H||C(!1)}return L(),()=>{H=!0}},[r]);const B=p.useCallback(()=>{r<yA-1&&(A(1),l(H=>H+1))},[r]),F=p.useCallback(()=>{r>0&&(A(-1),l(H=>H-1))},[r]),M=p.useCallback(()=>{t()},[t]),R=p.useCallback(async()=>{if(U)try{await P(U)}catch{a("error","Failed to set project directory")}t()},[t,U,a]),Y=p.useCallback(async H=>{g(I=>({...I,[H]:!0}));try{await s(H),b(I=>({...I,[H]:{...I[H],installed:!0}})),x(I=>I.includes(H)?I:[...I,H])}catch{b(I=>({...I,[H]:{...I[H],failed:!0}}))}finally{g(I=>({...I,[H]:!1}))}},[s]),W=p.useCallback(async(H,I)=>{try{if(!(await fetch(`/api/credentials/${encodeURIComponent(H)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:I})})).ok)throw new Error("Failed to save key");b(J=>({...J,[H]:{...J[H],authenticated:!0,maskedKey:`${I.slice(0,6)}${"•".repeat(20)}`}})),a("success","API key saved")}catch(L){throw a("error","Failed to save key",L.message),L}},[a]),ee=p.useCallback(async(H,I)=>{y(H),j(I);try{await n(H,I)}catch{}},[n]),K=ja.some(H=>{var I;return(I=O[H.id])==null?void 0:I.installed}),_=ja.some(H=>{var I;return(I=O[H.id])==null?void 0:I.authenticated}),E=r===0||r===1?!0:r===2?K:r===3?_:r===4?!!v:!1;p.useEffect(()=>{const H=I=>{I.key==="Enter"&&r<yA-1&&E&&B(),I.key==="Escape"&&M()};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[r,E,B,M]);const q=[e.jsx(Pee,{onNext:B,onSkip:M},"welcome"),e.jsx(Fee,{selectedDir:U,onSelectDir:P},"folder"),e.jsx($ee,{providerStatus:O,selected:f,onInstall:Y,installing:h,statusChecking:N},"install"),e.jsx(Mee,{providerStatus:O,installedIds:f,onSaveKey:W},"auth"),e.jsx(Iee,{providerStatus:O,installedIds:f,defaultProvider:v,defaultModel:S,onSetDefault:ee},"default"),e.jsx(zee,{providerStatus:O,defaultProvider:v,defaultModel:S,onFinish:R},"done")];return e.jsxs("div",{ref:T,className:"fixed inset-0 z-50 bg-gradient-to-b from-surface-0 to-surface-1 flex flex-col font-sans overflow-hidden",children:[cd()&&e.jsx("div",{className:"h-8 w-full electron-drag shrink-0"}),e.jsxs("div",{className:"flex items-center justify-between px-8 py-4 shrink-0",children:[e.jsx(Eee,{current:r,total:yA}),r>0&&r<yA-1&&e.jsx("button",{type:"button",onClick:M,className:"text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent rounded px-2 py-1",children:"Skip setup"})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center px-8 py-4 overflow-y-auto",children:e.jsx(Mi,{mode:"wait",custom:c,children:e.jsx(_n.div,{custom:c,variants:Tee,initial:"enter",animate:"center",exit:"exit",transition:Uee,className:"w-full",children:q[r]},r)})}),r>0&&r<yA-1&&e.jsxs("div",{className:"flex items-center justify-between px-8 py-8 shrink-0",children:[e.jsxs("button",{type:"button",onClick:F,className:"h-10 px-6 rounded-md text-sm text-text-2 hover:text-text-0 bg-surface-3 hover:bg-surface-4 transition-colors duration-100 cursor-pointer flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[e.jsx(Di,{className:"w-4 h-4"}),"Back"]}),e.jsxs("button",{type:"button",onClick:B,disabled:!E,className:"h-10 px-8 rounded-md text-sm font-medium bg-accent text-surface-0 hover:bg-accent/80 transition-colors duration-100 cursor-pointer disabled:opacity-40 disabled:pointer-events-none flex items-center gap-1.5 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent",children:[r===4?"Finish Setup":"Continue",e.jsx(Tt,{className:"w-4 h-4"})]})]})]})}const Dee=[{icon:Ns,label:"Federation",desc:"Multi-machine daemon pairing"},{icon:Eb,label:"Cloud Teams",desc:"Coming soon"}];function SQ(){var y;const t=k(S=>S.upgradeModalOpen),s=k(S=>S.setUpgradeModalOpen),n=k(S=>S.marketplaceAuthenticated),a=k(S=>S.marketplaceLogin),r=k(S=>S.startCheckout),l=k(S=>S.addToast),[c,A]=p.useState(null),[f,x]=p.useState("monthly"),[h,g]=p.useState(!1);p.useEffect(()=>{t&&!c&&k.getState().fetchSubscriptionPlans().then(S=>A(S)).catch(()=>{})},[t,c]);const O=(y=c==null?void 0:c.pro)==null?void 0:y[f],b=f==="annual"?`$${Math.round(((O==null?void 0:O.price)||96)/12)}/mo`:`$${(O==null?void 0:O.price)||10}/mo`;async function v(){var S;if(!n){a();return}if(!(O!=null&&O.priceId)){sO("https://groovedev.ai/pro"),s(!1);return}g(!0);try{await r(O.priceId),s(!1)}catch(j){j.status===401||(S=j.message)!=null&&S.includes("Not authenticated")?(l("info","Please sign in first"),a()):j.status===409&&(l("info","You already have a subscription"),s(!1))}finally{g(!1)}}return e.jsx(Vt,{open:t,onOpenChange:s,children:e.jsx(Kt,{title:"Upgrade to Pro",className:"max-w-[440px]",children:e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("div",{className:"mx-auto mb-3 w-12 h-12 rounded-full bg-accent/10 flex items-center justify-center",children:e.jsx(Js,{size:22,className:"text-accent"})}),e.jsx("h2",{className:"text-lg font-bold text-text-0",children:"Upgrade to Groove Pro"}),e.jsx("p",{className:"text-sm text-text-2 mt-1",children:"Unlock powerful features for your AI workflow"})]}),e.jsx("div",{className:"space-y-3 mb-6",children:Dee.map(S=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx(S.icon,{size:15,className:"text-accent"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-text-0",children:S.label}),e.jsx("p",{className:"text-2xs text-text-3",children:S.desc})]}),e.jsx(Je,{size:14,className:"text-success ml-auto flex-shrink-0"})]},S.label))}),e.jsxs("div",{className:"flex gap-1 mb-5 bg-surface-3 p-0.5 rounded-md",children:[e.jsx("button",{type:"button",onClick:()=>x("monthly"),className:Z("flex-1 h-8 rounded text-xs font-medium transition-colors cursor-pointer",f==="monthly"?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:"Monthly"}),e.jsxs("button",{type:"button",onClick:()=>x("annual"),className:Z("flex-1 h-8 rounded text-xs font-medium transition-colors cursor-pointer",f==="annual"?"bg-surface-5 text-text-0":"text-text-3 hover:text-text-1"),children:["Annual",e.jsx("span",{className:"ml-1 text-success text-2xs",children:"Save 20%"})]})]}),e.jsxs("div",{className:"text-center mb-5",children:[e.jsx("span",{className:"text-3xl font-bold text-text-0",children:b}),f==="annual"&&e.jsxs("p",{className:"text-2xs text-text-3 mt-1",children:["Billed $",(O==null?void 0:O.price)||96,"/year"]})]}),e.jsx("button",{type:"button",onClick:v,disabled:h,className:"w-full h-10 rounded-lg bg-accent text-white font-semibold text-sm hover:bg-accent/90 transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none flex items-center justify-center gap-2",children:h?"Processing...":n?e.jsxs(e.Fragment,{children:[e.jsx(Js,{size:15})," Subscribe — ",b]}):e.jsxs(e.Fragment,{children:[e.jsx(PS,{size:15})," Sign in to subscribe"]})}),e.jsx("button",{type:"button",onClick:()=>s(!1),className:"w-full mt-2 text-xs text-text-4 hover:text-text-2 transition-colors cursor-pointer py-1",children:"Maybe later"})]})})})}function Lee(){const t=k(l=>l.dataSharingModalOpen),s=k(l=>l.setTrainingOptIn),n=k(l=>l.dismissDataSharingModal),[a,r]=p.useState(!1);return e.jsx(Vt,{open:t,children:e.jsxs(Kt,{className:"max-w-md",description:"Help improve Groove by sharing usage data",onInteractOutside:l=>l.preventDefault(),onEscapeKeyDown:l=>l.preventDefault(),children:[e.jsxs("div",{className:"relative bg-gradient-to-br from-accent/5 to-transparent px-6 pt-8 pb-6 text-center",children:[e.jsx("div",{className:"flex justify-center mb-3",children:e.jsx("div",{className:"w-14 h-14 rounded-xl bg-accent/10 flex items-center justify-center",children:e.jsx(Js,{size:32,className:"text-accent"})})}),e.jsx(nm,{className:"text-xl font-bold text-text-0 font-sans",children:"Help Build a Better Groove"}),e.jsx("p",{className:"text-sm text-text-2 font-sans mt-2 max-w-md mx-auto",children:"We collect errors and usage reports to improve the quality of Groove for everyone."})]}),e.jsx("div",{className:"px-6 pt-4",children:e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2/30 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx(vn,{size:14,className:"text-text-2"}),e.jsx("span",{className:"text-xs font-semibold uppercase text-text-3 tracking-wider font-sans",children:"What We Never Collect"})]}),e.jsx("div",{className:"space-y-1.5",children:["Your source code or file contents","API keys, passwords, or credentials","Personal information — emails, names, file paths","Anything that could identify you, your IP or projects"].map(l=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{size:12,className:"text-danger flex-shrink-0"}),e.jsx("span",{className:"text-xs text-text-1 font-sans",children:l})]},l))}),e.jsx("p",{className:"text-xs text-text-0 font-sans font-medium mt-3",children:"PII is automatically scrubbed before any data leaves your machine."})]})}),e.jsxs("div",{className:"border-t border-border-subtle mt-5 pt-4 pb-1 px-6",children:[e.jsxs("button",{type:"button",onClick:()=>s(!0),className:"w-full h-10 rounded-lg bg-accent text-white font-semibold text-sm hover:bg-accent/90 transition-colors cursor-pointer flex items-center justify-center gap-2",children:[e.jsx(Js,{size:15}),"Turn On Sharing"]}),e.jsx("div",{className:"text-center mt-2.5",children:e.jsx("button",{type:"button",onClick:()=>n(a),className:"text-xs text-text-3 hover:text-text-1 transition-colors font-sans cursor-pointer",children:"Maybe Later"})}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[e.jsx("input",{type:"checkbox",id:"data-sharing-dismiss",checked:a,onChange:l=>r(l.target.checked),className:"w-3.5 h-3.5 rounded border-border accent-accent cursor-pointer"}),e.jsx("label",{htmlFor:"data-sharing-dismiss",className:"text-2xs text-text-3 font-sans cursor-pointer select-none",children:"Don't show this again"})]}),e.jsx("p",{className:"text-center text-2xs text-text-4 font-sans mt-2 mb-1",children:"You can always enable this later in Settings"})]})]})})}function Hee(){const t=k(P=>P.recentProjects),s=k(P=>P.setProjectDir),n=k(P=>P.removeRecentProject),a=k(P=>P.remoteHomedir),r=k(P=>P.savedTunnels),l=k(P=>P.fetchTunnels),c=k(P=>P.deleteTunnel),A=k(P=>P.connectTunnel),f=k(P=>P.disconnectTunnel),x=k(P=>P.toggleQuickConnect),h=k(P=>P.addToast),g=k(P=>P.tunnelConnectStep),[O,b]=p.useState(!1),[v,y]=p.useState(null);p.useEffect(()=>{l()},[l]);const S=(t||[]).slice(0,8),j=S.length>0,N=r.length>0,C=j||N;async function U(P){var T,B;if(P.active){(B=(T=window.groove)==null?void 0:T.remote)!=null&&B.openWindow?window.groove.remote.openWindow(P.localPort,P.name):window.open(`http://localhost:${P.localPort}?instance=${encodeURIComponent(P.name)}`,"_blank");return}y(P.id);try{await A(P.id)}catch(F){const M=(F==null?void 0:F.message)||"Unknown error";/permission|EACCES|sudo|Node\.js is not installed|npm install failed|write access/i.test(M)?(x(),h("warning","Remote setup needed","Follow the instructions to set up the remote server.")):h("error","Connection failed",M)}y(null)}return e.jsxs("div",{className:"fixed inset-0 z-50 overflow-y-auto welcome-bg",children:[e.jsx("div",{className:"pointer-events-none fixed top-0 left-1/2 -translate-x-1/2 w-[800px] h-[600px] rounded-full bg-accent/[0.03] blur-[120px]"}),e.jsxs("div",{className:"relative min-h-screen flex flex-col items-center px-8 pt-[14vh] pb-12 max-sm:pt-[8vh] max-sm:px-5",children:[e.jsxs("div",{className:"flex flex-col items-center text-center mb-14",children:[e.jsxs("div",{className:"relative mb-8",children:[e.jsx("div",{className:"absolute -inset-10 rounded-full bg-accent/[0.06] blur-3xl animate-welcome-breathe"}),e.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/25 animate-welcome-ring"}),e.jsx("div",{className:"absolute -inset-4 rounded-full border border-accent/15 animate-welcome-ring-delayed"}),e.jsx("div",{className:"relative w-[88px] h-[88px] rounded-full bg-accent/[0.07] border border-accent/20 flex items-center justify-center welcome-logo-shadow",children:e.jsx("img",{src:"/favicon.png",className:"w-12 h-12 rounded-full",alt:"Groove"})})]}),e.jsx("h1",{className:"text-4xl font-bold text-text-0 tracking-tight mb-3 font-sans max-sm:text-3xl",children:"Welcome to Groove"}),e.jsxs("p",{className:"text-base text-text-2 font-sans max-w-md leading-relaxed max-sm:text-sm",children:["The most powerful agenticOS ever built.",e.jsx("br",{className:"max-sm:hidden"}),e.jsx("span",{className:"max-sm:hidden",children:" "}),"Spawn fast. Stay aware. Never lose context."]})]}),e.jsxs("div",{className:"w-full max-w-2xl grid grid-cols-2 gap-4 mb-14 max-sm:grid-cols-1 max-sm:max-w-sm",children:[e.jsxs("button",{onClick:()=>b(!0),className:"group relative overflow-hidden rounded-xl border border-accent/20 bg-gradient-to-br from-accent/[0.08] via-accent/[0.03] to-transparent p-6 text-left hover:border-accent/40 hover:from-accent/[0.14] hover:via-accent/[0.06] transition-all duration-300 cursor-pointer",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/15 border border-accent/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300",children:e.jsx(Ys,{size:24,className:"text-accent"})}),e.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Open Project"}),e.jsx("div",{className:"text-sm text-text-2 font-sans",children:"Browse the filesystem to pick a project"}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-accent font-sans mt-4 opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:["Browse files ",e.jsx(Mo,{size:12})]})]}),e.jsxs("button",{onClick:x,className:"group relative overflow-hidden rounded-xl border border-border bg-surface-1 p-6 text-left hover:border-accent/30 hover:bg-surface-2 transition-all duration-300 cursor-pointer",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-surface-4 border border-border-subtle flex items-center justify-center mb-4 group-hover:scale-110 group-hover:bg-accent/10 group-hover:border-accent/20 transition-all duration-300",children:e.jsx(Ui,{size:24,className:"text-text-2 group-hover:text-accent transition-colors duration-300"})}),e.jsx("div",{className:"text-lg font-semibold text-text-0 font-sans mb-1",children:"Connect to Remote"}),e.jsx("div",{className:"text-sm text-text-2 font-sans",children:"SSH tunnel to a server running Groove"}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-accent font-sans mt-4 opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:["Setup connection ",e.jsx(Mo,{size:12})]})]})]}),C&&e.jsxs("div",{className:Z("w-full max-w-4xl gap-6 mb-14 max-sm:flex max-sm:flex-col max-sm:gap-6",j&&N?"grid grid-cols-2":"flex justify-center"),children:[j&&e.jsxs("div",{className:Z(!N&&"w-full max-w-lg"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Dn,{size:13,className:"text-text-3"}),e.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Recent Projects"})]}),e.jsx("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:S.map(P=>e.jsxs("div",{className:"group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-surface-3 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/10 transition-colors",children:e.jsx(Ys,{size:14,className:"text-text-3 group-hover:text-accent transition-colors"})}),e.jsxs("button",{onClick:()=>s(P.path),className:"flex-1 min-w-0 text-left cursor-pointer",children:[e.jsx("div",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:P.name}),e.jsx("div",{className:"text-2xs font-mono text-text-4 truncate",children:P.path})]}),e.jsx("button",{onClick:T=>{T.stopPropagation(),n(P.path)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all flex-shrink-0",title:"Remove from recent",children:e.jsx(qe,{size:14})})]},P.path))})]}),N&&e.jsxs("div",{className:Z(!j&&"w-full max-w-lg"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ns,{size:13,className:"text-text-3"}),e.jsx("h2",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"SSH Connections"})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-1/50 overflow-hidden divide-y divide-border-subtle",children:[r.map(P=>e.jsxs("div",{className:Z("group flex items-center gap-3 px-4 py-3 hover:bg-surface-2/50 transition-colors",v===P.id&&"opacity-60 pointer-events-none"),children:[e.jsx("div",{className:Z("w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 transition-colors",P.active?"bg-success/10":"bg-surface-3 group-hover:bg-accent/10"),children:e.jsx(Ns,{size:14,className:Z("transition-colors",P.active?"text-success":"text-text-3 group-hover:text-accent")})}),e.jsxs("button",{onClick:()=>U(P),disabled:v===P.id,className:"flex-1 min-w-0 text-left cursor-pointer",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium text-text-1 group-hover:text-accent truncate transition-colors font-sans",children:P.name}),P.active&&e.jsx(Gt,{status:"running",size:"sm"})]}),e.jsxs("div",{className:"text-2xs font-mono text-text-4 truncate",children:[P.user,"@",P.host]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[v===P.id?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(De,{size:14,className:"text-text-3 animate-spin"}),(g==null?void 0:g.id)===P.id&&(g==null?void 0:g.step)&&e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:{testing:"Testing…",installing:"Installing…",checking:"Checking for updates…",upgrading:"Updating remote…",starting:"Starting daemon…",connecting:"Connecting…",forwarding:"Establishing tunnel…"}[g.step]||g.step})]}):P.active?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>U(P),className:"opacity-0 group-hover:opacity-100 flex items-center gap-0.5 text-2xs text-success hover:text-success/80 cursor-pointer transition-all font-sans",children:[e.jsx(Ws,{size:11})," Open"]}),e.jsx("button",{onClick:async()=>{await f(P.id),h("info","Disconnected",P.name)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all",title:"Disconnect",children:e.jsx(Yx,{size:12})})]}):null,e.jsx("button",{onClick:T=>{T.stopPropagation(),c(P.id)},className:"opacity-0 group-hover:opacity-100 p-1 text-text-4 hover:text-danger cursor-pointer transition-all flex-shrink-0",title:"Remove connection",children:e.jsx(qe,{size:14})})]})]},P.id)),e.jsxs("button",{onClick:x,className:"flex items-center gap-1.5 text-2xs text-accent hover:text-accent/80 font-sans font-medium cursor-pointer transition-colors w-full px-4 py-2.5 hover:bg-surface-2/30",children:[e.jsx(it,{size:11})," Add Connection"]})]})]})]}),e.jsx("div",{className:"mt-auto pt-8 flex flex-col items-center gap-4",children:e.jsxs("div",{className:"flex items-center gap-5 text-xs text-text-4 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘K"}),e.jsx("span",{children:"palette"})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘N"}),e.jsx("span",{children:"spawn"})]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("kbd",{className:"font-mono bg-surface-4 px-1.5 py-0.5 rounded text-text-3 text-2xs",children:"⌘J"}),e.jsx("span",{children:"terminal"})]})]})})]}),e.jsx(gc,{open:O,onOpenChange:b,currentPath:a||"/home",homePath:a,onSelect:P=>{b(!1),s(P)}}),e.jsx(NC,{}),e.jsx(ZS,{})]})}const Xee={js:"text-text-2",jsx:"text-text-2",ts:"text-text-2",tsx:"text-text-2",css:"text-text-3",html:"text-text-3",json:"text-text-3",md:"text-text-3",py:"text-text-2",rs:"text-text-3",go:"text-text-2",sh:"text-text-3",yaml:"text-text-3",yml:"text-text-3",sql:"text-text-3",xml:"text-text-3",svg:"text-text-3"};function Gee(t){var n;const s=(n=t.split(".").pop())==null?void 0:n.toLowerCase();return Xee[s]||"text-text-3"}function Zee({x:t,y:s,items:n,onClose:a}){const r=p.useRef(null);return p.useEffect(()=>{function l(c){r.current&&!r.current.contains(c.target)&&a()}return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[a]),e.jsx("div",{ref:r,className:"fixed z-50 min-w-[160px] py-1 bg-surface-2 border border-border rounded-lg shadow-xl",style:{left:t,top:s},children:n.map((l,c)=>l.separator?e.jsx("div",{className:"h-px bg-border-subtle my-1"},c):e.jsxs("button",{onClick:()=>{l.action(),a()},className:Z("w-full flex items-center gap-2.5 px-3 py-1.5 text-xs font-sans text-left cursor-pointer transition-colors",l.danger?"text-danger hover:bg-danger/10":"text-text-1 hover:bg-surface-5"),children:[l.icon&&e.jsx(l.icon,{size:12,className:l.danger?"text-danger":"text-text-3"}),l.label]},c))})}function Tx({defaultValue:t="",placeholder:s,onSubmit:n,onCancel:a,depth:r=0}){const[l,c]=p.useState(t),A=p.useRef(null);p.useEffect(()=>{var x,h;(x=A.current)==null||x.focus(),t&&((h=A.current)==null||h.select())},[t]);function f(x){if(x.key==="Enter"){const h=l.trim();h&&n(h)}x.key==="Escape"&&a()}return e.jsx("div",{className:"flex items-center py-0.5",style:{paddingLeft:r*16+8},children:e.jsx("input",{ref:A,value:l,onChange:x=>c(x.target.value),onKeyDown:f,onBlur:a,placeholder:s,className:"w-full h-5 px-1.5 text-xs bg-surface-0 border border-accent rounded text-text-0 font-sans focus:outline-none"})})}function Vee({status:t}){if(!t)return null;const s=t==="A"||t==="?"?"bg-success":t==="D"?"bg-danger":"bg-warning";return e.jsx("span",{className:Z("w-1.5 h-1.5 rounded-full flex-shrink-0",s)})}function Kee(t,s){const n=document.createElement("a");n.href=`/api/files/download?path=${encodeURIComponent(t)}`,n.download=s?`${t.split("/").pop()}.zip`:t.split("/").pop(),document.body.appendChild(n),n.click(),n.remove()}function E4({entry:t,depth:s=0,activePath:n,onFileClick:a,onDirToggle:r,expanded:l,onContextMenu:c,dragState:A,onDragStartEntry:f,onDragEndEntry:x,onSetDragOver:h,onDropOnDir:g,gitStatusMap:O}){const b=t.type==="dir",v=n===t.path,y=l.has(t.path),S=s*16+8,j=(A==null?void 0:A.draggingPath)===t.path,N=b&&(A==null?void 0:A.dragOverPath)===t.path,C=b?null:O==null?void 0:O[t.path];function U(P){P.preventDefault(),P.stopPropagation(),c(P,t)}return e.jsxs("button",{draggable:!0,onDragStart:P=>{P.dataTransfer.setData("application/json",JSON.stringify({path:t.path,name:t.name,type:t.type})),P.dataTransfer.effectAllowed="move",f(t.path)},onDragEnd:x,onDragOver:P=>{P.preventDefault(),b&&(P.stopPropagation(),h(t.path))},onDrop:P=>g(b?t.path:t.path.includes("/")?t.path.split("/").slice(0,-1).join("/"):"",P),onClick:()=>b?r(t.path):a(t.path),onDoubleClick:U,onContextMenu:U,className:Z("w-full flex items-center gap-1.5 py-[3px] text-xs font-sans cursor-pointer","hover:bg-surface-5 transition-colors text-left select-none",v&&"bg-accent/10 text-text-0",!v&&"text-text-1",j&&"opacity-50",N&&"bg-accent/15 ring-1 ring-accent/50 rounded"),style:{paddingLeft:S},children:[b?e.jsxs(e.Fragment,{children:[y?e.jsx(xt,{size:12,className:"text-text-4 flex-shrink-0"}):e.jsx(Tt,{size:12,className:"text-text-4 flex-shrink-0"}),y?e.jsx(Ys,{size:14,className:"text-accent flex-shrink-0"}):e.jsx(Li,{size:14,className:"text-text-3 flex-shrink-0"})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-3"}),e.jsx(Lo,{size:14,className:Z("flex-shrink-0",Gee(t.name))})]}),e.jsx("span",{className:"truncate flex-1",children:t.name}),C&&e.jsx(Vee,{status:C})]})}function P4({dirPath:t,depth:s,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:x,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y}){const S=c[t]||[];return p.useEffect(()=>{r.has(t)&&!c[t]&&A(t)},[r,t,c,A]),r.has(t)?e.jsxs(e.Fragment,{children:[(x==null?void 0:x.parentPath)===t&&e.jsx(Tx,{placeholder:x.type==="file"?"filename.ext":"folder-name",onSubmit:x.onSubmit,onCancel:x.onCancel,depth:s}),S.map(j=>e.jsxs("div",{children:[(x==null?void 0:x.renamePath)===j.path?e.jsx(Tx,{defaultValue:j.name,onSubmit:x.onSubmit,onCancel:x.onCancel,depth:s}):e.jsx(E4,{entry:j,depth:s,activePath:n,onFileClick:a,onDirToggle:l,expanded:r,onContextMenu:f,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y}),j.type==="dir"&&e.jsx(P4,{dirPath:j.path,depth:s+1,activePath:n,onFileClick:a,expanded:r,onDirToggle:l,treeCache:c,fetchTreeDir:A,onContextMenu:f,inlineInput:x,dragState:h,onDragStartEntry:g,onDragEndEntry:O,onSetDragOver:b,onDropOnDir:v,gitStatusMap:y})]},j.path))]}):null}function qee({rootDir:t,onCollapse:s}){const n=k(L=>L.editorTreeCache),a=k(L=>L.editorActiveFile),r=k(L=>L.openFile),l=k(L=>L.fetchTreeDir),c=k(L=>L.addToast),[A,f]=p.useState(new Set([""])),[x,h]=p.useState(""),[g,O]=p.useState(null),[b,v]=p.useState(null),[y,S]=p.useState({draggingPath:null,dragOverPath:null}),[j,N]=p.useState([]);p.useEffect(()=>{l("")},[l,t]),p.useEffect(()=>{G.get("/files/git-status").then(L=>{N(L.entries||[])}).catch(()=>N([]))},[t]);const C={};for(const L of j)C[L.path]=L.status;function U(L){f(J=>{const D=new Set(J);return D.has(L)?D.delete(L):D.add(L),D})}function P(){f(new Set([""]))}function T(L){S({draggingPath:L,dragOverPath:null})}function B(){S({draggingPath:null,dragOverPath:null})}function F(L){S(J=>J.dragOverPath===L?J:{...J,dragOverPath:L})}async function M(L,J){var V,te;if(J.preventDefault(),J.stopPropagation(),S({draggingPath:null,dragOverPath:null}),((te=(V=J.dataTransfer)==null?void 0:V.files)==null?void 0:te.length)>0){q(L,Array.from(J.dataTransfer.files));return}let D;try{D=JSON.parse(J.dataTransfer.getData("application/json"))}catch{return}if(!(D!=null&&D.path))return;if(D.type==="dir"&&(L===D.path||L.startsWith(D.path+"/"))){c("error","Cannot move a folder into itself");return}const se=W(D.path);if(se===L)return;const le=L?`${L}/${D.name}`:D.name;try{await G.post("/files/rename",{oldPath:D.path,newPath:le}),l(se),l(L),c("success",`Moved ${D.name} to ${L||"/"}`)}catch(ae){c("error","Move failed",ae.message)}}function R(L,J){O({x:L.clientX,y:L.clientY,entry:J})}function Y(L){L.preventDefault(),O({x:L.clientX,y:L.clientY,entry:{type:"dir",path:"",name:"root"}})}function W(L){const J=L.split("/");return J.pop(),J.join("/")}async function ee(L){f(J=>new Set([...J,L])),v({type:"file",parentPath:L,onSubmit:async J=>{const D=L?`${L}/${J}`:J;try{await G.post("/files/create",{path:D,content:""}),l(L),r(D),c("success",`Created ${J}`)}catch(se){c("error","Create failed",se.message)}v(null)},onCancel:()=>v(null)})}async function K(L){f(J=>new Set([...J,L])),v({type:"folder",parentPath:L,onSubmit:async J=>{const D=L?`${L}/${J}`:J;try{await G.post("/files/mkdir",{path:D}),l(L),f(se=>new Set([...se,D])),c("success",`Created ${J}/`)}catch(se){c("error","Create folder failed",se.message)}v(null)},onCancel:()=>v(null)})}async function _(L){v({type:"rename",renamePath:L.path,onSubmit:async J=>{const D=W(L.path),se=D?`${D}/${J}`:J;try{await G.post("/files/rename",{oldPath:L.path,newPath:se}),l(D),c("success",`Renamed to ${J}`)}catch(le){c("error","Rename failed",le.message)}v(null)},onCancel:()=>v(null)})}async function E(L){const J=L.type==="dir"?`folder "${L.name}" and all contents`:`"${L.name}"`;if(window.confirm(`Delete ${J}?`))try{await G.delete(`/files/delete?path=${encodeURIComponent(L.path)}`),l(W(L.path)),c("success",`Deleted ${L.name}`)}catch(D){c("error","Delete failed",D.message)}}async function q(L,J){const D=[];for(const se of J){const le=await new Promise((V,te)=>{const ae=new FileReader;ae.onload=()=>V(ae.result.split(",")[1]),ae.onerror=te,ae.readAsDataURL(se)});D.push({name:se.name,content:le})}try{const se=await G.post("/files/upload",{dir:L,files:D});c("success",`Uploaded ${se.total} file${se.total!==1?"s":""}`),l(L)}catch(se){c("error","Upload failed",se.message)}}function H(L){const J=L.type==="dir",D=[];return J&&(D.push({icon:Vl,label:"New File",action:()=>ee(L.path)}),D.push({icon:RA,label:"New Folder",action:()=>K(L.path)})),L.name!=="root"?(D.push({icon:qs,label:J?"Download as ZIP":"Download",action:()=>Kee(L.path,J)}),D.length>0&&D.push({separator:!0}),D.push({icon:Ua,label:"Rename",action:()=>_(L)}),D.push({icon:Ft,label:"Delete",danger:!0,action:()=>E(L)})):(D.length=0,D.push({icon:Vl,label:"New File",action:()=>ee("")}),D.push({icon:RA,label:"New Folder",action:()=>K("")})),D}const I=n[""]||[];return e.jsxs("div",{className:"flex flex-col h-full bg-surface-1",onContextMenu:Y,children:[e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-border-subtle",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(As,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:x,onChange:L=>h(L.target.value),placeholder:"Filter...",className:"w-full h-6 pl-6 pr-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-1 placeholder:text-text-4 focus:outline-none focus:border-accent font-sans"})]}),e.jsx("button",{onClick:()=>ee(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New file",children:e.jsx(Vl,{size:12})}),e.jsx("button",{onClick:()=>K(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"New folder",children:e.jsx(RA,{size:12})}),e.jsx("button",{onClick:()=>l(""),className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Refresh",children:e.jsx(Ls,{size:12})}),e.jsx("button",{onClick:P,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse all",children:e.jsx(wS,{size:12})}),s&&e.jsx("button",{onClick:s,className:"p-1 text-text-4 hover:text-text-1 transition-colors cursor-pointer",title:"Collapse sidebar",children:e.jsx(Vx,{size:12})})]}),e.jsx(Qt,{className:"flex-1",children:e.jsxs("div",{className:"py-1 min-h-full",onDragOver:L=>{L.preventDefault(),y.draggingPath&&F(null)},onDrop:L=>M("",L),children:[(b==null?void 0:b.parentPath)===""&&e.jsx(Tx,{placeholder:b.type==="file"?"filename.ext":"folder-name",onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}),I.filter(L=>!x||L.name.toLowerCase().includes(x.toLowerCase())).map(L=>e.jsxs("div",{children:[(b==null?void 0:b.renamePath)===L.path?e.jsx(Tx,{defaultValue:L.name,onSubmit:b.onSubmit,onCancel:b.onCancel,depth:0}):e.jsx(E4,{entry:L,depth:0,activePath:a,onFileClick:r,onDirToggle:U,expanded:A,onContextMenu:R,dragState:y,onDragStartEntry:T,onDragEndEntry:B,onSetDragOver:F,onDropOnDir:M,gitStatusMap:C}),L.type==="dir"&&e.jsx(P4,{dirPath:L.path,depth:1,activePath:a,onFileClick:r,expanded:A,onDirToggle:U,treeCache:n,fetchTreeDir:l,onContextMenu:R,inlineInput:b,dragState:y,onDragStartEntry:T,onDragEndEntry:B,onSetDragOver:F,onDropOnDir:M,gitStatusMap:C})]},L.path)),I.length===0&&!x&&e.jsxs("div",{className:"px-3 py-6 text-center",children:[e.jsx("p",{className:"text-xs text-text-4",children:"No files found"}),e.jsx("button",{onClick:()=>l(""),className:"mt-2 text-xs text-accent hover:underline cursor-pointer",children:"Retry"})]})]})}),g&&e.jsx(Zee,{x:g.x,y:g.y,items:H(g.entry),onClose:()=>O(null)})]})}function Wee(){const t=k(y=>y.editorOpenTabs),s=k(y=>y.editorActiveFile),n=k(y=>y.editorFiles),a=k(y=>y.setActiveFile),r=k(y=>y.closeFile),l=p.useRef(null),[c,A]=p.useState(!1),f=p.useCallback(()=>{const y=l.current;y&&A(y.scrollWidth>y.clientWidth)},[]);p.useEffect(()=>{f();const y=l.current;if(!y)return;const S=new ResizeObserver(f);return S.observe(y),()=>S.disconnect()},[f,t.length]);function x(){var y;(y=l.current)==null||y.scrollBy({left:-120,behavior:"smooth"})}function h(){var y;(y=l.current)==null||y.scrollBy({left:120,behavior:"smooth"})}function g(y){t.filter(S=>S!==y).forEach(S=>r(S))}function O(){[...t].forEach(y=>r(y))}function b(y){const S=t.indexOf(y);t.slice(S+1).forEach(j=>r(j))}function v(y){var S;(S=navigator.clipboard)==null||S.writeText(y)}return t.length===0?null:e.jsxs("div",{className:"flex items-stretch h-9 bg-surface-3 border-b border-border-subtle flex-shrink-0",children:[c&&e.jsx("button",{onClick:x,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:e.jsx(Di,{size:14})}),e.jsx("div",{ref:l,className:"flex items-stretch flex-1 min-w-0 overflow-x-auto scrollbar-none scroll-smooth",style:{scrollSnapType:"x mandatory"},children:t.map(y=>{const S=y===s,j=n[y],N=j&&j.content!==j.originalContent,C=y.split("/").pop();return e.jsxs(Uv,{children:[e.jsx(Ev,{asChild:!0,children:e.jsxs("div",{className:Z("flex items-center gap-1.5 px-3 text-xs font-sans cursor-pointer select-none","border-r border-white/5","transition-colors duration-75 flex-shrink-0",S?"bg-surface-0 text-text-0 border-b border-b-accent":"bg-surface-3 text-text-4 hover:text-text-1 hover:bg-surface-4 border-b border-b-transparent"),style:{scrollSnapAlign:"start"},onClick:()=>a(y),onAuxClick:U=>{U.button===1&&(U.preventDefault(),r(y))},children:[e.jsx("span",{className:"truncate max-w-[120px]",children:C}),N&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-warning flex-shrink-0"}),e.jsx("button",{onClick:U=>{U.stopPropagation(),r(y)},className:"p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 transition-colors cursor-pointer ml-0.5",children:e.jsx(qe,{size:12})})]})}),e.jsxs(Pv,{children:[e.jsxs(ya,{onSelect:()=>r(y),children:[e.jsx(qe,{size:12,className:"text-text-3"})," Close"]}),e.jsxs(ya,{onSelect:()=>g(y),children:[e.jsx(AO,{size:12,className:"text-text-3"})," Close Others"]}),e.jsxs(ya,{onSelect:()=>O(),children:[e.jsx(AO,{size:12,className:"text-text-3"})," Close All"]}),e.jsxs(ya,{onSelect:()=>b(y),children:[e.jsx(Tt,{size:12,className:"text-text-3"})," Close to the Right"]}),e.jsx(Fv,{}),e.jsxs(ya,{onSelect:()=>v(y),children:[e.jsx(Ba,{size:12,className:"text-text-3"})," Copy Path"]})]})]},y)})}),c&&e.jsx("button",{onClick:h,className:"flex-shrink-0 px-1 h-full text-text-4 hover:text-text-1 hover:bg-surface-4 transition-colors cursor-pointer",children:e.jsx(Tt,{size:14})})]})}const Yee={javascript:"JavaScript",typescript:"TypeScript",css:"CSS",html:"HTML",json:"JSON",markdown:"Markdown",python:"Python"},F4=Object.keys(Po),$4=F4.filter(t=>!["githubLight","vscodeLight","eclipse","xcodeLight","solarizedLight","gruvboxLight","materialLight","duotoneLight","quietlight","bbedit","tokyoNightDay","basicLight"].includes(t)),Jee=F4.filter(t=>!$4.includes(t));function ete({cursorPos:t,language:s}){var A;const n=k(f=>f.editorTheme),a=k(f=>f.setEditorTheme),[r,l]=p.useState(!1),c=p.useRef(null);return p.useEffect(()=>{if(!r)return;function f(x){c.current&&!c.current.contains(x.target)&&l(!1)}return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[r]),e.jsxs("div",{className:"flex items-center justify-between h-6 px-3 bg-surface-1 border-t border-border-subtle text-2xs font-sans text-text-3 flex-shrink-0 select-none",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("span",{children:["Ln ",t.line,", Col ",t.col]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",ref:c,children:[e.jsxs("button",{onClick:()=>l(!r),className:"flex items-center gap-1.5 hover:text-text-0 transition-colors cursor-pointer",children:[e.jsx(YM,{size:10}),e.jsx("span",{children:((A=Po[n])==null?void 0:A.label)||n})]}),r&&e.jsxs("div",{className:"absolute bottom-6 right-0 w-48 max-h-72 overflow-y-auto rounded-md border border-border bg-surface-2 shadow-xl z-50 py-1 scrollbar-thin",children:[e.jsx("div",{className:"px-2 py-1 text-2xs text-text-4 font-semibold uppercase tracking-wider",children:"Dark"}),$4.map(f=>e.jsx("button",{onClick:()=>{a(f),l(!1)},className:Z("w-full text-left px-3 py-1 text-2xs font-sans cursor-pointer transition-colors",f===n?"text-accent bg-accent/10":"text-text-1 hover:bg-surface-4"),children:Po[f].label},f)),e.jsx("div",{className:"px-2 py-1 mt-1 text-2xs text-text-4 font-semibold uppercase tracking-wider border-t border-border-subtle",children:"Light"}),Jee.map(f=>e.jsx("button",{onClick:()=>{a(f),l(!1)},className:Z("w-full text-left px-3 py-1 text-2xs font-sans cursor-pointer transition-colors",f===n?"text-accent bg-accent/10":"text-text-1 hover:bg-surface-4"),children:Po[f].label},f))]})]}),e.jsx("span",{className:"cursor-default",children:Yee[s]||s||"Plain Text"}),e.jsx("span",{children:"Spaces: 2"}),e.jsx("span",{children:"UTF-8"})]})]})}function tte({currentLine:t,onGoto:s,onClose:n}){const[a,r]=p.useState(""),l=p.useRef(null);p.useEffect(()=>{var A;(A=l.current)==null||A.focus()},[]);function c(A){if(A.key==="Enter"){const f=parseInt(a,10);f>0&&s(f),n()}A.key==="Escape"&&n()}return e.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20 flex items-center gap-2 bg-surface-2 border border-border rounded-lg shadow-xl p-2",children:[e.jsx("label",{className:"text-2xs font-sans text-text-3 whitespace-nowrap",children:"Go to Line:"}),e.jsx("input",{ref:l,value:a,onChange:A=>r(A.target.value),onKeyDown:c,onBlur:n,placeholder:String(t),className:"w-20 h-6 px-2 text-xs bg-surface-0 border border-border-subtle rounded text-text-0 font-mono focus:outline-none focus:border-accent"})]})}function ste({path:t}){if(!t)return null;const s=t.split("/").filter(Boolean);return e.jsx("div",{className:"flex items-center h-7 px-3 bg-surface-2 border-b border-border-subtle text-2xs font-sans text-text-3 overflow-hidden flex-shrink-0 select-none",children:s.map((n,a)=>{const r=a===s.length-1;return e.jsxs("span",{className:"flex items-center min-w-0",children:[a>0&&e.jsx(Tt,{size:10,className:"mx-0.5 flex-shrink-0 text-text-4"}),e.jsx("span",{className:r?"text-text-1 font-medium truncate":"hover:text-text-1 cursor-pointer truncate transition-colors",children:n})]},a)})})}function nte(t){var n;const s=(n=t==null?void 0:t.split(".").pop())==null?void 0:n.toLowerCase();return s==="html"||s==="htm"}const ate=240,rte=160,ote=400;function ite(){const t=k(J=>J.editorActiveFile),s=k(J=>J.editorFiles),n=k(J=>J.updateFileContent),a=k(J=>J.saveFile),r=k(J=>J.editorSidebarWidth),l=k(J=>J.setEditorSidebarWidth),c=k(J=>J.projectDir),[A,f]=p.useState(""),[x,h]=p.useState(!1),[g,O]=p.useState(0),[b,v]=p.useState({line:1,col:1}),[y,S]=p.useState(!1),[j,N]=p.useState(!1),[C,U]=p.useState(!1),P=p.useRef(0),T=k(J=>J.addToast),B=k(J=>J.fetchTreeDir),F=p.useRef(null),M=p.useRef(!1),R=p.useRef(0),Y=p.useRef(0);p.useEffect(()=>{G.get("/files/root").then(J=>f(J.root||"")).catch(()=>{})},[c]),p.useEffect(()=>{h(!1)},[t]),p.useEffect(()=>{function J(D){(D.metaKey||D.ctrlKey)&&D.key==="g"&&(D.preventDefault(),S(!0))}return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[]);function W(J){var D,se;J.preventDefault(),P.current++,(se=(D=J.dataTransfer)==null?void 0:D.types)!=null&&se.includes("Files")&&U(!0)}function ee(J){J.preventDefault(),P.current--,P.current<=0&&(P.current=0,U(!1))}function K(J){J.preventDefault(),J.dataTransfer.dropEffect="copy"}async function _(J){var le;J.preventDefault(),P.current=0,U(!1);const D=(le=J.dataTransfer)==null?void 0:le.files;if(!(D!=null&&D.length))return;const se=[];for(const V of Array.from(D)){const te=await new Promise((ae,be)=>{const z=new FileReader;z.onload=()=>ae(z.result.split(",")[1]),z.onerror=be,z.readAsDataURL(V)});se.push({name:V.name,content:te})}try{const V=await G.post("/files/upload",{dir:"",files:se});T("success",`Uploaded ${V.total} file${V.total!==1?"s":""}`),B("")}catch(V){T("error","Upload failed",V.message)}}const E=p.useCallback(J=>{J.preventDefault(),M.current=!0,R.current=J.clientX,Y.current=r;function D(le){if(!M.current)return;const V=le.clientX-R.current,te=Math.min(Math.max(Y.current+V,rte),ote);l(te)}function se(){M.current=!1,document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",se)}document.addEventListener("mousemove",D),document.addEventListener("mouseup",se)},[r,l]);function q(J){const D=F.current;if(!D)return;const se=D.state.doc.line(Math.min(J,D.state.doc.lines));D.dispatch({selection:{anchor:se.from},scrollIntoView:!0}),D.focus()}const H=t?s[t]:null,I=t&&g5(t),L=t&&nte(t);return e.jsxs("div",{className:"flex h-full",children:[e.jsxs("div",{className:Z("relative flex-shrink-0 border-r border-border transition-all duration-200 overflow-hidden",j&&"w-0 border-r-0"),style:j?void 0:{width:r},children:[e.jsx(qee,{rootDir:A,onCollapse:()=>N(!0)}),e.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:E,onDoubleClick:()=>l(ate)})]}),j&&e.jsx("button",{onClick:()=>N(!1),className:"flex-shrink-0 w-6 flex items-start justify-center pt-2 border-r border-border bg-surface-2 text-text-4 hover:text-text-0 hover:bg-surface-3 transition-colors cursor-pointer",title:"Show sidebar",children:e.jsx(Kx,{size:14})}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 bg-surface-1 relative",onDragEnter:W,onDragLeave:ee,onDragOver:K,onDrop:_,children:[C&&e.jsx("div",{className:"absolute inset-0 z-50 bg-accent/8 border-2 border-dashed border-accent/40 rounded-lg flex items-center justify-center pointer-events-none",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 text-accent",children:[e.jsx(Hb,{size:32}),e.jsx("span",{className:"text-sm font-semibold font-sans",children:"Drop files to upload"})]})}),e.jsx(Wee,{}),t&&!I&&e.jsx(ste,{path:t}),e.jsxs("div",{className:"flex-1 relative min-h-0",children:[y&&e.jsx(tte,{currentLine:b.line,onGoto:q,onClose:()=>S(!1)}),!t&&e.jsx("div",{className:"w-full h-full flex items-center justify-center text-text-4 font-sans",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(bn,{size:32,className:"mx-auto"}),e.jsx("p",{className:"text-sm",children:"Open a file from the tree"})]})}),t&&I&&e.jsx(O5,{path:t}),t&&!I&&L&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"absolute top-0 right-4 z-10 flex items-center gap-0.5 mt-2 bg-surface-2 border border-border-subtle rounded-md p-0.5",children:[e.jsxs("button",{onClick:()=>h(!1),className:Z("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",x?"text-text-3 hover:text-text-1":"bg-surface-4 text-text-0 font-medium"),children:[e.jsx(Fb,{size:12})," Code"]}),e.jsxs("button",{onClick:()=>{h(!0),O(J=>J+1)},className:Z("flex items-center gap-1.5 px-2.5 py-1 text-xs font-sans rounded cursor-pointer transition-colors",x?"bg-surface-4 text-text-0 font-medium":"text-text-3 hover:text-text-1"),children:[e.jsx(Vs,{size:12})," Preview"]})]}),x?e.jsx("iframe",{src:`/api/files/raw?path=${encodeURIComponent(t)}`,className:"w-full h-full border-0",sandbox:"allow-scripts allow-same-origin",title:"HTML Preview"},g):H&&e.jsx(KO,{content:H.content,language:H.language,onChange:J=>n(t,J),onSave:()=>a(t),onCursorChange:v,viewRef:F})]}),t&&!I&&!L&&H&&e.jsx(KO,{content:H.content,language:H.language,onChange:J=>n(t,J),onSave:()=>a(t),onCursorChange:v,viewRef:F})]}),t&&!I&&e.jsx(ete,{cursorPos:b,language:H==null?void 0:H.language})]})]})}function lte(){var C;const t=k(U=>U.connected),s=k(U=>U.agents),[n,a]=p.useState(null),[r,l]=p.useState([]),[c,A]=p.useState({constraints:[],discoveries:[],roles:[],specializations:null}),[f,x]=p.useState(!0),[h,g]=p.useState({tokens:[],cost:[],saved:[],efficiency:[],cache:[],inputOutput:[],agents:[],turns:[]}),O=p.useRef(0);p.useEffect(()=>{if(!t)return;let U=!0;async function P(){try{const[B,F,M,R,Y,W]=await Promise.all([G.get("/dashboard"),G.get("/tokens/by-team").catch(()=>({teams:[]})),G.get("/memory/constraints").catch(()=>({constraints:[]})),G.get("/memory/discoveries?limit=20").catch(()=>({discoveries:[]})),G.get("/memory/handoff-chain").catch(()=>({roles:[]})),G.get("/memory/specializations").catch(()=>({perAgent:{},perProjectRole:{}}))]);if(!U)return;a(B),l((F==null?void 0:F.teams)||[]),A({constraints:(M==null?void 0:M.constraints)||[],discoveries:(R==null?void 0:R.discoveries)||[],roles:(Y==null?void 0:Y.roles)||[],specializations:W||{perAgent:{},perProjectRole:{}}}),x(!1),O.current=Date.now(),g(ee=>{var D,se,le,V,te,ae,be,z,oe;const K=Date.now(),_=(ue,ve)=>[...ue.slice(-59),{t:K,v:ve||0}],E=((D=B.tokens)==null?void 0:D.totalTokens)||0,q=((se=B.tokens)==null?void 0:se.totalInputTokens)||0,H=((le=B.tokens)==null?void 0:le.totalOutputTokens)||0,L=(((V=B.agents)==null?void 0:V.breakdown)||[]).filter(ue=>{var ve;return((ve=ue.quality)==null?void 0:ve.score)!=null}),J=L.length>0?L.reduce((ue,ve)=>ue+ve.quality.score,0)/L.length:0;return{tokens:_(ee.tokens,E),cost:_(ee.cost,(te=B.tokens)==null?void 0:te.totalCostUsd),saved:_(ee.saved,J),efficiency:_(ee.efficiency,((ae=B.rotation)==null?void 0:ae.totalRotations)||0),cache:_(ee.cache,(be=B.tokens)==null?void 0:be.cacheHitRate),inputOutput:_(ee.inputOutput,H>0?q/H:0),agents:_(ee.agents,((z=B.agents)==null?void 0:z.running)||0),turns:_(ee.turns,(oe=B.tokens)==null?void 0:oe.totalTurns)}})}catch{U&&x(!1)}}P();const T=setInterval(P,4e3);return()=>{U=!1,clearInterval(T)}},[t]);const b=((C=n==null?void 0:n.agents)==null?void 0:C.breakdown)||[],v=(n==null?void 0:n.routing)||null,y=(n==null?void 0:n.rotation)||null,S=(n==null?void 0:n.adaptive)||[],j=(n==null?void 0:n.journalist)||null,N=(y==null?void 0:y.rotating)||[];return{data:n,loading:f,agents:s,connected:t,kpiHistory:h,lastFetch:O.current,agentBreakdown:b,routing:v,rotation:y,adaptive:S,journalist:j,rotating:N,teamBurn:r,memory:c}}const CQ=p.memo(function({connected:s,runningCount:n,totalCount:a,uptime:r,lastFetch:l,activeTeam:c}){return e.jsxs("div",{className:"flex items-center gap-4 px-4 py-2 bg-surface-1 border-b border-border",children:[e.jsx("h2",{className:"text-xs font-semibold text-text-0 font-sans tracking-wide uppercase",children:"Command Center"}),c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-xs font-mono text-text-2",children:c.name})]}),e.jsx("div",{className:"flex-1"}),s&&e.jsxs("div",{className:"flex items-center gap-3.5 text-xs font-mono text-text-2",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-text-1",children:n}),e.jsxs("span",{className:"text-text-3",children:["/",a]}),e.jsx("span",{className:"ml-1 text-text-3",children:"agents"})]}),r>0&&e.jsxs("span",{className:"text-text-3",children:["Up ",Xo(r)]}),l>0&&e.jsxs("span",{className:"flex items-center gap-1 text-text-4",children:[e.jsx(Ls,{size:9}),e.jsx("span",{children:$t(l)})]})]}),e.jsx(Gt,{status:s?"running":"crashed",size:"sm"})]})});function nt(t,s){const n=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),r=parseInt(t.slice(5,7),16);return`rgba(${n},${a},${r},${s})`}const ce={surface0:"#1a1e25",surface3:"#282c34",surface4:"#2c313a",surface5:"#333842",text0:"#e6e6e6",text1:"#bcc2cd",text2:"#8b929e",text3:"#6e7681",text4:"#505862",accent:"#33afbc",success:"#4ae168",warning:"#e5c07b",danger:"#e06c75",info:"#61afef",purple:"#c678dd",orange:"#d19a66"};function cte({data:t,color:s=ce.text3,width:n=72,height:a=22}){if(!t||t.length<2)return e.jsx("div",{style:{width:n,height:a}});const r=t.map(h=>h.v),l=Math.min(...r),A=Math.max(...r)-l||1,f=t.map((h,g)=>{const O=g/(t.length-1)*n,b=a-(h.v-l)/A*(a-2)-1;return`${O},${b}`}).join(" "),x=`kpi-${s.replace("#","")}`;return e.jsxs("svg",{width:n,height:a,className:"flex-shrink-0",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:x,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:"0.2"}),e.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:"0"})]})}),e.jsx("polygon",{points:`0,${a} ${f} ${n},${a}`,fill:`url(#${x})`}),e.jsx("polyline",{points:f,fill:"none",stroke:s,strokeWidth:"1.5",strokeLinejoin:"round",strokeOpacity:"0.8"})]})}const Ate=p.memo(function({label:s,value:n,sparkData:a,color:r=ce.text3,hint:l,className:c}){return e.jsxs("div",{className:Z("flex items-center gap-2.5 px-3 py-2.5 min-w-0","bg-surface-1",c),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider mb-0.5 truncate flex items-center gap-1",children:[s,l&&e.jsx(dt,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:l}),side:"bottom",children:e.jsx(ki,{size:10,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors"})})]}),e.jsx("div",{className:"text-base font-semibold font-mono text-text-0 tabular-nums leading-none",children:n})]}),e.jsx(cte,{data:a,color:r})]})});function dte({kpis:t}){return e.jsx("div",{className:"flex flex-wrap border-b border-border bg-surface-0",children:t.map(s=>e.jsx(Ate,{label:s.label,value:s.value,sparkData:s.sparkData,color:s.color,hint:s.hint,className:Z("flex-1 basis-[12.5%] min-w-[140px]","border-b border-r border-border")},s.label))})}const ute={actual:"ACT",estimated:"EST",local:"LOC"};function fte(t){if(!t||t==="auto"||t==="default")return"default";const s=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gem ").replace("-preview",""):t.length>12?t.slice(0,12)+"...":t}const xte=p.memo(function({agent:s,isRotating:n}){const a=s.status==="running"||s.status==="starting",r=Math.round((s.contextUsage||0)*100),l=n?ce.accent:Gb(s.status),c=s.quality,A=(c==null?void 0:c.toolSuccessRate)!=null?Math.round(c.toolSuccessRate*100):null,f=s.rotationThreshold?Math.round(s.rotationThreshold*100):null,x=Ha(s.role),h=ce.text1;return e.jsxs("div",{className:"px-3 pl-6 py-2 hover:bg-surface-4 transition-colors space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-sm",style:{background:l}}),a&&e.jsx("span",{className:"absolute inset-[-2px] rounded-sm",style:{background:l,opacity:.15,animation:"node-pulse-bar 2s ease-in-out infinite"}})]}),e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate leading-none flex-shrink-0 max-w-[80px]",children:s.name}),e.jsx("span",{className:"text-2xs font-mono font-semibold px-1.5 py-px rounded-sm flex-shrink-0 capitalize",style:{background:x.bg,color:x.text},children:(s.role||"").toLowerCase()}),e.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1 py-px rounded-sm flex-shrink-0 truncate max-w-[72px]",children:fte(s.model)}),e.jsx("div",{className:"flex-1"}),A!=null&&e.jsxs("span",{className:"text-2xs font-mono font-bold px-1 py-px rounded-sm flex-shrink-0 text-text-1 bg-surface-4",children:[A,"%"]}),s.costSource&&s.costSource!=="actual"&&e.jsx("span",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex-shrink-0",children:ute[s.costSource]||""}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[e.jsx("div",{className:"text-xs font-mono text-text-1 tabular-nums leading-none",children:jt(s.tokens||0)}),(s.costUsd||0)>0&&e.jsx("div",{className:"text-2xs font-mono text-text-3 mt-0.5",children:er(s.costUsd)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 h-0.5 rounded-sm overflow-visible",style:{background:nt(ce.text4,.2)},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 rounded-sm transition-all duration-700",style:{width:`${Math.max(r,1)}%`,background:h}}),f&&e.jsx("div",{className:"absolute top-[-1px] w-px h-[4px]",style:{left:`${f}%`,background:ce.text3},title:`Rotation at ${f}%`})]}),e.jsxs("span",{className:"text-2xs font-mono text-text-2 tabular-nums flex-shrink-0 w-7 text-right",children:[r,"%"]})]})]})});function mte({team:t,members:s,rotatingSet:n}){const[a,r]=p.useState(!0),l=s.filter(x=>x.status==="running"||x.status==="starting").length,c=l>0,A=s.reduce((x,h)=>x+(h.tokens||0),0),f=s.reduce((x,h)=>x+(h.costUsd||0),0);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>r(x=>!x),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-surface-4 bg-surface-3",style:{borderLeft:c?`2px solid ${ce.accent}`:"2px solid transparent"},children:[a?e.jsx(xt,{size:10,className:"text-text-4 flex-shrink-0"}):e.jsx(Tt,{size:10,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-mono font-semibold text-text-2 uppercase tracking-widest flex-1 truncate",children:t}),e.jsx("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:jt(A)}),f>0&&e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums ml-1",children:er(f)}),e.jsxs("span",{className:"text-2xs font-mono tabular-nums flex-shrink-0 ml-1.5",style:{color:c?ce.text1:void 0},children:[l,"/",s.length]})]}),a&&s.map(x=>e.jsx(xte,{agent:x,isRotating:n.has(x.id)},x.id))]})}const hte=p.memo(function({agentBreakdown:s,rotating:n=[],teams:a=[]}){if(!(s!=null&&s.length))return e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono p-4",children:"No agents"});const r={};for(const A of a)r[A.id]=A.name;const l={};for(const A of s){const f=A.teamId||"ungrouped";l[f]||(l[f]=[]),l[f].push(A)}const c=new Set(n);return e.jsx(Qt,{className:"flex-1",children:e.jsx("div",{className:"py-1",children:Object.entries(l).map(([A,f])=>e.jsx(mte,{team:r[A]||(A==="ungrouped"?"Ungrouped":A),members:f,rotatingSet:c},A))})})}),Is=36,nb=3,Wf=(Is-nb)/2,Qf=2*Math.PI*Wf,BQ=-90;function pte(){return ce.text1}function gte({name:t,pct:s,threshold:n}){const a=pte(),r=s/100*Qf;return e.jsxs("div",{className:"flex flex-col items-center gap-0.5",title:`${t}: ${s}% context used`,children:[e.jsxs("svg",{width:Is,height:Is,viewBox:`0 0 ${Is} ${Is}`,children:[e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:nb,className:"stroke-surface-4"}),e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:nb,strokeLinecap:"round",style:{stroke:a,strokeDasharray:`${r} ${Qf-r}`,strokeDashoffset:0,transition:"stroke-dasharray 0.5s ease"},transform:`rotate(${BQ} ${Is/2} ${Is/2})`}),n&&e.jsx("circle",{cx:Is/2,cy:Is/2,r:Wf,fill:"none",strokeWidth:1,strokeLinecap:"butt",style:{stroke:ce.text3,strokeDasharray:`1 ${Qf-1}`,strokeDashoffset:-(n/100)*Qf},transform:`rotate(${BQ} ${Is/2} ${Is/2})`}),e.jsx("text",{x:Is/2,y:Is/2+1,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-1 font-mono font-semibold",style:{fontSize:9},children:s})]}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate max-w-[40px] leading-none",children:t})]})}function Ote({zones:t}){return e.jsxs("div",{className:"flex items-center gap-2 text-2xs font-mono",children:[e.jsx("span",{className:"text-text-2",children:t.healthy}),e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-text-2",children:t.warning}),e.jsx("span",{className:"text-text-4",children:"/"}),e.jsx("span",{className:"text-text-2",children:t.critical})]})}const bte=p.memo(function({agentBreakdown:s}){const n=(s||[]).filter(r=>r.status==="running"||r.status==="starting");if(n.length===0)return null;const a={healthy:0,warning:0,critical:0};for(const r of n){const l=Math.round((r.contextUsage||0)*100);l>80?a.critical++:l>60?a.warning++:a.healthy++}return e.jsxs("div",{className:"px-3 py-2 flex-shrink-0 border-b border-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Context Health"}),e.jsx(Ote,{zones:a})]}),e.jsx("div",{className:"flex items-start gap-2 overflow-x-auto",children:n.map(r=>{const l=Math.round((r.contextUsage||0)*100),c=r.rotationThreshold?Math.round(r.rotationThreshold*100):null;return e.jsx(gte,{name:r.name,pct:l,threshold:c},r.id)})})]})}),vte=p.memo(function({data:s}){const n=p.useRef(null),a=p.useRef(null),[r,l]=p.useState({width:0,height:0}),[c,A]=p.useState(null),{width:f,height:x}=r,h={top:28,right:12,bottom:8,left:12},g=Math.max(f-h.left-h.right,0),O=Math.max(x-h.top-h.bottom,0),b=p.useMemo(()=>!s||s.length<2?[]:s.slice(1).map((S,j)=>{const N=s[j],C=(S.t-N.t)/6e4,U=Math.max((S.tokens||0)-(N.tokens||0),0);return{burnRate:C>0?Math.round(U/C):0,cacheHitRate:S.cacheHitRate||0,running:S.running||0,agents:S.agents||0,t:S.t}}),[s]);p.useEffect(()=>{const S=n.current;if(!S)return;const j=new ResizeObserver(N=>{const{width:C,height:U}=N[0].contentRect;C>0&&U>0&&l({width:Math.floor(C),height:Math.floor(U)})});return j.observe(S),()=>j.disconnect()},[]);const v=p.useCallback(S=>{const j=a.current;if(!j||!b.length||g<=0)return;const N=j.getBoundingClientRect(),C=S.clientX-N.left-h.left;if(C<0||C>g){A(null);return}const U=Math.round(C/g*(b.length-1));A({x:h.left+U/Math.max(b.length-1,1)*g,index:U})},[b,g,h.left]),y=p.useCallback(()=>A(null),[]);return p.useEffect(()=>{const S=a.current;if(!S||!b.length||f<=0||x<=0||g<=0||O<=0)return;const j=S.getContext("2d"),N=window.devicePixelRatio||1;S.width=f*N,S.height=x*N,j.scale(N,N),j.clearRect(0,0,f,x);const C=b.map(E=>E.burnRate),U=b.map(E=>E.cacheHitRate),P=b.map(E=>E.running),T=Math.max(...C,100),B=Math.max(...P,1),F=E=>h.left+E/Math.max(b.length-1,1)*g,M=E=>h.top+O-E/T*O,R=E=>h.top+O-E*O,Y=Math.max(g/b.length-1,2);for(let E=0;E<b.length;E++){const q=P[E];if(q<=0)continue;const H=q/B*O*.3,I=F(E)-Y/2,L=h.top+O-H;j.fillStyle=nt(ce.surface5,.5),j.fillRect(I,L,Y,H)}j.setLineDash([2,4]),j.strokeStyle=nt(ce.text4,.2),j.lineWidth=1;for(let E=1;E<=3;E++){const q=h.top+O/4*E;j.beginPath(),j.moveTo(h.left,q),j.lineTo(h.left+g,q),j.stroke()}j.setLineDash([]),j.font="9px 'SF Mono', ui-monospace, Menlo, Consolas, monospace",j.textAlign="left",j.fillStyle=nt(ce.text3,.5),j.fillText(`${jt(T)}/m`,h.left+4,h.top+10),j.fillText(`${jt(Math.round(T/2))}/m`,h.left+4,h.top+O/2+4),j.beginPath(),j.moveTo(h.left,h.top+O);for(let E=0;E<b.length;E++)j.lineTo(F(E),M(C[E]));j.lineTo(F(b.length-1),h.top+O),j.closePath();const W=j.createLinearGradient(0,h.top,0,h.top+O);W.addColorStop(0,nt(ce.accent,.2)),W.addColorStop(.7,nt(ce.accent,.04)),W.addColorStop(1,nt(ce.accent,0)),j.fillStyle=W,j.fill(),j.beginPath(),j.strokeStyle=ce.accent,j.lineWidth=1.5,j.lineJoin="round";for(let E=0;E<b.length;E++){const q=F(E),H=M(C[E]);E===0?j.moveTo(q,H):j.lineTo(q,H)}j.stroke();const ee=U.some(E=>E>0);if(ee){j.beginPath(),j.strokeStyle=nt(ce.text2,.5),j.lineWidth=1,j.lineJoin="round",j.setLineDash([2,3]);for(let E=0;E<b.length;E++){const q=F(E),H=R(U[E]);E===0?j.moveTo(q,H):j.lineTo(q,H)}j.stroke(),j.setLineDash([])}j.font="9px 'Inter Variable', sans-serif",j.textAlign="right";let K=f-h.right-4;const _=14;if(ee&&(j.fillStyle=nt(ce.text2,.5),j.fillText("Cache %",K,_),K-=j.measureText("Cache %").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),K-=14),j.fillStyle=nt(ce.surface5,.7),j.fillText("Agents",K,_),K-=j.measureText("Agents").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),K-=14,j.fillStyle=ce.accent,j.fillText("Burn Rate",K,_),K-=j.measureText("Burn Rate").width+4,j.beginPath(),j.arc(K,_-3,2.5,0,Math.PI*2),j.fill(),c&&c.index>=0&&c.index<b.length){const E=c.x,q=b[c.index];j.beginPath(),j.moveTo(E,h.top),j.lineTo(E,h.top+O),j.strokeStyle=nt(ce.text1,.15),j.lineWidth=1,j.stroke();const H=M(q.burnRate);j.beginPath(),j.arc(E,H,3,0,Math.PI*2),j.fillStyle=ce.accent,j.fill();const I=[{label:"Burn",value:`${jt(q.burnRate)}/m`,color:ce.accent},{label:"Cache",value:pc(q.cacheHitRate*100),color:ce.text2},{label:"Agents",value:`${q.running}/${q.agents}`,color:ce.text3}],L=104,J=I.length*16+12;let D=E+12;D+L>f-8&&(D=E-L-12);const se=Math.max(h.top,H-J/2);j.fillStyle=nt(ce.surface0,.92),j.beginPath(),j.roundRect(D,se,L,J,4),j.fill(),j.strokeStyle=nt(ce.text4,.2),j.lineWidth=1,j.stroke(),j.textAlign="left",I.forEach((le,V)=>{const te=se+14+V*16;j.beginPath(),j.arc(D+8,te-3,2,0,Math.PI*2),j.fillStyle=le.color,j.fill(),j.font="8px 'Inter Variable', sans-serif",j.fillStyle=ce.text3,j.fillText(le.label,D+14,te),j.font="9px 'SF Mono', ui-monospace, Menlo, Consolas, monospace",j.fillStyle=ce.text0,j.textAlign="right",j.fillText(le.value,D+L-8,te),j.textAlign="left"})}},[b,f,x,c,g,O,h]),e.jsx("div",{ref:n,className:"absolute inset-0",children:f>0&&x>0&&e.jsx("canvas",{ref:a,style:{width:f,height:x},className:"block cursor-crosshair",onMouseMove:v,onMouseLeave:y})})}),yte=p.memo(function({cacheRead:s=0,cacheCreation:n=0,totalInput:a=0,size:r=140}){const l=p.useRef(null),c=s+n,A=c,f=c>0?s/c*100:0;return p.useEffect(()=>{const x=l.current;if(!x)return;const h=window.devicePixelRatio||1;x.width=r*h,x.height=r*h;const g=x.getContext("2d");g.scale(h,h),g.clearRect(0,0,r,r);const O=r/2,b=r/2,v=(r-12)/2,y=5,S=135*Math.PI/180,j=405*Math.PI/180,N=j-S;if(g.beginPath(),g.arc(O,b,v,S,j),g.strokeStyle=ce.surface4,g.lineWidth=y,g.lineCap="round",g.stroke(),A>0){const C=s/A,U=n/A;if(C>0){const P=S+N*C;g.beginPath(),g.arc(O,b,v,S,P),g.strokeStyle=ce.text0,g.lineWidth=y,g.lineCap="round",g.stroke()}if(U>0){const P=S+N*C,T=P+N*U;g.beginPath(),g.arc(O,b,v,P,T),g.strokeStyle=ce.text3,g.lineWidth=y,g.lineCap="butt",g.stroke()}}g.textAlign="center",g.textBaseline="middle",g.font=`600 ${r*.2}px 'SF Mono', ui-monospace, Menlo, Consolas, monospace`,g.fillStyle=ce.text0,g.fillText(`${Math.round(f)}%`,O,b-3),g.font=`500 ${r*.08}px 'SF Mono', ui-monospace, Menlo, Consolas, monospace`,g.fillStyle=ce.text3,g.fillText("CACHE",O,b+r*.13)},[s,n,a,r,A,f]),e.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-3 py-3",children:[e.jsx("canvas",{ref:l,className:"flex-shrink-0",style:{width:r,height:r}}),e.jsxs("div",{className:"w-full mt-3 space-y-1.5 max-w-[160px]",children:[e.jsx(Lg,{color:ce.text0,label:"Read",value:jt(s)}),e.jsx(Lg,{color:ce.text3,label:"Create",value:jt(n)}),e.jsx(Lg,{color:ce.surface5,label:"Miss",value:jt(Math.max(a-s-n,0))})]})]})});function Lg({color:t,label:s,value:n}){return e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:t}}),e.jsx("span",{className:"text-text-3 uppercase tracking-wider flex-1",children:s}),e.jsx("span",{className:"text-text-1 tabular-nums",children:n})]})}const R4={heavy:ce.text0,medium:ce.text2,light:ce.text4},wte={heavy:"Heavy",medium:"Medium",light:"Light"},an=80,ab=6,rb=(an-ab)/2,kQ=2*Math.PI*rb;function jte({byTier:t,total:s,tiers:n}){let a=0;const r=[];for(const l of n){const c=t[l]||0;if(c===0)continue;const f=c/s*kQ;r.push({tier:l,dashLen:f,offset:a}),a+=f}return s>0&&Math.round((t.heavy||0)/s*100),e.jsxs("svg",{width:an,height:an,viewBox:`0 0 ${an} ${an}`,className:"flex-shrink-0",children:[e.jsx("circle",{cx:an/2,cy:an/2,r:rb,fill:"none",strokeWidth:ab,className:"stroke-surface-4"}),r.map(l=>e.jsx("circle",{cx:an/2,cy:an/2,r:rb,fill:"none",strokeWidth:ab,strokeLinecap:"butt",style:{stroke:R4[l.tier],strokeDasharray:`${l.dashLen} ${kQ-l.dashLen}`,strokeDashoffset:-l.offset},transform:`rotate(-90 ${an/2} ${an/2})`},l.tier)),e.jsx("text",{x:an/2,y:an/2-2,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-0 text-sm font-mono font-semibold",children:jt(s)}),e.jsx("text",{x:an/2,y:an/2+11,textAnchor:"middle",dominantBaseline:"central",className:"fill-text-3 font-mono",style:{fontSize:7},children:"decisions"})]})}const Qte=p.memo(function({routing:s,agentBreakdown:n}){if(!s)return null;const{byTier:a={},totalDecisions:r=0,autoRoutedCount:l=0}=s,c=["heavy","medium","light"],A=c.reduce((g,O)=>g+(a[O]||0),0),f={};for(const g of n||[]){const O=g.model||"default";f[O]||(f[O]={tokens:0,agents:0}),f[O].tokens+=g.tokens||0,f[O].agents+=1}const x=Object.entries(f).sort((g,O)=>O[1].tokens-g[1].tokens),h=x.length>0?x[0][1].tokens:0;return e.jsxs("div",{className:"flex flex-col h-full px-3 py-3 overflow-y-auto",children:[A>0&&e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(jte,{byTier:a,total:A,tiers:c}),e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1 min-w-0",children:[c.map(g=>{const O=a[g]||0;if(O===0)return null;const b=O/A*100;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full flex-shrink-0",style:{background:R4[g]}}),e.jsx("span",{className:"text-2xs font-mono text-text-2 flex-1",children:wte[g]}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums",children:O}),e.jsx("span",{className:"text-2xs font-mono text-text-4 tabular-nums w-8 text-right",children:pc(b)})]},g)}),l>0&&e.jsxs("div",{className:"text-2xs font-mono text-text-4 mt-0.5",children:[l," auto-routed"]})]})]}),x.length>0&&e.jsxs("div",{className:"space-y-1.5 flex-1",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-wider",children:"Models in Use"}),e.jsx("div",{className:"space-y-1.5",children:x.map(([g,O])=>{const b=h>0?O.tokens/h*100:0;return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 flex-1 truncate",children:Nte(g)}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 tabular-nums",children:[O.agents," agent",O.agents!==1?"s":""]}),e.jsx("span",{className:"text-xs font-mono text-text-1 tabular-nums",children:jt(O.tokens)})]}),e.jsx("div",{className:"h-0.5 bg-surface-4 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all duration-500",style:{width:`${Math.max(b,2)}%`,background:ce.text2}})})]},g)})})]}),A===0&&x.length===0&&e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-text-3 font-mono",children:"No routing data"})]})});function Nte(t){if(!t||t==="auto"||t==="default")return"Default";const s=t.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)/);return s?`${s[1][0].toUpperCase()}${s[1].slice(1)} ${s[2]}.${s[3]}`:t.startsWith("gemini-")?t.replace("gemini-","Gemini ").replace("-preview",""):t}function M4({text:t}){return e.jsx(dt,{content:e.jsx("span",{className:"max-w-[220px] block leading-relaxed",children:t}),side:"bottom",children:e.jsx(ki,{size:9,className:"text-text-4 hover:text-text-2 cursor-help flex-shrink-0 transition-colors ml-0.5"})})}function Ste({children:t,tip:s}){return e.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider flex items-center gap-0.5",children:[t,s&&e.jsx(M4,{text:s})]})}function Nf({label:t,value:s,tip:n}){return e.jsxs("div",{children:[e.jsx(Ste,{tip:n,children:t}),e.jsx("div",{className:"text-sm font-mono font-semibold text-text-1 tabular-nums leading-snug",children:s})]})}function jd({title:t,children:s,tip:n}){return e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"text-2xs font-mono text-text-4 uppercase tracking-wider mb-2 flex items-center gap-0.5",children:[t,n&&e.jsx(M4,{text:n})]}),s]})}function vc(){return e.jsx("div",{className:"h-px bg-border mx-3"})}function Cte({tokens:t,rotation:s,agentBreakdown:n}){const r=(n||[]).filter(c=>{var A;return((A=c.quality)==null?void 0:A.score)!=null}),l=r.length>0?Math.round(r.reduce((c,A)=>c+A.quality.score,0)/r.length):null;return e.jsxs("div",{className:"px-3 py-3 flex items-start gap-5",children:[e.jsx(Nf,{label:"Quality",value:l??"—",tip:"Average session quality (0-100). Below 40 triggers auto-rotation."}),e.jsx(Nf,{label:"Cache",value:pc(((t==null?void 0:t.cacheHitRate)||0)*100),tip:"Prompt cache hit rate. Higher = faster + cheaper."}),e.jsx(Nf,{label:"Rotations",value:(s==null?void 0:s.totalRotations)||0,tip:"Total context rotations this session."}),((t==null?void 0:t.totalCostUsd)||0)>0&&e.jsx(Nf,{label:"Cost",value:er(t.totalCostUsd),tip:"Total cost reported by providers."})]})}function Bte({agentBreakdown:t,rotation:s}){const n=(s==null?void 0:s.liveScores)||{},a=(t||[]).filter(r=>r.status==="running");return a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Live agents",children:e.jsx("div",{className:"space-y-0",children:a.map(r=>{var x;const l=r.quality||{},c=((x=n[r.id])==null?void 0:x.score)??l.score,A=Ha(r.role),f=[l.errorCount>0&&`${l.errorCount} err`,l.repetitions>0&&`${l.repetitions} rep`,l.fileChurn>0&&`${l.fileChurn} churn`].filter(Boolean);return e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[e.jsx("span",{className:"text-2xs font-semibold capitalize px-1 py-px rounded-sm flex-shrink-0",style:{background:A.bg,color:A.text},children:r.role}),e.jsx("span",{className:"text-text-2 truncate flex-1",children:r.name}),f.length>0&&e.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:f.join(" · ")}),e.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0 w-6 text-right",children:c??"—"})]},r.id)})})})]})}function kte({rotation:t}){const s=((t==null?void 0:t.history)||[]).slice(-5).reverse();if(s.length===0)return null;function n(a){return a.reason==="quality_degradation"?`Q:${a.qualityScore}`:a.reason==="token_limit_exceeded"?"tokens":a.reason==="runaway_velocity"?"velocity":a.reason==="natural_compaction"?"compacted":pc((a.contextUsage||0)*100)}return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Recent rotations",children:e.jsx("div",{className:"space-y-0",children:s.map((a,r)=>e.jsxs("div",{className:"flex items-center gap-2 py-0.5 text-xs font-mono",children:[e.jsx("span",{className:"text-text-2 truncate flex-1",children:a.agentName||a.role}),e.jsx("span",{className:"text-text-3 flex-shrink-0",children:n(a)}),e.jsx("span",{className:"text-text-4 flex-shrink-0 w-10 text-right",children:$t(a.timestamp)})]},r))})})]})}function Tte({adaptive:t}){if(!(t!=null&&t.length))return null;function s(n){const a=n.split(":");return{provider:a[0]||n,role:a[1]||""}}return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsx(jd,{title:"Adaptive thresholds",tip:"Per-role rotation thresholds. GROOVE learns when each role benefits from rotation and adjusts automatically.",children:e.jsx("div",{className:"space-y-0",children:t.map(n=>{const{provider:a,role:r}=s(n.key),l=r||a,c=Ha(l);return e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs font-mono",children:[e.jsx("span",{className:"text-2xs font-semibold capitalize px-1 py-px rounded-sm flex-shrink-0",style:{background:c.bg,color:c.text},children:l}),r&&e.jsx("span",{className:"text-2xs text-text-4 flex-shrink-0",children:a}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-text-1 font-semibold tabular-nums flex-shrink-0",children:pc(n.threshold*100)}),n.converged?e.jsx("span",{className:"text-2xs font-semibold flex-shrink-0",style:{color:ce.accent},children:"Converged"}):e.jsxs("span",{className:"text-2xs text-text-3 flex-shrink-0 flex items-center gap-1",children:[e.jsx("span",{className:"w-1 h-1 rounded-full [animation:node-pulse-bar_1.5s_ease-in-out_infinite]",style:{background:ce.text3}}),"Learning"]})]},n.key)})})})]})}function Ute({journalist:t}){return!t||!((t.cycleCount||0)>0)&&!t.synthesizing?null:e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs(jd,{title:"Journalist",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs font-mono",children:[e.jsxs("span",{className:"text-text-2",children:[t.cycleCount||0," cycles"]}),t.lastCycleAt&&e.jsx("span",{className:"text-text-4",children:$t(t.lastCycleAt)}),t.synthesizing&&e.jsx("span",{className:"font-semibold text-accent animate-pulse",children:"Synthesizing"})]}),t.lastSummary&&e.jsx("div",{className:"text-xs text-text-3 leading-relaxed mt-1.5 line-clamp-3",children:t.lastSummary})]})]})}function Ete({memory:t}){var f,x;const s=(t==null?void 0:t.constraints)||[],n=(t==null?void 0:t.discoveries)||[],a=(t==null?void 0:t.roles)||[],r=((f=t==null?void 0:t.specializations)==null?void 0:f.perProjectRole)||{},l=Object.keys(((x=t==null?void 0:t.specializations)==null?void 0:x.perAgent)||{}).length;if(s.length+n.length+a.length+l===0)return null;const A=[s.length>0&&`${s.length} constraints`,n.length>0&&`${n.length} discoveries`,a.length>0&&`${a.length} role chains`,l>0&&`${l} specializations`].filter(Boolean);return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs(jd,{title:"Memory",tip:"Persistent knowledge across agent rotations. Constraints, error→fix discoveries, and handoff chains.",children:[e.jsx("div",{className:"text-xs font-mono text-text-3 mb-1.5",children:A.join(" · ")}),s.length>0&&e.jsxs("div",{className:"mt-2 space-y-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Constraints"}),s.slice(0,3).map(h=>e.jsx("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:h.text},h.hash)),s.length>3&&e.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",s.length-3," more"]})]}),n.length>0&&e.jsxs("div",{className:"mt-2 space-y-0",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Discoveries"}),n.slice(0,3).map((h,g)=>e.jsxs("div",{className:"text-xs font-mono text-text-2 py-0.5 truncate",children:[e.jsx("span",{className:"text-text-4",children:h.trigger})," → ",h.fix]},g)),n.length>3&&e.jsxs("div",{className:"text-2xs font-mono text-text-4",children:["+",n.length-3," more"]})]}),Object.keys(r).length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"text-2xs font-mono text-text-4 mb-1",children:"Role quality"}),e.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-0.5",children:Object.entries(r).map(([h,g])=>e.jsxs("span",{className:"text-xs font-mono text-text-3",children:[e.jsx("span",{className:"text-text-2 capitalize",children:h})," Q:",g.avgQualityScore," ",e.jsxs("span",{className:"text-text-4",children:["(",g.sessionCount,"s)"]})]},h))})]})]})]})}function Pte({tokens:t}){var r,l;if(!((r=t==null?void 0:t.internalOverhead)!=null&&r.tokens)||!((l=t==null?void 0:t.savings)!=null&&l.total))return null;const s=t.internalOverhead,n=t.savings,a=t.totalTokens>0?Math.round(s.tokens/t.totalTokens*100):0;return e.jsxs(e.Fragment,{children:[e.jsx(vc,{}),e.jsxs("div",{className:"px-3 py-2.5 flex items-center gap-3 text-xs font-mono",children:[e.jsx("span",{className:"text-text-4",children:"Overhead"}),e.jsxs("span",{className:"text-text-3 tabular-nums",children:[jt(s.tokens)," (",a,"%)"]}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-text-4",children:"Saved"}),e.jsx("span",{className:"text-text-3 tabular-nums",children:jt(n.total)})]})]})}const Fte=p.memo(function({tokens:s,rotation:n,adaptive:a,journalist:r,agentBreakdown:l,memory:c}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-shrink-0 px-3 pt-2.5 pb-1.5",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Intel"})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[e.jsx(Cte,{tokens:s,rotation:n,agentBreakdown:l}),e.jsx(Bte,{agentBreakdown:l,rotation:n}),e.jsx(kte,{rotation:n}),e.jsx(Tte,{adaptive:a}),e.jsx(Ute,{journalist:r}),e.jsx(Ete,{memory:c}),e.jsx(Pte,{tokens:s}),e.jsx("div",{className:"h-3"})]})]})}),$te=p.memo(function({teams:s=[]}){const n=s.reduce((r,l)=>r+(l.totalTokens||0),0),a=s.reduce((r,l)=>Math.max(r,l.totalTokens||0),0);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0 flex items-center justify-between",children:[e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Team Burn"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:[jt(n)," total"]})]}),e.jsx(Qt,{className:"flex-1 min-h-0",children:s.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-text-3 font-mono",children:"No team activity yet"}):e.jsx("div",{className:"px-3 py-3 space-y-3",children:s.map(r=>{const l=a>0?r.totalTokens/a*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:r.teamName}),r.isDefault&&e.jsx("span",{className:"text-[9px] font-mono text-text-3 uppercase tracking-wider",children:"default"}),e.jsxs("span",{className:"text-2xs font-mono text-text-3 flex-shrink-0",children:[r.agentCount," ",r.agentCount===1?"agent":"agents"]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 font-mono text-2xs",children:[e.jsx("span",{className:"text-text-1",children:jt(r.totalTokens)}),e.jsx("span",{className:"text-text-3",children:er(r.totalCostUsd)})]})]}),e.jsx("div",{className:"h-0.5 bg-surface-2 rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-all",style:{width:`${l}%`,background:ce.text3}})})]},r.teamId)})})})]})}),Rte={spawn:HS,complete:Ga,crash:Aa,kill:AO,rotate:hd,error:Db},Mte={spawn:"text-text-2",complete:"text-text-2",crash:"text-danger",kill:"text-text-3",rotate:"text-text-2",error:"text-danger"};function Ite(t){const s=t.agentName||t.role||"";switch(t.type){case"spawn":return`${s} spawned`;case"complete":return`${s} completed`;case"crash":return`${s} crashed`;case"kill":return`${s} killed`;case"rotate":return`${s} rotated`;default:return t.text||t.type||"event"}}const zte=p.memo(function({events:s=[]}){return s.length?e.jsx("div",{className:"flex items-center gap-3 overflow-x-auto py-2 px-3",children:s.slice(-15).reverse().map((n,a)=>{const r=Rte[n.type]||qt,l=Mte[n.type]||"text-text-3",c=Ite(n);return e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(r,{size:11,className:l}),e.jsx("span",{className:"text-xs font-sans text-text-2 whitespace-nowrap",children:c}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:$t(n.t||n.timestamp)})]},a)})}):e.jsx("div",{className:"text-xs text-text-3 font-mono py-2.5 text-center",children:"No recent activity"})});function ia({className:t,...s}){return e.jsx("div",{className:Z("rounded-md bg-surface-4","bg-gradient-to-r from-surface-4 via-surface-5 to-surface-4","bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]",t),...s})}function _te(){return e.jsxs("div",{className:"flex-1 grid gap-px p-0 bg-surface-3",style:{gridTemplateRows:"auto minmax(0, 1fr) minmax(0, 1fr)",gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[e.jsx("div",{className:"col-span-3",children:e.jsx(ia,{className:"h-[72px] rounded-none"})}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx(ia,{className:"rounded-none"}),e.jsx("div",{className:"col-span-2",children:e.jsx(ia,{className:"h-full rounded-none"})})]})}function Dte(){const{data:t,loading:s,agents:n,connected:a,kpiHistory:r,lastFetch:l,agentBreakdown:c,routing:A,rotation:f,adaptive:x,journalist:h,rotating:g,teamBurn:O,memory:b}=lte(),v=k(R=>R.teams),y=n.filter(R=>R.status==="running").length;if(!a)return e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2 text-text-3 font-mono",children:[e.jsx(Lx,{size:28,className:"mx-auto"}),e.jsx("p",{className:"text-xs",children:"Connecting to daemon..."})]})});if(s||!t)return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(CQ,{connected:a,runningCount:0,totalCount:0,uptime:0,lastFetch:0}),e.jsx(_te,{})]});const S=t.tokens||{},j={totalTokens:S.totalTokens||0,totalCostUsd:S.totalCostUsd||0,totalInputTokens:S.totalInputTokens||0,totalOutputTokens:S.totalOutputTokens||0,cacheReadTokens:S.cacheReadTokens||0,cacheCreationTokens:S.cacheCreationTokens||0,cacheHitRate:S.cacheHitRate||0,totalTurns:S.totalTurns||0,agentCount:S.agentCount||0,savings:S.savings||{},internalOverhead:S.internalOverhead||{tokens:0,costUsd:0,components:{}}},N=j.totalOutputTokens>0?(j.totalInputTokens/j.totalOutputTokens).toFixed(1):"—",C=(f==null?void 0:f.totalRotations)||0,U=(c||[]).filter(R=>{var Y;return((Y=R.quality)==null?void 0:Y.score)!=null}),P=U.length>0?Math.round(U.reduce((R,Y)=>R+Y.quality.score,0)/U.length):null,T=t.timeline||{},B=T.snapshots||[],F=T.events||t.events||[],M=[{label:"Tokens Used",value:jt(j.totalTokens),sparkData:r.tokens,color:ce.text3,hint:"Total tokens consumed across all agents — input, output, and cache tokens combined."},{label:"Total Cost",value:er(j.totalCostUsd),sparkData:r.cost,color:ce.text3,hint:"Actual cost reported by providers. Claude Code reports real billing; other providers use estimated rates."},{label:"Quality",value:P!=null?`${P}`:"—",sparkData:r.saved,color:ce.text3,hint:"Average session quality score (0-100) across running agents. Based on error rate, repetitions, file churn, and tool success. Below 40 triggers auto-rotation."},{label:"Cache Rate",value:pc(j.cacheHitRate*100),sparkData:r.cache,color:ce.text3,hint:"Percentage of input tokens served from prompt cache. Higher = faster responses and lower cost. Managed by your AI provider."},{label:"Rotations",value:`${C}`,sparkData:r.efficiency,color:ce.text3,hint:"Total context rotations — includes quality-based (auto), context threshold, natural compaction (provider-managed), and manual rotations."},{label:"I/O Ratio",value:`${N}:1`,sparkData:r.inputOutput,color:ce.text3,hint:"Ratio of input to output tokens. High ratios mean agents are reading more than writing — common for analysis tasks."},{label:"Agents",value:`${y}/${n.length}`,sparkData:r.agents,color:ce.text3,hint:"Running agents out of total spawned this session (including completed and crashed)."},{label:"Turns",value:jt(j.totalTurns),sparkData:r.turns,color:ce.text3,hint:"Total conversation turns across all agents. Each turn is one request-response cycle with the AI provider."}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(CQ,{connected:a,runningCount:y,totalCount:n.length,uptime:t.uptime||0,lastFetch:l,activeTeam:t.activeTeam}),e.jsx(dte,{kpis:M}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col bg-surface-3 gap-px",children:[e.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"3fr 1.5fr 1.5fr"},children:[e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 relative",children:e.jsx(vte,{data:B})}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Cache Performance"})}),e.jsx(yte,{cacheRead:j.cacheReadTokens,cacheCreation:j.cacheCreationTokens,totalInput:j.totalInputTokens})]}),e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-l border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Model Routing"})}),e.jsx(Qte,{routing:A,agentBreakdown:c})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 grid gap-x-px",style:{gridTemplateColumns:"2fr 2.5fr 1.5fr"},children:[e.jsxs("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-border",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 flex-shrink-0",children:e.jsx("span",{className:"text-2xs font-mono text-text-3 uppercase tracking-widest",children:"Agent Fleet"})}),e.jsx(bte,{agentBreakdown:c}),e.jsx(hte,{agentBreakdown:c,rotating:g,teams:v})]}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx(Fte,{tokens:j,rotation:f,adaptive:x,journalist:h,agentBreakdown:c,memory:b})}),e.jsx("div",{className:"min-w-0 min-h-0 overflow-hidden bg-surface-1 flex flex-col border-t border-l border-border",children:e.jsx($te,{teams:O})})]})]}),e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-t border-border",children:e.jsx(zte,{events:F})})]})}const TQ={sm:12,md:16,lg:20};function Lte({fill:t="full",size:s,color:n="#fbbf24",emptyColor:a="rgba(255,255,255,0.4)"}){const r=`star-${Math.random().toString(36).slice(2,8)}`;return e.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",children:[t==="half"&&e.jsx("defs",{children:e.jsxs("linearGradient",{id:r,children:[e.jsx("stop",{offset:"50%",stopColor:n}),e.jsx("stop",{offset:"50%",stopColor:a})]})}),e.jsx("path",{d:"M10 1.5l2.47 5.01 5.53.8-4 3.9.94 5.49L10 14.27 5.06 16.7 6 11.21l-4-3.9 5.53-.8L10 1.5z",fill:t==="full"?n:t==="half"?`url(#${r})`:a})]})}function Hte({rating:t=0,count:s,size:n="sm"}){const a=TQ[n]||TQ.sm,r=[];for(let l=1;l<=5;l++)t>=l?r.push("full"):t>=l-.5?r.push("half"):r.push("empty");return e.jsxs("span",{className:"inline-flex items-center",style:{gap:1},children:[r.map((l,c)=>e.jsx(Lte,{fill:l,size:a},c)),s!=null&&e.jsxs("span",{className:"ml-1 text-[11px] text-[var(--text-dim,#6b7f95)] font-sans",children:["(",s,")"]})]})}const UQ={design:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},quality:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},devtools:{color:"#33afbc",bg:"rgba(51,175,188,0.14)"},workflow:{color:"#fbbf24",bg:"rgba(251,191,36,0.12)"},security:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},specialized:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},verified:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},anthropic:{color:"#f59e0b",bg:"rgba(245,158,11,0.12)"},published:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"},draft:{color:"#6b7f95",bg:"rgba(255,255,255,0.06)"},review:{color:"#c678dd",bg:"rgba(198,120,221,0.12)"},rejected:{color:"#f87171",bg:"rgba(248,113,113,0.12)"},free:{color:"#4ade80",bg:"rgba(74,222,128,0.12)"}};function Xte({label:t,variant:s,className:n}){const a=UQ[s]||UQ.draft;return e.jsx("span",{className:Z("inline-flex items-center whitespace-nowrap font-sans select-none",n),style:{padding:"3px 8px",borderRadius:4,fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px",lineHeight:1.4,color:a.color,background:a.bg},children:t})}function Gte({price:t=0,size:s="sm"}){const n=!t||t===0,a={sm:"text-2xs px-2 py-0.5",md:"text-xs px-2.5 py-0.5",lg:"text-xs px-3 py-1"};return e.jsx("span",{className:`inline-flex items-center font-mono font-semibold rounded whitespace-nowrap ${a[s]||a.sm} ${n?"bg-success/12 text-success":"bg-white/8 text-text-1"}`,children:n?"Free":`$${t.toFixed(2)}`})}function Zte({type:t="verified",size:s=12}){const n=t==="claude-official"||t==="anthropic"?"#f59e0b":"#4ade80";return e.jsxs("svg",{width:s,height:s,viewBox:"0 0 20 20",fill:"none",className:"inline-block flex-shrink-0",children:[e.jsx("path",{d:"M10 0l2.36 3.15L16.18 2l.68 3.93L20.8 7.1l-1.87 3.52L20.8 14.14l-3.94 1.17-.68 3.93-3.82-1.15L10 21.24l-2.36-3.15-3.82 1.15-.68-3.93-3.94-1.17 1.87-3.52L-.8 7.1l3.94-1.17.68-3.93 3.82 1.15L10 0z",fill:n}),e.jsx("path",{d:"M7 10.5l2 2 4-4.5",fill:"none",stroke:"#24282f",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Vte(){return e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md animate-pulse",style:{padding:20,minHeight:280},children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-surface-4"}),e.jsx("div",{className:"mt-3 h-4 w-[70%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-2 h-3 w-[40%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-3 w-full rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[90%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-1.5 h-3 w-[60%] rounded bg-surface-4"}),e.jsx("div",{className:"mt-3.5 h-5 w-[50px] rounded bg-surface-4"}),e.jsx("div",{className:"h-px bg-surface-4 my-3"}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("div",{className:"h-3 w-16 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-12 rounded bg-surface-4"}),e.jsx("div",{className:"h-3 w-10 rounded bg-surface-4"})]})]})}const Ni={"google-workspace":"https://cdn.simpleicons.org/google/white",slack:"https://cdn.simpleicons.org/slack/E01E5A",discord:"https://cdn.simpleicons.org/discord/5865F2",github:"https://cdn.simpleicons.org/github/white",stripe:"https://cdn.simpleicons.org/stripe/635BFF",gmail:"https://cdn.simpleicons.org/gmail/EA4335","google-calendar":"https://cdn.simpleicons.org/googlecalendar/4285F4","google-drive":"https://cdn.simpleicons.org/googledrive/4285F4","google-docs":"https://cdn.simpleicons.org/googledocs/4285F4","google-sheets":"https://cdn.simpleicons.org/googlesheets/34A853","google-slides":"https://cdn.simpleicons.org/googleslides/FBBC04","google-maps":"https://cdn.simpleicons.org/googlemaps/4285F4",postgres:"https://cdn.simpleicons.org/postgresql/4169E1",notion:"https://cdn.simpleicons.org/notion/white",linear:"https://cdn.simpleicons.org/linear/5E6AD2","brave-search":"https://cdn.simpleicons.org/brave/FB542B","home-assistant":"https://cdn.simpleicons.org/homeassistant/18BCF2",sentry:"https://cdn.simpleicons.org/sentry/362D59",elevenlabs:"https://cdn.simpleicons.org/elevenlabs/white",hubspot:"https://cdn.simpleicons.org/hubspot/FF7A59",jira:"https://cdn.simpleicons.org/jira/0052CC",sendgrid:"https://cdn.simpleicons.org/sendgrid/1A82E2",resend:"https://cdn.simpleicons.org/resend/white",replicate:"https://cdn.simpleicons.org/replicate/white",vercel:"https://cdn.simpleicons.org/vercel/white",supabase:"https://cdn.simpleicons.org/supabase/3FCF8E",mixpanel:"https://cdn.simpleicons.org/mixpanel/7856FF",datadog:"https://cdn.simpleicons.org/datadog/632CA6",airtable:"https://cdn.simpleicons.org/airtable/18BFFF",zendesk:"https://cdn.simpleicons.org/zendesk/03363D",intercom:"https://cdn.simpleicons.org/intercom/6AFDEF",twilio:"https://cdn.simpleicons.org/twilio/F22F46",telnyx:"https://cdn.simpleicons.org/telnyx/00C08B",aws:"https://cdn.simpleicons.org/amazonaws/FF9900",plaid:"https://cdn.simpleicons.org/plaid/white"};function Kte({item:t,size:s=40}){const n=Ni[t.id];if(n)return e.jsxs("div",{className:"rounded-md bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:[e.jsx("img",{src:n,alt:t.name,className:"w-5 h-5",onError:l=>{l.target.style.display="none",l.target.nextSibling.style.display="flex"}}),e.jsx("div",{className:"hidden items-center justify-center w-full h-full text-lg font-bold font-sans text-text-1",children:(t.name||"?")[0]})]});const a=(t.name||"?")[0].toUpperCase(),r=t.name?t.name.charCodeAt(0)*37%360:200;return e.jsx("div",{className:"rounded-md flex items-center justify-center flex-shrink-0 text-lg font-bold font-sans",style:{width:s,height:s,background:`hsl(${r}, 40%, 18%)`,color:`hsl(${r}, 60%, 65%)`},children:a})}function Ux({item:t,onClick:s,className:n,statusBadge:a}){var l;const r=t.installed;return e.jsxs("button",{onClick:()=>s(t),className:Z("flex flex-col p-5 rounded-md border border-border-subtle bg-surface-1 text-left","hover:border-accent/30 hover:bg-surface-2","transition-all duration-150 cursor-pointer group",n),style:{minHeight:200},children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(Kte,{item:t,size:36}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-0 font-sans truncate",children:t.name}),(t.verified||t.verified==="mcp-official")&&e.jsx(Ga,{size:11,className:"text-accent flex-shrink-0"})]}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.author||"Community"})]})]}),e.jsx("p",{className:"text-xs text-text-2 font-sans line-clamp-3 mb-3 flex-1 leading-relaxed",children:t.description}),e.jsx("div",{className:"h-px bg-border-subtle my-2"}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(qs,{size:10}),jt(t.downloads||0)]}),(t.rating||0)>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lb,{size:10,className:"text-warning",fill:"currentColor"}),(l=t.rating)==null?void 0:l.toFixed(1)]}),e.jsx("span",{className:"flex-1"}),a||r&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:t._installedCount?`${t._installedCount} active`:"Installed"})]})]})}function I4({value:t,onChange:s,placeholder:n="Search skills, tags, authors...",large:a}){const[r,l]=p.useState(t||""),c=p.useRef(null);p.useEffect(()=>{l(t||"")},[t]);function A(f){const x=f.target.value;l(x),clearTimeout(c.current),c.current=setTimeout(()=>s(x),300)}return e.jsxs("div",{className:"relative w-full",children:[e.jsx(As,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{value:r,onChange:A,placeholder:n,className:Z("w-full font-sans outline-none","bg-surface-0 border border-border text-text-0 placeholder:text-text-4","focus:border-accent/40 transition-colors",a?"py-3 pl-11 pr-12 text-[15px] rounded-lg":"py-2.5 pl-10 pr-3 text-sm rounded-md")}),a&&e.jsx("kbd",{className:"absolute right-3.5 top-1/2 -translate-y-1/2 bg-surface-4 text-text-4 px-2 py-0.5 rounded text-xs font-mono",children:"/"})]})}function Hn(){const t=k(s=>s.addToast);return{success:(s,n)=>t("success",s,n),error:(s,n)=>t("error",s,n),info:(s,n)=>t("info",s,n),warning:(s,n)=>t("warning",s,n)}}const rs=p.forwardRef(({className:t,label:s,error:n,mono:a,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[s&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),e.jsx("input",{ref:l,className:Z("h-8 w-full rounded-md px-3 text-sm","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",a?"font-mono":"font-sans",n&&"border-danger focus:ring-danger",t),...r}),n&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));rs.displayName="Input";const Rv=p.forwardRef(({className:t,label:s,error:n,mono:a,...r},l)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[s&&e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:s}),e.jsx("textarea",{ref:l,className:Z("w-full rounded-md px-3 py-2 text-sm resize-none","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors duration-100",a?"font-mono":"font-sans",n&&"border-danger focus:ring-danger",t),...r}),n&&e.jsx("span",{className:"text-2xs text-danger font-sans",children:n})]}));Rv.displayName="Textarea";const EQ=["bg-accent/15 text-accent","bg-purple/15 text-purple","bg-success/15 text-success","bg-warning/15 text-warning","bg-danger/15 text-danger","bg-info/15 text-info"];function Jl({item:t,size:s=48}){const n=Ni[t.id];if(n)return e.jsx("div",{className:"rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0 overflow-hidden",style:{width:s,height:s},children:e.jsx("img",{src:n,alt:t.name,className:"w-6 h-6",onError:l=>{l.target.classList.add("hidden")}})});const a=(t.name||"?")[0].toUpperCase(),r=EQ[(t.name||"").charCodeAt(0)%EQ.length];return e.jsx("div",{className:`rounded-lg flex items-center justify-center flex-shrink-0 text-xl font-bold font-sans ${r}`,style:{width:s,height:s},children:a})}function ob({value:t,onChange:s,placeholder:n,disabled:a}){const[r,l]=p.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsx(rs,{type:r?"text":"password",value:t,onChange:c=>s(c.target.value),placeholder:n,disabled:a,mono:!0,className:"pr-9"}),e.jsx("button",{type:"button",onClick:()=>l(c=>!c),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded text-text-4 hover:text-text-1 transition-colors cursor-pointer",tabIndex:-1,children:r?e.jsx(To,{size:14}):e.jsx(Vs,{size:14})})]})}function qte({integrationId:t,envKey:s,onSaved:n}){const a=Hn(),[r,l]=p.useState(""),[c,A]=p.useState(!1),[f,x]=p.useState(s.set),[h,g]=p.useState(!1);async function O(){if(r.trim()){A(!0);try{await G.post(`/integrations/${t}/credentials`,{key:s.key,value:r.trim()}),x(!0),l(""),a.success(`${s.label} saved`),n==null||n()}catch(v){a.error("Failed to save",v.message)}A(!1)}}async function b(){g(!0);try{await G.delete(`/integrations/${t}/credentials/${s.key}`),x(!1),a.success(`${s.label} removed`),n==null||n()}catch(v){a.error("Failed to remove",v.message)}g(!1)}return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),s.label,s.required&&e.jsx("span",{className:"text-danger",children:"*"})]}),f&&e.jsxs("span",{className:"flex items-center gap-1 text-2xs text-success font-sans",children:[e.jsx(Je,{size:10})," Set"]})]}),f?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-8 rounded-md px-3 bg-surface-2 border border-border-subtle flex items-center",children:e.jsx("span",{className:"text-xs text-text-4 font-mono tracking-widest",children:"*".repeat(16)})}),e.jsx(pe,{variant:"ghost",size:"sm",onClick:b,disabled:h,className:"text-text-3 hover:text-danger",children:h?e.jsx(De,{size:12,className:"animate-spin"}):e.jsx(Ft,{size:12})})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx(ob,{value:r,onChange:l,placeholder:s.placeholder||`Enter ${s.label.toLowerCase()}...`,disabled:c})}),e.jsx(pe,{variant:"primary",size:"sm",onClick:O,disabled:c||!r.trim(),children:c?e.jsx(De,{size:12,className:"animate-spin"}):"Save"})]})]})}function Wte({item:t,status:s,installing:n,onInstall:a,onUninstall:r,onNext:l}){var A;const c=s==null?void 0:s.installed;return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Jl,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:t.name}),(t.verified==="mcp-official"||t.verified==="verified")&&e.jsxs(Te,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(vn,{size:9})," Verified"]})]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:t.author||"Community"}),t.category&&e.jsx(Te,{variant:"default",className:"text-2xs mt-2",children:t.category})]})]}),e.jsx("p",{className:"text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((A=t.tags)==null?void 0:A.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map(f=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:f},f))}),e.jsx("div",{className:"h-px bg-border-subtle"}),c?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsx(Ga,{size:16,className:"text-success"}),e.jsx("span",{className:"text-sm font-medium text-success font-sans",children:"Installed"})]}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:r,className:"text-text-3 hover:text-danger gap-1.5",children:[e.jsx(Ft,{size:12})," Uninstall"]}),e.jsxs(pe,{variant:"primary",size:"sm",onClick:l,className:"gap-1",children:["Configure ",e.jsx(Tt,{size:12})]})]}):e.jsx(pe,{variant:"primary",size:"lg",onClick:a,disabled:n,className:"w-full gap-2",children:n?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"}),"Installing..."]}):"Install"}),n&&e.jsx("p",{className:"text-2xs text-text-4 font-sans text-center",children:"This may take up to 30 seconds..."})]})}function Yte({item:t,onClose:s}){const n=k(j=>j.agents),a=k(j=>j.teams),r=k(j=>j.installViaExistingAgent),l=k(j=>j.spawnIntegrationTeam),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(null),O=n.filter(j=>j.status==="running"||j.status==="idle"),b={};for(const j of O){const N=j.teamId||"_none";b[N]||(b[N]=[]),b[N].push(j)}const v={};for(const j of a)v[j.id]=j.name;async function y(){h&&(await r(t,h),s())}async function S(){x(!0);try{await l(t),s()}catch{x(!1)}}return c?c==="spawn"?e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Spawn Integration Agent"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Creates a team and planner for ",t.name]})]})]}),e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"What happens next"}),e.jsx("ol",{className:"space-y-1.5",children:[`A new team "${t.name}" will be created`,"A planner agent will spawn with full integration context","The agent will handle installation and configuration"].map((j,N)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono flex-shrink-0 w-4 text-right",children:[N+1,"."]}),e.jsx("span",{children:j})]},N))})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{variant:"secondary",size:"lg",onClick:()=>A(null),className:"flex-1",disabled:f,children:"Back"}),e.jsx(pe,{variant:"primary",size:"lg",onClick:S,disabled:f,className:"flex-1 gap-2",children:f?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Spawning..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ei,{size:14})," Spawn Agent"]})})]})]}):e.jsxs("div",{className:"px-5 py-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Choose an Agent"}),e.jsxs("p",{className:"text-2xs text-text-3 font-sans",children:["Send ",t.name," setup instructions to a running agent"]})]})]}),e.jsx(Qt,{className:"max-h-64",children:e.jsx("div",{className:"space-y-3",children:Object.entries(b).map(([j,N])=>e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-1.5 px-1",children:v[j]||"Unassigned"}),e.jsx("div",{className:"space-y-1",children:N.map(C=>e.jsxs("button",{onClick:()=>g(C.id),className:`w-full text-left px-3 py-2.5 rounded-md border transition-all cursor-pointer flex items-center gap-3 ${h===C.id?"border-accent bg-accent/8":"border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-border"}`,children:[e.jsx(qa,{size:14,className:h===C.id?"text-accent":"text-text-4"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:C.name||C.id}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:C.role})]}),h===C.id&&e.jsx(Je,{size:14,className:"text-accent flex-shrink-0"})]},C.id))})]},j))})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{variant:"secondary",size:"lg",onClick:()=>{A(null),g(null)},className:"flex-1",children:"Back"}),e.jsxs(pe,{variant:"primary",size:"lg",onClick:y,disabled:!h,className:"flex-1 gap-2",children:[e.jsx(qa,{size:14})," Send Instructions"]})]})]}):e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Jl,{item:t,size:52}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("h2",{className:"text-base font-bold text-text-0 font-sans",children:["Install ",t.name]}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-0.5",children:"Choose how to set up this integration"})]})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("button",{onClick:()=>O.length>0?A("existing"):null,disabled:O.length===0,className:"w-full text-left px-4 py-3.5 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-accent/30 transition-all cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed group",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0 group-hover:bg-accent/15 transition-colors",children:e.jsx(yn,{size:18,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Use Existing Agent"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:O.length>0?`Send setup instructions to one of ${O.length} running agent${O.length!==1?"s":""}`:"No agents running — spawn one first"})]}),O.length>0&&e.jsx(Tt,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})}),e.jsx("button",{onClick:()=>A("spawn"),className:"w-full text-left px-4 py-3.5 rounded-lg border border-border-subtle bg-surface-2 hover:bg-surface-3 hover:border-accent/30 transition-all cursor-pointer group",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-purple/10 flex items-center justify-center flex-shrink-0 group-hover:bg-purple/15 transition-colors",children:e.jsx(Ei,{size:18,className:"text-purple"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-0 font-sans",children:"Spawn New Agent"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:"Create a dedicated team and planner for this integration"})]}),e.jsx(Tt,{size:14,className:"text-text-4 group-hover:text-accent transition-colors"})]})})]})]})}const Jte={gmail:"Gmail API","google-calendar":"Google Calendar API","google-drive":"Google Drive API","google-docs":"Google Docs API","google-sheets":"Google Sheets API","google-slides":"Google Slides API"};function z4({integrationId:t,onConfigured:s}){const n=Hn(),[a,r]=p.useState(""),[l,c]=p.useState(""),[A,f]=p.useState(!1),x=Jte[t]||"the relevant Google API";async function h(){if(!(!a.trim()||!l.trim())){f(!0);try{await G.post("/integrations/google-oauth/setup",{clientId:a.trim(),clientSecret:l.trim()}),n.success("Google OAuth credentials saved"),s()}catch(O){n.error("Failed to save",O.message)}f(!1)}}const g=[{text:"Go to the Google Cloud Console and sign in with your Google account",link:{url:"https://console.cloud.google.com",label:"Open Google Cloud Console"}},{text:"Create a new project (or select an existing one). Any name is fine — this is just a container for your credentials."},{text:e.jsxs(e.Fragment,{children:["Enable the ",e.jsx("strong",{children:x})," — search for it in the API Library and click ",e.jsx("strong",{children:"Enable"})]}),link:{url:"https://console.cloud.google.com/apis/library",label:"Open API Library"}},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Credentials"})," and click ",e.jsx("strong",{children:"Create Credentials"})," → ",e.jsx("strong",{children:"OAuth client ID"})]}),link:{url:"https://console.cloud.google.com/apis/credentials",label:"Open Credentials page"}},{text:e.jsxs(e.Fragment,{children:["If prompted to configure the consent screen, choose ",e.jsx("strong",{children:"External"}),', fill in an app name (e.g. "Groove"), your email, and save. You can skip optional fields.']})},{text:e.jsxs(e.Fragment,{children:["Go to ",e.jsx("strong",{children:"Audience"})," and click ",e.jsx("strong",{children:"Publish App"}),". Then scroll down to ",e.jsx("strong",{children:"Test users"}),", click ",e.jsx("strong",{children:"Add Users"}),", enter your Google email address, and save."]})},{text:e.jsxs(e.Fragment,{children:["For Application type, choose ",e.jsx("strong",{children:"Desktop app"})," (not Web application). Give it any name."]})},{text:e.jsxs(e.Fragment,{children:["Click ",e.jsx("strong",{children:"Create"}),", then copy the ",e.jsx("strong",{children:"Client ID"})," and ",e.jsx("strong",{children:"Client Secret"})," and paste them below."]})}];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-3",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"How to get your Google credentials"}),e.jsx("ol",{className:"space-y-2.5",children:g.map((O,b)=>e.jsxs("li",{className:"flex gap-2.5 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-accent font-mono font-bold flex-shrink-0 w-4 text-right",children:[b+1,"."]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{children:O.text}),O.link&&e.jsxs("a",{href:O.link.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-2xs text-accent font-sans hover:underline mt-0.5",children:[e.jsx(Ws,{size:9}),O.link.label]}),O.copyable&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("code",{className:"flex-1 min-w-0 text-2xs font-mono text-accent bg-surface-4 px-2.5 py-1.5 rounded select-all break-all",children:O.copyable}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(O.copyable)},className:"flex-shrink-0 p-1.5 rounded text-text-3 hover:text-accent hover:bg-accent/10 transition-colors cursor-pointer",title:"Copy to clipboard",children:e.jsx(Ba,{size:12})})]})]})]},b))})]}),e.jsx("div",{className:"bg-accent/8 border border-accent/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsx("strong",{className:"text-text-1",children:"One-time setup"})," — these same credentials work for Gmail, Calendar, Drive, Docs, Sheets, and Slides. You only need to do this once. For each integration, just enable the matching API in your Google Cloud project."]})}),e.jsx("div",{className:"bg-warning/8 border border-warning/15 rounded-md px-4 py-2.5",children:e.jsxs("p",{className:"text-2xs text-text-2 font-sans leading-relaxed",children:[e.jsx("strong",{className:"text-text-1",children:'Google "unverified app" warning'})," — when signing in, Google may show a warning that the app isn't verified. This is normal for personal OAuth apps. Click ",e.jsx("strong",{children:"Advanced"}),", then ",e.jsx("strong",{children:"Go to [your app name] (unsafe)"})," to continue. Your credentials stay local and are never sent to Groove servers."]})}),e.jsx("div",{className:"h-px bg-border-subtle"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),"Client ID ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(ob,{value:a,onChange:r,placeholder:"123456789.apps.googleusercontent.com",disabled:A})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-text-2 font-sans flex items-center gap-1.5",children:[e.jsx(Ti,{size:11,className:"text-text-4"}),"Client Secret ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(ob,{value:l,onChange:c,placeholder:"GOCSPX-...",disabled:A})]})]}),e.jsx(pe,{variant:"primary",size:"lg",onClick:h,disabled:A||!a.trim()||!l.trim(),className:"w-full gap-2",children:A?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Saving..."]}):"Save Credentials"})]})}function ese({item:t,status:s,onDone:n,onRefreshStatus:a}){var S;const r=Hn(),[l,c]=p.useState(!1),[A,f]=p.useState(null),x=t.authType,h=x==="google-autoauth"||x==="oauth-google";p.useEffect(()=>{h&&G.get("/integrations/google-oauth/status").then(j=>f(j.configured)).catch(()=>f(!1))},[h]);const g=p.useRef(null);p.useEffect(()=>()=>{g.current&&clearInterval(g.current)},[]);async function O(){c(!0);try{const j=await G.post(`/integrations/${t.id}/oauth/start`);if(j.url){const N=await ON(j.url);if(N!=null&&N.error){r.error("Sign-in failed",N.error),c(!1);return}r.success("Browser opened — complete sign-in there");let C=0;g.current&&clearInterval(g.current),g.current=setInterval(async()=>{if(C+=2e3,C>6e4){clearInterval(g.current),g.current=null,c(!1);return}try{const U=await G.get(`/integrations/${t.id}/status`);((U==null?void 0:U.envKeys)||[]).some(B=>B.key==="GOOGLE_REFRESH_TOKEN"&&B.set)&&(clearInterval(g.current),g.current=null,r.success("Connected!",`${t.name} is now authenticated`),a(),c(!1))}catch{}},2e3)}}catch(j){r.error("Sign-in failed",j.message),c(!1)}}const b=(s==null?void 0:s.envKeys)||[],v=b.filter(j=>j.required&&!j.hidden),y=v.length===0||v.every(j=>j.set);return e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Jl,{item:t,size:36}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm font-bold text-text-0 font-sans",children:["Configure ",t.name]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Set up credentials to connect"})]})]}),((S=t.setupSteps)==null?void 0:S.length)>0&&!(h&&A===!1)&&e.jsxs("div",{className:"bg-surface-2 rounded-md px-4 py-3 space-y-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-1 font-sans",children:"Setup guide"}),e.jsx("ol",{className:"space-y-1.5",children:t.setupSteps.map((j,N)=>e.jsxs("li",{className:"flex gap-2 text-xs text-text-2 font-sans leading-relaxed",children:[e.jsxs("span",{className:"text-text-4 font-mono flex-shrink-0 w-4 text-right",children:[N+1,"."]}),e.jsx("span",{children:j})]},N))}),t.setupUrl&&e.jsxs("a",{href:t.setupUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-accent font-sans hover:underline mt-1",children:[e.jsx(Ws,{size:11}),new URL(t.setupUrl).hostname]})]}),!(h&&A===!1)&&e.jsx("div",{className:"h-px bg-border-subtle"}),x==="api-key"&&e.jsx("div",{className:"space-y-4",children:b.filter(j=>!j.hidden).map(j=>e.jsx(qte,{integrationId:t.id,envKey:j,onSaved:a},j.key))}),h&&A===!1&&e.jsx(z4,{integrationId:t.id,onConfigured:()=>f(!0)}),h&&A&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(pe,{variant:"primary",size:"lg",onClick:O,disabled:l,className:"w-full gap-2",children:l?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"}),"Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["A browser window will open — sign in and allow access to your ",t.name]}),e.jsx("button",{type:"button",onClick:()=>f(!1),className:"w-full text-2xs text-text-4 font-sans hover:text-text-2 transition-colors cursor-pointer py-1",children:"Reconfigure Google OAuth credentials"})]}),h&&A===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(De,{size:16,className:"animate-spin text-text-4"})}),e.jsx(pe,{variant:y?"primary":"secondary",size:"lg",onClick:n,className:"w-full gap-1.5",children:y?e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:14}),"Done"]}):"Skip for now"})]})}function tse({item:t,onClose:s}){return e.jsxs("div",{className:"px-5 py-10 flex flex-col items-center text-center space-y-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Ga,{size:28,className:"text-success"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-bold text-text-0 font-sans",children:"Integration ready"}),e.jsxs("p",{className:"text-sm text-text-3 font-sans mt-1",children:[t.name," is installed and configured. Agents can now use it."]})]}),e.jsx(pe,{variant:"primary",size:"lg",onClick:s,className:"mt-2",children:"Close"})]})}function _4({integration:t,open:s,onClose:n}){const a=Hn(),[r,l]=p.useState("overview"),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(!0),O=t==null?void 0:t.id,b=p.useCallback(async()=>{if(O){try{const C=await G.get(`/integrations/${O}/status`);A(C)}catch{A(null)}g(!1)}},[O]);p.useEffect(()=>{s&&t&&(l("overview"),g(!0),b())},[s,t,b]);function v(){l("agent-setup")}async function y(){try{await G.delete(`/integrations/${t.id}`),a.success(`${t.name} uninstalled`),await b()}catch(C){a.error("Uninstall failed",C.message)}}function S(){l("configure")}function j(){l("done")}if(!t)return null;const N={overview:t.name,"agent-setup":"Install",configure:"Configure",done:"Complete"};return e.jsx(Vt,{open:s,onOpenChange:C=>{C||n()},children:e.jsx(Kt,{title:N[r]||t.name,description:`Setup wizard for ${t.name}`,className:"max-w-md",children:h?e.jsx("div",{className:"px-5 py-10 flex items-center justify-center",children:e.jsx(De,{size:20,className:"animate-spin text-text-4"})}):r==="overview"?e.jsx(Wte,{item:t,status:c,installing:f,onInstall:v,onUninstall:y,onNext:S}):r==="agent-setup"?e.jsx(Yte,{item:t,onClose:n}):r==="configure"?e.jsx(ese,{item:t,status:c,onDone:j,onRefreshStatus:b}):e.jsx(tse,{item:t,onClose:n})})})}const sse=["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"];function nse({item:t,status:s,onInstall:n,onUninstall:a,busy:r}){const l=s==null?void 0:s.installed,c=s==null?void 0:s.authenticated;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-2 border border-border-subtle",children:[e.jsx(Jl,{item:t,size:32}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:t.name}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:t.description})]}),l&&c&&!(s!=null&&s.needsReauth)&&e.jsxs(Te,{variant:"success",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Je,{size:8})," Ready"]}),l&&c&&(s==null?void 0:s.needsReauth)&&e.jsxs(Te,{variant:"warning",className:"text-2xs flex-shrink-0 gap-1",children:[e.jsx(Ls,{size:8})," Update"]}),l&&!c&&e.jsx(Te,{variant:"warning",className:"text-2xs flex-shrink-0",children:"Needs sign-in"}),e.jsx(pe,{variant:l?"ghost":"primary",size:"sm",onClick:()=>l?a(t.id):n(t.id),disabled:r===t.id,className:l?"text-text-3 hover:text-danger":"",children:r===t.id?e.jsx(De,{size:12,className:"animate-spin"}):l?e.jsx(Ft,{size:12}):"Install"})]})}function ase({integrations:t,open:s,onClose:n}){const a=Hn(),[r,l]=p.useState(null),[c,A]=p.useState({}),[f,x]=p.useState(null),[h,g]=p.useState(!1),[O,b]=p.useState(!0),v=p.useRef(null),y=t.filter(B=>sse.includes(B.id)),S=p.useCallback(async()=>{const B={};await Promise.all(y.map(async F=>{try{B[F.id]=await G.get(`/integrations/${F.id}/status`)}catch{B[F.id]=null}})),A(B),b(!1)},[y.map(B=>B.id).join(",")]);p.useEffect(()=>(s&&(b(!0),G.get("/integrations/google-oauth/status").then(B=>l(B.configured)).catch(()=>l(!1)),S()),()=>{v.current&&clearInterval(v.current)}),[s]);const j=Object.entries(c).filter(([,B])=>B==null?void 0:B.installed).map(([B])=>B),N=j.length>0&&j.every(B=>{var F;return(F=c[B])==null?void 0:F.authenticated});j.some(B=>{var F;return!((F=c[B])!=null&&F.authenticated)});const C=N&&j.some(B=>{var F;return(F=c[B])==null?void 0:F.needsReauth});async function U(B){var F;x(B);try{await G.post(`/integrations/${B}/install`),a.success(`${(F=y.find(M=>M.id===B))==null?void 0:F.name} installed`),await S()}catch(M){a.error("Install failed",M.message)}x(null)}async function P(B){var F;x(B);try{await G.delete(`/integrations/${B}`),a.success(`${(F=y.find(M=>M.id===B))==null?void 0:F.name} removed`),await S()}catch(M){a.error("Uninstall failed",M.message)}x(null)}async function T(){if(!j.length){a.error("Install at least one service first");return}g(!0);try{const B=await G.post("/integrations/google-workspace/oauth/start",{integrationIds:j});if(B.url){const F=await ON(B.url);if(F!=null&&F.error){a.error("Sign-in failed",F.error),g(!1);return}a.success("Browser opened — complete sign-in there"),v.current&&clearInterval(v.current),v.current=setInterval(async()=>{await S()},3e3),setTimeout(()=>{v.current&&clearInterval(v.current)},18e4)}}catch(B){a.error("Sign-in failed",B.message)}g(!1)}return p.useEffect(()=>{N&&v.current&&(clearInterval(v.current),v.current=null)},[N]),s?e.jsx(Vt,{open:s,onOpenChange:B=>{B||n()},children:e.jsx(Kt,{title:"Google Workspace",description:"Connect your Google services",className:"max-w-md",children:e.jsxs("div",{className:"px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg bg-surface-4 flex items-center justify-center flex-shrink-0",children:e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"Google",className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans",children:"Google Workspace"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"One set of credentials for all Google services"})]})]}),r===!1&&e.jsx(z4,{integrationId:"gmail",onConfigured:()=>l(!0)}),r===null&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(De,{size:16,className:"animate-spin text-text-4"})}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans",children:"Services"}),e.jsx("div",{className:"space-y-1.5",children:O?Array.from({length:4}).map((B,F)=>e.jsx("div",{className:"h-14 rounded-md bg-surface-2 animate-pulse"},F)):y.map(B=>e.jsx(nse,{item:B,status:c[B.id],onInstall:U,onUninstall:P,busy:f},B.id))})]}),e.jsx("div",{className:"h-px bg-border-subtle"}),j.length>0&&!N&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(pe,{variant:"primary",size:"lg",onClick:T,disabled:h,className:"w-full gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:"https://cdn.simpleicons.org/google/white",alt:"",className:"w-4 h-4"}),"Sign in with Google"]})}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans text-center",children:["Connects ",j.length," service",j.length!==1?"s":""," with one sign-in"]})]}),N&&j.length>0&&e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-success/15 flex items-center justify-center",children:e.jsx(Ga,{size:20,className:"text-success"})}),e.jsx("p",{className:"text-sm font-medium text-success font-sans",children:"All services connected"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Your agents can now use these Google integrations."}),C?e.jsxs("div",{className:"w-full space-y-2 pt-2",children:[e.jsx("p",{className:"text-2xs text-warning font-sans",children:"New permissions available — re-authenticate to enable all features."}),e.jsx(pe,{variant:"secondary",size:"sm",onClick:T,disabled:h,className:"w-full gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12,className:"animate-spin"})," Opening browser..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ls,{size:12})," Re-authenticate"]})})]}):e.jsx("button",{onClick:T,disabled:h,className:"text-2xs text-text-4 hover:text-text-2 font-sans underline underline-offset-2 transition-colors mt-1",children:h?"Opening browser...":"Re-authenticate"})]}),j.length===0&&!O&&e.jsx("p",{className:"text-xs text-text-4 font-sans text-center py-2",children:"Install at least one service above, then connect with Google."})]}),e.jsx(pe,{variant:"secondary",size:"lg",onClick:n,className:"w-full",children:N&&j.length>0?"Done":"Close"})]})})}):null}const Hg=/github\.com\/([^/]+)\/([^/\s#?]+)/;function rse(){const[t,s]=p.useState("input"),[n,a]=p.useState(""),[r,l]=p.useState(!1),[c,A]=p.useState(null),[f,x]=p.useState("standalone"),[h,g]=p.useState(""),[O,b]=p.useState(!0),[v,y]=p.useState(""),S=k(B=>B.previewRepo),j=k(B=>B.importRepo),N=k(B=>B.importInProgress),C=Hn(),U=p.useCallback(async B=>{const F=B.match(Hg);if(F){l(!0);try{const M=await S(B);A(M),y(M.name||F[2]),s("preview")}catch(M){C.error("Preview failed",M.message)}finally{l(!1)}}},[S,C]),P=p.useCallback(B=>{const F=B.target.value;a(F),Hg.test(F)&&t==="input"&&U(F)},[t,U]),T=p.useCallback(async()=>{if(!c)return;let B;f==="standalone"?B=`~/Projects/${c.name}`:f==="subdirectory"?B=`./packages/${c.name}`:B=h;try{await j(n,B,O,v),C.success(`Importing ${c.name}`,"Setup agent will handle the rest"),s("input"),a(""),A(null)}catch(F){C.error("Import failed",F.message)}},[c,f,h,n,O,v,j,C]);if(t==="input")return e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"}),e.jsx("input",{type:"text",value:n,onChange:P,placeholder:"Paste a GitHub URL...",className:Z("w-full h-9 rounded-lg pl-9 pr-20 text-sm font-sans","bg-surface-1 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors duration-100")}),e.jsx(pe,{variant:"primary",size:"sm",className:"absolute right-1.5 top-1/2 -translate-y-1/2",onClick:()=>U(n),disabled:!Hg.test(n)||r,children:r?e.jsx(De,{size:12,className:"animate-spin"}):"Preview"})]});if(t==="preview"&&c)return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-accent/8 flex items-center justify-center flex-shrink-0",children:e.jsx(Kl,{size:22,className:"text-accent"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5 mb-1",children:[e.jsx("span",{className:"text-lg font-bold text-text-0 font-sans",children:c.name}),e.jsx("span",{className:"text-xs text-text-4 font-sans",children:c.owner})]}),e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[c.language&&e.jsx(Te,{variant:"outline",className:"text-2xs",children:c.language}),c.stars!=null&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Lb,{size:10,className:"text-warning",fill:"currentColor"}),jt(c.stars)]}),c.license&&e.jsx("span",{children:c.license})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(pe,{variant:"primary",size:"sm",onClick:()=>s("configure"),className:"h-8 text-xs gap-1.5 px-4",children:[e.jsx(Ys,{size:13}),"Clone & Setup"]}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>{try{const B=n.startsWith("http")?n:`https://${n}`,F=new URL(B);(F.protocol==="https:"||F.protocol==="http:")&&window.open(B,"_blank")}catch{}},className:"h-8 text-xs gap-1.5",children:[e.jsx(Ws,{size:12}),"GitHub"]}),e.jsx("button",{onClick:()=>{s("input"),A(null)},className:"text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 ml-1",children:"Cancel"})]})]})}),c.description&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2",children:"About"}),e.jsx("p",{className:"text-sm text-text-1 font-sans leading-relaxed",children:c.description})]}),c.readmePreview&&e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-1 px-5 py-4",children:[e.jsx("h4",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-3",children:"README"}),e.jsx("div",{className:"text-sm text-text-2 font-sans leading-relaxed whitespace-pre-wrap",children:c.readmePreview})]})]});if(t==="configure"&&c){const B=[{id:"standalone",icon:xd,title:"Standalone project",description:"Clone to its own directory, separate from this workspace",path:`~/Projects/${c.name}`},{id:"subdirectory",icon:zb,title:"Workspace package",description:"Add as a package inside this project's monorepo",path:`./packages/${c.name}`},{id:"custom",icon:RS,title:"Custom location",description:"Choose your own path",path:null}];return e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface-2 overflow-hidden",children:[e.jsx("div",{className:"px-5 py-4 border-b border-border-subtle bg-surface-3/50",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(qs,{size:16,className:"text-accent"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-text-0 font-sans",children:["Clone ",c.name]}),e.jsxs("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:[c.owner,"/",c.name," — configure where to install"]})]})]})}),e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider mb-2.5 block",children:"Install location"}),e.jsx("div",{className:"space-y-2",children:B.map(F=>{const M=F.icon,R=f===F.id;return e.jsx("button",{onClick:()=>x(F.id),className:Z("w-full text-left rounded-lg border p-3.5 transition-all duration-150 cursor-pointer",R?"border-accent bg-accent/5 ring-1 ring-accent/30":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-1/80"),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:Z("w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0 mt-0.5",R?"bg-accent/15 text-accent":"bg-surface-3 text-text-4"),children:e.jsx(M,{size:15})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:Z("text-xs font-semibold font-sans",R?"text-text-0":"text-text-2"),children:F.title}),R&&e.jsx("div",{className:"w-4 h-4 rounded-full bg-accent flex items-center justify-center",children:e.jsx(Je,{size:10,className:"text-white"})})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5 leading-relaxed",children:F.description}),F.path&&R&&e.jsx("code",{className:"text-2xs text-accent/80 font-mono mt-1.5 block truncate",children:F.path})]})]})},F.id)})}),f==="custom"&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:h,onChange:F=>g(F.target.value),placeholder:"/path/to/clone",autoFocus:!0,className:Z("w-full h-9 px-3 text-xs font-mono rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-surface-3 flex items-center justify-center",children:e.jsx(yn,{size:14,className:"text-text-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans block",children:"Create a team"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Organize agents working on this repo into their own team"})]})]}),e.jsx("button",{onClick:()=>b(!O),className:Z("w-9 h-5 rounded-full p-0.5 transition-colors cursor-pointer flex-shrink-0",O?"bg-accent":"bg-surface-5"),children:e.jsx("div",{className:Z("w-4 h-4 rounded-full bg-white shadow-sm transition-transform",O?"translate-x-4":"translate-x-0")})})]}),O&&e.jsx("div",{className:"mt-2.5 ml-11",children:e.jsx("input",{value:v,onChange:F=>y(F.target.value),placeholder:"Team name",className:Z("w-full h-9 px-3 text-xs font-sans rounded-md","bg-surface-0 border border-border text-text-0","placeholder:text-text-4","focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent","transition-colors")})})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle bg-surface-3/30 flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>s("preview"),className:"flex items-center gap-1.5 text-2xs text-text-4 font-sans hover:text-text-2 cursor-pointer bg-transparent border-0 transition-colors",children:[e.jsx(kb,{size:11}),"Back"]}),e.jsx(pe,{variant:"primary",size:"sm",onClick:T,disabled:N||f==="custom"&&!h.trim(),className:"h-8 text-xs gap-1.5 px-5",children:N?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:12,className:"animate-spin"})," Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(qs,{size:12})," Clone & Setup"]})})]})]})}return null}function ose({repo:t,onRemove:s,onNuke:n,onOpen:a}){return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-2 p-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:t.repoName||t.name}),e.jsx("span",{className:"text-2xs text-text-3 font-sans",children:t.repoOwner||t.owner})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[t.language&&e.jsx(Te,{variant:"outline",className:"text-2xs",children:t.language}),e.jsx("span",{className:"text-2xs text-text-4 font-mono truncate max-w-[180px]",children:t.clonedTo||t.path})]}),e.jsx("span",{className:"text-2xs text-text-4 font-sans mt-0.5 block",children:t.clonedAt?`Imported ${$t(t.clonedAt)}`:t.status||""})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a&&e.jsxs("button",{onClick:()=>a(t),className:Z("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-accent bg-accent/10 hover:bg-accent/20 border-0 transition-colors"),children:[e.jsx(Ys,{size:11}),"Open"]}),s&&e.jsxs("button",{onClick:()=>s(t),className:Z("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-text-3 hover:text-text-1 hover:bg-surface-4 bg-transparent border-0 transition-colors"),children:[e.jsx(Ft,{size:11}),"Remove"]}),n&&e.jsxs("button",{onClick:()=>n(t),className:Z("flex items-center gap-1 px-2 py-1 rounded text-2xs font-sans cursor-pointer","text-danger bg-danger/10 hover:bg-danger/20 border-0 transition-colors"),children:[e.jsx(_$,{size:11}),"Nuke"]})]})]})}function ise({repo:t,open:s,onClose:n,onConfirm:a}){var h,g,O;const[r,l]=p.useState(!0);if(!t)return null;const c=((h=t.agents)==null?void 0:h.length)||0,A=((g=t.processes)==null?void 0:g.length)||0,f=((O=t.credentialKeys)==null?void 0:O.length)||0,x=t.fileCount||0;return e.jsx(Vt,{open:s,onOpenChange:b=>{b||n()},children:e.jsx(Kt,{title:`Nuke ${t.repoName||t.name}?`,description:"Confirm destructive removal of imported repo",children:e.jsxs("div",{className:"px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Aa,{size:16,className:"text-danger flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-text-1 font-sans",children:"This cannot be undone."})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-text-2 font-sans",children:[c>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Kill ",c," agent",c!==1?"s":""]}),A>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Stop ",A," process",A!==1?"es":""]}),f>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Remove ",f," credential",f!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"}),' Delete team "',t.teamId||t.repoName||t.name,'"']}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-success",children:"✓"})," Clean all .groove state"]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:b=>l(b.target.checked),className:"accent-[var(--color-danger)]"}),e.jsxs("span",{className:"text-xs text-text-1 font-sans",children:["Delete repo files",x>0?` (${x} files)`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(pe,{variant:"danger",size:"sm",onClick:()=>a(r),children:"Nuke Everything"}),e.jsx(pe,{variant:"ghost",size:"sm",onClick:n,children:"Cancel"})]})]})})})}function lse({skill:t,onBack:s}){var P,T,B;const n=Hn(),[a,r]=p.useState(""),[l,c]=p.useState(!1),[A,f]=p.useState(!1),[x,h]=p.useState(!1),[g,O]=p.useState(!1),[b,v]=p.useState(t.installed),[y,S]=p.useState(!0);p.useEffect(()=>{S(!0),G.get(`/skills/${t.id}/content`).then(F=>{r(F.content||""),c(F.requiresPurchase||!1)}).catch(()=>{}).finally(()=>S(!1))},[t.id]);async function j(){f(!0);try{await G.post(`/skills/${t.id}/install`),v(!0),n.success(`${t.name} installed`)}catch(F){n.error("Install failed",F.message)}f(!1)}async function N(){h(!0);try{await G.post(`/skills/${t.id}/update`),n.success(`${t.name} updated to latest`);const F=await G.get(`/skills/${t.id}/content`);F.content&&r(F.content)}catch(F){n.error("Update failed",F.message)}h(!1)}async function C(){O(!0);try{await G.delete(`/skills/${t.id}`),v(!1),n.success(`${t.name} uninstalled`)}catch(F){n.error("Uninstall failed",F.message)}O(!1)}async function U(){const{marketplaceAuthenticated:F,marketplaceLogin:M,marketplaceCheckout:R}=k.getState();if(!F){M();return}try{await R(t.id)}catch{}}return e.jsx(Qt,{className:"h-full",children:e.jsxs("div",{className:"px-6 py-5",children:[e.jsxs("button",{onClick:s,className:"flex items-center gap-1 text-xs text-text-3 font-sans hover:text-text-0 cursor-pointer bg-transparent border-0 mb-4",children:[e.jsx(Di,{size:14})," Back"]}),e.jsxs("div",{className:"flex gap-8",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-lg flex items-center justify-center flex-shrink-0 bg-accent/10 border border-accent/20 text-[22px]",children:t.icon||((T=(P=t.name)==null?void 0:P[0])==null?void 0:T.toUpperCase())}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-lg font-bold text-text-0 font-sans",children:t.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-xs text-text-3 font-sans",children:[e.jsx("span",{children:t.author||"Community"}),(t.source==="claude-official"||t.verified)&&e.jsx(Zte,{type:t.source,size:13})]})]})]}),e.jsx("p",{className:"mt-3 text-sm text-text-2 font-sans leading-relaxed",children:t.description}),((B=t.tags)==null?void 0:B.length)>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:t.tags.map(F=>e.jsx("span",{className:"text-2xs text-text-3 font-sans px-2 py-0.5 rounded bg-surface-4",children:F},F))}),e.jsx("div",{className:"h-px bg-border-subtle my-5"}),y?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-3 w-48 bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-full bg-surface-4 rounded animate-pulse"}),e.jsx("div",{className:"h-3 w-3/4 bg-surface-4 rounded animate-pulse"})]}):a?e.jsxs("div",{className:"text-sm text-text-2 font-sans leading-relaxed",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 mb-2",children:"About"}),e.jsx("pre",{className:"whitespace-pre-wrap font-sans",children:a})]}):l?e.jsxs("div",{className:"bg-warning/5 border border-warning/15 rounded-lg px-4 py-3",children:[e.jsx("p",{className:"text-sm text-text-1 font-sans font-medium",children:"Paid skill — purchase to view content"}),e.jsx("p",{className:"text-xs text-text-3 font-sans mt-1",children:"Sign in and purchase this skill to access its full instructions."})]}):e.jsx("p",{className:"text-xs text-text-4 font-sans",children:"Content loading failed — check your connection."})]}),e.jsx("div",{className:"w-[240px] flex-shrink-0",children:e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-lg p-4 sticky top-4",children:[e.jsx(Gte,{price:t.price||0,size:"md"}),l&&!b?e.jsxs("button",{onClick:U,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 flex items-center justify-center gap-2 border bg-warning/15 text-warning border-warning/20 hover:bg-warning/25",children:["Buy $",(t.price||0).toFixed(2)]}):b?e.jsxs("div",{className:"mt-3 flex flex-col gap-1.5",children:[e.jsxs("button",{onClick:N,disabled:x,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:[e.jsx(Ls,{size:12,className:x?"animate-spin":""}),x?"Updating...":"Pull Latest"]}),e.jsxs("button",{onClick:C,disabled:g,className:"w-full py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-error/10 text-error border-error/20 hover:bg-error/15",children:[e.jsx(Ft,{size:12}),g?"Removing...":"Uninstall"]})]}):e.jsx("button",{onClick:j,disabled:A,className:"w-full mt-3 py-2 px-3 text-xs font-sans font-semibold rounded cursor-pointer transition-all hover:opacity-85 disabled:opacity-60 disabled:cursor-not-allowed flex items-center justify-center gap-2 border bg-accent/15 text-accent border-accent/20 hover:bg-accent/25",children:A?"Installing...":"Install"}),e.jsx("div",{className:"mt-4 flex flex-col gap-2.5",children:[["Downloads",e.jsx("span",{className:"font-mono text-text-0",children:jt(t.downloads||0)},"d")],["Rating",e.jsx(Hte,{rating:t.rating||0,count:t.rating_count||t.ratingCount,size:"sm"},"r")],["Version",e.jsx("span",{className:"font-mono text-text-0",children:t.version||"1.0.0"},"v")],["Category",e.jsx(Xte,{label:t.category||"general",variant:t.category||"draft"},"c")],["Source",e.jsx("span",{className:"text-text-0",children:t.source==="claude-official"?"Anthropic":"Community"},"s")]].map(([F,M])=>e.jsxs("div",{className:"flex justify-between items-center text-xs font-sans",children:[e.jsx("span",{className:"text-text-3",children:F}),M]},F))})]})})]})]})})}function cse({open:t,onClose:s}){const[n,a]=p.useState("new"),[r,l]=p.useState(""),[c,A]=p.useState(""),[f,x]=p.useState(""),[h,g]=p.useState(""),[O,b]=p.useState(""),[v,y]=p.useState(!1),S=k(M=>M.teams),j=k(M=>M.activeTeamId),N=k(M=>M.createTeam),C=k(M=>M.spawnAgent),U=k(M=>M.setActiveView),P=k(M=>M.selectAgent),T=Hn();p.useEffect(()=>{t&&(a("new"),l(""),A(j||""),x(""),g(""),b(""),y(!1))},[t,j]);async function B(){if(f.trim()){y(!0);try{let M;n==="new"?M=(await N(r.trim()||f.trim())).id:M=c;const R=[`The user wants to integrate the **${f.trim()}** API into their project.`,""];h.trim()&&R.push(`**API Documentation:** ${h.trim()}`),O.trim()&&R.push("**API Key:** The user has provided an API key. Store it securely using environment variables — never hardcode it."),R.push("","Start by:","1. Reviewing the API documentation to understand available endpoints and authentication","2. Asking the user what they want to build with this API","3. Setting up the necessary configuration and authentication","4. Building the integration together","","Ask the user about their project and how they'd like to use this API.");const Y=R.join(`
1013
1013
  `),W=await C({role:"fullstack",prompt:Y,teamId:M});O.trim()&&await G.post(`/agents/${W.id}/instruct`,{message:`Here is the API key for ${f.trim()}: \`${O.trim()}\`
1014
1014
 
1015
1015
  Store this in a .env file as an environment variable. Do not commit it to git.`}).catch(()=>{}),U("agents"),P(W.id),s()}catch(M){T("error","Failed to start integration",M.message),y(!1)}}}const F=f.trim()&&(n==="new"||c);return e.jsx(Vt,{open:t,onOpenChange:M=>!M&&s(),children:e.jsx(Kt,{title:"New Integration",description:"Set up a custom API integration",children:e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[e.jsx(rs,{label:"Integration name",placeholder:"e.g. NASA APOD, Stripe, Twilio…",value:f,onChange:M=>x(M.target.value),autoFocus:!0}),e.jsx(rs,{label:"Documentation URL",placeholder:"https://api.example.com/docs",value:h,onChange:M=>g(M.target.value)}),e.jsx(rs,{label:"API key (optional)",placeholder:"sk-...",value:O,onChange:M=>b(M.target.value),mono:!0,type:"password"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-text-2 font-sans",children:"Team"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>a("new"),className:`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-md text-xs font-medium font-sans border transition-colors cursor-pointer ${n==="new"?"border-accent bg-accent/10 text-accent":"border-border bg-surface-0 text-text-2 hover:border-accent/50"}`,children:[e.jsx(it,{size:12}),"New team"]}),e.jsxs("button",{onClick:()=>a("existing"),className:`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-md text-xs font-medium font-sans border transition-colors cursor-pointer ${n==="existing"?"border-accent bg-accent/10 text-accent":"border-border bg-surface-0 text-text-2 hover:border-accent/50"}`,children:[e.jsx(yn,{size:12}),"Existing team"]})]}),n==="new"?e.jsx(rs,{placeholder:f?f.trim():"Team name (defaults to integration name)",value:r,onChange:M=>l(M.target.value)}):e.jsxs("select",{value:c,onChange:M=>A(M.target.value),className:"h-8 w-full rounded-md px-3 text-sm font-sans bg-surface-1 border border-border text-text-0 focus:outline-none focus:ring-1 focus:ring-accent focus:border-accent cursor-pointer",children:[e.jsx("option",{value:"",children:"Select a team…"}),S.map(M=>e.jsx("option",{value:M.id,children:M.name},M.id))]})]}),e.jsx(pe,{onClick:B,disabled:!F||v,className:"w-full mt-1",children:v?e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14,className:"animate-spin"})," Setting up…"]}):"Go"})]})})})}const PQ=new Set(["gmail","google-calendar","google-drive","google-docs","google-sheets","google-slides"]);function Ase(){const[t,s]=p.useState([]),[n,a]=p.useState(!0),[r,l]=p.useState(""),[c,A]=p.useState(null),[f,x]=p.useState(!1),[h,g]=p.useState(!1),[O,b]=p.useState(!1),v=()=>{a(!0),G.get(`/integrations/registry?search=${encodeURIComponent(r)}`).then(P=>s(P.integrations||P.items||(Array.isArray(P)?P:[]))).catch(()=>s([])).finally(()=>a(!1))};p.useEffect(()=>{v()},[r]);const y=t.filter(P=>PQ.has(P.id)),S=t.filter(P=>!PQ.has(P.id)),j=y.filter(P=>P.installed).length;function N(P){A(P),x(!0)}function C(){x(!1),A(null),v()}const U=!r||"google workspace gmail calendar drive docs sheets slides".includes(r.toLowerCase());return e.jsxs(Qt,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-72",children:e.jsx(I4,{value:r,onChange:l,placeholder:"Search integrations..."})}),e.jsx("div",{className:"flex-1"}),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>b(!0),className:"gap-1 text-xs",children:[e.jsx(it,{size:13}),"New"]}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:S.length+(y.length>0?1:0)})]}),e.jsx("div",{className:"mt-4 grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:n?Array.from({length:6}).map((P,T)=>e.jsx(Vte,{},T)):e.jsxs(e.Fragment,{children:[y.length>0&&U&&e.jsx(Ux,{item:{id:"google-workspace",name:"Google Workspace",description:"Gmail, Calendar, Drive, Docs, Sheets, Slides — one sign-in for all",category:"productivity",tags:["google","email","calendar","drive","docs"],verified:"mcp-official",installed:j>0,_installedCount:j},onClick:()=>g(!0)},"google-workspace"),S.map(P=>e.jsx(Ux,{item:P,onClick:()=>N(P)},P.id))]})}),!n&&S.length===0&&y.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No integrations found."})]}),e.jsx(_4,{integration:c,open:f,onClose:C}),e.jsx(ase,{integrations:t,open:h,onClose:()=>{g(!1),v()}}),e.jsx(cse,{open:O,onClose:()=>b(!1)})]})}function dse(){const t=k(K=>K.marketplaceAuthenticated),s=k(K=>K.marketplaceLogin),[n,a]=p.useState([]),[r,l]=p.useState([]),[c,A]=p.useState([]),[f,x]=p.useState(!0),[h,g]=p.useState("all"),[O,b]=p.useState(""),[v,y]=p.useState(null),[S,j]=p.useState(null),[N,C]=p.useState(!1),U=Hn(),P=p.useRef(null),T=async()=>{const[K,_]=await Promise.all([G.get("/skills/installed").catch(()=>[]),G.get("/integrations/installed").catch(()=>[])]);l(Array.isArray(K)?K:K.skills||[]),A(Array.isArray(_)?_:_.integrations||[])};p.useEffect(()=>{x(!0),Promise.all([t?G.get("/auth/purchases").then(K=>K.purchases||[]).catch(()=>[]):Promise.resolve([]),G.get("/skills/installed").then(K=>Array.isArray(K)?K:K.skills||[]).catch(()=>[]),G.get("/integrations/installed").then(K=>Array.isArray(K)?K:K.integrations||[]).catch(()=>[])]).then(([K,_,E])=>{a(K),l(_),A(E)}).finally(()=>x(!1))},[t]);async function B(K){var E;const _=(E=K.target.files)==null?void 0:E[0];if(_){try{const q=await _.text(),H=_.name.replace(/\.md$/i,"");await G.post("/skills/import",{name:H,content:q}),U.success(`Imported "${H}"`),await T()}catch(q){U.error("Import failed",q.message)}K.target.value=""}}if(v)return e.jsx(lse,{skill:v,onBack:()=>y(null)});const F=O.toLowerCase(),M=h==="all"||h==="skills"?r.filter(K=>!F||(K.name||K.id||"").toLowerCase().includes(F)||(K.description||"").toLowerCase().includes(F)):[],R=h==="all"||h==="integrations"?c.filter(K=>!F||(K.name||K.id||"").toLowerCase().includes(F)||(K.description||"").toLowerCase().includes(F)):[],Y=[...M.map(K=>({...K,_type:"skill"})),...R.map(K=>({...K,_type:"integration"}))],W=[{id:"all",label:"All"},{id:"skills",label:"Skills"},{id:"integrations",label:"Integrations"}],ee={all:"No skills or integrations installed yet. Visit the Marketplace to get started.",skills:"No skills installed.",integrations:"No integrations installed."};return f?e.jsx("div",{className:"p-5 space-y-3",children:[...Array(4)].map((K,_)=>e.jsx(ia,{className:"h-14 rounded-md"},_))}):e.jsxs(Qt,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("div",{className:"w-72",children:e.jsx(I4,{value:O,onChange:b,placeholder:"Search library..."})}),e.jsx("div",{className:"flex items-center gap-1",children:W.map(K=>e.jsx("button",{onClick:()=>g(K.id),className:`px-3 py-1.5 text-xs font-semibold font-sans rounded-full cursor-pointer select-none transition-colors ${h===K.id?"bg-accent/15 text-accent border border-accent/25":"text-text-3 hover:text-text-1 border border-transparent hover:border-border-subtle"}`,children:K.label},K.id))}),e.jsx("div",{className:"flex-1"}),e.jsx("input",{ref:P,type:"file",accept:".md",onChange:B,className:"hidden"}),e.jsxs(pe,{variant:"secondary",size:"md",onClick:()=>{var K;return(K=P.current)==null?void 0:K.click()},className:"gap-1.5",children:[e.jsx(Hb,{size:13}),"Import .md"]}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0",children:Y.length})]}),t&&n.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[e.jsx(Lp,{size:12}),"Purchases (",n.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:n.map(K=>{var _,E;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-md bg-surface-1 border border-border-subtle",children:[e.jsx("div",{className:"w-8 h-8 rounded-md bg-accent/10 flex items-center justify-center text-sm flex-shrink-0",children:K.skill_icon||((E=(_=K.skill_name)==null?void 0:_[0])==null?void 0:E.toUpperCase())||"?"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:K.skill_name||K.skill_id}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans",children:["$",(K.amount||0).toFixed(2)," · ",$t(K.created_at)]})]}),e.jsx(Te,{variant:"success",className:"text-2xs flex-shrink-0",children:"Owned"})]},K.id||K.skill_id)})})]}),t&&n.length===0&&e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[e.jsx(Lp,{size:20,className:"mx-auto text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No purchases yet"})]}),!t&&e.jsxs("div",{className:"bg-surface-1 border border-border-subtle rounded-md px-4 py-6 text-center",children:[e.jsx(Lp,{size:20,className:"mx-auto text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-2 font-sans mb-3",children:"Sign in to see your purchases"}),e.jsxs(pe,{variant:"primary",size:"sm",onClick:s,className:"gap-1.5 mx-auto",children:[e.jsx(PS,{size:12})," Sign in"]})]}),Y.length>0?e.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))"},children:Y.map(K=>K._type==="skill"?e.jsx(Ux,{item:{...K,installed:!0},onClick:()=>y(K)},`skill-${K.id}`):e.jsx(Ux,{item:{...K,installed:!0},onClick:()=>{j(K),C(!0)},statusBadge:e.jsx(Te,{variant:K.configured?"success":"warning",className:"text-2xs",children:K.configured?"Active":"Not configured"})},`int-${K.id}`))}):e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:ee[h]})]}),e.jsx(_4,{integration:S,open:N,onClose:()=>{C(!1),j(null),T()}})]})}function use(){const t=k(x=>x.importedRepos),s=k(x=>x.fetchImportedRepos),n=k(x=>x.softRemoveRepo),a=k(x=>x.hardNukeRepo),r=Hn(),[l,c]=p.useState(null);p.useEffect(()=>{s()},[]);async function A(x){try{await n(x.id),r.success(`Removed ${x.repoName||x.name}`)}catch(h){r.error("Remove failed",h.message)}}async function f(x){if(l){try{x?await a(l.id):await n(l.id),r.success(`${x?"Nuked":"Removed"} ${l.name||l.repo}`)}catch(h){r.error("Nuke failed",h.message)}c(null)}}return e.jsxs(Qt,{className:"h-full",children:[e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsx(rse,{}),t.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider mb-3",children:"Recently Imported"}),e.jsx("div",{className:"space-y-2",children:(Array.isArray(t)?t:[]).map(x=>e.jsx(ose,{repo:x,onRemove:()=>A(x),onNuke:()=>c(x)},x.id))})]}),t.length===0&&e.jsx("div",{className:"text-center py-16 text-text-4 font-sans text-sm",children:"No repos imported yet. Paste a GitHub URL above to get started."})]}),e.jsx(ise,{repo:l,open:!!l,onClose:()=>c(null),onConfirm:f})]})}function fse(){const[t,s]=p.useState("integrations"),n=[{id:"integrations",label:"Integrations",icon:on},{id:"github",label:"GitHub",icon:Kl},{id:"library",label:"My Library",icon:zb}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-shrink-0 bg-surface-1 border-b border-border-subtle",children:e.jsxs("div",{className:"flex items-center px-5 h-11",children:[e.jsx("div",{className:"flex items-center",children:n.map(a=>{const r=a.icon;return e.jsxs("button",{onClick:()=>s(a.id),className:`flex items-center gap-1.5 px-3 py-2.5 text-xs font-semibold font-sans cursor-pointer select-none border-b-2 -mb-px transition-colors ${t===a.id?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"}`,children:[e.jsx(r,{size:12}),a.label]},a.id)})}),e.jsx("div",{className:"flex-1"})]})}),e.jsxs("div",{className:"flex-1 min-h-0",children:[t==="integrations"&&e.jsx(Ase,{}),t==="github"&&e.jsx(use,{}),t==="library"&&e.jsx(dse,{})]})]})}const Mv=[{label:"Every hour",cron:"0 * * * *",description:"Runs at the start of every hour"},{label:"Every morning",cron:"0 9 * * *",description:"Daily at 9:00 AM"},{label:"Twice daily",cron:"0 9,17 * * *",description:"9:00 AM and 5:00 PM"},{label:"Every weekday",cron:"0 9 * * 1-5",description:"Monday-Friday at 9:00 AM"},{label:"Mon & Thu",cron:"0 9 * * 1,4",description:"Monday and Thursday at 9:00 AM"},{label:"Weekly",cron:"0 9 * * 1",description:"Every Monday at 9:00 AM"},{label:"Monthly",cron:"0 9 1 * *",description:"1st of each month at 9:00 AM"}],xse=new Map(Mv.map(t=>[t.cron,t.description]));function mse(t){if(!t)return"";const s=t.trim(),n=xse.get(s);return n||s}const hse=[{name:"minute",min:0,max:59},{name:"hour",min:0,max:23},{name:"day of month",min:1,max:31},{name:"month",min:1,max:12},{name:"day of week",min:0,max:7}];function pse(t,s){if(t==="*")return null;if(/^\*\/\d+$/.test(t)){const a=parseInt(t.slice(2),10);return a<1||a>s.max?`Invalid step ${a} for ${s.name}`:null}const n=t.split(",");for(const a of n)if(a.includes("-")){const[r,l]=a.split("-").map(Number);if(isNaN(r)||isNaN(l)||r<s.min||l>s.max||r>l)return`Invalid range ${a} for ${s.name} (${s.min}-${s.max})`}else{const r=Number(a);if(isNaN(r)||r<s.min||r>s.max)return`Invalid value ${a} for ${s.name} (${s.min}-${s.max})`}return null}function gse(t){if(!t||typeof t!="string")return{valid:!1,error:"Expression is required"};const s=t.trim().split(/\s+/);if(s.length!==5)return{valid:!1,error:`Expected 5 fields, got ${s.length}`};for(let n=0;n<5;n++){const a=pse(s[n],hse[n]);if(a)return{valid:!1,error:a}}return{valid:!0}}function Ose({automation:t}){var T,B,F,M,R,Y,W,ee,K,_;const s=k(E=>E.toggleAutomation),n=k(E=>E.deleteAutomation),a=k(E=>E.duplicateAutomation),r=k(E=>E.runAutomation),l=k(E=>E.setEditingAutomation),c=k(E=>E.openAutomationWizard),A=k(E=>E.openDetail),f=k(E=>E.agents),[x,h]=p.useState(!1),g=p.useRef(null);p.useEffect(()=>{if(!x)return;function E(q){g.current&&!g.current.contains(q.target)&&h(!1)}return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[x]);const O=t,b=O.teamConfig||(O.agentConfig?[O.agentConfig]:O.role?[{role:O.role}]:[]),v=((T=O.instructionSource)==null?void 0:T.type)==="inline"?O.instructionSource.content:((B=O.instructionSource)==null?void 0:B.type)==="file"?null:O.prompt||null,y=((F=O.instructionSource)==null?void 0:F.type)==="file"?O.instructionSource.filePath:null,S=((M=O.outputConfig)==null?void 0:M.gatewayIds)||[],j=O.lastRunStatus||(O.lastRunAt?"completed":null),N=(O.activeAgentIds||[]).map(E=>f.find(q=>q.id===E)).filter(Boolean),C=(R=O.lastRun)!=null&&R.agentId?O.lastRun.agentId.split(",").filter(Boolean):[],U=O.isRunning?[]:C.map(E=>f.find(q=>q.id===E)).filter(Boolean);function P(E){A({type:"agent",agentId:E})}return e.jsxs("div",{className:Z("rounded-md border bg-surface-1 overflow-hidden transition-colors",O.enabled?"border-border-subtle":"border-border-subtle/50 opacity-75"),children:[e.jsxs("div",{className:"px-4 py-3 flex items-start gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans truncate",children:O.name}),e.jsx(Te,{variant:O.enabled?"success":"default",className:"text-2xs flex-shrink-0",children:O.enabled?"Active":"Paused"})]}),O.description&&e.jsx("p",{className:"text-2xs text-text-3 font-sans truncate mt-0.5",children:O.description})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx("button",{onClick:()=>s(O.id,O.enabled),className:Z("p-1.5 rounded transition-colors cursor-pointer",O.enabled?"text-success hover:text-success/80":"text-text-4 hover:text-text-2"),title:O.enabled?"Pause automation":"Enable automation",children:O.enabled?e.jsx(qx,{size:13}):e.jsx(Za,{size:13})}),e.jsxs("div",{ref:g,className:"relative",children:[e.jsx("button",{onClick:()=>h(!x),className:"p-1.5 rounded text-text-4 hover:text-text-2 transition-colors cursor-pointer",children:e.jsx(Xx,{size:13})}),x&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[150px] bg-surface-2 border border-border rounded-md shadow-lg py-1",children:[e.jsxs("button",{onClick:()=>{l(O.id),c(),h(!1)},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 transition-colors cursor-pointer flex items-center gap-2",children:[e.jsx(Ua,{size:10})," Edit"]}),e.jsxs("button",{onClick:()=>{a(O.id),h(!1)},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 transition-colors cursor-pointer flex items-center gap-2",children:[e.jsx(Ba,{size:10})," Duplicate"]}),e.jsxs("button",{onClick:()=>{r(O.id),h(!1)},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 transition-colors cursor-pointer flex items-center gap-2",children:[e.jsx(Za,{size:10})," Run Now"]}),e.jsx("div",{className:"h-px my-1 bg-border-subtle"}),e.jsxs("button",{onClick:()=>{n(O.id),h(!1)},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-danger hover:bg-danger/5 transition-colors cursor-pointer flex items-center gap-2",children:[e.jsx(Ft,{size:10})," Delete"]})]})]})]})]}),b.length>0&&e.jsxs("div",{className:"px-4 pb-2 flex items-center gap-1.5 flex-wrap",children:[b.map((E,q)=>e.jsxs(Te,{variant:"default",className:"text-2xs",children:[E.role,E.phase?` P${E.phase}`:""]},q)),((Y=O.integrationIds)==null?void 0:Y.length)>0&&e.jsxs("span",{className:"text-2xs text-text-4 font-sans ml-1",children:["+",O.integrationIds.length," integrations"]})]}),(v||y)&&e.jsx("div",{className:"px-4 pb-2",children:y?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Li,{size:10,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:y})]}):e.jsxs("p",{className:"text-2xs text-text-3 font-sans truncate",children:[e.jsx(On,{size:10,className:"inline mr-1 text-text-4"}),v.slice(0,100),v.length>100?"...":""]})}),e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle bg-surface-0 flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Dn,{size:10,className:"text-text-4"}),e.jsx("span",{className:"text-2xs font-mono text-text-2",children:mse(O.cron)})]}),O.nextRunAt&&e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:["Next: ",$t(O.nextRunAt)]}),O.lastRunAt&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-2xs font-mono text-text-3",children:["Last: ",$t(O.lastRunAt)]}),e.jsx(Gt,{status:j==="error"?"crashed":j==="running"?"running":"completed",size:"sm"})]}),!O.lastRunAt&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Never run"})]}),(S.length>0||((W=O.outputConfig)==null?void 0:W.filePath)||((ee=O.outputConfig)==null?void 0:ee.customInstructions))&&e.jsxs("div",{className:"px-4 py-1.5 border-t border-border-subtle bg-surface-0 space-y-1",children:[S.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Gateways:"}),e.jsx("span",{className:"text-2xs font-sans text-text-3",children:S.join(", ")})]}),((K=O.outputConfig)==null?void 0:K.filePath)&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"File:"}),e.jsx("span",{className:"text-2xs font-mono text-text-3 truncate",children:O.outputConfig.filePath})]}),((_=O.outputConfig)==null?void 0:_.customInstructions)&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"Custom:"}),e.jsxs("span",{className:"text-2xs font-sans text-text-3 truncate",children:[O.outputConfig.customInstructions.slice(0,80),O.outputConfig.customInstructions.length>80?"...":""]})]})]}),N.length>0&&e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle bg-surface-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx(Gt,{status:"running",size:"sm"}),e.jsx("span",{className:"text-2xs font-sans text-text-2 font-medium",children:"Running"})]}),e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:N.map(E=>e.jsxs("button",{onClick:()=>P(E.id),className:"flex items-center gap-1.5 px-2 py-1 rounded bg-surface-4 hover:bg-surface-5 transition-colors cursor-pointer group",children:[e.jsx(Gt,{status:E.status,size:"sm"}),e.jsx("span",{className:"text-2xs font-sans text-text-1 group-hover:text-text-0",children:E.name||E.role}),e.jsx(Ws,{size:9,className:"text-text-4 group-hover:text-accent"})]},E.id))})]}),!O.isRunning&&U.length>0&&e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle bg-surface-0",children:[e.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:e.jsx("span",{className:"text-2xs font-sans text-text-3",children:"Last run agents"})}),e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:U.map(E=>e.jsxs("button",{onClick:()=>P(E.id),className:"flex items-center gap-1.5 px-2 py-1 rounded bg-surface-4 hover:bg-surface-5 transition-colors cursor-pointer group",children:[e.jsx(Gt,{status:E.status,size:"sm"}),e.jsx("span",{className:"text-2xs font-sans text-text-2 group-hover:text-text-0",children:E.name||E.role}),e.jsx(Ws,{size:9,className:"text-text-4 group-hover:text-accent"})]},E.id))})]}),e.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle flex items-center gap-3",children:[e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>r(O.id),className:"h-6 px-2 text-2xs gap-1",children:[e.jsx(Za,{size:10})," Run Now"]}),e.jsx("div",{className:"flex-1"}),O.lastRunDuration!=null&&e.jsx("span",{className:"text-2xs font-mono text-text-4",children:Xo(O.lastRunDuration/1e3)}),O.lastRunCost!=null&&O.lastRunCost>0&&e.jsx("span",{className:"text-2xs font-mono text-text-4",children:er(O.lastRunCost)})]})]})}function Ex({title:t,icon:s,defaultOpen:n=!1,badge:a,children:r,className:l}){const[c,A]=p.useState(n);return e.jsxs("div",{className:Z("border-t border-border-subtle",l),children:[e.jsxs("button",{onClick:()=>A(!c),className:"w-full flex items-center gap-2 px-5 py-3 text-left cursor-pointer hover:bg-surface-5/30 transition-colors group",children:[e.jsx(Tt,{size:12,className:Z("text-text-4 transition-transform duration-200 flex-shrink-0",c&&"rotate-90")}),s&&e.jsx(s,{size:13,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:t}),a&&e.jsx("span",{className:"text-2xs font-mono text-text-4 bg-surface-4 px-1.5 py-0.5 rounded",children:a})]}),c&&e.jsx("div",{className:"px-5 pb-4",children:r})]})}const bse=[{id:"solo",label:"Solo Agent",icon:XS,description:"Single agent for focused tasks"},{id:"dev",label:"Dev Team",icon:vR,description:"Frontend + Backend + QC"},{id:"business",label:"Business Team",icon:V$,description:"CMO + CFO + Analyst"},{id:"custom",label:"Custom",icon:oc,description:"Build your own team"}],Iv=[{role:"frontend",phase:1},{role:"backend",phase:1},{role:"fullstack",phase:2}],zv=[{role:"CMO",phase:1},{role:"CFO",phase:1},{role:"analyst",phase:2}],FQ=["chat","planner","backend","frontend","fullstack","testing","devops","docs","security","database","cmo","cfo","ea","support","analyst","creative","slides","ambassador"],vse={chat:"Chat",planner:"Planner",backend:"Backend",frontend:"Frontend",fullstack:"Fullstack",testing:"Testing",devops:"DevOps",docs:"Docs",security:"Security",database:"Database",cmo:"CMO",cfo:"CFO",ea:"EA",support:"Support",analyst:"Analyst",creative:"Writer",slides:"Slides",ambassador:"Ambassador"};function Sf(t){return vse[t]||t}const yse=/\[read\]\s*#[\w/.-]+/g;function wse(t){return t?[...t.matchAll(yse)].map(s=>s[0]):[]}function D4({text:t}){const s=wse(t);return s.length===0?null:e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap px-1",children:s.map((n,a)=>e.jsx("span",{className:"text-2xs font-mono text-teal-400",children:n},a))})}const jse=[{value:"min",label:"minutes"},{value:"hour",label:"hours"},{value:"day",label:"days"},{value:"week",label:"weeks"}],Xg={name:"",description:"",teamType:null,soloRole:"planner",customRoles:[{role:"fullstack",phase:1}],provider:"",model:"",runtimeId:"",instructionMode:"write",instructions:"",filePath:"",cronPreset:null,scheduleMode:"preset",scheduleCount:1,scheduleUnit:"hour",enabledOnCreate:!0,gatewayIds:[],notifyOn:"complete",integrationIds:[],outputFilePath:"",outputCustom:""};function ib(t,s){const n=parseInt(t,10);if(!n||n<1)return null;switch(s){case"min":return`*/${n} * * * *`;case"hour":return n===1?"0 * * * *":`0 */${n} * * *`;case"day":return n===1?"0 9 * * *":`0 9 */${n} * *`;case"week":return"0 9 * * 1";default:return null}}function Qse(t,s){const n=parseInt(t,10);if(!n||n<1)return"";const a={min:"minute",hour:"hour",day:"day",week:"week"};return`Every ${n===1?"":n+" "}${a[s]}${n!==1?"s":""}`}function Nse(t){if(!t)return null;const s=t.trim().split(/\s+/);if(s.length!==5)return null;const[n,a,r,l,c]=s;return n.startsWith("*/")&&a==="*"&&r==="*"&&l==="*"&&c==="*"?{count:parseInt(n.slice(2)),unit:"min"}:n==="0"&&a==="*"&&r==="*"&&l==="*"&&c==="*"?{count:1,unit:"hour"}:n==="0"&&a.startsWith("*/")&&r==="*"&&l==="*"&&c==="*"?{count:parseInt(a.slice(2)),unit:"hour"}:n==="0"&&/^\d+$/.test(a)&&r==="*"&&l==="*"&&c==="*"?{count:1,unit:"day"}:n==="0"&&/^\d+$/.test(a)&&r.startsWith("*/")&&l==="*"&&c==="*"?{count:parseInt(r.slice(2)),unit:"day"}:n==="0"&&/^\d+$/.test(a)&&r==="*"&&l==="*"&&/^\d$/.test(c)?{count:1,unit:"week"}:null}function $Q(t,s){return t.length===s.length&&t.every((n,a)=>{var r,l;return((r=s[a])==null?void 0:r.role)===n.role&&(((l=s[a])==null?void 0:l.phase)||1)===n.phase})}function Sse(t){var g,O,b,v,y,S,j,N,C,U,P,T,B,F;let s="custom",n="planner",a=[{role:"fullstack",phase:1}];t.agentConfig&&!t.teamConfig?(s="solo",n=t.agentConfig.role||"planner"):t.teamConfig&&($Q(Iv,t.teamConfig)?s="dev":$Q(zv,t.teamConfig)?s="business":a=t.teamConfig.map(M=>({role:M.role,phase:M.phase||1})));const r=((g=Mv.find(M=>M.cron===t.cron))==null?void 0:g.cron)||null;let l="preset",c=1,A="hour";if(!r){const M=Nse(t.cron);M&&(l="simple",c=M.count,A=M.unit)}let f=((O=t.agentConfig)==null?void 0:O.provider)||((v=(b=t.teamConfig)==null?void 0:b[0])==null?void 0:v.provider)||"",x=((y=t.agentConfig)==null?void 0:y.model)||((j=(S=t.teamConfig)==null?void 0:S[0])==null?void 0:j.model)||"",h="";if(f==="local"&&(x!=null&&x.startsWith("runtime:"))){const M=x.split(":");h=M[1],x=M.slice(2).join(":")}return{name:t.name||"",description:t.description||"",teamType:s,soloRole:n,customRoles:a,provider:f,model:x==="auto"?"":x,runtimeId:h,instructionMode:((N=t.instructionSource)==null?void 0:N.type)==="file"?"file":"write",instructions:((C=t.instructionSource)==null?void 0:C.type)==="inline"&&t.instructionSource.content||"",filePath:((U=t.instructionSource)==null?void 0:U.type)==="file"&&t.instructionSource.filePath||"",cronPreset:r,scheduleMode:l,scheduleCount:c,scheduleUnit:A,enabledOnCreate:t.enabled!==!1,gatewayIds:((P=t.outputConfig)==null?void 0:P.gatewayIds)||[],notifyOn:((T=t.outputConfig)==null?void 0:T.notifyOn)||"complete",integrationIds:t.integrationIds||[],outputFilePath:((B=t.outputConfig)==null?void 0:B.filePath)||"",outputCustom:((F=t.outputConfig)==null?void 0:F.customInstructions)||""}}function Cse(){const t=k(R=>R.automationWizardOpen),s=k(R=>R.closeAutomationWizard),n=k(R=>R.createAutomation),a=k(R=>R.updateAutomation),r=k(R=>R.editingAutomationId),l=k(R=>R.automations),c=k(R=>R.availableGateways),A=k(R=>R.availableIntegrations),f=k(R=>R.fetchGateways),x=k(R=>R.fetchInstalledIntegrations),h=!!r,[g,O]=p.useState(1),[b,v]=p.useState(Xg),[y,S]=p.useState([]),[j,N]=p.useState([]),C=k(R=>R.labRuntimes),U=k(R=>R.fetchLabRuntimes);p.useEffect(()=>{if(t){if(O(1),r){const R=l.find(Y=>Y.id===r);v(R?Sse(R):Xg)}else v(Xg);f(),x(),U(),G.get("/providers").then(R=>{var ee;const Y=Array.isArray(R)?R:R.providers||[];S(Y);const W=Y.find(K=>K.id==="local");(ee=W==null?void 0:W.models)!=null&&ee.length&&N(W.models)}).catch(()=>S([])),G.get("/providers/ollama/models").then(R=>{const Y=R.installed||[],W=R.catalog||[];(Y.length||W.length)&&N(ee=>{const K=new Set(ee.map(E=>E.id)),_=[...ee];for(const E of Y)K.has(E.id)||(_.push(E),K.add(E.id));for(const E of W)K.has(E.id)||_.push({id:E.id,name:E.name||E.id});return _})}).catch(()=>{})}},[t]);function P(R){v(Y=>({...Y,...R}))}function T(){return b.cronPreset?b.cronPreset:ib(b.scheduleCount,b.scheduleUnit)}function B(){let R=b.provider||void 0,Y=b.model||void 0;switch(R==="local"&&b.runtimeId&&Y&&(Y=`runtime:${b.runtimeId}:${Y}`),b.teamType){case"solo":return{agentConfig:{role:b.soloRole,provider:R,model:Y}};case"dev":return{teamConfig:Iv.map(W=>({...W,provider:R,model:Y}))};case"business":return{teamConfig:zv.map(W=>({...W,provider:R,model:Y}))};case"custom":return{teamConfig:b.customRoles.filter(W=>W.role).map(W=>({...W,provider:R,model:Y}))};default:return{}}}function F(){switch(g){case 1:return b.name.trim()&&b.teamType;case 2:return b.instructionMode==="write"?b.instructions.trim():b.filePath.trim();case 3:{if(b.cronPreset)return!0;const R=ib(b.scheduleCount,b.scheduleUnit);return R&&gse(R).valid}case 4:return!0;default:return!1}}function M(){const R=T(),Y={name:b.name.trim(),description:b.description.trim()||void 0,cron:R,...B(),instructionSource:b.instructionMode==="write"?{type:"inline",content:b.instructions}:{type:"file",filePath:b.filePath},outputConfig:{gatewayIds:b.gatewayIds,notifyOn:b.notifyOn,filePath:b.outputFilePath||void 0,customInstructions:b.outputCustom||void 0},integrationIds:b.integrationIds.length>0?b.integrationIds:void 0,enabled:b.enabledOnCreate};h?(a(r,Y),s()):n(Y)}return e.jsx(Vt,{open:t,onOpenChange:R=>!R&&s(),children:e.jsxs(Kt,{title:h?"Edit Automation":"New Automation",description:h?"Update this automation":"Create a scheduled automation",className:"max-w-xl",children:[e.jsx("div",{className:"px-5 py-3 border-b border-border-subtle flex items-center justify-center gap-2",children:[1,2,3,4].map(R=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:Z("w-2 h-2 rounded-full transition-colors",R===g?"bg-accent":R<g?"bg-accent/40":"bg-surface-5")}),R<4&&e.jsx("div",{className:Z("w-6 h-px",R<g?"bg-accent/40":"bg-surface-5")})]},R))}),e.jsxs("div",{className:"px-5 py-4 min-h-[300px]",children:[g===1&&e.jsx(Bse,{form:b,update:P,providers:y,labRuntimes:C||[],localModels:j}),g===2&&e.jsx(kse,{form:b,update:P}),g===3&&e.jsx(Tse,{form:b,update:P}),g===4&&e.jsx(Use,{form:b,update:P,gateways:c,integrations:A})]}),e.jsxs("div",{className:"px-5 py-3 border-t border-border-subtle flex items-center justify-between",children:[e.jsx("div",{children:g>1&&e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>O(g-1),className:"gap-1",children:[e.jsx(Di,{size:12})," Back"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{variant:"ghost",size:"sm",onClick:s,children:"Cancel"}),g<4?e.jsxs(pe,{variant:"primary",size:"sm",disabled:!F(),onClick:()=>O(g+1),className:"gap-1",children:["Next ",e.jsx(Tt,{size:12})]}):e.jsx(pe,{variant:"primary",size:"sm",disabled:!F(),onClick:M,children:h?"Save":"Create"})]})]})]})})}const RQ={ollama:"Ollama",vllm:"vLLM","llama-cpp":"llama.cpp",mlx:"MLX",tgi:"TGI","openai-compatible":"OpenAI Compatible"};function Bse({form:t,update:s,providers:n,labRuntimes:a,localModels:r}){const l=t.provider==="local",c=n.find(x=>x.id===t.provider),A=l?r||[]:(c==null?void 0:c.models)||[],f=l?a.find(x=>x.id===t.runtimeId):null;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(rs,{label:"Name",placeholder:"Morning briefing",value:t.name,onChange:x=>s({name:x.target.value})}),e.jsx(rs,{label:"Description (optional)",placeholder:"Check email, calendar, and write a daily summary",value:t.description,onChange:x=>s({description:x.target.value})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Team Type"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:bse.map(x=>e.jsxs("button",{onClick:()=>s({teamType:x.id}),className:Z("flex items-center gap-3 p-3 rounded-md border text-left transition-colors cursor-pointer",t.teamType===x.id?"border-accent bg-accent/5":"border-border-subtle bg-surface-0 hover:border-border hover:bg-surface-2"),children:[e.jsx(x.icon,{size:16,className:Z(t.teamType===x.id?"text-accent":"text-text-3")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans",children:x.label}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:x.description})]})]},x.id))})]}),t.teamType==="solo"&&e.jsxs(Rn,{value:t.soloRole,onValueChange:x=>s({soloRole:x}),children:[e.jsx(Mn,{placeholder:"Select role"}),e.jsx(In,{children:FQ.map(x=>e.jsx(ms,{value:x,children:Sf(x)},x))})]}),t.teamType==="dev"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Roles"}),Iv.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md bg-surface-0 border border-border-subtle",children:[e.jsx(Te,{variant:"default",className:"text-2xs",children:Sf(x.role)}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"text-2xs font-mono text-text-4",children:["Phase ",x.phase]})]},h))]}),t.teamType==="business"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Roles"}),zv.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md bg-surface-0 border border-border-subtle",children:[e.jsx(Te,{variant:"default",className:"text-2xs",children:Sf(x.role)}),e.jsx("div",{className:"flex-1"}),e.jsxs("span",{className:"text-2xs font-mono text-text-4",children:["Phase ",x.phase]})]},h))]}),t.teamType==="custom"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Roles"}),t.customRoles.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Rn,{value:x.role,onValueChange:g=>MQ(t,s,h,{role:g}),children:[e.jsx(Mn,{placeholder:"Role",className:"flex-1"}),e.jsx(In,{children:FQ.map(g=>e.jsx(ms,{value:g,children:Sf(g)},g))})]}),e.jsxs("button",{onClick:()=>MQ(t,s,h,{phase:x.phase===1?2:1}),className:Z("h-8 px-2.5 rounded-md text-2xs font-mono border transition-colors cursor-pointer",x.phase===1?"border-accent/30 text-accent bg-accent/5":"border-border text-text-3 bg-surface-0"),children:["P",x.phase]}),e.jsx("button",{onClick:()=>{const g=t.customRoles.filter((O,b)=>b!==h);s({customRoles:g.length>0?g:[{role:"fullstack",phase:1}]})},className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",children:e.jsx(qe,{size:12})})]},h)),e.jsxs(pe,{variant:"ghost",size:"sm",onClick:()=>s({customRoles:[...t.customRoles,{role:"fullstack",phase:1}]}),className:"gap-1 text-2xs",children:[e.jsx(it,{size:10})," Add Role"]})]}),t.teamType&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider & Model"}),e.jsxs("div",{className:Z("grid gap-3",l?"grid-cols-3":"grid-cols-2"),children:[e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:t.provider,onChange:x=>s({provider:x.target.value,model:"",runtimeId:""}),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Auto"}),n.filter(x=>x.authType!=="local").map(x=>e.jsxs("option",{value:x.id,disabled:x.authType==="api-key"?!(x.installed&&x.hasKey):!x.installed,children:[x.name,x.installed?x.authType==="api-key"&&!x.hasKey?" (No API key)":"":" (Not installed)"]},x.id)),e.jsx("option",{value:"local",children:"Local Model"})]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:t.model,onChange:x=>s({model:x.target.value}),disabled:!t.provider,className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-40",children:[e.jsx("option",{value:"",children:"Auto"}),A.map(x=>e.jsx("option",{value:x.id,children:x.name||x.id},x.id))]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),l&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:t.runtimeId,onChange:x=>s({runtimeId:x.target.value}),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select runtime"}),a.map(x=>e.jsxs("option",{value:x.id,children:[x.name||RQ[x.type]||x.type,x.status==="connected"?"":" (offline)"]},x.id))]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),l&&e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[e.jsx(Aa,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("span",{className:"text-2xs font-sans text-text-2",children:["Make sure your runtime",f?` (${f.name||RQ[f.type]||f.type})`:""," is running when this automation fires."]})]}),l&&a.length===0&&e.jsx("div",{className:"flex items-start gap-2 px-3 py-2 rounded-md bg-surface-4 border border-border-subtle",children:e.jsx("span",{className:"text-2xs font-sans text-text-3",children:"No runtimes configured. Set one up in the Model Lab tab first."})})]})]})}function MQ(t,s,n,a){s({customRoles:t.customRoles.map((r,l)=>l===n?{...r,...a}:r)})}function kse({form:t,update:s}){const[n,a]=p.useState(!1);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>s({instructionMode:"write"}),className:Z("px-3 py-1.5 text-xs font-sans rounded-md transition-colors cursor-pointer",t.instructionMode==="write"?"bg-accent/10 text-accent border border-accent/30":"text-text-3 border border-border-subtle hover:text-text-1"),children:"Write instructions"}),e.jsx("button",{onClick:()=>s({instructionMode:"file"}),className:Z("px-3 py-1.5 text-xs font-sans rounded-md transition-colors cursor-pointer",t.instructionMode==="file"?"bg-accent/10 text-accent border border-accent/30":"text-text-3 border border-border-subtle hover:text-text-1"),children:"Reference a document"})]}),t.instructionMode==="write"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Rv,{mono:!0,value:t.instructions,onChange:r=>s({instructions:r.target.value}),placeholder:`Describe what this team should do...
@@ -1067,4 +1067,4 @@ Make the prompt comprehensive — include identity, philosophy, available tools,
1067
1067
  Make the roadmap have 2-4 stages with clear graduation criteria.
1068
1068
  Keep the conversation friendly and efficient. Ask one question at a time.`;function woe({msg:t}){const s=t.role==="user";return e.jsxs("div",{className:Z("flex gap-2",s?"justify-end":"justify-start"),children:[!s&&e.jsx("div",{className:"w-6 h-6 rounded-full bg-accent/10 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(Js,{size:12,className:"text-accent"})}),e.jsx("div",{className:Z("max-w-[85%] rounded-lg px-3 py-2 text-xs font-sans",s?"bg-accent text-surface-0 rounded-br-sm":"bg-surface-2 text-text-1 rounded-bl-sm"),children:e.jsx("p",{className:"whitespace-pre-wrap",children:t.content})})]})}function joe({config:t,onDeploy:s,onEdit:n,deploying:a}){var c,A;const[r,l]=p.useState(!1);return e.jsxs("div",{className:"rounded-lg border border-accent/30 bg-accent/5 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qa,{size:16,className:"text-accent"}),e.jsx("span",{className:"text-sm font-semibold text-text-0 font-sans",children:"Ready to Deploy"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs font-sans",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-text-4 text-2xs",children:"Name"}),e.jsx("p",{className:"text-text-0",children:t.name})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-4 text-2xs",children:"Cadence"}),e.jsx("p",{className:"text-text-0",children:((c=voe.find(f=>f.value===t.cadence))==null?void 0:c.label)||t.cadence})]})]}),t.description&&e.jsx("p",{className:"text-xs text-text-2 font-sans",children:t.description}),((A=t.guardrails)==null?void 0:A.length)>0&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-2xs text-text-4 font-sans flex items-center gap-1",children:[e.jsx(vn,{size:10})," Guardrails"]}),e.jsx("ul",{className:"text-2xs text-text-2 font-sans mt-1 space-y-0.5",children:t.guardrails.map((f,x)=>e.jsxs("li",{children:["• ",f]},x))})]}),e.jsxs("button",{onClick:()=>l(!r),className:"text-2xs text-accent font-sans flex items-center gap-1 cursor-pointer hover:underline",children:[r?e.jsx(Hx,{size:10}):e.jsx(xt,{size:10}),r?"Hide":"Show"," full config"]}),r&&e.jsx("pre",{className:"text-2xs font-mono text-text-3 bg-surface-0 rounded p-2 overflow-x-auto max-h-48 overflow-y-auto border border-border-subtle",children:JSON.stringify(t,null,2)}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(pe,{variant:"primary",size:"sm",onClick:s,disabled:a,className:"flex-1 gap-1.5",children:a?"Deploying...":e.jsxs(e.Fragment,{children:[e.jsx(Je,{size:12})," Deploy Agent"]})}),e.jsxs(pe,{variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[e.jsx(RS,{size:12})," Edit"]})]})]})}function nN(){const t=k(C=>C.autoAgentWizardOpen),s=k(C=>C.closeAutoAgentWizard),n=k(C=>C.createAutoAgent),a=k(C=>C.setActiveView),[r,l]=p.useState([]),[c,A]=p.useState(""),[f,x]=p.useState(!1),[h,g]=p.useState(null),[O,b]=p.useState(!1),v=p.useRef(null),y=p.useRef(null);p.useEffect(()=>{t&&r.length===0&&(l([{role:"assistant",content:"Hey! I'll help you set up an autonomous agent. What task do you want it to handle? Tell me what you're trying to accomplish and I'll help configure everything."}]),g(null))},[t]),p.useEffect(()=>{v.current&&(v.current.scrollTop=v.current.scrollHeight)},[r]);const S=p.useCallback(async()=>{if(!c.trim()||f)return;const C={role:"user",content:c.trim()},U=[...r,C];l(U),A(""),x(!0);try{const P=U.map(F=>({role:F.role,content:F.content})),T=await G.post("/auto-agents/setup-chat",{messages:P,systemPrompt:yoe}),B={role:"assistant",content:T.response};l(F=>[...F,B]),T.config&&g(T.config)}catch(P){l(T=>[...T,{role:"assistant",content:`Sorry, I hit an error: ${P.message}. Let me try again — could you rephrase that?`}])}finally{x(!1)}},[c,r,f]),j=p.useCallback(async()=>{if(h){b(!0);try{await n(h)&&a("auto-agents")}finally{b(!1)}}},[h]),N=()=>{s(),l([]),g(null),A("")};return e.jsx(_v,{open:t,onOpenChange:C=>{C||N()},children:e.jsx(Dv,{title:"New Auto Agent",width:520,onClose:N,children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{ref:v,className:"flex-1 overflow-y-auto px-4 py-4 space-y-3",children:[r.map((C,U)=>e.jsx(woe,{msg:C},U)),f&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-accent/10 flex items-center justify-center flex-shrink-0",children:e.jsx(Js,{size:12,className:"text-accent animate-pulse"})}),e.jsx("div",{className:"bg-surface-2 rounded-lg px-3 py-2 rounded-bl-sm",children:e.jsx("span",{className:"text-xs text-text-3 font-sans animate-pulse",children:"Thinking..."})})]}),h&&e.jsx(joe,{config:h,onDeploy:j,onEdit:()=>g(null),deploying:O})]}),e.jsxs("div",{className:"border-t border-border-subtle px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{ref:y,type:"text",value:c,onChange:C=>A(C.target.value),onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),S())},placeholder:h?"Ask to adjust the config...":"Describe what you want the agent to do...",className:"flex-1 bg-surface-0 border border-border-subtle rounded-md px-3 py-2 text-xs text-text-0 font-sans placeholder:text-text-4 focus:outline-none focus:border-accent",disabled:f}),e.jsx(pe,{variant:"primary",size:"icon-sm",onClick:S,disabled:!c.trim()||f,children:e.jsx(Ln,{size:14})})]}),!h&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:["ML training pipeline","Content generation","Data monitoring","Code review"].map(C=>e.jsx("button",{onClick:()=>{var U;A(C),(U=y.current)==null||U.focus()},className:"px-2 py-0.5 text-2xs font-sans text-text-3 bg-surface-2 rounded-full hover:bg-surface-3 cursor-pointer transition-colors",children:C},C))})]})]})})})}function Qoe(){const t=k(l=>l.autoAgents),s=k(l=>l.fetchAutoAgents),n=k(l=>l.openAutoAgentWizard),a=k(l=>l.selectedAutoAgentId),r=k(l=>l.selectAutoAgent);return p.useEffect(()=>{s();const l=setInterval(s,1e4);return()=>clearInterval(l)},[]),a?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(boe,{agentId:a,onBack:()=>r(null)}),e.jsx(nN,{})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border-subtle bg-surface-1",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-0 font-sans uppercase tracking-wide",children:"Auto Agents"}),e.jsxs(pe,{variant:"primary",size:"sm",onClick:n,className:"gap-1.5",children:[e.jsx(it,{size:12})," New Auto Agent"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center h-full",children:e.jsxs("div",{className:"text-center space-y-3 py-20",children:[e.jsx(qa,{size:28,className:"mx-auto text-text-4"}),e.jsx("p",{className:"text-xs font-sans text-text-3",children:"No auto agents yet"}),e.jsx("p",{className:"text-2xs font-sans text-text-4 max-w-xs mx-auto",children:"Auto agents run autonomously on a schedule — iterating, learning, and making progress on complex tasks 24/7."}),e.jsxs(pe,{variant:"primary",size:"sm",onClick:n,className:"gap-1.5 mt-2",children:[e.jsx(it,{size:12})," Create Auto Agent"]})]})}):e.jsx("div",{className:"p-4 space-y-3",children:t.map(l=>e.jsx(moe,{agent:l},l.id))})}),e.jsx(nN,{})]})}const Noe={code:"Code",general:"General"},Soe={light:"text-success",medium:"text-accent",heavy:"text-warning"};function Coe(t){return t<1?`${Math.round(t*1024)} MB`:`${t} GB`}function uT({hardware:t}){if(!t)return null;const{totalRamGb:s,gpu:n,isAppleSilicon:a}=t;return e.jsxs("div",{className:"flex items-center gap-3 bg-surface-0 rounded-lg border border-border-subtle px-3 py-2.5",children:[e.jsx(md,{size:14,className:"text-text-3 flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs font-sans",children:[e.jsxs("span",{className:"text-text-0 font-semibold",children:[s," GB RAM"]}),n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{className:"text-text-2",children:n.name})]}),a&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:"Unified Memory"})]})})]})}function Boe({onRecheck:t}){const[s,n]=p.useState(null),[a,r]=p.useState(!1),[l,c]=p.useState(!1),[A,f]=p.useState(!1),x=k(U=>U.addToast);p.useEffect(()=>{G.post("/providers/ollama/check").then(n).catch(()=>{})},[]);async function h(){r(!0);try{const U=await G.post("/providers/ollama/check");n(U),U.installed&&U.serverRunning?(x("success","Ollama is ready!"),t()):U.installed?x("info","Ollama installed — server needs to start"):x("info","Ollama not found — install and try again")}catch{}r(!1)}async function g(){c(!0);try{if((await G.post("/providers/ollama/serve")).ok){x("success","Ollama server started!");let P=!1;for(let T=0;T<5;T++){await new Promise(F=>setTimeout(F,2e3));const B=await G.post("/providers/ollama/check");if(n(B),B.serverRunning){P=!0;break}}P&&t()}}catch(U){x("error","Could not start server",U.message)}c(!1)}function O(U){navigator.clipboard.writeText(U),f(!0),setTimeout(()=>f(!1),2e3)}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{hardware:b,install:v,requirements:y,installed:S,serverRunning:j}=s,N=b.totalRamGb>=y.minRAM,C=b.recommended;return e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsx(uT,{hardware:b}),N?e.jsxs("div",{className:"flex items-start gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2.5",children:[e.jsx(Je,{size:14,className:"text-success flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans",children:[e.jsx("span",{className:"text-success font-semibold",children:"Your system is ready."}),e.jsx("span",{className:"text-text-2 ml-1",children:C.code?`Recommended: ${C.code}`:`${b.totalRamGb} GB RAM available`})]})]}):e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Ks,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsxs("span",{className:"text-warning font-semibold",children:[b.totalRamGb," GB RAM detected."]})," ","Minimum ",y.minRAM," GB needed. Smallest models may still work."]})]}),S&&!j&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-start gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Ks,{size:14,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama installed but server not running."})," ","The server needs to be running to pull and use models."]})]}),e.jsxs(pe,{variant:"primary",size:"md",onClick:g,disabled:l,className:"w-full gap-1.5",children:[e.jsx(qt,{size:12}),l?"Starting...":"Start Ollama Server"]})]}),!S&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold text-text-1 font-sans",children:"Install Ollama"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 bg-surface-0 border border-border-subtle rounded-md px-3 py-2 text-xs font-mono text-text-1 truncate",children:v.command}),e.jsxs(pe,{variant:"secondary",size:"sm",onClick:()=>O(v.command),className:"h-8 px-2.5 gap-1 flex-shrink-0",children:[A?e.jsx(Je,{size:12}):e.jsx(Ba,{size:12}),A?"Copied":"Copy"]})]}),v.alt&&e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:v.alt})]}),e.jsxs(pe,{variant:"secondary",size:"md",onClick:h,disabled:a,className:"w-full gap-1.5",children:[e.jsx(Ls,{size:12,className:a?"animate-spin":""}),a?"Checking...":S?"Check again":"I installed it — check again"]})]})}function koe({model:t,isInstalled:s,isRecommended:n,canRun:a,onPull:r,onDelete:l,pulling:c}){const A=c===t.id;return e.jsxs("div",{className:Z("flex items-center gap-2 px-3 py-2 border-t border-border-subtle transition-colors",!a&&"opacity-40"),children:[s?e.jsx(Je,{size:12,className:"text-success flex-shrink-0"}):e.jsx("div",{className:"w-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-mono text-text-1 truncate",children:t.name}),n&&e.jsx(Lb,{size:10,className:"text-warning flex-shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:Z("text-2xs font-semibold font-sans",Soe[t.tier]),children:t.tier}),e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:Coe(t.sizeGb)}),e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["· ",t.ramGb," GB RAM"]})]})]}),s?e.jsx("button",{onClick:()=>l(t.id),className:"p-1.5 text-text-4 hover:text-danger rounded transition-colors cursor-pointer",title:"Remove model",children:e.jsx(Ft,{size:12})}):a?e.jsx(pe,{variant:"secondary",size:"sm",onClick:()=>r(t.id),disabled:!!c,className:"h-7 px-2 text-2xs gap-1",children:A?e.jsxs(e.Fragment,{children:[e.jsx(Ls,{size:10,className:"animate-spin"})," Pulling..."]}):e.jsxs(e.Fragment,{children:[e.jsx(qs,{size:10})," Pull"]})}):e.jsxs("span",{className:"text-2xs text-text-4 font-sans",children:["Needs ",t.ramGb," GB"]})]})}function Toe({onStopped:t}){const[s,n]=p.useState(null),a=k(c=>c.addToast);async function r(){n("stopping");try{(await G.post("/providers/ollama/stop")).ok?(a("info","Ollama server stopped"),t&&t()):a("error","Could not stop server")}catch(c){a("error","Stop failed",c.message)}n(null)}async function l(){n("restarting");try{(await G.post("/providers/ollama/restart")).ok?a("success","Ollama server restarted"):a("error","Restart failed")}catch(c){a("error","Restart failed",c.message)}n(null)}return e.jsxs("div",{className:"flex items-center gap-2 bg-success/8 border border-success/20 rounded-lg px-3 py-2",children:[e.jsxs("span",{className:"relative flex-shrink-0 w-[6px] h-[6px]",children:[e.jsx("span",{className:"absolute inset-0 rounded-full bg-success"}),e.jsx("span",{className:"absolute inset-[-2px] rounded-full bg-success opacity-20 animate-pulse"})]}),e.jsx("span",{className:"text-xs font-sans text-success font-semibold",children:"Server Running"}),e.jsx("span",{className:"text-2xs font-mono text-text-4",children:":11434"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:l,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-accent cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(Ls,{size:10,className:s==="restarting"?"animate-spin":""}),s==="restarting"?"Restarting...":"Restart"]}),e.jsxs("button",{onClick:r,disabled:!!s,className:"flex items-center gap-1 text-2xs font-sans text-text-3 hover:text-danger cursor-pointer transition-colors disabled:opacity-40",children:[e.jsx(Ks,{size:10}),s==="stopping"?"Stopping...":"Stop"]})]})}function Uoe({onModelChange:t}){var F,M;const[s,n]=p.useState(null),[a,r]=p.useState(null),[l,c]=p.useState("code"),[A,f]=p.useState(!1),[x,h]=p.useState(!1),g=k(R=>R.addToast),O=p.useRef(!1);function b(){G.get("/providers/ollama/models").then(R=>{var Y;n(R),!O.current&&((Y=R.installed)==null?void 0:Y.length)===0&&(O.current=!0,setTimeout(b,2e3))}).catch(()=>{})}p.useEffect(()=>{b()},[]);async function v(R){r(R);try{await G.post("/providers/ollama/pull",{model:R}),g("success",`Pulled ${R}`),b(),t&&t()}catch(Y){g("error",`Pull failed: ${Y.message}`)}r(null)}async function y(R){try{await G.delete(`/providers/ollama/models/${encodeURIComponent(R)}`),g("info",`Removed ${R}`),b(),t&&t()}catch(Y){g("error",`Delete failed: ${Y.message}`)}}if(!s)return e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Loading..."});const{installed:S,catalog:j,hardware:N}=s,C=new Set(S.map(R=>R.id)),U=N.totalRamGb,P=[(F=N.recommended)==null?void 0:F.code,(M=N.recommended)==null?void 0:M.general].filter(Boolean),T=j.filter(R=>R.category===l),B=A?T:T.filter(R=>R.ramGb<=U);return x?e.jsxs("div",{className:"space-y-3 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-warning/8 border border-warning/20 rounded-lg px-3 py-2.5",children:[e.jsx(Ks,{size:14,className:"text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-sans text-text-2",children:[e.jsx("span",{className:"text-warning font-semibold",children:"Ollama server stopped."})," ","Start it again to pull and use models."]})]}),e.jsxs(pe,{variant:"primary",size:"md",onClick:async()=>{try{(await G.post("/providers/ollama/serve")).ok&&(g("success","Ollama server started!"),h(!1),O.current=!1,setTimeout(b,2e3))}catch(R){g("error","Could not start server",R.message)}},className:"w-full gap-1.5",children:[e.jsx(qt,{size:12}),"Start Ollama Server"]})]}):e.jsxs("div",{className:"space-y-2 p-3",children:[e.jsx(Toe,{onStopped:()=>h(!0)}),e.jsx(uT,{hardware:N}),S.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-sans text-text-2",children:[e.jsx(xd,{size:12,className:"text-text-3"}),e.jsx("span",{className:"font-semibold",children:S.length})," model",S.length!==1?"s":""," installed"]}),e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:Object.entries(Noe).map(([R,Y])=>e.jsx("button",{onClick:()=>c(R),className:Z("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",l===R?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:Y},R))}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[B.map(R=>e.jsx(koe,{model:R,isInstalled:C.has(R.id),isRecommended:P.includes(R.id),canRun:R.ramGb<=U,onPull:v,onDelete:y,pulling:a},R.id)),B.length===0&&e.jsxs("div",{className:"px-3 py-4 text-center text-xs text-text-4 font-sans",children:["No ",l," models available for your hardware"]})]}),!A&&T.length>B.length&&e.jsxs("button",{onClick:()=>f(!0),className:"flex items-center gap-1 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(xt,{size:10}),"Show ",T.length-B.length," more (exceed your RAM)"]})]})}function Eoe({isInstalled:t,onModelChange:s}){const[n,a]=p.useState(!1),[r,l]=p.useState(!1);return p.useEffect(()=>{t?G.post("/providers/ollama/check").then(c=>{a(c.installed&&c.serverRunning),l(!0)}).catch(()=>l(!0)):l(!0)},[t]),r?n?e.jsx(Uoe,{onModelChange:s}):e.jsx(Boe,{onRecheck:()=>{a(!0),s&&s()}}):e.jsx("div",{className:"py-4 text-center text-xs text-text-4 font-sans",children:"Checking Ollama..."})}function Ef({options:t,value:s,onChange:n}){return e.jsx("div",{className:"flex bg-surface-0 rounded-lg p-0.5 border border-border-subtle",children:t.map(a=>e.jsx("button",{onClick:()=>n(a.value),className:Z("flex-1 px-3 py-1.5 text-2xs font-semibold font-sans rounded-md transition-all cursor-pointer",s===a.value?"bg-accent/15 text-accent shadow-sm":"text-text-3 hover:text-text-1"),children:a.label},a.value))})}function aa({label:t,icon:s,children:n,description:a}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs font-semibold text-text-1 font-sans",children:[s&&e.jsx(s,{size:13,className:"text-text-3"}),t]}),a&&e.jsx("p",{className:"text-2xs text-text-4 font-sans mt-0.5",children:a})]}),n]})}function Poe({agent:t}){const s=k(v=>v.killAgent),n=k(v=>v.rotateAgent),a=k(v=>v.spawnAgent),r=k(v=>v.closeDetail),l=k(v=>v.addToast),[c,A]=p.useState(null),[f,x]=p.useState(!1),h=t.status==="running"||t.status==="starting";async function g(){A("rotate");try{await n(t.id)}catch{}A(null)}async function O(){if(!f){x(!0),setTimeout(()=>x(!1),3e3);return}A("kill");try{await s(t.id,!h),r()}catch{}A(null),x(!1)}async function b(){A("clone");try{await a({role:t.role,provider:t.provider,model:t.model,name:`${t.name}-clone`,scope:t.scope,workingDir:t.workingDir}),l("success",`Cloned ${t.name}`)}catch{}A(null)}return h?e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs(pe,{variant:"primary",size:"md",onClick:g,disabled:c==="rotate",className:"gap-1.5",children:[e.jsx(hd,{size:12,className:c==="rotate"?"animate-spin":""}),"Rotate"]}),e.jsxs(pe,{variant:"info",size:"md",onClick:b,disabled:!!c,className:"gap-1.5",children:[e.jsx(Ba,{size:12})," Clone"]}),e.jsxs(pe,{variant:"danger",size:"md",onClick:O,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(Db,{size:12}),f?"Confirm":"Kill"]})]})}):e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs(pe,{variant:"info",size:"md",onClick:b,disabled:!!c,className:"gap-1.5",children:[e.jsx(Ba,{size:12})," Clone"]}),e.jsxs(pe,{variant:"danger",size:"md",onClick:O,disabled:c==="kill",className:"gap-1.5",children:[e.jsx(Ft,{size:12}),f?"Confirm":"Remove"]})]})}function Foe({agent:t}){var Fe;const s=k(Ae=>Ae.addToast),n=k(Ae=>Ae.remoteHomedir),[a,r]=p.useState([]),[l,c]=p.useState(t.model||""),[A,f]=p.useState(""),[x,h]=p.useState(t.effort||"default"),[g,O]=p.useState(!1),[b,v]=p.useState(""),[y,S]=p.useState(null),[j,N]=p.useState(!1),[C,U]=p.useState(null),[P,T]=p.useState(t.routingMode||"auto"),[B,F]=p.useState([]),[M,R]=p.useState(""),[Y,W]=p.useState(!1),[ee,K]=p.useState([]),[_,E]=p.useState(!1),[q,H]=p.useState([]),[I,L]=p.useState(null),[J,D]=p.useState(t.authMode||"subscription"),[se,le]=p.useState(!1),V=t.status==="running"||t.status==="starting";p.useEffect(()=>{te(),G.get("/integrations/installed").then(ke=>H(Array.isArray(ke)?ke:[])).catch(()=>{}),G.get("/repos/imported").then(ke=>F((Array.isArray(ke)?ke:[]).filter(Re=>Re.status==="active"))).catch(()=>{}),t.provider==="claude-code"&&(G.get("/providers/claude-code/auth").then(ke=>L(ke)).catch(()=>L(null)),G.get("/credentials").then(ke=>le(Array.isArray(ke)&&ke.some(Re=>Re.provider==="claude-code"))).catch(()=>le(!1)));function Ae(){te()}return window.addEventListener("groove:providers-changed",Ae),()=>window.removeEventListener("groove:providers-changed",Ae)},[]);function te(){G.get("/providers").then(Ae=>r(Array.isArray(Ae)?Ae:[])).catch(()=>{})}p.useEffect(()=>{D(t.authMode||"subscription")},[t.id,t.authMode]),p.useEffect(()=>{c(t.model||""),G.get(`/agents/${t.id}/routing/recommend`).then(Ae=>{T((Ae==null?void 0:Ae.mode)||"fixed")}).catch(()=>{})},[t.id,t.model]),p.useEffect(()=>{W(!1),t.personality?G.get(`/personalities/${t.name}`).then(Ae=>{R((Ae==null?void 0:Ae.content)||""),W(!0)}).catch(()=>{R(""),W(!0)}):(R(""),W(!0)),G.get("/personalities").then(Ae=>{K(Array.isArray(Ae)?Ae:Ae.personalities||[])}).catch(()=>{})},[t.id,t.name]);const ae=a.find(Ae=>Ae.id===t.provider);async function be(Ae){const ke=J;D(Ae);try{await G.patch(`/agents/${t.id}`,{authMode:Ae}),s("success",`Billing → ${Ae==="usage"?"usage credits":"subscription"}`)}catch(Re){D(ke),s("error","Failed to change billing mode",Re.message)}}async function z(Ae,ke){c(ke);try{const Re={model:ke};Ae&&Ae!==t.provider&&(Re.provider=Ae),await G.patch(`/agents/${t.id}`,Re),s("success",`Model → ${ke}${Re.provider?` (${Ae})`:""}`)}catch(Re){s("error","Model swap failed",Re.message)}}async function oe(Ae){try{await G.patch(`/agents/${t.id}`,{workingDir:Ae}),s("success",`Working dir → ${Ae.split("/").pop()||Ae}`)}catch(ke){s("error","Update failed",ke.message)}}async function ue(Ae){h(Ae);try{await G.patch(`/agents/${t.id}`,{effort:Ae}),s("success",`Effort → ${Ae}`)}catch(ke){s("error","Update failed",ke.message)}}async function ve(Ae){if(!Ae.trim())return;const ke=[...t.scope||[],Ae.trim()];try{await G.patch(`/agents/${t.id}`,{scope:ke}),f("")}catch(Re){s("error","Scope update failed",Re.message)}}async function Ce(Ae){const ke=(t.scope||[]).filter((Re,Nt)=>Nt!==Ae);try{await G.patch(`/agents/${t.id}`,{scope:ke})}catch(Re){s("error","Scope update failed",Re.message)}}async function Ne(Ae){if(b.trim())try{await G.post(`/credentials/${Ae}`,{key:b.trim()}),s("success",`API key set for ${Ae}`),v(""),S(null),te(),window.dispatchEvent(new CustomEvent("groove:providers-changed"))}catch(ke){s("error","Failed to set key",ke.message)}}const Xe=t.spawnedAt||t.createdAt;return e.jsxs("div",{className:"px-5 py-5 space-y-6 overflow-y-auto h-full",children:[e.jsx(aa,{label:"Active Model",icon:ka,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold font-mono text-text-0",children:t.model||"auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans mt-0.5",children:(ae==null?void 0:ae.name)||t.provider})]}),(ae==null?void 0:ae.canHotSwap)&&V&&e.jsxs(Te,{variant:"accent",className:"text-2xs gap-1",children:[e.jsx(qt,{size:8})," Hot-swap"]})]}),((Fe=ae==null?void 0:ae.models)==null?void 0:Fe.length)>1&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3 pt-3 border-t border-border-subtle",children:ae.models.filter(Ae=>!Ae.disabled).map(Ae=>{const ke=Ae.id===t.model;return e.jsx("button",{onClick:()=>z(t.provider,Ae.id),disabled:!1,className:Z("px-2.5 py-1 rounded-md text-xs font-mono transition-all","cursor-pointer",ke?"bg-accent/15 text-accent font-semibold":"bg-surface-4 text-text-2 hover:bg-surface-5 hover:text-text-0"),children:Ae.name||Ae.id},Ae.id)})}),t.provider==="claude-code"&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-2xs font-medium text-text-2 font-sans",children:"Billing"}),e.jsx("div",{className:"flex gap-1 p-0.5 rounded-md bg-surface-3",children:[{id:"subscription",label:"Subscription"},{id:"usage",label:"Usage credits"}].map(Ae=>e.jsx("button",{onClick:()=>be(Ae.id),disabled:Ae.id==="usage"&&!se,className:Z("px-2 py-1 rounded text-2xs font-semibold font-sans transition-colors",Ae.id==="usage"&&!se&&"opacity-40 cursor-not-allowed",J===Ae.id?"bg-accent text-white":"text-text-2 hover:text-text-0"),children:Ae.label},Ae.id))})]}),e.jsx("p",{className:"text-2xs text-text-3 font-sans mt-1.5",children:se?"Applies on next rotation or restart — the running process keeps its current billing.":"Add an Anthropic API key in Settings → Providers to enable usage credits."})]})]})}),e.jsx(Poe,{agent:t}),e.jsxs(aa,{label:"Providers",icon:rc,description:"Click a provider to see its models and connection status.",children:[e.jsx("div",{className:"space-y-1.5",children:a.map(Ae=>{var ar;const ke=Ae.id===t.provider,Re=Ae.authType==="subscription"?Ae.installed||((ar=Ae.authStatus)==null?void 0:ar.authenticated):Ae.authType==="local"?Ae.installed:Ae.installed&&Ae.hasKey,Nt=C===Ae.id,Ss=Ae.models||[];return e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-surface-0 overflow-hidden",children:[e.jsxs("button",{onClick:()=>U(Nt?null:Ae.id),className:"w-full flex items-center gap-2.5 px-3 py-2 cursor-pointer hover:bg-surface-4/50 transition-colors",children:[e.jsx("div",{className:Z("w-2 h-2 rounded-full flex-shrink-0",Re?"bg-success":"bg-text-4")}),e.jsx("span",{className:Z("text-xs font-semibold font-sans flex-1 text-left",Re?"text-text-0":"text-text-3"),children:Ae.name||Ae.id}),ke&&e.jsx(Te,{variant:"accent",className:"text-2xs",children:"Active"}),!Re&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:Ae.installed?"No key":"Not installed"}),e.jsx(xt,{size:12,className:Z("text-text-4 transition-transform",Nt&&"rotate-180")})]}),Nt&&Ae.authType==="local"&&e.jsx("div",{className:"border-t border-border-subtle",children:e.jsx(Eoe,{isInstalled:Re,onModelChange:te})}),Nt&&Ae.authType!=="local"&&e.jsxs("div",{className:"border-t border-border-subtle",children:[(!Re||Ae.hasKey)&&e.jsx("div",{className:"px-3 py-2 bg-surface-1/50",children:y===Ae.id?e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx("input",{value:b,onChange:ts=>v(ts.target.value),onKeyDown:ts=>ts.key==="Enter"&&Ne(Ae.id),type:j?"text":"password",placeholder:`${Ae.name||Ae.id} API key...`,className:"w-full h-7 px-2.5 pr-7 text-2xs bg-surface-0 border border-border rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent",autoFocus:!0}),e.jsx("button",{onClick:()=>N(!j),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 hover:text-text-2 cursor-pointer",children:j?e.jsx(To,{size:10}):e.jsx(Vs,{size:10})})]}),e.jsx(pe,{variant:"primary",size:"sm",onClick:()=>Ne(Ae.id),disabled:!b.trim(),className:"h-7 px-2 text-2xs",children:"Save"}),e.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>{S(null),v("")},className:"h-7 px-2 text-2xs",children:"Cancel"})]}):e.jsxs("button",{onClick:()=>{S(Ae.id),v(""),N(!1)},className:"flex items-center gap-1.5 text-2xs text-text-3 hover:text-accent font-sans cursor-pointer transition-colors",children:[e.jsx(Ti,{size:10}),Re?"Update API key":"Add API key to enable"]})}),Re&&Ss.filter(ts=>!ts.disabled).length>0&&Ss.filter(ts=>!ts.disabled).map(ts=>{const is=Ae.id===t.provider&&ts.id===t.model;return e.jsxs("button",{onClick:()=>z(Ae.id,ts.id),disabled:!1,className:Z("w-full flex items-center gap-2 px-3 py-2 text-left text-xs font-sans transition-colors","border-t border-border-subtle","cursor-pointer hover:bg-surface-4/50",is?"text-accent":"text-text-2"),children:[is?e.jsx(Je,{size:11,className:"text-accent flex-shrink-0"}):e.jsx("div",{className:"w-[11px]"}),e.jsx("span",{className:"font-mono flex-1 truncate",children:ts.name||ts.id}),e.jsx(Te,{variant:is?"accent":"default",className:"text-2xs",children:ts.tier})]},ts.id)})]})]},Ae.id)})}),V&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-text-3 font-sans mt-1.5",children:[e.jsx(Ks,{size:10}),e.jsx("span",{children:"Model changes apply on next rotation or respawn."})]})]}),t.provider==="claude-code"&&I&&!I.authenticated&&e.jsxs("div",{className:"rounded-lg border border-warning/30 bg-warning/5 px-4 py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Claude Code is not signed in"})]}),e.jsxs("p",{className:"text-2xs text-text-2 font-sans",children:["Open the terminal and run: ",e.jsx("code",{className:"font-mono text-accent bg-surface-4 px-1.5 py-0.5 rounded text-2xs",children:"claude"})]})]}),t.provider==="claude-code"&&(I==null?void 0:I.authenticated)&&e.jsxs("div",{className:"flex items-center gap-2 text-2xs text-text-2 font-sans",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-success flex-shrink-0"}),"Signed in as ",I.email||"Claude user"," (",I.subscriptionType||"subscription",")"]}),e.jsx(aa,{label:"Working Directory",icon:Ys,description:"The root directory this agent operates in.",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1 bg-surface-0 rounded-lg px-3 py-2.5 text-sm font-mono text-text-1 border border-border-subtle truncate min-w-0",children:t.workingDir||"Project root"}),e.jsxs(pe,{variant:"secondary",size:"md",onClick:()=>O(!0),className:"gap-1.5 flex-shrink-0",children:[e.jsx(Rb,{size:14})," Browse"]})]})}),e.jsx(aa,{label:"Permission Mode",icon:vn,description:"Full Send = no approvals. Agent Approve = Fullstack Manager reviews risky operations.",children:e.jsx(Ef,{options:[{value:"full",label:"Full Send"},{value:"auto",label:"Agent Approve"}],value:t.permission||"full",onChange:async Ae=>{try{await G.patch(`/agents/${t.id}`,{permission:Ae}),s("success",`Permission → ${Ae==="full"?"Full Send":"Agent Approve"}`)}catch(ke){s("error","Update failed",ke.message)}}})}),e.jsxs(aa,{label:"Model Routing",icon:Ro,description:"How Groove selects models for this agent's tasks.",children:[e.jsx(Ef,{options:[{value:"fixed",label:"Fixed"},{value:"auto",label:"Auto"},{value:"auto-floor",label:"Auto + Floor"}],value:P,onChange:async Ae=>{T(Ae);try{await G.post(`/agents/${t.id}/routing`,{mode:Ae}),s("success",`Routing → ${Ae}`)}catch(ke){s("error","Update failed",ke.message)}}}),e.jsxs("div",{className:"text-2xs text-text-4 font-sans mt-1",children:[P==="fixed"&&"Uses the selected model for all tasks.",P==="auto"&&"Groove picks Opus/Sonnet/Haiku based on task complexity.",P==="auto-floor"&&"Auto-routes but never drops below Sonnet."]})]}),e.jsx(aa,{label:"File Scope",icon:vn,description:"Restrict which files this agent can access. Empty = unrestricted.",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(t.scope||[]).map((Ae,ke)=>e.jsxs(Te,{variant:"default",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[Ae,e.jsx("button",{onClick:()=>Ce(ke),className:"hover:text-danger cursor-pointer",children:e.jsx(qe,{size:10})})]},ke)),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{value:A,onChange:Ae=>f(Ae.target.value),onKeyDown:Ae=>Ae.key==="Enter"&&ve(A),placeholder:"e.g. src/**",className:"w-28 h-7 px-2.5 text-xs bg-surface-0 border border-border-subtle rounded-md text-text-0 font-mono placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsx("button",{onClick:()=>ve(A),disabled:!A.trim(),className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:e.jsx(it,{size:12})})]})]})}),e.jsx(aa,{label:"Effort Level",icon:SS,description:"Controls how deep the agent reasons. Higher = more tokens but better results.",children:e.jsx(Ef,{options:[{value:"min",label:"Min"},{value:"low",label:"Low"},{value:"default",label:"Default"},{value:"high",label:"High"},{value:"max",label:"Max"},{value:"ultra",label:"Ultra"}],value:x,onChange:ue})}),e.jsx(aa,{label:"Agent Details",icon:rc,children:e.jsxs("div",{className:"bg-surface-0 rounded-lg border border-border-subtle divide-y divide-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"ID"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.id})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Role"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.role})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Provider"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.provider})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Model"}),e.jsx("span",{className:"text-xs text-text-1 font-mono",children:t.model||"auto"})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Status"}),e.jsx("span",{className:"text-xs text-text-1 font-sans capitalize",children:t.status})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Spawned"}),e.jsx("span",{className:"text-xs text-text-1 font-sans",children:Xe?$t(Xe):"—"})]}),t.sessionId&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-xs text-text-3 font-sans",children:"Session"}),e.jsxs("span",{className:"text-xs text-text-1 font-mono",children:[t.sessionId.slice(0,16),"..."]})]})]})}),e.jsxs(aa,{label:"Integrations",icon:on,description:"Attach MCP integrations for external services.",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.integrations||[]).map(Ae=>{const ke=Ni[Ae],Re=q.find(Nt=>Nt.id===Ae);return e.jsxs(Te,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[ke?e.jsx("img",{src:ke,alt:"",className:"w-2.5 h-2.5"}):e.jsx(on,{size:9}),(Re==null?void 0:Re.name)||Ae,e.jsx("button",{onClick:async()=>{try{await G.delete(`/agents/${t.id}/integrations/${Ae}`),s("success",`Detached ${(Re==null?void 0:Re.name)||Ae}`)}catch(Nt){s("error","Detach failed",Nt.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(qe,{size:10})})]},Ae)}),q.filter(Ae=>Ae.configured!==!1&&!(t.integrations||[]).includes(Ae.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(it,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:q.filter(Ae=>Ae.configured!==!1&&!(t.integrations||[]).includes(Ae.id)).map(Ae=>{const ke=Ni[Ae.id];return e.jsxs("button",{onClick:async()=>{try{await G.post(`/agents/${t.id}/integrations/${Ae.id}`),s("success",`Attached ${Ae.name||Ae.id}`)}catch(Re){s("error","Attach failed",Re.message)}},className:"w-full flex items-center gap-2 text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-4 cursor-pointer transition-colors",children:[ke?e.jsx("img",{src:ke,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(on,{size:12,className:"text-text-3 flex-shrink-0"}),Ae.name||Ae.id]},Ae.id)})})]}),(t.integrations||[]).length===0&&q.length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No integrations installed — browse the Marketplace"})]}),(t.integrations||[]).length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"text-2xs font-medium text-text-3 font-sans block mb-1.5",children:"Integration Approvals"}),e.jsx(Ef,{options:[{value:"auto",label:"Auto"},{value:"manual",label:"Manual"}],value:t.integrationApproval||"manual",onChange:async Ae=>{try{await G.patch(`/agents/${t.id}`,{integrationApproval:Ae}),s("success",`Integration approvals → ${Ae==="auto"?"Auto":"Manual"}`)}catch(ke){s("error","Update failed",ke.message)}}})]})]}),B.length>0&&e.jsx(aa,{label:"Repos",icon:Kl,description:"Attach imported repos so this agent knows where they are.",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[(t.repos||[]).map(Ae=>{const ke=B.find(Re=>Re.id===Ae);return e.jsxs(Te,{variant:"accent",className:"font-mono text-xs gap-1.5 px-2.5 py-1",children:[(ke==null?void 0:ke.name)||Ae,e.jsx("button",{onClick:async()=>{try{await G.delete(`/agents/${t.id}/repos/${Ae}`),s("success",`Detached ${(ke==null?void 0:ke.name)||Ae}`)}catch(Re){s("error","Detach failed",Re.message)}},className:"hover:text-danger cursor-pointer",children:e.jsx(qe,{size:10})})]},Ae)}),B.filter(Ae=>!(t.repos||[]).includes(Ae.id)).length>0&&e.jsxs("div",{className:"relative group",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center rounded-md bg-surface-4 border border-border-subtle text-text-3 hover:text-accent cursor-pointer transition-colors",children:e.jsx(it,{size:12})}),e.jsx("div",{className:"absolute top-full left-0 mt-1 z-20 hidden group-hover:block bg-surface-2 border border-border-subtle rounded-lg shadow-xl py-1 min-w-[200px]",children:B.filter(Ae=>!(t.repos||[]).includes(Ae.id)).map(Ae=>e.jsxs("button",{onClick:async()=>{try{await G.post(`/agents/${t.id}/repos/${Ae.id}`),s("success",`Attached ${Ae.name||Ae.id}`)}catch(ke){s("error","Attach failed",ke.message)}},className:"w-full text-left px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-4 cursor-pointer transition-colors",children:[e.jsx("div",{className:"font-semibold",children:Ae.name||Ae.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:Ae.clonedTo})]},Ae.id))})]}),(t.repos||[]).length===0&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"No repos attached — import one from the Marketplace"})]})}),e.jsxs(aa,{label:"Personality",icon:Ho,description:"Injected into every prompt. Changes apply on next spawn or rotation.",children:[e.jsx("textarea",{value:M,onChange:Ae=>R(Ae.target.value),placeholder:Y?"Describe this agent's personality, tone, and behavior...":"Loading...",rows:4,className:"w-full min-h-[4rem] max-h-[10rem] resize-y bg-surface-0 border border-border-subtle rounded-md p-2 text-xs font-mono text-text-1 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(pe,{variant:"primary",size:"sm",disabled:_,onClick:async()=>{E(!0);try{await G.put(`/personalities/${t.name}`,{content:M}),s("success","Personality saved")}catch(Ae){s("error","Save failed",Ae.message)}E(!1)},className:"h-7 px-3 text-2xs gap-1",children:[e.jsx(_r,{size:10}),_?"Saving...":"Save"]}),ee.length>0&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:"",onChange:Ae=>{if(!Ae.target.value)return;const ke=ee.find(Re=>(Re.name||Re)===Ae.target.value);ke&&G.get(`/personalities/${ke.name||ke}`).then(Re=>{Re!=null&&Re.content&&R(Re.content)}).catch(()=>{})},className:"h-7 px-2 pr-7 text-2xs rounded-md bg-surface-1 border border-border-subtle text-text-2 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Clone from..."}),ee.filter(Ae=>(Ae.name||Ae)!==t.name).map(Ae=>e.jsx("option",{value:Ae.name||Ae,children:Ae.name||Ae},Ae.name||Ae))]}),e.jsx(xt,{size:10,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-4 pointer-events-none"})]})]})]}),t.prompt&&e.jsx(aa,{label:"Original Prompt",icon:Ro,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3 py-3 text-xs text-text-2 font-sans leading-relaxed max-h-40 overflow-y-auto",children:t.prompt})}),e.jsx(gc,{open:g,onOpenChange:O,currentPath:t.workingDir||n||"/",homePath:n,onSelect:oe})]})}const aN=[];function $oe({data:t,isAlive:s,height:n=48}){const a=p.useRef(null);return p.useEffect(()=>{const r=a.current;if(!r||!t.length)return;const l=r.getContext("2d"),c=window.devicePixelRatio||1,A=r.clientWidth,f=r.clientHeight;r.width=A*c,r.height=f*c,l.scale(c,c),l.clearRect(0,0,A,f);const x=t.map(v=>v.v),h=Math.min(...x),O=Math.max(...x,1)-h||1;l.beginPath(),l.moveTo(0,f),t.forEach((v,y)=>{const S=y/(t.length-1)*A,j=f-(v.v-h)/O*(f-4)-2;l.lineTo(S,j)}),l.lineTo(A,f),l.closePath();const b=l.createLinearGradient(0,0,0,f);if(b.addColorStop(0,s?"rgba(51,175,188,0.15)":"rgba(110,118,129,0.08)"),b.addColorStop(1,"rgba(0,0,0,0)"),l.fillStyle=b,l.fill(),l.beginPath(),l.strokeStyle=s?ce.accent:ce.text3,l.lineWidth=1.5,t.forEach((v,y)=>{const S=y/(t.length-1)*A,j=f-(v.v-h)/O*(f-4)-2;y===0?l.moveTo(S,j):l.lineTo(S,j)}),l.stroke(),t.length>1&&s){const v=t[t.length-1],y=A-1,S=f-(v.v-h)/O*(f-4)-2;l.beginPath(),l.arc(y,S,5,0,Math.PI*2),l.fillStyle="rgba(51,175,188,0.3)",l.fill(),l.beginPath(),l.arc(y,S,2.5,0,Math.PI*2),l.fillStyle=ce.accent,l.fill()}},[t,s]),e.jsx("div",{className:"w-full rounded-lg bg-surface-0 overflow-hidden border border-border-subtle",style:{height:n},children:e.jsx("canvas",{ref:a,className:"w-full h-full"})})}function Pf({icon:t,label:s,value:n,color:a,sub:r}){return e.jsxs("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(t,{size:12,className:a||"text-text-3"}),e.jsx("span",{className:"text-2xs text-text-4 font-sans uppercase tracking-wider",children:s})]}),e.jsx("div",{className:Z("text-lg font-bold font-mono tabular-nums",a||"text-text-0"),children:n}),r&&e.jsx("div",{className:"text-2xs text-text-4 font-sans mt-0.5",children:r})]})}function Roe({score:t}){const s=Math.min(Math.max(t,0),100);let n=ce.success,a="Healthy";return s<40?(n=ce.danger,a="Degraded"):s<70&&(n=ce.warning,a="Fair"),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-2xs text-text-3 font-sans flex items-center gap-1.5",children:[e.jsx(fM,{size:11}),"Session Health"]}),e.jsxs("span",{className:"text-xs font-bold font-mono",style:{color:n},children:[s,"/100"]})]}),e.jsx("div",{className:"h-2 bg-surface-0 rounded-full overflow-hidden border border-border-subtle",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700",style:{width:`${s}%`,background:n}})}),e.jsx("span",{className:"text-2xs font-sans mt-1 block",style:{color:n},children:a})]})}function Moe(t){const s=(t||"").toLowerCase();return s.includes("edit")||s.includes("writ")?{icon:KA,color:"text-warning"}:s.includes("read")||s.includes("view")?{icon:Vs,color:"text-info"}:s.includes("search")||s.includes("grep")||s.includes("glob")?{icon:As,color:"text-purple"}:s.includes("bash")||s.includes("command")||s.includes("terminal")?{icon:Wa,color:"text-orange"}:s.includes("error")||s.includes("fail")?{icon:Ks,color:"text-danger"}:s.includes("spawn")||s.includes("start")?{icon:qt,color:"text-success"}:s.includes("complet")||s.includes("done")?{icon:rx,color:"text-success"}:{icon:Dn,color:"text-text-4"}}function Ioe({agent:t}){const s=k(c=>c.tokenTimeline[t.id])||aN,n=k(c=>c.activityLog[t.id])||aN,a=t.status==="running"||t.status==="starting",r=p.useMemo(()=>{if(s.length<2)return 0;const c=s.slice(-10),A=(c[c.length-1].t-c[0].t)/6e4,f=c[c.length-1].v-c[0].v;return A>0?Math.round(f/A):0},[s]),l=p.useMemo(()=>{const c=t.contextUsage||0;let A=100;return c>90?A-=50:c>70?A-=25:c>50&&(A-=10),r>5e3?A-=15:r>3e3&&(A-=8),t.status==="crashed"&&(A=10),t.status==="completed"&&(A=95),Math.max(0,Math.min(100,A))},[t.contextUsage,t.status,r]);return e.jsxs("div",{className:"px-5 py-5 space-y-5 overflow-y-auto h-full",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider",children:"Token Burn"}),a&&e.jsx("span",{className:"text-2xs text-accent font-mono animate-pulse",children:"LIVE"})]}),e.jsx($oe,{data:s,isAlive:a,height:56})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Pf,{icon:ZR,label:"Burn Rate",value:r>0?`${jt(r)}/m`:"—",color:r>5e3?"text-danger":r>2e3?"text-warning":"text-text-0"}),e.jsx(Pf,{icon:jS,label:"Cost",value:er(t.costUsd||0),color:"text-text-0"}),e.jsx(Pf,{icon:hd,label:"Rotations",value:t.rotations||"0",color:"text-text-0"}),e.jsx(Pf,{icon:qt,label:"Turns",value:t.turns||"0",color:"text-text-0"})]}),e.jsx(Roe,{score:l}),t.prompt&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-1.5",children:"Task"}),e.jsx("div",{className:"bg-surface-0 rounded-lg px-3 py-2.5 text-xs text-text-2 font-sans leading-relaxed max-h-28 overflow-y-auto border border-border-subtle",children:t.prompt})]}),n.length>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-2xs font-semibold text-text-3 font-sans uppercase tracking-wider block mb-2",children:"Activity"}),e.jsxs("div",{className:"space-y-0 relative",children:[e.jsx("div",{className:"absolute left-[9px] top-2 bottom-2 w-px bg-border-subtle"}),n.slice(-12).reverse().map((c,A)=>{const f=Moe(c.text),x=f.icon;return e.jsxs("div",{className:"flex items-start gap-3 py-1.5 relative",children:[e.jsx("div",{className:Z("w-[18px] h-[18px] rounded-full flex items-center justify-center flex-shrink-0 z-10","bg-surface-1 border border-border-subtle"),children:e.jsx(x,{size:9,className:f.color})}),e.jsx("span",{className:"text-2xs text-text-2 font-sans flex-1 line-clamp-1 pt-0.5",children:c.text}),e.jsx("span",{className:"text-2xs text-text-4 font-mono flex-shrink-0 pt-0.5",children:$t(c.timestamp)})]},A)})]})]})]})}function zoe({agent:t}){const s=k(B=>B.addToast),[n,a]=p.useState([]),[r,l]=p.useState(""),[c,A]=p.useState(null),[f,x]=p.useState(""),[h,g]=p.useState(""),[O,b]=p.useState(!1),[v,y]=p.useState(!1),[S,j]=p.useState("");async function N(){try{const B=await G.get(`/agents/${t.id}/mdfiles`);a(B.files||[]),l(B.workingDir||"")}catch{}}p.useEffect(()=>{N()},[t.id]);async function C(B){try{const F=await G.get(`/agents/${t.id}/mdfiles/read?path=${encodeURIComponent(B)}`);x(F.content||""),g(F.content||""),A(B)}catch(F){s("error","Failed to read file",F.message)}}async function U(){if(c){b(!0);try{await G.put(`/agents/${t.id}/mdfiles/write`,{path:c,content:f}),g(f),s("success",`Saved ${c}`)}catch(B){s("error","Save failed",B.message)}b(!1)}}async function P(){const B=S.trim();if(B)try{await G.post(`/agents/${t.id}/mdfiles/create`,{name:B}),j(""),y(!1),s("success",`Created ${B}.md`),N()}catch(F){s("error","Create failed",F.message)}}const T=f!==h;return c?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border-subtle",children:[e.jsx("button",{onClick:()=>{A(null),x(""),g("")},className:"p-1 text-text-3 hover:text-text-0 cursor-pointer",children:e.jsx(Di,{size:14})}),e.jsx(On,{size:12,className:"text-accent"}),e.jsx("span",{className:"text-xs text-text-0 font-sans font-medium flex-1 truncate",children:c}),T&&e.jsx("span",{className:"text-[10px] text-warning font-sans",children:"unsaved"}),e.jsxs("button",{onClick:U,disabled:!T||O,className:Z("flex items-center gap-1 px-2.5 py-1 rounded text-2xs font-sans font-medium cursor-pointer transition-colors",T?"bg-accent/15 text-accent hover:bg-accent/25":"text-text-4 opacity-50 cursor-not-allowed"),children:[e.jsx(_r,{size:10}),O?"Saving...":"Save"]})]}),e.jsx("textarea",{value:f,onChange:B=>x(B.target.value),className:"flex-1 w-full px-4 py-3 bg-surface-0 text-[12px] font-mono text-text-1 leading-relaxed resize-none focus:outline-none",spellCheck:!1})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border-subtle",children:[e.jsx(On,{size:12,className:"text-text-3"}),e.jsx("span",{className:"text-2xs font-semibold text-text-2 font-sans uppercase tracking-wider flex-1",children:"Markdown Files"}),e.jsx("button",{onClick:()=>y(!0),className:"p-1 text-text-4 hover:text-accent cursor-pointer",title:"Create file",children:e.jsx(it,{size:12})}),e.jsx("button",{onClick:N,className:"p-1 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(Ls,{size:11})})]}),r&&e.jsx("div",{className:"px-4 py-1.5 text-[10px] text-text-4 font-mono truncate border-b border-border-subtle/50",children:r}),v&&e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-b border-border-subtle bg-surface-0",children:[e.jsx(On,{size:11,className:"text-accent flex-shrink-0"}),e.jsx("input",{autoFocus:!0,value:S,onChange:B=>j(B.target.value),onKeyDown:B=>{B.key==="Enter"&&P(),B.key==="Escape"&&(y(!1),j(""))},placeholder:"filename",className:"flex-1 bg-transparent text-xs text-text-0 font-mono outline-none placeholder:text-text-4"}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:".md"}),e.jsx("button",{onClick:P,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(_r,{size:11})}),e.jsx("button",{onClick:()=>{y(!1),j("")},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:11})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center px-4",children:[e.jsx(On,{size:20,className:"text-text-4 mb-2"}),e.jsx("p",{className:"text-xs text-text-3 font-sans",children:"No markdown files found"}),e.jsx("p",{className:"text-[10px] text-text-4 font-sans mt-1",children:"MD files in the agent's working directory will appear here"})]}):e.jsx("div",{className:"py-1",children:n.map(B=>e.jsxs("button",{onClick:()=>C(B.path),className:"w-full flex items-center gap-2.5 px-4 py-2 text-left hover:bg-surface-5 transition-colors cursor-pointer",children:[e.jsx(On,{size:13,className:"text-accent flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-xs text-text-0 font-sans block truncate",children:B.name}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono",children:B.path})]}),e.jsx("span",{className:"text-[10px] text-text-4 font-mono flex-shrink-0",children:B.size>1024?`${(B.size/1024).toFixed(1)}K`:`${B.size}B`}),B.source==="personality"&&e.jsx("span",{className:"text-[9px] font-mono text-purple bg-purple/10 px-1 py-px rounded flex-shrink-0",children:"personality"}),B.source==="user"&&e.jsx("span",{className:"text-[9px] font-mono text-accent bg-accent/10 px-1 py-px rounded flex-shrink-0",children:"custom"})]},B.path))})})]})}const _oe={running:"bg-accent",starting:"bg-warning",completed:"bg-info",crashed:"bg-danger",stopped:"bg-text-4",killed:"bg-text-4",rotating:"bg-accent"},Doe={running:"success",starting:"warning",stopped:"default",crashed:"danger",completed:"accent",killed:"default",rotating:"purple"},Loe={running:"Running",starting:"Starting",stopped:"Stopped",crashed:"Crashed",completed:"Done",killed:"Killed",rotating:"Rotating"},Hoe=[{id:"command",label:"Chat",icon:fa},{id:"config",label:"Config",icon:oc},{id:"telemetry",label:"Monitor",icon:Ro},{id:"mdfiles",label:"Files",icon:On}];function Xoe({agent:t}){const s=k(j=>j.addToast),n=k(j=>j.agents),a=k(j=>j.teams),r=k(j=>j.switchAgentPanel),[l,c]=p.useState(!1),[A,f]=p.useState(t.name),[x,h]=p.useState(!1),[g,O]=p.useState(""),b=p.useRef(null);p.useEffect(()=>{if(!x)return;const j=C=>{b.current&&!b.current.contains(C.target)&&h(!1)},N=C=>{C.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",j),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",N)}},[x]);const v=p.useMemo(()=>{const j=g.trim().toLowerCase(),N=new Map;for(const C of n){if(j&&!C.name.toLowerCase().includes(j)&&!C.role.toLowerCase().includes(j))continue;const U=C.teamId||"_none";N.has(U)||N.set(U,[]),N.get(U).push(C)}return Array.from(N.entries()).map(([C,U])=>{var P;return{teamId:C,name:((P=a.find(T=>T.id===C))==null?void 0:P.name)||"No team",agents:U.sort((T,B)=>T.name.localeCompare(B.name))}}).sort((C,U)=>C.name.localeCompare(U.name))},[n,a,g]);async function y(){const j=A.trim();if(!j||j===t.name){c(!1);return}try{await G.patch(`/agents/${t.id}`,{name:j.replace(/\s+/g,"-")}),s("success",`Renamed → ${j}`)}catch(N){s("error","Rename failed",N.message),f(t.name)}c(!1)}function S(j){h(!1),O(""),j!==t.id&&r(j)}return l?e.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0",children:[e.jsx("input",{value:A,onChange:j=>f(j.target.value),onKeyDown:j=>{j.key==="Enter"&&y(),j.key==="Escape"&&(f(t.name),c(!1))},className:"flex-1 min-w-0 h-6 px-1.5 text-sm font-bold bg-surface-0 border border-accent/30 rounded text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent/40",autoFocus:!0}),e.jsx("button",{onClick:y,className:"p-0.5 text-accent hover:text-accent/80 cursor-pointer",children:e.jsx(Je,{size:12})}),e.jsx("button",{onClick:()=>{f(t.name),c(!1)},className:"p-0.5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:12})})]}):e.jsxs("div",{ref:b,className:"relative flex items-center gap-1.5 flex-1 min-w-0 group",children:[e.jsxs("button",{onClick:()=>h(j=>!j),className:"flex items-center gap-1 min-w-0 cursor-pointer rounded px-1 -mx-1 py-0.5 hover:bg-surface-3 transition-colors",title:"Switch agent",children:[e.jsx("h2",{className:"text-sm font-bold text-text-0 font-sans truncate",children:t.name}),e.jsx(xt,{size:13,className:Z("text-text-4 flex-shrink-0 transition-transform",x&&"rotate-180")})]}),e.jsx("button",{onClick:()=>{f(t.name),c(!0)},className:"p-0.5 text-text-4 opacity-0 group-hover:opacity-100 hover:text-text-1 cursor-pointer transition-opacity flex-shrink-0",title:"Rename agent",children:e.jsx(Ua,{size:10})}),x&&e.jsxs("div",{className:"absolute top-full left-0 mt-1.5 w-72 max-h-[70vh] flex flex-col bg-surface-1 border border-border rounded-lg shadow-xl z-50 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-2 border-b border-border-subtle",children:[e.jsx(As,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("input",{value:g,onChange:j=>O(j.target.value),placeholder:"Switch to agent…",autoFocus:!0,className:"flex-1 min-w-0 bg-transparent text-xs text-text-0 font-sans placeholder:text-text-4 focus:outline-none"})]}),e.jsxs("div",{className:"overflow-y-auto py-1",children:[v.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-text-4 font-sans text-center",children:"No agents match"}),v.map(j=>e.jsxs("div",{children:[e.jsx("div",{className:"px-2.5 pt-1.5 pb-0.5 text-2xs font-semibold text-text-4 font-sans uppercase tracking-wide",children:j.name}),j.agents.map(N=>e.jsxs("button",{onClick:()=>S(N.id),className:Z("w-full flex items-center gap-2 px-2.5 py-1.5 text-left cursor-pointer transition-colors",N.id===t.id?"bg-accent/10":"hover:bg-surface-3"),children:[e.jsx("span",{className:Z("w-1.5 h-1.5 rounded-full flex-shrink-0",_oe[N.status]||"bg-text-4")}),e.jsx("span",{className:Z("text-xs font-sans truncate",N.id===t.id?"text-accent font-medium":"text-text-1"),children:N.name}),e.jsx("span",{className:"text-2xs text-text-4 font-sans ml-auto flex-shrink-0 capitalize",children:N.role})]},N.id))]},j.teamId))]})]})]})}function Goe(){const t=k(v=>v.detailPanel),s=k(v=>v.agents),n=k(v=>v.activeTeamId),a=k(v=>v.activeView);k(v=>v.addToast);const[r,l]=p.useState("command"),c=p.useRef(null),A=(t==null?void 0:t.type)==="agent"?t.agentId:null,f=A?s.find(v=>v.id===A):null;f?c.current=f:c.current&&A&&c.current.id!==A&&(c.current=null);const x=f||c.current,h=(f==null?void 0:f.status)==="running"||(f==null?void 0:f.status)==="starting";if(!x||a!=="fleet"&&n&&x.teamId&&x.teamId!==n)return null;const g=Math.round((x.contextUsage||0)*100),O=x.spawnedAt||x.createdAt,b=O?Math.floor((Date.now()-new Date(O).getTime())/1e3):0;return Ha(x.role),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsxs("div",{className:"pl-4 pr-10 pt-3 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xoe,{agent:x}),e.jsx(Te,{variant:Doe[x.status]||"default",dot:h?"pulse":void 0,className:"text-2xs flex-shrink-0",children:Loe[x.status]||x.status})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-2xs text-text-3 font-mono",children:[e.jsx("span",{className:"capitalize",children:x.role}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[x.provider,":",x.model||"auto"]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{children:[jt(x.tokensUsed||0)," tok"]}),g>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-4",children:"·"}),e.jsxs("span",{className:Z(g>80?"text-danger":g>60?"text-warning":"text-text-3"),children:[g,"% ctx"]})]}),e.jsx("span",{className:"text-text-4",children:"·"}),e.jsx("span",{children:Xo(b)})]})]}),e.jsx("div",{className:"flex items-center px-4 border-b border-border-subtle",children:Hoe.map(v=>{const y=v.icon,S=r===v.id;return e.jsxs("button",{onClick:()=>l(v.id),className:Z("flex items-center gap-1.5 px-3 py-2 text-2xs font-semibold font-sans transition-all cursor-pointer select-none border-b-2 -mb-px",S?"border-accent text-text-0":"border-transparent text-text-3 hover:text-text-1"),children:[e.jsx(y,{size:11}),v.label]},v.id)})})]}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[r==="command"&&e.jsx(dT,{agent:x}),r==="config"&&e.jsx(Foe,{agent:x}),r==="telemetry"&&e.jsx(Ioe,{agent:x}),r==="mdfiles"&&e.jsx(zoe,{agent:x})]})]})}const Zoe=[{id:"chat",label:"Chat",desc:"Companion, assistant, conversation",icon:Ho,tier:"Medium"},{id:"planner",label:"Planner",desc:"Plans the team and tasks",icon:Ei,tier:"Heavy"},{id:"backend",label:"Backend",desc:"APIs, services, databases",icon:Ns,tier:"Medium"},{id:"frontend",label:"Frontend",desc:"UI, components, styling",icon:md,tier:"Medium"},{id:"fullstack",label:"Fullstack",desc:"End-to-end implementation",icon:bn,tier:"Heavy"},{id:"testing",label:"Testing",desc:"Tests, coverage, QA",icon:Wx,tier:"Medium"},{id:"devops",label:"DevOps",desc:"CI/CD, infra, deployment",icon:Eb,tier:"Medium"},{id:"docs",label:"Docs",desc:"Documentation, guides",icon:On,tier:"Light"},{id:"security",label:"Security",desc:"Audits, vulnerabilities",icon:vn,tier:"Medium"},{id:"database",label:"Database",desc:"Schema, migrations, queries",icon:Pb,tier:"Medium"},{id:"cmo",label:"CMO",desc:"Marketing, content, growth",icon:Ib,tier:"Medium"},{id:"cfo",label:"CFO",desc:"Finance, metrics, forecasting",icon:bS,tier:"Medium"},{id:"ea",label:"EA",desc:"Executive assistant, scheduling",icon:LS,tier:"Light"},{id:"support",label:"Support",desc:"Customer support, FAQs",icon:kS,tier:"Medium"},{id:"analyst",label:"Analyst",desc:"Data analysis, insights",icon:Lx,tier:"Medium"},{id:"creative",label:"Writer",desc:"Copy, articles, proposals",icon:MS,tier:"Heavy",skillHint:!0},{id:"slides",label:"Slides",desc:"Pitch decks, presentations",icon:zS,tier:"Heavy",skillHint:!0},{id:"ambassador",label:"Ambassador",desc:"Bridge to federated server",icon:ua,tier:"Light"}];function rN(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"text-accent flex-shrink-0",children:[e.jsx("circle",{cx:"7",cy:"7",r:"6",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1"}),e.jsx("path",{d:"M4.5 7 L6.5 9 L9.5 5.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Voe(){var Qd;const t=k(re=>re.detailPanel),s=k(re=>re.closeDetail),n=k(re=>re.spawnAgent),a=Hn(),r=k(re=>re.fetchProviders),l=k(re=>re.teams),c=k(re=>re.activeTeamId),A=k(re=>re.createTeam),f=(t==null?void 0:t.type)==="spawn",[x,h]=p.useState(""),[g,O]=p.useState(""),[b,v]=p.useState(""),[y,S]=p.useState(""),[j,N]=p.useState(""),[C,U]=p.useState(""),[P,T]=p.useState([]),[B,F]=p.useState([]),[M,R]=p.useState([]),[Y,W]=p.useState(!1),[ee,K]=p.useState(""),[_,E]=p.useState("manual"),[q,H]=p.useState([]),[I,L]=p.useState([]),[J,D]=p.useState(!1),[se,le]=p.useState(""),[V,te]=p.useState([]),[ae,be]=p.useState(""),[z,oe]=p.useState(!1),[ue,ve]=p.useState(!1),[Ce,Ne]=p.useState(""),[Xe,Fe]=p.useState([]),[Ae,ke]=p.useState(null),[Re,Nt]=p.useState([]),[Ss,ar]=p.useState(!1),[ts,is]=p.useState(!1),[rr,Vo]=p.useState("subscription"),[Ko,or]=p.useState(!1),[Es,ir]=p.useState("new"),[ha,wn]=p.useState(""),[en,vs]=p.useState(""),Xn=k(re=>re.federation),Ot=k(re=>re.ollamaRunningModels),de=x||g,He=P.find(re=>re.id===y),Se=(He==null?void 0:He.models)||[],Ge=P.filter(re=>re.authType==="api-key"?re.installed&&re.hasKey:re.installed),ss=!!(t!=null&&t.presetProvider||t!=null&&t.presetModel),ys=(t==null?void 0:t.presetTeamId)||null,tn=!ys&&(ss||!c);p.useEffect(()=>{if(f){const re=(t==null?void 0:t.presetProvider)||"",Be=(t==null?void 0:t.presetModel)||"";r().then(Ve=>{const Ke=Array.isArray(Ve)?Ve:Ve.providers||[];T(Ke);const Fa=Ke.filter(sn=>sn.authType==="api-key"?sn.installed&&sn.hasKey:sn.installed);if(Fa.length>0&&!re){const lr=["claude-code","gemini","codex","ollama"].find(Gi=>Fa.some(An=>An.id===Gi))||Fa[0].id;S(lr)}if(re&&S(re),Be){const sn=Ke.find(An=>An.id===(re||y)),lr=(sn==null?void 0:sn.models)||[];if(lr.find(An=>An.id===Be))N(Be);else{const An=Be.split(":"),Zi=An.length>=3?An.slice(2).join(":"):An[An.length-1],Vi=lr.find(jn=>jn.id===Be||jn.id===`gguf:${Zi}`||jn.id.endsWith(`:${Zi}`)||jn.name===Zi);N((Vi==null?void 0:Vi.id)||Be)}}}).catch(()=>{}),G.get("/integrations/installed").then(Ve=>{F(Array.isArray(Ve)?Ve:[])}).catch(()=>{}),G.get("/repos/imported").then(Ve=>{H((Array.isArray(Ve)?Ve:[]).filter(Ke=>Ke.status==="active"))}).catch(()=>{}),G.get("/personalities").then(Ve=>{te(Array.isArray(Ve)?Ve:Ve.personalities||[])}).catch(()=>{}),h(""),O(""),v(""),S(re),N(Be),is(!1),Vo("subscription"),ir("new"),vs(""),wn(Be?Be.split(":").pop().replace(/[-_]/g," "):""),U(""),R([]),E("manual"),L([]),be(""),Ne(""),oe(!1),Fe([]),ke(null)}},[f,r]),p.useEffect(()=>{if(!de||!f){Fe([]);return}G.get(`/roles/integrations?role=${encodeURIComponent(de)}`).then(re=>{const Be=Array.isArray(re)?re:(re==null?void 0:re.recommendations)||[];Fe(Be);const Ve=Be.filter(Ke=>Ke.installed&&Ke.configured&&Ke.authenticated).map(Ke=>Ke.id);Ve.length>0&&R(Ke=>[...new Set([...Ke,...Ve])])}).catch(()=>Fe([]))},[de,f]),p.useEffect(()=>{f&&G.get("/credentials").then(re=>or(Array.isArray(re)&&re.some(Be=>Be.provider==="claude-code"))).catch(()=>or(!1))},[f]),p.useEffect(()=>{if(!f||y!=="ollama"){Nt([]);return}G.get("/providers/ollama/models").then(re=>{Nt(re.installed||[])}).catch(()=>Nt([])),G.post("/providers/ollama/check").then(re=>{ar(re.serverRunning)}).catch(()=>ar(!1))},[f,y]);async function qo(){ve(!0);try{let re;if(ys)re=ys;else if(!tn)re=c;else if(Es==="new"){const Ve=ha.trim()||de||"New Team";re=(await A(Ve)).id}else Es==="existing"&&en&&(re=en);const Be={role:de,...b&&{name:b.replace(/\s+/g,"-")},...y&&{provider:y},...j&&{model:j},...C&&{prompt:C},...M.length>0&&{integrations:M},...M.length>0&&{integrationApproval:_},...I.length>0&&{repos:I},...ts&&{fast:!0},...y==="claude-code"&&{authMode:rr},...ae&&{personality:ae},...de==="ambassador"&&Ce&&{peerId:Ce},...re&&{teamId:re}};await n(Be),s()}catch{}ve(!1)}async function Wo(){var re;if(de){if(y==="claude-code"&&rr==="usage"&&!Ko){a.error("Add an Anthropic API key in Settings → Providers to spawn with usage credits.");return}try{const Be=await G.post("/agents/preflight",{role:de,integrations:M});if(((re=Be==null?void 0:Be.issues)==null?void 0:re.length)>0){ke(Be.issues);return}}catch{}qo()}}return e.jsxs(_v,{open:f,onOpenChange:re=>{re||s()},children:[e.jsx(Dv,{title:"Spawn Agent",width:480,onClose:()=>s(),children:e.jsxs("div",{className:"flex flex-col h-[calc(100%-57px)]",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-3",children:"Choose Role"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Zoe.map(re=>{const Be=Ha(re.id),Ve=x===re.id;return e.jsxs("button",{onClick:()=>{h(re.id),O("")},className:Z("flex items-center gap-2.5 p-3 rounded-md border text-left transition-all cursor-pointer",Ve?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border hover:bg-surface-2"),children:[e.jsx("div",{className:"w-8 h-8 rounded-md flex items-center justify-center flex-shrink-0",style:{background:Be.bg},children:e.jsx(re.icon,{size:16,style:{color:Be.text}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:re.label}),re.skillHint&&e.jsx("span",{className:"text-2xs font-mono text-warning/70 bg-warning/8 px-1 py-px rounded",children:"skill"})]}),e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:re.desc})]})]},re.id)})}),e.jsx("div",{className:"mt-3",children:e.jsx(rs,{placeholder:"or type a custom role (e.g. chat-agent)...",value:g,onChange:re=>{O(re.target.value.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9_-]/g,"").slice(0,50)),h("")},className:"text-xs"})})]}),de&&Xe.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Recommended Integrations"}),e.jsx("div",{className:"space-y-1.5",children:Xe.map(re=>{const Be=Ni[re.id];return re.installed&&re.configured&&re.authenticated?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-success/5 border border-success/20",children:[e.jsx(Je,{size:13,className:"text-success flex-shrink-0"}),Be?e.jsx("img",{src:Be,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(on,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:re.name||re.id}),e.jsx(Te,{variant:"success",className:"text-2xs ml-auto",children:"Ready"})]},re.id):re.installed?e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-warning/5 border border-warning/20",children:[e.jsx(Aa,{size:13,className:"text-warning flex-shrink-0"}),Be?e.jsx("img",{src:Be,alt:"",className:"w-3.5 h-3.5 flex-shrink-0"}):e.jsx(on,{size:12,className:"text-text-3 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:re.name||re.id}),e.jsx(pe,{variant:"ghost",size:"sm",className:"ml-auto text-2xs text-warning h-6 px-2",onClick:()=>{s(),k.getState().setActiveView("marketplace")},children:"Configure"})]},re.id):e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-md bg-surface-1 border border-border-subtle",children:[Be?e.jsx("img",{src:Be,alt:"",className:"w-3.5 h-3.5 flex-shrink-0 opacity-40"}):e.jsx(on,{size:12,className:"text-text-4 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-text-3 font-sans",children:re.name||re.id}),e.jsx("button",{onClick:()=>{s(),k.getState().setActiveView("marketplace")},className:"ml-auto text-2xs text-accent hover:underline font-sans cursor-pointer",children:"Install in Marketplace"})]},re.id)})})]}),de==="ambassador"&&(()=>{const re=Xn.whitelist.filter(Be=>typeof Be=="object"&&(Be.status==="mutual"||Be.status==="connected"));return re.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border-subtle bg-surface-1/50 px-4 py-4 text-center",children:[e.jsx(ua,{size:18,className:"text-text-4 mx-auto mb-1.5"}),e.jsx("p",{className:"text-2xs text-text-3 font-sans mb-2",children:"No federated servers connected. Add one in the Federation view."}),e.jsx(pe,{variant:"ghost",size:"sm",className:"text-2xs text-accent",onClick:()=>{s(),k.getState().setActiveView("federation")},children:"Go to Federation"})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block mb-2",children:"Target Server"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:Ce,onChange:Be=>Ne(Be.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select a server..."}),re.map(Be=>e.jsx("option",{value:Be.ip,children:Be.name||`${Be.ip}:${Be.port||31415}`},Be.ip))]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})})(),de&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"text-xs font-semibold text-text-2 font-sans uppercase tracking-wider block",children:"Configuration"}),e.jsx(rs,{label:"Name (optional)",value:b,onChange:re=>v(re.target.value),placeholder:`${de}-1`}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Provider"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:y,onChange:re=>{S(re.target.value),N("")},className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Auto"}),P.map(re=>e.jsxs("option",{value:re.id,disabled:re.authType==="api-key"?!(re.installed&&re.hasKey):!re.installed,children:[re.name,re.installed?re.authType==="api-key"&&!re.hasKey?" (No API key)":"":" (Not installed)"]},re.id))]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Model"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:j,onChange:re=>N(re.target.value),disabled:!y,className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent disabled:opacity-40",children:[e.jsx("option",{value:"",children:"Auto"}),y==="ollama"&&Re.length>0?e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Installed Models",children:Re.map(re=>{const Be=Ot.some(Ve=>Ve.name===re.id);return e.jsxs("option",{value:re.id,children:[re.name||re.id," (",re.size,")",Be?" ● Running":""]},re.id)})}),e.jsx("optgroup",{label:"Catalog",children:Se.filter(re=>!Re.some(Be=>Be.id===re.id)).map(re=>e.jsxs("option",{value:re.id,children:[re.name," (not installed)"]},re.id))})]}):y==="local"?(()=>{const re=Se.filter(Ke=>Ke.source==="runtime"),Be=Se.filter(Ke=>Ke.source==="gguf"),Ve=Se.filter(Ke=>Ke.source==="ollama"||!Ke.source);return e.jsxs(e.Fragment,{children:[re.length>0&&e.jsx("optgroup",{label:"Lab Runtimes",children:re.map(Ke=>e.jsxs("option",{value:Ke.id,children:[Ke.name,Ke.runtimeType?` (${Ke.runtimeType})`:""]},Ke.id))}),Be.length>0&&e.jsx("optgroup",{label:"GGUF Models",children:Be.map(Ke=>e.jsxs("option",{value:Ke.id,children:[Ke.name,Ke.hasRuntime?"":" (no runtime)"]},Ke.id))}),Ve.length>0&&e.jsx("optgroup",{label:"Ollama",children:Ve.map(Ke=>e.jsx("option",{value:Ke.id,children:Ke.name},Ke.id))})]})})():Se.map(re=>e.jsx("option",{value:re.id,children:re.name},re.id))]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]})]}),y&&He&&e.jsx("div",{className:"text-2xs text-text-3 font-sans flex items-center gap-2 flex-wrap",children:He.authType==="local"?e.jsx(Te,{variant:"success",children:"Local"}):He.authType==="subscription"?e.jsx(Te,{variant:"accent",children:"Subscription"}):He.hasKey?e.jsx(Te,{variant:"success",children:"API key set"}):e.jsxs(Te,{variant:"warning",children:["No API key — set with: groove set-key ",y," YOUR_KEY"]})}),y==="claude-code"&&j&&j.includes("opus")&&e.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":ts,onClick:()=>is(!ts),className:Z("relative w-8 h-[18px] rounded-full transition-colors flex-shrink-0",ts?"bg-accent":"bg-surface-5"),children:e.jsx("span",{className:Z("absolute top-[2px] left-[2px] w-[14px] h-[14px] rounded-full bg-white transition-transform",ts&&"translate-x-[14px]")})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans",children:"Fast mode"}),e.jsx("span",{className:"text-2xs text-text-3 font-sans ml-1.5",children:"Faster output, same model"})]})]}),y==="claude-code"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Billing"}),e.jsx("div",{className:"flex gap-1 p-0.5 rounded-md bg-surface-3 w-fit",children:[{id:"subscription",label:"Subscription"},{id:"usage",label:"Usage credits"}].map(re=>e.jsx("button",{type:"button",onClick:()=>Vo(re.id),className:Z("px-2.5 py-1 rounded text-2xs font-semibold font-sans transition-colors",rr===re.id?"bg-accent text-white":"text-text-2 hover:text-text-0"),children:re.label},re.id))}),rr==="usage"&&!Ko&&e.jsx("p",{className:"text-2xs text-warning font-sans",children:"No Anthropic API key stored — add one in Settings → Providers before spawning."}),rr==="subscription"&&e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Uses your Claude Code login (Pro/Max)."})]}),y==="ollama"&&j&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-2xs font-sans",children:[Ot.some(re=>re.name===j)?e.jsxs(Te,{variant:"success",className:"text-2xs gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success"}),"Ready — running in memory"]}):Re.some(re=>re.id===j)?e.jsx(Te,{variant:"subtle",className:"text-2xs",children:"Will auto-start when agent spawns"}):e.jsx(Te,{variant:"warning",className:"text-2xs",children:"Not installed — will pull first"}),!Ss&&e.jsx("span",{className:"text-warning",children:"Server not running — will auto-start"})]}),tn&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Team"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>ir("new"),className:Z("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Es==="new"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(it,{size:13,className:Es==="new"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"New Team"})})]}),e.jsxs("button",{onClick:()=>ir("existing"),className:Z("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",Es==="existing"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(yn,{size:13,className:Es==="existing"?"text-accent":"text-text-3"}),e.jsx("div",{children:e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Existing"})})]})]}),Es==="new"&&e.jsx(rs,{value:ha,onChange:re=>wn(re.target.value),placeholder:"Team name...",className:"text-xs"}),Es==="existing"&&e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:en,onChange:re=>vs(re.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"Select team..."}),l.filter(re=>!re.archived).map(re=>e.jsx("option",{value:re.id,children:re.name},re.id))]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integrations"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[M.map(re=>{const Be=B.find(Ke=>Ke.id===re),Ve=Ni[re];return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[Ve?e.jsx("img",{src:Ve,alt:"",className:"w-2.5 h-2.5"}):e.jsx(on,{size:9}),(Be==null?void 0:Be.name)||re,e.jsx("button",{onClick:()=>R(Ke=>Ke.filter(Fa=>Fa!==re)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(qe,{size:9})})]},re)}),e.jsxs("button",{onClick:()=>{W(!0),K("")},className:Z("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(on,{size:10}),M.length>0?"Add integration":"Attach integration"]})]})]}),e.jsx(Vt,{open:Y,onOpenChange:W,children:e.jsx(Kt,{title:"Select Integration",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:ee,onChange:re=>K(re.target.value),placeholder:"Search integrations...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-1",children:[B.filter(re=>{if(!ee)return!0;const Be=ee.toLowerCase();return(re.name||re.id).toLowerCase().includes(Be)||(re.description||"").toLowerCase().includes(Be)}).map(re=>{const Be=M.includes(re.id),Ve=re.configured!==!1,Ke=Ni[re.id],Fa=de&&Array.isArray(re.roles)&&re.roles.includes(de);return e.jsxs("button",{onClick:()=>{Ve&&R(sn=>Be?sn.filter(lr=>lr!==re.id):[...sn,re.id])},disabled:!Ve,className:Z("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors",Ve?"cursor-pointer":"opacity-40 cursor-not-allowed",Be?"bg-accent/10 border border-accent/25":Ve?"hover:bg-surface-3 border border-transparent":"border border-transparent"),children:[Ke?e.jsx("img",{src:Ke,alt:"",className:"w-4 h-4 flex-shrink-0"}):e.jsx(on,{size:12,className:Be?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:re.name||re.id}),!Ve&&e.jsx("span",{className:"text-2xs text-text-4 font-sans",children:"(not configured)"}),Ve&&Fa&&e.jsx("span",{className:"text-2xs font-mono text-accent/70 bg-accent/8 px-1 py-px rounded",children:"rec"})]}),re.description&&e.jsx("div",{className:"text-2xs text-text-3 font-sans truncate",children:re.description}),!Ve&&e.jsx("div",{className:"text-2xs text-text-4 font-sans",children:"Configure in Marketplace"})]}),Be&&e.jsx(rN,{})]},re.id)}),B.length===0&&e.jsx("div",{className:"text-center py-6 text-xs text-text-3 font-sans",children:"No integrations installed. Visit the Marketplace to install integrations."})]})]})})}),M.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Integration Approvals"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("button",{onClick:()=>E("manual"),className:Z("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",_==="manual"?"border-accent bg-accent/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(vn,{size:13,className:_==="manual"?"text-accent":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Manual"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"You approve each action"})]})]}),e.jsxs("button",{onClick:()=>E("auto"),className:Z("flex-1 flex items-center gap-2 px-3 py-2 rounded-md border text-left transition-all cursor-pointer",_==="auto"?"border-warning bg-warning/5":"border-border-subtle bg-surface-1 hover:border-border"),children:[e.jsx(Js,{size:13,className:_==="auto"?"text-warning":"text-text-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xs font-semibold text-text-0 font-sans",children:"Auto"}),e.jsx("div",{className:"text-2xs text-text-3 font-sans",children:"Agent acts without asking"})]})]})]})]}),q.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Repos"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[I.map(re=>{const Be=q.find(Ve=>Ve.id===re);return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded bg-accent/12 text-accent border border-accent/25 text-2xs font-sans",children:[e.jsx(Kl,{size:9}),(Be==null?void 0:Be.name)||re,e.jsx("button",{onClick:()=>L(Ve=>Ve.filter(Ke=>Ke!==re)),className:"ml-0.5 hover:text-text-0 cursor-pointer",children:e.jsx(qe,{size:9})})]},re)}),e.jsxs("button",{onClick:()=>{D(!0),le("")},className:Z("inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-2xs font-sans transition-colors cursor-pointer","bg-surface-0 text-text-2 border border-border-subtle hover:border-border hover:text-text-0"),children:[e.jsx(Kl,{size:10}),I.length>0?"Add repo":"Attach repo"]})]})]}),e.jsx(Vt,{open:J,onOpenChange:D,children:e.jsx(Kt,{title:"Select Repository",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-3 p-4",children:[q.length>1&&e.jsxs("div",{className:"relative",children:[e.jsx(As,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-4"}),e.jsx("input",{value:se,onChange:re=>le(re.target.value),placeholder:"Search repos...",autoFocus:!0,className:"w-full h-8 pl-8 pr-3 text-xs rounded-md bg-surface-0 border border-border text-text-0 font-sans focus:outline-none focus:ring-1 focus:ring-accent"})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:q.filter(re=>{if(!se)return!0;const Be=se.toLowerCase();return(re.name||re.repo||re.id).toLowerCase().includes(Be)}).map(re=>{const Be=I.includes(re.id);return e.jsxs("button",{onClick:()=>{L(Ve=>Be?Ve.filter(Ke=>Ke!==re.id):[...Ve,re.id])},className:Z("w-full flex items-center gap-2.5 px-3 py-2 rounded-md text-left transition-colors cursor-pointer",Be?"bg-accent/10 border border-accent/25":"hover:bg-surface-3 border border-transparent"),children:[e.jsx(Kl,{size:12,className:Be?"text-accent":"text-text-3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-text-0 font-sans truncate",children:re.name||re.repo}),e.jsx("div",{className:"text-2xs text-text-4 font-mono truncate",children:re.clonedTo})]}),Be&&e.jsx(rN,{})]},re.id)})})]})})}),(x==="chat"||z)&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-text-2 font-sans",children:"Personality"}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:ae,onChange:re=>be(re.target.value),className:"w-full h-8 px-3 pr-8 text-sm rounded-md bg-surface-1 border border-border text-text-0 font-sans appearance-none cursor-pointer focus:outline-none focus:ring-1 focus:ring-accent",children:[e.jsx("option",{value:"",children:"None (blank)"}),V.map(re=>e.jsx("option",{value:re.name||re,children:re.name||re},re.name||re))]}),e.jsx(xt,{size:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-3 pointer-events-none"})]}),e.jsx("p",{className:"text-2xs text-text-4 font-sans",children:"Personality is injected into every prompt for this agent."})]}),x!=="chat"&&!z&&e.jsx("button",{onClick:()=>oe(!0),className:"text-2xs text-text-3 hover:text-accent font-sans transition-colors cursor-pointer",children:"+ Advanced options"})]})]}),e.jsxs("div",{className:"border-t border-border-subtle px-5 py-4 bg-surface-1",children:[Ge.length===0&&P.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 px-3 py-2 rounded-md bg-warning/8 border border-warning/20",children:[e.jsx(Aa,{size:13,className:"text-warning flex-shrink-0"}),e.jsx("span",{className:"text-2xs font-sans text-text-2",children:"No AI providers installed. Install Claude Code, Gemini CLI, Codex, or Ollama to spawn agents."})]}),de&&Ge.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 text-xs text-text-3 font-sans flex-wrap",children:[e.jsx("span",{children:"Spawning"}),e.jsx(Te,{variant:"accent",children:de}),y&&e.jsxs("span",{children:["on ",(He==null?void 0:He.name)||y]}),b&&e.jsxs("span",{children:["as ",b.replace(/\s+/g,"-")]}),Es==="new"&&e.jsxs("span",{children:["in new team",ha?` "${ha}"`:""]}),Es==="existing"&&en&&e.jsxs("span",{children:["in ",((Qd=l.find(re=>re.id===en))==null?void 0:Qd.name)||"team"]})]}),e.jsx(pe,{variant:"primary",size:"lg",onClick:Wo,disabled:!de||ue||Ge.length===0||Es==="existing"&&!en,className:"w-full",children:ue?"Spawning...":"Spawn Agent"})]})]})}),e.jsx(Vt,{open:!!Ae,onOpenChange:re=>{re||ke(null)},children:e.jsx(Kt,{title:"Integration Warning",className:"max-w-sm",children:e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx("div",{className:"space-y-2",children:(Ae||[]).map((re,Be)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs text-text-1 font-sans",children:[e.jsx(Aa,{size:13,className:"text-warning flex-shrink-0 mt-0.5"}),e.jsx("span",{children:re.name?`${re.name}: ${re.problem==="not_installed"?"not installed":re.problem==="not_configured"?"not configured":"not authenticated"}`:re.message||String(re)})]},Be))}),e.jsx("p",{className:"text-2xs text-text-3 font-sans",children:"Continue anyway?"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(pe,{variant:"ghost",size:"md",onClick:()=>ke(null),className:"flex-1",children:"Cancel"}),e.jsx(pe,{variant:"warning",size:"md",onClick:()=>{ke(null),qo()},className:"flex-1",children:"Spawn Anyway"})]})]})})})]})}function Koe(){const t=k(g=>g.journalistStatus),s=k(g=>g.fetchJournalist),n=k(g=>g.triggerJournalistCycle),[a,r]=p.useState(!0),[l,c]=p.useState(!1);p.useEffect(()=>{s().then(()=>r(!1));const g=setInterval(s,1e4);return()=>clearInterval(g)},[s]);async function A(){c(!0);try{await n()}catch{}c(!1)}if(a)return e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx(ia,{className:"h-6 w-32 rounded"}),e.jsx(ia,{className:"h-20 rounded-md"}),e.jsx(ia,{className:"h-20 rounded-md"})]});const f=t||{},x=f.lastSynthesis,h=f.history||[];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"pl-5 pr-10 py-4 border-b border-border-subtle flex items-center gap-2",children:[e.jsx(ox,{size:16,className:"text-accent"}),e.jsx("h3",{className:"text-sm font-semibold text-text-0 font-sans flex-1",children:"Journalist"}),e.jsxs(pe,{variant:"secondary",size:"sm",onClick:A,disabled:l,className:"gap-1.5 text-2xs",children:[e.jsx(Ls,{size:11,className:l?"animate-spin":""}),l?"Running...":"Run Synthesis"]})]}),e.jsx(Qt,{className:"flex-1",children:e.jsxs("div",{className:"px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 text-2xs text-text-3 font-sans",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ro,{size:10}),e.jsxs("span",{children:[f.cycleCount||0," cycles"]})]}),f.lastCycleTime&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Dn,{size:10}),e.jsxs("span",{children:["Last: ",$t(f.lastCycleTime)]})]}),e.jsx(Te,{variant:f.cycleCount>0?"success":"default",className:"text-2xs",children:f.cycleCount>0?"Active":"Idle"})]}),(x==null?void 0:x.summary)&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(On,{size:12,className:"text-text-3"}),"Latest Summary"]}),e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-sans leading-relaxed",children:x.summary})]}),(x==null?void 0:x.projectMap)&&e.jsx(Ex,{title:"Project Map",icon:$M,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.projectMap})}),(x==null?void 0:x.decisions)&&e.jsx(Ex,{title:"Decisions Log",icon:On,children:e.jsx("div",{className:"bg-surface-0 rounded-lg border border-border-subtle px-3.5 py-3 text-xs text-text-2 font-mono leading-relaxed max-h-64 overflow-y-auto whitespace-pre-wrap",children:x.decisions})}),h.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-xs font-semibold text-text-1 font-sans flex items-center gap-1.5",children:[e.jsx(Dn,{size:12,className:"text-text-3"}),"History (",h.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:h.slice().reverse().slice(0,20).map((g,O)=>e.jsxs("div",{className:"bg-surface-0 rounded-md border border-border-subtle px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-2xs",children:[e.jsxs(Te,{variant:"default",className:"text-2xs",children:["Cycle ",g.cycle]}),e.jsxs("span",{className:"text-text-4 font-sans",children:[g.agentCount," agent",g.agentCount!==1?"s":""]}),e.jsx("span",{className:"text-text-4 font-sans ml-auto",children:$t(g.timestamp)})]}),g.summary&&e.jsx("p",{className:"text-xs text-text-2 font-sans mt-1 leading-relaxed",children:g.summary})]},O))})]}),!x&&h.length===0&&e.jsxs("div",{className:"text-center py-8 text-text-4 font-sans",children:[e.jsx(ox,{size:28,className:"mx-auto mb-2"}),e.jsx("p",{className:"text-sm",children:"No synthesis data yet"}),e.jsx("p",{className:"text-2xs mt-1",children:"The journalist runs automatically when agents are active, or trigger manually above"})]})]})})]})}const qoe=[{cmd:"save",args:"#tag",desc:"Save the message and send it to the agent"},{cmd:"append",args:"#tag",desc:"Add to an existing memory and send to agent"},{cmd:"update",args:"#tag",desc:"Open the editor to modify a memory in place"},{cmd:"delete",args:"#tag",desc:"Remove a memory permanently"},{cmd:"view",args:"#tag",desc:"Read a memory in the viewer"},{cmd:"read",args:"#tag1 #tag2 ...",desc:"Send memory content to the agent — chat stays clean"},{cmd:"doc",args:"#tag",desc:"AI synthesizes the full conversation into a document"},{cmd:"link",args:"#tag path/to/doc",desc:"Link a memory to a NORTHSTAR or external document"},{cmd:"[instruct]",args:"",desc:"Show this command reference"}];function Woe(){var j;const t=k(N=>N.keeperEditing),s=k(N=>N.setKeeperEditing),n=k(N=>N.saveKeeperItem),a=k(N=>N.updateKeeperItem),r=k(N=>N.activeView),[l,c]=p.useState(""),[A,f]=p.useState(""),x=p.useRef(null),h=!!t&&r!=="memory";p.useEffect(()=>{t&&(c(t.tag||""),f(t.content||""))},[t]),p.useEffect(()=>{h&&x.current&&setTimeout(()=>{var N;return(N=x.current)==null?void 0:N.focus()},100)},[h]);const g=N=>{N||s(null)},O=async()=>{!l.trim()||t!=null&&t.readOnly||(t!=null&&t.isNew?await n(l.trim(),A):await a(l.trim(),A),s(null))},b=N=>{N.key==="s"&&(N.metaKey||N.ctrlKey)&&(N.preventDefault(),O())};if(!t)return null;const v=t.readOnly,y=t.isNew,S=v?`#${t.tag}`:y?"New Memory":`Edit #${t.tag}`;return e.jsx(Vt,{open:h,onOpenChange:g,children:e.jsx(Kt,{title:S,description:"Memory content",className:"max-w-2xl",children:e.jsxs("div",{className:"p-5 space-y-4",onKeyDown:b,children:[y&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-text-2 mb-1.5",children:"Tag"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-sm text-text-3",children:"#"}),e.jsx("input",{type:"text",value:l,onChange:N=>c(N.target.value.replace(/[^a-zA-Z0-9/_-]/g,"").toLowerCase()),placeholder:"project/feature-name",className:"flex-1 px-2 py-1.5 text-sm font-mono rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent"})]})]}),e.jsx("textarea",{ref:x,value:A,onChange:N=>!v&&f(N.target.value),readOnly:v,rows:16,className:"w-full px-3 py-2 text-sm font-mono leading-relaxed rounded-md bg-surface-0 border border-border text-text-0 placeholder:text-text-4 focus:outline-none focus:ring-1 focus:ring-accent resize-y",placeholder:"Write your thoughts, ideas, context..."}),e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[v?e.jsx("p",{className:"text-2xs text-text-4",children:"Read-only view"}):e.jsxs("p",{className:"text-2xs text-text-4",children:[(j=navigator.platform)!=null&&j.includes("Mac")?"Cmd":"Ctrl","+S to save"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>s(null),children:v?"Close":"Cancel"}),!v&&e.jsxs(pe,{variant:"primary",size:"sm",onClick:O,disabled:!l.trim(),children:[e.jsx(_r,{size:14})," Save"]})]})]})]})})})}function Yoe(){const t=k(n=>n.keeperInstructOpen);return k(n=>n.activeView)==="memory"?null:e.jsx(Vt,{open:t,onOpenChange:n=>k.setState({keeperInstructOpen:n}),children:e.jsx(Kt,{title:"Keeper Commands",description:"Memory system command reference",className:"max-w-lg",children:e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-text-2 leading-relaxed",children:"Type these commands in any agent chat to manage your tagged memories. Commands are intercepted by Keeper — the agent never sees them."}),e.jsx("div",{className:"space-y-1.5",children:qoe.map(n=>e.jsxs("div",{className:"flex items-start gap-3 py-1.5 border-b border-border-subtle last:border-0",children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-1",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-accent/15 text-accent font-mono text-xs font-semibold",children:n.cmd}),n.args&&e.jsx("span",{className:"text-xs text-text-3 font-mono",children:n.args})]}),e.jsx("span",{className:"text-xs text-text-3 pt-0.5",children:n.desc})]},n.cmd))}),e.jsxs("div",{className:"pt-2 space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Tag Hierarchy"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:["Use ",e.jsx("span",{className:"font-mono text-accent",children:"/"})," for nesting: ",e.jsx("span",{className:"font-mono text-accent",children:"#groove/memory-system"}),". Pull a parent to get all children."]}),e.jsx("h3",{className:"text-xs font-semibold text-text-1",children:"Memory Types"}),e.jsxs("p",{className:"text-xs text-text-3 leading-relaxed",children:[e.jsx("span",{className:"font-semibold",children:"Manual"})," — you write via [save]/[append]/[update]. ",e.jsx("span",{className:"font-semibold",children:"Doc"})," — AI writes via [doc]. Both editable."]})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx(pe,{variant:"ghost",size:"sm",onClick:()=>k.setState({keeperInstructOpen:!1}),children:"Close"})})]})})})}function Joe(){return e.jsxs(e.Fragment,{children:[e.jsx(Woe,{}),e.jsx(Yoe,{})]})}function eie({onSelect:t,onClose:s}){const n=p.useRef(null),a=k(f=>f.agents),r=k(f=>f.teams);p.useEffect(()=>{function f(h){n.current&&!n.current.contains(h.target)&&s()}function x(h){h.key==="Escape"&&s()}return document.addEventListener("mousedown",f),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",x)}},[s]);const l=a.filter(f=>f.status==="running"||f.status==="starting"),c=a.filter(f=>f.status!=="running"&&f.status!=="starting");function A(f){const x=r.find(h=>h.id===f);return(x==null?void 0:x.name)||"Default"}return e.jsxs("div",{ref:n,className:"absolute bottom-full right-0 mb-1 z-50 min-w-[220px] max-h-[300px] overflow-y-auto py-1 bg-surface-2 border border-border rounded-lg shadow-xl",children:[l.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:"Active"}),l.map(f=>e.jsxs("button",{onClick:()=>t(f.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-1 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-success flex-shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:f.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(f.teamId)})]},f.id))]}),c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-1 text-2xs text-text-4 font-sans font-medium uppercase tracking-wider",children:l.length>0?"Other":"Agents"}),c.slice(0,10).map(f=>e.jsxs("button",{onClick:()=>t(f.id),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs font-sans text-text-2 hover:bg-surface-5 cursor-pointer transition-colors text-left",children:[e.jsx("span",{className:Z("w-1.5 h-1.5 rounded-full flex-shrink-0",f.status==="completed"?"bg-accent":f.status==="crashed"?"bg-danger":"bg-text-4")}),e.jsx("span",{className:"truncate flex-1",children:f.name}),e.jsx("span",{className:"text-2xs text-text-4",children:A(f.teamId)})]},f.id))]}),a.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-text-4 font-sans text-center",children:"No agents available"})]})}function tie({children:t,height:s,onHeightChange:n,visible:a,fullHeight:r,tabs:l,activeTab:c,onSelectTab:A,onAddTab:f,onCloseTab:x,onToggleFullHeight:h,onMinimize:g,onClose:O,onRenameTab:b,selectedText:v}){const y=p.useRef(!1),[S,j]=p.useState(null),[N,C]=p.useState(""),[U,P]=p.useState(!1),T=p.useRef(0),B=p.useRef(0),F=k(I=>I.detailPanel),M=k(I=>I.workspaceAgentId),R=(F==null?void 0:F.type)==="agent"?F.agentId:M||null,Y=k(I=>I.agents),W=k(I=>I.attachSnippet),ee=Y.find(I=>I.id===R),K=v&&v.trim().length>0,_=p.useCallback(I=>{if(r)return;I.preventDefault(),y.current=!0,T.current=I.clientY,B.current=s;function L(D){if(!y.current)return;const se=T.current-D.clientY,le=Math.min(Math.max(B.current+se,120),600);n(le)}function J(){y.current=!1,document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",J)}document.addEventListener("mousemove",L),document.addEventListener("mouseup",J)},[s,n,r]);function E(I){!I||!(v!=null&&v.trim())||(P(!1),W({type:"terminal",code:v.trim()}),k.getState().selectAgent(I))}function q(){R?E(R):P(!0)}const H=l||[{id:"default",label:"Terminal"}];return e.jsxs("div",{className:Z("flex flex-col border-t border-border bg-surface-0 relative",!a&&"hidden"),style:a?r?{flex:1,minHeight:0}:{height:s,flexShrink:0}:{height:0},children:[!r&&e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 cursor-row-resize hover:bg-accent/30 transition-colors z-10",onMouseDown:_}),e.jsxs("div",{className:"flex items-center h-9 bg-surface-1 border-b border-border flex-shrink-0 pl-0 pr-3",children:[e.jsxs("div",{className:"flex items-center gap-0 flex-1 min-w-0 overflow-x-auto scrollbar-none h-full",children:[H.map(I=>e.jsxs("button",{onClick:()=>A==null?void 0:A(I.id),onDoubleClick:()=>{j(I.id),C(I.label)},className:Z("inline-flex items-center gap-1.5 px-3 h-full text-[11px] font-medium font-sans cursor-pointer select-none transition-colors duration-100 flex-shrink-0",I.id===c?"text-text-0 bg-surface-3":"text-text-2 hover:text-text-0 hover:bg-surface-5/50"),children:[e.jsx(Wa,{size:11}),S===I.id?e.jsx("input",{className:"bg-transparent border border-border rounded px-1 text-[11px] text-text-0 outline-none w-20 font-sans",value:N,onChange:L=>C(L.target.value),onBlur:()=>{N.trim()&&(b==null||b(I.id,N.trim())),j(null)},onKeyDown:L=>{L.key==="Enter"&&(N.trim()&&(b==null||b(I.id,N.trim())),j(null)),L.key==="Escape"&&j(null)},autoFocus:!0,onClick:L=>L.stopPropagation()}):e.jsx("span",{className:"truncate max-w-[100px]",children:I.label}),H.length>1&&e.jsx("button",{onClick:L=>{L.stopPropagation(),x==null||x(I.id)},className:"ml-1 p-0.5 rounded hover:bg-surface-5 text-text-4 hover:text-text-1 cursor-pointer",children:e.jsx(qe,{size:9})})]},I.id)),e.jsx("button",{onClick:f,className:"flex items-center justify-center w-6 h-6 text-text-3 hover:text-text-0 hover:bg-surface-5/50 rounded cursor-pointer transition-colors flex-shrink-0 ml-1",title:"New terminal",children:e.jsx(it,{size:11})})]}),e.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0 ml-2",children:[K&&e.jsxs("div",{className:"relative flex items-center",children:[e.jsx(dt,{content:R?`Send to ${(ee==null?void 0:ee.name)||"agent"}`:"Send to agent",side:"top",children:e.jsx("button",{onClick:q,className:Z("flex items-center gap-1.5 px-2 py-1 rounded text-xs font-sans cursor-pointer transition-colors mr-1","bg-accent/15 text-accent hover:bg-accent/25 disabled:opacity-50"),children:R?e.jsxs(e.Fragment,{children:[e.jsx(Ln,{size:11}),e.jsx("span",{className:"text-2xs max-w-[80px] truncate",children:(ee==null?void 0:ee.name)||"Agent"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Js,{size:11}),e.jsx("span",{className:"text-2xs",children:"Agent"}),e.jsx(xt,{size:9})]})})}),!R&&K&&e.jsx(dt,{content:"Pick agent",side:"top",children:e.jsx("button",{onClick:()=>P(!U),className:"p-1 rounded text-text-3 hover:text-accent hover:bg-accent/10 cursor-pointer transition-colors mr-1",children:e.jsx(xt,{size:10})})}),U&&e.jsx(eie,{onSelect:I=>E(I),onClose:()=>P(!1)})]}),r?e.jsx("button",{onClick:g,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Restore",children:e.jsx(HM,{size:12})}):e.jsx("button",{onClick:h,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Maximize",children:e.jsx(Mb,{size:12})}),e.jsx("button",{onClick:O,className:"p-1.5 rounded text-text-3 hover:text-text-0 hover:bg-surface-5 cursor-pointer transition-colors",title:"Close terminal",children:e.jsx(qe,{size:12})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 pl-2 pt-1",children:t})]})}const sie={background:"#1a1e25",foreground:"#c8ccd4",cursor:"#33afbc",cursorAccent:"#1a1e25",selectionBackground:"rgba(51, 175, 188, 0.3)",selectionForeground:"#ffffff",black:"#1a1e25",red:"#e06c75",green:"#4ae168",yellow:"#e5c07b",blue:"#61afef",magenta:"#c678dd",cyan:"#33afbc",white:"#abb2bf",brightBlack:"#5c6370",brightRed:"#f07178",brightGreen:"#4ae168",brightYellow:"#e5c07b",brightBlue:"#61afef",brightMagenta:"#c678dd",brightCyan:"#56b6c2",brightWhite:"#ffffff"};let eO=0,nie=0;function aie({tabId:t,visible:s,registerKill:n,onSelectionChange:a}){const r=p.useRef(null),l=p.useRef(null),c=p.useRef(null),A=p.useRef(null),f=p.useRef(null),x=p.useRef(!1),h=p.useRef(s),g=p.useRef({cols:0,rows:0}),O=p.useRef(!1);p.useEffect(()=>{n==null||n(t,()=>{const v=k.getState().ws;(v==null?void 0:v.readyState)===WebSocket.OPEN&&A.current&&v.send(JSON.stringify({type:"terminal:kill",id:A.current}))})},[t,n]);const b=k(v=>v.terminalPendingCommand);return p.useEffect(()=>{if(!b||!s)return;let v=0,y=null;const S=()=>{const j=k.getState().ws;if((j==null?void 0:j.readyState)===WebSocket.OPEN&&A.current&&O.current){j.send(JSON.stringify({type:"terminal:input",id:A.current,data:b.command+"\r"})),k.getState().clearTerminalPendingCommand();return}v++<40&&(y=setTimeout(S,150))};return S(),()=>clearTimeout(y)},[b,s]),p.useEffect(()=>{if(!r.current||x.current)return;x.current=!0;const v=new JU({theme:sie,fontFamily:"'SF Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace",fontSize:12,lineHeight:1.1,letterSpacing:0,cursorBlink:!0,cursorStyle:"bar",cursorWidth:1,scrollback:1e4,allowProposedApi:!0,minimumContrastRatio:1,drawBoldTextInBrightColors:!0,fontWeight:"400",fontWeightBold:"600",overviewRulerWidth:0}),y=new eE;v.loadAddon(y),v.loadAddon(new tE),v.open(r.current),l.current=v,c.current=y,v.onSelectionChange(()=>{const F=v.getSelection();a==null||a(F||"")});let S=0,j=!1;function N(){S++;const F=k.getState().ws;if(!F||F.readyState!==WebSocket.OPEN){S<20&&setTimeout(N,500);return}const M=`spawn-${++nie}`;F.send(JSON.stringify({type:"terminal:spawn",cols:v.cols,rows:v.rows,requestId:M}));function R(W){let ee;try{ee=JSON.parse(W.data)}catch{return}ee.type==="terminal:spawned"&&ee.requestId===M&&!A.current?(A.current=ee.id,setTimeout(()=>{try{y.fit()}catch{}const K=v.cols,_=v.rows;if(K>1&&_>1&&A.current){const q=k.getState().ws;(q==null?void 0:q.readyState)===WebSocket.OPEN&&(q.send(JSON.stringify({type:"terminal:resize",id:A.current,rows:_,cols:K})),g.current={cols:K,rows:_})}v.reset(),j=!0,O.current=!0;const E=k.getState().ws;(E==null?void 0:E.readyState)===WebSocket.OPEN&&A.current&&E.send(JSON.stringify({type:"terminal:input",id:A.current,data:"\f"}))},300)):ee.type==="terminal:output"&&ee.id===A.current?j&&v.write(ee.data):ee.type==="terminal:exit"&&ee.id===A.current&&(j=!0,O.current=!1,v.write(`\r
1069
1069
  \x1B[90m[session ended]\x1B[0m\r
1070
- `),A.current=null)}F.addEventListener("message",R),f.current={ws:F,handler:R},v.onData(W=>{const ee=k.getState().ws;(ee==null?void 0:ee.readyState)===WebSocket.OPEN&&A.current&&ee.send(JSON.stringify({type:"terminal:input",id:A.current,data:W}))});let Y=null;v.onResize(({cols:W,rows:ee})=>{W===g.current.cols&&ee===g.current.rows||W<2||ee<2||(g.current={cols:W,rows:ee},clearTimeout(Y),Y=setTimeout(()=>{const{cols:K,rows:_}=g.current,E=k.getState().ws;(E==null?void 0:E.readyState)===WebSocket.OPEN&&A.current&&E.send(JSON.stringify({type:"terminal:resize",id:A.current,rows:_,cols:K}))},150))})}let C=!1,U=null;function P(){if(C)return;const F=r.current;if(!F||F.offsetWidth<200||F.offsetHeight<50){clearTimeout(U),U=null;return}U||(U=setTimeout(()=>{if(C)return;const M=r.current;if(!M||M.offsetWidth<200||M.offsetHeight<50){U=null;return}C=!0;try{y.fit()}catch{}N()},200))}requestAnimationFrame(P);const T=setTimeout(()=>{if(!C){C=!0;try{y.fit()}catch{}N()}},5e3),B=new ResizeObserver(()=>{h.current&&requestAnimationFrame(()=>{if(!C)P();else try{y.fit()}catch{}})});return B.observe(r.current),()=>{clearTimeout(U),clearTimeout(T),B.disconnect(),f.current&&f.current.ws.removeEventListener("message",f.current.handler),v.dispose(),c.current=null,l.current=null,x.current=!1}},[]),p.useEffect(()=>{h.current=s,s&&c.current&&requestAnimationFrame(()=>{try{c.current.fit()}catch{}})},[s]),e.jsx("div",{ref:r,className:"w-full h-full overflow-hidden",style:{display:s?"block":"none"}})}function rie(){const t=k(j=>j.terminalVisible),s=k(j=>j.terminalHeight),n=k(j=>j.setTerminalVisible),a=k(j=>j.setTerminalHeight),r=k(j=>j.terminalFullHeight),l=k(j=>j.setTerminalFullHeight),[c,A]=p.useState([{id:"term-0",label:"Terminal"}]),[f,x]=p.useState("term-0"),[h,g]=p.useState(""),O=p.useRef({}),b=p.useCallback((j,N)=>{O.current[j]=N},[]),v=p.useCallback(()=>{eO++;const j=`term-${eO}`;A(N=>[...N,{id:j,label:`Terminal ${eO+1}`}]),x(j)},[]),y=p.useCallback((j,N)=>{A(C=>C.map(U=>U.id===j?{...U,label:N}:U))},[]),S=p.useCallback(j=>{var N,C;(C=(N=O.current)[j])==null||C.call(N),delete O.current[j],A(U=>{const P=U.filter(T=>T.id!==j);if(P.length===0)return n(!1),U;if(f===j){const T=U.findIndex(F=>F.id===j),B=P[Math.min(T,P.length-1)];x(B.id)}return P})},[f,n]);return e.jsx(tie,{visible:t,height:s,onHeightChange:a,fullHeight:r,tabs:c,activeTab:f,onSelectTab:x,onAddTab:v,onCloseTab:S,onRenameTab:y,onToggleFullHeight:()=>l(!0),onMinimize:()=>l(!1),onClose:()=>n(!1),selectedText:h,children:c.map(j=>e.jsx(aie,{tabId:j.id,visible:j.id===f,registerKill:b,onSelectionChange:j.id===f?g:void 0},j.id))})}class Ff extends go.Component{constructor(s){super(s),this.state={error:null}}static getDerivedStateFromError(s){return{error:s}}render(){return this.state.error?e.jsxs("div",{className:"h-screen bg-surface-0 p-10 font-sans",children:[e.jsx("h2",{className:"text-lg font-semibold text-text-0 mb-4",children:"Groove — Render Error"}),e.jsx("pre",{className:"text-sm text-danger whitespace-pre-wrap mb-4",children:this.state.error.message}),e.jsx("pre",{className:"text-xs text-text-3 whitespace-pre-wrap",children:this.state.error.stack}),e.jsx("button",{onClick:()=>this.setState({error:null}),className:"mt-6 px-4 py-2 bg-accent text-surface-0 rounded-md font-medium text-sm cursor-pointer",children:"Try Again"})]}):this.props.children}}function oie(){const t=k(l=>l.activeView),s=k(l=>l.detailPanel);k(l=>l.agents);const n=k(l=>l.networkUnlocked);let a;switch(t){case"agents":a=e.jsx(Dg,{});break;case"editor":a=e.jsx(ite,{});break;case"dashboard":a=e.jsx(Dte,{});break;case"marketplace":a=e.jsx(fse,{});break;case"teams":a=e.jsx(Ese,{});break;case"auto-agents":a=e.jsx(Qoe,{});break;case"models":a=e.jsx(tne,{});break;case"model-lab":a=e.jsx(lae,{});break;case"federation":a=e.jsx(bne,{});break;case"settings":a=e.jsx(Kse,{});break;case"chat":a=e.jsx(Sre,{});break;case"fleet":a=e.jsx(foe,{});break;case"memory":a=e.jsx(Pre,{});break;case"network":a=n?e.jsx(sre,{}):e.jsx(Dg,{});break;default:a=e.jsx(Dg,{})}let r=null;if(s)switch(s.type){case"agent":{r=e.jsx(Goe,{});break}case"journalist":r=e.jsx(Koe,{});break;case"spawn":r=null;break}return e.jsxs(Bee,{detailContent:r,terminalContent:e.jsx(rie,{}),children:[a,e.jsx(Voe,{})]})}function iie(){const t=k(n=>n.remoteHomedir),s=k(n=>n.setProjectDir);return e.jsxs("div",{className:"fixed inset-0 z-40 bg-surface-0 flex flex-col items-center justify-center gap-3",children:[e.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Connected — choose a project directory to continue"}),e.jsx(gc,{open:!0,onOpenChange:()=>{},currentPath:t||"/home",homePath:t,onSelect:n=>s(n),mandatory:!0})]})}function lie(){const t=k(A=>A.connected),[s,n]=p.useState(!1),[a,r]=p.useState(!1),l=p.useRef(!1);p.useEffect(()=>{const A=setTimeout(()=>n(!0),6e3);return()=>clearTimeout(A)},[]),p.useEffect(()=>{var A;!s||t||l.current||(A=window.groove)!=null&&A.reconnect&&(l.current=!0,r(!0),window.groove.reconnect().catch(()=>{}).finally(()=>r(!1)))},[s,t]);async function c(){var A;if((A=window.groove)!=null&&A.reconnect){r(!0);try{await window.groove.reconnect()}catch{}r(!1)}window.location.reload()}return e.jsxs("div",{className:"h-screen bg-surface-0 flex flex-col items-center justify-center gap-4",children:[e.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60 animate-pulse"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:a?"Re-establishing connection…":t?"Loading…":"Connecting to daemon…"}),s&&e.jsxs("div",{className:"flex flex-col items-center gap-2 mt-1",children:[e.jsx("p",{className:"text-xs text-text-4 font-sans max-w-xs text-center",children:"Still trying to reach the daemon. If you just woke your machine, the connection is re-establishing."}),e.jsx("button",{onClick:c,disabled:a,className:"px-3 py-1.5 rounded-md text-xs font-medium font-sans border border-accent/40 bg-accent/10 text-accent hover:bg-accent/20 disabled:opacity-50 transition-colors cursor-pointer",children:a?"Reconnecting…":"Reconnect"})]})]})}function cie(){const t=k(c=>c.connect),s=k(c=>c.hydrated),n=k(c=>c.tunneled),a=k(c=>c.onboardingComplete),r=k(c=>c.showProjectPicker);p.useEffect(()=>{t()},[t]),p.useEffect(()=>{async function c(){var x;if((x=window.groove)!=null&&x.getInstanceInfo){const h=await window.groove.getInstanceInfo();if(h!=null&&h.name){document.title=`${h.name} — Groove`;return}}const f=new URLSearchParams(window.location.search).get("instance");if(f){const h=f.replace(/[\x00-\x1F]/g,"").slice(0,50);document.title=`${h} — Groove`}else n?document.title="Remote — Groove":document.title="Groove"}c()},[n]);const l=p.useMemo(()=>{var c;return(c=window.groove)!=null&&c.openFolder?[{key:"o",meta:!0,handler:()=>window.groove.openFolder()}]:[]},[]);return pN(l),s?a?r&&n?e.jsx(Ff,{children:e.jsx(iie,{})}):r?e.jsxs(Ff,{children:[e.jsx(Hee,{}),e.jsx(SQ,{})]}):e.jsxs(Ff,{children:[e.jsx(oie,{}),e.jsx(SQ,{}),e.jsx(Lee,{}),e.jsx(Joe,{})]}):e.jsx(Ff,{children:e.jsx(_ee,{})}):e.jsx(lie,{})}oE.createRoot(document.getElementById("root")).render(e.jsx(p.StrictMode,{children:e.jsx(cie,{})}));
1070
+ `),A.current=null)}F.addEventListener("message",R),f.current={ws:F,handler:R},v.onData(W=>{const ee=k.getState().ws;(ee==null?void 0:ee.readyState)===WebSocket.OPEN&&A.current&&ee.send(JSON.stringify({type:"terminal:input",id:A.current,data:W}))});let Y=null;v.onResize(({cols:W,rows:ee})=>{W===g.current.cols&&ee===g.current.rows||W<2||ee<2||(g.current={cols:W,rows:ee},clearTimeout(Y),Y=setTimeout(()=>{const{cols:K,rows:_}=g.current,E=k.getState().ws;(E==null?void 0:E.readyState)===WebSocket.OPEN&&A.current&&E.send(JSON.stringify({type:"terminal:resize",id:A.current,rows:_,cols:K}))},150))})}let C=!1,U=null;function P(){if(C)return;const F=r.current;if(!F||F.offsetWidth<200||F.offsetHeight<50){clearTimeout(U),U=null;return}U||(U=setTimeout(()=>{if(C)return;const M=r.current;if(!M||M.offsetWidth<200||M.offsetHeight<50){U=null;return}C=!0;try{y.fit()}catch{}N()},200))}requestAnimationFrame(P);const T=setTimeout(()=>{if(!C){C=!0;try{y.fit()}catch{}N()}},5e3),B=new ResizeObserver(()=>{h.current&&requestAnimationFrame(()=>{if(!C)P();else try{y.fit()}catch{}})});return B.observe(r.current),()=>{clearTimeout(U),clearTimeout(T),B.disconnect(),f.current&&f.current.ws.removeEventListener("message",f.current.handler),v.dispose(),c.current=null,l.current=null,x.current=!1}},[]),p.useEffect(()=>{h.current=s,s&&c.current&&requestAnimationFrame(()=>{try{c.current.fit()}catch{}})},[s]),e.jsx("div",{ref:r,className:"w-full h-full overflow-hidden",style:{display:s?"block":"none"}})}function rie(){const t=k(j=>j.terminalVisible),s=k(j=>j.terminalHeight),n=k(j=>j.setTerminalVisible),a=k(j=>j.setTerminalHeight),r=k(j=>j.terminalFullHeight),l=k(j=>j.setTerminalFullHeight),[c,A]=p.useState([{id:"term-0",label:"Terminal"}]),[f,x]=p.useState("term-0"),[h,g]=p.useState(""),O=p.useRef({}),b=p.useCallback((j,N)=>{O.current[j]=N},[]),v=p.useCallback(()=>{eO++;const j=`term-${eO}`;A(N=>[...N,{id:j,label:`Terminal ${eO+1}`}]),x(j)},[]),y=p.useCallback((j,N)=>{A(C=>C.map(U=>U.id===j?{...U,label:N}:U))},[]),S=p.useCallback(j=>{var N,C;(C=(N=O.current)[j])==null||C.call(N),delete O.current[j],A(U=>{const P=U.filter(T=>T.id!==j);if(P.length===0)return n(!1),U;if(f===j){const T=U.findIndex(F=>F.id===j),B=P[Math.min(T,P.length-1)];x(B.id)}return P})},[f,n]);return e.jsx(tie,{visible:t,height:s,onHeightChange:a,fullHeight:r,tabs:c,activeTab:f,onSelectTab:x,onAddTab:v,onCloseTab:S,onRenameTab:y,onToggleFullHeight:()=>l(!0),onMinimize:()=>l(!1),onClose:()=>n(!1),selectedText:h,children:c.map(j=>e.jsx(aie,{tabId:j.id,visible:j.id===f,registerKill:b,onSelectionChange:j.id===f?g:void 0},j.id))})}class Ff extends go.Component{constructor(s){super(s),this.state={error:null}}static getDerivedStateFromError(s){return{error:s}}render(){return this.state.error?e.jsxs("div",{className:"h-screen bg-surface-0 p-10 font-sans",children:[e.jsx("h2",{className:"text-lg font-semibold text-text-0 mb-4",children:"Groove — Render Error"}),e.jsx("pre",{className:"text-sm text-danger whitespace-pre-wrap mb-4",children:this.state.error.message}),e.jsx("pre",{className:"text-xs text-text-3 whitespace-pre-wrap",children:this.state.error.stack}),e.jsx("button",{onClick:()=>this.setState({error:null}),className:"mt-6 px-4 py-2 bg-accent text-surface-0 rounded-md font-medium text-sm cursor-pointer",children:"Try Again"})]}):this.props.children}}function oie(){const t=k(l=>l.activeView),s=k(l=>l.detailPanel);k(l=>l.agents);const n=k(l=>l.networkUnlocked);let a;switch(t){case"agents":a=e.jsx(Dg,{});break;case"editor":a=e.jsx(ite,{});break;case"dashboard":a=e.jsx(Dte,{});break;case"marketplace":a=e.jsx(fse,{});break;case"teams":a=e.jsx(Ese,{});break;case"auto-agents":a=e.jsx(Qoe,{});break;case"models":a=e.jsx(tne,{});break;case"model-lab":a=e.jsx(lae,{});break;case"federation":a=e.jsx(bne,{});break;case"settings":a=e.jsx(Kse,{});break;case"chat":a=e.jsx(Sre,{});break;case"fleet":a=e.jsx(foe,{});break;case"memory":a=e.jsx(Pre,{});break;case"network":a=n?e.jsx(sre,{}):e.jsx(Dg,{});break;default:a=e.jsx(Dg,{})}let r=null;if(s)switch(s.type){case"agent":{r=e.jsx(Goe,{});break}case"journalist":r=e.jsx(Koe,{});break;case"spawn":r=null;break}return e.jsxs(Bee,{detailContent:r,terminalContent:e.jsx(rie,{}),children:[a,e.jsx(Voe,{})]})}function iie(){const t=k(n=>n.remoteHomedir),s=k(n=>n.setProjectDir);return e.jsxs("div",{className:"fixed inset-0 z-40 bg-surface-0 flex flex-col items-center justify-center gap-3",children:[e.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:"Connected — choose a project directory to continue"}),e.jsx(gc,{open:!0,onOpenChange:()=>{},currentPath:t||"/home",homePath:t,onSelect:n=>s(n),mandatory:!0})]})}function lie(){const t=k(c=>c.connected),[s,n]=p.useState(!1),[a,r]=p.useState(!1);p.useEffect(()=>{const c=setTimeout(()=>n(!0),12e3);return()=>clearTimeout(c)},[]);async function l(){var c;if((c=window.groove)!=null&&c.reconnect){r(!0);try{await window.groove.reconnect()}catch{}r(!1)}window.location.reload()}return e.jsxs("div",{className:"h-screen bg-surface-0 flex flex-col items-center justify-center gap-4",children:[e.jsx("img",{src:"/favicon.png",alt:"",className:"w-10 h-10 opacity-60 animate-pulse"}),e.jsx("p",{className:"text-sm text-text-3 font-sans",children:a?"Re-establishing connection…":t?"Loading…":"Connecting to daemon…"}),s&&e.jsxs("div",{className:"flex flex-col items-center gap-2 mt-1",children:[e.jsx("p",{className:"text-xs text-text-4 font-sans max-w-xs text-center",children:"Still trying to reach the daemon. If you just woke your machine, the connection is re-establishing."}),e.jsx("button",{onClick:l,disabled:a,className:"px-3 py-1.5 rounded-md text-xs font-medium font-sans border border-accent/40 bg-accent/10 text-accent hover:bg-accent/20 disabled:opacity-50 transition-colors cursor-pointer",children:a?"Reconnecting…":"Reconnect"})]})]})}function cie(){const t=k(c=>c.connect),s=k(c=>c.hydrated),n=k(c=>c.tunneled),a=k(c=>c.onboardingComplete),r=k(c=>c.showProjectPicker);p.useEffect(()=>{t()},[t]),p.useEffect(()=>{async function c(){var x;if((x=window.groove)!=null&&x.getInstanceInfo){const h=await window.groove.getInstanceInfo();if(h!=null&&h.name){document.title=`${h.name} — Groove`;return}}const f=new URLSearchParams(window.location.search).get("instance");if(f){const h=f.replace(/[\x00-\x1F]/g,"").slice(0,50);document.title=`${h} — Groove`}else n?document.title="Remote — Groove":document.title="Groove"}c()},[n]);const l=p.useMemo(()=>{var c;return(c=window.groove)!=null&&c.openFolder?[{key:"o",meta:!0,handler:()=>window.groove.openFolder()}]:[]},[]);return pN(l),s?a?r&&n?e.jsx(Ff,{children:e.jsx(iie,{})}):r?e.jsxs(Ff,{children:[e.jsx(Hee,{}),e.jsx(SQ,{})]}):e.jsxs(Ff,{children:[e.jsx(oie,{}),e.jsx(SQ,{}),e.jsx(Lee,{}),e.jsx(Joe,{})]}):e.jsx(Ff,{children:e.jsx(_ee,{})}):e.jsx(lie,{})}oE.createRoot(document.getElementById("root")).render(e.jsx(p.StrictMode,{children:e.jsx(cie,{})}));