skypilot-nightly 1.0.0.dev20251024__py3-none-any.whl → 1.0.0.dev20251025__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of skypilot-nightly might be problematic. Click here for more details.

Files changed (52) hide show
  1. sky/__init__.py +2 -2
  2. sky/client/cli/command.py +22 -15
  3. sky/client/cli/table_utils.py +3 -1
  4. sky/dashboard/out/404.html +1 -1
  5. sky/dashboard/out/_next/static/{KxZarRnMeQID-gZkBfhzv → WfMolkH3tkVNEHhHaH9uk}/_buildManifest.js +1 -1
  6. sky/dashboard/out/_next/static/chunks/1141-d5204f35a3388bf4.js +11 -0
  7. sky/dashboard/out/_next/static/chunks/1871-81adbc5f25dff78f.js +6 -0
  8. sky/dashboard/out/_next/static/chunks/2755.227c84f5adf75c6b.js +26 -0
  9. sky/dashboard/out/_next/static/chunks/3294.6d5054a953a818cb.js +1 -0
  10. sky/dashboard/out/_next/static/chunks/{3785.e4aaef3b6c460dfb.js → 3785.538eb23a098fc304.js} +1 -1
  11. sky/dashboard/out/_next/static/chunks/9353-cff34f7e773b2e2b.js +1 -0
  12. sky/dashboard/out/_next/static/chunks/pages/{_app-7d2f4467a685de9b.js → _app-513d332313670f2a.js} +1 -1
  13. sky/dashboard/out/_next/static/chunks/pages/clusters/[cluster]/{[job]-1d90fbf8f0ffd194.js → [job]-c815b90e296b8075.js} +1 -1
  14. sky/dashboard/out/_next/static/chunks/pages/clusters/[cluster]-fbf2907ce2bb67e2.js +1 -0
  15. sky/dashboard/out/_next/static/chunks/pages/{clusters-d887733ca514d22e.js → clusters-9e0df5442b04f7d0.js} +1 -1
  16. sky/dashboard/out/_next/static/chunks/pages/infra/{[context]-79b68556c00d284e.js → [context]-9b6e47c2e8b485a2.js} +1 -1
  17. sky/dashboard/out/_next/static/chunks/pages/{infra-e1c3789e69102cdb.js → infra-c84a3b8a9d599b02.js} +1 -1
  18. sky/dashboard/out/_next/static/chunks/pages/jobs/[job]-eb5822dac0c9509b.js +16 -0
  19. sky/dashboard/out/_next/static/chunks/pages/{users-0befb1254ac5c965.js → users-96d6b8bb2dec055f.js} +1 -1
  20. sky/dashboard/out/_next/static/chunks/pages/workspaces/{[name]-ecc38434a21e8a1e.js → [name]-fb1b4d3bfb047cad.js} +1 -1
  21. sky/dashboard/out/_next/static/chunks/{webpack-31acb2000f9b372c.js → webpack-4abaae354da0ba13.js} +1 -1
  22. sky/dashboard/out/clusters/[cluster]/[job].html +1 -1
  23. sky/dashboard/out/clusters/[cluster].html +1 -1
  24. sky/dashboard/out/clusters.html +1 -1
  25. sky/dashboard/out/config.html +1 -1
  26. sky/dashboard/out/index.html +1 -1
  27. sky/dashboard/out/infra/[context].html +1 -1
  28. sky/dashboard/out/infra.html +1 -1
  29. sky/dashboard/out/jobs/[job].html +1 -1
  30. sky/dashboard/out/jobs/pools/[pool].html +1 -1
  31. sky/dashboard/out/jobs.html +1 -1
  32. sky/dashboard/out/users.html +1 -1
  33. sky/dashboard/out/volumes.html +1 -1
  34. sky/dashboard/out/workspace/new.html +1 -1
  35. sky/dashboard/out/workspaces/[name].html +1 -1
  36. sky/dashboard/out/workspaces.html +1 -1
  37. sky/jobs/server/utils.py +4 -1
  38. sky/jobs/utils.py +39 -0
  39. {skypilot_nightly-1.0.0.dev20251024.dist-info → skypilot_nightly-1.0.0.dev20251025.dist-info}/METADATA +37 -37
  40. {skypilot_nightly-1.0.0.dev20251024.dist-info → skypilot_nightly-1.0.0.dev20251025.dist-info}/RECORD +45 -45
  41. sky/dashboard/out/_next/static/chunks/1141-145e542070a6b615.js +0 -11
  42. sky/dashboard/out/_next/static/chunks/1871-5f68bb683940d23f.js +0 -6
  43. sky/dashboard/out/_next/static/chunks/2755.210d4b7c92c6efb2.js +0 -26
  44. sky/dashboard/out/_next/static/chunks/3294.bdfea6492fdf845a.js +0 -1
  45. sky/dashboard/out/_next/static/chunks/8632-396a81107ba407c3.js +0 -1
  46. sky/dashboard/out/_next/static/chunks/pages/clusters/[cluster]-5edf81da6677352c.js +0 -1
  47. sky/dashboard/out/_next/static/chunks/pages/jobs/[job]-10f12af2b199ff68.js +0 -16
  48. /sky/dashboard/out/_next/static/{KxZarRnMeQID-gZkBfhzv → WfMolkH3tkVNEHhHaH9uk}/_ssgManifest.js +0 -0
  49. {skypilot_nightly-1.0.0.dev20251024.dist-info → skypilot_nightly-1.0.0.dev20251025.dist-info}/WHEEL +0 -0
  50. {skypilot_nightly-1.0.0.dev20251024.dist-info → skypilot_nightly-1.0.0.dev20251025.dist-info}/entry_points.txt +0 -0
  51. {skypilot_nightly-1.0.0.dev20251024.dist-info → skypilot_nightly-1.0.0.dev20251025.dist-info}/licenses/LICENSE +0 -0
  52. {skypilot_nightly-1.0.0.dev20251024.dist-info → skypilot_nightly-1.0.0.dev20251025.dist-info}/top_level.txt +0 -0
sky/__init__.py CHANGED
@@ -7,7 +7,7 @@ import urllib.request
7
7
  from sky.utils import directory_utils
8
8
 
9
9
  # Replaced with the current commit when building the wheels.
10
- _SKYPILOT_COMMIT_SHA = '22d11ebba6e4901078e7df41b10b08cce86bb280'
10
+ _SKYPILOT_COMMIT_SHA = 'db2c05dcce1bdbe095b652c2902a1627aca435c8'
11
11
 
12
12
 
13
13
  def _get_git_commit():
@@ -37,7 +37,7 @@ def _get_git_commit():
37
37
 
38
38
 
39
39
  __commit__ = _get_git_commit()
40
- __version__ = '1.0.0.dev20251024'
40
+ __version__ = '1.0.0.dev20251025'
41
41
  __root_dir__ = directory_utils.get_sky_dir()
42
42
 
43
43
 
sky/client/cli/command.py CHANGED
@@ -1350,12 +1350,16 @@ def _handle_jobs_queue_request(
1350
1350
  show_all: bool,
1351
1351
  show_user: bool,
1352
1352
  max_num_jobs_to_show: Optional[int],
1353
+ pool_status_request_id: Optional[server_common.RequestId[List[Dict[
1354
+ str, Any]]]] = None,
1353
1355
  is_called_by_user: bool = False,
1354
1356
  only_in_progress: bool = False,
1355
1357
  ) -> Tuple[Optional[int], str]:
