skypilot-nightly 1.0.0.dev20251019__py3-none-any.whl → 1.0.0.dev20251022__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 (95) hide show
  1. sky/__init__.py +2 -2
  2. sky/adaptors/kubernetes.py +64 -0
  3. sky/backends/backend_utils.py +11 -11
  4. sky/backends/cloud_vm_ray_backend.py +15 -4
  5. sky/client/cli/command.py +39 -10
  6. sky/client/cli/flags.py +4 -2
  7. sky/client/sdk.py +26 -3
  8. sky/dashboard/out/404.html +1 -1
  9. sky/dashboard/out/_next/static/IgACOQPupLbX9z-RYVEDx/_buildManifest.js +1 -0
  10. sky/dashboard/out/_next/static/chunks/1141-ec6f902ffb865853.js +11 -0
  11. sky/dashboard/out/_next/static/chunks/2755.9b1e69c921b5a870.js +26 -0
  12. sky/dashboard/out/_next/static/chunks/3015-d014dc5b9412fade.js +1 -0
  13. sky/dashboard/out/_next/static/chunks/{3294.1fafbf42b3bcebff.js → 3294.998db87cd52a1238.js} +1 -1
  14. sky/dashboard/out/_next/static/chunks/{3785.a19328ba41517b8b.js → 3785.483a3dda2d52f26e.js} +1 -1
  15. sky/dashboard/out/_next/static/chunks/{1121-d0782b9251f0fcd3.js → 4282-d2f3ef2fbf78e347.js} +1 -1
  16. sky/dashboard/out/_next/static/chunks/6856-5c94d394259cdb6e.js +1 -0
  17. sky/dashboard/out/_next/static/chunks/8969-0389e2cb52412db3.js +1 -0
  18. sky/dashboard/out/_next/static/chunks/9360.14326e329484b57e.js +31 -0
  19. sky/dashboard/out/_next/static/chunks/pages/clusters/[cluster]/{[job]-8f058b0346db2aff.js → [job]-602eeead010ec1d6.js} +1 -1
  20. sky/dashboard/out/_next/static/chunks/pages/clusters/{[cluster]-477555ab7c0b13d8.js → [cluster]-18b334dedbd9f6f2.js} +1 -1
  21. sky/dashboard/out/_next/static/chunks/pages/{clusters-2f61f65487f6d8ff.js → clusters-57221ec2e4e01076.js} +1 -1
  22. sky/dashboard/out/_next/static/chunks/pages/infra/{[context]-553b8b5cb65e100b.js → [context]-44ce535a0a0ad4ec.js} +1 -1
  23. sky/dashboard/out/_next/static/chunks/pages/{infra-910a22500c50596f.js → infra-872e6a00165534f4.js} +1 -1
  24. sky/dashboard/out/_next/static/chunks/pages/{jobs-a35a9dc3c5ccd657.js → jobs-0dc34cf9a8710a9f.js} +1 -1
  25. sky/dashboard/out/_next/static/chunks/pages/{users-98d2ed979084162a.js → users-3a543725492fb896.js} +1 -1
  26. sky/dashboard/out/_next/static/chunks/pages/{volumes-835d14ba94808f79.js → volumes-d2af9d22e87cc4ba.js} +1 -1
  27. sky/dashboard/out/_next/static/chunks/pages/workspaces/{[name]-e8688c35c06f0ac5.js → [name]-9ad108cd67d16d96.js} +1 -1
  28. sky/dashboard/out/_next/static/chunks/pages/{workspaces-69c80d677d3c2949.js → workspaces-6fc994fa1ee6c6bf.js} +1 -1
  29. sky/dashboard/out/_next/static/chunks/webpack-919e3c01ab6b2633.js +1 -0
  30. sky/dashboard/out/clusters/[cluster]/[job].html +1 -1
  31. sky/dashboard/out/clusters/[cluster].html +1 -1
  32. sky/dashboard/out/clusters.html +1 -1
  33. sky/dashboard/out/config.html +1 -1
  34. sky/dashboard/out/index.html +1 -1
  35. sky/dashboard/out/infra/[context].html +1 -1
  36. sky/dashboard/out/infra.html +1 -1
  37. sky/dashboard/out/jobs/[job].html +1 -1
  38. sky/dashboard/out/jobs/pools/[pool].html +1 -1
  39. sky/dashboard/out/jobs.html +1 -1
  40. sky/dashboard/out/users.html +1 -1
  41. sky/dashboard/out/volumes.html +1 -1
  42. sky/dashboard/out/workspace/new.html +1 -1
  43. sky/dashboard/out/workspaces/[name].html +1 -1
  44. sky/dashboard/out/workspaces.html +1 -1
  45. sky/data/storage.py +2 -2
  46. sky/global_user_state.py +137 -37
  47. sky/jobs/constants.py +1 -1
  48. sky/jobs/server/core.py +4 -2
  49. sky/jobs/server/server.py +21 -12
  50. sky/jobs/state.py +307 -55
  51. sky/jobs/utils.py +248 -144
  52. sky/provision/kubernetes/network.py +9 -6
  53. sky/provision/provisioner.py +8 -0
  54. sky/schemas/api/responses.py +2 -0
  55. sky/schemas/db/skypilot_config/001_initial_schema.py +30 -0
  56. sky/serve/server/server.py +8 -7
  57. sky/server/common.py +10 -15
  58. sky/server/constants.py +1 -1
  59. sky/server/daemons.py +4 -2
  60. sky/server/requests/executor.py +30 -28
  61. sky/server/requests/payloads.py +5 -1
  62. sky/server/requests/preconditions.py +9 -4
  63. sky/server/requests/requests.py +130 -53
  64. sky/server/requests/serializers/encoders.py +3 -3
  65. sky/server/server.py +91 -58
  66. sky/server/stream_utils.py +127 -38
  67. sky/server/uvicorn.py +18 -17
  68. sky/setup_files/alembic.ini +4 -0
  69. sky/skylet/services.py +5 -5
  70. sky/skypilot_config.py +87 -75
  71. sky/ssh_node_pools/server.py +4 -4
  72. sky/users/permission.py +4 -0
  73. sky/utils/asyncio_utils.py +63 -3
  74. sky/utils/db/db_utils.py +11 -3
  75. sky/utils/db/migration_utils.py +7 -3
  76. sky/volumes/server/server.py +3 -3
  77. sky/workspaces/server.py +6 -6
  78. {skypilot_nightly-1.0.0.dev20251019.dist-info → skypilot_nightly-1.0.0.dev20251022.dist-info}/METADATA +37 -37
  79. {skypilot_nightly-1.0.0.dev20251019.dist-info → skypilot_nightly-1.0.0.dev20251022.dist-info}/RECORD +87 -86
  80. sky/dashboard/out/_next/static/8e35zdobdd0bK_Nkba03m/_buildManifest.js +0 -1
  81. sky/dashboard/out/_next/static/chunks/1141-3b40c39626f99c89.js +0 -11
  82. sky/dashboard/out/_next/static/chunks/2755.97300e1362fe7c98.js +0 -26
  83. sky/dashboard/out/_next/static/chunks/3015-7e0e8f06bb2f881c.js +0 -1
  84. sky/dashboard/out/_next/static/chunks/6856-5fdc9b851a18acdb.js +0 -1
  85. sky/dashboard/out/_next/static/chunks/8969-66237729cdf9749e.js +0 -1
  86. sky/dashboard/out/_next/static/chunks/9360.71e83b2ddc844ec2.js +0 -31
  87. sky/dashboard/out/_next/static/chunks/webpack-3c431f6c9086e487.js +0 -1
  88. /sky/dashboard/out/_next/static/{8e35zdobdd0bK_Nkba03m → IgACOQPupLbX9z-RYVEDx}/_ssgManifest.js +0 -0
  89. /sky/dashboard/out/_next/static/chunks/{1871-49141c317f3a9020.js → 1871-df9f87fcb7f24292.js} +0 -0
  90. /sky/dashboard/out/_next/static/chunks/pages/jobs/{[job]-e5c9ce6a24fc0de4.js → [job]-8677af16befde039.js} +0 -0
  91. /sky/dashboard/out/_next/static/chunks/pages/jobs/pools/{[pool]-bc979970c247d8f3.js → [pool]-e020fd69dbe76cea.js} +0 -0
  92. {skypilot_nightly-1.0.0.dev20251019.dist-info → skypilot_nightly-1.0.0.dev20251022.dist-info}/WHEEL +0 -0
  93. {skypilot_nightly-1.0.0.dev20251019.dist-info → skypilot_nightly-1.0.0.dev20251022.dist-info}/entry_points.txt +0 -0
  94. {skypilot_nightly-1.0.0.dev20251019.dist-info → skypilot_nightly-1.0.0.dev20251022.dist-info}/licenses/LICENSE +0 -0
  95. {skypilot_nightly-1.0.0.dev20251019.dist-info → skypilot_nightly-1.0.0.dev20251022.dist-info}/top_level.txt +0 -0
