skypilot-nightly 1.0.0.dev20251027__py3-none-any.whl → 1.0.0.dev20251101__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 (114) hide show
  1. sky/__init__.py +2 -2
  2. sky/adaptors/aws.py +25 -7
  3. sky/adaptors/coreweave.py +278 -0
  4. sky/backends/backend_utils.py +9 -6
  5. sky/backends/cloud_vm_ray_backend.py +2 -3
  6. sky/check.py +25 -13
  7. sky/client/cli/command.py +52 -24
  8. sky/cloud_stores.py +73 -0
  9. sky/clouds/aws.py +59 -11
  10. sky/core.py +7 -5
  11. sky/dashboard/out/404.html +1 -1
  12. sky/dashboard/out/_next/static/{YP5Vc3ROcDnTGta0XAhcs → 8ixeA0NVQJN8HUdijid8b}/_buildManifest.js +1 -1
  13. sky/dashboard/out/_next/static/chunks/{1141-d5204f35a3388bf4.js → 1141-c3c10e2c6ed71a8f.js} +1 -1
  14. sky/dashboard/out/_next/static/chunks/2755.d6dc6d530fed0b61.js +26 -0
  15. sky/dashboard/out/_next/static/chunks/3294.87a13fba0058865b.js +1 -0
  16. sky/dashboard/out/_next/static/chunks/{3785.538eb23a098fc304.js → 3785.170be320e0060eaf.js} +1 -1
  17. sky/dashboard/out/_next/static/chunks/4282-49b2065b7336e496.js +1 -0
  18. sky/dashboard/out/_next/static/chunks/7615-80aa7b09f45a86d2.js +1 -0
  19. sky/dashboard/out/_next/static/chunks/8969-4ed9236db997b42b.js +1 -0
  20. sky/dashboard/out/_next/static/chunks/9360.10a3aac7aad5e3aa.js +31 -0
  21. sky/dashboard/out/_next/static/chunks/pages/clusters/[cluster]/[job]-ac4a217f17b087cb.js +16 -0
  22. sky/dashboard/out/_next/static/chunks/pages/clusters/{[cluster]-fbf2907ce2bb67e2.js → [cluster]-1704039ccaf997cf.js} +1 -1
  23. sky/dashboard/out/_next/static/chunks/pages/{jobs-0dc34cf9a8710a9f.js → jobs-7eee823559e5cf9f.js} +1 -1
  24. sky/dashboard/out/_next/static/chunks/pages/{users-96d6b8bb2dec055f.js → users-2b172f13f8538a7a.js} +1 -1
  25. sky/dashboard/out/_next/static/chunks/pages/workspaces/{[name]-fb1b4d3bfb047cad.js → [name]-bbfe5860c93470fd.js} +1 -1
  26. sky/dashboard/out/_next/static/chunks/pages/{workspaces-6fc994fa1ee6c6bf.js → workspaces-1891376c08050940.js} +1 -1
  27. sky/dashboard/out/_next/static/chunks/{webpack-585d805f693dbceb.js → webpack-e38d5319cd10a3a0.js} +1 -1
  28. sky/dashboard/out/_next/static/css/0748ce22df867032.css +3 -0
  29. sky/dashboard/out/clusters/[cluster]/[job].html +1 -1
  30. sky/dashboard/out/clusters/[cluster].html +1 -1
  31. sky/dashboard/out/clusters.html +1 -1
  32. sky/dashboard/out/config.html +1 -1
  33. sky/dashboard/out/index.html +1 -1
  34. sky/dashboard/out/infra/[context].html +1 -1
  35. sky/dashboard/out/infra.html +1 -1
  36. sky/dashboard/out/jobs/[job].html +1 -1
  37. sky/dashboard/out/jobs/pools/[pool].html +1 -1
  38. sky/dashboard/out/jobs.html +1 -1
  39. sky/dashboard/out/users.html +1 -1
  40. sky/dashboard/out/volumes.html +1 -1
  41. sky/dashboard/out/workspace/new.html +1 -1
  42. sky/dashboard/out/workspaces/[name].html +1 -1
  43. sky/dashboard/out/workspaces.html +1 -1
  44. sky/data/data_utils.py +92 -1
  45. sky/data/mounting_utils.py +71 -2
  46. sky/data/storage.py +166 -9
  47. sky/global_user_state.py +14 -18
  48. sky/jobs/constants.py +2 -0
  49. sky/jobs/controller.py +62 -67
  50. sky/jobs/file_content_utils.py +80 -0
  51. sky/jobs/log_gc.py +201 -0
  52. sky/jobs/scheduler.py +15 -2
  53. sky/jobs/server/core.py +85 -13
  54. sky/jobs/server/server.py +14 -13
  55. sky/jobs/server/utils.py +28 -10
  56. sky/jobs/state.py +216 -40
  57. sky/jobs/utils.py +65 -28
  58. sky/metrics/utils.py +18 -0
  59. sky/optimizer.py +1 -1
  60. sky/provision/kubernetes/instance.py +88 -19
  61. sky/provision/kubernetes/volume.py +2 -2
  62. sky/schemas/api/responses.py +3 -5
  63. sky/schemas/db/spot_jobs/004_job_file_contents.py +42 -0
  64. sky/schemas/db/spot_jobs/005_logs_gc.py +38 -0
  65. sky/schemas/generated/managed_jobsv1_pb2.py +39 -35
  66. sky/schemas/generated/managed_jobsv1_pb2.pyi +21 -5
  67. sky/serve/replica_managers.py +2 -2
  68. sky/serve/serve_utils.py +9 -2
  69. sky/serve/server/server.py +8 -7
  70. sky/server/common.py +21 -15
  71. sky/server/constants.py +1 -1
  72. sky/server/daemons.py +23 -17
  73. sky/server/requests/executor.py +7 -3
  74. sky/server/requests/payloads.py +2 -0
  75. sky/server/requests/request_names.py +80 -0
  76. sky/server/requests/requests.py +137 -102
  77. sky/server/requests/serializers/decoders.py +0 -6
  78. sky/server/requests/serializers/encoders.py +33 -6
  79. sky/server/server.py +105 -36
  80. sky/server/stream_utils.py +56 -13
  81. sky/setup_files/dependencies.py +2 -0
  82. sky/skylet/constants.py +6 -1
  83. sky/skylet/events.py +7 -0
  84. sky/skylet/services.py +18 -7
  85. sky/ssh_node_pools/server.py +5 -4
  86. sky/task.py +14 -42
  87. sky/templates/kubernetes-ray.yml.j2 +1 -1
  88. sky/templates/nebius-ray.yml.j2 +1 -0
  89. sky/templates/websocket_proxy.py +140 -12
  90. sky/users/permission.py +4 -1
  91. sky/utils/cli_utils/status_utils.py +8 -2
  92. sky/utils/context_utils.py +13 -1
  93. sky/utils/db/migration_utils.py +1 -1
  94. sky/utils/resource_checker.py +4 -1
  95. sky/utils/resources_utils.py +53 -29
  96. sky/utils/schemas.py +23 -4
  97. sky/volumes/server/server.py +4 -3
  98. sky/workspaces/server.py +7 -6
  99. {skypilot_nightly-1.0.0.dev20251027.dist-info → skypilot_nightly-1.0.0.dev20251101.dist-info}/METADATA +53 -37
  100. {skypilot_nightly-1.0.0.dev20251027.dist-info → skypilot_nightly-1.0.0.dev20251101.dist-info}/RECORD +106 -100
  101. sky/dashboard/out/_next/static/chunks/2755.227c84f5adf75c6b.js +0 -26
  102. sky/dashboard/out/_next/static/chunks/3015-2dcace420c8939f4.js +0 -1
  103. sky/dashboard/out/_next/static/chunks/3294.6d5054a953a818cb.js +0 -1
  104. sky/dashboard/out/_next/static/chunks/4282-d2f3ef2fbf78e347.js +0 -1
  105. sky/dashboard/out/_next/static/chunks/8969-0389e2cb52412db3.js +0 -1
  106. sky/dashboard/out/_next/static/chunks/9360.07d78b8552bc9d17.js +0 -31
  107. sky/dashboard/out/_next/static/chunks/pages/clusters/[cluster]/[job]-c815b90e296b8075.js +0 -16
  108. sky/dashboard/out/_next/static/css/4c052b4444e52a58.css +0 -3
  109. /sky/dashboard/out/_next/static/{YP5Vc3ROcDnTGta0XAhcs → 8ixeA0NVQJN8HUdijid8b}/_ssgManifest.js +0 -0
  110. /sky/dashboard/out/_next/static/chunks/pages/{_app-513d332313670f2a.js → _app-bde01e4a2beec258.js} +0 -0
  111. {skypilot_nightly-1.0.0.dev20251027.dist-info → skypilot_nightly-1.0.0.dev20251101.dist-info}/WHEEL +0 -0
  112. {skypilot_nightly-1.0.0.dev20251027.dist-info → skypilot_nightly-1.0.0.dev20251101.dist-info}/entry_points.txt +0 -0
  113. {skypilot_nightly-1.0.0.dev20251027.dist-info → skypilot_nightly-1.0.0.dev20251101.dist-info}/licenses/LICENSE +0 -0
  114. {skypilot_nightly-1.0.0.dev20251027.dist-info → skypilot_nightly-1.0.0.dev20251101.dist-info}/top_level.txt +0 -0
