"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3495],{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 Z},GPUs:function(){return q},InfrastructureSection:function(){return R}});var a=s(85893),r=s(67294),l=s(55739);s(9353);var n=s(96122),o=s(26409),i=s(98418),c=s(13626),d=s(23001),m=s(17853);function u(e){return null==e?"-":Math.round(e).toString()}function x(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 h=s(30017),g=s(32045);s(93225);var p=s(17324),f=s(23266),y=s(68969);s(47145);var j=s(29326),N=s(50326),b=s(30803),v=s(42557),w=s(36185),S=s(69123);function _(e){let{isOpen:t,onClose:s,onSave:n,poolData:o=null,isLoading:i=!1}=e,[c,d]=(0,r.useState)(""),[m,u]=(0,r.useState)(""),[x,h]=(0,r.useState)("ubuntu"),[g,p]=(0,r.useState)(null),[f,y]=(0,r.useState)(""),[_,C]=(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")),h((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(""),h("ubuntu"),p(null),y("");C({})},[k,o]);let P=()=>{let e={};return c.trim()||(e.poolName="Pool name is required"),m.trim()||(e.hosts="At least one host is required"),x.trim()||(e.sshUser="SSH user is required"),g||f||(e.auth="Either SSH key file or password is required"),C(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:x};try{if(g){let t=g.name;await (0,j.hY)(t,g),e.identity_file="~/.sky/ssh_keys/".concat(t)}f&&(e.password=f),n(c,e)}catch(e){console.error("Failed to upload SSH key:",e),C({..._,keyUpload:"Failed to upload SSH key"})}},D=()=>{i||s()};return(0,a.jsx)(N.Vq,{open:t,onOpenChange:D,children:(0,a.jsxs)(N.cZ,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[(0,a.jsx)(N.fK,{children:(0,a.jsx)(N.$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)(w._,{htmlFor:"poolName",children:"Pool Name"}),(0,a.jsx)(v.I,{id:"poolName",placeholder:"my-ssh-cluster",value:c,onChange:e=>d(e.target.value),disabled:k,className:"placeholder:text-gray-500 ".concat(_.poolName?"border-red-500":"")}),_.poolName&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:_.poolName})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(w._,{htmlFor:"hosts",children:"Hosts (one per line)"}),(0,a.jsx)(S.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(_.hosts?"border-red-500":"")}),_.hosts&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:_.hosts})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(w._,{htmlFor:"sshUser",children:"SSH User"}),(0,a.jsx)(v.I,{id:"sshUser",placeholder:"ubuntu",value:x,onChange:e=>h(e.target.value),className:"placeholder:text-gray-500 ".concat(_.sshUser?"border-red-500":"")}),_.sshUser&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:_.sshUser})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(w._,{htmlFor:"keyFile",children:"SSH Private Key File"}),(0,a.jsx)(v.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"}),_.keyUpload&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:_.keyUpload})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(w._,{htmlFor:"password",children:"Password (optional, if sudo requires a password)"}),(0,a.jsx)(v.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"})]}),_.auth&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:_.auth})]}),(0,a.jsxs)(N.cN,{children:[(0,a.jsx)(b.z,{variant:"outline",onClick:D,disabled:i,children:"Cancel"}),(0,a.jsx)(b.z,{onClick:U,disabled:i,className:"bg-blue-600 hover:bg-blue-700 text-white disabled:bg-gray-300 disabled:text-gray-500",children:i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(l.Z,{size:16,className:"mr-2"}),"Saving..."]}):k?"Update Pool":"Create Pool"})]})]})})}var C=s(6378),k=s(36856),P=s(51214),U=s(11163),D=s(41664),I=s.n(D),E=s(470);s(37673);var M=s(62935);let F=P.nb.REFRESH_INTERVAL,A=P.MO.NAME_TRUNCATE_LENGTH,H=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,i=Math.max(0,l-o-n),c="".concat(n," not ready"),d="".concat(i," used"),m="".concat(o," free"),u=l>0?e=>e/l*100:()=>0,x=u(n),h=u(i),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:[x>0&&(0,a.jsx)("div",{style:{width:"".concat(x,"%"),fontSize:"clamp(8px, 1.2vw, 12px)"},title:c,className:"bg-gray-400 h-full flex items-center justify-center text-white font-medium overflow-hidden whitespace-nowrap px-1",children:x>15&&c}),h>0&&(0,a.jsx)("div",{style:{width:"".concat(h,"%"),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:h>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:i,groupedPerContextGPUs:c,groupedPerNodeGPUs:d,handleContextClick:m,contextStats:g={},jobsData:p={},isJobsDataLoading:f=!0,isClusterDataLoading:y=!0,isSSH:j=!1,isSlurm:N=!1,actionButton:b=null,contextWorkspaceMap:v={},contextErrors:w={},gpuMetricsRefreshTrigger:S=0,loadedContexts:_=new Set,isInitialLoad:C=!0}=e,k=o||[];if(r&&0===k.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}),b]}),(0,a.jsxs)("p",{className:"text-sm text-gray-500",children:["No ",t," found or ",t," is not configured."]})]})});if(C&&s&&!r&&0===k.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 P=!C&&(s||!(N||j)&&k.length>0&&!k.every(e=>_.has(e)));return k.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:[k.length," ",1===k.length?j?"pool":N?"cluster":"context":j?"pools":N?"clusters":"contexts"]})]}),b]}),(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(P?"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-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"}),!N&&(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/8",children:"CPU"}),!N&&(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 ".concat(k.length>5?"max-h-[250px] overflow-y-auto block":""),children:k.map(e=>{var t;let r=c[e]||[],l=d[e]||[],o=r.reduce((e,t)=>e+(t.gpu_total||0),0),i=(0,h.G)(e,{isSSH:j,isSlurm:N}),b=g[i]||{clusters:0,jobs:0},S=N||j?!s:_.has(e),k=N||j?!s:_.has(e),P=0===r.length?null:Object.keys(r.reduce((e,t)=>(e[t.gpu_name]=(e[t.gpu_name]||0)+(t.gpu_total||0),e),{})).join(", "),U=x(l,"cpu_count",!0),D=x(l,"memory_gb",!0),I=j?e.replace(/^ssh-/,""):e,M=v[e]||[],F=M.length>1?" (workspaces: ".concat(M.join(", "),")"):"";return(0,a.jsxs)("tr",{className:"hover:bg-muted/50 ".concat(S||C?"":"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)(E.Md,{content:"".concat(I).concat(F),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>A?"".concat(I.substring(0,Math.floor((A-3)/2)),"...").concat(I.substring(I.length-Math.ceil((A-3)/2))):I,F&&(0,a.jsx)("span",{className:"text-xs text-gray-500 ml-1",children:F})]})}),w[e]&&(0,a.jsx)(E.Md,{content:"Context unreachable: ".concat(w[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: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:b.clusters})}),(0,a.jsx)("td",{className:"p-3",children:f?(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=p[i])||void 0===t?void 0:t.jobs)||0})}),(0,a.jsx)("td",{className:"p-3",children:k?(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,{})}),!N&&(0,a.jsx)("td",{className:"p-3",children:k?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:u(U)}):(0,a.jsx)(L,{})}),!N&&(0,a.jsx)("td",{className:"p-3",children:k?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:null==D?"-":"".concat(Math.round(D)," GB")}):(0,a.jsx)(L,{})}),(0,a.jsx)("td",{className:"p-3",children:S?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:P||"-"}):(0,a.jsx)(L,{})}),(0,a.jsx)("td",{className:"p-3",children:S?(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)})})]})})}),i&&i.length>0&&(0,a.jsx)("div",{children:(0,a.jsx)("div",{className:"overflow-x-auto rounded-md border shadow-sm bg-card ".concat(P?"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.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:[i.reduce((e,t)=>e+t.gpu_free,0)," ","of"," ",i.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 ".concat(i.length>5?"max-h-[250px] overflow-y-auto block":""),children:i.map(e=>{let t=c?Object.values(c).flat().filter(t=>{if(t.gpu_name!==e.gpu_name)return!1;if(N)return!0;let s=t.context||t.cluster;return!!s&&(j?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: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)(H,{gpu:e,heightClass:"h-5",wrapperClassName:"flex-1 min-w-[100px] w-full"})})})]},e.gpu_name)})})]})})})]})]})}):null}function Z(e){let{contextName:t,gpusInContext:s,nodesInContext:n,gpuMetricsRefreshTrigger:o=0,isSlurm:i=!1}=e,c=t.startsWith("ssh-"),[d,x]=(0,r.useState)([]),[h,g]=(0,r.useState)("$__all"),[p,f]=(0,r.useState)({from:"now-1h",to:"now"}),[y,j]=(0,r.useState)(!1),[N,b]=(0,r.useState)(!1);(0,r.useEffect)(()=>{(async()=>{b(await (0,m.TO)())})()},[]);let v=(0,r.useCallback)(async()=>{if(N){j(!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();x(t),console.log("Successfully fetched hosts for cluster ".concat(s||"in-cluster",":"),t)}else console.log("No nodes found for this cluster"),x([])}else console.log("HTTP ".concat(t.status," from ").concat(r,": ").concat(t.statusText)),x([])}catch(e){console.log("Failed to fetch from ".concat(r,":"),e),x([])}}catch(e){console.error("Error fetching available hosts:",e),x([])}finally{j(!1)}}},[N,t]);(0,r.useEffect)(()=>{N&&n&&n.length>0&&v()},[n,N,v]);let w=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(h),"&var-gpu=$__all&var-cluster=").concat(encodeURIComponent(a),"&refresh=5s&theme=light&from=").concat(encodeURIComponent(p.from),"&to=").concat(encodeURIComponent(p.to),"&panelId=").concat(e,"&__feature.dashboardSceneSolo")},S=e=>{f({"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:[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)(H,{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"}),!i&&(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||[],c=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&&(c=t.join(", "))}let d=n.length>0||c?n.join(", "):"Healthy",m=0===n.length&&!c;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}),!i&&(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: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}),c&&(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:c})]})})]},"".concat(e.node_name,"-").concat(t))})})]})}),N&&s&&s.length>0&&!c&&!i&&(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:h,onChange:e=>{g(e.target.value)},disabled:y,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))]}),y&&(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:()=>S(e.value),className:"px-2 py-1 text-xs font-medium rounded border transition-colors ".concat(p.from==="now-".concat(e.value)&&"now"===p.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"===h?"All nodes":h," ","• Time: ",p.from," to ",p.to,d.length>0&&(0,a.jsxs)("span",{children:[" ","• ",d.length," nodes available"]})]}):(0,a.jsxs)(a.Fragment,{children:["Cluster:"," ",c?t.replace(/^ssh-/,""):t," ","• Time: ",p.from," to ",p.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:w("6"),width:"100%",height:"400",frameBorder:"0",title:"GPU Utilization",className:"rounded"},"gpu-util-".concat(h,"-").concat(p.from,"-").concat(p.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:w("18"),width:"100%",height:"400",frameBorder:"0",title:"GPU Memory",className:"rounded"},"gpu-memory-".concat(h,"-").concat(p.from,"-").concat(p.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:w("10"),width:"100%",height:"400",frameBorder:"0",title:"GPU Power Consumption",className:"rounded"},"gpu-power-".concat(h,"-").concat(p.from,"-").concat(p.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:w("12"),width:"100%",height:"400",frameBorder:"0",title:"GPU Temperature",className:"rounded"},"gpu-temp-".concat(h,"-").concat(p.from,"-").concat(p.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:w("22"),width:"100%",height:"400",frameBorder:"0",title:"CPU Utilization",className:"rounded"},"cpu-util-".concat(h,"-").concat(p.from,"-").concat(p.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:w("21"),width:"100%",height:"400",frameBorder:"0",title:"Memory Utilization",className:"rounded"},"memory-util-".concat(h,"-").concat(p.from,"-").concat(p.to,"-").concat(o||0))})})]})]})]})})})}function G(e){var t;let{poolName:s,gpusInContext:n,nodesInContext:c,handleDeploySSHPool:d,handleEditSSHPool:m,handleDeleteSSHPool:u,poolConfig:x}=e,[h,g]=(0,r.useState)(null),[p,f]=(0,r.useState)(!0),[y,v]=(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,j.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:_}=(()=>{if(!h)return{deployDisabled:!0};let e=h.status;return"Ready"===e?{deployDisabled:!0}:"Error"===e?{deployDisabled:!0}:{deployDisabled:!1}})(),C=async()=>{v({...y,loading:!0});try{if("deploy"===y.action){v({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,j.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,j.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){v({isOpen:!1,action:null,loading:!1}),S({isOpen:!0,logs:"",isStreaming:!0,deploymentComplete:!1,deploymentSuccess:!1,requestId:null});try{let e=(await (0,j.ez)(s)).request_id;S(t=>({...t,requestId:e})),e&&await (0,j.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),v({...y,loading:!1})}},k=()=>{v({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,j.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(_?"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:_?void 0:()=>{v({isOpen:!0,action:"deploy",loading:!1})},disabled:_,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:()=>{v({isOpen:!0,action:"delete",loading:!1})},children:[(0,a.jsx)(i.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:c?c.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..."})]}):h?(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:h.status,reason:h.reason}):(0,a.jsx)("span",{className:"text-gray-500",children:"Unknown"})})]})]})})]})}),(0,a.jsx)(Z,{contextName:"ssh-".concat(s),gpusInContext:n,nodesInContext:c}),(0,a.jsx)(N.Vq,{open:y.isOpen,onOpenChange:k,children:(0,a.jsxs)(N.cZ,{className:"sm:max-w-md",children:[(0,a.jsxs)(N.fK,{className:"",children:[(0,a.jsx)(N.$N,{className:"",children:U.title}),(0,a.jsx)(N.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)(N.cN,{className:"",children:[(0,a.jsx)(b.z,{variant:"outline",onClick:k,disabled:y.loading,className:"",children:"Cancel"}),(0,a.jsx)(b.z,{onClick:C,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)(N.Vq,{open:w.isOpen,onOpenChange:w.isStreaming?void 0:P,children:(0,a.jsxs)(N.cZ,{className:"sm:max-w-4xl max-h-[80vh]",children:[(0,a.jsxs)(N.fK,{className:"",children:[(0,a.jsxs)(N.$N,{className:"",children:["Deploying SSH Node Pool: ",s]}),(0,a.jsx)(N.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)(N.cN,{className:"",children:(0,a.jsx)(b.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 O(){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 q(){let[e,t]=(0,r.useState)(!0),[s,n]=(0,r.useState)(!0),[o,i]=(0,r.useState)(!0),m=r.useRef(null),u=(0,d.X)(),[x,h]=(0,r.useState)(!1),[N,b]=(0,r.useState)(!1),v=(0,U.useRouter)(),[w,S]=(0,r.useState)([]),[P,D]=(0,r.useState)([]),[A,H]=(0,r.useState)([]),[q,T]=(0,r.useState)([]),[z,W]=(0,r.useState)(new Set),[B,V]=(0,r.useState)([]),[$,K]=(0,r.useState)([]),[J,Q]=(0,r.useState)([]),[X,Y]=(0,r.useState)([]),[ee,et]=(0,r.useState)(0),[es,ea]=(0,r.useState)(0),[er,el]=(0,r.useState)({}),[en,eo]=(0,r.useState)({}),[ei,ec]=(0,r.useState)({}),[ed,em]=(0,r.useState)({}),[eu,ex]=(0,r.useState)({}),[eh,eg]=(0,r.useState)({}),[ep,ef]=(0,r.useState)("all"),[ey,ej]=(0,r.useState)([]),[eN,eb]=(0,r.useState)({}),[ev,ew]=(0,r.useState)(!1),[eS,e_]=(0,r.useState)(null),[eC,ek]=(0,r.useState)(!1),[eP,eU]=(0,r.useState)(!0),[eD,eI]=(0,r.useState)(!1),[eE,eM]=(0,r.useState)(!0),[eF,eA]=(0,r.useState)({}),[eH,eL]=(0,r.useState)(!0),[eR,eZ]=(0,r.useState)(null),[eG,eO]=(0,r.useState)(0),eq=r.useRef(!0),[eT,ez]=(0,r.useState)(!1),eW=r.useRef(0),eB=r.useRef(!1),[eV,e$]=(0,r.useState)(null),eK=r.useCallback(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{showLoadingIndicators:!0},{showLoadingIndicators:s=!0,forceRefresh:a=!1}=e;ez(!0),eB.current=!1,s&&(t(!0),n(!0),ek(!0),eU(!0),eM(!0),eL(!0));try{let e=a?(0,p.LD)().catch(e=>{console.error("Error during sky check refresh:",e)}):Promise.resolve();await Promise.all([e,eJ(a,s),e1(a),e0(a),eQ(),eX(),eY()]),eB.current=!0,0===eW.current&&ez(!1)}catch(e){console.error("Error in fetchData:",e),eg({}),S([]),D([]),H([]),T([]),ec({}),em({}),ex({}),ej([]),h(!0),t(!1),eL(!1),Y([]),et(0),ea(0),el({}),eo({}),b(!0),eb({}),ek(!1),eU(!1),V([]),K([]),Q([]),eA({}),eM(!1),eB.current=!0,0===eW.current&&ez(!1)}finally{s&&(t(!1),n(!1),ek(!1),eU(!1),eM(!1),eL(!1)),o&&s&&i(!1)}},[o]),eJ=async function(e){let s=!(arguments.length>1)||void 0===arguments[1]||arguments[1];try{let a=e?await (0,g.CI)():await C.ZP.get(g.CI);if(!a){eg({}),S([]),D([]),H([]),T([]),em({}),ex({}),ej([]),h(!0),t(!1);return}let{workspaces:r,allContextNames:l,contextWorkspaceMap:n}=a;eg(r||{}),S(l||[]),em(n||{});let o=Object.keys(r||{});ej(o.sort()),h(!0),t(!1);let i=(l||[]).filter(e=>e&&"string"==typeof e);if(0===i.length){s&&(D([]),H([]),T([]),ex({}),W(new Set));return}s&&(W(new Set),ex({})),eW.current=i.length,i.forEach(t=>{(e?(0,g.UU)(t):C.ZP.get(g.UU,[t])).then(e=>{W(e=>new Set([...e,t])),H(s=>[...s.filter(e=>e.context!==t),...e.perContextGPUs]),T(s=>[...s.filter(e=>e.context!==t),...e.perNodeGPUs]),e.error&&ex(s=>({...s,[t]:e.error}))}).catch(e=>{W(e=>new Set([...e,t])),ex(s=>({...s,[t]:e.message||"Failed to load GPU data"}))}).finally(()=>{eW.current--,0===eW.current&&eB.current&&ez(!1)})})}catch(e){console.error("Error in fetchKubernetesData:",e),eg({}),S([]),D([]),H([]),T([]),em({}),ex({}),ej([]),h(!0),t(!1)}},eQ=async()=>{try{let e=await C.ZP.get(y.getManagedJobs,[{allUsers:!0,skipFinished:!0}]),t=(null==e?void 0:e.jobs)||[];eA(await (0,g.R8)(t));let s={};t.forEach(e=>{e.cloud&&(s[e.cloud]=(s[e.cloud]||0)+1)}),eo(s),eM(!1)}catch(e){console.error("Error in fetchManagedJobsData:",e),eA({}),eo({}),eM(!1)}},eX=async()=>{try{let e=await C.ZP.get(f.getClusters)||[],t=await (0,g.F5)(e);ec(t);let s={};e.forEach(e=>{e.cloud&&(s[e.cloud]=(s[e.cloud]||0)+1)}),el(s),eL(!1)}catch(e){console.error("Error in fetchClusterStatsData:",e),ec({}),el({}),eL(!1)}},eY=async()=>{try{let e=await C.ZP.get(g.Ve);e&&(V(e.allSlurmGPUs||[]),K(e.perClusterSlurmGPUs||[]),Q(e.perNodeSlurmGPUs||[])),eI(!0),eU(!1)}catch(e){console.error("Error in fetchSlurmData:",e),V([]),K([]),Q([]),eI(!0),eU(!1)}},e0=async e=>{try{let t=e?await (0,g.oD)():await C.ZP.get(g.oD);t?(Y(t.clouds||[]),et(t.totalClouds||0),ea(t.enabledClouds||0),b(!0)):null===t&&(Y([]),et(0),ea(0),b(!0)),n(!1)}catch(e){console.error("Error in fetchCloudData:",e),Y([]),et(0),ea(0),b(!0),n(!1)}},e1=async e=>{try{let t=e?await (0,j.It)():await C.ZP.get(j.It);eb(t),ek(!1)}catch(e){console.error("Failed to fetch SSH Node Pools:",e),eb({}),ek(!1)}},e2=(e,t)=>{e_({name:e,config:t}),ew(!0)},e5=async e=>{try{await (0,j.MV)(e),await e1(),e$(null),v.push("/infra")}catch(e){throw console.error("Failed to delete SSH Node Pool:",e),e}},e3=async e=>{try{await (0,j._x)(e)}catch(e){throw console.error("Failed to deploy SSH Node Pool:",e),e}},e6=async(e,t)=>{ek(!0);try{let s={...eN};s[e]=t,await (0,j.Ri)(s),await e1(),ew(!1)}catch(e){console.error("Failed to save SSH Node Pool:",e),alert("Failed to save SSH Node Pool. Please try again.")}finally{ek(!1)}};(0,r.useEffect)(()=>{m.current=eK},[eK]),(0,r.useEffect)(()=>{let e={};A.forEach(t=>{t.gpu_name in e?(e[t.gpu_name].gpu_total+=t.gpu_total||0,e[t.gpu_name].gpu_free+=t.gpu_free||0,e[t.gpu_name].gpu_not_ready+=t.gpu_not_ready||0):e[t.gpu_name]={gpu_name:t.gpu_name,gpu_total:t.gpu_total||0,gpu_free:t.gpu_free||0,gpu_not_ready:t.gpu_not_ready||0}}),D(Object.values(e))},[A]),(0,r.useEffect)(()=>{(async()=>{await k.ZP.preloadForPage("infra"),await eK({showLoadingIndicators:!0})})()},[]),(0,r.useEffect)(()=>{let e=!0,t=setInterval(()=>{e&&m.current&&"visible"===window.document.visibilityState&&m.current({showLoadingIndicators:!1})},F);return()=>{e=!1,clearInterval(t)}},[]),(0,r.useEffect)(()=>()=>{h(!1),b(!1),ek(!1),eU(!1),eI(!1),i(!0),eM(!1),eL(!1)},[]);let e4=async()=>{C.ZP.invalidate(f.getClusters),C.ZP.invalidate(y.getManagedJobs,[{allUsers:!0,skipFinished:!0}]),C.ZP.invalidate(g.CI),C.ZP.invalidate(g.Xg),C.ZP.invalidate(g.oD),C.ZP.invalidate(g.ef,[!1]),C.ZP.invalidate(j.It),C.ZP.invalidate(g.Ve),eO(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(),e4())};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[]),(P||[]).length,(P||[]).reduce((e,t)=>e+t.gpu_total,0),(P||[]).reduce((e,t)=>e+t.gpu_free,0);let e8=r.useMemo(()=>A?A.reduce((e,t)=>{let{context:s}=t;return e[s]||(e[s]=[]),e[s].push(t),e},{}):{},[A]),e7=r.useCallback(e=>"all"===ep?e:e.filter(e=>(ed[e]||[]).includes(ep)),[ep,ed]),e9=r.useMemo(()=>{if(e&&0===Object.keys(eh).length)return null;if("all"===ep){let e=new Set;return Object.values(eh).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=eh[ep];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)}},[ep,eh,e]),te=r.useMemo(()=>X&&0!==X.length?null===e9?X:X.filter(e=>e9.includes(e.name.toLowerCase())):[],[X,e9]),tt=r.useMemo(()=>te.length,[te]),ts=r.useMemo(()=>w&&Array.isArray(w)?e7(w.filter(e=>e.startsWith("ssh-"))):[],[w,e7]),ta=r.useMemo(()=>w&&Array.isArray(w)?e7(w.filter(e=>!e.startsWith("ssh-"))):[],[w,e7]),tr=r.useMemo(()=>{if(!A||!P)return[];let e=new Set;return A.forEach(t=>{t.context.startsWith("ssh-")&&e.add(t.gpu_name)}),P.filter(t=>e.has(t.gpu_name))},[P,A]),tl=r.useMemo(()=>{if(!A||!P)return[];let e=new Set;return A.forEach(t=>{t.context.startsWith("ssh-")||e.add(t.gpu_name)}),P.filter(t=>e.has(t.gpu_name))},[P,A]),tn=r.useMemo(()=>$&&Array.isArray($)?[...new Set($.map(e=>e.cluster))].sort():[],[$]),to=r.useMemo(()=>$?$.reduce((e,t)=>{let{cluster:s}=t;return e[s]||(e[s]=[]),e[s].push(t),e},{}):{},[$]),ti=r.useMemo(()=>J?J.reduce((e,t)=>{let{cluster:s}=t;return e[s]||(e[s]=[]),e[s].push(t),e},{}):{},[J]),tc=r.useMemo(()=>q?q.reduce((e,t)=>{let{context:s}=t;return e[s]||(e[s]=[]),e[s].push(t),e},{}):{},[q]),td=(()=>{if(!N||!x||e||s)return!1;let t=0===ts.length,a=0===ta.length,r=0===tn.length;return 0===es&&t&&a&&r})();(0,r.useEffect)(()=>{v.isReady&&v.query.context&&e$(decodeURIComponent(Array.isArray(v.query.context)?v.query.context[0]:v.query.context))},[v.isReady,v.query.context]);let tm=e=>{e$(e);let t="/infra/".concat(encodeURIComponent(e));v.asPath!==t&&v.push(t)},tu=t=>{let s=tn.includes(t),r=s?to[t]||[]:e8[t]||[],n=s?ti[t]||[]:tc[t]||[];if(e&&!x)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)(G,{poolName:e,gpusInContext:r,nodesInContext:n,handleDeploySSHPool:e3,handleEditSSHPool:e2,handleDeleteSSHPool:e5,poolConfig:eN[e]})}return(0,a.jsx)(Z,{contextName:t,gpusInContext:r,nodesInContext:n,gpuMetricsRefreshTrigger:eG,isSlurm:s})},tx=()=>o&&s&&(!X||0===X.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:[tt," of ",ee," enabled"]})]}),te&&0!==te.length?(0,a.jsx)("div",{className:"overflow-x-auto rounded-md border shadow-sm bg-card ".concat(!o&&(eH||eE)?"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:te.map(e=>{var t,s;let r=null!==(t=er[e.name])&&void 0!==t?t:e.clusters,l=null!==(s=en[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:eH?(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:eE?(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"===ep?"No enabled clouds available.":'No enabled clouds for workspace "'.concat(ep,'".')})]})}),th=()=>(0,a.jsx)(R,{title:"SSH Node Pool",isLoading:e,isDataLoaded:x,contexts:ts,gpus:tr,groupedPerContextGPUs:e8,groupedPerNodeGPUs:tc,handleContextClick:tm,contextStats:ei,jobsData:eF,isJobsDataLoading:eE,isClusterDataLoading:eH,isSSH:!0,contextWorkspaceMap:ed,contextErrors:eu,gpuMetricsRefreshTrigger:eG,loadedContexts:z,isInitialLoad:o,actionButton:null}),tg=()=>(0,a.jsx)(R,{title:"Kubernetes",isLoading:e,isDataLoaded:x,contexts:ta,gpus:tl,groupedPerContextGPUs:e8,groupedPerNodeGPUs:tc,handleContextClick:tm,contextStats:ei,jobsData:eF,isJobsDataLoading:eE,isClusterDataLoading:eH,isSSH:!1,contextWorkspaceMap:ed,contextErrors:eu,gpuMetricsRefreshTrigger:eG,loadedContexts:z,isInitialLoad:o}),tp=()=>(0,a.jsx)(R,{title:"Slurm",isLoading:eP,isDataLoaded:eD,contexts:tn,gpus:B,groupedPerContextGPUs:to,groupedPerNodeGPUs:ti,handleContextClick:tm,contextStats:ei,jobsData:eF,isJobsDataLoading:eE,isClusterDataLoading:eH,isSSH:!1,isSlurm:!0,contextWorkspaceMap:{},isInitialLoad:o}),tf=w.length>0&&z.size<w.length,ty=e||s||eP||eE||eH||tf||eT;return(0,r.useEffect)(()=>{eq.current&&!ty&&eZ(new Date),eq.current=ty},[ty]),(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"}):tn.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:[ey.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)(M.Ph,{value:ep,onValueChange:ef,children:[(0,a.jsx)(M.i4,{className:"w-40 h-8 text-sm",children:(0,a.jsx)(M.ki,{})}),(0,a.jsxs)(M.Bw,{children:[(0,a.jsx)(M.Ql,{value:"all",children:"All Workspaces"}),ey.map(e=>(0,a.jsx)(M.Ql,{value:e,children:e},e))]})]})]}),ty&&(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..."})]}),!ty&&eR&&(0,a.jsx)(E.$3,{timestamp:eR,className:"mr-2"}),(0,a.jsxs)("button",{onClick:e4,disabled:ty,className:"text-sky-blue hover:text-sky-blue-bright flex items-center",children:[(0,a.jsx)(c.Z,{className:"h-4 w-4 mr-1.5"}),!u&&"Refresh"]})]})]}),(()=>{if(eV)return e&&!x?(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..."})]}):tu(eV);let t=[];td&&t.push({name:"Infrastructure Hint",render:()=>(0,a.jsx)(O,{}),hasActivity:!1,priority:0}),t.push({name:"Kubernetes",render:tg,hasActivity:ta.length>0,priority:1}),t.push({name:"Slurm",render:tp,hasActivity:tn.length>0,priority:2}),t.push({name:"Cloud",render:tx,hasActivity:es>0,priority:3}),t.push({name:"SSH Node Pool",render:th,hasActivity:ts.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:ev,onClose:()=>ew(!1),onSave:e6,poolData:eS,isLoading:eC})]})}},42557:function(e,t,s){s.d(t,{I:function(){return n}});var a=s(85893),r=s(67294),l=s(46990);let n=r.forwardRef((e,t)=>{let{className:s,type:r,...n}=e;return(0,a.jsx)("input",{type:r,className:(0,l.cn)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...n})});n.displayName="Input"},36185:function(e,t,s){s.d(t,{_:function(){return c}});var a=s(85893),r=s(67294),l=s(49102),n=s(12003),o=s(46990);let i=(0,n.j)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),c=r.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,a.jsx)(l.f,{ref:t,className:(0,o.cn)(i(),s),...r})});c.displayName=l.f.displayName},69123:function(e,t,s){s.d(t,{g:function(){return n}});var a=s(85893),r=s(67294),l=s(46990);let n=r.forwardRef((e,t)=>{let{className:s,...r}=e;return(0,a.jsx)("textarea",{className:(0,l.cn)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s),ref:t,...r})});n.displayName="Textarea"},49102:function(e,t,s){s.d(t,{f:function(){return o}});var a=s(67294),r=s(75320),l=s(85893),n=a.forwardRef((e,t)=>(0,l.jsx)(r.WV.label,{...e,ref:t,onMouseDown:t=>{t.target.closest("button, input, select, textarea")||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));n.displayName="Label";var o=n},12003:function(e,t,s){s.d(t,{j:function(){return n}});var a=s(90512);let r=e=>"boolean"==typeof e?`${e}`:0===e?"0":e,l=a.W,n=(e,t)=>s=>{var a;if((null==t?void 0:t.variants)==null)return l(e,null==s?void 0:s.class,null==s?void 0:s.className);let{variants:n,defaultVariants:o}=t,i=Object.keys(n).map(e=>{let t=null==s?void 0:s[e],a=null==o?void 0:o[e];if(null===t)return null;let l=r(t)||r(a);return n[e][l]}),c=s&&Object.entries(s).reduce((e,t)=>{let[s,a]=t;return void 0===a||(e[s]=a),e},{});return l(e,i,null==t?void 0:null===(a=t.compoundVariants)||void 0===a?void 0:a.reduce((e,t)=>{let{class:s,className:a,...r}=t;return Object.entries(r).every(e=>{let[t,s]=e;return Array.isArray(s)?s.includes({...o,...c}[t]):({...o,...c})[t]===s})?[...e,s,a]:e},[]),null==s?void 0:s.class,null==s?void 0:s.className)}}}]);