sky/__init__.py CHANGED
@@ -7,7 +7,7 @@ import urllib.request
7
7
  from sky.utils import directory_utils
8
8
 
9
9
  # Replaced with the current commit when building the wheels.
10
- _SKYPILOT_COMMIT_SHA = '4e30b0661870f76cbcad27b082fbd37dd0b12bcd'
10
+ _SKYPILOT_COMMIT_SHA = '460bf4d1b00bcac85ffb617452ccbc87501261c5'
11
11
 
12
12
 
13
13
  def _get_git_commit():
@@ -37,7 +37,7 @@ def _get_git_commit():
37
37
 
38
38
 
39
39
  __commit__ = _get_git_commit()
40
- __version__ = '1.0.0.dev20251019'
40
+ __version__ = '1.0.0.dev20251022'
41
41
  __root_dir__ = directory_utils.get_sky_dir()
42
42
 
43
43
 
@@ -1,4 +1,5 @@
1
1
  """Kubernetes adaptors"""
2
+ import functools
2
3
  import logging
3
4
  import os
4
5
  import platform
@@ -162,8 +163,61 @@ def list_kube_config_contexts():
162
163
  return kubernetes.config.list_kube_config_contexts(_get_config_file())
163
164
 
164
165
 
166
+ class ClientWrapper:
167
+ """Wrapper around the kubernetes API clients.
168
+
169
+ This is needed because we cache kubernetes.client.ApiClient and other typed
170
+ clients (e.g. kubernetes.client.CoreV1Api) and lru_cache.cache_clear() does
171
+ not call close() on the client to cleanup external resources like
172
+ semaphores. This decorator wraps the client with __del__ to ensure the
173
+ external state of kubernetes clients are properly cleaned up on GC.
174
+ """
175
+
176
+ def __init__(self, client):
177
+ self._client = client
178
+
179
+ def __getattr__(self, name):
180
+ """Delegate to the underlying client"""
181
+ return getattr(self._client, name)
182
+
183
+ def __del__(self):
184
+ """Clean up the underlying client"""
185
+ try:
186
+ real_client = None
187
+ if isinstance(self._client, kubernetes.client.ApiClient):
188
+ real_client = self._client
189
+ elif isinstance(self._client, kubernetes.watch.Watch):
190
+ real_client = getattr(self._client, '_api_client', None)
191
+ else:
192
+ # Otherwise, the client is a typed client, the typed client
193
+ # is generated by codegen and all of them should have an
194
+ # 'api_client' attribute referring to the real client.
195
+ real_client = getattr(self._client, 'api_client', None)
196
+ if real_client is not None:
197
+ real_client.close()
198
+ else:
199
+ # logger may already be cleaned up during __del__ at shutdown
200
+ if logger is not None:
201
+ logger.debug(f'No client found for {self._client}')
202
+ except Exception as e: # pylint: disable=broad-except
203
+ if logger is not None:
204
+ logger.debug(f'Error closing Kubernetes client: {e}')
205
+
206
+
207
+ def wrap_kubernetes_client(func):
208
+ """Wraps kubernetes API clients for proper cleanup."""
209
+
210
+ @functools.wraps(func)
211
+ def wrapper(*args, **kwargs):
212
+ obj = func(*args, **kwargs)
213
+ return ClientWrapper(obj)
214
+
215
+ return wrapper
216
+
217
+
165
218
  @_api_logging_decorator('urllib3', logging.ERROR)