1356
1358
  """Get the in-progress managed jobs.
1357
1359
 
1358
1360
  Args:
1361
+ request_id: The request ID for managed jobs.
1362
+ pool_status_request_id: The request ID for pool status, or None.
1359
1363
  show_all: Show all information of each job (e.g., region, price).
1360
1364
  show_user: Show the user who submitted the job.
1361
1365
  max_num_jobs_to_show: If not None, limit the number of jobs to show to
@@ -1375,6 +1379,7 @@ def _handle_jobs_queue_request(
1375
1379
  num_in_progress_jobs = None
1376
1380
  msg = ''
1377
1381
  status_counts: Optional[Dict[str, int]] = None
1382
+ pool_status_result = None
1378
1383
  try:
1379
1384
  if not is_called_by_user:
1380
1385
  usage_lib.messages.usage.set_internal()
@@ -1395,6 +1400,13 @@ def _handle_jobs_queue_request(
1395
1400
  managed_jobs_ = result
1396
1401
  num_in_progress_jobs = len(
1397
1402
  set(job['job_id'] for job in managed_jobs_))
1403
+ # Try to get pool status if request was made
1404
+ if pool_status_request_id is not None:
1405
+ try:
1406
+ pool_status_result = sdk.stream_and_get(pool_status_request_id)
1407
+ except Exception: # pylint: disable=broad-except
1408
+ # If getting pool status fails, just continue without it
1409
+ pool_status_result = None
1398
1410
  except exceptions.ClusterNotUpError as e:
1399
1411
  controller_status = e.cluster_status
1400
1412
  msg = str(e)
@@ -1440,6 +1452,7 @@ def _handle_jobs_queue_request(
1440
1452
  else:
1441
1453
  msg = table_utils.format_job_table(
1442
1454
  managed_jobs_,
1455
+ pool_status=pool_status_result,
1443
1456
  show_all=show_all,
1444
1457
  show_user=show_user,
1445
1458
  max_jobs=max_num_jobs_to_show,
@@ -1945,6 +1958,7 @@ def status(verbose: bool, refresh: bool, ip: bool, endpoints: bool,
1945
1958
  try:
1946
1959
  num_in_progress_jobs, msg = _handle_jobs_queue_request(
1947
1960
  managed_jobs_queue_request_id,
1961
+ pool_status_request_id=pool_status_request_id,
1948
1962
  show_all=False,
1949
1963
  show_user=all_users,
1950
1964
  max_num_jobs_to_show=_NUM_MANAGED_JOBS_TO_SHOW_IN_STATUS,
@@ -4621,21 +4635,6 @@ def jobs_launch(
4621
4635
 
4622
4636
  job_ids = [job_id_handle[0]] if isinstance(job_id_handle[0],
4623
4637
  int) else job_id_handle[0]
4624
- if pool:
4625
- # Display the worker assignment for the jobs.
4626
- logger.debug(f'Getting service records for pool: {pool}')
4627
- records_request_id = managed_jobs.pool_status(pool_names=pool)
4628
- service_records = _async_call_or_wait(records_request_id, async_call,
4629
- 'sky.jobs.pool_status')
4630
- logger.debug(f'Pool status: {service_records}')
4631
- replica_infos = service_records[0]['replica_info']
4632
- for replica_info in replica_infos:
4633
- job_id = replica_info.get('used_by', None)
4634
- if job_id in job_ids:
4635
- worker_id = replica_info['replica_id']
4636
- version = replica_info['version']
4637
- logger.info(f'Job ID: {job_id} assigned to pool {pool} '
4638
- f'(worker: {worker_id}, version: {version})')
4639
4638
 
4640
4639
  if not detach_run:
4641
4640
  if len(job_ids) == 1:
@@ -4768,8 +4767,16 @@ def jobs_queue(verbose: bool, refresh: bool, skip_finished: bool,
4768
4767
  all_users=all_users,
4769
4768
  limit=max_num_jobs_to_show,
4770
4769
  fields=fields)
4770
+ # Try to get pool status for worker information
4771
+ pool_status_request_id = None
4772
+ try:
4773
+ pool_status_request_id = managed_jobs.pool_status(pool_names=None)
4774
+ except Exception: # pylint: disable=broad-except
4775
+ # If pool_status fails, we'll just skip the worker information
4776
+ pass
4771
4777
  num_jobs, msg = _handle_jobs_queue_request(
4772
4778
  managed_jobs_request_id,
4779
+ pool_status_request_id=pool_status_request_id,
4773
4780
  show_all=verbose,
4774
4781
  show_user=all_users,
4775
4782
  max_num_jobs_to_show=max_num_jobs_to_show,
@@ -1,7 +1,7 @@
1
1
  """Utilities for formatting tables for CLI output."""
2
2
  import abc
3
3
  from datetime import datetime
4
- from typing import Dict, List, Optional
4
+ from typing import Any, Dict, List, Optional
5
5
 
6
6
  import prettytable
7
7
 
@@ -92,12 +92,14 @@ def format_job_table(
92
92
  jobs: List[responses.ManagedJobRecord],
93
93
  show_all: bool,
94
94
  show_user: bool,
95
+ pool_status: Optional[List[Dict[str, Any]]] = None,
95
96
  max_jobs: Optional[int] = None,
96
97
  status_counts: Optional[Dict[str, int]] = None,
97
98
  ):
98
99
  jobs = [job.model_dump() for job in jobs]
99
100
  return managed_jobs.format_job_table(
100
101
  jobs,
102
+ pool_status=pool_status,
101
103
  show_all=show_all,
102
104
  show_user=show_user,
103
105
  max_jobs=max_jobs,
@@ -1 +1 @@
1
- <!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/dashboard/_next/static/css/4c052b4444e52a58.css" as="style"/><link rel="stylesheet" href="/dashboard/_next/static/css/4c052b4444e52a58.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/dashboard/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js"></script><script src="/dashboard/_next/static/chunks/webpack-31acb2000f9b372c.js" defer=""></script><script src="/dashboard/_next/static/chunks/framework-cf60a09ccd051a10.js" defer=""></script><script src="/dashboard/_next/static/chunks/main-f15ccb73239a3bf1.js" defer=""></script><script src="/dashboard/_next/static/chunks/pages/_app-7d2f4467a685de9b.js" defer=""></script><script src="/dashboard/_next/static/chunks/pages/_error-c66a4e8afc46f17b.js" defer=""></script><script src="/dashboard/_next/static/KxZarRnMeQID-gZkBfhzv/_buildManifest.js" defer=""></script><script src="/dashboard/_next/static/KxZarRnMeQID-gZkBfhzv/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"KxZarRnMeQID-gZkBfhzv","assetPrefix":"/dashboard","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
1
+ <!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/dashboard/_next/static/css/4c052b4444e52a58.css" as="style"/><link rel="stylesheet" href="/dashboard/_next/static/css/4c052b4444e52a58.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/dashboard/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js"></script><script src="/dashboard/_next/static/chunks/webpack-4abaae354da0ba13.js" defer=""></script><script src="/dashboard/_next/static/chunks/framework-cf60a09ccd051a10.js" defer=""></script><script src="/dashboard/_next/static/chunks/main-f15ccb73239a3bf1.js" defer=""></script><script src="/dashboard/_next/static/chunks/pages/_app-513d332313670f2a.js" defer=""></script><script src="/dashboard/_next/static/chunks/pages/_error-c66a4e8afc46f17b.js" defer=""></script><script src="/dashboard/_next/static/WfMolkH3tkVNEHhHaH9uk/_buildManifest.js" defer=""></script><script src="/dashboard/_next/static/WfMolkH3tkVNEHhHaH9uk/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"WfMolkH3tkVNEHhHaH9uk","assetPrefix":"/dashboard","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
@@ -1 +1 @@
1
- self.__BUILD_MANIFEST=function(s,c,a,e,t,f,u,n,o,b,j,r,i,k,h){return{__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/":["static/chunks/pages/index-444f1804401f04ea.js"],"/_error":["static/chunks/pages/_error-c66a4e8afc46f17b.js"],"/clusters":["static/chunks/pages/clusters-d887733ca514d22e.js"],"/clusters/[cluster]":[s,c,a,f,u,j,b,e,t,n,r,o,i,k,h,"static/chunks/6856-5c94d394259cdb6e.js","static/chunks/1871-5f68bb683940d23f.js","static/chunks/pages/clusters/[cluster]-5edf81da6677352c.js"],"/clusters/[cluster]/[job]":[s,c,a,f,e,t,o,"static/chunks/pages/clusters/[cluster]/[job]-1d90fbf8f0ffd194.js"],"/config":["static/chunks/pages/config-dfb9bf07b13045f4.js"],"/infra":["static/chunks/pages/infra-e1c3789e69102cdb.js"],"/infra/[context]":["static/chunks/pages/infra/[context]-79b68556c00d284e.js"],"/jobs":["static/chunks/pages/jobs-0dc34cf9a8710a9f.js"],"/jobs/pools/[pool]":[s,c,a,u,b,e,t,n,"static/chunks/pages/jobs/pools/[pool]-e020fd69dbe76cea.js"],"/jobs/[job]":[s,c,a,f,u,b,e,t,n,o,"static/chunks/pages/jobs/[job]-10f12af2b199ff68.js"],"/users":["static/chunks/pages/users-0befb1254ac5c965.js"],"/volumes":["static/chunks/pages/volumes-d2af9d22e87cc4ba.js"],"/workspace/new":["static/chunks/pages/workspace/new-3f88a1c7e86a3f86.js"],"/workspaces":["static/chunks/pages/workspaces-6fc994fa1ee6c6bf.js"],"/workspaces/[name]":[s,c,a,f,u,j,e,t,n,r,o,i,k,h,"static/chunks/1141-145e542070a6b615.js","static/chunks/pages/workspaces/[name]-ecc38434a21e8a1e.js"],sortedPages:["/","/_app","/_error","/clusters","/clusters/[cluster]","/clusters/[cluster]/[job]","/config","/infra","/infra/[context]","/jobs","/jobs/pools/[pool]","/jobs/[job]","/users","/volumes","/workspace/new","/workspaces","/workspaces/[name]"]}}("static/chunks/616-3d59f75e2ccf9321.js","static/chunks/6130-2be46d70a38f1e82.js","static/chunks/5739-d67458fcb1386c92.js","static/chunks/6989-01359c57e018caa4.js","static/chunks/3850-ff4a9a69d978632b.js","static/chunks/7411-b15471acd2cba716.js","static/chunks/1272-1ef0bf0237faccdb.js","static/chunks/8969-0389e2cb52412db3.js","static/chunks/8632-396a81107ba407c3.js","static/chunks/6212-7bd06f60ba693125.js","static/chunks/7359-c8d04e06886000b3.js","static/chunks/6990-f6818c84ed8f1c86.js","static/chunks/4282-d2f3ef2fbf78e347.js","static/chunks/6601-06114c982db410b6.js","static/chunks/3015-2dcace420c8939f4.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();
1
+ self.__BUILD_MANIFEST=function(s,c,e,a,t,f,b,u,n,o,j,r,i,k,d){return{__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/":["static/chunks/pages/index-444f1804401f04ea.js"],"/_error":["static/chunks/pages/_error-c66a4e8afc46f17b.js"],"/clusters":["static/chunks/pages/clusters-9e0df5442b04f7d0.js"],"/clusters/[cluster]":[s,c,e,f,b,j,o,a,t,u,r,n,i,k,d,"static/chunks/6856-5c94d394259cdb6e.js","static/chunks/1871-81adbc5f25dff78f.js","static/chunks/pages/clusters/[cluster]-fbf2907ce2bb67e2.js"],"/clusters/[cluster]/[job]":[s,c,e,f,a,t,n,"static/chunks/pages/clusters/[cluster]/[job]-c815b90e296b8075.js"],"/config":["static/chunks/pages/config-dfb9bf07b13045f4.js"],"/infra":["static/chunks/pages/infra-c84a3b8a9d599b02.js"],"/infra/[context]":["static/chunks/pages/infra/[context]-9b6e47c2e8b485a2.js"],"/jobs":["static/chunks/pages/jobs-0dc34cf9a8710a9f.js"],"/jobs/pools/[pool]":[s,c,e,b,o,a,t,u,"static/chunks/pages/jobs/pools/[pool]-e020fd69dbe76cea.js"],"/jobs/[job]":[s,c,e,f,b,o,a,t,u,n,"static/chunks/pages/jobs/[job]-eb5822dac0c9509b.js"],"/users":["static/chunks/pages/users-96d6b8bb2dec055f.js"],"/volumes":["static/chunks/pages/volumes-d2af9d22e87cc4ba.js"],"/workspace/new":["static/chunks/pages/workspace/new-3f88a1c7e86a3f86.js"],"/workspaces":["static/chunks/pages/workspaces-6fc994fa1ee6c6bf.js"],"/workspaces/[name]":[s,c,e,f,b,j,a,t,u,r,n,i,k,d,"static/chunks/1141-d5204f35a3388bf4.js","static/chunks/pages/workspaces/[name]-fb1b4d3bfb047cad.js"],sortedPages:["/","/_app","/_error","/clusters","/clusters/[cluster]","/clusters/[cluster]/[job]","/config","/infra","/infra/[context]","/jobs","/jobs/pools/[pool]","/jobs/[job]","/users","/volumes","/workspace/new","/workspaces","/workspaces/[name]"]}}("static/chunks/616-3d59f75e2ccf9321.js","static/chunks/6130-2be46d70a38f1e82.js","static/chunks/5739-d67458fcb1386c92.js","static/chunks/6989-01359c57e018caa4.js","static/chunks/3850-ff4a9a69d978632b.js","static/chunks/7411-b15471acd2cba716.js","static/chunks/1272-1ef0bf0237faccdb.js","static/chunks/8969-0389e2cb52412db3.js","static/chunks/9353-cff34f7e773b2e2b.js","static/chunks/6212-7bd06f60ba693125.js","static/chunks/7359-c8d04e06886000b3.js","static/chunks/6990-f6818c84ed8f1c86.js","static/chunks/4282-d2f3ef2fbf78e347.js","static/chunks/6601-06114c982db410b6.js","static/chunks/3015-2dcace420c8939f4.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();
@@ -0,0 +1,11 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1141],{99333:function(e,s,a){a.d(s,{Z:function(){return t}});/**
2
+ * @license lucide-react v0.407.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */let t=(0,a(60998).Z)("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]])},98418:function(e,s,a){a.d(s,{Z:function(){return t}});/**
7
+ * @license lucide-react v0.407.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */let t=(0,a(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"}]])},1812:function(e,s,a){a.d(s,{X:function(){return n}});var t=a(85893),r=a(67294);let l=e=>{if(!(null==e?void 0:e.message))return"An unexpected error occurred.";let s=e.message;return s.includes("failed:")&&(s=s.split("failed:")[1].trim()),s},n=e=>{let{error:s,title:a="Error",onDismiss:n}=e,[c,i]=(0,r.useState)(!1);if((0,r.useEffect)(()=>{s&&i(!1)},[s]),!s||c)return null;let o="string"==typeof s?s:l(s);return(0,t.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-md p-3 mb-4",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex",children:[(0,t.jsx)("div",{className:"flex-shrink-0",children:(0,t.jsx)("svg",{className:"h-5 w-5 text-red-400",viewBox:"0 0 20 20",fill:"currentColor",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})})}),(0,t.jsx)("div",{className:"ml-3",children:(0,t.jsxs)("div",{className:"text-sm text-red-800",children:[(0,t.jsxs)("strong",{children:[a,":"]})," ",o]})})]}),(0,t.jsx)("button",{onClick:()=>{i(!0),n&&n()},className:"flex-shrink-0 ml-4 text-red-400 hover:text-red-600 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 focus:ring-offset-red-50 rounded","aria-label":"Dismiss error",children:(0,t.jsx)("svg",{className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]})})}},69123:function(e,s,a){a.d(s,{g:function(){return n}});var t=a(85893),r=a(67294),l=a(32350);let n=r.forwardRef((e,s)=>{let{className:a,...r}=e;return(0,t.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",a),ref:s,...r})});n.displayName="Textarea"},11141:function(e,s,a){a.r(s),a.d(s,{WorkspaceEditor:function(){return _}});var t=a(85893),r=a(67294),l=a(11163),n=a(17324),c=a(23266),i=a(68969);a(9353);var o=a(41664),d=a.n(o),u=a(9008),x=a.n(u),m=a(37673),h=a(30803),f=a(69123),g=a(55739),p=a(70282),b=a(6021),j=a(13626),y=a(98418),N=a(99333),k=a(50326);let v=e=>{let{className:s="",variant:a="default",children:r,...l}=e;return(0,t.jsx)("div",{role:"alert",className:"".concat("relative w-full rounded-lg border p-4 flex items-start space-x-2"," ").concat({default:"bg-blue-50 border-blue-200 text-blue-800",destructive:"bg-red-50 border-red-200 text-red-800"}[a]," ").concat(s),...l,children:r})},w=e=>{let{className:s="",children:a,...r}=e;return(0,t.jsx)("div",{className:"text-sm leading-relaxed ".concat(s),...r,children:a})};var C=a(53850),L=a(1812),E=a(23015),S=a(1272),W=a(93225),A=a(53081),M=a(6378);let Z=e=>{let{message:s}=e;return s?(0,t.jsxs)(v,{className:"border-green-200 bg-green-50",children:[(0,t.jsx)(p.Z,{className:"h-4 w-4 text-green-600"}),(0,t.jsx)(w,{className:"text-green-800",children:s})]}):null},D=e=>{let{workspaceName:s,config:a,enabledClouds:r=[]}=e;if(!a)return null;let l="default"===s,n=0===Object.keys(a).length;if(l&&n)return(0,t.jsx)("div",{className:"text-sm text-gray-500 mb-3 italic p-3 bg-sky-50 rounded border border-sky-200",children:"Workspace 'default' can use all accessible infrastructure."});let c=[],i=[],o=[],d=new Set(r.map(e=>e.toLowerCase()));Object.entries(a).forEach(e=>{let[s,a]=e;if("private"===s||"allowed_users"===s)return;let r=W.Z2[s.toLowerCase()]||s.toUpperCase(),l=null==r?void 0:r.toLowerCase(),n=d.has(l)||Array.from(d).some(e=>e.startsWith(l+"/")),u=()=>"kubernetes"===s.toLowerCase()?Array.from(d).filter(e=>e.startsWith(l+"/")).map(e=>e.split("/")[1]):[];if((null==a?void 0:a.disabled)===!0)i.push(r);else if(a&&Object.keys(a).length>0){let e="";if("gcp"===s.toLowerCase()&&a.project_id)e=" (Project ID: ".concat(a.project_id,")");else if("aws"===s.toLowerCase()&&a.region)e=" (Region: ".concat(a.region,")");else if("kubernetes"===s.toLowerCase()){let s=u();s.length>0&&(e=" (Contexts: ".concat(s.join(", "),")"))}n?c.push((0,t.jsxs)("span",{className:"block",children:[r,e," is enabled."]},"".concat(s,"-enabled"))):o.push((0,t.jsxs)("span",{className:"block text-amber-700",children:[r,e," is configured but not currently available."]},"".concat(s,"-configured-not-enabled")))}else if(n){let e="";if("kubernetes"===s.toLowerCase()){let s=u();s.length>0&&(e=" (Contexts: ".concat(s.join(", "),")"))}c.push((0,t.jsxs)("span",{className:"block",children:[r,e," is enabled (using default settings)."]},"".concat(s,"-default-enabled")))}else o.push((0,t.jsxs)("span",{className:"block text-amber-700",children:[r," is configured but not currently available."]},"".concat(s,"-default-not-enabled")))});let u=[];if(i.length>0){let e=i.join(" and ");u.push((0,t.jsxs)("span",{className:"block",children:[e," ",1===i.length?"is":"are"," explicitly disabled."]},"disabled-clouds"))}return(u.push(...c),u.push(...o),u.length>0)?(0,t.jsx)("div",{className:"text-sm text-gray-700 mb-3 p-3 bg-sky-50 rounded border border-sky-200",children:u}):!l&&n?(0,t.jsx)("div",{className:"text-sm text-gray-500 mb-3 italic p-3 bg-sky-50 rounded border border-sky-200",children:"This workspace has no specific cloud resource configurations and can use all accessible infrastructure."}):null},P=e=>{let{isPrivate:s}=e;return s?(0,t.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-700 border border-gray-300",children:"Private"}):(0,t.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-700 border border-green-300",children:"Public"})},R=e=>{let{workspaceConfig:s,allUsers:a}=e;if(!s.private)return null;let r=s.allowed_users||[],l=(a||[]).filter(e=>"admin"===e.role).map(e=>e.username),n=[...new Set([...r,...l])];return 0===n.length?(0,t.jsxs)("div",{className:"mt-4",children:[(0,t.jsx)("h4",{className:"mb-2 text-xs text-gray-500 tracking-wider",children:"Allowed Users (0)"}),(0,t.jsx)("div",{className:"text-amber-600 text-xs italic p-2 bg-amber-50 rounded border border-amber-200",children:"No users configured (workspace may be inaccessible)"})]}):(0,t.jsxs)("div",{className:"mt-4",children:[(0,t.jsxs)("h4",{className:"mb-2 text-xs text-gray-500 tracking-wider",children:["Allowed Users (",n.length,")"]}),(0,t.jsx)("div",{className:"space-y-1 max-h-48 overflow-y-auto border border-gray-200 rounded",children:n.map(e=>{let s=l.includes(e);return(0,t.jsxs)("div",{className:"flex items-center justify-between text-xs p-2 bg-gray-50 hover:bg-gray-100 border-b border-gray-100 last:border-b-0",children:[(0,t.jsx)("span",{className:"font-medium text-gray-700",children:e}),s?(0,t.jsxs)("span",{className:"inline-flex items-center text-blue-600",children:[(0,t.jsx)(C.r7,{className:"w-3 h-3 mr-1"}),"Admin"]}):(0,t.jsxs)("span",{className:"inline-flex items-center text-gray-600",children:[(0,t.jsx)(b.Z,{className:"w-3 h-3 mr-1"}),"User"]})]},e)})})]})};function _(e){let{workspaceName:s,isNewWorkspace:a=!1}=e,o=(0,l.useRouter)(),[u,p]=(0,r.useState)({}),[b,v]=(0,r.useState)({}),[w,W]=(0,r.useState)(""),[_,z]=(0,r.useState)(!0),[O,U]=(0,r.useState)(!1),[T,Y]=(0,r.useState)(!1),[J,F]=(0,r.useState)(null),[I,V]=(0,r.useState)(null),[H,B]=(0,r.useState)(null),[X,G]=(0,r.useState)([]),[q,K]=(0,r.useState)({showDialog:!1,deleting:!1,error:null}),[Q,$]=(0,r.useState)({totalClusterCount:0,runningClusterCount:0,managedJobsCount:0,clouds:[]}),[ee,es]=(0,r.useState)(!1),ea=(0,r.useCallback)(async()=>{z(!0),F(null);try{let e;let[a,t]=await Promise.all([(0,n.getWorkspaces)(),(0,A.R)()]),r=a[s]||{};p(r),v(r),G(t||[]),e=0===Object.keys(r).length?"".concat(s,":\n # Empty workspace configuration - uses all accessible infrastructure\n"):S.ZP.dump({[s]:r},{indent:2,lineWidth:-1,noRefs:!0,skipInvalid:!0,flowLevel:-1}),W(e)}catch(e){console.error("Error fetching workspace config:",e),F(e)}finally{z(!1)}},[s]),et=(0,r.useCallback)(async()=>{if(!a){es(!0);try{let[e,a,t]=await Promise.all([M.dashboardCache.get(c.getClusters),M.dashboardCache.get(i.getManagedJobs,[{allUsers:!0,skipFinished:!0,workspaceMatch:s,fields:["workspace","status"]}]),M.dashboardCache.get(n.getEnabledClouds,[s,!0])]),r=e.filter(e=>(e.workspace||"default")===s),l=r.filter(e=>"RUNNING"===e.status||"LAUNCHING"===e.status),o={};e.forEach(e=>{o[e.cluster]=e.workspace||"default"});let d=a.jobs||[],u=new Set(E.statusGroups.active),x=0;d.forEach(e=>{e.workspace===s&&u.has(e.status)&&x++}),$({totalClusterCount:r.length,runningClusterCount:l.length,managedJobsCount:x,clouds:Array.isArray(t)?t:[]})}catch(e){console.error("Failed to fetch workspace stats:",e)}finally{es(!1)}}},[s,a]);(0,r.useEffect)(()=>{a?(z(!1),W("".concat(s,":\n # New workspace configuration\n # Leave empty to use all accessible infrastructure\n"))):(ea(),et())},[s,a,ea,et]),(0,r.useEffect)(()=>{Y(JSON.stringify(u)!==JSON.stringify(b))},[u,b]);let er=e=>{W(e),B(null);try{let a=S.ZP.load(e)||{},t=Object.keys(a);if(0===t.length)p({});else if(1===t.length){let e=t[0];if(e!==s){B('Workspace name cannot be changed. Expected "'.concat(s,'" but found "').concat(e,'".'));return}let r=a[s]||{};p(r)}else B("Configuration must contain only one workspace. Found: ".concat(t.join(", ")))}catch(e){B("Invalid YAML: ".concat(e.message))}},el=async()=>{U(!0),F(null),V(null);try{if(H)throw Error("Please fix YAML errors before saving");let e=S.ZP.load(w)||{},t=Object.keys(e);if(t.length>0&&t[0]!==s)throw Error('Workspace name cannot be changed. Expected "'.concat(s,'".'));a?(await (0,n.MB)(s,u),V("Workspace created successfully!"),setTimeout(()=>{o.push("/workspaces/".concat(s))},1500)):(await (0,n.eA)(s,u),V("Workspace updated successfully!"),v(u),et())}catch(e){console.error("Error saving workspace:",e),F(e)}finally{U(!1)}},en=async()=>{K(e=>({...e,deleting:!0,error:null}));try{await (0,n.zl)(s),V("Workspace deleted successfully!"),setTimeout(()=>{o.push("/workspaces")},1500)}catch(e){console.error("Error deleting workspace:",e),K(s=>({...s,deleting:!1,error:e}))}},ec=()=>{K({showDialog:!1,deleting:!1,error:null})},ei=async()=>{await Promise.all([ea(),et()])};if(!o.isReady)return(0,t.jsx)("div",{children:"Loading..."});let eo=a?"Create New Workspace | SkyPilot Dashboard":"Workspace: ".concat(s," | SkyPilot Dashboard");return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(x(),{children:(0,t.jsx)("title",{children:eo})}),(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-4 h-5",children:[(0,t.jsxs)("div",{className:"text-base flex items-center",children:[(0,t.jsx)(d(),{href:"/workspaces",className:"text-sky-blue hover:underline",children:"Workspaces"}),(0,t.jsx)("span",{className:"mx-2 text-gray-500",children:"›"}),(0,t.jsx)(d(),{href:a?"/workspace/new":"/workspaces/".concat(s),className:"text-sky-blue hover:underline",children:a?"New Workspace":s}),T&&(0,t.jsx)("span",{className:"ml-3 px-2 py-1 bg-yellow-100 text-yellow-800 text-xs rounded",children:"Unsaved changes"})]}),(0,t.jsxs)("div",{className:"text-sm flex items-center",children:[(_||O||ee)&&(0,t.jsxs)("div",{className:"flex items-center mr-4",children:[(0,t.jsx)(g.Z,{size:15,className:"mt-0"}),(0,t.jsx)("span",{className:"ml-2 text-gray-500",children:O?"Saving...":"Loading..."})]}),(0,t.jsxs)("div",{className:"flex items-center space-x-4",children:[!a&&(0,t.jsxs)("button",{onClick:ei,disabled:_||O||ee,className:"text-sky-blue hover:text-sky-blue-bright font-medium inline-flex items-center",children:[(0,t.jsx)(j.Z,{className:"w-4 h-4 mr-1.5"}),"Refresh"]}),!a&&"default"!==s&&(0,t.jsxs)("button",{onClick:()=>K({...q,showDialog:!0}),disabled:q.deleting||O,className:"text-red-600 hover:text-red-700 font-medium inline-flex items-center",children:[(0,t.jsx)(y.Z,{className:"w-4 h-4 mr-1.5"}),"Delete"]})]})]})]}),_?(0,t.jsxs)("div",{className:"flex justify-center items-center py-12",children:[(0,t.jsx)(g.Z,{size:24,className:"mr-2"}),(0,t.jsx)("span",{className:"text-gray-500",children:"Loading workspace configuration..."})]}):(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsx)(L.X,{error:J,title:"Error",onDismiss:()=>F(null)}),(0,t.jsx)(Z,{message:I}),(0,t.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[!a&&(0,t.jsx)("div",{className:"lg:col-span-1",children:(0,t.jsxs)(m.Zb,{className:"h-full",children:[(0,t.jsx)(m.Ol,{children:(0,t.jsx)(m.ll,{className:"text-base font-normal",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"font-semibold",children:"Workspace:"})," ",s]}),(0,t.jsx)(P,{isPrivate:!0===b.private})]})})}),(0,t.jsxs)(m.aY,{className:"text-sm pb-2 flex-1",children:[(0,t.jsxs)("div",{className:"py-2 flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center text-gray-600",children:[(0,t.jsx)(C.QT,{className:"w-4 h-4 mr-2 text-gray-500"}),(0,t.jsx)("span",{children:"Clusters (Running / Total)"})]}),(0,t.jsx)("span",{className:"font-normal text-gray-800",children:ee?"...":"".concat(Q.runningClusterCount," / ").concat(Q.totalClusterCount)})]}),(0,t.jsxs)("div",{className:"py-2 flex items-center justify-between border-t border-gray-100",children:[(0,t.jsxs)("div",{className:"flex items-center text-gray-600",children:[(0,t.jsx)(C.Vp,{className:"w-4 h-4 mr-2 text-gray-500"}),(0,t.jsx)("span",{children:"Managed Jobs"})]}),(0,t.jsx)("span",{className:"font-normal text-gray-800",children:ee?"...":Q.managedJobsCount})]})]}),(0,t.jsxs)("div",{className:"px-6 pb-6 text-sm pt-3",children:[(0,t.jsx)("h4",{className:"mb-2 text-xs text-gray-500 tracking-wider",children:"Enabled Infra"}),(0,t.jsx)("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:ee?(0,t.jsx)("span",{className:"text-gray-500",children:"Loading..."}):Q.clouds.length>0?Q.clouds.map(e=>(0,t.jsxs)("div",{className:"flex items-center text-gray-700",children:[(0,t.jsx)(C.Ye,{className:"w-3.5 h-3.5 mr-1.5 text-green-500"}),(0,t.jsx)("span",{children:e})]},e)):(0,t.jsx)("span",{className:"text-gray-500 italic",children:"No enabled infrastructure"})}),(0,t.jsx)("div",{className:"mt-4",children:(0,t.jsx)(D,{workspaceName:s,config:b,enabledClouds:Q.clouds})}),(0,t.jsx)(R,{workspaceConfig:b,allUsers:X})]})]})}),(0,t.jsx)("div",{className:a?"lg:col-span-3":"lg:col-span-2",children:(0,t.jsxs)(m.Zb,{className:"h-full flex flex-col",children:[(0,t.jsx)(m.Ol,{children:(0,t.jsx)(m.ll,{className:"text-base font-normal",children:a?"New Workspace YAML":"Edit Workspace YAML"})}),(0,t.jsx)(m.aY,{className:"flex-1 flex flex-col",children:(0,t.jsxs)("div",{className:"space-y-4 flex-1 flex flex-col",children:[H&&(0,t.jsx)(L.X,{error:H,onDismiss:()=>B(null)}),(0,t.jsxs)("div",{className:"flex-1 flex flex-col",children:[(0,t.jsxs)("p",{className:"text-sm text-gray-600 mb-3",children:["Configure infra-specific settings for this workspace. Leave empty to use all accessible infrastructure. Refer to"," ",(0,t.jsx)("a",{href:"https://docs.skypilot.co/en/latest/admin/workspaces.html#configuration",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600",children:"SkyPilot Docs"})," ","for more details."]}),(0,t.jsxs)("div",{className:"mb-4",children:[(0,t.jsx)("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Example configuration:"}),(0,t.jsx)("div",{className:"p-3 bg-gray-50 border rounded-lg",children:(0,t.jsx)("pre",{className:"text-xs font-mono text-gray-600 whitespace-pre-wrap",children:"".concat(s||"my-workspace",":\n private: true\n allowed_users:\n - user1@mydomain.com\n - user2@mydomain.com\n gcp:\n project_id: xxx\n disabled: false\n kubernetes:\n allowed_contexts:\n - context-1")})})]}),(0,t.jsx)(f.g,{value:w,onChange:e=>er(e.target.value),className:"font-mono text-sm flex-1 resize-none",style:{minHeight:"350px"},spellCheck:!1,placeholder:"# Enter workspace configuration in YAML format"}),(0,t.jsx)("div",{className:"flex justify-end space-x-3 pt-3 border-gray-200",children:(0,t.jsxs)(h.z,{onClick:el,disabled:O||H||_,className:"inline-flex items-center bg-sky-600 hover:bg-sky-700 text-white",children:[(0,t.jsx)(N.Z,{className:"w-4 h-4 mr-1.5"}),O?"Applying...":"Apply"]})})]})]})})]})})]})]}),(0,t.jsx)(k.Vq,{open:q.showDialog,onOpenChange:ec,children:(0,t.jsxs)(k.cZ,{className:"sm:max-w-md",children:[(0,t.jsxs)(k.fK,{className:"",children:[(0,t.jsx)(k.$N,{children:"Delete Workspace"}),(0,t.jsxs)(k.Be,{children:['Are you sure you want to delete workspace "',s,'"? This action cannot be undone.']})]}),q.error&&(0,t.jsx)(L.X,{error:q.error,title:"Deletion Failed",onDismiss:()=>K(e=>({...e,error:null}))}),(0,t.jsxs)(k.cN,{className:"",children:[(0,t.jsx)(h.z,{variant:"outline",onClick:ec,disabled:q.deleting,children:"Cancel"}),(0,t.jsx)(h.z,{variant:"destructive",onClick:en,disabled:q.deleting,children:q.deleting?"Deleting...":"Delete"})]})]})})]})]})}}}]);
@@ -0,0 +1,6 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1871],{39037:function(e,s,t){t.r(s),t.d(s,{ClusterTable:function(){return _},Clusters:function(){return I},Status2Actions:function(){return F},enabledActions:function(){return H},handleVSCodeConnection:function(){return O}});var r=t(85893),l=t(67294),a=t(11163),n=t(55739),i=t(36989),c=t(41664),o=t.n(c),u=t(30803),d=t(37673),h=t(68764),x=t(23266),p=t(17324),m=t(94545),f=t(13626),j=t(60998);/**
2
+ * @license lucide-react v0.407.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */let v=(0,j.Z)("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]),g=(0,j.Z)("SquareCode",[["path",{d:"M10 9.5 8 12l2 2.5",key:"3mjy60"}],["path",{d:"m14 9.5 2 2.5-2 2.5",key:"1bir2l"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);t(9353);var y=t(92128),w=t(99307),b=t(23001),k=t(88950),N=t(6378),C=t(36856);t(1272);var S=t(20546);let L=[{label:"Status",value:"status"},{label:"Cluster",value:"cluster"},{label:"User",value:"user"},{label:"Workspace",value:"workspace"},{label:"Infra",value:"infra"}],M=(e,s)=>{let t="",r="";return e>=0&&(t=e+"m",r=" "),s&&(t+="".concat(r,"(down)")),""===t&&(t="-"),t},R=(e,s)=>{if(e&&e.includes("@")){let t=e.split("@")[0];return s&&s!==t?"".concat(t," (").concat(s,")"):t}let t=e||s||"N/A";return s&&s!==t?"".concat(t," (").concat(s,")"):t},E=e=>{if(!e||0===e)return"-";let s=e=Math.floor(e),t="",r=0;for(let e of[{value:31536e3,label:"y"},{value:2592e3,label:"mo"},{value:86400,label:"d"},{value:3600,label:"h"},{value:60,label:"m"},{value:1,label:"s"}])if(s>=e.value&&r<2){let l=Math.floor(s/e.value);t+="".concat(l).concat(e.label," "),s%=e.value,r++}return t.trim()||"0s"};function I(){let e=(0,a.useRouter)(),[s,t]=(0,l.useState)(!1),c=l.useRef(null),[u,d]=(0,l.useState)(!1),[h,m]=(0,l.useState)(!1),[j,v]=(0,l.useState)(null),[g,w]=(0,l.useState)(()=>!!e.isReady&&"true"===e.query.history),[S,M]=(0,l.useState)(!0),[E,I]=(0,l.useState)(()=>{if(e.isReady){let s=e.query.historyDays;if(s&&"string"==typeof s&&["1","5","10","30"].includes(s))return parseInt(s)}return 1}),O=(0,b.X)(),[q,H]=(0,l.useState)([]),[W,F]=(0,l.useState)({status:[],cluster:[],user:[],workspace:[],infra:[]}),[A,D]=(0,l.useState)(!1);(0,l.useEffect)(()=>{if(e.isReady){U();let s="true"===e.query.history;g!==s&&(M(!1),w(s),setTimeout(()=>M(!0),50));let t=e.query.historyDays;if(t&&"string"==typeof t&&["1","5","10","30"].includes(t)){let e=parseInt(t);E!==e&&I(e)}}},[e.isReady,e.query.history,e.query.historyDays]),(0,l.useEffect)(()=>{(async()=>{try{await C.ZP.preloadForPage("clusters");let e=await N.default.get(p.getWorkspaces),s=Object.keys(e),t=await N.default.get(x.getClusters),r=[...new Set(t.map(e=>e.workspace||"default").filter(e=>e))],l=new Set(s);r.includes("default")&&l.has("default"),r.forEach(e=>l.add(e));let a=[...new Set(t.map(e=>({userId:e.user_hash||e.user,username:e.user})).filter(e=>e.userId)).values()],n=new Map;a.forEach(e=>{n.set(e.userId,{userId:e.userId,username:e.username,display:R(e.username,e.userId)})}),D(!0)}catch(e){console.error("Error fetching data for filters:",e),D(!0)}})()},[]);let P=s=>{let t={...e.query},r=[],l=[],a=[];s.map((e,s)=>{var t;r.push(null!==(t=e.property.toLowerCase())&&void 0!==t?t:""),l.push(e.operator),a.push(e.value)}),t.property=r,t.operator=l,t.value=a,e.replace({pathname:e.pathname,query:t},void 0,{shallow:!0})},Z=s=>{let t={...e.query};t.history=s.toString(),e.replace({pathname:e.pathname,query:t},void 0,{shallow:!0})},B=s=>{let t={...e.query};t.historyDays=s.toString(),e.replace({pathname:e.pathname,query:t},void 0,{shallow:!0})},U=()=>{let s={...e.query},t=s.property,r=s.operator,l=s.value;if(void 0===t)return;let a=[],n=Array.isArray(t)?t.length:1,i=new Map;if(i.set("",""),i.set("status","Status"),i.set("cluster","Cluster"),i.set("user","User"),i.set("workspace","Workspace"),i.set("infra","Infra"),1===n)a.push({property:i.get(t),operator:r,value:l});else for(let e=0;e<n;e++)a.push({property:i.get(t[e]),operator:r[e],value:l[e]});H(a)};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mb-1 min-h-[20px]",children:[(0,r.jsx)("div",{className:"flex items-center gap-2",children:(0,r.jsx)(o(),{href:"/clusters",className:"text-sky-blue hover:underline leading-none text-base",children:"Sky Clusters"})}),(0,r.jsx)("div",{className:"w-full sm:w-auto",children:(0,r.jsx)(V,{propertyList:L,valueList:W,setFilters:H,updateURLParams:P,placeholder:"Filter clusters"})}),(0,r.jsxs)("div",{className:"flex items-center gap-2 ml-auto",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("label",{className:"flex items-center cursor-pointer",children:[(0,r.jsx)("input",{type:"checkbox",checked:g,onChange:e=>{let s=e.target.checked;w(s),Z(s)},className:"sr-only"}),(0,r.jsx)("div",{className:"relative inline-flex h-5 w-9 items-center rounded-full ".concat(S?"transition-colors":""," ").concat(g?"bg-sky-600":"bg-gray-300"),children:(0,r.jsx)("span",{className:"inline-block h-3 w-3 transform rounded-full bg-white ".concat(S?"transition-transform":""," ").concat(g?"translate-x-5":"translate-x-1")})}),(0,r.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"Show history"})]}),g&&(0,r.jsxs)(k.Ph,{value:E.toString(),onValueChange:e=>{let s=parseInt(e);I(s),B(s)},children:[(0,r.jsx)(k.i4,{className:"w-24 h-8 text-xs",children:(0,r.jsx)(k.ki,{})}),(0,r.jsxs)(k.Bw,{children:[(0,r.jsx)(k.Ql,{value:"1",children:"1 day"}),(0,r.jsx)(k.Ql,{value:"5",children:"5 days"}),(0,r.jsx)(k.Ql,{value:"10",children:"10 days"}),(0,r.jsx)(k.Ql,{value:"30",children:"30 days"})]})]})]}),s&&(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(n.Z,{size:15,className:"mt-0"}),(0,r.jsx)("span",{className:"ml-2 text-gray-500 text-sm",children:"Loading..."})]}),(0,r.jsxs)("button",{onClick:()=>{N.default.invalidate(x.getClusters),N.default.invalidate(p.getWorkspaces),g&&N.default.invalidate(x.uR),D(!1),C.ZP.preloadForPage("clusters",{force:!0}).then(()=>{D(!0),c.current&&c.current()})},disabled:s,className:"text-sky-blue hover:text-sky-blue-bright flex items-center",children:[(0,r.jsx)(f.Z,{className:"h-4 w-4 mr-1.5"}),!O&&(0,r.jsx)("span",{children:"Refresh"})]})]})]}),(0,r.jsx)(z,{filters:q,setFilters:H,updateURLParams:P}),(0,r.jsx)(_,{refreshInterval:i.yc,setLoading:t,refreshDataRef:c,filters:q,showHistory:g,historyDays:E,onOpenSSHModal:e=>{v(e),d(!0)},onOpenVSCodeModal:e=>{v(e),m(!0)},setOptionValues:F,preloadingComplete:A}),(0,r.jsx)(y.Oh,{isOpen:u,onClose:()=>d(!1),cluster:j}),(0,r.jsx)(y._R,{isOpen:h,onClose:()=>m(!1),cluster:j})]})}function _(e){let{refreshInterval:s,setLoading:t,refreshDataRef:a,filters:c,showHistory:p,historyDays:f,onOpenSSHModal:j,onOpenVSCodeModal:v,setOptionValues:g,preloadingComplete:y}=e,[b,k]=(0,l.useState)([]),[C,L]=(0,l.useState)({key:null,direction:"ascending"}),[R,I]=(0,l.useState)(!1),[_,O]=(0,l.useState)(!0),[q,H]=(0,l.useState)(1),[W,V]=(0,l.useState)(10),z=e=>{let s={status:[],cluster:[],user:[],workspace:[],infra:[]},t=(e,s)=>{e.includes(s)||e.push(s)};return e.map(e=>{t(s.status,e.status),t(s.cluster,e.cluster),t(s.user,e.user),t(s.workspace,e.workspace),t(s.infra,e.infra)}),s},A=l.useCallback(async()=>{t(!0),I(!0);try{let e=await N.default.get(x.getClusters);if(p){let s=await N.default.get(x.uR,[null,f]),t=e.map(e=>({...e,isHistorical:!1})),r=s.map(e=>({...e,isHistorical:!0})),l=[...t];r.forEach(s=>{e.some(e=>e.cluster_hash===s.cluster_hash)||l.push(s)}),g(z(l)),k(l)}else{let s=e.map(e=>({...e,isHistorical:!1}));g(z(s)),k(s)}}catch(e){console.error("Error fetching cluster data:",e),g(z([])),k([])}t(!1),I(!1),O(!1)},[t,p,f,g]),D=(e,s)=>{var t;let{property:r,operator:l,value:a}=s;if(!a)return!0;if(!r){let s=a.toLowerCase();return Object.values(e).some(e=>null==e?void 0:e.toString().toLowerCase().includes(s))}let n=null===(t=e[r.toLowerCase()])||void 0===t?void 0:t.toString().toLowerCase(),i=a.toString().toLowerCase();switch(l){case"=":return n===i;case":":return null==n?void 0:n.includes(i);default:return!0}},P=l.useMemo(()=>{let e=0===c.length?b:b.filter(e=>{let s=null;for(let t=0;t<c.length;t++){let r=D(e,c[t]);s=null===s?r:s&&r}return s});return(0,m.R0)(e,C.key,C.direction)},[b,C,c]);l.useEffect(()=>{a&&(a.current=A)},[a,A]),(0,l.useEffect)(()=>{k([]);let e=!0;if(y){A();let t=setInterval(()=>{e&&"visible"===window.document.visibilityState&&A()},s);return()=>{e=!1,clearInterval(t)}}return()=>{e=!1}},[s,A,y]),(0,l.useEffect)(()=>{H(1)},[b.length]);let Z=e=>{let s="ascending";C.key===e&&"ascending"===C.direction&&(s="descending"),L({key:e,direction:s})},B=e=>C.key===e?"ascending"===C.direction?" ↑":" ↓":"",U=Math.ceil(P.length/W),Q=(q-1)*W,T=Q+W,X=P.slice(Q,T);return(0,r.jsxs)("div",{children:[(0,r.jsx)(d.Zb,{children:(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg",children:(0,r.jsxs)(h.iA,{className:"min-w-full",children:[(0,r.jsx)(h.xD,{children:(0,r.jsxs)(h.SC,{children:[(0,r.jsxs)(h.ss,{className:"sortable whitespace-nowrap",onClick:()=>Z("status"),children:["Status",B("status")]}),(0,r.jsxs)(h.ss,{className:"sortable whitespace-nowrap",onClick:()=>Z("cluster"),children:["Cluster",B("cluster")]}),(0,r.jsxs)(h.ss,{className:"sortable whitespace-nowrap",onClick:()=>Z("user"),children:["User",B("user")]}),(0,r.jsxs)(h.ss,{className:"sortable whitespace-nowrap",onClick:()=>Z("workspace"),children:["Workspace",B("workspace")]}),(0,r.jsxs)(h.ss,{className:"sortable whitespace-nowrap",onClick:()=>Z("infra"),children:["Infra",B("infra")]}),(0,r.jsxs)(h.ss,{className:"sortable whitespace-nowrap",onClick:()=>Z("resources_str"),children:["Resources",B("resources_str")]}),(0,r.jsxs)(h.ss,{className:"sortable whitespace-nowrap",onClick:()=>Z("time"),children:["Started",B("time")]}),p&&(0,r.jsxs)(h.ss,{className:"sortable whitespace-nowrap",onClick:()=>Z("duration"),children:["Duration",B("duration")]}),(0,r.jsxs)(h.ss,{className:"sortable whitespace-nowrap",onClick:()=>Z("autostop"),children:["Autostop",B("autostop")]}),(0,r.jsx)(h.ss,{className:"md:sticky md:right-0 md:bg-white",children:"Actions"})]})}),(0,r.jsx)(h.RM,{children:R||!y?(0,r.jsx)(h.SC,{children:(0,r.jsx)(h.pj,{colSpan:9,className:"text-center py-6 text-gray-500",children:(0,r.jsxs)("div",{className:"flex justify-center items-center",children:[(0,r.jsx)(n.Z,{size:20,className:"mr-2"}),(0,r.jsx)("span",{children:"Loading..."})]})})}):X.length>0?X.map((e,s)=>(0,r.jsxs)(h.SC,{children:[(0,r.jsx)(h.pj,{children:(0,r.jsx)(w.OE,{status:e.status})}),(0,r.jsx)(h.pj,{children:(0,r.jsx)(o(),{href:"/clusters/".concat(e.isHistorical?e.cluster_hash:e.cluster||e.name),className:"text-blue-600",children:e.cluster||e.name})}),(0,r.jsx)(h.pj,{children:(0,r.jsx)(S.H,{username:e.user,userHash:e.user_hash})}),(0,r.jsx)(h.pj,{children:(0,r.jsx)(o(),{href:"/workspaces",className:"text-gray-700 hover:text-blue-600 hover:underline",children:e.workspace||"default"})}),(0,r.jsx)(h.pj,{children:(0,r.jsx)(i.Md,{content:e.full_infra||e.infra,className:"text-sm text-muted-foreground",children:(0,r.jsxs)("span",{children:[(0,r.jsx)(o(),{href:"/infra",className:"text-blue-600 hover:underline",children:e.cloud}),e.infra.includes("(")&&(0,r.jsx)("span",{children:" "+e.infra.substring(e.infra.indexOf("("))})]})})}),(0,r.jsx)(h.pj,{children:(0,r.jsx)(i.Md,{content:e.resources_str_full||e.resources_str,className:"text-sm text-muted-foreground",children:(0,r.jsx)("span",{children:e.resources_str})})}),(0,r.jsx)(h.pj,{children:(0,r.jsx)(i.Zg,{date:e.time})}),p&&(0,r.jsx)(h.pj,{children:E(e.duration)}),(0,r.jsx)(h.pj,{children:e.isHistorical?"-":M(e.autostop,e.to_down)}),(0,r.jsx)(h.pj,{className:"text-left md:sticky md:right-0 md:bg-white",children:!e.isHistorical&&(0,r.jsx)(F,{cluster:e.cluster,status:e.status,onOpenSSHModal:j,onOpenVSCodeModal:v})})]},s)):(0,r.jsx)(h.SC,{children:(0,r.jsx)(h.pj,{colSpan:9,className:"text-center py-6 text-gray-500",children:p?"No clusters found":"No active clusters"})})})]})})}),b.length>0&&(0,r.jsx)("div",{className:"flex justify-end items-center py-2 px-4 text-sm text-gray-700",children:(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{className:"mr-2",children:"Rows per page:"}),(0,r.jsxs)("div",{className:"relative inline-block",children:[(0,r.jsxs)("select",{value:W,onChange:e=>{V(parseInt(e.target.value,10)),H(1)},className:"py-1 pl-2 pr-6 appearance-none outline-none cursor-pointer border-none bg-transparent",style:{minWidth:"40px"},children:[(0,r.jsx)("option",{value:10,children:"10"}),(0,r.jsx)("option",{value:30,children:"30"}),(0,r.jsx)("option",{value:50,children:"50"}),(0,r.jsx)("option",{value:100,children:"100"}),(0,r.jsx)("option",{value:200,children:"200"})]}),(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-gray-500 absolute right-0 top-1/2 transform -translate-y-1/2 pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]})]}),(0,r.jsx)("div",{children:"".concat(Q+1," - ").concat(Math.min(T,P.length)," of ").concat(P.length)}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)(u.z,{variant:"ghost",size:"icon",onClick:()=>{H(e=>Math.max(e-1,1))},disabled:1===q,className:"text-gray-500 h-8 w-8 p-0",children:(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"chevron-left",children:(0,r.jsx)("path",{d:"M15 18l-6-6 6-6"})})}),(0,r.jsx)(u.z,{variant:"ghost",size:"icon",onClick:()=>{H(e=>Math.min(e+1,U))},disabled:q===U||0===U,className:"text-gray-500 h-8 w-8 p-0",children:(0,r.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"chevron-right",children:(0,r.jsx)("path",{d:"M9 18l6-6-6-6"})})})]})]})})]})}let O=(e,s)=>{s&&s(e)},q=(e,s)=>{s?s(e):window.open("ssh://".concat(e))},H=e=>"RUNNING"===e?["connect","VSCode"]:[],W={connect:(0,r.jsx)(v,{className:"w-4 h-4 text-gray-500 inline-block"}),VSCode:(0,r.jsx)(g,{className:"w-4 h-4 text-gray-500 inline-block"})};function F(e){let{withLabel:s=!1,cluster:t,status:l,onOpenSSHModal:a,onOpenVSCodeModal:n}=e,c=H(l),o=(0,b.X)(),u=e=>{switch(e){case"connect":q(t,a);break;case"VSCode":O(t,n);break;default:return}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{className:"flex items-center space-x-4",children:Object.entries(W).map(e=>{let t,l,[a,n]=e;switch(a){case"connect":t="Connect",l="Connect with SSH";break;case"VSCode":t="VSCode",l="Open in VS Code"}return(s||(t=""),c.includes(a))?(0,r.jsx)(i.WH,{content:l,className:"capitalize text-sm text-muted-foreground",children:(0,r.jsxs)("button",{onClick:()=>u(a),className:"text-sky-blue hover:text-sky-blue-bright font-medium inline-flex items-center",children:[n,!o&&(0,r.jsx)("span",{className:"ml-1.5",children:t})]})},a):(0,r.jsx)(i.WH,{content:l,className:"capitalize text-sm text-muted-foreground",children:(0,r.jsxs)("span",{className:"opacity-30 flex items-center cursor-not-allowed text-sm",title:a,children:[n,!o&&(0,r.jsx)("span",{className:"ml-1.5",children:t})]})},a)})})})}let V=e=>{let{propertyList:s=[],valueList:t,setFilters:a,updateURLParams:n,placeholder:i="Filter clusters"}=e,c=(0,l.useRef)(null),o=(0,l.useRef)(null),[u,d]=(0,l.useState)(!1),[h,x]=(0,l.useState)(""),[p,m]=(0,l.useState)("status"),[f,j]=(0,l.useState)([]);(0,l.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&c.current&&!c.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]),(0,l.useEffect)(()=>{let e=[];if(t&&"object"==typeof t)switch(p){case"status":e=t.status||[];break;case"user":e=t.user||[];break;case"cluster":e=t.cluster||[];break;case"workspace":e=t.workspace||[];break;case"infra":e=t.infra||[]}""!==h.trim()&&(e=e.filter(e=>e&&e.toString().toLowerCase().includes(h.toLowerCase()))),j(e)},[p,t,h]);let v=e=>{let t=s.find(s=>s.value===e);return t?t.label:e},g=e=>{a(s=>{let t=[...s,{property:v(p),operator:":",value:e}];return n(t),t}),d(!1),x(""),c.current.focus()};return(0,r.jsxs)("div",{className:"flex flex-row border border-gray-300 rounded-md overflow-visible",children:[(0,r.jsx)("div",{className:"border-r border-gray-300 flex-shrink-0",children:(0,r.jsxs)(k.Ph,{onValueChange:m,value:p,children:[(0,r.jsx)(k.i4,{"aria-label":"Filter Property",className:"focus:ring-0 focus:ring-offset-0 border-none rounded-l-md rounded-r-none w-20 sm:w-24 md:w-32 h-8 text-xs sm:text-sm",children:(0,r.jsx)(k.ki,{placeholder:"Status"})}),(0,r.jsx)(k.Bw,{children:s.map((e,s)=>(0,r.jsx)(k.Ql,{value:e.value,children:e.label},"property-item-".concat(s)))})]})}),(0,r.jsxs)("div",{className:"relative flex-1",children:[(0,r.jsx)("input",{type:"text",ref:c,placeholder:i,value:h,onChange:e=>{x(e.target.value),u||d(!0)},onFocus:()=>{d(!0)},onKeyDown:e=>{"Enter"===e.key&&""!==h.trim()?(a(e=>{let s=[...e,{property:v(p),operator:":",value:h}];return n(s),s}),x(""),d(!1)):"Escape"===e.key&&(d(!1),c.current.blur())},className:"h-8 w-full sm:w-96 px-3 pr-8 text-sm border-none rounded-l-none rounded-r-md focus:ring-0 focus:outline-none",autoComplete:"off"}),h&&(0,r.jsx)("button",{onClick:()=>{x(""),d(!1)},className:"absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600",title:"Clear filter",tabIndex:-1,children:(0,r.jsx)("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),u&&f.length>0&&(0,r.jsx)("div",{ref:o,className:"absolute z-50 mt-1 w-full bg-white border border-gray-200 rounded-md shadow-lg max-h-60 overflow-y-auto",style:{zIndex:9999},children:f.map((e,s)=>(0,r.jsx)("div",{className:"px-3 py-2 cursor-pointer hover:bg-gray-50 text-sm ".concat(s!==f.length-1?"border-b border-gray-100":""),onClick:()=>g(e),children:(0,r.jsx)("span",{className:"text-sm text-gray-700",children:e})},"".concat(e,"-").concat(s)))})]})]})},z=e=>{let{filters:s=[],setFilters:t,updateURLParams:l}=e,a=e=>{t(s=>{let t=s.filter((s,t)=>t!==e);return l(t),t})};return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{className:"flex items-center gap-4 py-2 px-2",children:(0,r.jsxs)("div",{className:"flex flex-wrap items-content gap-2",children:[s.map((e,s)=>(0,r.jsx)(A,{filter:e,onRemove:()=>a(s)},"filteritem-".concat(s))),s.length>0&&(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("button",{onClick:()=>{l([]),t([])},className:"rounded-full px-4 py-1 text-sm text-gray-700 bg-gray-200 hover:bg-gray-300",children:"Clear filters"})})]})})})},A=e=>{let{filter:s,onRemove:t}=e;return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{className:"flex items-center text-blue-600 bg-blue-100 px-1 py-1 rounded-full text-sm",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2",children:[(0,r.jsx)("span",{children:"".concat(s.property," ")}),(0,r.jsx)("span",{children:"".concat(s.operator," ")}),(0,r.jsx)("span",{children:" ".concat(s.value)})]}),(0,r.jsx)("button",{onClick:()=>t(),className:"p-0.5 ml-1 transform text-gray-400 hover:text-gray-600 bg-blue-500 hover:bg-blue-600 rounded-full flex flex-col items-center",title:"Clear filter",children:(0,r.jsx)("svg",{className:"h-3 w-3",fill:"none",stroke:"white",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:5,d:"M6 18L18 6M6 6l12 12"})})})]})})}},12003:function(e,s,t){t.d(s,{j:function(){return n}});var r=t(90512);let l=e=>"boolean"==typeof e?`${e}`:0===e?"0":e,a=r.W,n=(e,s)=>t=>{var r;if((null==s?void 0:s.variants)==null)return a(e,null==t?void 0:t.class,null==t?void 0:t.className);let{variants:n,defaultVariants:i}=s,c=Object.keys(n).map(e=>{let s=null==t?void 0:t[e],r=null==i?void 0:i[e];if(null===s)return null;let a=l(s)||l(r);return n[e][a]}),o=t&&Object.entries(t).reduce((e,s)=>{let[t,r]=s;return void 0===r||(e[t]=r),e},{});return a(e,c,null==s?void 0:null===(r=s.compoundVariants)||void 0===r?void 0:r.reduce((e,s)=>{let{class:t,className:r,...l}=s;return Object.entries(l).every(e=>{let[s,t]=e;return Array.isArray(t)?t.includes({...i,...o}[s]):({...i,...o})[s]===t})?[...e,t,r]:e},[]),null==t?void 0:t.class,null==t?void 0:t.className)}}}]);
@@ -0,0 +1,26 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2755],{81260:function(e,s,t){t.d(s,{Z:function(){return r}});/**
2
+ * @license lucide-react v0.407.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */let r=(0,t(60998).Z)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},47603:function(e,s,t){t.d(s,{Z:function(){return r}});/**
7
+ * @license lucide-react v0.407.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */let r=(0,t(60998).Z)("Trash2",[["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"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]])},1812:function(e,s,t){t.d(s,{X:function(){return l}});var r=t(85893),n=t(67294);let a=e=>{if(!(null==e?void 0:e.message))return"An unexpected error occurred.";let s=e.message;return s.includes("failed:")&&(s=s.split("failed:")[1].trim()),s},l=e=>{let{error:s,title:t="Error",onDismiss:l}=e,[i,o]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{s&&o(!1)},[s]),!s||i)return null;let c="string"==typeof s?s:a(s);return(0,r.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-md p-3 mb-4",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("div",{className:"flex-shrink-0",children:(0,r.jsx)("svg",{className:"h-5 w-5 text-red-400",viewBox:"0 0 20 20",fill:"currentColor",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})})}),(0,r.jsx)("div",{className:"ml-3",children:(0,r.jsxs)("div",{className:"text-sm text-red-800",children:[(0,r.jsxs)("strong",{children:[t,":"]})," ",c]})})]}),(0,r.jsx)("button",{onClick:()=>{o(!0),l&&l()},className:"flex-shrink-0 ml-4 text-red-400 hover:text-red-600 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 focus:ring-offset-red-50 rounded","aria-label":"Dismiss error",children:(0,r.jsx)("svg",{className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]})})}},27669:function(e,s,t){t.r(s),t.d(s,{Users:function(){return K}});var r=t(85893),n=t(67294),a=t(45697),l=t.n(a),i=t(55739),o=t(41664),c=t.n(o),d=t(11163),u=t(30803),m=t(68764),x=t(53081),h=t(23266),p=t(68969),g=t(6378),b=t(36856),f=t(51214),j=t(94545),v=t(36989),y=t(60998);/**
12
+ * @license lucide-react v0.407.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */let w=(0,y.Z)("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]);var N=t(13626),k=t(81260);/**
17
+ * @license lucide-react v0.407.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */let C=(0,y.Z)("EyeOff",[["path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24",key:"1jxqfv"}],["path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68",key:"9wicm4"}],["path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61",key:"1jreej"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]),_=(0,y.Z)("Eye",[["path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z",key:"rwhkz3"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);var S=t(16826),R=t(70282),E=t(43767);/**
22
+ * @license lucide-react v0.407.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */let D=(0,y.Z)("Pen",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]]),I=(0,y.Z)("KeyRound",[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]]);var Z=t(47603),L=t(27325);t(9353);var F=t(23001),U=t(66235),A=t(37673),M=t(47145),T=t(50326),P=t(1812);let z=new Set(t(23015).statusGroups.active),q=(e,s)=>e&&e.includes("@")?e.split("@")[0]:e||"N/A",V=(e,s)=>e&&e.includes("@")?e:s||"-",O=f.nb.REFRESH_INTERVAL,B=e=>{let{message:s,onDismiss:t}=e;return s?(0,r.jsx)("div",{className:"bg-green-50 border border-green-200 rounded p-4 mb-6",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("div",{className:"flex-shrink-0",children:(0,r.jsx)("svg",{className:"h-5 w-5 text-green-400",viewBox:"0 0 20 20",fill:"currentColor",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})})}),(0,r.jsx)("div",{className:"ml-3",children:(0,r.jsx)("p",{className:"text-sm font-medium text-green-800",children:s})})]}),t&&(0,r.jsx)("div",{className:"ml-auto pl-3",children:(0,r.jsx)("div",{className:"-mx-1.5 -my-1.5",children:(0,r.jsxs)("button",{type:"button",onClick:t,className:"inline-flex rounded-md bg-green-50 p-1.5 text-green-500 hover:bg-green-100 focus:outline-none focus:ring-2 focus:ring-green-600 focus:ring-offset-2 focus:ring-offset-green-50",children:[(0,r.jsx)("span",{className:"sr-only",children:"Dismiss"}),(0,r.jsx)("svg",{className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})]})})})]})}):null};function K(){let e=(0,d.useRouter)(),{userEmail:s}=(0,U.Ap)(),[t,a]=(0,n.useState)(!1),l=(0,n.useRef)(null),o=(0,F.X)(),[c,m]=(0,n.useState)(!1),[b,f]=(0,n.useState)({username:"",password:"",role:"user"}),[j,v]=(0,n.useState)(!1),[y,R]=(0,n.useState)({open:!1,message:"",userName:""}),[E,D]=(0,n.useState)(null),[I,Z]=(0,n.useState)(!1),[L,A]=(0,n.useState)(!1),[z,q]=(0,n.useState)(!1),[V,K]=(0,n.useState)(null),[J,W]=(0,n.useState)(!1),[Q,X]=(0,n.useState)(null),[Y,G]=(0,n.useState)("import"),[ee,es]=(0,n.useState)(!1),[et,er]=(0,n.useState)(null),[en,ea]=(0,n.useState)(""),[el,ei]=(0,n.useState)(!1),[eo,ec]=(0,n.useState)(null),[ed,eu]=(0,n.useState)(!1),[em,ex]=(0,n.useState)(null),[eh,ep]=(0,n.useState)(null),[eg,eb]=(0,n.useState)(!1),[ef,ej]=(0,n.useState)(null),[ev,ey]=(0,n.useState)(null),[ew,eN]=(0,n.useState)(void 0),[ek,eC]=(0,n.useState)("users"),[e_,eS]=(0,n.useState)(!1),[eR,eE]=(0,n.useState)(!1),[eD,eI]=(0,n.useState)(null),[eZ,eL]=(0,n.useState)(!1),[eF,eU]=(0,n.useState)(""),[eA,eM]=(0,n.useState)(""),[eT,eP]=(0,n.useState)(()=>{if(e.isReady){let s=e.query.deduplicate;if(void 0!==s)return"true"===s}return!0});(0,n.useEffect)(()=>{if(e.isReady){let s=e.query.deduplicate;if(void 0===s)ez(!0);else{let e="true"===s;eT!==e&&eP(e)}}},[e.isReady,e.query.deduplicate]);let ez=s=>{let t={...e.query};t.deduplicate=s.toString(),e.replace({pathname:e.pathname,query:t},void 0,{shallow:!0})};(0,n.useEffect)(()=>{e.isReady&&("service-accounts"===e.query.tab?eC("service-accounts"):eC("users"))},[e.isReady,e.query.tab]),(0,n.useEffect)(()=>{(async function(){try{let e=await M.x.get("/api/health");if(e.ok){let s=await e.json();eN(!!s.basic_auth_enabled)}else eN(!1)}catch(e){eN(!1)}})()},[]);let eq=(0,n.useCallback)(async()=>{if(E&&Date.now()-E.timestamp<3e5)return E;Z(!0);try{let e=await M.x.get("/users/role");if(!e.ok){let s=await e.json();throw Error(s.detail||"Failed to get user role")}let s=await e.json(),t={role:s.role,name:s.name,id:s.id,timestamp:Date.now()};return D(t),Z(!1),t}catch(e){throw Z(!1),e}},[E]);(0,n.useEffect)(()=>{eq().catch(()=>{console.error("Failed to get user role")})},[eq]);let eV=async(e,s)=>{try{let t=await eq();if("admin"!==t.role)return R({open:!0,message:e,userName:t.name.toLowerCase()}),!1;return s(),!0}catch(e){return console.error("Failed to check user role:",e),R({open:!0,message:"Error: ".concat(e.message),userName:""}),!1}},eO=()=>{g.default.invalidate(x.R),g.default.invalidate(h.getClusters),g.default.invalidate(p.getManagedJobs,[{allUsers:!0,skipFinished:!0,fields:["user_hash","status"]}]),l.current&&l.current()},eB=async()=>{if(!b.username||!b.password){ey(Error("Username and password are required.")),m(!1);return}v(!0),ey(null),ej(null);try{let e=await M.x.post("/users/create",b);if(!e.ok){let s=await e.json();throw Error(s.detail||"Failed to create user")}ej('User "'.concat(b.username,'" created successfully!')),m(!1),f({username:"",password:"",role:"user"}),eO()}catch(e){ey(e),m(!1),f({username:"",password:"",role:"user"})}finally{v(!1)}},eK=async e=>{let s=e.target.files[0];s&&(K(s),X(null))},e$=async()=>{if(!V){alert("Please select a CSV file first.");return}W(!0);try{let e=new FileReader;e.onload=async e=>{try{let s=e.target.result,t=await M.x.post("/users/import",{csv_content:s});if(!t.ok){let e=await t.json();throw Error(e.detail||"Failed to import users")}let r=await t.json(),n="Import completed. ".concat(r.success_count," users created successfully.");r.error_count>0&&(n+="\n".concat(r.error_count," failed."),r.creation_errors.length>0&&(n+="\nErrors: ".concat(r.creation_errors.slice(0,3).join(", ")),r.creation_errors.length>3&&(n+=" and ".concat(r.creation_errors.length-3," more...")))),X({message:n}),r.success_count>0&&eO()}catch(e){alert("Error importing users: ".concat(e.message))}finally{W(!1)}},e.readAsText(V)}catch(e){alert("Error reading file: ".concat(e.message)),W(!1)}},eH=async e=>{er(e),ea(""),es(!0)},eJ=async()=>{if(!en){ey(Error("Please enter a new password."));return}ei(!0),ec(null);try{let e=await M.x.post("/users/update",{user_id:et.userId,password:en});if(!e.ok){let s=await e.json();throw Error(s.detail||"Failed to reset password")}ej('Password reset successfully for user "'.concat(et.usernameDisplay,'"!')),es(!1),er(null),ea("")}catch(e){es(!1),er(null),ea(""),ec(null),ey(e)}finally{ei(!1)}},eW=async()=>{if(em){eb(!0),ep(null);try{let e=await M.x.post("/users/delete",{user_id:em.userId});if(!e.ok){let s=await e.json();throw Error(s.detail||"Failed to delete user")}ej('User "'.concat(em.usernameDisplay,'" deleted successfully!')),eu(!1),ex(null),eO()}catch(e){eu(!1),ex(null),ep(null),ey(e)}finally{eb(!1)}}},eQ=()=>{eu(!1),ex(null)},eX=()=>{es(!1),er(null),ea("")};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,r.jsxs)("div",{className:"text-base flex items-center",children:[(0,r.jsx)("button",{className:"leading-none mr-6 pb-2 px-2 border-b-2 ".concat("users"===ek?"text-sky-blue border-sky-500":"text-gray-500 hover:text-gray-700 border-transparent"),onClick:()=>{eC("users"),e.push("/users",void 0,{shallow:!0})},children:"Users"}),(0,r.jsx)("button",{className:"leading-none pb-2 px-2 border-b-2 ".concat("service-accounts"===ek?"text-sky-blue border-sky-500":"text-gray-500 hover:text-gray-700 border-transparent"),onClick:()=>{eC("service-accounts"),e.push("/users?tab=service-accounts",void 0,{shallow:!0})},children:"Service Accounts"})]}),(0,r.jsxs)("div",{className:"flex items-center",children:[t&&(0,r.jsxs)("div",{className:"flex items-center mr-2",children:[(0,r.jsx)(i.Z,{size:15,className:"mt-0"}),(0,r.jsx)("span",{className:"ml-2 text-gray-500",children:"Loading..."})]}),"users"===ek&&ew&&(null==E?void 0:E.role)==="admin"&&(0,r.jsx)("button",{onClick:async()=>{await eV("cannot create users",()=>{m(!0)})},className:"text-sky-blue hover:text-sky-blue-bright flex items-center rounded px-2 py-1 mr-2",title:"Create New User",children:"+ New User"}),"users"===ek&&ew&&(null==E?void 0:E.role)==="admin"&&(0,r.jsxs)("button",{onClick:async()=>{await eV("cannot import users",()=>{q(!0)})},className:"text-sky-blue hover:text-sky-blue-bright flex items-center rounded px-2 py-1 mr-2",title:"Import/Export Users",children:[(0,r.jsx)(w,{className:"h-4 w-4 mr-1"}),"Import/Export"]}),(0,r.jsxs)("button",{onClick:eO,disabled:t,className:"text-sky-blue hover:text-sky-blue-bright flex items-center",children:[(0,r.jsx)(N.Z,{className:"h-4 w-4 mr-1.5"}),!o&&(0,r.jsx)("span",{children:"Refresh"})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,r.jsxs)("div",{className:"relative flex-1 max-w-md",children:[(0,r.jsx)("input",{type:"text",placeholder:"users"===ek?"Search users by name, email, or role":"Search by service account name, or created by",value:"users"===ek?eF:eA,onChange:e=>{"users"===ek?eU(e.target.value):eM(e.target.value)},className:"h-8 w-full px-3 pr-8 text-sm border border-gray-300 rounded-md focus:ring-1 focus:ring-sky-500 focus:border-sky-500 outline-none"}),("users"===ek&&eF||"service-accounts"===ek&&eA)&&(0,r.jsx)("button",{onClick:()=>{"users"===ek?eU(""):eM("")},className:"absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600",title:"Clear search",children:(0,r.jsx)("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),"users"===ek&&!s&&(0,r.jsxs)("label",{className:"flex items-center cursor-pointer ml-4",children:[(0,r.jsx)("input",{type:"checkbox",checked:eT,onChange:e=>{let s=e.target.checked;eP(s),ez(s)},className:"sr-only"}),(0,r.jsx)("div",{className:"relative inline-flex h-5 w-9 items-center rounded-full transition-colors ".concat(eT?"bg-sky-600":"bg-gray-300"),children:(0,r.jsx)("span",{className:"inline-block h-3 w-3 transform rounded-full bg-white transition-transform ".concat(eT?"translate-x-5":"translate-x-1")})}),(0,r.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"Deduplicate users"})]}),"service-accounts"===ek&&(0,r.jsxs)("button",{onClick:()=>{eV("cannot create service account tokens",()=>{eS(!0)})},className:"ml-4 bg-sky-600 hover:bg-sky-700 text-white flex items-center rounded-md px-3 py-1 text-sm font-medium transition-colors duration-200",title:"Create Service Account",children:[(0,r.jsx)(k.Z,{className:"h-4 w-4 mr-2"}),"Create Service Account"]})]}),(0,r.jsxs)("div",{className:"fixed top-20 right-4 z-[9999] max-w-md",children:[(0,r.jsx)(B,{message:ef,onDismiss:()=>ej(null)}),(0,r.jsx)(P.X,{error:ev,title:"Error",onDismiss:()=>ey(null)})]}),"users"===ek?(0,r.jsx)($,{refreshInterval:O,setLoading:a,refreshDataRef:l,checkPermissionAndAct:eV,roleLoading:I,onResetPassword:eH,onDeleteUser:e=>{eV("cannot delete users",()=>{ex(e),eu(!0)})},basicAuthEnabled:ew,currentUserRole:null==E?void 0:E.role,currentUserId:null==E?void 0:E.id,searchQuery:eF,setSearchQuery:eU,deduplicateUsers:eT}):(0,r.jsx)(H,{checkPermissionAndAct:eV,userRoleCache:E,setCreateSuccess:ej,setCreateError:ey,showCreateDialog:e_,setShowCreateDialog:eS,showRotateDialog:eR,setShowRotateDialog:eE,tokenToRotate:eD,setTokenToRotate:eI,rotating:eZ,setRotating:eL,searchQuery:eA,setSearchQuery:eM}),(0,r.jsx)(T.Vq,{open:c,onOpenChange:e=>{m(e),e||ey(null)},children:(0,r.jsxs)(T.cZ,{className:"sm:max-w-md",children:[(0,r.jsx)(T.fK,{children:(0,r.jsx)(T.$N,{children:"Create User"})}),(0,r.jsxs)("div",{className:"flex flex-col gap-4 py-4",children:[(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Username"}),(0,r.jsx)("input",{className:"border rounded px-3 py-2 w-full",placeholder:"Username",value:b.username,onChange:e=>f({...b,username:e.target.value})})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Password"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("input",{className:"border rounded px-3 py-2 w-full pr-10",placeholder:"Password",type:L?"text":"password",value:b.password,onChange:e=>f({...b,password:e.target.value})}),(0,r.jsx)("button",{type:"button",className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600",onClick:()=>A(!L),children:L?(0,r.jsx)(C,{className:"h-4 w-4"}):(0,r.jsx)(_,{className:"h-4 w-4"})})]})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Role"}),(0,r.jsxs)("select",{className:"border rounded px-3 py-2 w-full",value:b.role,onChange:e=>f({...b,role:e.target.value}),children:[(0,r.jsx)("option",{value:"user",children:"User"}),(0,r.jsx)("option",{value:"admin",children:"Admin"})]})]})]}),(0,r.jsxs)(T.cN,{children:[(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2",onClick:()=>m(!1),disabled:j,children:"Cancel"}),(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-sky-600 text-white hover:bg-sky-700 h-10 px-4 py-2",onClick:eB,disabled:j,children:j?"Creating...":"Create"})]})]})}),(0,r.jsx)(T.Vq,{open:y.open,onOpenChange:e=>{R(s=>({...s,open:e})),e||ey(null)},children:(0,r.jsxs)(T.cZ,{className:"sm:max-w-md transition-all duration-200 ease-in-out",children:[(0,r.jsxs)(T.fK,{children:[(0,r.jsx)(T.$N,{children:"Permission Denied"}),(0,r.jsx)(T.Be,{children:I?(0,r.jsxs)("div",{className:"flex items-center py-2",children:[(0,r.jsx)(i.Z,{size:16,className:"mr-2"}),(0,r.jsx)("span",{children:"Checking permissions..."})]}):(0,r.jsx)(r.Fragment,{children:y.userName?(0,r.jsxs)(r.Fragment,{children:[y.userName," is logged in as non-admin and ",y.message,"."]}):y.message})})]}),(0,r.jsx)(T.cN,{children:(0,r.jsx)(u.z,{variant:"outline",onClick:()=>R(e=>({...e,open:!1})),disabled:I,children:"OK"})})]})}),(0,r.jsx)(T.Vq,{open:z,onOpenChange:e=>{q(e),e||ey(null)},children:(0,r.jsxs)(T.cZ,{className:"sm:max-w-lg",children:[(0,r.jsx)(T.fK,{children:(0,r.jsx)(T.$N,{children:"Import/Export Users"})}),(0,r.jsxs)("div",{className:"flex border-b border-gray-200 mb-4",children:[(0,r.jsx)("button",{className:"px-4 py-2 text-sm font-medium ".concat("import"===Y?"border-b-2 border-sky-500 text-sky-600":"text-gray-500 hover:text-gray-700"),onClick:()=>G("import"),children:"Import"}),(0,r.jsx)("button",{className:"px-4 py-2 text-sm font-medium ".concat("export"===Y?"border-b-2 border-sky-500 text-sky-600":"text-gray-500 hover:text-gray-700"),onClick:()=>G("export"),children:"Export"})]}),(0,r.jsx)("div",{className:"flex flex-col gap-4 py-4",children:"import"===Y?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"CSV File"}),(0,r.jsx)("input",{type:"file",accept:".csv",onChange:eK,className:"border rounded px-3 py-2 w-full"}),(0,r.jsxs)("p",{className:"text-xs text-gray-500",children:["CSV should have columns: username, password, role",(0,r.jsx)("br",{}),"Supports both plain text passwords and exported password hashes."]})]}),Q&&(0,r.jsx)("div",{className:"p-3 bg-green-50 border border-green-200 rounded text-green-700 text-sm",children:Q.message})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Export Users to CSV"}),(0,r.jsx)("p",{className:"text-xs text-gray-500",children:"Download all users as a CSV file with password hashes."}),(0,r.jsxs)("div",{className:"p-3 bg-amber-50 border border-amber-200 rounded",children:[(0,r.jsx)("p",{className:"text-sm text-amber-700",children:"⚠️ This will export all users with columns: username, password (hashed), role"}),(0,r.jsx)("p",{className:"text-xs text-amber-600 mt-1",children:"Password hashes can be imported directly for system backups."})]})]})})}),(0,r.jsxs)(T.cN,{children:[(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2",onClick:()=>q(!1),disabled:J,children:"Cancel"}),"import"===Y?(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-sky-600 text-white hover:bg-sky-700 h-10 px-4 py-2",onClick:e$,disabled:J||!V,children:J?"Importing...":"Import"}):(0,r.jsxs)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-sky-600 text-white hover:bg-sky-700 h-10 px-4 py-2",onClick:async()=>{try{let e=await M.x.get("/users/export");if(!e.ok){let s=await e.json();throw Error(s.detail||"Failed to export users")}let s=await e.json(),t=s.csv_content,r=new Blob([t],{type:"text/csv;charset=utf-8;"}),n=URL.createObjectURL(r),a=document.createElement("a");a.href=n;let l=new Date,i=e=>String(e).padStart(2,"0"),o=l.getFullYear(),c=i(l.getMonth()+1),d=i(l.getDate()),u=i(l.getHours()),m=i(l.getMinutes()),x=i(l.getSeconds());a.download="users_export_".concat(o,"-").concat(c,"-").concat(d,"-").concat(u,"-").concat(m,"-").concat(x,".csv"),a.click(),URL.revokeObjectURL(n),alert("Successfully exported ".concat(s.user_count," users to CSV file."))}catch(e){alert("Error exporting users: ".concat(e.message))}},children:[(0,r.jsx)(S.Z,{className:"h-4 w-4 mr-1"}),"Export"]})]})]})}),(0,r.jsx)(T.Vq,{open:ee,onOpenChange:e=>{e||(eX(),ey(null))},children:(0,r.jsxs)(T.cZ,{className:"sm:max-w-md",children:[(0,r.jsxs)(T.fK,{children:[(0,r.jsx)(T.$N,{children:"Reset Password"}),(0,r.jsxs)(T.Be,{children:["Enter a new password for"," ",(null==et?void 0:et.usernameDisplay)||"this user","."]})]}),(0,r.jsx)("div",{className:"flex flex-col gap-4 py-4",children:(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"New Password"}),(0,r.jsx)("input",{type:"password",className:"border rounded px-3 py-2 w-full",placeholder:"Enter new password",value:en,onChange:e=>ea(e.target.value),autoFocus:!0})]})}),(0,r.jsxs)(T.cN,{children:[(0,r.jsx)(u.z,{variant:"outline",onClick:eX,disabled:el,children:"Cancel"}),(0,r.jsx)(u.z,{variant:"default",onClick:eJ,disabled:el||!en,className:"bg-sky-600 text-white hover:bg-sky-700",children:el?"Resetting...":"Reset Password"})]})]})}),(0,r.jsx)(T.Vq,{open:ed,onOpenChange:e=>{e||(eQ(),ey(null))},children:(0,r.jsxs)(T.cZ,{className:"sm:max-w-md",children:[(0,r.jsxs)(T.fK,{children:[(0,r.jsx)(T.$N,{children:"Delete User"}),(0,r.jsxs)(T.Be,{children:['Are you sure you want to delete user "',(null==em?void 0:em.usernameDisplay)||"this user",'"? This action cannot be undone.']})]}),(0,r.jsxs)(T.cN,{children:[(0,r.jsx)(u.z,{variant:"outline",onClick:eQ,disabled:eg,children:"Cancel"}),(0,r.jsx)(u.z,{variant:"destructive",onClick:eW,disabled:eg,children:eg?"Deleting...":"Delete"})]})]})})]})}function $(e){let{refreshInterval:s,setLoading:t,refreshDataRef:a,checkPermissionAndAct:l,roleLoading:o,onResetPassword:d,onDeleteUser:u,basicAuthEnabled:f,currentUserRole:y,currentUserId:w,searchQuery:N,setSearchQuery:k,deduplicateUsers:C}=e,[_,S]=(0,n.useState)([]),[L,F]=(0,n.useState)(!0),[U,T]=(0,n.useState)(!1),[P,O]=(0,n.useState)({key:"username",direction:"ascending"}),[B,K]=(0,n.useState)(null),[$,H]=(0,n.useState)(""),J=(0,n.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];t&&e&&t(!0),e&&F(!0);try{let s=await g.default.get(x.R),r=(s||[]).map(e=>({...e,usernameDisplay:q(e.username,e.userId),fullEmailID:V(e.username,e.userId),clusterCount:-1,jobCount:-1}));S(r),T(!0),t&&e&&t(!1),e&&F(!1);let[n,a]=await Promise.all([g.default.get(h.getClusters),g.default.get(p.getManagedJobs,[{allUsers:!0,skipFinished:!0,fields:["user_hash","status"]}])]),l=a.jobs||[],i=(s||[]).map(e=>{let s=(n||[]).filter(s=>s.user_hash===e.userId),t=(l||[]).filter(s=>s.user_hash===e.userId&&z.has(s.status)).length;return{...e,usernameDisplay:q(e.username,e.userId),fullEmailID:V(e.username,e.userId),clusterCount:s.length,jobCount:t}});S(i)}catch(s){console.error("Failed to fetch or process user data:",s),S([]),T(!0),t&&e&&t(!1),e&&F(!1)}},[t]);(0,n.useEffect)(()=>{a&&(a.current=()=>J(!0))},[a,J]),(0,n.useEffect)(()=>{(async()=>{T(!1),F(!0),await b.ZP.preloadForPage("users"),J(!0)})();let e=setInterval(()=>{"visible"===window.document.visibilityState&&J(!1)},s);return()=>clearInterval(e)},[J,s]);let W=(0,n.useMemo)(()=>{let e=_;if(null==N?void 0:N.trim()){let s=N.toLowerCase();e=_.filter(e=>{var t,r,n;return(null===(t=e.usernameDisplay)||void 0===t?void 0:t.toLowerCase().includes(s))||(null===(r=e.fullEmailID)||void 0===r?void 0:r.toLowerCase().includes(s))||(null===(n=e.role)||void 0===n?void 0:n.toLowerCase().includes(s))})}if(C){let s={};e.forEach(e=>{let t=e.usernameDisplay;s[t]?(s[t].userIds.push(e.userId),-1!==e.clusterCount&&(-1===s[t].clusterCount?s[t].clusterCount=e.clusterCount:s[t].clusterCount+=e.clusterCount),-1!==e.jobCount&&(-1===s[t].jobCount?s[t].jobCount=e.jobCount:s[t].jobCount+=e.jobCount),e.created_at&&(!s[t].created_at||e.created_at<s[t].created_at)&&(s[t].created_at=e.created_at)):s[t]={...e,userIds:[e.userId],clusterCount:e.clusterCount,jobCount:e.jobCount,created_at:e.created_at}}),e=Object.values(s)}return(0,j.R0)(e,P.key,P.direction)},[_,P,N,C]),Q=e=>{let s="ascending";P.key===e&&"ascending"===P.direction&&(s="descending"),O({key:e,direction:s})},X=e=>P.key===e?"ascending"===P.direction?" ↑":" ↓":"",Y=async(e,s)=>{await l("cannot edit user role",()=>{K(e),H(s)})},G=()=>{K(null),H("")},ee=async e=>{if(!e||!$){console.error("User ID or role is missing."),alert("Error: User ID or role is missing.");return}F(!0);try{let s=await M.x.post("/users/update",{user_id:e,role:$});if(!s.ok){let e=await s.json();throw Error(e.detail||"Failed to update role")}g.default.invalidate(x.R),await J(!0),G()}catch(e){console.error("Failed to update user role:",e),alert("Error updating role: ".concat(e.message))}finally{F(!1)}};return L&&0===_.length&&!U?(0,r.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,r.jsx)(i.Z,{})}):U?W&&0!==W.length?(0,r.jsx)(A.Zb,{children:(0,r.jsx)("div",{className:"overflow-x-auto rounded-lg",children:(0,r.jsxs)(m.iA,{className:"min-w-full",children:[(0,r.jsx)(m.xD,{children:(0,r.jsxs)(m.SC,{children:[(0,r.jsxs)(m.ss,{onClick:()=>Q("usernameDisplay"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Name",X("usernameDisplay")]}),!C&&(0,r.jsxs)(m.ss,{onClick:()=>Q("fullEmailID"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["User ID",X("fullEmailID")]}),!C&&(0,r.jsxs)(m.ss,{onClick:()=>Q("role"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Role",X("role")]}),(0,r.jsxs)(m.ss,{onClick:()=>Q("created_at"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Joined",X("created_at")]}),(0,r.jsxs)(m.ss,{onClick:()=>Q("clusterCount"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Clusters",X("clusterCount")]}),(0,r.jsxs)(m.ss,{onClick:()=>Q("jobCount"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Jobs",X("jobCount")]}),!C&&(f||"admin"===y)&&(0,r.jsx)(m.ss,{className:"whitespace-nowrap w-1/7",children:"Actions"})]})}),(0,r.jsx)(m.RM,{children:W.map(e=>(0,r.jsxs)(m.SC,{children:[(0,r.jsx)(m.pj,{className:"truncate",title:e.username,children:e.usernameDisplay}),!C&&(0,r.jsx)(m.pj,{className:"truncate",title:e.fullEmailID,children:e.fullEmailID}),!C&&(0,r.jsx)(m.pj,{className:"truncate",title:e.role,children:(0,r.jsx)("div",{className:"flex items-center gap-2",children:B===e.userId?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("select",{value:$,onChange:e=>H(e.target.value),className:"block w-auto p-1 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-sky-blue focus:border-sky-blue sm:text-sm",children:[(0,r.jsx)("option",{value:"admin",children:"Admin"}),(0,r.jsx)("option",{value:"user",children:"User"})]}),(0,r.jsx)("button",{onClick:()=>ee(e.userId),className:"text-green-600 hover:text-green-800 p-1",title:"Save",children:(0,r.jsx)(R.Z,{className:"h-4 w-4"})}),(0,r.jsx)("button",{onClick:G,className:"text-gray-500 hover:text-gray-700 p-1",title:"Cancel",children:(0,r.jsx)(E.Z,{className:"h-4 w-4"})})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"capitalize",children:e.role}),"admin"===y&&(0,r.jsx)("button",{onClick:()=>Y(e.userId,e.role),className:"text-blue-600 hover:text-blue-700 p-1",title:"Edit role",children:(0,r.jsx)(D,{className:"h-3 w-3"})})]})})}),(0,r.jsx)(m.pj,{className:"truncate",children:e.created_at?(0,r.jsx)(v.Zg,{date:new Date(1e3*e.created_at)}):"-"}),(0,r.jsx)(m.pj,{children:-1===e.clusterCount?(0,r.jsxs)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-400 rounded text-xs font-medium flex items-center",children:[(0,r.jsx)(i.Z,{size:10,className:"mr-1"}),"Loading..."]}):(0,r.jsx)(c(),{href:"/clusters?user=".concat(encodeURIComponent(e.userId)),className:"px-2 py-0.5 rounded text-xs font-medium transition-colors duration-200 cursor-pointer inline-block ".concat(e.clusterCount>0?"bg-blue-100 text-blue-600 hover:bg-blue-200 hover:text-blue-700":"bg-gray-100 text-gray-500 hover:bg-gray-200 hover:text-gray-700"),title:"View ".concat(e.clusterCount," cluster").concat(1!==e.clusterCount?"s":""," for ").concat(e.usernameDisplay),children:e.clusterCount})}),(0,r.jsx)(m.pj,{children:-1===e.jobCount?(0,r.jsxs)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-400 rounded text-xs font-medium flex items-center",children:[(0,r.jsx)(i.Z,{size:10,className:"mr-1"}),"Loading..."]}):(0,r.jsx)(c(),{href:"/jobs?user=".concat(encodeURIComponent(e.userId)),className:"px-2 py-0.5 rounded text-xs font-medium transition-colors duration-200 cursor-pointer inline-block ".concat(e.jobCount>0?"bg-green-100 text-green-600 hover:bg-green-200 hover:text-green-700":"bg-gray-100 text-gray-500 hover:bg-gray-200 hover:text-gray-700"),title:"View ".concat(e.jobCount," active job").concat(1!==e.jobCount?"s":""," for ").concat(e.usernameDisplay),children:e.jobCount})}),!C&&(f||"admin"===y)&&(0,r.jsx)(m.pj,{className:"relative",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[f&&(0,r.jsx)("button",{onClick:"admin"===y||e.userId===w?async()=>{d(e)}:void 0,className:"admin"===y||e.userId===w?"text-blue-600 hover:text-blue-700 p-1":"text-gray-300 cursor-not-allowed p-1",title:"admin"===y||e.userId===w?"Reset Password":"You can only reset your own password",disabled:"admin"!==y&&e.userId!==w,children:(0,r.jsx)(I,{className:"h-4 w-4"})}),"admin"===y&&(0,r.jsx)("button",{onClick:()=>u(e),className:"text-red-600 hover:text-red-700 p-1",title:"Delete User",children:(0,r.jsx)(Z.Z,{className:"h-4 w-4"})})]})})]},e.userId))})]})})}):(0,r.jsxs)("div",{className:"text-center py-12",children:[(0,r.jsx)("p",{className:"text-lg font-semibold text-gray-500",children:(null==N?void 0:N.trim())?"No users match your search.":"No users found."}),(0,r.jsx)("p",{className:"text-sm text-gray-400 mt-1",children:(null==N?void 0:N.trim())?"Try adjusting your search terms.":"There are currently no users to display."})]}):(0,r.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,r.jsx)(i.Z,{}),(0,r.jsx)("span",{className:"ml-2 text-gray-500",children:"Loading users..."})]})}function H(e){let{checkPermissionAndAct:s,userRoleCache:t,setCreateSuccess:a,setCreateError:l,showCreateDialog:o,setShowCreateDialog:d,showRotateDialog:u,setShowRotateDialog:x,tokenToRotate:b,setTokenToRotate:f,rotating:j,setRotating:y,searchQuery:w,setSearchQuery:k}=e,[C,_]=(0,n.useState)([]),[S,F]=(0,n.useState)(!0),[U,P]=(0,n.useState)(!1),[q,V]=(0,n.useState)(null),[O,B]=(0,n.useState)(null),[K,$]=(0,n.useState)({token_name:"",expires_in_days:30}),[H,J]=(0,n.useState)(""),[W,Q]=(0,n.useState)(!1),[X,Y]=(0,n.useState)(!1),[G,ee]=(0,n.useState)(""),[es,et]=(0,n.useState)(null),[er,en]=(0,n.useState)(null),[ea,el]=(0,n.useState)(null),[ei,eo]=(0,n.useState)(""),[ec,ed]=(0,n.useState)([]),eu=async()=>{try{F(!0);let e=await M.x.get("/users/service-account-tokens");if(!e.ok){console.error("Failed to fetch tokens"),_([]),ed([]);return}let s=await e.json();_(s||[]);let[t,r]=await Promise.all([g.default.get(h.getClusters),g.default.get(p.getManagedJobs,[{allUsers:!0,skipFinished:!0,fields:["user_hash","status"]}])]),n=t||[],a=(null==r?void 0:r.jobs)||[],l=(s||[]).map(e=>{let s=e.service_account_user_id,t=n.filter(e=>e.user_hash===s),r=a.filter(e=>e.user_hash===s&&z.has(e.status));return{...e,clusterCount:t.length,jobCount:r.length,primaryRole:e.service_account_roles&&e.service_account_roles.length>0?e.service_account_roles[0]:"user"}});ed(l)}catch(e){console.error("Error fetching tokens and counts:",e),_([]),ed([])}finally{F(!1)}};(0,n.useEffect)(()=>{eu()},[]);let em=async(e,t)=>{await s("cannot edit service account role",()=>{el(e),eo(t)})},ex=()=>{el(null),eo("")},eh=async e=>{if(!e||!ei){console.error("Token ID or role is missing."),l(Error("Token ID or role is missing."));return}F(!0);try{let s=await M.x.post("/users/service-account-tokens/update-role",{token_id:e,role:ei});if(!s.ok){let e=await s.json();throw Error(e.detail||"Failed to update role")}a("Service account role updated successfully!"),await eu(),ex()}catch(e){console.error("Failed to update service account role:",e),l(e)}finally{F(!1)}},ep=async e=>{try{await navigator.clipboard.writeText(e),ee("Copied!"),setTimeout(()=>ee(""),2e3)}catch(e){console.error("Failed to copy:",e)}},eg=async()=>{if(!K.token_name.trim()){l(Error("Token name is required"));return}Q(!0);try{let e={token_name:K.token_name.trim(),expires_in_days:""===K.expires_in_days?null:K.expires_in_days},s=await M.x.post("/users/service-account-tokens",e);if(s.ok){let e=await s.json();et(e.token),$({token_name:"",expires_in_days:30}),await eu()}else{let e=await s.json();throw Error(e.detail||"Failed to create token")}}catch(e){l(e)}finally{Q(!1)}},eb=async()=>{if(q){Y(!0),B(null);try{let e=await M.x.post("/users/service-account-tokens/delete",{token_id:q.token_id});if(e.ok)a('Service account "'.concat(q.token_name,'" deleted successfully!')),P(!1),V(null),B(null),await eu();else{let s=await e.json();throw Error(s.detail||"Failed to delete service account")}}catch(e){P(!1),V(null),B(null),l(e)}finally{Y(!1)}}},ef=async()=>{if(b){y(!0);try{let e={token_id:b.token_id,expires_in_days:""===H?null:parseInt(H)},s=await M.x.post("/users/service-account-tokens/rotate",e);if(s.ok){let e=await s.json();en(e.token),await eu()}else{let e=await s.json();throw Error(e.detail||"Failed to rotate token")}}catch(e){l(e)}finally{y(!1)}}},ej=ec.filter(e=>{var s,t,r,n;if(!(null==w?void 0:w.trim()))return!0;let a=w.toLowerCase();return(null===(s=e.token_name)||void 0===s?void 0:s.toLowerCase().includes(a))||(null===(t=e.creator_name)||void 0===t?void 0:t.toLowerCase().includes(a))||(null===(r=e.service_account_name)||void 0===r?void 0:r.toLowerCase().includes(a))||(null===(n=e.primaryRole)||void 0===n?void 0:n.toLowerCase().includes(a))});return S&&0===ec.length?(0,r.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,r.jsx)(i.Z,{size:32}),(0,r.jsx)("span",{className:"ml-3",children:"Loading tokens..."})]}):(0,r.jsxs)(r.Fragment,{children:[0===ej.length?(0,r.jsxs)("div",{className:"text-center py-12",children:[(0,r.jsx)(I,{className:"mx-auto h-12 w-12 text-gray-400"}),(0,r.jsx)("h3",{className:"mt-2 text-sm font-medium text-gray-900",children:(null==w?void 0:w.trim())?"No tokens match your search":"No service accounts"}),(0,r.jsx)("p",{className:"mt-1 text-sm text-gray-500",children:(null==w?void 0:w.trim())?"Try adjusting your search terms.":"No service accounts have been created yet."})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(A.Zb,{children:(0,r.jsxs)(m.iA,{children:[(0,r.jsx)(m.xD,{children:(0,r.jsxs)(m.SC,{children:[(0,r.jsx)(m.ss,{children:"Name"}),(0,r.jsx)(m.ss,{children:"Created by"}),(0,r.jsx)(m.ss,{children:"Role"}),(0,r.jsx)(m.ss,{children:"Clusters"}),(0,r.jsx)(m.ss,{children:"Jobs"}),(0,r.jsx)(m.ss,{children:"Created"}),(0,r.jsx)(m.ss,{children:"Last used"}),(0,r.jsx)(m.ss,{children:"Expires"}),(0,r.jsx)(m.ss,{children:"Actions"})]})}),(0,r.jsx)(m.RM,{children:ej.map(e=>(0,r.jsxs)(m.SC,{children:[(0,r.jsx)(m.pj,{className:"truncate",title:e.token_name,children:e.token_name}),(0,r.jsx)(m.pj,{className:"truncate",children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("span",{children:e.creator_name||"Unknown"}),e.creator_user_hash!==(null==t?void 0:t.id)&&(0,r.jsx)("span",{className:"ml-2 px-1.5 py-0.5 text-xs bg-gray-100 text-gray-600 rounded",children:"Other"})]})}),(0,r.jsx)(m.pj,{className:"truncate",children:(0,r.jsx)("div",{className:"flex items-center gap-2",children:ea===e.token_id?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("select",{value:ei,onChange:e=>eo(e.target.value),className:"block w-auto p-1 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-sky-blue focus:border-sky-blue sm:text-sm",children:[(0,r.jsx)("option",{value:"admin",children:"Admin"}),(0,r.jsx)("option",{value:"user",children:"User"})]}),(0,r.jsx)("button",{onClick:()=>eh(e.token_id),className:"text-green-600 hover:text-green-800 p-1",title:"Save",children:(0,r.jsx)(R.Z,{className:"h-4 w-4"})}),(0,r.jsx)("button",{onClick:ex,className:"text-gray-500 hover:text-gray-700 p-1",title:"Cancel",children:(0,r.jsx)(E.Z,{className:"h-4 w-4"})})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"capitalize",children:e.primaryRole}),((null==t?void 0:t.role)==="admin"||e.creator_user_hash===(null==t?void 0:t.id))&&(0,r.jsx)("button",{onClick:()=>em(e.token_id,e.primaryRole),className:"text-blue-600 hover:text-blue-700 p-1",title:"Edit role",children:(0,r.jsx)(D,{className:"h-3 w-3"})})]})})}),(0,r.jsx)(m.pj,{children:(0,r.jsx)(c(),{href:"/clusters?user=".concat(encodeURIComponent(e.service_account_user_id)),className:"px-2 py-0.5 rounded text-xs font-medium transition-colors duration-200 cursor-pointer inline-block ".concat(e.clusterCount>0?"bg-blue-100 text-blue-600 hover:bg-blue-200 hover:text-blue-700":"bg-gray-100 text-gray-500 hover:bg-gray-200 hover:text-gray-700"),title:"View ".concat(e.clusterCount," cluster").concat(1!==e.clusterCount?"s":""," for ").concat(e.token_name),children:e.clusterCount})}),(0,r.jsx)(m.pj,{children:(0,r.jsx)(c(),{href:"/jobs?user=".concat(encodeURIComponent(e.service_account_user_id)),className:"px-2 py-0.5 rounded text-xs font-medium transition-colors duration-200 cursor-pointer inline-block ".concat(e.jobCount>0?"bg-green-100 text-green-600 hover:bg-green-200 hover:text-green-700":"bg-gray-100 text-gray-500 hover:bg-gray-200 hover:text-gray-700"),title:"View ".concat(e.jobCount," active job").concat(1!==e.jobCount?"s":""," for ").concat(e.token_name),children:e.jobCount})}),(0,r.jsx)(m.pj,{className:"truncate",children:e.created_at?(0,r.jsx)(v.Zg,{date:new Date(1e3*e.created_at)}):"Never"}),(0,r.jsx)(m.pj,{className:"truncate",children:e.last_used_at?(0,r.jsx)(v.Zg,{date:new Date(1e3*e.last_used_at)}):"Never"}),(0,r.jsx)(m.pj,{className:"truncate",children:e.expires_at?new Date(1e3*e.expires_at)<new Date?(0,r.jsx)("span",{className:"text-red-600",children:"Expired"}):(0,r.jsx)(v.Zg,{date:new Date(1e3*e.expires_at)}):"Never"}),(0,r.jsx)(m.pj,{children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[((null==t?void 0:t.role)==="admin"||e.creator_user_hash===(null==t?void 0:t.id))&&(0,r.jsx)(v.WH,{content:"Rotate token",className:"capitalize text-sm text-muted-foreground",children:(0,r.jsx)("button",{onClick:()=>{s("cannot rotate service account tokens",()=>{f(e),x(!0)})},className:"text-sky-blue hover:text-sky-blue-bright font-medium inline-flex items-center",children:(0,r.jsx)(N.Z,{className:"h-4 w-4"})})}),((null==t?void 0:t.role)==="admin"||e.creator_user_hash===(null==t?void 0:t.id))&&(0,r.jsx)(v.WH,{content:"Delete ".concat(e.token_name),className:"capitalize text-sm text-muted-foreground",children:(0,r.jsx)("button",{onClick:()=>{s("cannot delete service account tokens",()=>{V(e),P(!0)})},className:"text-red-600 hover:text-red-800 font-medium inline-flex items-center",children:(0,r.jsx)(Z.Z,{className:"h-4 w-4"})})})]})})]},e.token_id))})]})})}),(0,r.jsx)(T.Vq,{open:o,onOpenChange:e=>{d(e),e||(et(null),l(null))},children:(0,r.jsxs)(T.cZ,{className:"sm:max-w-2xl",children:[(0,r.jsxs)(T.fK,{children:[(0,r.jsx)(T.$N,{children:"Create Service Account"}),(0,r.jsx)(T.Be,{children:"Create a new service account with an API token for programmatic access to SkyPilot."})]}),(0,r.jsx)("div",{className:"flex flex-col gap-4 py-4",children:es?(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{className:"p-4 bg-green-50 border border-green-200 rounded-lg",children:[(0,r.jsxs)("div",{className:"flex items-center mb-3",children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-green-900",children:"⚠️ Service account created successfully - save this token now!"}),(0,r.jsx)(v.WH,{content:G?"Copied!":"Copy token",className:"text-muted-foreground",children:(0,r.jsx)("button",{onClick:()=>ep(es),className:"flex items-center text-green-600 hover:text-green-800 transition-colors duration-200 p-1 ml-2",children:G?(0,r.jsx)(R.Z,{className:"w-4 h-4"}):(0,r.jsx)(L.Z,{className:"w-4 h-4"})})})]}),(0,r.jsx)("p",{className:"text-sm text-green-700 mb-3",children:"This service account token will not be shown again. Please copy and store it securely."}),(0,r.jsx)("div",{className:"bg-white border border-green-300 rounded-md p-3",children:(0,r.jsx)("code",{className:"text-sm text-gray-800 font-mono break-all block",children:es})})]})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Service Account Name"}),(0,r.jsx)("input",{className:"border rounded px-3 py-2 w-full",placeholder:"e.g., ci-pipeline, monitoring-system",value:K.token_name,onChange:e=>$({...K,token_name:e.target.value})})]}),(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Expiration (days)"}),(0,r.jsx)("input",{type:"number",className:"border rounded px-3 py-2 w-full",placeholder:"e.g., 30",min:"0",max:"365",value:K.expires_in_days||"",onChange:e=>$({...K,expires_in_days:e.target.value?parseInt(e.target.value):null})}),(0,r.jsx)("p",{className:"text-xs text-gray-500",children:"Leave empty or enter 0 to never expire. Maximum 365 days."})]})]})}),(0,r.jsx)(T.cN,{children:es?(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-sky-600 text-white hover:bg-sky-700 h-10 px-4 py-2",onClick:()=>{d(!1),et(null)},children:"Close"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2",onClick:()=>{d(!1),et(null)},disabled:W,children:"Cancel"}),(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-sky-600 text-white hover:bg-sky-700 h-10 px-4 py-2",onClick:eg,disabled:W||!K.token_name.trim(),children:W?"Creating...":"Create Token"})]})})]})}),(0,r.jsx)(T.Vq,{open:U,onOpenChange:e=>{P(e),e||(V(null),l(null))},children:(0,r.jsxs)(T.cZ,{className:"sm:max-w-md",children:[(0,r.jsxs)(T.fK,{children:[(0,r.jsx)(T.$N,{children:"Delete Service Account Token"}),(0,r.jsxs)(T.Be,{children:['Are you sure you want to delete the service account "',null==q?void 0:q.token_name,'"',(null==q?void 0:q.creator_user_hash)!==(null==t?void 0:t.id)&&(null==t?void 0:t.role)==="admin"?" owned by ".concat(null==q?void 0:q.creator_name):"","? This action cannot be undone and will immediately revoke access for any systems using this token."]})]}),(0,r.jsxs)(T.cN,{children:[(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2",onClick:()=>{P(!1),V(null)},disabled:X,children:"Cancel"}),(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-red-600 text-white hover:bg-red-700 h-10 px-4 py-2",onClick:eb,disabled:X,children:X?"Deleting...":"Delete Token"})]})]})}),(0,r.jsx)(T.Vq,{open:u,onOpenChange:e=>{x(e),e||(f(null),J(""),en(null),l(null))},children:(0,r.jsxs)(T.cZ,{className:"sm:max-w-2xl",children:[(0,r.jsxs)(T.fK,{children:[(0,r.jsx)(T.$N,{children:"Rotate Service Account Token"}),(0,r.jsxs)(T.Be,{children:['Rotate the service account token "',null==b?void 0:b.token_name,'"',(null==b?void 0:b.creator_user_hash)!==(null==t?void 0:t.id)&&(null==t?void 0:t.role)==="admin"?" owned by ".concat(null==b?void 0:b.creator_name):"",". This will generate a new token value and invalidate the current one."]})]}),(0,r.jsx)("div",{className:"flex flex-col gap-4 py-4",children:er?(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{className:"p-4 bg-green-50 border border-green-200 rounded-lg",children:[(0,r.jsxs)("div",{className:"flex items-center mb-3",children:[(0,r.jsx)("h4",{className:"text-sm font-medium text-green-900",children:"\uD83D\uDD04 Service account token rotated successfully - save this new token now!"}),(0,r.jsx)(v.WH,{content:G?"Copied!":"Copy token",className:"text-muted-foreground",children:(0,r.jsx)("button",{onClick:()=>ep(er),className:"flex items-center text-green-600 hover:text-green-800 transition-colors duration-200 p-1 ml-2",children:G?(0,r.jsx)(R.Z,{className:"w-4 h-4"}):(0,r.jsx)(L.Z,{className:"w-4 h-4"})})})]}),(0,r.jsx)("p",{className:"text-sm text-green-700 mb-3",children:"This new token replaces the old one. Please copy and store it securely. The old token is now invalid."}),(0,r.jsx)("div",{className:"bg-white border border-green-300 rounded-md p-3",children:(0,r.jsx)("code",{className:"text-sm text-gray-800 font-mono break-all block",children:er})})]})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"grid gap-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"New Expiration (days)"}),(0,r.jsx)("input",{type:"number",className:"border rounded px-3 py-2 w-full",placeholder:"Leave empty to preserve current expiration",min:"0",max:"365",value:H,onChange:e=>J(e.target.value)}),(0,r.jsx)("p",{className:"text-xs text-gray-500",children:"Leave empty to preserve current expiration. Enter number of days for new expiration, or enter 0 to set to never expire. Maximum 365 days."})]}),(0,r.jsx)("div",{className:"p-3 bg-amber-50 border border-amber-200 rounded",children:(0,r.jsx)("p",{className:"text-sm text-amber-700",children:"⚠️ Any systems using the current token will need to be updated with the new token."})})]})}),(0,r.jsx)(T.cN,{children:er?(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-green-600 text-white hover:bg-green-700 h-10 px-4 py-2",onClick:()=>{x(!1),f(null),J(""),en(null)},children:"Close"}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2",onClick:()=>{x(!1),f(null),J(""),en(null)},disabled:j,children:"Cancel"}),(0,r.jsx)("button",{className:"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-sky-600 text-white hover:bg-sky-700 h-10 px-4 py-2",onClick:ef,disabled:j,children:j?"Rotating...":"Rotate Token"})]})})]})})]})}$.propTypes={refreshInterval:l().number.isRequired,setLoading:l().func.isRequired,refreshDataRef:l().shape({current:l().func}).isRequired,checkPermissionAndAct:l().func.isRequired,roleLoading:l().bool.isRequired,onResetPassword:l().func.isRequired,onDeleteUser:l().func.isRequired,basicAuthEnabled:l().bool,currentUserRole:l().string,currentUserId:l().string}},12003:function(e,s,t){t.d(s,{j:function(){return l}});var r=t(90512);let n=e=>"boolean"==typeof e?`${e}`:0===e?"0":e,a=r.W,l=(e,s)=>t=>{var r;if((null==s?void 0:s.variants)==null)return a(e,null==t?void 0:t.class,null==t?void 0:t.className);let{variants:l,defaultVariants:i}=s,o=Object.keys(l).map(e=>{let s=null==t?void 0:t[e],r=null==i?void 0:i[e];if(null===s)return null;let a=n(s)||n(r);return l[e][a]}),c=t&&Object.entries(t).reduce((e,s)=>{let[t,r]=s;return void 0===r||(e[t]=r),e},{});return a(e,o,null==s?void 0:null===(r=s.compoundVariants)||void 0===r?void 0:r.reduce((e,s)=>{let{class:t,className:r,...n}=s;return Object.entries(n).every(e=>{let[s,t]=e;return Array.isArray(t)?t.includes({...i,...c}[s]):({...i,...c})[s]===t})?[...e,t,r]:e},[]),null==t?void 0:t.class,null==t?void 0:t.className)}}}]);
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3294],{53294:function(e,s,t){t.r(s),t.d(s,{ContextDetails:function(){return D},GPUs:function(){return E},InfrastructureSection:function(){return I}});var a=t(85893),l=t(67294),r=t(55739);t(9353);var n=t(26409),o=t(98418),i=t(13626),c=t(23001),d=t(17853),m=t(32045),u=t(23266),x=t(68969),h=t(29326),g=t(50326),p=t(30803),f=t(42557),y=t(36185),j=t(69123);function b(e){let{isOpen:s,onClose:t,onSave:n,poolData:o=null,isLoading:i=!1}=e,[c,d]=(0,l.useState)(""),[m,u]=(0,l.useState)(""),[x,b]=(0,l.useState)("ubuntu"),[N,v]=(0,l.useState)(null),[w,S]=(0,l.useState)(""),[_,C]=(0,l.useState)({}),k=null!==o;(0,l.useEffect)(()=>{if(k&&o){var e,s,t;d(o.name||""),u(((null===(e=o.config)||void 0===e?void 0:e.hosts)||[]).join("\n")),b((null===(s=o.config)||void 0===s?void 0:s.user)||"ubuntu"),S((null===(t=o.config)||void 0===t?void 0:t.password)||"")}else d(""),u(""),b("ubuntu"),v(null),S("");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"),N||w||(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(N){let s=N.name;await (0,h.hY)(s,N),e.identity_file="~/.sky/ssh_keys/".concat(s)}w&&(e.password=w),n(c,e)}catch(e){console.error("Failed to upload SSH key:",e),C({..._,keyUpload:"Failed to upload SSH key"})}},I=()=>{i||t()};return(0,a.jsx)(g.Vq,{open:s,onOpenChange:I,children:(0,a.jsxs)(g.cZ,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[(0,a.jsx)(g.fK,{children:(0,a.jsx)(g.$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)(y._,{htmlFor:"poolName",children:"Pool Name"}),(0,a.jsx)(f.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)(y._,{htmlFor:"hosts",children:"Hosts (one per line)"}),(0,a.jsx)(j.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)(y._,{htmlFor:"sshUser",children:"SSH User"}),(0,a.jsx)(f.I,{id:"sshUser",placeholder:"ubuntu",value:x,onChange:e=>b(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)(y._,{htmlFor:"keyFile",children:"SSH Private Key File"}),(0,a.jsx)(f.I,{id:"keyFile",type:"file",accept:".pem,.key,id_rsa,id_ed25519",onChange:e=>{var s;return v((null===(s=e.target.files)||void 0===s?void 0:s[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)(y._,{htmlFor:"password",children:"Password (optional, if sudo requires a password)"}),(0,a.jsx)(f.I,{id:"password",type:"password",placeholder:"Leave empty if using passwordless sudo",value:w,onChange:e=>S(e.target.value),className:"placeholder:text-gray-500"})]}),_.auth&&(0,a.jsx)("p",{className:"text-sm text-red-500",children:_.auth})]}),(0,a.jsxs)(g.cN,{children:[(0,a.jsx)(p.z,{variant:"outline",onClick:I,disabled:i,children:"Cancel"}),(0,a.jsx)(p.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)(r.Z,{size:16,className:"mr-2"}),"Saving..."]}):k?"Update Pool":"Create Pool"})]})]})})}var N=t(6378),v=t(36856),w=t(51214),S=t(11163),_=t(41664),C=t.n(_),k=t(36989);t(37673);let P=w.nb.REFRESH_INTERVAL,U=w.MO.NAME_TRUNCATE_LENGTH;function I(e){let{title:s,isLoading:t,isDataLoaded:l,contexts:n,gpus:o,groupedPerContextGPUs:i,groupedPerNodeGPUs:c,handleContextClick:d,contextStats:m={},jobsData:u={},isJobsDataLoading:x=!0,isSSH:h=!1,actionButton:g=null,contextWorkspaceMap:p={}}=e,f=n||[];return t&&0===f.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:s}),(0,a.jsxs)("div",{className:"flex items-center justify-center py-6",children:[(0,a.jsx)(r.Z,{size:24,className:"mr-3"}),(0,a.jsxs)("span",{className:"text-gray-500",children:["Loading ",s,"..."]})]})]})}):l&&0===f.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.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold",children:s}),g]}),(0,a.jsxs)("p",{className:"text-sm text-gray-500",children:["No ",s," found or ",s," is not configured."]})]})}):f.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:s}),(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:[f.length," ",1===f.length?h?"pool":"context":h?"pools":"contexts"]})]}),g]}),(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 border-gray-200 shadow-sm bg-white",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:h?"Node Pool":"Context"}),(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"}),(0,a.jsx)("th",{className:"p-3 text-left font-medium text-gray-600 w-1/4",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(f.length>5?"max-h-[250px] overflow-y-auto block":""),children:f.map(e=>{var s,t;let n=i[e]||[],o=c[e]||[],g=n.reduce((e,s)=>e+(s.gpu_total||0),0),f=h?"ssh/".concat(e.replace(/^ssh-/,"")):"kubernetes/".concat(e),y=m[f]||{clusters:0,jobs:0},j=Object.keys(m).length>0&&m[f]||l,b=i&&Object.keys(i).length>0||l,N=c&&Object.keys(c).length>0||l,v=b?Object.keys(n.reduce((e,s)=>(e[s.gpu_name]=(e[s.gpu_name]||0)+(s.gpu_total||0),e),{})).join(", "):null,w=h?e.replace(/^ssh-/,""):e,S=p[e]||[],_=S.length>0?" (".concat(S.join(", "),")"):"";return(0,a.jsxs)("tr",{className:"hover:bg-gray-50",children:[(0,a.jsx)("td",{className:"p-3",children:(0,a.jsx)(k.Md,{content:"".concat(w).concat(_),className:"text-sm text-muted-foreground",children:(0,a.jsxs)("span",{className:"text-blue-600 hover:underline cursor-pointer",onClick:()=>d(e),children:[w.length>U?"".concat(w.substring(0,Math.floor((U-3)/2)),"...").concat(w.substring(w.length-Math.ceil((U-3)/2))):w,_&&(0,a.jsx)("span",{className:"text-xs text-gray-500 ml-1",children:_})]})})}),(0,a.jsx)("td",{className:"p-3",children:j?y.clusters>0?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded text-xs font-medium",children:y.clusters}):(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:"0"}):(0,a.jsx)("div",{className:"flex items-center justify-center",children:(0,a.jsx)(r.Z,{size:12})})}),(0,a.jsx)("td",{className:"p-3",children:x?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:(0,a.jsx)(r.Z,{size:12})}):(null===(s=u[f])||void 0===s?void 0:s.jobs)?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-green-100 text-green-800 rounded text-xs font-medium",children:null===(t=u[f])||void 0===t?void 0:t.jobs}):(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:"0"})}),(0,a.jsx)("td",{className:"p-3",children:N?(0,a.jsx)("span",{className:0===o.length?"text-gray-400":"",title:0===o.length?"Context may be unavailable or timed out":"",children:0===o.length?"0*":o.length}):(0,a.jsx)("div",{className:"flex items-center justify-center",children:(0,a.jsx)(r.Z,{size:16})})}),(0,a.jsx)("td",{className:"p-3",children:b?v||"-":(0,a.jsx)("div",{className:"flex items-center justify-center",children:(0,a.jsx)(r.Z,{size:16})})}),(0,a.jsx)("td",{className:"p-3",children:b?g:(0,a.jsx)("div",{className:"flex items-center justify-center",children:(0,a.jsx)(r.Z,{size:16})})})]},e)})})]})})}),o&&o.length>0&&(0,a.jsx)("div",{children:(0,a.jsx)("div",{className:"overflow-x-auto rounded-md border border-gray-200 shadow-sm bg-white",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:[o.reduce((e,s)=>e+s.gpu_free,0)," ","of"," ",o.reduce((e,s)=>e+s.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(o.length>5?"max-h-[250px] overflow-y-auto block":""),children:o.map(e=>{let s=e.gpu_total-e.gpu_free,t=e.gpu_total>0?e.gpu_free/e.gpu_total*100:0,l=e.gpu_total>0?s/e.gpu_total*100:0,r=i?Object.values(i).flat().filter(s=>s.gpu_name===e.gpu_name&&(h?s.context.startsWith("ssh-"):!s.context.startsWith("ssh-"))).map(e=>e.gpu_requestable_qty_per_node).filter((e,s,t)=>t.indexOf(e)===s).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:[r||"-"," / 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.jsxs)("div",{className:"flex-1 bg-gray-100 rounded-md h-5 flex overflow-hidden shadow-sm min-w-[100px] w-full",children:[l>0&&(0,a.jsx)("div",{style:{width:"".concat(l,"%")},className:"bg-yellow-500 h-full flex items-center justify-center text-white text-xs font-medium",children:l>15&&"".concat(s," used")}),t>0&&(0,a.jsx)("div",{style:{width:"".concat(t,"%")},className:"bg-green-700 h-full flex items-center justify-center text-white text-xs font-medium",children:t>15&&"".concat(e.gpu_free," free")})]})})})]},e.gpu_name)})})]})})})]})]})}):null}function D(e){let{contextName:s,gpusInContext:t,nodesInContext:n}=e,o=s.startsWith("ssh-"),[i,c]=(0,l.useState)([]),[m,u]=(0,l.useState)("$__all"),[x,h]=(0,l.useState)({from:"now-1h",to:"now"}),[g,p]=(0,l.useState)(!1),[f,y]=(0,l.useState)(!1);(0,l.useEffect)(()=>{(async()=>{y(await (0,d.TO)())})()},[]);let j=(0,l.useCallback)(async()=>{if(f){p(!0);try{let e=(0,d.ki)(),t="in-cluster"===s?"^$":s,a="query="+encodeURIComponent('group by (node) (DCGM_FI_DEV_GPU_TEMP{cluster=~"'.concat(t,'"} or label_replace(amd_gpu_gfx_activity{cluster=~"').concat(t,'"}, "node", "$1", "hostname", "(.*)"))')),l="/api/datasources/proxy/1/api/v1/query?".concat(a);try{let s=await fetch("".concat(e).concat(l),{method:"GET",credentials:"include",headers:{Accept:"application/json"}});if(s.ok){let e=await s.json();if(e.data&&e.data.result&&e.data.result.length>0){let s=e.data.result.map(e=>e.metric.node).filter(Boolean).sort();c(s),console.log("Successfully fetched hosts for cluster ".concat(t||"in-cluster",":"),s)}else console.log("No nodes found for this cluster"),c([])}else console.log("HTTP ".concat(s.status," from ").concat(l,": ").concat(s.statusText)),c([])}catch(e){console.log("Failed to fetch from ".concat(l,":"),e),c([])}}catch(e){console.error("Error fetching available hosts:",e),c([])}finally{p(!1)}}},[f,s]);(0,l.useEffect)(()=>{f&&n&&n.length>0&&j()},[n,f,j]);let b=e=>{let t=(0,d.ki)(),a="in-cluster"===s?"^$":s;return"".concat(t,"/d-solo/skypilot-dcgm-cluster-dashboard/skypilot-dcgm-kubernetes-cluster-dashboard?orgId=1&timezone=browser&var-datasource=prometheus&var-host=").concat(encodeURIComponent(m),"&var-gpu=$__all&var-cluster=").concat(encodeURIComponent(a),"&refresh=5s&theme=light&from=").concat(encodeURIComponent(x.from),"&to=").concat(encodeURIComponent(x.to),"&panelId=").concat(e,"&__feature.dashboardSceneSolo")},N=e=>{h({"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:"Available GPUs"})}),(0,a.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-6",children:t.map(e=>{let s=e.gpu_total-e.gpu_free,t=e.gpu_total>0?e.gpu_free/e.gpu_total*100:0,l=e.gpu_total>0?s/e.gpu_total*100:0;return(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.jsxs)("div",{className:"w-full bg-gray-100 rounded-md h-4 flex overflow-hidden shadow-sm",children:[l>0&&(0,a.jsx)("div",{style:{width:"".concat(l,"%")},className:"bg-yellow-500 h-full flex items-center justify-center text-white text-xs",children:l>15&&"".concat(s," used")}),t>0&&(0,a.jsx)("div",{style:{width:"".concat(t,"%")},className:"bg-green-700 h-full flex items-center justify-center text-white text-xs",children:t>15&&"".concat(e.gpu_free," free")})]})]},e.gpu_name)})}),n&&n.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("h4",{className:"text-lg font-semibold mb-4",children:"Nodes"}),(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"}),(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:"GPU"}),(0,a.jsx)("th",{className:"p-3 text-right font-medium text-gray-600",children:"Availability"})]})}),(0,a.jsx)("tbody",{className:"bg-white divide-y divide-gray-200",children:n.map((e,s)=>(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}),(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:e.gpu_name}),(0,a.jsx)("td",{className:"p-3 whitespace-nowrap text-right text-gray-700",children:"".concat(e.gpu_free," of ").concat(e.gpu_total," free")})]},"".concat(e.node_name,"-").concat(s)))})]})})]}),f&&t&&t.length>0&&!o&&(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:m,onChange:e=>{u(e.target.value)},disabled:g,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"}),i.map(e=>(0,a.jsx)("option",{value:e,children:e},e))]}),g&&(0,a.jsx)("div",{className:"ml-2",children:(0,a.jsx)(r.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:()=>N(e.value),className:"px-2 py-1 text-xs font-medium rounded border transition-colors ".concat(x.from==="now-".concat(e.value)&&"now"===x.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"===m?"All nodes":m," ","• Time: ",x.from," to ",x.to,i.length>0&&(0,a.jsxs)("span",{children:[" ","• ",i.length," nodes available"]})]}):(0,a.jsxs)(a.Fragment,{children:["Cluster:"," ",o?s.replace(/^ssh-/,""):s," ","• Time: ",x.from," to ",x.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:b("6"),width:"100%",height:"400",frameBorder:"0",title:"GPU Utilization",className:"rounded"},"gpu-util-".concat(m,"-").concat(x.from,"-").concat(x.to))})}),(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:b("18"),width:"100%",height:"400",frameBorder:"0",title:"GPU Memory",className:"rounded"},"gpu-memory-".concat(m,"-").concat(x.from,"-").concat(x.to))})}),(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:b("10"),width:"100%",height:"400",frameBorder:"0",title:"GPU Power Consumption",className:"rounded"},"gpu-power-".concat(m,"-").concat(x.from,"-").concat(x.to))})}),(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:b("12"),width:"100%",height:"400",frameBorder:"0",title:"GPU Temperature",className:"rounded"},"gpu-temp-".concat(m,"-").concat(x.from,"-").concat(x.to))})}),(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:b("22"),width:"100%",height:"400",frameBorder:"0",title:"CPU Utilization",className:"rounded"},"cpu-util-".concat(m,"-").concat(x.from,"-").concat(x.to))})}),(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:b("21"),width:"100%",height:"400",frameBorder:"0",title:"Memory Utilization",className:"rounded"},"memory-util-".concat(m,"-").concat(x.from,"-").concat(x.to))})})]})]})]})})})}function F(e){var s;let{poolName:t,gpusInContext:i,nodesInContext:c,handleDeploySSHPool:d,handleEditSSHPool:m,handleDeleteSSHPool:u,poolConfig:x}=e,[f,y]=(0,l.useState)(null),[j,b]=(0,l.useState)(!0),[N,v]=(0,l.useState)({isOpen:!1,action:null,loading:!1}),[w,S]=(0,l.useState)({isOpen:!1,logs:"",isStreaming:!1,deploymentComplete:!1,deploymentSuccess:!1,requestId:null});(0,l.useEffect)(()=>{(async()=>{try{b(!0);let e=await (0,h.IS)(t);y(e)}catch(e){console.error("Failed to fetch SSH Node Pool status:",e),y({pool_name:t,status:"Error",reason:"Failed to fetch status"})}finally{b(!1)}})()},[t]);let{deployDisabled:_}=(()=>{if(!f)return{deployDisabled:!0};let e=f.status;return"Ready"===e?{deployDisabled:!0}:"Error"===e?{deployDisabled:!0}:{deployDisabled:!1}})(),C=async()=>{v({...N,loading:!0});try{if("deploy"===N.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(t)).request_id;S(s=>({...s,requestId:e}));let s=new AbortController;await (0,h.wJ)({requestId:e,signal:s.signal,onNewLog:e=>{S(s=>({...s,logs:s.logs+e}))}}),S(e=>({...e,isStreaming:!1,deploymentComplete:!0,deploymentSuccess:!0})),setTimeout(async()=>{(async()=>{try{let e=await (0,h.IS)(t);y(e)}catch(e){console.error("Failed to fetch SSH Node Pool status after deployment:",e)}})()},1e3)}catch(e){console.error("Deployment failed:",e),S(s=>({...s,isStreaming:!1,deploymentComplete:!0,deploymentSuccess:!1,logs:s.logs+"\nDeployment failed: ".concat(e.message)}))}}else if("delete"===N.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,h.ez)(t)).request_id;S(s=>({...s,requestId:e})),e&&await (0,h.mF)({requestId:e,signal:null,onNewLog:e=>{S(s=>({...s,logs:s.logs+e}))},operationType:"down"}),await u(t),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(s=>({...s,isStreaming:!1,deploymentComplete:!0,deploymentSuccess:!1,logs:s.logs+"\nTeardown failed: ".concat(e.message)}))}}}catch(e){console.error("Action failed:",e),v({...N,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,h.IS)(t);y(e)}catch(e){console.error("Failed to refresh status:",e)}})()},1e3)},U="deploy"===N.action?{title:"Deploy SSH Node Pool",description:'Are you sure you want to deploy SSH Node Pool "'.concat(t,'"?'),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(t,'"?'),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)(n.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)(o.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:t})]}),(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:j?(0,a.jsxs)("div",{className:"flex items-center",children:[(0,a.jsx)(r.Z,{size:16,className:"mr-2"}),(0,a.jsx)("span",{className:"text-gray-500",children:"Loading..."})]}):f?(0,a.jsx)(e=>{let{status:s,reason:t}=e,l="Ready"===s,r="Not Ready"===s?"Click Deploy to set up this node pool":t;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(l?"bg-green-100":"bg-red-100"," ").concat(l?"text-green-800":"text-red-800"),children:s}),!l&&r&&(0,a.jsxs)("span",{className:"text-sm text-gray-600",children:["(",r,")"]})]})},{status:f.status,reason:f.reason}):(0,a.jsx)("span",{className:"text-gray-500",children:"Unknown"})})]})]})})]})}),(0,a.jsx)(D,{contextName:"ssh-".concat(t),gpusInContext:i,nodesInContext:c}),(0,a.jsx)(g.Vq,{open:N.isOpen,onOpenChange:k,children:(0,a.jsxs)(g.cZ,{className:"sm:max-w-md",children:[(0,a.jsxs)(g.fK,{className:"",children:[(0,a.jsx)(g.$N,{className:"",children:U.title}),(0,a.jsx)(g.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,s)=>(0,a.jsx)("p",{className:""===e?"pt-2":"",children:e},s))]})}),(0,a.jsxs)(g.cN,{className:"",children:[(0,a.jsx)(p.z,{variant:"outline",onClick:k,disabled:N.loading,className:"",children:"Cancel"}),(0,a.jsx)(p.z,{onClick:C,disabled:N.loading,className:"deploy"===N.action?"bg-green-600 hover:bg-green-700 text-white":"bg-red-600 hover:bg-red-700 text-white",children:N.loading?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.Z,{size:16,className:"mr-2"}),"deploy"===N.action?"Deploying...":"Deleting..."]}):"deploy"===N.action?"Deploy":"Delete"})]})]})}),(0,a.jsx)(g.Vq,{open:w.isOpen,onOpenChange:w.isStreaming?void 0:P,children:(0,a.jsxs)(g.cZ,{className:"sm:max-w-4xl max-h-[80vh]",children:[(0,a.jsxs)(g.fK,{className:"",children:[(0,a.jsxs)(g.$N,{className:"",children:["Deploying SSH Node Pool: ",t]}),(0,a.jsx)(g.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:(s=w.logs)?s.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)(r.Z,{size:16,className:"mr-2 text-green-400"}),(0,a.jsx)("span",{className:"text-green-400",children:"Streaming logs..."})]})]})}),(0,a.jsx)(g.cN,{className:"",children:(0,a.jsx)(p.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)(r.Z,{size:16,className:"mr-2"}),"Deploying..."]}):"Close"})})]})})]})}function E(){let[e,s]=(0,l.useState)(!0),[t,n]=(0,l.useState)(!0),[o,d]=(0,l.useState)(!0),g=l.useRef(null),p=(0,c.X)(),[f,y]=(0,l.useState)(!1),[j,w]=(0,l.useState)(!1),_=(0,S.useRouter)(),[k,U]=(0,l.useState)([]),[E,H]=(0,l.useState)([]),[A,z]=(0,l.useState)([]),[R,q]=(0,l.useState)([]),[O,M]=(0,l.useState)([]),[Z,G]=(0,l.useState)(0),[L,T]=(0,l.useState)(0),[W,B]=(0,l.useState)({}),[K,$]=(0,l.useState)({}),[J,V]=(0,l.useState)({}),[X,Y]=(0,l.useState)("all"),[Q,ee]=(0,l.useState)([]),[es,et]=(0,l.useState)({}),[ea,el]=(0,l.useState)(!1),[er,en]=(0,l.useState)(null),[eo,ei]=(0,l.useState)(!1),[ec,ed]=(0,l.useState)(!0),[em,eu]=(0,l.useState)({}),[ex,eh]=(0,l.useState)(null),eg=l.useCallback(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{showLoadingIndicators:!0},{showLoadingIndicators:t=!0,forceRefresh:a=!1}=e;t&&(s(!0),n(!0),ei(!0),ed(!0));try{async function l(e){await ep(e),await ej(e)}await Promise.all([l(a),ey(a),ef(a)])}catch(e){console.error("Error in fetchData:",e),V({}),U([]),H([]),z([]),q([]),B({}),$({}),ee([]),y(!0),s(!1),M([]),G(0),T(0),w(!0),et({}),ei(!1),eu({}),ed(!1)}finally{t&&(s(!1),n(!1),ei(!1),ed(!1)),o&&t&&d(!1)}},[o]),ep=async e=>{try{let t=e?await (0,m.Xg)():await N.default.get(m.Xg);if(t){let{workspaces:e,allContextNames:a,allGPUs:l,perContextGPUs:r,perNodeGPUs:n,contextStats:o,contextWorkspaceMap:i}=t;V(e||{}),U(a||[]),H(l||[]),z(r||[]),q(n||[]),B(o||{}),$(i||{});let c=Object.keys(e||{});ee(c.sort()),y(!0),s(!1)}else null===t&&(V({}),U([]),H([]),z([]),q([]),B({}),$({}),ee([]),y(!0),s(!1))}catch(e){console.error("Error in fetchKubernetesData:",e),V({}),U([]),H([]),z([]),q([]),B({}),$({}),ee([]),y(!0),s(!1)}},ef=async e=>{try{let s=e?await (0,x.getManagedJobs)({allUsers:!0,skipFinished:!0,fields:["cloud","region"]}):await N.default.get(x.getManagedJobs,[{allUsers:!0,skipFinished:!0,fields:["cloud","region"]}]),t=(null==s?void 0:s.jobs)||[];eu(await (0,m.R8)(t)),ed(!1)}catch(e){console.error("Error in fetchManagedJobsData:",e),eu({}),ed(!1)}},ey=async e=>{try{let s=e?await (0,m.ef)():await N.default.get(m.ef,[e]);s?(M(s.clouds||[]),G(s.totalClouds||0),T(s.enabledClouds||0),w(!0)):null===s&&(M([]),G(0),T(0),w(!0))}catch(e){console.error("Error in fetchCloudData:",e),M([]),G(0),T(0),w(!0)}},ej=async e=>{try{let s=e?await (0,h.It)():await N.default.get(h.It);et(s),ei(!1)}catch(e){console.error("Failed to fetch SSH Node Pools:",e),et({}),ei(!1)}},eb=(e,s)=>{en({name:e,config:s}),el(!0)},eN=async e=>{try{await (0,h.MV)(e),await ej(),eh(null),_.push("/infra")}catch(e){throw console.error("Failed to delete SSH Node Pool:",e),e}},ev=async e=>{try{await (0,h._x)(e)}catch(e){throw console.error("Failed to deploy SSH Node Pool:",e),e}},ew=async(e,s)=>{ei(!0);try{let t={...es};t[e]=s,await (0,h.Ri)(t),await ej(),el(!1)}catch(e){console.error("Failed to save SSH Node Pool:",e),alert("Failed to save SSH Node Pool. Please try again.")}finally{ei(!1)}};(0,l.useEffect)(()=>{g.current=eg},[eg]),(0,l.useEffect)(()=>{(async()=>{await v.ZP.preloadForPage("infra"),eg({showLoadingIndicators:!0})})()},[]),(0,l.useEffect)(()=>{let e=!0,s=setInterval(()=>{e&&g.current&&"visible"===window.document.visibilityState&&g.current({showLoadingIndicators:!1})},P);return()=>{e=!1,clearInterval(s)}},[]),(0,l.useEffect)(()=>()=>{y(!1),w(!1),ei(!1),d(!0),ed(!1)},[]);let eS=()=>{N.default.invalidate(u.getClusters),N.default.invalidate(x.getManagedJobs,[{allUsers:!0,skipFinished:!0,fields:["cloud","region"]}]),N.default.invalidate(m.Xg),N.default.invalidate(m.ef,[!1]),N.default.invalidate(h.It),g.current&&g.current({showLoadingIndicators:!0,forceRefresh:!0})};(0,l.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"r"===e.key&&(e.preventDefault(),eS())};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[]),(E||[]).length,(E||[]).reduce((e,s)=>e+s.gpu_total,0),(E||[]).reduce((e,s)=>e+s.gpu_free,0);let e_=l.useMemo(()=>A?A.reduce((e,s)=>{let{context:t}=s;return e[t]||(e[t]=[]),e[t].push(s),e},{}):{},[A]),eC=l.useCallback(e=>"all"===X?e:e.filter(e=>(K[e]||[]).includes(X)),[X,K]),ek=l.useMemo(()=>k&&Array.isArray(k)?eC(k.filter(e=>e.startsWith("ssh-"))):[],[k,eC]),eP=l.useMemo(()=>k&&Array.isArray(k)?eC(k.filter(e=>!e.startsWith("ssh-"))):[],[k,eC]),eU=l.useMemo(()=>{if(!A||!E)return[];let e=new Set;return A.forEach(s=>{s.context.startsWith("ssh-")&&e.add(s.gpu_name)}),E.filter(s=>e.has(s.gpu_name))},[E,A]),eI=l.useMemo(()=>{if(!A||!E)return[];let e=new Set;return A.forEach(s=>{s.context.startsWith("ssh-")||e.add(s.gpu_name)}),E.filter(s=>e.has(s.gpu_name))},[E,A]),eD=l.useMemo(()=>R?R.reduce((e,s)=>{let{context:t}=s;return e[t]||(e[t]=[]),e[t].push(s),e},{}):{},[R]);(0,l.useEffect)(()=>{_.isReady&&_.query.context&&eh(decodeURIComponent(Array.isArray(_.query.context)?_.query.context[0]:_.query.context))},[_.isReady,_.query.context]);let eF=e=>{eh(e);let s="/infra/".concat(encodeURIComponent(e));_.asPath!==s&&_.push(s)},eE=s=>{let t=e_[s]||[],l=eD[s]||[];if(e&&!f)return(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center h-64",children:[(0,a.jsx)(r.Z,{size:32,className:"mb-4"}),(0,a.jsx)("span",{className:"text-gray-500 text-lg",children:"Loading Context..."})]});if(s.startsWith("ssh-")){let e=s.replace(/^ssh-/,"");return(0,a.jsx)(F,{poolName:e,gpusInContext:t,nodesInContext:l,handleDeploySSHPool:ev,handleEditSSHPool:eb,handleDeleteSSHPool:eN,poolConfig:es[e]})}return(0,a.jsx)(D,{contextName:s,gpusInContext:t,nodesInContext:l})},eH=()=>t&&(!O||0===O.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)(r.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:[L," of ",Z," enabled"]})]}),O&&0!==O.length?(0,a.jsx)("div",{className:"overflow-x-auto rounded-md border border-gray-200 shadow-sm bg-white",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-white divide-y divide-gray-200",children:O.map(e=>{let s=j&&void 0!==e.clusters&&void 0!==e.jobs;return(0,a.jsxs)("tr",{className:"hover:bg-gray-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:s?e.clusters>0?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded text-xs font-medium",children:e.clusters}):(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:"0"}):(0,a.jsx)("div",{className:"flex items-center justify-center",children:(0,a.jsx)(r.Z,{size:16})})}),(0,a.jsx)("td",{className:"p-3",children:s?e.jobs>0?(0,a.jsx)("span",{className:"px-2 py-0.5 bg-green-100 text-green-800 rounded text-xs font-medium",children:e.jobs}):(0,a.jsx)("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-500 rounded text-xs font-medium",children:"0"}):(0,a.jsx)("div",{className:"flex items-center justify-center",children:(0,a.jsx)(r.Z,{size:16})})})]},e.name)})})]})}):(0,a.jsx)("p",{className:"text-sm text-gray-500",children:"No enabled clouds available."})]})}),eA=()=>(0,a.jsx)(I,{title:"SSH Node Pool",isLoading:e,isDataLoaded:f,contexts:ek,gpus:eU,groupedPerContextGPUs:e_,groupedPerNodeGPUs:eD,handleContextClick:eF,contextStats:W,jobsData:em,isJobsDataLoading:ec,isSSH:!0,contextWorkspaceMap:K,actionButton:null}),ez=()=>(0,a.jsx)(I,{title:"Kubernetes",isLoading:e,isDataLoaded:f,contexts:eP,gpus:eI,groupedPerContextGPUs:e_,groupedPerNodeGPUs:eD,handleContextClick:eF,contextStats:W,jobsData:em,isJobsDataLoading:ec,isSSH:!1,contextWorkspaceMap:K}),eR=e||t;return(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)(C(),{href:"/infra",className:"text-sky-blue hover:underline ".concat(ex?"":"cursor-default"),children:"Infrastructure"}),ex&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"mx-2 text-gray-500",children:"›"}),ex.startsWith("ssh-")?(0,a.jsx)(C(),{href:"/infra",className:"text-sky-blue hover:underline cursor-pointer",children:"SSH Node Pool"}):(0,a.jsx)(C(),{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:ex.startsWith("ssh-")?ex.replace(/^ssh-/,""):ex})]})]}),(0,a.jsxs)("div",{className:"flex items-center",children:[Q.length>0&&(0,a.jsxs)("div",{className:"flex items-center mr-4",children:[(0,a.jsx)("label",{htmlFor:"workspace-selector",className:"text-sm font-medium text-gray-700 mr-2",children:"Workspace:"}),(0,a.jsxs)("select",{id:"workspace-selector",value:X,onChange:e=>Y(e.target.value),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 Workspaces"}),Q.map(e=>(0,a.jsx)("option",{value:e,children:e},e))]})]}),eR&&(0,a.jsxs)("div",{className:"flex items-center mr-2",children:[(0,a.jsx)(r.Z,{size:15,className:"mt-0"}),(0,a.jsx)("span",{className:"ml-2 text-gray-500",children:"Loading..."})]}),(0,a.jsxs)("button",{onClick:eS,disabled:eR,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"}),!p&&"Refresh"]})]})]}),(()=>{if(ex)return e&&!f?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center h-64",children:[(0,a.jsx)(r.Z,{size:32,className:"mb-4"}),(0,a.jsx)("span",{className:"text-gray-500 text-lg",children:"Loading Context..."})]}):eE(ex);let s=[];s.push({name:"Kubernetes",render:ez,hasActivity:eP.length>0,priority:1}),s.push({name:"Cloud",render:eH,hasActivity:L>0,priority:2}),s.push({name:"SSH Node Pool",render:eA,hasActivity:ek.length>0&&function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e.some(e=>{let t=W[s?"ssh/".concat(e.replace(/^ssh-/,"")):"kubernetes/".concat(e)]||{clusters:0,jobs:0};return t.clusters>0||t.jobs>0})}(ek,!0),priority:3});let t=s.sort((e,s)=>e.hasActivity!==s.hasActivity?e.hasActivity?-1:1:e.priority-s.priority);return(0,a.jsx)(a.Fragment,{children:t.map((e,s)=>(0,a.jsx)(l.Fragment,{children:e.render()},s))})})(),(0,a.jsx)(b,{isOpen:ea,onClose:()=>el(!1),onSave:ew,poolData:er,isLoading:eo})]})}},42557:function(e,s,t){t.d(s,{I:function(){return n}});var a=t(85893),l=t(67294),r=t(32350);let n=l.forwardRef((e,s)=>{let{className:t,type:l,...n}=e;return(0,a.jsx)("input",{type:l,className:(0,r.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",t),ref:s,...n})});n.displayName="Input"},36185:function(e,s,t){t.d(s,{_:function(){return c}});var a=t(85893),l=t(67294),r=t(49102),n=t(12003),o=t(32350);let i=(0,n.j)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),c=l.forwardRef((e,s)=>{let{className:t,...l}=e;return(0,a.jsx)(r.f,{ref:s,className:(0,o.cn)(i(),t),...l})});c.displayName=r.f.displayName},69123:function(e,s,t){t.d(s,{g:function(){return n}});var a=t(85893),l=t(67294),r=t(32350);let n=l.forwardRef((e,s)=>{let{className:t,...l}=e;return(0,a.jsx)("textarea",{className:(0,r.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",t),ref:s,...l})});n.displayName="Textarea"},17853:function(e,s,t){t.d(s,{TO:function(){return r},ki:function(){return n}});let a=null,l=null,r=async()=>null!==a?a:l||(l=(async()=>{try{let e="".concat(window.location.origin,"/grafana"),s=await fetch("".concat(e,"/api/health"),{method:"GET",credentials:"include",headers:{Accept:"application/json"},signal:AbortSignal.timeout(5e3)});return 200==s.status}catch(e){return console.debug("Grafana availability check failed:",e),a=!1,!1}finally{l=null}})()),n=()=>"".concat(window.location.origin,"/grafana")}}]);