sky/cloud_stores.py CHANGED
@@ -18,6 +18,7 @@ from sky import sky_logging
18
18
  from sky.adaptors import aws
19
19
  from sky.adaptors import azure
20
20
  from sky.adaptors import cloudflare
21
+ from sky.adaptors import coreweave
21
22
  from sky.adaptors import ibm
22
23
  from sky.adaptors import nebius
23
24
  from sky.adaptors import oci
@@ -602,6 +603,77 @@ class NebiusCloudStorage(CloudStorage):
602
603
  return ' && '.join(all_commands)
603
604
 
604
605
 
606
+ class CoreWeaveCloudStorage(CloudStorage):
607
+ """CoreWeave Cloud Storage."""
608
+
609
+ # List of commands to install AWS CLI
610
+ _GET_AWSCLI = [
611
+ 'aws --version >/dev/null 2>&1 || '
612
+ f'{constants.SKY_UV_PIP_CMD} install awscli',
613
+ ]
614
+
615
+ def is_directory(self, url: str) -> bool:
616
+ """Checks if the coreweave object is a directory.
617
+
618
+ In cloud object stores, a "directory" refers to a regular object whose
619
+ name is a prefix of other objects.
620
+
621
+ Args:
622
+ url: coreweave object URL.
623
+ """
624
+ cw = coreweave.resource('s3')
625
+ bucket_name, path = data_utils.split_coreweave_path(url)
626
+ bucket = cw.Bucket(bucket_name)
627
+
628
+ num_objects = 0
629
+ for obj in bucket.objects.filter(Prefix=path):
630
+ num_objects += 1
631
+ if obj.key == path:
632
+ return False
633
+ # If there are more than 1 object in filter, then it is a directory
634
+ if num_objects == 3:
635
+ return True
636
+
637
+ # A directory with few or no items
638
+ return True
639
+
640
+ def make_sync_dir_command(self, source: str, destination: str) -> str:
641
+ """Downloads using AWS CLI."""
642
+ # AWS Sync by default uses 10 threads to upload files to the bucket.
643
+ # To increase parallelism, modify max_concurrent_requests in your
644
+ # aws config file (Default path: ~/.coreweave/cw.config).
645
+ assert 'cw://' in source, 'cw:// is not in source'
646
+ source = source.replace('cw://', 's3://')
647
+ download_via_awscli = (
648
+ 'AWS_SHARED_CREDENTIALS_FILE='
649
+ f'{coreweave.COREWEAVE_CREDENTIALS_PATH} '
650
+ f'AWS_CONFIG_FILE={coreweave.COREWEAVE_CONFIG_PATH} '
651
+ f'{constants.SKY_REMOTE_PYTHON_ENV}/bin/aws s3 '
652
+ 'sync --no-follow-symlinks '
653
+ f'{source} {destination} '
654
+ f'--profile={coreweave.COREWEAVE_PROFILE_NAME}')
655
+
656
+ all_commands = list(self._GET_AWSCLI)
657
+ all_commands.append(download_via_awscli)
658
+ return ' && '.join(all_commands)
659
+
660
+ def make_sync_file_command(self, source: str, destination: str) -> str:
661
+ """Downloads a file using AWS CLI."""
662
+ assert 'cw://' in source, 'cw:// is not in source'
663
+ source = source.replace('cw://', 's3://')
664
+ download_via_awscli = (
665
+ 'AWS_SHARED_CREDENTIALS_FILE='
666
+ f'{coreweave.COREWEAVE_CREDENTIALS_PATH} '
667
+ f'AWS_CONFIG_FILE={coreweave.COREWEAVE_CONFIG_PATH} '
668
+ f'{constants.SKY_REMOTE_PYTHON_ENV}/bin/aws s3 '
669
+ f'cp {source} {destination} '
670
+ f'--profile={coreweave.COREWEAVE_PROFILE_NAME}')
671
+
672
+ all_commands = list(self._GET_AWSCLI)
673
+ all_commands.append(download_via_awscli)
674
+ return ' && '.join(all_commands)
675
+
676
+
605
677
  def get_storage_from_path(url: str) -> CloudStorage:
606
678
  """Returns a CloudStorage by identifying the scheme:// in a URL."""
607
679
  result = urllib.parse.urlsplit(url)