166
219
  @annotations.lru_cache(scope='request')
220
+ @wrap_kubernetes_client
167
221
  def core_api(context: Optional[str] = None):
168
222
  _load_config(context)
169
223
  return kubernetes.client.CoreV1Api()
@@ -171,6 +225,7 @@ def core_api(context: Optional[str] = None):
171
225
 
172
226
  @_api_logging_decorator('urllib3', logging.ERROR)
173
227
  @annotations.lru_cache(scope='request')
228
+ @wrap_kubernetes_client
174
229
  def storage_api(context: Optional[str] = None):
175
230
  _load_config(context)
176
231
  return kubernetes.client.StorageV1Api()
@@ -178,6 +233,7 @@ def storage_api(context: Optional[str] = None):
178
233
 
179
234
  @_api_logging_decorator('urllib3', logging.ERROR)
180
235
  @annotations.lru_cache(scope='request')
236
+ @wrap_kubernetes_client
181
237
  def auth_api(context: Optional[str] = None):
182
238
  _load_config(context)
183
239
  return kubernetes.client.RbacAuthorizationV1Api()
@@ -185,6 +241,7 @@ def auth_api(context: Optional[str] = None):
185
241
 
186
242
  @_api_logging_decorator('urllib3', logging.ERROR)
187
243
  @annotations.lru_cache(scope='request')
244
+ @wrap_kubernetes_client
188
245
  def networking_api(context: Optional[str] = None):
189
246
  _load_config(context)
190
247
  return kubernetes.client.NetworkingV1Api()
