"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[495],{13626:function(e,t,s){s.d(t,{Z:function(){return a}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let a=(0,s(60998).Z)("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]])},98418:function(e,t,s){s.d(t,{Z:function(){return a}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let a=(0,s(60998).Z)("Trash",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}]])},96122:function(e,t,s){s.d(t,{Z:function(){return a}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let a=(0,s(60998).Z)("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]])},23495:function(e,t,s){s.r(t),s.d(t,{ContextDetails:function(){return G},GPUs:function(){return T},InfrastructureSection:function(){return R}});var a=s(85893),r=s(67294),l=s(55739);s(33872);var n=s(96122),o=s(26409),c=s(98418),i=s(13626),d=s(23001),m=s(17853);function u(e){return null==e?"-":Math.round(e).toString()}function h(e,t,s){if(!s||0===e.length)return null;let a=e.reduce((e,s)=>{let a=s[t];return e+(null!=a?a:0)},0);return a>0?a:null}var x=s(30017),g=s(33907),p=s(32045);s(93225);var f=s(17324),y=s(23266),j=s(68969);s(47145);var N=s(29326),b=s(91360),v=s(30803),w=s(42557),S=s(29749),C=s(69123);function _(e){let{isOpen:t,onClose:s,onSave:n,poolData:o=null,isLoading:c=!1}=e,[i,d]=(0,r.useState)(""),[m,u]=(0,r.useState)(""),[h,x]=(0,r.useState)("ubuntu"),[g,p]=(0,r.useState)(null),[f,y]=(0,r.useState)(""),[j,_]=(0,r.useState)({}),k=null!==o;(0,r.useEffect)(()=>{if(k&&o){var e,t,s;d(o.name||""),u(((null===(e=o.config)||void 0===e?void 0:e.hosts)||[]).join("\n")),x((null===(t=o.config)||void 0===t?void 0:t.user)||"ubuntu"),y((null===(s=o.config)||void 0===s?void 0:s.password)||"")}else d(""),u(""),x("ubuntu"),p(null),y("");_({})},[k,o]);let P=()=>{let e={};return i.trim()||(e.poolName="Pool name is required"),m.trim()||(e.hosts="At least one host is required"),h.trim()||(e.sshUser="SSH user is required"),g||f||(e.auth="Either SSH key file or password is required"),_(e),0===Object.keys(e).length},U=async()=>{if(!P())return;let e={hosts:m.split("\n").map(e=>e.trim()).filter(e=>e.length>0),user:h};try{if(g){let t=g.name;await (0,N.hY)(t,g),e.identity_file="~/.sky/ssh_keys/".concat(t)}f&&(e.password=f),n(i,e)}catch(e){console.error("Failed to upload SSH key:",e),_({...j,keyUpload:"Failed to upload SSH key"})}},D=()=>{c||s()};return(0,a.jsx)(b.Vq,{open:t,onOpenChange:D,children:(0,a.jsxs)(b.cZ,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[(0,a.jsx)(b.fK,{children:(0,a.jsx)(b.$N,{children:k?"Edit SSH Node Pool: ".concat(null==o?void 0:o.name):"Add SSH Node Pool"})}),(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(S._,{htmlFor:"poolName",children:"Pool Name"}),(0,a.jsx)(w.I,{id:"poolName",placeholder:"my-ssh-cluster",value:i,onChange:e=>d(e.target.value),disabled:k,className:"placeholder:text-gray-500 ".concat(j.poolName?"border-red-500":"")}),j.poolName&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:j.poolName})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(S._,{htmlFor:"hosts",children:"Hosts (one per line)"}),(0,a.jsx)(C.g,{id:"hosts",placeholder:"192.168.1.10\n192.168.1.11\nhostname.example.com",value:m,onChange:e=>u(e.target.value),rows:6,className:"placeholder:text-gray-500 ".concat(j.hosts?"border-red-500":"")}),j.hosts&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:j.hosts})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(S._,{htmlFor:"sshUser",children:"SSH User"}),(0,a.jsx)(w.I,{id:"sshUser",placeholder:"ubuntu",value:h,onChange:e=>x(e.target.value),className:"placeholder:text-gray-500 ".concat(j.sshUser?"border-red-500":"")}),j.sshUser&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:j.sshUser})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(S._,{htmlFor:"keyFile",children:"SSH Private Key File"}),(0,a.jsx)(w.I,{id:"keyFile",type:"file",accept:".pem,.key,id_rsa,id_ed25519",onChange:e=>{var t;return p((null===(t=e.target.files)||void 0===t?void 0:t[0])||null)},className:"border-0 bg-transparent p-0 shadow-none focus:ring-0 file:mr-2 file:text-sm file:py-1 file:px-3 file:border file:border-gray-300 file:rounded file:bg-gray-50 hover:file:bg-gray-100 file:cursor-pointer"}),j.keyUpload&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:j.keyUpload})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(S._,{htmlFor:"password",children:"Password (optional, if sudo requires a password)"}),(0,a.jsx)(w.I,{id:"password",type:"password",placeholder:"Leave empty if using passwordless sudo",value:f,onChange:e=>y(e.target.value),className:"placeholder:text-gray-500"})]}),j.auth&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:j.auth})]}),(0,a.jsxs)(b.cN,{children:[(0,a.jsx)(v.z,{variant:"outline",onClick:D,disabled:c,children:"Cancel"}),(0,a.jsx)(v.z,{onClick:U,disabled:c,className:"bg-blue-600 hover:bg-blue-700 text-white disabled:bg-gray-300 disabled:text-gray-500",children:c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(l.Z,{size:16,className:"mr-2"}),"Saving..."]}):k?"Update Pool":"Create Pool"})]})]})})}var k=s(6378),P=s(36856),U=s(51214),D=s(11163),E=s(41664),I=s.n(E),M=s(470);s(37673);var F=s(62935);let H=U.nb.REFRESH_INTERVAL,Z=U.MO.NAME_TRUNCATE_LENGTH,A=e=>{let{gpu:t,heightClass:s="h-4",wrapperClassName:r=""}=e,l=(null==t?void 0:t.gpu_total)||0,n=(null==t?void 0:t.gpu_not_ready)||0,o=(null==t?void 0:t.gpu_free)||0,c=Math.max(0,l-o-n),i="".concat(n," not ready"),d="".concat(c," used"),m="".concat(o," free"),u=l>0?e=>e/l*100:()=>0,h=u(n),x=u(c),g=u(o);return(0,a.jsxs)("div",{className:"bg-gray-100 rounded-md flex overflow-hidden shadow-sm ".concat(s," ").concat(r).trim(),children:[h>0&&(0,a.jsx)("div",{style:{width:"".concat(h,"%"),fontSize:"clamp(8px, 1.2vw, 12px)"},title:i,className:"bg-gray-400 h-full flex items-center justify-center text-white font-medium overflow-hidden whitespace-nowrap px-1",children:h>15&&i}),x>0&&(0,a.jsx)("div",{style:{width:"".concat(x,"%"),fontSize:"clamp(8px, 1.2vw, 12px)"},title:d,className:"bg-yellow-500 h-full flex items-center justify-center text-white font-medium overflow-hidden whitespace-nowrap px-1",children:x>15&&d}),g>0&&(0,a.jsx)("div",{style:{width:"".concat(g,"%"),fontSize:"clamp(8px, 1.2vw, 12px)"},title:m,className:"bg-green-700 h-full flex items-center justify-center text-white font-medium overflow-hidden whitespace-nowrap px-1",children:g>15&&m})]})},L=()=>(0,a.jsx)("span",{className:"px-2 py-0.5 bg-muted rounded text-xs font-medium inline-flex items-center",children:(0,a.jsx)("span",{className:"infra-skeleton-text",style:{width:"20px",height:"12px"}})});function R(e){let{title:t,isLoading:s,isDataLoaded:r,contexts:o,gpus:c,groupedPerContextGPUs:i,groupedPerNodeGPUs:d,handleContextClick:m,contextStats:p={},jobsData:f={},isJobsDataLoading:y=!0,isClusterDataLoading:j=!0,isSSH:N=!1,isSlurm:b=!1,actionButton:v=null,contextWorkspaceMap:w={},contextErrors:S={},gpuMetricsRefreshTrigger:C=0,loadedContexts:_=new Set,isInitialLoad:k=!0}=e,P=o||[];if(r&&0===P.length)return(0,a.jsx)("div",{className:"rounded-lg border bg-card text-card-foreground shadow-sm mb-6",children:(0,a.jsxs)("div",{className:"p-5",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold",children:t}),v]}),(0,a.jsxs)("p",{className:"text-sm text-gray-500",children:["No ",t," found or ",t," is not configured."]})]})});if(k&&s&&!r&&0===P.length)return(0,a.jsx)("div",{className:"rounded-lg border bg-card text-card-foreground shadow-sm mb-6",children:(0,a.jsxs)("div",{className:"p-5",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold mb-4",children:t}),(0,a.jsxs)("div",{className:"flex items-center justify-center py-6",children:[(0,a.jsx)(l.Z,{size:24,className:"mr-3"}),(0,a.jsxs)("span",{className:"text-gray-500",children:["Loading ",t,"..."]})]})]})});let U=!k&&(s||!(b||N)&&P.length>0&&!P.every(e=>_.has(e)));return P.length>0?(0,a.jsx)("div",{className:"rounded-lg border bg-card text-card-foreground shadow-sm mb-6",children:(0,a.jsxs)("div",{className:"p-5",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold",children:t}),(0,a.jsxs)("span",{className:"ml-2 px-2 py-0.5 bg-blue-100 text-blue-800 rounded-full text-xs font-medium",children:[P.length," ",1===P.length?N?"pool":b?"cluster":"context":N?"pools":b?"clusters":"contexts"]})]}),v]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,a.jsx)("div",{children:(0,a.jsx)("div",{className:"overflow-x-auto rounded-md border shadow-sm bg-card ".concat(U?"infra-table-refreshing":""," ").concat(P.length>5?"max-h-[300px] overflow-y-auto":""),children:(0,a.jsxs)("table",{className:"min-w-full text-sm",children:[(0,a.jsx)("thead",{className:"bg-gray-50 sticky top-0 z-10",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/4",children:"Name"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/8",children:"Clusters"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/8",children:"Jobs"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/8",children:"Nodes"}),!b&&(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/8",children:"CPU"}),!b&&(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/6",children:"Memory"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/6",children:"GPU Types"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/8",children:"GPUs"})]})}),(0,a.jsx)("tbody",{className:"bg-white divide-y divide-gray-200",children:P.map(e=>{var t;let r=i[e]||[],l=d[e]||[],o=r.reduce((e,t)=>e+(t.gpu_total||0),0),c=(0,x.G)(e,{isSSH:N,isSlurm:b}),v=p[c]||{clusters:0,jobs:0},C=b||N?!s:_.has(e),P=b||N?!s:_.has(e),U=0===r.length?null:Object.keys(r.reduce((e,t)=>{let s=(0,g.y)(t.gpu_name);return e[s]=(e[s]||0)+(t.gpu_total||0),e},{})).join(", "),D=h(l,"cpu_count",!0),E=h(l,"memory_gb",!0),I=N?e.replace(/^ssh-/,""):e,F=w[e]||[],H=F.length>1?" (workspaces: ".concat(F.join(", "),")"):"";return(0,a.jsxs)("tr",{className:"hover:bg-muted/50 ".concat(C||k?"":"infra-loading-row"),children:[(0,a.jsx)("td",{className:"p-3",children:(0,a.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,a.jsx)(M.Md,{content:"".concat(I).concat(H),className:"text-sm text-muted-foreground",children:(0,a.jsxs)("span",{className:"text-blue-600 hover:underline cursor-pointer",onClick:()=>m(e),children:[I.length>Z?"".concat(I.substring(0,Math.floor((Z-3)/2)),"...").concat(I.substring(I.length-Math.ceil((Z-3)/2))):I,H&&(0,a.jsx)("span",{className:"text-xs text-gray-500 ml-1",children:H})]})}),S[e]&&(0,a.jsx)(M.Md,{content:"Context unreachable: ".concat(S[e]),className:"text-sm text-muted-foreground",children:(0,a.jsx)(n.Z,{className:"w-4 h-4 text-yellow-500 flex-shrink-0"})})]})}),(0,a.jsx)("td",{className:"p-3",children:j?(0,a.jsx)(L,{}):(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:v.clusters})}),(0,a.jsx)("td",{className:"p-3",children:y?(0,a.jsx)(L,{}):(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:(null===(t=f[c])||void 0===t?void 0:t.jobs)||0})}),(0,a.jsx)("td",{className:"p-3",children:P?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:l.length}):(0,a.jsx)(L,{})}),!b&&(0,a.jsx)("td",{className:"p-3",children:P?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:u(D)}):(0,a.jsx)(L,{})}),!b&&(0,a.jsx)("td",{className:"p-3",children:P?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:null==E?"-":"".concat(Math.round(E)," GB")}):(0,a.jsx)(L,{})}),(0,a.jsx)("td",{className:"p-3",children:C?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:U||"-"}):(0,a.jsx)(L,{})}),(0,a.jsx)("td",{className:"p-3",children:C?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:o}):(0,a.jsx)(L,{})})]},e)})})]})})}),c&&c.length>0&&(0,a.jsx)("div",{children:(0,a.jsx)("div",{className:"overflow-x-auto rounded-md border shadow-sm bg-card ".concat(U?"infra-table-refreshing":""," ").concat(c.length>5?"max-h-[300px] overflow-y-auto":""),children:(0,a.jsxs)("table",{className:"min-w-full text-sm",children:[(0,a.jsx)("thead",{className:"bg-gray-50 sticky top-0 z-10",children:(0,a.jsxs)("tr",{children:[(0,a.jsxs)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/4 whitespace-nowrap",children:["GPU",(0,a.jsxs)("span",{className:"ml-2 px-2 py-0.5 bg-green-100 text-green-800 rounded-full text-xs font-medium whitespace-nowrap",children:[c.reduce((e,t)=>e+t.gpu_free,0)," ","of"," ",c.reduce((e,t)=>e+t.gpu_total,0)," ","free"]})]}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/4",children:"Requestable"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/2",children:(0,a.jsx)("div",{className:"flex items-center",children:(0,a.jsx)("span",{children:"Utilization"})})})]})}),(0,a.jsx)("tbody",{className:"bg-white divide-y divide-gray-200",children:c.map(e=>{let t=i?Object.values(i).flat().filter(t=>{if((0,g.y)(t.gpu_name)!==e.gpu_name)return!1;if(b)return!0;let s=t.context||t.cluster;return!!s&&(N?s.startsWith("ssh-"):!s.startsWith("ssh-"))}).map(e=>e.gpu_requestable_qty_per_node).filter((e,t,s)=>s.indexOf(e)===t).join(", "):"-";return(0,a.jsxs)("tr",{children:[(0,a.jsx)("td",{className:"p-3 font-medium w-24 whitespace-nowrap",children:(0,g.y)(e.gpu_name)}),(0,a.jsxs)("td",{className:"p-3 text-xs text-gray-600",children:[t||"-"," / node"]}),(0,a.jsx)("td",{className:"p-3 w-2/3",children:(0,a.jsx)("div",{className:"flex items-center gap-3",children:(0,a.jsx)(A,{gpu:e,heightClass:"h-5",wrapperClassName:"flex-1 min-w-[100px] w-full"})})})]},e.gpu_name)})})]})})})]})]})}):null}function G(e){let{contextName:t,gpusInContext:s,nodesInContext:n,gpuMetricsRefreshTrigger:o=0,isSlurm:c=!1}=e,i=t.startsWith("ssh-"),[d,h]=(0,r.useState)([]),[x,p]=(0,r.useState)("$__all"),[f,y]=(0,r.useState)({from:"now-1h",to:"now"}),[j,N]=(0,r.useState)(!1),[b,v]=(0,r.useState)(!1);(0,r.useEffect)(()=>{(async()=>{v(await (0,m.TO)())})()},[]);let w=(0,r.useCallback)(async()=>{if(b){N(!0);try{let e=(0,m.ki)(),s="in-cluster"===t?"^$":t,a="query="+encodeURIComponent('group by (node) (DCGM_FI_DEV_GPU_TEMP{cluster=~"'.concat(s,'"} or label_replace(amd_gpu_gfx_activity{cluster=~"').concat(s,'"}, "node", "$1", "hostname", "(.*)"))')),r="/api/datasources/proxy/1/api/v1/query?".concat(a);try{let t=await fetch("".concat(e).concat(r),{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(t.ok){let e=await t.json();if(e.data&&e.data.result&&e.data.result.length>0){let t=e.data.result.map(e=>e.metric.node).filter(Boolean).sort();h(t),console.log("Successfully fetched hosts for cluster ".concat(s||"in-cluster",":"),t)}else console.log("No nodes found for this cluster"),h([])}else console.log("HTTP ".concat(t.status," from ").concat(r,": ").concat(t.statusText)),h([])}catch(e){console.log("Failed to fetch from ".concat(r,":"),e),h([])}}catch(e){console.error("Error fetching available hosts:",e),h([])}finally{N(!1)}}},[b,t]);(0,r.useEffect)(()=>{b&&n&&n.length>0&&w()},[n,b,w]);let S=e=>{let s=(0,m.ki)(),a="in-cluster"===t?"^$":t;return"".concat(s,"/d-solo/skypilot-dcgm-cluster-dashboard/skypilot-dcgm-kubernetes-cluster-dashboard?orgId=1&timezone=browser&var-datasource=prometheus&var-host=").concat(encodeURIComponent(x),"&var-gpu=$__all&var-cluster=").concat(encodeURIComponent(a),"&refresh=5s&theme=light&from=").concat(encodeURIComponent(f.from),"&to=").concat(encodeURIComponent(f.to),"&panelId=").concat(e,"&__feature.dashboardSceneSolo")},C=e=>{y({"15m":{from:"now-15m",to:"now"},"1h":{from:"now-1h",to:"now"},"6h":{from:"now-6h",to:"now"},"24h":{from:"now-24h",to:"now"},"7d":{from:"now-7d",to:"now"}}[e])};return(0,a.jsx)("div",{className:"mb-4",children:(0,a.jsx)("div",{className:"rounded-lg border bg-card text-card-foreground shadow-sm h-full",children:(0,a.jsxs)("div",{className:"p-5",children:[(0,a.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,a.jsx)("h4",{className:"text-lg font-semibold",children:"Nodes"})}),s.length>0&&(0,a.jsxs)("div",{className:"mb-6",children:[(0,a.jsx)("h4",{className:"text-base font-semibold mb-3",children:"Available GPUs"}),(0,a.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:s.map(e=>(0,a.jsxs)("div",{className:"p-3 bg-gray-50 rounded-md border border-gray-200 shadow-sm",children:[(0,a.jsxs)("div",{className:"flex justify-between items-center mb-1.5 flex-wrap",children:[(0,a.jsxs)("div",{className:"font-medium text-gray-800 text-sm",children:[(0,g.y)(e.gpu_name),(0,a.jsxs)("span",{className:"text-xs text-gray-500 ml-2",children:["(Requestable: ",e.gpu_requestable_qty_per_node," / node)"]})]}),(0,a.jsxs)("span",{className:"text-xs font-medium",children:[e.gpu_free," free / ",e.gpu_total," total"]})]}),(0,a.jsx)("div",{className:"w-full",children:(0,a.jsx)(A,{gpu:e,heightClass:"h-4",wrapperClassName:"w-full"})})]},e.gpu_name))})]}),n.length>0&&(0,a.jsx)("div",{className:"overflow-x-auto rounded-md border border-gray-200 shadow-sm",children:(0,a.jsxs)("table",{className:"min-w-full text-sm",children:[(0,a.jsx)("thead",{className:"bg-gray-100",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600",children:"Node"}),!c&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600",children:"IP Address"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600",children:"vCPU"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600",children:"Memory (GB)"})]}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600",children:"GPU"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600",children:"GPU Utilization"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600",children:"Node Status"})]})}),(0,a.jsx)("tbody",{className:"bg-white divide-y divide-gray-200",children:n.map((e,t)=>{let s="-";if(null!==e.cpu_count&&void 0!==e.cpu_count){let t=u(e.cpu_count);if(null!==e.cpu_free&&void 0!==e.cpu_free){let a=u(e.cpu_free);s="".concat(a," of ").concat(t," free")}else s=t}let r="-";if(null!==e.memory_gb&&void 0!==e.memory_gb){let t=e.memory_gb.toFixed(1);if(null!==e.memory_free_gb&&void 0!==e.memory_free_gb){let s=e.memory_free_gb.toFixed(1);r="".concat(s," of ").concat(t," free")}else r=t}let l="".concat(e.gpu_free," of ").concat(e.gpu_total," free"),n=[];!1===e.is_ready&&n.push("NotReady"),!0===e.is_cordoned&&n.push("Cordoned");let o=e.taints||[],i=null;if(o.length>0){let e={};for(let t of o){let s=t.effect,a=t.key;e[s]||(e[s]=[]),e[s].push(a)}let t=Object.entries(e).map(e=>{let[t,s]=e;return"".concat(t," Taint [").concat(s.join(", "),"]")});t.length>0&&(i=t.join(", "))}let d=n.length>0||i?n.join(", "):"Healthy",m=0===n.length&&!i;return(0,a.jsxs)("tr",{className:"hover:bg-gray-50",children:[(0,a.jsx)("td",{className:"p-3 whitespace-nowrap text-gray-700",children:e.node_name}),!c&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("td",{className:"p-3 whitespace-nowrap text-gray-700",children:e.ip_address||"-"}),(0,a.jsx)("td",{className:"p-3 whitespace-nowrap text-gray-700",children:s}),(0,a.jsx)("td",{className:"p-3 whitespace-nowrap text-gray-700",children:r})]}),(0,a.jsx)("td",{className:"p-3 whitespace-nowrap text-gray-700",children:(0,g.y)(e.gpu_name)}),(0,a.jsx)("td",{className:"p-3 whitespace-nowrap text-gray-700",children:l}),(0,a.jsx)("td",{className:"p-3 max-w-xs",children:(0,a.jsxs)("div",{className:"flex flex-col gap-1.5",children:[d&&(0,a.jsx)("span",{className:"inline-flex items-center px-2.5 py-1 rounded-md text-xs font-medium w-fit ".concat(m?"bg-emerald-50 text-emerald-700 ring-1 ring-inset ring-emerald-600/20":"bg-amber-50 text-amber-700 ring-1 ring-inset ring-amber-600/20"),children:d}),i&&(0,a.jsx)("span",{className:"inline-flex items-center px-2.5 py-1 rounded-md text-xs font-medium w-fit bg-gray-50 text-gray-700 ring-1 ring-inset ring-gray-600/20",children:i})]})})]},"".concat(e.node_name,"-").concat(t))})})]})}),b&&s&&s.length>0&&!i&&!c&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("h4",{className:"text-lg font-semibold mb-4 mt-6",children:"GPU Metrics"}),(0,a.jsxs)("div",{className:"mb-4 p-4 bg-gray-50 rounded-md border border-gray-200",children:[(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center",children:[n&&n.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("label",{htmlFor:"host-select",className:"text-sm font-medium text-gray-700 whitespace-nowrap",children:"Node:"}),(0,a.jsxs)("select",{id:"host-select",value:x,onChange:e=>{p(e.target.value)},disabled:j,className:"px-3 py-1 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-sky-blue focus:border-transparent",children:[(0,a.jsx)("option",{value:"$__all",children:"All Nodes"}),d.map(e=>(0,a.jsx)("option",{value:e,children:e},e))]}),j&&(0,a.jsx)("div",{className:"ml-2",children:(0,a.jsx)(l.Z,{size:16})})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("label",{className:"text-sm font-medium text-gray-700 whitespace-nowrap",children:"Time Range:"}),(0,a.jsx)("div",{className:"flex gap-1",children:[{label:"15m",value:"15m"},{label:"1h",value:"1h"},{label:"6h",value:"6h"},{label:"24h",value:"24h"},{label:"7d",value:"7d"}].map(e=>(0,a.jsx)("button",{onClick:()=>C(e.value),className:"px-2 py-1 text-xs font-medium rounded border transition-colors ".concat(f.from==="now-".concat(e.value)&&"now"===f.to?"bg-sky-blue text-white border-sky-blue":"bg-white text-gray-600 border-gray-300 hover:bg-gray-50"),children:e.label},e.value))})]})]}),(0,a.jsx)("div",{className:"mt-2 text-xs text-gray-500",children:n&&n.length>0?(0,a.jsxs)(a.Fragment,{children:["Showing:"," ","$__all"===x?"All nodes":x," ","• Time: ",f.from," to ",f.to,d.length>0&&(0,a.jsxs)("span",{children:[" ","• ",d.length," nodes available"]})]}):(0,a.jsxs)(a.Fragment,{children:["Cluster:"," ",i?t.replace(/^ssh-/,""):t," ","• Time: ",f.from," to ",f.to," • Showing metrics for all nodes in cluster"]})})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[(0,a.jsx)("div",{className:"bg-white rounded-md border border-gray-200 shadow-sm",children:(0,a.jsx)("div",{className:"p-2",children:(0,a.jsx)("iframe",{src:S("6"),width:"100%",height:"400",frameBorder:"0",title:"GPU Utilization",className:"rounded"},"gpu-util-".concat(x,"-").concat(f.from,"-").concat(f.to,"-").concat(o||0))})}),(0,a.jsx)("div",{className:"bg-white rounded-md border border-gray-200 shadow-sm",children:(0,a.jsx)("div",{className:"p-2",children:(0,a.jsx)("iframe",{src:S("18"),width:"100%",height:"400",frameBorder:"0",title:"GPU Memory",className:"rounded"},"gpu-memory-".concat(x,"-").concat(f.from,"-").concat(f.to,"-").concat(o||0))})}),(0,a.jsx)("div",{className:"bg-white rounded-md border border-gray-200 shadow-sm",children:(0,a.jsx)("div",{className:"p-2",children:(0,a.jsx)("iframe",{src:S("10"),width:"100%",height:"400",frameBorder:"0",title:"GPU Power Consumption",className:"rounded"},"gpu-power-".concat(x,"-").concat(f.from,"-").concat(f.to,"-").concat(o||0))})}),(0,a.jsx)("div",{className:"bg-white rounded-md border border-gray-200 shadow-sm",children:(0,a.jsx)("div",{className:"p-2",children:(0,a.jsx)("iframe",{src:S("12"),width:"100%",height:"400",frameBorder:"0",title:"GPU Temperature",className:"rounded"},"gpu-temp-".concat(x,"-").concat(f.from,"-").concat(f.to,"-").concat(o||0))})}),(0,a.jsx)("div",{className:"bg-white rounded-md border border-gray-200 shadow-sm",children:(0,a.jsx)("div",{className:"p-2",children:(0,a.jsx)("iframe",{src:S("22"),width:"100%",height:"400",frameBorder:"0",title:"CPU Utilization",className:"rounded"},"cpu-util-".concat(x,"-").concat(f.from,"-").concat(f.to,"-").concat(o||0))})}),(0,a.jsx)("div",{className:"bg-white rounded-md border border-gray-200 shadow-sm",children:(0,a.jsx)("div",{className:"p-2",children:(0,a.jsx)("iframe",{src:S("21"),width:"100%",height:"400",frameBorder:"0",title:"Memory Utilization",className:"rounded"},"memory-util-".concat(x,"-").concat(f.from,"-").concat(f.to,"-").concat(o||0))})})]})]})]})})})}function q(e){var t;let{poolName:s,gpusInContext:n,nodesInContext:i,handleDeploySSHPool:d,handleEditSSHPool:m,handleDeleteSSHPool:u,poolConfig:h}=e,[x,g]=(0,r.useState)(null),[p,f]=(0,r.useState)(!0),[y,j]=(0,r.useState)({isOpen:!1,action:null,loading:!1}),[w,S]=(0,r.useState)({isOpen:!1,logs:"",isStreaming:!1,deploymentComplete:!1,deploymentSuccess:!1,requestId:null});(0,r.useEffect)(()=>{(async()=>{try{f(!0);let e=await (0,N.IS)(s);g(e)}catch(e){console.error("Failed to fetch SSH Node Pool status:",e),g({pool_name:s,status:"Error",reason:"Failed to fetch status"})}finally{f(!1)}})()},[s]);let{deployDisabled:C}=(()=>{if(!x)return{deployDisabled:!0};let e=x.status;return"Ready"===e?{deployDisabled:!0}:"Error"===e?{deployDisabled:!0}:{deployDisabled:!1}})(),_=async()=>{j({...y,loading:!0});try{if("deploy"===y.action){j({isOpen:!1,action:null,loading:!1}),S({isOpen:!0,logs:"",isStreaming:!0,deploymentComplete:!1,deploymentSuccess:!1,requestId:null});try{let e=(await d(s)).request_id;S(t=>({...t,requestId:e}));let t=new AbortController;await (0,N.wJ)({requestId:e,signal:t.signal,onNewLog:e=>{S(t=>({...t,logs:t.logs+e}))}}),S(e=>({...e,isStreaming:!1,deploymentComplete:!0,deploymentSuccess:!0})),setTimeout(async()=>{(async()=>{try{let e=await (0,N.IS)(s);g(e)}catch(e){console.error("Failed to fetch SSH Node Pool status after deployment:",e)}})()},1e3)}catch(e){console.error("Deployment failed:",e),S(t=>({...t,isStreaming:!1,deploymentComplete:!0,deploymentSuccess:!1,logs:t.logs+"\nDeployment failed: ".concat(e.message)}))}}else if("delete"===y.action){j({isOpen:!1,action:null,loading:!1}),S({isOpen:!0,logs:"",isStreaming:!0,deploymentComplete:!1,deploymentSuccess:!1,requestId:null});try{let e=(await (0,N.ez)(s)).request_id;S(t=>({...t,requestId:e})),e&&await (0,N.mF)({requestId:e,signal:null,onNewLog:e=>{S(t=>({...t,logs:t.logs+e}))},operationType:"down"}),await u(s),S(e=>({...e,isStreaming:!1,deploymentComplete:!0,deploymentSuccess:!0,logs:e.logs+"\nSSH Node Pool teardown completed successfully."}))}catch(e){console.error("Down operation failed:",e),S(t=>({...t,isStreaming:!1,deploymentComplete:!0,deploymentSuccess:!1,logs:t.logs+"\nTeardown failed: ".concat(e.message)}))}}}catch(e){console.error("Action failed:",e),j({...y,loading:!1})}},k=()=>{j({isOpen:!1,action:null,loading:!1})},P=()=>{S({isOpen:!1,logs:"",isStreaming:!1,deploymentComplete:!1,deploymentSuccess:!1,requestId:null}),w.deploymentComplete&&setTimeout(()=>{(async()=>{try{let e=await (0,N.IS)(s);g(e)}catch(e){console.error("Failed to refresh status:",e)}})()},1e3)},U="deploy"===y.action?{title:"Deploy SSH Node Pool",description:'Are you sure you want to deploy SSH Node Pool "'.concat(s,'"?'),details:["• Set up SkyPilot runtime on the configured SSH hosts","• Install required components and dependencies","• Make the node pool available for workloads","","This process may take a few minutes to complete."]}:{title:"Delete SSH Node Pool",description:'Are you sure you want to delete SSH Node Pool "'.concat(s,'"?'),details:["• Clean up any deployed resources","• Remove the SSH Node Pool configuration"]};return(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"mb-6",children:(0,a.jsxs)("div",{className:"rounded-lg border bg-card text-card-foreground shadow-sm",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between px-4 pt-4",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold",children:"SSH Node Pool Details"}),(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsxs)("button",{className:"px-3 py-1 text-sm border rounded flex items-center ".concat(C?"border-gray-300 bg-gray-100 text-gray-400 cursor-not-allowed":"border-green-300 bg-green-50 text-green-700 hover:bg-green-100"),onClick:C?void 0:()=>{j({isOpen:!0,action:"deploy",loading:!1})},disabled:C,children:[(0,a.jsx)(o.Z,{className:"w-4 h-4 mr-2"}),"Deploy"]}),(0,a.jsxs)("button",{className:"px-3 py-1 text-sm border border-gray-300 rounded hover:bg-gray-50 flex items-center text-red-600 hover:text-red-700",onClick:()=>{j({isOpen:!0,action:"delete",loading:!1})},children:[(0,a.jsx)(c.Z,{className:"w-4 h-4 mr-2"}),"Delete"]})]})]}),(0,a.jsx)("div",{className:"p-4",children:(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-6",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-gray-600 font-medium text-base",children:"Pool Name"}),(0,a.jsx)("div",{className:"text-base mt-1",children:s})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-gray-600 font-medium text-base",children:"Nodes"}),(0,a.jsx)("div",{className:"text-base mt-1",children:i?i.length:0})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"text-gray-600 font-medium text-base",children:"Status"}),(0,a.jsx)("div",{className:"text-base mt-1",children:p?(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(l.Z,{size:16,className:"mr-2"}),(0,a.jsx)("span",{className:"text-gray-500",children:"Loading..."})]}):x?(0,a.jsx)(e=>{let{status:t,reason:s}=e,r="Ready"===t,l="Not Ready"===t?"Click Deploy to set up this node pool":s;return(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)("span",{className:"px-2 py-0.5 rounded text-xs font-medium ".concat(r?"bg-green-100":"bg-red-100"," ").concat(r?"text-green-800":"text-red-800"),children:t}),!r&&l&&(0,a.jsxs)("span",{className:"text-sm text-gray-600",children:["(",l,")"]})]})},{status:x.status,reason:x.reason}):(0,a.jsx)("span",{className:"text-gray-500",children:"Unknown"})})]})]})})]})}),(0,a.jsx)(G,{contextName:"ssh-".concat(s),gpusInContext:n,nodesInContext:i}),(0,a.jsx)(b.Vq,{open:y.isOpen,onOpenChange:k,children:(0,a.jsxs)(b.cZ,{className:"sm:max-w-md",children:[(0,a.jsxs)(b.fK,{className:"",children:[(0,a.jsx)(b.$N,{className:"",children:U.title}),(0,a.jsx)(b.Be,{className:"",children:U.description})]}),(0,a.jsx)("div",{className:"py-4",children:(0,a.jsxs)("div",{className:"text-sm text-gray-600 space-y-1",children:[(0,a.jsx)("p",{className:"font-medium mb-2",children:"This will:"}),U.details.map((e,t)=>(0,a.jsx)("p",{className:""===e?"pt-2":"",children:e},t))]})}),(0,a.jsxs)(b.cN,{className:"",children:[(0,a.jsx)(v.z,{variant:"outline",onClick:k,disabled:y.loading,className:"",children:"Cancel"}),(0,a.jsx)(v.z,{onClick:_,disabled:y.loading,className:"deploy"===y.action?"bg-green-600 hover:bg-green-700 text-white":"bg-red-600 hover:bg-red-700 text-white",children:y.loading?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(l.Z,{size:16,className:"mr-2"}),"deploy"===y.action?"Deploying...":"Deleting..."]}):"deploy"===y.action?"Deploy":"Delete"})]})]})}),(0,a.jsx)(b.Vq,{open:w.isOpen,onOpenChange:w.isStreaming?void 0:P,children:(0,a.jsxs)(b.cZ,{className:"sm:max-w-4xl max-h-[80vh]",children:[(0,a.jsxs)(b.fK,{className:"",children:[(0,a.jsxs)(b.$N,{className:"",children:["Deploying SSH Node Pool: ",s]}),(0,a.jsx)(b.Be,{className:"",children:w.isStreaming?"Deployment in progress. Do not close this dialog.":w.deploymentSuccess?"Deployment completed successfully!":"Deployment completed with errors."})]}),(0,a.jsx)("div",{className:"py-4",children:(0,a.jsxs)("div",{className:"bg-black text-green-400 p-4 rounded-md font-mono text-sm max-h-96 overflow-y-auto",children:[(0,a.jsx)("pre",{className:"whitespace-pre-wrap",children:(t=w.logs)?t.split("\n").map(e=>(e=e.replace(/\x1b\[[0-9;]*m/g,"")).match(/^D \d{2}-\d{2} \d{2}:\d{2}:\d{2}/)?null:e=(e=e.replace(/├──/g,"├─")).replace(/└──/g,"└─")).filter(e=>null!==e&&""!==e.trim()).join("\n"):""}),w.isStreaming&&(0,a.jsxs)("div",{className:"flex items-center mt-2",children:[(0,a.jsx)(l.Z,{size:16,className:"mr-2 text-green-400"}),(0,a.jsx)("span",{className:"text-green-400",children:"Streaming logs..."})]})]})}),(0,a.jsx)(b.cN,{className:"",children:(0,a.jsx)(v.z,{onClick:P,disabled:w.isStreaming,className:w.deploymentSuccess?"bg-green-600 hover:bg-green-700 text-white":w.deploymentComplete&&!w.deploymentSuccess?"bg-red-600 hover:bg-red-700 text-white":"bg-gray-600 hover:bg-gray-700 text-white",children:w.isStreaming?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(l.Z,{size:16,className:"mr-2"}),"Deploying..."]}):"Close"})})]})})]})}function z(){return(0,a.jsx)("div",{className:"rounded-lg border bg-card text-card-foreground shadow-sm mb-6",children:(0,a.jsx)("div",{className:"p-5",children:(0,a.jsx)("div",{className:"flex items-start",children:(0,a.jsxs)("div",{className:"ml-3 flex-1",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:"No Infrastructure Enabled"}),(0,a.jsx)("p",{className:"text-sm text-gray-600 mb-4",children:"No cloud providers, Kubernetes contexts, SSH node pools, or Slurm clusters are currently enabled or configured."}),(0,a.jsxs)("div",{className:"space-y-2 mb-4",children:[(0,a.jsx)("p",{className:"text-sm text-gray-600",children:"To check enabled infrastructures, you can:"}),(0,a.jsxs)("ul",{className:"list-disc list-inside text-sm text-gray-600 space-y-1 ml-2",children:[(0,a.jsxs)("li",{children:["Click ",(0,a.jsx)("strong",{children:'"Refresh"'}),"."]}),(0,a.jsxs)("li",{children:["Run"," ",(0,a.jsx)("code",{className:"bg-gray-100 px-1.5 py-0.5 rounded",children:"sky check"})," ","in your CLI."]})]})]})]})})})})}function T(){let[e,t]=(0,r.useState)(!0),[s,n]=(0,r.useState)(!0),[o,c]=(0,r.useState)(!0),m=r.useRef(null),u=(0,d.X)(),[h,x]=(0,r.useState)(!1),[b,v]=(0,r.useState)(!1),w=(0,D.useRouter)(),[S,C]=(0,r.useState)([]),[U,E]=(0,r.useState)([]),[Z,A]=(0,r.useState)([]),[T,O]=(0,r.useState)([]),[W,B]=(0,r.useState)(new Set),[K,V]=(0,r.useState)([]),[$,J]=(0,r.useState)([]),[Q,X]=(0,r.useState)([]),[Y,ee]=(0,r.useState)([]),[et,es]=(0,r.useState)(0),[ea,er]=(0,r.useState)(0),[el,en]=(0,r.useState)({}),[eo,ec]=(0,r.useState)({}),[ei,ed]=(0,r.useState)({}),[em,eu]=(0,r.useState)({}),[eh,ex]=(0,r.useState)({}),[eg,ep]=(0,r.useState)({}),[ef,ey]=(0,r.useState)("all"),[ej,eN]=(0,r.useState)([]),[eb,ev]=(0,r.useState)({}),[ew,eS]=(0,r.useState)(!1),[eC,e_]=(0,r.useState)(null),[ek,eP]=(0,r.useState)(!1),[eU,eD]=(0,r.useState)(!0),[eE,eI]=(0,r.useState)(!1),[eM,eF]=(0,r.useState)(!0),[eH,eZ]=(0,r.useState)({}),[eA,eL]=(0,r.useState)(!0),[eR,eG]=(0,r.useState)(null),[eq,ez]=(0,r.useState)(0),eT=r.useRef(!0),[eO,eW]=(0,r.useState)(!1),eB=r.useRef(0),eK=r.useRef(!1),[eV,e$]=(0,r.useState)(null),eJ=r.useCallback(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{showLoadingIndicators:!0},{showLoadingIndicators:s=!0,forceRefresh:a=!1}=e;eW(!0),eK.current=!1,s&&(t(!0),n(!0),eP(!0),eD(!0),eF(!0),eL(!0));try{let e=a?(0,f.LD)().catch(e=>{console.error("Error during sky check refresh:",e)}):Promise.resolve();await Promise.all([e,eQ(a,s),e2(a),e1(a),eX(),eY(),e0()]),eK.current=!0,0===eB.current&&eW(!1)}catch(e){console.error("Error in fetchData:",e),ep({}),C([]),E([]),A([]),O([]),ed({}),eu({}),ex({}),eN([]),x(!0),t(!1),eL(!1),ee([]),es(0),er(0),en({}),ec({}),v(!0),ev({}),eP(!1),eD(!1),V([]),J([]),X([]),eZ({}),eF(!1),eK.current=!0,0===eB.current&&eW(!1)}finally{s&&(t(!1),n(!1),eP(!1),eD(!1),eF(!1),eL(!1)),o&&s&&c(!1)}},[o]),eQ=async function(e){let s=!(arguments.length>1)||void 0===arguments[1]||arguments[1];try{let a=e?await (0,p.CI)():await k.ZP.get(p.CI);if(!a){ep({}),C([]),E([]),A([]),O([]),eu({}),ex({}),eN([]),x(!0),t(!1);return}let{workspaces:r,allContextNames:l,contextWorkspaceMap:n}=a;ep(r||{}),C(l||[]),eu(n||{});let o=Object.keys(r||{});eN(o.sort()),x(!0),t(!1);let c=(l||[]).filter(e=>e&&"string"==typeof e);if(0===c.length){s&&(E([]),A([]),O([]),ex({}),B(new Set));return}s&&(B(new Set),ex({})),eB.current=c.length,c.forEach(t=>{(e?(0,p.UU)(t):k.ZP.get(p.UU,[t])).then(e=>{B(e=>new Set([...e,t])),A(s=>[...s.filter(e=>e.context!==t),...e.perContextGPUs]),O(s=>[...s.filter(e=>e.context!==t),...e.perNodeGPUs]),e.error&&ex(s=>({...s,[t]:e.error}))}).catch(e=>{B(e=>new Set([...e,t])),ex(s=>({...s,[t]:e.message||"Failed to load GPU data"}))}).finally(()=>{eB.current--,0===eB.current&&eK.current&&eW(!1)})})}catch(e){console.error("Error in fetchKubernetesData:",e),ep({}),C([]),E([]),A([]),O([]),eu({}),ex({}),eN([]),x(!0),t(!1)}},eX=async()=>{try{let e=await k.ZP.get(j.getManagedJobs,[{allUsers:!0,skipFinished:!0}]),t=(null==e?void 0:e.jobs)||[];eZ(await (0,p.R8)(t));let s={};t.forEach(e=>{e.cloud&&(s[e.cloud]=(s[e.cloud]||0)+1)}),ec(s),eF(!1)}catch(e){console.error("Error in fetchManagedJobsData:",e),eZ({}),ec({}),eF(!1)}},eY=async()=>{try{let e=await k.ZP.get(y.getClusters)||[],t=await (0,p.F5)(e);ed(t);let s={};e.forEach(e=>{e.cloud&&(s[e.cloud]=(s[e.cloud]||0)+1)}),en(s),eL(!1)}catch(e){console.error("Error in fetchClusterStatsData:",e),ed({}),en({}),eL(!1)}},e0=async()=>{try{let e=await k.ZP.get(p.Ve);e&&(V(e.allSlurmGPUs||[]),J(e.perClusterSlurmGPUs||[]),X(e.perNodeSlurmGPUs||[])),eI(!0),eD(!1)}catch(e){console.error("Error in fetchSlurmData:",e),V([]),J([]),X([]),eI(!0),eD(!1)}},e1=async e=>{try{let t=e?await (0,p.oD)():await k.ZP.get(p.oD);t?(ee(t.clouds||[]),es(t.totalClouds||0),er(t.enabledClouds||0),v(!0)):null===t&&(ee([]),es(0),er(0),v(!0)),n(!1)}catch(e){console.error("Error in fetchCloudData:",e),ee([]),es(0),er(0),v(!0),n(!1)}},e2=async e=>{try{let t=e?await (0,N.It)():await k.ZP.get(N.It);ev(t),eP(!1)}catch(e){console.error("Failed to fetch SSH Node Pools:",e),ev({}),eP(!1)}},e5=(e,t)=>{e_({name:e,config:t}),eS(!0)},e3=async e=>{try{await (0,N.MV)(e),await e2(),e$(null),w.push("/infra")}catch(e){throw console.error("Failed to delete SSH Node Pool:",e),e}},e6=async e=>{try{await (0,N._x)(e)}catch(e){throw console.error("Failed to deploy SSH Node Pool:",e),e}},e4=async(e,t)=>{eP(!0);try{let s={...eb};s[e]=t,await (0,N.Ri)(s),await e2(),eS(!1)}catch(e){console.error("Failed to save SSH Node Pool:",e),alert("Failed to save SSH Node Pool. Please try again.")}finally{eP(!1)}};(0,r.useEffect)(()=>{m.current=eJ},[eJ]),(0,r.useEffect)(()=>{let e={};Z.forEach(t=>{let s=(0,g.y)(t.gpu_name);s in e?(e[s].gpu_total+=t.gpu_total||0,e[s].gpu_free+=t.gpu_free||0,e[s].gpu_not_ready+=t.gpu_not_ready||0):e[s]={gpu_name:s,gpu_total:t.gpu_total||0,gpu_free:t.gpu_free||0,gpu_not_ready:t.gpu_not_ready||0}}),E(Object.values(e))},[Z]),(0,r.useEffect)(()=>{(async()=>{await P.ZP.preloadForPage("infra"),await eJ({showLoadingIndicators:!0})})()},[]),(0,r.useEffect)(()=>{let e=!0,t=setInterval(()=>{e&&m.current&&"visible"===window.document.visibilityState&&m.current({showLoadingIndicators:!1})},H);return()=>{e=!1,clearInterval(t)}},[]),(0,r.useEffect)(()=>()=>{x(!1),v(!1),eP(!1),eD(!1),eI(!1),c(!0),eF(!1),eL(!1)},[]);let e7=async()=>{k.ZP.invalidate(y.getClusters),k.ZP.invalidate(j.getManagedJobs,[{allUsers:!0,skipFinished:!0}]),k.ZP.invalidate(p.CI),k.ZP.invalidate(p.Xg),k.ZP.invalidate(p.oD),k.ZP.invalidate(p.ef,[!1]),k.ZP.invalidate(N.It),k.ZP.invalidate(p.Ve),ez(e=>e+1),m.current&&await m.current({showLoadingIndicators:!0,forceRefresh:!0})};(0,r.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"r"===e.key&&(e.preventDefault(),e7())};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[]),(U||[]).length,(U||[]).reduce((e,t)=>e+t.gpu_total,0),(U||[]).reduce((e,t)=>e+t.gpu_free,0);let e8=r.useMemo(()=>Z?Z.reduce((e,t)=>{let{context:s}=t;return e[s]||(e[s]=[]),e[s].push(t),e},{}):{},[Z]),e9=r.useCallback(e=>"all"===ef?e:e.filter(e=>(em[e]||[]).includes(ef)),[ef,em]),te=r.useMemo(()=>{if(e&&0===Object.keys(eg).length)return null;if("all"===ef){let e=new Set;return Object.values(eg).forEach(t=>{t.clouds&&Array.isArray(t.clouds)&&t.clouds.forEach(t=>{let s=t.toLowerCase().split("/")[0];e.add(s)})}),Array.from(e)}{let e=eg[ef];if(!e||!e.clouds||!Array.isArray(e.clouds))return[];let t=new Set;return e.clouds.forEach(e=>{let s=e.toLowerCase().split("/")[0];t.add(s)}),Array.from(t)}},[ef,eg,e]),tt=r.useMemo(()=>Y&&0!==Y.length?null===te?Y:Y.filter(e=>te.includes(e.name.toLowerCase())):[],[Y,te]),ts=r.useMemo(()=>tt.length,[tt]),ta=r.useMemo(()=>S&&Array.isArray(S)?e9(S.filter(e=>e.startsWith("ssh-"))):[],[S,e9]),tr=r.useMemo(()=>S&&Array.isArray(S)?e9(S.filter(e=>!e.startsWith("ssh-"))):[],[S,e9]),tl=r.useMemo(()=>{if(!Z||!U)return[];let e=new Set;return Z.forEach(t=>{t.context.startsWith("ssh-")&&e.add((0,g.y)(t.gpu_name))}),U.filter(t=>e.has(t.gpu_name))},[U,Z]),tn=r.useMemo(()=>{if(!Z||!U)return[];let e=new Set;return Z.forEach(t=>{t.context.startsWith("ssh-")||e.add((0,g.y)(t.gpu_name))}),U.filter(t=>e.has(t.gpu_name))},[U,Z]),to=r.useMemo(()=>$&&Array.isArray($)?[...new Set($.map(e=>e.cluster))].sort():[],[$]),tc=r.useMemo(()=>$?$.reduce((e,t)=>{let{cluster:s}=t;return e[s]||(e[s]=[]),e[s].push(t),e},{}):{},[$]),ti=r.useMemo(()=>Q?Q.reduce((e,t)=>{let{cluster:s}=t;return e[s]||(e[s]=[]),e[s].push(t),e},{}):{},[Q]),td=r.useMemo(()=>T?T.reduce((e,t)=>{let{context:s}=t;return e[s]||(e[s]=[]),e[s].push(t),e},{}):{},[T]),tm=(()=>{if(!b||!h||e||s)return!1;let t=0===ta.length,a=0===tr.length,r=0===to.length;return 0===ea&&t&&a&&r})();(0,r.useEffect)(()=>{w.isReady&&w.query.context&&e$(decodeURIComponent(Array.isArray(w.query.context)?w.query.context[0]:w.query.context))},[w.isReady,w.query.context]);let tu=e=>{e$(e);let t="/infra/".concat(encodeURIComponent(e));w.asPath!==t&&w.push(t)},th=t=>{let s=to.includes(t),r=s?tc[t]||[]:e8[t]||[],n=s?ti[t]||[]:td[t]||[];if(e&&!h)return(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center h-64",children:[(0,a.jsx)(l.Z,{size:32,className:"mb-4"}),(0,a.jsx)("span",{className:"text-gray-500 text-lg",children:"Loading Context..."})]});if(t.startsWith("ssh-")){let e=t.replace(/^ssh-/,"");return(0,a.jsx)(q,{poolName:e,gpusInContext:r,nodesInContext:n,handleDeploySSHPool:e6,handleEditSSHPool:e5,handleDeleteSSHPool:e3,poolConfig:eb[e]})}return(0,a.jsx)(G,{contextName:t,gpusInContext:r,nodesInContext:n,gpuMetricsRefreshTrigger:eq,isSlurm:s})},tx=()=>o&&s&&(!Y||0===Y.length)?(0,a.jsx)("div",{className:"rounded-lg border bg-card text-card-foreground shadow-sm mb-6",children:(0,a.jsxs)("div",{className:"p-5",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold mb-4",children:"Cloud"}),(0,a.jsxs)("div",{className:"flex items-center justify-center py-6",children:[(0,a.jsx)(l.Z,{size:24,className:"mr-3"}),(0,a.jsx)("span",{className:"text-gray-500",children:"Loading Cloud..."})]})]})}):(0,a.jsx)("div",{className:"rounded-lg border bg-card text-card-foreground shadow-sm mb-6",children:(0,a.jsxs)("div",{className:"p-5",children:[(0,a.jsxs)("div",{className:"flex items-center mb-4",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold",children:"Cloud"}),(0,a.jsxs)("span",{className:"ml-2 px-2 py-0.5 bg-blue-100 text-blue-800 rounded-full text-xs font-medium",children:[ts," of ",et," enabled"]})]}),tt&&0!==tt.length?(0,a.jsx)("div",{className:"overflow-x-auto rounded-md border shadow-sm bg-card ".concat(!o&&(eA||eM)?"infra-table-refreshing":""),children:(0,a.jsxs)("table",{className:"min-w-full text-sm",children:[(0,a.jsx)("thead",{className:"bg-gray-50",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-32",children:"Cloud"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-24",children:"Clusters"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-24",children:"Jobs"})]})}),(0,a.jsx)("tbody",{className:"bg-card divide-y divide-gray-200",children:tt.map(e=>{var t,s;let r=null!==(t=el[e.name])&&void 0!==t?t:e.clusters,l=null!==(s=eo[e.name])&&void 0!==s?s:e.jobs;return(0,a.jsxs)("tr",{className:"hover:bg-muted/50",children:[(0,a.jsx)("td",{className:"p-3 font-medium text-gray-700",children:e.name}),(0,a.jsx)("td",{className:"p-3",children:eA?(0,a.jsx)(L,{}):(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:null!=r?r:0})}),(0,a.jsx)("td",{className:"p-3",children:eM?(0,a.jsx)(L,{}):(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:null!=l?l:0})})]},e.name)})})]})}):(0,a.jsx)("p",{className:"text-sm text-gray-500",children:"all"===ef?"No enabled clouds available.":'No enabled clouds for workspace "'.concat(ef,'".')})]})}),tg=()=>(0,a.jsx)(R,{title:"SSH Node Pool",isLoading:e,isDataLoaded:h,contexts:ta,gpus:tl,groupedPerContextGPUs:e8,groupedPerNodeGPUs:td,handleContextClick:tu,contextStats:ei,jobsData:eH,isJobsDataLoading:eM,isClusterDataLoading:eA,isSSH:!0,contextWorkspaceMap:em,contextErrors:eh,gpuMetricsRefreshTrigger:eq,loadedContexts:W,isInitialLoad:o,actionButton:null}),tp=()=>(0,a.jsx)(R,{title:"Kubernetes",isLoading:e,isDataLoaded:h,contexts:tr,gpus:tn,groupedPerContextGPUs:e8,groupedPerNodeGPUs:td,handleContextClick:tu,contextStats:ei,jobsData:eH,isJobsDataLoading:eM,isClusterDataLoading:eA,isSSH:!1,contextWorkspaceMap:em,contextErrors:eh,gpuMetricsRefreshTrigger:eq,loadedContexts:W,isInitialLoad:o}),tf=()=>(0,a.jsx)(R,{title:"Slurm",isLoading:eU,isDataLoaded:eE,contexts:to,gpus:K,groupedPerContextGPUs:tc,groupedPerNodeGPUs:ti,handleContextClick:tu,contextStats:ei,jobsData:eH,isJobsDataLoading:eM,isClusterDataLoading:eA,isSSH:!1,isSlurm:!0,contextWorkspaceMap:{},isInitialLoad:o}),ty=S.length>0&&W.size<S.length,tj=e||s||eU||eM||eA||ty||eO;return(0,r.useEffect)(()=>{eT.current&&!tj&&eG(new Date),eT.current=tj},[tj]),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-4 h-5",children:[(0,a.jsxs)("div",{className:"text-base flex items-center",children:[(0,a.jsx)(I(),{href:"/infra",className:"text-sky-blue hover:underline ".concat(eV?"":"cursor-default"),children:"Infrastructure"}),eV&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"mx-2 text-gray-500",children:"›"}),eV.startsWith("ssh-")?(0,a.jsx)(I(),{href:"/infra",className:"text-sky-blue hover:underline cursor-pointer",children:"SSH Node Pool"}):to.includes(eV)?(0,a.jsx)(I(),{href:"/infra",className:"text-sky-blue hover:underline cursor-pointer",children:"Slurm"}):(0,a.jsx)(I(),{href:"/infra",className:"text-sky-blue hover:underline cursor-pointer",children:"Kubernetes"}),(0,a.jsx)("span",{className:"mx-2 text-gray-500",children:"›"}),(0,a.jsx)("span",{className:"text-sky-blue",children:eV.startsWith("ssh-")?eV.replace(/^ssh-/,""):eV})]})]}),(0,a.jsxs)("div",{className:"flex items-center",children:[ej.length>0&&(0,a.jsxs)("div",{className:"flex items-center mr-4",children:[(0,a.jsx)("label",{className:"text-sm font-medium text-gray-700 mr-2",children:"Workspace:"}),(0,a.jsxs)(F.Ph,{value:ef,onValueChange:ey,children:[(0,a.jsx)(F.i4,{className:"w-40 h-8 text-sm",children:(0,a.jsx)(F.ki,{})}),(0,a.jsxs)(F.Bw,{children:[(0,a.jsx)(F.Ql,{value:"all",children:"All Workspaces"}),ej.map(e=>(0,a.jsx)(F.Ql,{value:e,children:e},e))]})]})]}),tj&&(0,a.jsxs)("div",{className:"flex items-center mr-2",children:[(0,a.jsx)(l.Z,{size:15,className:"mt-0"}),(0,a.jsx)("span",{className:"ml-2 text-gray-500",children:"Loading..."})]}),!tj&&eR&&(0,a.jsx)(M.$3,{timestamp:eR,className:"mr-2"}),(0,a.jsxs)("button",{onClick:e7,disabled:tj,className:"text-sky-blue hover:text-sky-blue-bright flex items-center",children:[(0,a.jsx)(i.Z,{className:"h-4 w-4 mr-1.5"}),!u&&"Refresh"]})]})]}),(()=>{if(eV)return e&&!h?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center h-64",children:[(0,a.jsx)(l.Z,{size:32,className:"mb-4"}),(0,a.jsx)("span",{className:"text-gray-500 text-lg",children:"Loading Context..."})]}):th(eV);let t=[];tm&&t.push({name:"Infrastructure Hint",render:()=>(0,a.jsx)(z,{}),hasActivity:!1,priority:0}),t.push({name:"Kubernetes",render:tp,hasActivity:tr.length>0,priority:1}),t.push({name:"Slurm",render:tf,hasActivity:to.length>0,priority:2}),t.push({name:"Cloud",render:tx,hasActivity:ea>0,priority:3}),t.push({name:"SSH Node Pool",render:tg,hasActivity:ta.length>0,priority:4});let s=t.sort((e,t)=>e.hasActivity!==t.hasActivity?e.hasActivity?-1:1:e.priority-t.priority);return(0,a.jsx)(a.Fragment,{children:s.map((e,t)=>(0,a.jsx)(r.Fragment,{children:e.render()},t))})})(),(0,a.jsx)(_,{isOpen:ew,onClose:()=>eS(!1),onSave:e4,poolData:eC,isLoading:ek})]})}}}]);