@@ -619,6 +691,7 @@ _REGISTRY = {
619
691
  'cos': IBMCosCloudStorage(),
620
692
  'oci': OciCloudStorage(),
621
693
  'nebius': NebiusCloudStorage(),
694
+ 'cw': CoreWeaveCloudStorage(),
622
695
  # TODO: This is a hack, as Azure URL starts with https://, we should
623
696
  # refactor the registry to be able to take regex, so that Azure blob can
624
697
  # be identified with `https://(.*?)\.blob\.core\.windows\.net`
sky/clouds/aws.py CHANGED
@@ -1,6 +1,7 @@
1
1
  """Amazon Web Services."""
2
2
  import enum
3
3
  import fnmatch
4
+ import functools
4
5
  import hashlib
5
6
  import json
6
7
  import os
@@ -8,7 +9,10 @@ import re
8
9
  import subprocess
9
10
  import time
10
11
  import typing
11
- from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Union
12
+ from typing import (Any, Callable, Dict, Iterator, List, Literal, Optional, Set,
13
+ Tuple, TypeVar, Union)
14
+
15
+ from typing_extensions import ParamSpec
12
16
 
13
17
  from sky import catalog
14
18
  from sky import clouds
@@ -113,6 +117,37 @@ _EFA_DOCKER_RUN_OPTIONS = [
113
117
  _EFA_IMAGE_NAME = 'Deep Learning Base OSS Nvidia Driver GPU AMI' \
114
118
  ' (Ubuntu 22.04) 20250808'
115
119
 
120
+ # For functions that needs caching per AWS profile.
121
+ _AWS_PROFILE_SCOPED_FUNC_CACHE_SIZE = 5
122
+
123
+ T = TypeVar('T')
124
+ P = ParamSpec('P')
125
+
126
+
127
+ def aws_profile_aware_lru_cache(*lru_cache_args,
128
+ scope: Literal['global', 'request'] = 'request',
129
+ **lru_cache_kwargs) -> Callable:
130
+ """Similar to annotations.lru_cache, but automatically includes the
131
+ AWS profile (if set in the workspace config) in the cache key.
132
+ """
133
+
134
+ def decorator(func: Callable[P, T]) -> Callable[P, T]:
135
+
136
+ @annotations.lru_cache(scope, *lru_cache_args, **lru_cache_kwargs)
137
+ def cached_impl(aws_profile, *args, **kwargs):
138
+ del aws_profile # Only used as part of the cache key.
139
+ return func(*args, **kwargs)
140
+
141
+ @functools.wraps(func)
142
+ def wrapper(*args, **kwargs):
143
+ aws_profile = aws.get_workspace_profile()
144
+ return cached_impl(aws_profile, *args, **kwargs)
145
+
146
+ wrapper.cache_clear = cached_impl.cache_clear # type: ignore[attr-defined]
147
+ return wrapper
148
+
149
+ return decorator
150
+
116
151
 
117
152
  def _is_efa_instance_type(instance_type: str) -> bool:
118
153
  """Check if the instance type is in EFA supported instance family."""
@@ -462,7 +497,8 @@ class AWS(clouds.Cloud):
462
497
  return image_size
463
498
 
464
499
  @classmethod
465
- @annotations.lru_cache(scope='request', maxsize=1)
500
+ @aws_profile_aware_lru_cache(scope='request',
501
+ maxsize=_AWS_PROFILE_SCOPED_FUNC_CACHE_SIZE)
466
502
  def get_image_root_device_name(cls, image_id: str,
467
503
  region: Optional[str]) -> str:
468
504
  if image_id.startswith('skypilot:'):
@@ -788,8 +824,9 @@ class AWS(clouds.Cloud):
788
824
  return cls._check_credentials()
789
825
 
790
826
  @classmethod
791
- @annotations.lru_cache(scope='request',
792
- maxsize=1) # Cache since getting identity is slow.
827
+ # Cache since getting identity is slow.
828
+ @aws_profile_aware_lru_cache(scope='request',
829
+ maxsize=_AWS_PROFILE_SCOPED_FUNC_CACHE_SIZE)
793
830
  def _check_credentials(cls) -> Tuple[bool, Optional[str]]:
794
831
  """Checks if the user has access credentials to AWS."""
795
832
 
@@ -924,9 +961,16 @@ class AWS(clouds.Cloud):
924
961
  return AWSIdentityType.SHARED_CREDENTIALS_FILE
925
962
 
926
963
  @classmethod
927
- @annotations.lru_cache(scope='request', maxsize=1)
964
+ @aws_profile_aware_lru_cache(scope='request',
965
+ maxsize=_AWS_PROFILE_SCOPED_FUNC_CACHE_SIZE)
928
966
  def _aws_configure_list(cls) -> Optional[bytes]:
929
- proc = subprocess.run('aws configure list',
967
+ cmd = 'aws configure list'
968
+ # Profile takes precedence over default configs.
969
+ profile = aws.get_workspace_profile()
970
+ if profile is not None:
971
+ # If profile does not exist, we will get returncode 255.
972
+ cmd += f' --profile {profile}'
973
+ proc = subprocess.run(cmd,
930
974
  shell=True,
931
975
  check=False,
932
976
  stdout=subprocess.PIPE,
@@ -936,8 +980,9 @@ class AWS(clouds.Cloud):
936
980
  return proc.stdout
937
981
 
938
982
  @classmethod
939
- @annotations.lru_cache(scope='request',
940
- maxsize=1) # Cache since getting identity is slow.
983
+ # Cache since getting identity is slow.
984
+ @aws_profile_aware_lru_cache(scope='request',
985
+ maxsize=_AWS_PROFILE_SCOPED_FUNC_CACHE_SIZE)
941
986
  def _sts_get_caller_identity(cls) -> Optional[List[List[str]]]:
942
987
  try:
943
988
  sts = aws.client('sts', check_credentials=False)
@@ -1018,8 +1063,9 @@ class AWS(clouds.Cloud):
1018
1063
  return [user_ids]
1019
1064
 
1020
1065
  @classmethod
1021
- @annotations.lru_cache(scope='request',
1022
- maxsize=1) # Cache since getting identity is slow.
1066
+ # Cache since getting identity is slow.
1067
+ @aws_profile_aware_lru_cache(scope='request',
1068
+ maxsize=_AWS_PROFILE_SCOPED_FUNC_CACHE_SIZE)
1023
1069
  def get_user_identities(cls) -> Optional[List[List[str]]]:
1024
1070
  """Returns a [UserId, Account] list that uniquely identifies the user.
1025
1071
 
@@ -1114,6 +1160,7 @@ class AWS(clouds.Cloud):
1114
1160
  # provider of the cluster to be launched in this function and make sure
1115
1161
  # the cluster will not be used for launching clusters in other clouds,
1116
1162
  # e.g. jobs controller.
1163
+
1117
1164
  if self._current_identity_type(
1118
1165
  ) != AWSIdentityType.SHARED_CREDENTIALS_FILE:
1119
1166
  return {}
@@ -1123,7 +1170,8 @@ class AWS(clouds.Cloud):
1123
1170
  if os.path.exists(os.path.expanduser(f'~/.aws/{filename}'))
1124
1171
  }
1125
1172
 
1126
- @annotations.lru_cache(scope='request', maxsize=1)
1173
+ @aws_profile_aware_lru_cache(scope='request',
1174
+ maxsize=_AWS_PROFILE_SCOPED_FUNC_CACHE_SIZE)
1127
1175
  def can_credential_expire(self) -> bool:
1128
1176
  identity_type = self._current_identity_type()
1129
1177
  return (identity_type is not None and
sky/core.py CHANGED
@@ -99,6 +99,7 @@ def status(
99
99
  all_users: bool = False,
100
100
  include_credentials: bool = False,
101
101
  summary_response: bool = False,
102
+ include_handle: bool = True,
102
103
  ) -> List[responses.StatusResponse]:
103
104
  # NOTE(dev): Keep the docstring consistent between the Python API and CLI.
104
105
  """Gets cluster statuses.
@@ -179,7 +180,8 @@ def status(
179
180
  cluster_names=cluster_names,
180
181
  all_users=all_users,
181
182
  include_credentials=include_credentials,
182
- summary_response=summary_response)
183
+ summary_response=summary_response,
184
+ include_handle=include_handle)
183
185
 
184
186
  status_responses = []
185
187
  for cluster in clusters:
@@ -414,12 +416,12 @@ def cost_report(
414
416
  # compatibility
415
417
  num_nodes = record.get('num_nodes', 1)
416
418
  try:
417
- resource_str_simple = resources_utils.format_resource(resources,
418
- simplify=True)
419
+ resource_str_simple, resource_str_full = (
420
+ resources_utils.format_resource(
421
+ resources, simplified_only=abbreviate_response))
419
422
  record['resources_str'] = f'{num_nodes}x{resource_str_simple}'
420
423
  if not abbreviate_response:
421
- resource_str_full = resources_utils.format_resource(
422
- resources, simplify=False)
424
+ assert resource_str_full is not None
423
425
  record[
424
426
  'resources_str_full'] = f'{num_nodes}x{resource_str_full}'
425
427
  except Exception as e: # pylint: disable=broad-except
@@ -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-585d805f693dbceb.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/YP5Vc3ROcDnTGta0XAhcs/_buildManifest.js" defer=""></script><script src="/dashboard/_next/static/YP5Vc3ROcDnTGta0XAhcs/_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":"YP5Vc3ROcDnTGta0XAhcs","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/0748ce22df867032.css" as="style"/><link rel="stylesheet" href="/dashboard/_next/static/css/0748ce22df867032.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-e38d5319cd10a3a0.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-bde01e4a2beec258.js" defer=""></script><script src="/dashboard/_next/static/chunks/pages/_error-c66a4e8afc46f17b.js" defer=""></script><script src="/dashboard/_next/static/8ixeA0NVQJN8HUdijid8b/_buildManifest.js" defer=""></script><script src="/dashboard/_next/static/8ixeA0NVQJN8HUdijid8b/_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":"8ixeA0NVQJN8HUdijid8b","assetPrefix":"/dashboard","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
@@ -1 +1 @@
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();
1
+ self.__BUILD_MANIFEST=function(s,c,a,e,t,f,b,u,n,o,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-9e0df5442b04f7d0.js"],"/clusters/[cluster]":[s,c,a,f,b,j,o,e,t,u,r,n,i,k,h,"static/chunks/6856-5c94d394259cdb6e.js","static/chunks/1871-81adbc5f25dff78f.js","static/chunks/pages/clusters/[cluster]-1704039ccaf997cf.js"],"/clusters/[cluster]/[job]":[s,c,a,f,e,t,n,"static/chunks/pages/clusters/[cluster]/[job]-ac4a217f17b087cb.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-7eee823559e5cf9f.js"],"/jobs/pools/[pool]":[s,c,a,b,o,e,t,u,"static/chunks/pages/jobs/pools/[pool]-e020fd69dbe76cea.js"],"/jobs/[job]":[s,c,a,f,b,o,e,t,u,n,"static/chunks/pages/jobs/[job]-eb5822dac0c9509b.js"],"/users":["static/chunks/pages/users-2b172f13f8538a7a.js"],"/volumes":["static/chunks/pages/volumes-d2af9d22e87cc4ba.js"],"/workspace/new":["static/chunks/pages/workspace/new-3f88a1c7e86a3f86.js"],"/workspaces":["static/chunks/pages/workspaces-1891376c08050940.js"],"/workspaces/[name]":[s,c,a,f,b,j,e,t,u,r,n,i,k,h,"static/chunks/1141-c3c10e2c6ed71a8f.js","static/chunks/pages/workspaces/[name]-bbfe5860c93470fd.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-4ed9236db997b42b.js","static/chunks/9353-cff34f7e773b2e2b.js","static/chunks/6212-7bd06f60ba693125.js","static/chunks/7359-c8d04e06886000b3.js","static/chunks/6990-f6818c84ed8f1c86.js","static/chunks/4282-49b2065b7336e496.js","static/chunks/6601-06114c982db410b6.js","static/chunks/7615-80aa7b09f45a86d2.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();
@@ -8,4 +8,4 @@
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
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"})]})]})})]})]})}}}]);
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(47615),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,26 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2755],{81260:function(e,t,s){s.d(t,{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,s(60998).Z)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},47603:function(e,t,s){s.d(t,{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,s(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,t,s){s.d(t,{X:function(){return l}});var r=s(85893),n=s(67294);let a=e=>{if(!(null==e?void 0:e.message))return"An unexpected error occurred.";let t=e.message;return t.includes("failed:")&&(t=t.split("failed:")[1].trim()),t},l=e=>{let{error:t,title:s="Error",onDismiss:l}=e,[o,i]=(0,n.useState)(!1);if((0,n.useEffect)(()=>{t&&i(!1)},[t]),!t||o)return null;let c="string"==typeof t?t:a(t);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:[s,":"]})," ",c]})})]}),(0,r.jsx)("button",{onClick:()=>{i(!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,t,s){s.r(t),s.d(t,{Users:function(){return H}});var r=s(85893),n=s(67294),a=s(45697),l=s.n(a),o=s(55739),i=s(41664),c=s.n(i),u=s(11163),d=s(30803),m=s(68764),x=s(53081),h=s(23266),p=s(68969),f=s(6378),g=s(36856),b=s(51214),j=s(94545),y=s(36989),v=s(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,v.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=s(13626),k=s(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,v.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,v.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=s(16826),R=s(70282),E=s(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,v.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,v.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 T=s(47603),L=s(27325);s(9353);var U=s(23001),F=s(66235),Z=s(37673),A=s(47145),P=s(50326),O=s(1812),M=s(47615),z=s(10546);let q=new Set(M.statusGroups.active),V=[{label:"Name",value:"name"},{label:"GPU",value:"gpu type"},{label:"Infra",value:"infra"},{label:"User ID",value:"user id"},{label:"Role",value:"role"}],B=(e,t)=>{if(!e)return 0;let s=e;if("string"==typeof e)try{let t=e.replace(/'/g,'"').replace(/None/g,"null");s=JSON.parse(t)}catch(t){return console.error("Failed to parse accelerators string:",e,t),0}if("object"==typeof s&&null!==s){let e=Object.entries(s);return 0===e.length?0:(e.length>1&&console.warn("".concat(t," has ").concat(e.length," accelerator entries:"),s),Number(e[0][1])||0)}return 0},G=(e,t)=>e&&e.includes("@")?e.split("@")[0]:e||"N/A",J=(e,t)=>e&&e.includes("@")?e:t||"-",K=b.nb.REFRESH_INTERVAL,$=e=>{let{message:t,onDismiss:s}=e;return t?(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:t})})]}),s&&(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:s,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 H(){let e=(0,u.useRouter)(),{userEmail:t}=(0,F.Ap)(),[s,a]=(0,n.useState)(!1),l=(0,n.useRef)(null),i=(0,U.X)(),[c,m]=(0,n.useState)(!1),[g,b]=(0,n.useState)({username:"",password:"",role:"user"}),[j,y]=(0,n.useState)(!1),[v,R]=(0,n.useState)({open:!1,message:"",userName:""}),[E,D]=(0,n.useState)(null),[I,T]=(0,n.useState)(!1),[L,Z]=(0,n.useState)(!1),[M,q]=(0,n.useState)(!1),[B,G]=(0,n.useState)(null),[J,H]=(0,n.useState)(!1),[Q,Y]=(0,n.useState)(null),[ee,et]=(0,n.useState)("import"),[es,er]=(0,n.useState)(!1),[en,ea]=(0,n.useState)(null),[el,eo]=(0,n.useState)(""),[ei,ec]=(0,n.useState)(!1),[eu,ed]=(0,n.useState)(null),[em,ex]=(0,n.useState)(!1),[eh,ep]=(0,n.useState)(null),[ef,eg]=(0,n.useState)(null),[eb,ej]=(0,n.useState)(!1),[ey,ev]=(0,n.useState)(null),[ew,eN]=(0,n.useState)(null),[ek,eC]=(0,n.useState)(void 0),[e_,eS]=(0,n.useState)(void 0),[eR,eE]=(0,n.useState)(!0),[eD,eI]=(0,n.useState)("users"),[eT,eL]=(0,n.useState)(!1),[eU,eF]=(0,n.useState)(!1),[eZ,eA]=(0,n.useState)(null),[eP,eO]=(0,n.useState)(!1),[eM,ez]=(0,n.useState)(""),[eq,eV]=(0,n.useState)(""),[eB,eG]=(0,n.useState)([]),[eJ,eK]=(0,n.useState)({name:[],"user id":[],role:[],"gpu type":[],infra:[]}),[e$,eH]=(0,n.useState)(()=>{if(e.isReady){let t=e.query.deduplicate;if(void 0!==t)return"true"===t}return!0});(0,n.useEffect)(()=>{if(e.isReady){let s=e.query.deduplicate;if(void 0===s)eW(!t);else{let e="true"===s;e$!==e&&eH(e)}}},[e.isReady,e.query.deduplicate,t]);let eW=t=>{let s={...e.query};s.deduplicate=t.toString(),e.replace({pathname:e.pathname,query:s},void 0,{shallow:!0})},eX=t=>{(0,z.eG)(e,t)},eQ=new Map([["name","Name"],["user id","User ID"],["role","Role"],["gpu type","GPU"],["infra","Infra"]]);(0,n.useEffect)(()=>{if(e.isReady&&"users"===eD){let t=(0,z.Fu)(e,eQ);t.length>0&&eG(t)}},[e.isReady,eD]),(0,n.useEffect)(()=>{e.isReady&&("service-accounts"===e.query.tab&&e_?eI("service-accounts"):eI("users"))},[e.isReady,e.query.tab,e_]),(0,n.useEffect)(()=>{(async function(){eE(!0);try{let e=await A.x.get("/api/health");if(e.ok){let t=await e.json();eC(!!t.basic_auth_enabled),eS(!!t.service_account_token_enabled)}else eC(!1),eS(!1)}catch(e){eC(!1),eS(!1)}finally{eE(!1)}})()},[]);let eY=(0,n.useCallback)(async()=>{if(E&&Date.now()-E.timestamp<3e5)return E;T(!0);try{let e=await A.x.get("/users/role");if(!e.ok){let t=await e.json();throw Error(t.detail||"Failed to get user role")}let t=await e.json(),s={role:t.role,name:t.name,id:t.id,timestamp:Date.now()};return D(s),T(!1),s}catch(e){throw T(!1),e}},[E]);(0,n.useEffect)(()=>{eY().catch(()=>{console.error("Failed to get user role")})},[eY]);let e0=async(e,t)=>{try{let s=await eY();if("admin"!==s.role)return R({open:!0,message:e,userName:s.name.toLowerCase()}),!1;return t(),!0}catch(e){return console.error("Failed to check user role:",e),R({open:!0,message:"Error: ".concat(e.message),userName:""}),!1}},e1=()=>{f.default.invalidate(x.R),f.default.invalidate(h.getClusters),f.default.invalidate(p.getManagedJobs,[{allUsers:!0,skipFinished:!0,fields:["user_hash","status"]}]),l.current&&l.current()},e2=async()=>{if(!g.username||!g.password){eN(Error("Username and password are required.")),m(!1);return}y(!0),eN(null),ev(null);try{let e=await A.x.post("/users/create",g);if(!e.ok){let t=await e.json();throw Error(t.detail||"Failed to create user")}ev('User "'.concat(g.username,'" created successfully!')),m(!1),b({username:"",password:"",role:"user"}),e1()}catch(e){eN(e),m(!1),b({username:"",password:"",role:"user"})}finally{y(!1)}},e4=async e=>{let t=e.target.files[0];t&&(G(t),Y(null))},e3=async()=>{if(!B){alert("Please select a CSV file first.");return}H(!0);try{let e=new FileReader;e.onload=async e=>{try{let t=e.target.result,s=await A.x.post("/users/import",{csv_content:t});if(!s.ok){let e=await s.json();throw Error(e.detail||"Failed to import users")}let r=await s.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...")))),Y({message:n}),r.success_count>0&&e1()}catch(e){alert("Error importing users: ".concat(e.message))}finally{H(!1)}},e.readAsText(B)}catch(e){alert("Error reading file: ".concat(e.message)),H(!1)}},e5=async e=>{ea(e),eo(""),er(!0)},e6=async()=>{if(!el){eN(Error("Please enter a new password."));return}ec(!0),ed(null);try{let e=await A.x.post("/users/update",{user_id:en.userId,password:el});if(!e.ok){let t=await e.json();throw Error(t.detail||"Failed to reset password")}ev('Password reset successfully for user "'.concat(en.usernameDisplay,'"!')),er(!1),ea(null),eo("")}catch(e){er(!1),ea(null),eo(""),ed(null),eN(e)}finally{ec(!1)}},e7=async()=>{if(eh){ej(!0),eg(null);try{let e=await A.x.post("/users/delete",{user_id:eh.userId});if(!e.ok){let t=await e.json();throw Error(t.detail||"Failed to delete user")}ev('User "'.concat(eh.usernameDisplay,'" deleted successfully!')),ex(!1),ep(null),e1()}catch(e){ex(!1),ep(null),eg(null),eN(e)}finally{ej(!1)}}},e8=()=>{ex(!1),ep(null)},e9=()=>{er(!1),ea(null),eo("")};return eR?(0,r.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,r.jsx)(o.Z,{}),(0,r.jsx)("span",{className:"ml-2 text-gray-500",children:"Loading..."})]}):(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:e_?"leading-none mr-6 pb-2 px-2 border-b-2 ".concat("users"===eD?"text-sky-blue border-sky-500":"text-gray-500 hover:text-gray-700 border-transparent"):"leading-none mr-6 pb-2 px-2",onClick:()=>{eI("users"),e.push("/users",void 0,{shallow:!0})},children:"Users"}),e_&&(0,r.jsx)("button",{className:"leading-none pb-2 px-2 border-b-2 ".concat("service-accounts"===eD?"text-sky-blue border-sky-500":"text-gray-500 hover:text-gray-700 border-transparent"),onClick:()=>{eI("service-accounts"),e.push("/users?tab=service-accounts",void 0,{shallow:!0})},children:"Service Accounts"})]}),(0,r.jsxs)("div",{className:"flex items-center",children:[s&&(0,r.jsxs)("div",{className:"flex items-center mr-2",children:[(0,r.jsx)(o.Z,{size:15,className:"mt-0"}),(0,r.jsx)("span",{className:"ml-2 text-gray-500",children:"Loading..."})]}),"users"===eD&&ek&&(null==E?void 0:E.role)==="admin"&&(0,r.jsx)("button",{onClick:async()=>{await e0("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"===eD&&ek&&(null==E?void 0:E.role)==="admin"&&(0,r.jsxs)("button",{onClick:async()=>{await e0("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:e1,disabled:s,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"}),!i&&(0,r.jsx)("span",{children:"Refresh"})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center justify-between mb-4",children:["users"===eD?(0,r.jsx)("div",{className:"w-full sm:w-auto max-w-md",children:(0,r.jsx)(z.ML,{propertyList:V,valueList:eJ,setFilters:eG,updateURLParams:eX,placeholder:"Filter users"})}):(0,r.jsxs)("div",{className:"relative flex-1 max-w-md",children:[(0,r.jsx)("input",{type:"text",placeholder:"Search by service account name, or created by",value:eq,onChange:e=>{eV(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"}),eq&&(0,r.jsx)("button",{onClick:()=>{eV("")},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"===eD&&!t&&(0,r.jsxs)("label",{className:"flex items-center cursor-pointer ml-4",children:[(0,r.jsx)("input",{type:"checkbox",checked:e$,onChange:e=>{let t=e.target.checked;eH(t),eW(t)},className:"sr-only"}),(0,r.jsx)("div",{className:"relative inline-flex h-5 w-9 items-center rounded-full transition-colors ".concat(e$?"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(e$?"translate-x-5":"translate-x-1")})}),(0,r.jsx)("span",{className:"ml-2 text-sm text-gray-700",children:"Deduplicate users"})]}),"service-accounts"===eD&&e_&&(0,r.jsxs)("button",{onClick:()=>{e0("cannot create service account tokens",()=>{eL(!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"]})]}),"users"===eD&&(0,r.jsx)(z.x$,{filters:eB,setFilters:eG,updateURLParams:eX}),(0,r.jsxs)("div",{className:"fixed top-20 right-4 z-[9999] max-w-md",children:[(0,r.jsx)($,{message:ey,onDismiss:()=>ev(null)}),(0,r.jsx)(O.X,{error:ew,title:"Error",onDismiss:()=>eN(null)})]}),"users"===eD?(0,r.jsx)(W,{refreshInterval:K,setLoading:a,refreshDataRef:l,checkPermissionAndAct:e0,roleLoading:I,onResetPassword:e5,onDeleteUser:e=>{e0("cannot delete users",()=>{ep(e),ex(!0)})},basicAuthEnabled:ek,currentUserRole:null==E?void 0:E.role,currentUserId:null==E?void 0:E.id,filters:eB,setValueList:eK,deduplicateUsers:e$}):e_&&(0,r.jsx)(X,{checkPermissionAndAct:e0,userRoleCache:E,setCreateSuccess:ev,setCreateError:eN,showCreateDialog:eT,setShowCreateDialog:eL,showRotateDialog:eU,setShowRotateDialog:eF,tokenToRotate:eZ,setTokenToRotate:eA,rotating:eP,setRotating:eO,searchQuery:eq,setSearchQuery:eV}),(0,r.jsx)(P.Vq,{open:c,onOpenChange:e=>{m(e),e||eN(null)},children:(0,r.jsxs)(P.cZ,{className:"sm:max-w-md",children:[(0,r.jsx)(P.fK,{children:(0,r.jsx)(P.$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:g.username,onChange:e=>b({...g,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:g.password,onChange:e=>b({...g,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:()=>Z(!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:g.role,onChange:e=>b({...g,role:e.target.value}),children:[(0,r.jsx)("option",{value:"user",children:"User"}),(0,r.jsx)("option",{value:"admin",children:"Admin"})]})]})]}),(0,r.jsxs)(P.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:e2,disabled:j,children:j?"Creating...":"Create"})]})]})}),(0,r.jsx)(P.Vq,{open:v.open,onOpenChange:e=>{R(t=>({...t,open:e})),e||eN(null)},children:(0,r.jsxs)(P.cZ,{className:"sm:max-w-md transition-all duration-200 ease-in-out",children:[(0,r.jsxs)(P.fK,{children:[(0,r.jsx)(P.$N,{children:"Permission Denied"}),(0,r.jsx)(P.Be,{children:I?(0,r.jsxs)("div",{className:"flex items-center py-2",children:[(0,r.jsx)(o.Z,{size:16,className:"mr-2"}),(0,r.jsx)("span",{children:"Checking permissions..."})]}):(0,r.jsx)(r.Fragment,{children:v.userName?(0,r.jsxs)(r.Fragment,{children:[v.userName," is logged in as non-admin and ",v.message,"."]}):v.message})})]}),(0,r.jsx)(P.cN,{children:(0,r.jsx)(d.z,{variant:"outline",onClick:()=>R(e=>({...e,open:!1})),disabled:I,children:"OK"})})]})}),(0,r.jsx)(P.Vq,{open:M,onOpenChange:e=>{q(e),e||eN(null)},children:(0,r.jsxs)(P.cZ,{className:"sm:max-w-lg",children:[(0,r.jsx)(P.fK,{children:(0,r.jsx)(P.$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"===ee?"border-b-2 border-sky-500 text-sky-600":"text-gray-500 hover:text-gray-700"),onClick:()=>et("import"),children:"Import"}),(0,r.jsx)("button",{className:"px-4 py-2 text-sm font-medium ".concat("export"===ee?"border-b-2 border-sky-500 text-sky-600":"text-gray-500 hover:text-gray-700"),onClick:()=>et("export"),children:"Export"})]}),(0,r.jsx)("div",{className:"flex flex-col gap-4 py-4",children:"import"===ee?(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:e4,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)(P.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"===ee?(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:e3,disabled:J||!B,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 A.x.get("/users/export");if(!e.ok){let t=await e.json();throw Error(t.detail||"Failed to export users")}let t=await e.json(),s=t.csv_content,r=new Blob([s],{type:"text/csv;charset=utf-8;"}),n=URL.createObjectURL(r),a=document.createElement("a");a.href=n;let l=new Date,o=e=>String(e).padStart(2,"0"),i=l.getFullYear(),c=o(l.getMonth()+1),u=o(l.getDate()),d=o(l.getHours()),m=o(l.getMinutes()),x=o(l.getSeconds());a.download="users_export_".concat(i,"-").concat(c,"-").concat(u,"-").concat(d,"-").concat(m,"-").concat(x,".csv"),a.click(),URL.revokeObjectURL(n),alert("Successfully exported ".concat(t.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)(P.Vq,{open:es,onOpenChange:e=>{e||(e9(),eN(null))},children:(0,r.jsxs)(P.cZ,{className:"sm:max-w-md",children:[(0,r.jsxs)(P.fK,{children:[(0,r.jsx)(P.$N,{children:"Reset Password"}),(0,r.jsxs)(P.Be,{children:["Enter a new password for"," ",(null==en?void 0:en.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:el,onChange:e=>eo(e.target.value),autoFocus:!0})]})}),(0,r.jsxs)(P.cN,{children:[(0,r.jsx)(d.z,{variant:"outline",onClick:e9,disabled:ei,children:"Cancel"}),(0,r.jsx)(d.z,{variant:"default",onClick:e6,disabled:ei||!el,className:"bg-sky-600 text-white hover:bg-sky-700",children:ei?"Resetting...":"Reset Password"})]})]})}),(0,r.jsx)(P.Vq,{open:em,onOpenChange:e=>{e||(e8(),eN(null))},children:(0,r.jsxs)(P.cZ,{className:"sm:max-w-md",children:[(0,r.jsxs)(P.fK,{children:[(0,r.jsx)(P.$N,{children:"Delete User"}),(0,r.jsxs)(P.Be,{children:['Are you sure you want to delete user "',(null==eh?void 0:eh.usernameDisplay)||"this user",'"? This action cannot be undone.']})]}),(0,r.jsxs)(P.cN,{children:[(0,r.jsx)(d.z,{variant:"outline",onClick:e8,disabled:eb,children:"Cancel"}),(0,r.jsx)(d.z,{variant:"destructive",onClick:e7,disabled:eb,children:eb?"Deleting...":"Delete"})]})]})})]})}function W(e){let{refreshInterval:t,setLoading:s,refreshDataRef:a,checkPermissionAndAct:l,roleLoading:i,onResetPassword:u,onDeleteUser:d,basicAuthEnabled:b,currentUserRole:v,currentUserId:w,filters:N,setValueList:k,deduplicateUsers:C}=e,[_,S]=(0,n.useState)([]),[L,U]=(0,n.useState)(!0),[F,P]=(0,n.useState)(!1),[O,M]=(0,n.useState)({key:"username",direction:"ascending"}),[V,K]=(0,n.useState)(null),[$,H]=(0,n.useState)(""),[W,X]=(0,n.useState)({}),[Q,Y]=(0,n.useState)(!1),ee=(0,n.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];s&&e&&s(!0),e&&U(!0),Y(!1);try{let t=await f.default.get(x.R),r=(t||[]).map(e=>({...e,usernameDisplay:G(e.username,e.userId),fullEmailID:J(e.username,e.userId),clusterCount:-1,jobCount:-1,gpuCount:-1}));S(r),P(!0),s&&e&&s(!1),e&&U(!1);let[n,a]=await Promise.all([f.default.get(h.getClusters),f.default.get(p.getManagedJobs,[{allUsers:!0,skipFinished:!0,fields:["user_hash","status","accelerators","job_name","job_id","infra"]}])]),l=a.jobs||[],o={},i=e=>{if(!e)return null;let t=e;if("string"==typeof e)try{let s=e.replace(/'/g,'"').replace(/None/g,"null");t=JSON.parse(s)}catch(e){return null}if("object"==typeof t&&null!==t){let e=Object.entries(t);if(e.length>0)return e[0][0]}return null},c=(e,t,s,r,n,a)=>{e&&t&&(o[e]||(o[e]={}),o[e][t]||(o[e][t]={}),o[e].Total||(o[e].Total={}),o[e][t].Total||(o[e][t].Total={clusterCount:0,jobCount:0,gpuCount:0}),o[e][t].Total.clusterCount+=r,o[e][t].Total.jobCount+=n,o[e][t].Total.gpuCount+=a,s&&(o[e][t][s]||(o[e][t][s]={clusterCount:0,jobCount:0,gpuCount:0}),o[e][t][s].clusterCount+=r,o[e][t][s].jobCount+=n,o[e][t][s].gpuCount+=a,o[e].Total[s]||(o[e].Total[s]={clusterCount:0,jobCount:0,gpuCount:0}),o[e].Total[s].clusterCount+=r,o[e].Total[s].jobCount+=n,o[e].Total[s].gpuCount+=a))};for(let e of n||[]){let t=e.user_hash;if(!t)continue;let s=i(e.gpus),r=e.infra,n=0;if("STOPPED"!==e.status&&"TERMINATED"!==e.status){let t=B(e.gpus,"Cluster ".concat(e.cluster)),s=e.num_nodes||1;n=t*s}c(t,r,s,1,0,n)}let u=e=>{if(!e||"string"!=typeof e)return 1;let t=e.match(/^(\d+)x/);return t?parseInt(t[1],10):1};for(let e of l||[]){if(!q.has(e.status))continue;let t=e.user_hash;if(!t)continue;let s=i(e.accelerators),r=e.infra,n=B(e.accelerators,"Job ".concat(e.job_id)),a=u(e.resources_str_full),l=n*a;c(t,r,s,0,1,l)}X(o),Y(!0);let d=(t||[]).map(e=>{let t=0,s=0,r=0,a=0;for(let r of n||[])if(r.user_hash===e.userId&&(t++,"STOPPED"!==r.status&&"TERMINATED"!==r.status)){let e=B(r.gpus,"Cluster ".concat(r.cluster)),t=r.num_nodes||1;s+=e*t}for(let t of l||[])if(t.user_hash===e.userId&&q.has(t.status)){r++;let e=B(t.accelerators,"Job ".concat(t.job_id)),s=u(t.resources_str_full);a+=e*s}return{...e,usernameDisplay:G(e.username,e.userId),fullEmailID:J(e.username,e.userId),clusterCount:t,jobCount:r,gpuCount:s+a}}),m=new Set,g=new Set;for(let e of Object.values(o)){for(let t of Object.keys(e))"Total"!==t&&m.add(t);if(e.Total)for(let t of Object.keys(e.Total))g.add(t)}let b=new Set,j=new Set,y=new Set;d.forEach(e=>{e.usernameDisplay&&b.add(e.usernameDisplay),e.userId&&j.add(e.userId),e.role&&y.add(e.role)}),k({name:Array.from(b).sort(),"user id":Array.from(j).sort(),role:Array.from(y).sort(),"gpu type":Array.from(g).sort(),infra:Array.from(m).sort()}),S(d)}catch(t){console.error("Failed to fetch or process user data:",t),S([]),P(!0),s&&e&&s(!1),e&&U(!1)}},[s]);(0,n.useEffect)(()=>{a&&(a.current=()=>ee(!0))},[a,ee]),(0,n.useEffect)(()=>{(async()=>{P(!1),U(!0),await g.ZP.preloadForPage("users"),ee(!0)})();let e=setInterval(()=>{"visible"===window.document.visibilityState&&ee(!1)},t);return()=>clearInterval(e)},[ee,t]);let et=(0,n.useMemo)(()=>{let e=_,t=N.filter(e=>"GPU"!==e.property&&"Infra"!==e.property),s=N.filter(e=>"GPU"===e.property),r=N.filter(e=>"Infra"===e.property);t.length>0&&(e=(0,z.cm)(_.map(e=>({...e,name:e.usernameDisplay,"user id":e.userId})),t));let n=(e,t,s)=>{let r=0,n=0,a=0,l=W[e];if(!l)return{clusterCount:0,jobCount:0,gpuCount:0};let o=t.map(e=>e.toLowerCase()),i=s.map(e=>e.toLowerCase()),c=o.length>0,u=i.length>0;if(c&&u){for(let e of i)for(let[t,s]of Object.entries(l))if("Total"!==t&&t.toLowerCase()===e)for(let e of o)for(let[t,l]of Object.entries(s))"Total"!==t&&t.toLowerCase()===e&&(r+=l.clusterCount,n+=l.jobCount,a+=l.gpuCount)}else if(u){for(let e of i)for(let[t,s]of Object.entries(l))if("Total"!==t&&t.toLowerCase()===e&&s.Total){let e=s.Total;r+=e.clusterCount,n+=e.jobCount,a+=e.gpuCount}}else if(c&&l.Total)for(let e of o)for(let[t,s]of Object.entries(l.Total))t.toLowerCase()===e&&(r+=s.clusterCount,n+=s.jobCount,a+=s.gpuCount);return{clusterCount:r,jobCount:n,gpuCount:a}},a=s.length>0,l=r.length>0;if(a||l){let t=s.map(e=>e.value).filter(Boolean),o=r.map(e=>e.value).filter(Boolean),i=t.map(e=>e.toLowerCase()),c=o.map(e=>e.toLowerCase());e=(e=e.filter(e=>{let t=W[e.userId];if(!t)return!1;if(a&&l){for(let e of c)for(let[s,r]of Object.entries(t))if("Total"!==s&&s.toLowerCase()===e){for(let e of i)for(let t of Object.keys(r))if("Total"!==t&&t.toLowerCase()===e)return!0}}else if(l){for(let e of c)for(let s of Object.keys(t))if("Total"!==s&&s.toLowerCase()===e)return!0}else if(a&&t.Total){for(let e of i)for(let s of Object.keys(t.Total))if(s.toLowerCase()===e)return!0}return!1})).map(e=>{let s=n(e.userId,t,o);return{...e,clusterCount:s.clusterCount,jobCount:s.jobCount,gpuCount:s.gpuCount}})}if(C){let t={};e.forEach(e=>{let s=e.usernameDisplay;t[s]?(t[s].userIds.push(e.userId),-1!==e.clusterCount&&(-1===t[s].clusterCount?t[s].clusterCount=e.clusterCount:t[s].clusterCount+=e.clusterCount),-1!==e.jobCount&&(-1===t[s].jobCount?t[s].jobCount=e.jobCount:t[s].jobCount+=e.jobCount),-1!==e.gpuCount&&(-1===t[s].gpuCount?t[s].gpuCount=e.gpuCount:t[s].gpuCount+=e.gpuCount),e.created_at&&(!t[s].created_at||e.created_at<t[s].created_at)&&(t[s].created_at=e.created_at)):t[s]={...e,userIds:[e.userId],clusterCount:e.clusterCount,jobCount:e.jobCount,gpuCount:e.gpuCount,created_at:e.created_at}}),e=Object.values(t)}return(0,j.R0)(e,O.key,O.direction)},[_,O,N,C,W]),es=e=>{let t="ascending";O.key===e&&"ascending"===O.direction&&(t="descending"),M({key:e,direction:t})},er=e=>O.key===e?"ascending"===O.direction?" ↑":" ↓":"",en=async(e,t)=>{await l("cannot edit user role",()=>{K(e),H(t)})},ea=()=>{K(null),H("")},el=async e=>{if(!e||!$){console.error("User ID or role is missing."),alert("Error: User ID or role is missing.");return}U(!0);try{let t=await A.x.post("/users/update",{user_id:e,role:$});if(!t.ok){let e=await t.json();throw Error(e.detail||"Failed to update role")}f.default.invalidate(x.R),await ee(!0),ea()}catch(e){console.error("Failed to update user role:",e),alert("Error updating role: ".concat(e.message))}finally{U(!1)}};return L&&0===_.length&&!F?(0,r.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,r.jsx)(o.Z,{})}):F?N.some(e=>"GPU"===e.property||"Infra"===e.property)&&!Q?(0,r.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,r.jsx)(o.Z,{}),(0,r.jsx)("span",{className:"ml-2 text-gray-500",children:"Loading filtered data..."})]}):et&&0!==et.length?(0,r.jsx)(Z.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:()=>es("usernameDisplay"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Name",er("usernameDisplay")]}),!C&&(0,r.jsxs)(m.ss,{onClick:()=>es("fullEmailID"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["User ID",er("fullEmailID")]}),!C&&(0,r.jsxs)(m.ss,{onClick:()=>es("role"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Role",er("role")]}),(0,r.jsxs)(m.ss,{onClick:()=>es("created_at"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Joined",er("created_at")]}),(0,r.jsxs)(m.ss,{onClick:()=>es("gpuCount"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["GPUs",er("gpuCount")]}),(0,r.jsxs)(m.ss,{onClick:()=>es("clusterCount"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Clusters",er("clusterCount")]}),(0,r.jsxs)(m.ss,{onClick:()=>es("jobCount"),className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50 w-1/6",children:["Jobs",er("jobCount")]}),!C&&(b||"admin"===v)&&(0,r.jsx)(m.ss,{className:"whitespace-nowrap w-1/7",children:"Actions"})]})}),(0,r.jsx)(m.RM,{children:et.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:V===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:()=>el(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:ea,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"===v&&(0,r.jsx)("button",{onClick:()=>en(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)(y.Zg,{date:new Date(1e3*e.created_at)}):"-"}),(0,r.jsx)(m.pj,{children:-1===e.gpuCount?(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)(o.Z,{size:10,className:"mr-1"}),"Loading..."]}):(0,r.jsx)("span",{className:"px-2 py-0.5 rounded text-xs font-medium ".concat(e.gpuCount>0?"bg-purple-100 text-purple-600":"bg-gray-100 text-gray-500"),title:"Total GPUs: ".concat(e.gpuCount),children:e.gpuCount})}),(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)(o.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)(o.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&&(b||"admin"===v)&&(0,r.jsx)(m.pj,{className:"relative",children:(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[b&&(0,r.jsx)("button",{onClick:"admin"===v||e.userId===w?async()=>{u(e)}:void 0,className:"admin"===v||e.userId===w?"text-blue-600 hover:text-blue-700 p-1":"text-gray-300 cursor-not-allowed p-1",title:"admin"===v||e.userId===w?"Reset Password":"You can only reset your own password",disabled:"admin"!==v&&e.userId!==w,children:(0,r.jsx)(I,{className:"h-4 w-4"})}),"admin"===v&&(0,r.jsx)("button",{onClick:()=>d(e),className:"text-red-600 hover:text-red-700 p-1",title:"Delete User",children:(0,r.jsx)(T.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:N.length>0?"No users match your filters.":"No users found."}),(0,r.jsx)("p",{className:"text-sm text-gray-400 mt-1",children:N.length>0?"Try adjusting your filter criteria.":"There are currently no users to display."})]}):(0,r.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,r.jsx)(o.Z,{}),(0,r.jsx)("span",{className:"ml-2 text-gray-500",children:"Loading users..."})]})}function X(e){let{checkPermissionAndAct:t,userRoleCache:s,setCreateSuccess:a,setCreateError:l,showCreateDialog:i,setShowCreateDialog:u,showRotateDialog:d,setShowRotateDialog:x,tokenToRotate:g,setTokenToRotate:b,rotating:j,setRotating:v,searchQuery:w,setSearchQuery:k}=e,[C,_]=(0,n.useState)([]),[S,U]=(0,n.useState)(!0),[F,O]=(0,n.useState)(!1),[M,z]=(0,n.useState)(null),[V,G]=(0,n.useState)(null),[J,K]=(0,n.useState)({token_name:"",expires_in_days:30}),[$,H]=(0,n.useState)(""),[W,X]=(0,n.useState)(!1),[Q,Y]=(0,n.useState)(!1),[ee,et]=(0,n.useState)(""),[es,er]=(0,n.useState)(null),[en,ea]=(0,n.useState)(null),[el,eo]=(0,n.useState)(null),[ei,ec]=(0,n.useState)(""),[eu,ed]=(0,n.useState)([]),em=async()=>{try{U(!0);let e=await A.x.get("/users/service-account-tokens");if(!e.ok){console.error("Failed to fetch tokens"),_([]),ed([]);return}let t=await e.json();_(t||[]);let[s,r]=await Promise.all([f.default.get(h.getClusters),f.default.get(p.getManagedJobs,[{allUsers:!0,skipFinished:!0,fields:["user_hash","status","accelerators","job_id","infra"]}])]),n=s||[],a=(null==r?void 0:r.jobs)||[],l=(t||[]).map(e=>{let t=e.service_account_user_id,s=0,r=0,l=0,o=0;for(let e of n)e.user_hash===t&&(s++,"STOPPED"!==e.status&&"TERMINATED"!==e.status&&(r+=B(e.gpus,"Cluster ".concat(e.cluster))));for(let e of a)e.user_hash===t&&q.has(e.status)&&(l++,o+=B(e.accelerators,"Job ".concat(e.job_name||e.job_id)));return{...e,clusterCount:s,jobCount:l,gpuCount:r+o,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{U(!1)}};(0,n.useEffect)(()=>{em()},[]);let ex=async(e,s)=>{await t("cannot edit service account role",()=>{eo(e),ec(s)})},eh=()=>{eo(null),ec("")},ep=async e=>{if(!e||!ei){console.error("Token ID or role is missing."),l(Error("Token ID or role is missing."));return}U(!0);try{let t=await A.x.post("/users/service-account-tokens/update-role",{token_id:e,role:ei});if(!t.ok){let e=await t.json();throw Error(e.detail||"Failed to update role")}a("Service account role updated successfully!"),await em(),eh()}catch(e){console.error("Failed to update service account role:",e),l(e)}finally{U(!1)}},ef=async e=>{try{await navigator.clipboard.writeText(e),et("Copied!"),setTimeout(()=>et(""),2e3)}catch(e){console.error("Failed to copy:",e)}},eg=async()=>{if(!J.token_name.trim()){l(Error("Token name is required"));return}X(!0);try{let e={token_name:J.token_name.trim(),expires_in_days:""===J.expires_in_days?null:J.expires_in_days},t=await A.x.post("/users/service-account-tokens",e);if(t.ok){let e=await t.json();er(e.token),K({token_name:"",expires_in_days:30}),await em()}else{let e=await t.json();throw Error(e.detail||"Failed to create token")}}catch(e){l(e)}finally{X(!1)}},eb=async()=>{if(M){Y(!0),G(null);try{let e=await A.x.post("/users/service-account-tokens/delete",{token_id:M.token_id});if(e.ok)a('Service account "'.concat(M.token_name,'" deleted successfully!')),O(!1),z(null),G(null),await em();else{let t=await e.json();throw Error(t.detail||"Failed to delete service account")}}catch(e){O(!1),z(null),G(null),l(e)}finally{Y(!1)}}},ej=async()=>{if(g){v(!0);try{let e={token_id:g.token_id,expires_in_days:""===$?null:parseInt($)},t=await A.x.post("/users/service-account-tokens/rotate",e);if(t.ok){let e=await t.json();ea(e.token),await em()}else{let e=await t.json();throw Error(e.detail||"Failed to rotate token")}}catch(e){l(e)}finally{v(!1)}}},ey=eu.filter(e=>{var t,s,r,n;if(!(null==w?void 0:w.trim()))return!0;let a=w.toLowerCase();return(null===(t=e.token_name)||void 0===t?void 0:t.toLowerCase().includes(a))||(null===(s=e.creator_name)||void 0===s?void 0:s.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===eu.length?(0,r.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,r.jsx)(o.Z,{size:32}),(0,r.jsx)("span",{className:"ml-3",children:"Loading tokens..."})]}):(0,r.jsxs)(r.Fragment,{children:[0===ey.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)(Z.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:"GPUs"}),(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:ey.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==s?void 0:s.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:el===e.token_id?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("select",{value:ei,onChange:e=>ec(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:()=>ep(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:eh,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==s?void 0:s.role)==="admin"||e.creator_user_hash===(null==s?void 0:s.id))&&(0,r.jsx)("button",{onClick:()=>ex(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,{children:(0,r.jsx)("span",{className:"px-2 py-0.5 rounded text-xs font-medium ".concat(e.gpuCount>0?"bg-purple-100 text-purple-600":"bg-gray-100 text-gray-500"),title:"Total GPUs: ".concat(e.gpuCount),children:e.gpuCount})}),(0,r.jsx)(m.pj,{className:"truncate",children:e.created_at?(0,r.jsx)(y.Zg,{date:new Date(1e3*e.created_at)}):"Never"}),(0,r.jsx)(m.pj,{className:"truncate",children:e.last_used_at?(0,r.jsx)(y.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)(y.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==s?void 0:s.role)==="admin"||e.creator_user_hash===(null==s?void 0:s.id))&&(0,r.jsx)(y.WH,{content:"Rotate token",className:"capitalize text-sm text-muted-foreground",children:(0,r.jsx)("button",{onClick:()=>{t("cannot rotate service account tokens",()=>{b(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==s?void 0:s.role)==="admin"||e.creator_user_hash===(null==s?void 0:s.id))&&(0,r.jsx)(y.WH,{content:"Delete ".concat(e.token_name),className:"capitalize text-sm text-muted-foreground",children:(0,r.jsx)("button",{onClick:()=>{t("cannot delete service account tokens",()=>{z(e),O(!0)})},className:"text-red-600 hover:text-red-800 font-medium inline-flex items-center",children:(0,r.jsx)(T.Z,{className:"h-4 w-4"})})})]})})]},e.token_id))})]})})}),(0,r.jsx)(P.Vq,{open:i,onOpenChange:e=>{u(e),e||(er(null),l(null))},children:(0,r.jsxs)(P.cZ,{className:"sm:max-w-2xl",children:[(0,r.jsxs)(P.fK,{children:[(0,r.jsx)(P.$N,{children:"Create Service Account"}),(0,r.jsx)(P.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)(y.WH,{content:ee?"Copied!":"Copy token",className:"text-muted-foreground",children:(0,r.jsx)("button",{onClick:()=>ef(es),className:"flex items-center text-green-600 hover:text-green-800 transition-colors duration-200 p-1 ml-2",children:ee?(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:J.token_name,onChange:e=>K({...J,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:J.expires_in_days||"",onChange:e=>K({...J,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)(P.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:()=>{u(!1),er(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:()=>{u(!1),er(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||!J.token_name.trim(),children:W?"Creating...":"Create Token"})]})})]})}),(0,r.jsx)(P.Vq,{open:F,onOpenChange:e=>{O(e),e||(z(null),l(null))},children:(0,r.jsxs)(P.cZ,{className:"sm:max-w-md",children:[(0,r.jsxs)(P.fK,{children:[(0,r.jsx)(P.$N,{children:"Delete Service Account Token"}),(0,r.jsxs)(P.Be,{children:['Are you sure you want to delete the service account "',null==M?void 0:M.token_name,'"',(null==M?void 0:M.creator_user_hash)!==(null==s?void 0:s.id)&&(null==s?void 0:s.role)==="admin"?" owned by ".concat(null==M?void 0:M.creator_name):"","? This action cannot be undone and will immediately revoke access for any systems using this token."]})]}),(0,r.jsxs)(P.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:()=>{O(!1),z(null)},disabled:Q,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:Q,children:Q?"Deleting...":"Delete Token"})]})]})}),(0,r.jsx)(P.Vq,{open:d,onOpenChange:e=>{x(e),e||(b(null),H(""),ea(null),l(null))},children:(0,r.jsxs)(P.cZ,{className:"sm:max-w-2xl",children:[(0,r.jsxs)(P.fK,{children:[(0,r.jsx)(P.$N,{children:"Rotate Service Account Token"}),(0,r.jsxs)(P.Be,{children:['Rotate the service account token "',null==g?void 0:g.token_name,'"',(null==g?void 0:g.creator_user_hash)!==(null==s?void 0:s.id)&&(null==s?void 0:s.role)==="admin"?" owned by ".concat(null==g?void 0:g.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:en?(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)(y.WH,{content:ee?"Copied!":"Copy token",className:"text-muted-foreground",children:(0,r.jsx)("button",{onClick:()=>ef(en),className:"flex items-center text-green-600 hover:text-green-800 transition-colors duration-200 p-1 ml-2",children:ee?(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:en})})]})}):(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:$,onChange:e=>H(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)(P.cN,{children:en?(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),b(null),H(""),ea(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),b(null),H(""),ea(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:ej,disabled:j,children:j?"Rotating...":"Rotate Token"})]})})]})})]})}W.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,t,s){s.d(t,{j:function(){return l}});var r=s(90512);let n=e=>"boolean"==typeof e?`${e}`:0===e?"0":e,a=r.W,l=(e,t)=>s=>{var r;if((null==t?void 0:t.variants)==null)return a(e,null==s?void 0:s.class,null==s?void 0:s.className);let{variants:l,defaultVariants:o}=t,i=Object.keys(l).map(e=>{let t=null==s?void 0:s[e],r=null==o?void 0:o[e];if(null===t)return null;let a=n(t)||n(r);return l[e][a]}),c=s&&Object.entries(s).reduce((e,t)=>{let[s,r]=t;return void 0===r||(e[s]=r),e},{});return a(e,i,null==t?void 0:null===(r=t.compoundVariants)||void 0===r?void 0:r.reduce((e,t)=>{let{class:s,className:r,...n}=t;return Object.entries(n).every(e=>{let[t,s]=e;return Array.isArray(s)?s.includes({...o,...c}[t]):({...o,...c})[t]===s})?[...e,s,r]:e},[]),null==s?void 0:s.class,null==s?void 0:s.className)}}}]);