@@ -192,6 +249,7 @@ def networking_api(context: Optional[str] = None):
192
249
 
193
250
  @_api_logging_decorator('urllib3', logging.ERROR)
194
251
  @annotations.lru_cache(scope='request')
252
+ @wrap_kubernetes_client
195
253
  def custom_objects_api(context: Optional[str] = None):
196
254
  _load_config(context)
197
255
  return kubernetes.client.CustomObjectsApi()
@@ -199,6 +257,7 @@ def custom_objects_api(context: Optional[str] = None):
199
257
 
200
258
  @_api_logging_decorator('urllib3', logging.ERROR)
201
259
  @annotations.lru_cache(scope='global')
260
+ @wrap_kubernetes_client
202
261
  def node_api(context: Optional[str] = None):
203
262
  _load_config(context)
204
263
  return kubernetes.client.NodeV1Api()
@@ -206,6 +265,7 @@ def node_api(context: Optional[str] = None):
206
265
 
207
266
  @_api_logging_decorator('urllib3', logging.ERROR)
208
267
  @annotations.lru_cache(scope='request')
268
+ @wrap_kubernetes_client
209
269
  def apps_api(context: Optional[str] = None):
210
270
  _load_config(context)
211
271
  return kubernetes.client.AppsV1Api()
@@ -213,6 +273,7 @@ def apps_api(context: Optional[str] = None):
213
273
 
214
274
  @_api_logging_decorator('urllib3', logging.ERROR)
215
275
  @annotations.lru_cache(scope='request')
276
+ @wrap_kubernetes_client
216
277
  def batch_api(context: Optional[str] = None):
217
278
  _load_config(context)
218
279
  return kubernetes.client.BatchV1Api()
@@ -220,6 +281,7 @@ def batch_api(context: Optional[str] = None):
220
281
 
221
282
  @_api_logging_decorator('urllib3', logging.ERROR)
222
283
  @annotations.lru_cache(scope='request')
284
+ @wrap_kubernetes_client
223
285
  def api_client(context: Optional[str] = None):
224
286
  _load_config(context)
225
287
  return kubernetes.client.ApiClient()
@@ -227,6 +289,7 @@ def api_client(context: Optional[str] = None):
227
289
 
228
290
  @_api_logging_decorator('urllib3', logging.ERROR)
229
291
  @annotations.lru_cache(scope='request')
292
+ @wrap_kubernetes_client
230
293
  def custom_resources_api(context: Optional[str] = None):
231
294
  _load_config(context)
232
295
  return kubernetes.client.CustomObjectsApi()
@@ -234,6 +297,7 @@ def custom_resources_api(context: Optional[str] = None):
234
297
 
235
298
  @_api_logging_decorator('urllib3', logging.ERROR)
236
299
  @annotations.lru_cache(scope='request')
300
+ @wrap_kubernetes_client
237
301
  def watch(context: Optional[str] = None):
238
302
  _load_config(context)
239
303
  return kubernetes.watch.Watch()
@@ -3128,12 +3128,12 @@ def refresh_cluster_records() -> None:
3128
3128
  # request info in backend_utils.py.
3129
3129
  # Refactor this to use some other info to
3130
3130
  # determine if a launch is in progress.
3131
- requests = requests_lib.get_request_tasks(
3132
- req_filter=requests_lib.RequestTaskFilter(
3133
- status=[requests_lib.RequestStatus.RUNNING],
3134
- include_request_names=['sky.launch']))
3135
3131
  cluster_names_with_launch_request = {
3136
- request.cluster_name for request in requests
3132
+ request.cluster_name for request in requests_lib.get_request_tasks(
3133
+ req_filter=requests_lib.RequestTaskFilter(
3134
+ status=[requests_lib.RequestStatus.RUNNING],
3135
+ include_request_names=['sky.launch'],
3136
+ fields=['cluster_name']))
3137
3137
  }
3138
3138
  cluster_names_without_launch_request = (cluster_names -
3139
3139
  cluster_names_with_launch_request)
@@ -3356,13 +3356,13 @@ def get_clusters(
3356
3356
  # request info in backend_utils.py.
3357
3357
  # Refactor this to use some other info to
3358
3358
  # determine if a launch is in progress.
3359
- requests = requests_lib.get_request_tasks(
3360
- req_filter=requests_lib.RequestTaskFilter(
3361
- status=[requests_lib.RequestStatus.RUNNING],
3362
- include_request_names=['sky.launch'],
3363
- cluster_names=cluster_names))
3364
3359
  cluster_names_with_launch_request = {
3365
- request.cluster_name for request in requests
3360
+ request.cluster_name for request in requests_lib.get_request_tasks(
3361
+ req_filter=requests_lib.RequestTaskFilter(
3362
+ status=[requests_lib.RequestStatus.RUNNING],
3363
+ include_request_names=['sky.launch'],
3364
+ cluster_names=cluster_names,
3365
+ fields=['cluster_name']))
3366
3366
  }
3367
3367
  # Preserve the index of the cluster name as it appears on "records"
3368
3368
  cluster_names_without_launch_request = [
@@ -2471,6 +2471,9 @@ class CloudVmRayResourceHandle(backends.backend.ResourceHandle):
2471
2471
  def get_cluster_name(self):
2472
2472
  return self.cluster_name
2473
2473
 
2474
+ def get_cluster_name_on_cloud(self):
2475
+ return self.cluster_name_on_cloud
2476
+
2474
2477
  def _use_internal_ips(self):
2475
2478
  """Returns whether to use internal IPs for SSH connections."""
2476
2479
  # Directly load the `use_internal_ips` flag from the cluster yaml
@@ -2954,6 +2957,12 @@ class CloudVmRayResourceHandle(backends.backend.ResourceHandle):
2954
2957
  def cluster_yaml(self, value: Optional[str]):
2955
2958
  self._cluster_yaml = value
2956
2959
 
2960
+ @property
2961
+ def instance_ids(self):
2962
+ if self.cached_cluster_info is not None:
2963
+ return self.cached_cluster_info.instance_ids()
2964
+ return None
2965
+
2957
2966
  @property
2958
2967
  def ssh_user(self):
2959
2968
  if self.cached_cluster_info is not None:
@@ -3623,9 +3632,10 @@ class CloudVmRayBackend(backends.Backend['CloudVmRayResourceHandle']):
3623
3632
  gap_seconds = _RETRY_UNTIL_UP_INIT_GAP_SECONDS
3624
3633
  retry_message = ux_utils.retry_message(
3625
3634
  f'Retry after {gap_seconds:.0f}s ')
3626
- hint_message = (f'\n{retry_message} '
3627
- f'{ux_utils.log_path_hint(log_path)}'
3628
- f'{colorama.Style.RESET_ALL}')
3635
+ hint_message = (
3636
+ f'\n{retry_message} '
3637
+ f'{ux_utils.provision_hint(cluster_name)}'
3638
+ f'{colorama.Style.RESET_ALL}')
3629
3639
 
3630
3640
  # Add cluster event for retry.
3631
3641
  global_user_state.add_cluster_event(
@@ -3654,7 +3664,7 @@ class CloudVmRayBackend(backends.Backend['CloudVmRayResourceHandle']):
3654
3664
  logger.error(
3655
3665
  ux_utils.error_message(
3656
3666
  'Failed to provision resources. '
3657
- f'{ux_utils.log_path_hint(log_path)}'))
3667
+ f'{ux_utils.provision_hint(cluster_name)}'))
3658
3668
  error_message += (
3659
3669
  '\nTo keep retrying until the cluster is up, use '
3660
3670
  'the `--retry-until-up` flag.')
@@ -3713,6 +3723,7 @@ class CloudVmRayBackend(backends.Backend['CloudVmRayResourceHandle']):
3713
3723
  # manually or by the cloud provider.
3714
3724
  # Optimize the case where the cluster's IPs can be retrieved
3715
3725
  # from cluster_info.
3726
+ handle.cached_cluster_info = cluster_info
3716
3727
  handle.docker_user = cluster_info.docker_user
3717
3728
  handle.update_cluster_ips(max_attempts=_FETCH_IP_MAX_ATTEMPTS,
3718
3729
  cluster_info=cluster_info)
sky/client/cli/command.py CHANGED
@@ -2150,6 +2150,12 @@ def queue(clusters: List[str], skip_finished: bool, all_users: bool):
2150
2150
  is_flag=True,
2151
2151
  default=False,
2152
2152
  help='Stream the cluster provisioning logs (provision.log).')
2153
+ @click.option('--worker',
2154
+ '-w',
2155
+ default=None,
2156
+ type=int,
2157
+ help='The worker ID to stream the logs from. '
2158
+ 'If not set, stream the logs of the head node.')
2153
2159
  @click.option(
2154
2160
  '--sync-down',
2155
2161
  '-s',
@@ -2187,6 +2193,7 @@ def logs(
2187
2193
  cluster: str,
2188
2194
  job_ids: Tuple[str, ...],
2189
2195
  provision: bool,
2196
+ worker: Optional[int],
2190
2197
  sync_down: bool,
2191
2198
  status: bool, # pylint: disable=redefined-outer-name
2192
2199
  follow: bool,
@@ -2216,6 +2223,13 @@ def logs(
2216
2223
  4. If the job fails or fetching the logs fails, the command will exit with
2217
2224
  a non-zero return code.
2218
2225
  """
2226
+ if worker is not None:
2227
+ if not provision:
2228
+ raise click.UsageError(
2229
+ '--worker can only be used with --provision.')
2230
+ if worker < 1:
2231
+ raise click.UsageError('--worker must be a positive integer.')
2232
+
2219
2233
  if provision and (sync_down or status or job_ids):
2220
2234
  raise click.UsageError(
2221
2235
  '--provision cannot be combined with job log options '
@@ -2235,7 +2249,11 @@ def logs(
2235
2249
 
2236
2250
  if provision:
2237
2251
  # Stream provision logs
2238
- sys.exit(sdk.tail_provision_logs(cluster, follow=follow, tail=tail))
2252
+ sys.exit(
2253
+ sdk.tail_provision_logs(cluster_name=cluster,
2254
+ worker=worker,
2255
+ follow=follow,
2256
+ tail=tail))
2239
2257
 
2240
2258
  if sync_down:
2241
2259
  with rich_utils.client_status(
@@ -3251,9 +3269,11 @@ def _down_or_stop_clusters(
3251
3269
  request_id = sdk.autostop(name, idle_minutes_to_autostop,
3252
3270
  wait_for, down)
3253
3271
  request_ids.append(request_id)
3272
+ progress.stop()
3254
3273
  _async_call_or_wait(
3255
3274
  request_id, async_call,
3256
3275
  server_constants.REQUEST_NAME_PREFIX + operation)
3276
+ progress.start()
3257
3277
  except (exceptions.NotSupportedError, exceptions.ClusterNotUpError,
3258
3278
  exceptions.CloudError) as e:
3259
3279
  message = str(e)
@@ -3281,9 +3301,11 @@ def _down_or_stop_clusters(
3281
3301
  else:
3282
3302
  request_id = sdk.stop(name, purge=purge)
3283
3303
  request_ids.append(request_id)
3304
+ progress.stop()
3284
3305
  _async_call_or_wait(
3285
3306
  request_id, async_call,
3286
3307
  server_constants.REQUEST_NAME_PREFIX + operation)
3308
+ progress.start()
3287
3309
  if not async_call:
3288
3310
  # Remove the cluster from the SSH config file as soon as it
3289
3311
  # is stopped or downed.
@@ -3317,6 +3339,10 @@ def _down_or_stop_clusters(
3317
3339
  progress.start()
3318
3340
 
3319
3341
  with progress:
3342
+ # we write a new line here to avoid the "Waiting for 'sky.down'
3343
+ # request to be scheduled" message from being printed on the same line
3344
+ # as the "Terminating <num> clusters..." message
3345
+ click.echo('')
3320
3346
  subprocess_utils.run_in_parallel(_down_or_stop, clusters)
3321
3347
  progress.live.transient = False
3322
3348
  # Make sure the progress bar not mess up the terminal.
@@ -6169,19 +6195,22 @@ def api_logs(request_id: Optional[str], server_logs: bool,
6169
6195
  **_get_shell_complete_args(_complete_api_request))
6170
6196
  @flags.all_option('Cancel all your requests.')
6171
6197
  @flags.all_users_option('Cancel all requests from all users.')
6198
+ @flags.yes_option()
6172
6199
  @usage_lib.entrypoint
6173
6200
  # pylint: disable=redefined-builtin
6174
- def api_cancel(request_ids: Optional[List[str]], all: bool, all_users: bool):
6201
+ def api_cancel(request_ids: Optional[List[str]], all: bool, all_users: bool,
6202
+ yes: bool):
6175
6203
  """Cancel a request running on SkyPilot API server."""
6176
6204
  if all or all_users:
6177
- keyword = 'ALL USERS\'' if all_users else 'YOUR'
6178
- user_input = click.prompt(
6179
- f'This will cancel all {keyword} requests.\n'
6180
- f'To proceed, please type {colorama.Style.BRIGHT}'
6181
- f'\'cancel all requests\'{colorama.Style.RESET_ALL}',
6182
- type=str)
6183
- if user_input != 'cancel all requests':
6184
- raise click.Abort()
6205
+ if not yes:
6206
+ keyword = 'ALL USERS\'' if all_users else 'YOUR'
6207
+ user_input = click.prompt(
6208
+ f'This will cancel all {keyword} requests.\n'
6209
+ f'To proceed, please type {colorama.Style.BRIGHT}'
6210
+ f'\'cancel all requests\'{colorama.Style.RESET_ALL}',
6211
+ type=str)
6212
+ if user_input != 'cancel all requests':
6213
+ raise click.Abort()
6185
6214
  request_ids = None
6186
6215
  cancelled_request_ids = sdk.get(
6187
6216
  sdk.api_cancel(request_ids=request_ids, all_users=all_users))
sky/client/cli/flags.py CHANGED
@@ -284,8 +284,10 @@ def config_option(expose_value: bool):
284
284
  return return_option_decorator
285
285
 
286
286
 
287
- def yes_option():
287
+ def yes_option(helptext: Optional[str] = None):
288
288
  """A decorator for the --yes/-y option."""
289
+ if helptext is None:
290
+ helptext = 'Skip confirmation prompt.'
289
291
 
290
292
  def return_option_decorator(func):
291
293
  return click.option('--yes',
@@ -293,7 +295,7 @@ def yes_option():
293
295
  is_flag=True,
294
296
  default=False,
295
297
  required=False,
296
- help='Skip confirmation prompt.')(func)
298
+ help=helptext)(func)
297
299
 
298
300
  return return_option_decorator
299
301
 
sky/client/sdk.py CHANGED
@@ -925,6 +925,7 @@ def tail_logs(
925
925
  @annotations.client_api
926
926
  @rest.retry_transient_errors()
927
927
  def tail_provision_logs(cluster_name: str,
928
+ worker: Optional[int] = None,
928
929
  follow: bool = True,
929
930
  tail: int = 0,
930
931
  output_stream: Optional['io.TextIOBase'] = None) -> int:
@@ -932,17 +933,31 @@ def tail_provision_logs(cluster_name: str,
932
933
 
933
934
  Args:
934
935
  cluster_name: name of the cluster.
936
+ worker: worker id in multi-node cluster.
937
+ If None, stream the logs of the head node.
935
938
  follow: follow the logs.
936
939
  tail: lines from end to tail.
937
940
  output_stream: optional stream to write logs.
938
941
  Returns:
939
942
  Exit code 0 on streaming success; raises on HTTP error.
940
943
  """
941
- body = payloads.ClusterNameBody(cluster_name=cluster_name)
944
+ body = payloads.ProvisionLogsBody(cluster_name=cluster_name)
945
+
946
+ if worker is not None:
947
+ remote_api_version = versions.get_remote_api_version()
948
+ if remote_api_version is not None and remote_api_version >= 21:
949
+ if worker < 1:
950
+ raise ValueError('Worker must be a positive integer.')
951
+ body.worker = worker
952
+ else:
953
+ raise exceptions.APINotSupportedError(
954
+ 'Worker node provision logs are not supported in your API '
955
+ 'server. Please upgrade to a newer API server to use it.')
942
956
  params = {
943
957
  'follow': str(follow).lower(),
944
958
  'tail': tail,
945
959
  }
960
+
946
961
  response = server_common.make_authenticated_request(
947
962
  'POST',
948
963
  '/provision_logs',
@@ -951,13 +966,21 @@ def tail_provision_logs(cluster_name: str,
951
966
  stream=True,
952
967
  timeout=(client_common.API_SERVER_REQUEST_CONNECTION_TIMEOUT_SECONDS,
953
968
  None))
969
+ # Check for HTTP errors before streaming the response
970
+ if response.status_code != 200:
971
+ with ux_utils.print_exception_no_traceback():
972
+ raise exceptions.CommandError(response.status_code,
973
+ 'tail_provision_logs',
974
+ 'Failed to stream provision logs',
975
+ response.text)
976
+
954
977
  # Log request is idempotent when tail is 0, thus can resume previous
955
978
  # streaming point on retry.
956
979
  # request_id=None here because /provision_logs does not create an async
957
980
  # request. Instead, it streams a plain file from the server. This does NOT
958
981
  # violate the stream_response doc warning about None in multi-user
959
- # environments: we are not asking stream_response to select the latest
960
- # request”. We already have the HTTP response to stream; request_id=None
982
+ # environments: we are not asking stream_response to select "the latest
983
+ # request". We already have the HTTP response to stream; request_id=None
961
984
  # merely disables the follow-up GET. It is also necessary for --no-follow
962
985
  # to return cleanly after printing the tailed lines. If we provided a
963
986
  # non-None request_id here, the get(request_id) in stream_response(
@@ -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/4614e06482d7309e.css" as="style"/><link rel="stylesheet" href="/dashboard/_next/static/css/4614e06482d7309e.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-3c431f6c9086e487.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-ce361c6959bc2001.js" defer=""></script><script src="/dashboard/_next/static/chunks/pages/_error-c66a4e8afc46f17b.js" defer=""></script><script src="/dashboard/_next/static/8e35zdobdd0bK_Nkba03m/_buildManifest.js" defer=""></script><script src="/dashboard/_next/static/8e35zdobdd0bK_Nkba03m/_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":"8e35zdobdd0bK_Nkba03m","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/4614e06482d7309e.css" as="style"/><link rel="stylesheet" href="/dashboard/_next/static/css/4614e06482d7309e.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-919e3c01ab6b2633.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-ce361c6959bc2001.js" defer=""></script><script src="/dashboard/_next/static/chunks/pages/_error-c66a4e8afc46f17b.js" defer=""></script><script src="/dashboard/_next/static/IgACOQPupLbX9z-RYVEDx/_buildManifest.js" defer=""></script><script src="/dashboard/_next/static/IgACOQPupLbX9z-RYVEDx/_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":"IgACOQPupLbX9z-RYVEDx","assetPrefix":"/dashboard","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
@@ -0,0 +1 @@
1
+ self.__BUILD_MANIFEST=function(s,c,e,a,t,f,u,n,o,b,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-57221ec2e4e01076.js"],"/clusters/[cluster]":[s,c,e,f,u,j,b,a,t,n,r,o,i,k,d,"static/chunks/6856-5c94d394259cdb6e.js","static/chunks/1871-df9f87fcb7f24292.js","static/chunks/pages/clusters/[cluster]-18b334dedbd9f6f2.js"],"/clusters/[cluster]/[job]":[s,c,e,f,a,t,o,"static/chunks/pages/clusters/[cluster]/[job]-602eeead010ec1d6.js"],"/config":["static/chunks/pages/config-dfb9bf07b13045f4.js"],"/infra":["static/chunks/pages/infra-872e6a00165534f4.js"],"/infra/[context]":["static/chunks/pages/infra/[context]-44ce535a0a0ad4ec.js"],"/jobs":["static/chunks/pages/jobs-0dc34cf9a8710a9f.js"],"/jobs/pools/[pool]":[s,c,e,u,b,a,t,n,"static/chunks/pages/jobs/pools/[pool]-e020fd69dbe76cea.js"],"/jobs/[job]":[s,c,e,f,u,b,a,t,n,o,"static/chunks/pages/jobs/[job]-8677af16befde039.js"],"/users":["static/chunks/pages/users-3a543725492fb896.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,u,j,a,t,n,r,o,i,k,d,"static/chunks/1141-ec6f902ffb865853.js","static/chunks/pages/workspaces/[name]-9ad108cd67d16d96.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/6135-4b4d5e824b7f9d3c.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-d014dc5b9412fade.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();
@@ -0,0 +1,11 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1141],{99333:function(e,s,a){a.d(s,{Z:function(){return t}});/**
2
+ * @license lucide-react v0.407.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */let t=(0,a(60998).Z)("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]])},98418:function(e,s,a){a.d(s,{Z:function(){return t}});/**
7
+ * @license lucide-react v0.407.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */let t=(0,a(60998).Z)("Trash",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}]])},1812:function(e,s,a){a.d(s,{X:function(){return n}});var t=a(85893),r=a(67294);let l=e=>{if(!(null==e?void 0:e.message))return"An unexpected error occurred.";let s=e.message;return s.includes("failed:")&&(s=s.split("failed:")[1].trim()),s},n=e=>{let{error:s,title:a="Error",onDismiss:n}=e,[c,i]=(0,r.useState)(!1);if((0,r.useEffect)(()=>{s&&i(!1)},[s]),!s||c)return null;let o="string"==typeof s?s:l(s);return(0,t.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-md p-3 mb-4",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex",children:[(0,t.jsx)("div",{className:"flex-shrink-0",children:(0,t.jsx)("svg",{className:"h-5 w-5 text-red-400",viewBox:"0 0 20 20",fill:"currentColor",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})})}),(0,t.jsx)("div",{className:"ml-3",children:(0,t.jsxs)("div",{className:"text-sm text-red-800",children:[(0,t.jsxs)("strong",{children:[a,":"]})," ",o]})})]}),(0,t.jsx)("button",{onClick:()=>{i(!0),n&&n()},className:"flex-shrink-0 ml-4 text-red-400 hover:text-red-600 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 focus:ring-offset-red-50 rounded","aria-label":"Dismiss error",children:(0,t.jsx)("svg",{className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:(0,t.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]})})}},69123:function(e,s,a){a.d(s,{g:function(){return n}});var t=a(85893),r=a(67294),l=a(32350);let n=r.forwardRef((e,s)=>{let{className:a,...r}=e;return(0,t.jsx)("textarea",{className:(0,l.cn)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",a),ref:s,...r})});n.displayName="Textarea"},11141:function(e,s,a){a.r(s),a.d(s,{WorkspaceEditor:function(){return _}});var t=a(85893),r=a(67294),l=a(11163),n=a(17324),c=a(23266),i=a(68969);a(6135);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"})]})]})})]})]})}}}]);