@phala/cloud 0.1.1 → 0.2.0

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.
package/dist/index.js CHANGED
@@ -32,7 +32,9 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  AddComposeHashSchema: () => AddComposeHashSchema,
34
34
  ApiErrorSchema: () => ApiErrorSchema,
35
+ AuthError: () => AuthError,
35
36
  AvailableNodesSchema: () => AvailableNodesSchema,
37
+ BusinessError: () => BusinessError,
36
38
  CommitCvmComposeFileUpdateRequestSchema: () => CommitCvmComposeFileUpdateRequestSchema,
37
39
  CommitCvmComposeFileUpdateSchema: () => CommitCvmComposeFileUpdateSchema,
38
40
  CommitCvmProvisionRequestSchema: () => CommitCvmProvisionRequestSchema,
@@ -48,12 +50,15 @@ __export(index_exports, {
48
50
  CvmNetworkSchema: () => CvmNetworkSchema,
49
51
  CvmNetworkUrlsSchema: () => CvmNetworkUrlsSchema,
50
52
  CvmNodeSchema: () => CvmNodeSchema,
53
+ CvmStateSchema: () => CvmStateSchema,
51
54
  CvmSystemInfoSchema: () => CvmSystemInfoSchema,
52
55
  DeleteCvmRequestSchema: () => DeleteCvmRequestSchema,
53
56
  DeployAppAuthRequestSchema: () => DeployAppAuthRequestSchema,
54
57
  DeployAppAuthSchema: () => DeployAppAuthSchema,
55
58
  GetAppEnvEncryptPubKeyRequestSchema: () => GetAppEnvEncryptPubKeyRequestSchema,
56
59
  GetAppEnvEncryptPubKeySchema: () => GetAppEnvEncryptPubKeySchema,
60
+ GetAvailableOSImagesRequestSchema: () => GetAvailableOSImagesRequestSchema,
61
+ GetAvailableOSImagesResponseSchema: () => GetAvailableOSImagesResponseSchema,
57
62
  GetCvmAttestationRequestSchema: () => GetCvmAttestationRequestSchema,
58
63
  GetCvmComposeFileRequestSchema: () => GetCvmComposeFileRequestSchema,
59
64
  GetCvmContainersStatsRequestSchema: () => GetCvmContainersStatsRequestSchema,
@@ -62,6 +67,7 @@ __export(index_exports, {
62
67
  GetCvmListRequestSchema: () => GetCvmListRequestSchema,
63
68
  GetCvmListSchema: () => GetCvmListSchema,
64
69
  GetCvmNetworkRequestSchema: () => GetCvmNetworkRequestSchema,
70
+ GetCvmStateRequestSchema: () => GetCvmStateRequestSchema,
65
71
  GetCvmStatsRequestSchema: () => GetCvmStatsRequestSchema,
66
72
  GetKmsInfoRequestSchema: () => GetKmsInfoRequestSchema,
67
73
  GetKmsListRequestSchema: () => GetKmsListRequestSchema,
@@ -71,9 +77,14 @@ __export(index_exports, {
71
77
  ListInstanceTypesRequestSchema: () => ListInstanceTypesRequestSchema,
72
78
  ListWorkspacesSchema: () => ListWorkspacesSchema,
73
79
  ManagedUserSchema: () => ManagedUserSchema,
80
+ MaxRetriesExceededError: () => MaxRetriesExceededError,
74
81
  NetworkError: () => NetworkError,
82
+ NextAppIdsRequestSchema: () => NextAppIdsRequestSchema,
83
+ NextAppIdsSchema: () => NextAppIdsSchema,
84
+ OSImageVariantSchema: () => OSImageVariantSchema,
75
85
  PaginatedInstanceTypesSchema: () => PaginatedInstanceTypesSchema,
76
86
  PaginationMetadataSchema: () => PaginationMetadataSchema,
87
+ PhalaCloudError: () => PhalaCloudError,
77
88
  ProvisionCvmComposeFileUpdateRequestSchema: () => ProvisionCvmComposeFileUpdateRequestSchema,
78
89
  ProvisionCvmComposeFileUpdateResultSchema: () => ProvisionCvmComposeFileUpdateResultSchema,
79
90
  ProvisionCvmRequestSchema: () => ProvisionCvmRequestSchema,
@@ -81,15 +92,21 @@ __export(index_exports, {
81
92
  RequestError: () => RequestError,
82
93
  RestartCvmRequestSchema: () => RestartCvmRequestSchema,
83
94
  SUPPORTED_CHAINS: () => SUPPORTED_CHAINS,
95
+ ServerError: () => ServerError,
84
96
  ShutdownCvmRequestSchema: () => ShutdownCvmRequestSchema,
85
97
  StartCvmRequestSchema: () => StartCvmRequestSchema,
86
98
  StopCvmRequestSchema: () => StopCvmRequestSchema,
87
99
  TransactionError: () => TransactionError,
100
+ UnknownError: () => UnknownError,
88
101
  UpdateCvmResourcesRequestSchema: () => UpdateCvmResourcesRequestSchema,
89
102
  UpdateCvmVisibilityRequestSchema: () => UpdateCvmVisibilityRequestSchema,
103
+ UpdateOsImageRequestSchema: () => UpdateOsImageRequestSchema,
90
104
  VMSchema: () => VMSchema,
105
+ ValidationError: () => ValidationError,
91
106
  VmInfoSchema: () => VmInfoSchema,
92
107
  WalletError: () => WalletError,
108
+ WatchAbortedError: () => WatchAbortedError,
109
+ WatchCvmStateRequestSchema: () => WatchCvmStateRequestSchema,
93
110
  WorkspaceResponseSchema: () => WorkspaceResponseSchema,
94
111
  addComposeHash: () => addComposeHash,
95
112
  addNetwork: () => addNetwork,
@@ -116,8 +133,11 @@ __export(index_exports, {
116
133
  executeTransaction: () => executeTransaction,
117
134
  executeTransactionWithRetry: () => executeTransactionWithRetry,
118
135
  extractNetworkClients: () => extractNetworkClients,
136
+ formatErrorMessage: () => formatErrorMessage,
137
+ formatValidationErrors: () => formatValidationErrors,
119
138
  getAppEnvEncryptPubKey: () => getAppEnvEncryptPubKey,
120
139
  getAvailableNodes: () => getAvailableNodes,
140
+ getAvailableOsImages: () => getAvailableOsImages,
121
141
  getComposeHash: () => import_get_compose_hash3.getComposeHash,
122
142
  getCurrentUser: () => getCurrentUser,
123
143
  getCvmAttestation: () => getCvmAttestation,
@@ -127,13 +147,17 @@ __export(index_exports, {
127
147
  getCvmInfo: () => getCvmInfo,
128
148
  getCvmList: () => getCvmList,
129
149
  getCvmNetwork: () => getCvmNetwork,
150
+ getCvmState: () => getCvmState,
130
151
  getCvmStats: () => getCvmStats,
131
152
  getErrorMessage: () => getErrorMessage,
132
153
  getKmsInfo: () => getKmsInfo,
133
154
  getKmsList: () => getKmsList,
155
+ getValidationFields: () => getValidationFields,
134
156
  getWorkspace: () => getWorkspace,
135
157
  listInstanceTypes: () => listInstanceTypes,
136
158
  listWorkspaces: () => listWorkspaces,
159
+ nextAppIds: () => nextAppIds,
160
+ parseApiError: () => parseApiError,
137
161
  parseEnv: () => parseEnv,
138
162
  parseEnvVars: () => parseEnvVars,
139
163
  preprocessAppCompose: () => preprocessAppCompose,
@@ -148,6 +172,7 @@ __export(index_exports, {
148
172
  safeDeployAppAuth: () => safeDeployAppAuth,
149
173
  safeGetAppEnvEncryptPubKey: () => safeGetAppEnvEncryptPubKey,
150
174
  safeGetAvailableNodes: () => safeGetAvailableNodes,
175
+ safeGetAvailableOsImages: () => safeGetAvailableOsImages,
151
176
  safeGetCurrentUser: () => safeGetCurrentUser,
152
177
  safeGetCvmAttestation: () => safeGetCvmAttestation,
153
178
  safeGetCvmComposeFile: () => safeGetCvmComposeFile,
@@ -156,12 +181,14 @@ __export(index_exports, {
156
181
  safeGetCvmInfo: () => safeGetCvmInfo,
157
182
  safeGetCvmList: () => safeGetCvmList,
158
183
  safeGetCvmNetwork: () => safeGetCvmNetwork,
184
+ safeGetCvmState: () => safeGetCvmState,
159
185
  safeGetCvmStats: () => safeGetCvmStats,
160
186
  safeGetKmsInfo: () => safeGetKmsInfo,
161
187
  safeGetKmsList: () => safeGetKmsList,
162
188
  safeGetWorkspace: () => safeGetWorkspace,
163
189
  safeListInstanceTypes: () => safeListInstanceTypes,
164
190
  safeListWorkspaces: () => safeListWorkspaces,
191
+ safeNextAppIds: () => safeNextAppIds,
165
192
  safeProvisionCvm: () => safeProvisionCvm,
166
193
  safeProvisionCvmComposeFileUpdate: () => safeProvisionCvmComposeFileUpdate,
167
194
  safeRestartCvm: () => safeRestartCvm,
@@ -170,6 +197,7 @@ __export(index_exports, {
170
197
  safeStopCvm: () => safeStopCvm,
171
198
  safeUpdateCvmResources: () => safeUpdateCvmResources,
172
199
  safeUpdateCvmVisibility: () => safeUpdateCvmVisibility,
200
+ safeUpdateOsImage: () => safeUpdateOsImage,
173
201
  safeValidateActionParameters: () => safeValidateActionParameters,
174
202
  shutdownCvm: () => shutdownCvm,
175
203
  sortObject: () => sortObject,
@@ -178,10 +206,12 @@ __export(index_exports, {
178
206
  switchToNetwork: () => switchToNetwork,
179
207
  updateCvmResources: () => updateCvmResources,
180
208
  updateCvmVisibility: () => updateCvmVisibility,
209
+ updateOsImage: () => updateOsImage,
181
210
  validateActionParameters: () => validateActionParameters,
182
211
  validateNetworkPrerequisites: () => validateNetworkPrerequisites,
183
212
  verifyEnvEncryptPublicKey: () => import_verify_env_encrypt_public_key.verifyEnvEncryptPublicKey,
184
213
  waitForTransactionReceipt: () => waitForTransactionReceipt,
214
+ watchCvmState: () => watchCvmState,
185
215
  withComposeMethods: () => withComposeMethods
186
216
  });
187
217
  module.exports = __toCommonJS(index_exports);
@@ -189,8 +219,9 @@ module.exports = __toCommonJS(index_exports);
189
219
  // src/client.ts
190
220
  var import_ofetch = require("ofetch");
191
221
  var import_debug = __toESM(require("debug"));
222
+ var import_mitt = __toESM(require("mitt"));
192
223
 
193
- // src/types/client.ts
224
+ // src/utils/errors.ts
194
225
  var import_zod = require("zod");
195
226
  var ApiErrorSchema = import_zod.z.object({
196
227
  detail: import_zod.z.union([
@@ -203,21 +234,34 @@ var ApiErrorSchema = import_zod.z.object({
203
234
  })
204
235
  ),
205
236
  import_zod.z.record(import_zod.z.unknown())
206
- ]),
237
+ ]).optional(),
207
238
  type: import_zod.z.string().optional(),
208
239
  code: import_zod.z.string().optional()
209
240
  });
210
- var RequestError = class _RequestError extends Error {
211
- constructor(message, options) {
241
+ var PhalaCloudError = class extends Error {
242
+ constructor(message, data) {
212
243
  super(message);
244
+ this.name = this.constructor.name;
245
+ this.status = data.status;
246
+ this.statusText = data.statusText;
247
+ this.detail = data.detail;
248
+ if (Error.captureStackTrace) {
249
+ Error.captureStackTrace(this, this.constructor);
250
+ }
251
+ }
252
+ };
253
+ var RequestError = class _RequestError extends PhalaCloudError {
254
+ constructor(message, options) {
255
+ super(message, {
256
+ status: options?.status ?? 0,
257
+ statusText: options?.statusText ?? "Unknown Error",
258
+ detail: options?.detail || message
259
+ });
213
260
  this.name = "RequestError";
214
261
  this.isRequestError = true;
215
- this.status = options?.status;
216
- this.statusText = options?.statusText;
217
262
  this.data = options?.data;
218
263
  this.request = options?.request;
219
264
  this.response = options?.response;
220
- this.detail = options?.detail || message;
221
265
  this.code = options?.code;
222
266
  this.type = options?.type;
223
267
  }
@@ -258,9 +302,172 @@ var RequestError = class _RequestError extends Error {
258
302
  });
259
303
  }
260
304
  };
305
+ var ValidationError = class extends PhalaCloudError {
306
+ constructor(message, data) {
307
+ super(message, data);
308
+ this.isValidationError = true;
309
+ this.validationErrors = data.validationErrors;
310
+ }
311
+ };
312
+ var AuthError = class extends PhalaCloudError {
313
+ constructor() {
314
+ super(...arguments);
315
+ this.isAuthError = true;
316
+ }
317
+ };
318
+ var BusinessError = class extends PhalaCloudError {
319
+ constructor() {
320
+ super(...arguments);
321
+ this.isBusinessError = true;
322
+ }
323
+ };
324
+ var ServerError = class extends PhalaCloudError {
325
+ constructor() {
326
+ super(...arguments);
327
+ this.isServerError = true;
328
+ }
329
+ };
330
+ var UnknownError = class extends PhalaCloudError {
331
+ constructor() {
332
+ super(...arguments);
333
+ this.isUnknownError = true;
334
+ }
335
+ };
336
+ function extractFieldPath(loc) {
337
+ const filtered = loc.filter((part) => {
338
+ if (typeof part === "string") {
339
+ return !["body", "query", "path", "header"].includes(part);
340
+ }
341
+ return true;
342
+ });
343
+ return filtered.length > 0 ? filtered.join(".") : "unknown";
344
+ }
345
+ function parseValidationErrors(detail) {
346
+ if (!Array.isArray(detail)) {
347
+ return {
348
+ errors: [],
349
+ message: typeof detail === "string" ? detail : "Validation error"
350
+ };
351
+ }
352
+ const errors = detail.map((item) => ({
353
+ field: extractFieldPath(item.loc),
354
+ message: item.msg,
355
+ type: item.type,
356
+ context: item.ctx
357
+ }));
358
+ const count = errors.length;
359
+ const message = count === 1 ? `Validation failed: ${errors[0].message}` : `Validation failed (${count} issue${count > 1 ? "s" : ""})`;
360
+ return { errors, message };
361
+ }
362
+ function categorizeErrorType(status) {
363
+ if (status === 422) {
364
+ return "validation";
365
+ }
366
+ if (status === 401) {
367
+ return "auth";
368
+ }
369
+ if (status === 403) {
370
+ return "auth";
371
+ }
372
+ if (status >= 400 && status < 500) {
373
+ return "business";
374
+ }
375
+ if (status >= 500) {
376
+ return "server";
377
+ }
378
+ return "unknown";
379
+ }
380
+ function extractPrimaryMessage(status, detail, defaultMessage) {
381
+ if (status === 422 && Array.isArray(detail)) {
382
+ const { message } = parseValidationErrors(detail);
383
+ return message;
384
+ }
385
+ if (typeof detail === "string") {
386
+ return detail;
387
+ }
388
+ if (detail && typeof detail === "object" && "message" in detail) {
389
+ const msg = detail.message;
390
+ if (typeof msg === "string") {
391
+ return msg;
392
+ }
393
+ }
394
+ return defaultMessage;
395
+ }
396
+ function parseApiError(requestError) {
397
+ const status = requestError.status ?? 0;
398
+ const statusText = requestError.statusText ?? "Unknown Error";
399
+ const detail = requestError.detail;
400
+ const errorType = categorizeErrorType(status);
401
+ const message = extractPrimaryMessage(status, detail, requestError.message);
402
+ const commonData = {
403
+ status,
404
+ statusText,
405
+ detail
406
+ };
407
+ if (errorType === "validation" && Array.isArray(detail)) {
408
+ const { errors } = parseValidationErrors(detail);
409
+ return new ValidationError(message, {
410
+ ...commonData,
411
+ validationErrors: errors
412
+ });
413
+ }
414
+ if (errorType === "auth") {
415
+ return new AuthError(message, commonData);
416
+ }
417
+ if (errorType === "business") {
418
+ return new BusinessError(message, commonData);
419
+ }
420
+ if (errorType === "server") {
421
+ return new ServerError(message, commonData);
422
+ }
423
+ return new UnknownError(message, commonData);
424
+ }
425
+ function getValidationFields(error) {
426
+ if (error instanceof ValidationError) {
427
+ return error.validationErrors.map((e) => e.field);
428
+ }
429
+ return [];
430
+ }
431
+ function formatValidationErrors(errors, options) {
432
+ const { numbered = true, indent = 2, showFields = true } = options ?? {};
433
+ const indentStr = " ".repeat(indent);
434
+ return errors.map((error, index) => {
435
+ const prefix = numbered ? `${index + 1}. ` : "\u2022 ";
436
+ const field = showFields ? `${error.field}: ` : "";
437
+ return `${indentStr}${prefix}${field}${error.message}`;
438
+ }).join("\n");
439
+ }
440
+ function formatErrorMessage(error, options) {
441
+ const { showFields = true, showType = false } = options ?? {};
442
+ const parts = [];
443
+ if (showType) {
444
+ parts.push(`[${error.constructor.name.toUpperCase()}]`);
445
+ }
446
+ parts.push(error.message);
447
+ if (error instanceof ValidationError && error.validationErrors.length > 0) {
448
+ parts.push("");
449
+ parts.push(formatValidationErrors(error.validationErrors, { showFields }));
450
+ }
451
+ return parts.join("\n");
452
+ }
453
+ function getErrorMessage(error) {
454
+ if (typeof error.detail === "string") {
455
+ return error.detail;
456
+ }
457
+ if (Array.isArray(error.detail)) {
458
+ if (error.detail.length > 0) {
459
+ return error.detail[0]?.msg || "Validation error";
460
+ }
461
+ return "Validation error";
462
+ }
463
+ if (typeof error.detail === "object" && error.detail !== null) {
464
+ return JSON.stringify(error.detail);
465
+ }
466
+ return "Unknown error occurred";
467
+ }
261
468
 
262
469
  // src/client.ts
263
- var SUPPORTED_API_VERSIONS = ["2025-05-31"];
470
+ var SUPPORTED_API_VERSIONS = ["2025-05-31", "2025-10-28"];
264
471
  var logger = (0, import_debug.default)("phala::api-client");
265
472
  function formatHeaders(headers) {
266
473
  return Object.entries(headers).map(([key, value]) => ` -H "${key}: ${value}"`).join("\n");
@@ -286,18 +493,14 @@ function formatResponse(status, statusText, headers, body) {
286
493
  }
287
494
  var Client = class {
288
495
  constructor(config = {}) {
496
+ this.emitter = (0, import_mitt.default)();
289
497
  const resolvedConfig = {
290
498
  ...config,
291
499
  apiKey: config.apiKey || process?.env?.PHALA_CLOUD_API_KEY,
292
500
  baseURL: config.baseURL || process?.env?.PHALA_CLOUD_API_PREFIX || "https://cloud-api.phala.network/api/v1"
293
501
  };
294
- const version = resolvedConfig.version && SUPPORTED_API_VERSIONS.includes(resolvedConfig.version) ? resolvedConfig.version : SUPPORTED_API_VERSIONS[0];
502
+ const version = resolvedConfig.version && SUPPORTED_API_VERSIONS.includes(resolvedConfig.version) ? resolvedConfig.version : SUPPORTED_API_VERSIONS[SUPPORTED_API_VERSIONS.length - 1];
295
503
  this.config = resolvedConfig;
296
- if (!resolvedConfig.useCookieAuth && !resolvedConfig.apiKey) {
297
- throw new Error(
298
- "API key is required. Provide it via config.apiKey or set PHALA_CLOUD_API_KEY environment variable."
299
- );
300
- }
301
504
  const { apiKey, baseURL, timeout, headers, useCookieAuth, onResponseError, ...fetchOptions } = resolvedConfig;
302
505
  const requestHeaders = {
303
506
  "X-Phala-Version": version,
@@ -380,75 +583,137 @@ var Client = class {
380
583
  get raw() {
381
584
  return this.fetchInstance;
382
585
  }
586
+ on(type, handler) {
587
+ this.emitter.on(type, handler);
588
+ }
589
+ off(type, handler) {
590
+ this.emitter.off(type, handler);
591
+ }
592
+ once(type, handler) {
593
+ const wrappedHandler = (event) => {
594
+ handler(event);
595
+ this.emitter.off(type, wrappedHandler);
596
+ };
597
+ this.emitter.on(type, wrappedHandler);
598
+ }
383
599
  // ===== Direct methods (throw on error) =====
384
600
  /**
385
- * Perform GET request (throws on error)
601
+ * Perform GET request (throws PhalaCloudError on error)
386
602
  */
387
603
  async get(request, options) {
388
- return this.fetchInstance(request, {
389
- ...options,
390
- method: "GET"
391
- });
604
+ try {
605
+ return await this.fetchInstance(request, {
606
+ ...options,
607
+ method: "GET"
608
+ });
609
+ } catch (error) {
610
+ const requestError = this.convertToRequestError(error);
611
+ const phalaCloudError = this.emitError(requestError);
612
+ throw phalaCloudError;
613
+ }
392
614
  }
393
615
  /**
394
- * Perform POST request (throws on error)
616
+ * Perform POST request (throws PhalaCloudError on error)
395
617
  */
396
618
  async post(request, body, options) {
397
- return this.fetchInstance(request, {
398
- ...options,
399
- method: "POST",
400
- body
401
- });
619
+ try {
620
+ return await this.fetchInstance(request, {
621
+ ...options,
622
+ method: "POST",
623
+ body
624
+ });
625
+ } catch (error) {
626
+ const requestError = this.convertToRequestError(error);
627
+ const phalaCloudError = this.emitError(requestError);
628
+ throw phalaCloudError;
629
+ }
402
630
  }
403
631
  /**
404
- * Perform PUT request (throws on error)
632
+ * Perform PUT request (throws PhalaCloudError on error)
405
633
  */
406
634
  async put(request, body, options) {
407
- return this.fetchInstance(request, {
408
- ...options,
409
- method: "PUT",
410
- body
411
- });
635
+ try {
636
+ return await this.fetchInstance(request, {
637
+ ...options,
638
+ method: "PUT",
639
+ body
640
+ });
641
+ } catch (error) {
642
+ const requestError = this.convertToRequestError(error);
643
+ const phalaCloudError = this.emitError(requestError);
644
+ throw phalaCloudError;
645
+ }
412
646
  }
413
647
  /**
414
- * Perform PATCH request (throws on error)
648
+ * Perform PATCH request (throws PhalaCloudError on error)
415
649
  */
416
650
  async patch(request, body, options) {
417
- return this.fetchInstance(request, {
418
- ...options,
419
- method: "PATCH",
420
- body
421
- });
651
+ try {
652
+ return await this.fetchInstance(request, {
653
+ ...options,
654
+ method: "PATCH",
655
+ body
656
+ });
657
+ } catch (error) {
658
+ const requestError = this.convertToRequestError(error);
659
+ const phalaCloudError = this.emitError(requestError);
660
+ throw phalaCloudError;
661
+ }
422
662
  }
423
663
  /**
424
- * Perform DELETE request (throws on error)
664
+ * Perform DELETE request (throws PhalaCloudError on error)
425
665
  */
426
666
  async delete(request, options) {
427
- return this.fetchInstance(request, {
428
- ...options,
429
- method: "DELETE"
430
- });
667
+ try {
668
+ return await this.fetchInstance(request, {
669
+ ...options,
670
+ method: "DELETE"
671
+ });
672
+ } catch (error) {
673
+ const requestError = this.convertToRequestError(error);
674
+ const phalaCloudError = this.emitError(requestError);
675
+ throw phalaCloudError;
676
+ }
431
677
  }
432
678
  // ===== Safe methods (return SafeResult) =====
679
+ /**
680
+ * Convert any error to RequestError
681
+ */
682
+ convertToRequestError(error) {
683
+ if (error && typeof error === "object" && "data" in error) {
684
+ return RequestError.fromFetchError(error);
685
+ }
686
+ if (error instanceof Error) {
687
+ return RequestError.fromError(error);
688
+ }
689
+ return new RequestError("Unknown error occurred", {
690
+ detail: "Unknown error occurred"
691
+ });
692
+ }
693
+ /**
694
+ * Broadcast error to event listeners (fire-and-forget)
695
+ * @param requestError - The request error to handle
696
+ * @returns PhalaCloudError instance to throw immediately
697
+ */
698
+ emitError(requestError) {
699
+ const phalaCloudError = parseApiError(requestError);
700
+ this.emitter.emit("error", phalaCloudError);
701
+ return phalaCloudError;
702
+ }
433
703
  /**
434
704
  * Safe wrapper for any request method (zod-style result)
705
+ * Returns PhalaCloudError (all errors extend this base class)
435
706
  */
436
707
  async safeRequest(fn) {
437
708
  try {
438
709
  const data = await fn();
439
710
  return { success: true, data };
440
711
  } catch (error) {
441
- if (error && typeof error === "object" && "data" in error) {
442
- const requestError2 = RequestError.fromFetchError(error);
443
- return { success: false, error: requestError2 };
444
- }
445
- if (error instanceof Error) {
446
- const requestError2 = RequestError.fromError(error);
447
- return { success: false, error: requestError2 };
712
+ if (error instanceof PhalaCloudError) {
713
+ return { success: false, error };
448
714
  }
449
- const requestError = new RequestError("Unknown error occurred", {
450
- detail: "Unknown error occurred"
451
- });
715
+ const requestError = this.convertToRequestError(error);
716
+ this.emitError(requestError);
452
717
  return { success: false, error: requestError };
453
718
  }
454
719
  }
@@ -571,7 +836,7 @@ function defineSimpleAction(schema, fn) {
571
836
  const data = await fn(client);
572
837
  return { success: true, data };
573
838
  } catch (error) {
574
- if (error && typeof error === "object" && "isRequestError" in error) {
839
+ if (error && typeof error === "object" && "status" in error) {
575
840
  return { success: false, error };
576
841
  }
577
842
  if (error && typeof error === "object" && "issues" in error) {
@@ -628,7 +893,7 @@ function defineAction(schema, fn) {
628
893
  const data = await fn(client, params);
629
894
  return { success: true, data };
630
895
  } catch (error) {
631
- if (error && typeof error === "object" && "isRequestError" in error) {
896
+ if (error && typeof error === "object" && "status" in error) {
632
897
  return { success: false, error };
633
898
  }
634
899
  if (error && typeof error === "object" && "issues" in error) {
@@ -1213,12 +1478,13 @@ var ProvisionCvmComposeFileUpdateRequestSchema = import_zod13.z.object({
1213
1478
  }).refine(
1214
1479
  (data) => !!(data.id || data.uuid || data.app_id || data.instance_id),
1215
1480
  "One of id, uuid, app_id, or instance_id must be provided"
1216
- ).transform((data) => ({
1217
- cvmId: data.id || data.uuid || data.app_id || data.instance_id,
1218
- request: data.app_compose,
1219
- update_env_vars: data.update_env_vars,
1220
- _raw: data
1221
- }));
1481
+ ).transform((data) => {
1482
+ return {
1483
+ cvmId: data.id || data.uuid || data.app_id || data.instance_id,
1484
+ request: { ...data.app_compose, update_env_vars: data.update_env_vars },
1485
+ _raw: data
1486
+ };
1487
+ });
1222
1488
  var ProvisionCvmComposeFileUpdateResultSchema = import_zod13.z.object({
1223
1489
  app_id: import_zod13.z.string().nullable(),
1224
1490
  device_id: import_zod13.z.string().nullable(),
@@ -1321,6 +1587,26 @@ var { action: getAppEnvEncryptPubKey, safeAction: safeGetAppEnvEncryptPubKey } =
1321
1587
  return await client.get(`/kms/${validatedRequest.kms}/pubkey/${validatedRequest.app_id}`);
1322
1588
  });
1323
1589
 
1590
+ // src/actions/kms/next_app_ids.ts
1591
+ var import_zod18 = require("zod");
1592
+ var NextAppIdsRequestSchema = import_zod18.z.object({
1593
+ counts: import_zod18.z.number().int().min(1).max(20).optional().default(1)
1594
+ }).strict();
1595
+ var NextAppIdsSchema = import_zod18.z.object({
1596
+ app_ids: import_zod18.z.array(
1597
+ import_zod18.z.object({
1598
+ app_id: import_zod18.z.string(),
1599
+ nonce: import_zod18.z.number().int().min(0)
1600
+ })
1601
+ )
1602
+ }).strict();
1603
+ var { action: nextAppIds, safeAction: safeNextAppIds } = defineAction(NextAppIdsSchema, async (client, payload) => {
1604
+ const validatedRequest = NextAppIdsRequestSchema.parse(payload ?? {});
1605
+ const params = new URLSearchParams();
1606
+ params.append("counts", validatedRequest.counts.toString());
1607
+ return await client.get(`/kms/phala/next_app_id?${params.toString()}`);
1608
+ });
1609
+
1324
1610
  // src/actions/cvms/start_cvm.ts
1325
1611
  var StartCvmRequestSchema = CvmIdSchema;
1326
1612
  var { action: startCvm, safeAction: safeStartCvm } = defineAction(VMSchema, async (client, request) => {
@@ -1346,10 +1632,10 @@ var { action: shutdownCvm, safeAction: safeShutdownCvm } = defineAction(VMSchema
1346
1632
  });
1347
1633
 
1348
1634
  // src/actions/cvms/restart_cvm.ts
1349
- var import_zod18 = require("zod");
1635
+ var import_zod19 = require("zod");
1350
1636
  var RestartCvmRequestSchema = refineCvmId(
1351
1637
  CvmIdObjectSchema.extend({
1352
- force: import_zod18.z.boolean().optional()
1638
+ force: import_zod19.z.boolean().optional()
1353
1639
  })
1354
1640
  );
1355
1641
  var { action: restartCvm, safeAction: safeRestartCvm } = defineAction(VMSchema, async (client, request) => {
@@ -1360,10 +1646,10 @@ var { action: restartCvm, safeAction: safeRestartCvm } = defineAction(VMSchema,
1360
1646
  });
1361
1647
 
1362
1648
  // src/actions/cvms/delete_cvm.ts
1363
- var import_zod19 = require("zod");
1649
+ var import_zod20 = require("zod");
1364
1650
  var DeleteCvmRequestSchema = CvmIdSchema;
1365
1651
  var { action: deleteCvm, safeAction: safeDeleteCvm } = defineAction(
1366
- import_zod19.z.void(),
1652
+ import_zod20.z.void(),
1367
1653
  async (client, request) => {
1368
1654
  const { cvmId } = DeleteCvmRequestSchema.parse(request);
1369
1655
  await client.delete(`/cvms/${cvmId}`);
@@ -1372,41 +1658,41 @@ var { action: deleteCvm, safeAction: safeDeleteCvm } = defineAction(
1372
1658
  );
1373
1659
 
1374
1660
  // src/actions/cvms/get_cvm_stats.ts
1375
- var import_zod20 = require("zod");
1376
- var DiskInfoSchema = import_zod20.z.object({
1377
- name: import_zod20.z.string(),
1378
- mount_point: import_zod20.z.string(),
1379
- total_size: import_zod20.z.number(),
1380
- free_size: import_zod20.z.number()
1661
+ var import_zod21 = require("zod");
1662
+ var DiskInfoSchema = import_zod21.z.object({
1663
+ name: import_zod21.z.string(),
1664
+ mount_point: import_zod21.z.string(),
1665
+ total_size: import_zod21.z.number(),
1666
+ free_size: import_zod21.z.number()
1381
1667
  });
1382
- var SystemInfoSchema = import_zod20.z.object({
1383
- os_name: import_zod20.z.string(),
1384
- os_version: import_zod20.z.string(),
1385
- kernel_version: import_zod20.z.string(),
1386
- cpu_model: import_zod20.z.string(),
1387
- num_cpus: import_zod20.z.number(),
1388
- total_memory: import_zod20.z.number(),
1389
- available_memory: import_zod20.z.number(),
1390
- used_memory: import_zod20.z.number(),
1391
- free_memory: import_zod20.z.number(),
1392
- total_swap: import_zod20.z.number(),
1393
- used_swap: import_zod20.z.number(),
1394
- free_swap: import_zod20.z.number(),
1395
- uptime: import_zod20.z.number(),
1396
- loadavg_one: import_zod20.z.number(),
1397
- loadavg_five: import_zod20.z.number(),
1398
- loadavg_fifteen: import_zod20.z.number(),
1399
- disks: import_zod20.z.array(DiskInfoSchema)
1668
+ var SystemInfoSchema = import_zod21.z.object({
1669
+ os_name: import_zod21.z.string(),
1670
+ os_version: import_zod21.z.string(),
1671
+ kernel_version: import_zod21.z.string(),
1672
+ cpu_model: import_zod21.z.string(),
1673
+ num_cpus: import_zod21.z.number(),
1674
+ total_memory: import_zod21.z.number(),
1675
+ available_memory: import_zod21.z.number(),
1676
+ used_memory: import_zod21.z.number(),
1677
+ free_memory: import_zod21.z.number(),
1678
+ total_swap: import_zod21.z.number(),
1679
+ used_swap: import_zod21.z.number(),
1680
+ free_swap: import_zod21.z.number(),
1681
+ uptime: import_zod21.z.number(),
1682
+ loadavg_one: import_zod21.z.number(),
1683
+ loadavg_five: import_zod21.z.number(),
1684
+ loadavg_fifteen: import_zod21.z.number(),
1685
+ disks: import_zod21.z.array(DiskInfoSchema)
1400
1686
  });
1401
- var CvmSystemInfoSchema = import_zod20.z.object({
1402
- is_online: import_zod20.z.boolean(),
1403
- is_public: import_zod20.z.boolean().default(false),
1404
- error: import_zod20.z.string().nullable(),
1687
+ var CvmSystemInfoSchema = import_zod21.z.object({
1688
+ is_online: import_zod21.z.boolean(),
1689
+ is_public: import_zod21.z.boolean().default(false),
1690
+ error: import_zod21.z.string().nullable(),
1405
1691
  sysinfo: SystemInfoSchema.nullable(),
1406
- status: import_zod20.z.string().nullable(),
1407
- in_progress: import_zod20.z.boolean().default(false),
1408
- boot_progress: import_zod20.z.string().nullable(),
1409
- boot_error: import_zod20.z.string().nullable()
1692
+ status: import_zod21.z.string().nullable(),
1693
+ in_progress: import_zod21.z.boolean().default(false),
1694
+ boot_progress: import_zod21.z.string().nullable(),
1695
+ boot_error: import_zod21.z.string().nullable()
1410
1696
  });
1411
1697
  var GetCvmStatsRequestSchema = CvmIdSchema;
1412
1698
  var { action: getCvmStats, safeAction: safeGetCvmStats } = defineAction(CvmSystemInfoSchema, async (client, request) => {
@@ -1415,18 +1701,18 @@ var { action: getCvmStats, safeAction: safeGetCvmStats } = defineAction(CvmSyste
1415
1701
  });
1416
1702
 
1417
1703
  // src/actions/cvms/get_cvm_network.ts
1418
- var import_zod21 = require("zod");
1419
- var CvmNetworkUrlsSchema2 = import_zod21.z.object({
1420
- app: import_zod21.z.string(),
1421
- instance: import_zod21.z.string()
1704
+ var import_zod22 = require("zod");
1705
+ var CvmNetworkUrlsSchema2 = import_zod22.z.object({
1706
+ app: import_zod22.z.string(),
1707
+ instance: import_zod22.z.string()
1422
1708
  });
1423
- var CvmNetworkSchema = import_zod21.z.object({
1424
- is_online: import_zod21.z.boolean(),
1425
- is_public: import_zod21.z.boolean().default(true),
1426
- error: import_zod21.z.string().nullable(),
1427
- internal_ip: import_zod21.z.string().nullable(),
1428
- latest_handshake: import_zod21.z.string().nullable(),
1429
- public_urls: import_zod21.z.array(CvmNetworkUrlsSchema2).nullable()
1709
+ var CvmNetworkSchema = import_zod22.z.object({
1710
+ is_online: import_zod22.z.boolean(),
1711
+ is_public: import_zod22.z.boolean().default(true),
1712
+ error: import_zod22.z.string().nullable(),
1713
+ internal_ip: import_zod22.z.string().nullable(),
1714
+ latest_handshake: import_zod22.z.string().nullable(),
1715
+ public_urls: import_zod22.z.array(CvmNetworkUrlsSchema2).nullable()
1430
1716
  });
1431
1717
  var GetCvmNetworkRequestSchema = CvmIdSchema;
1432
1718
  var { action: getCvmNetwork, safeAction: safeGetCvmNetwork } = defineAction(CvmNetworkSchema, async (client, request) => {
@@ -1435,36 +1721,36 @@ var { action: getCvmNetwork, safeAction: safeGetCvmNetwork } = defineAction(CvmN
1435
1721
  });
1436
1722
 
1437
1723
  // src/actions/cvms/get_cvm_docker_compose.ts
1438
- var import_zod22 = require("zod");
1724
+ var import_zod23 = require("zod");
1439
1725
  var GetCvmDockerComposeRequestSchema = CvmIdSchema;
1440
- var { action: getCvmDockerCompose, safeAction: safeGetCvmDockerCompose } = defineAction(import_zod22.z.string(), async (client, request) => {
1726
+ var { action: getCvmDockerCompose, safeAction: safeGetCvmDockerCompose } = defineAction(import_zod23.z.string(), async (client, request) => {
1441
1727
  const { cvmId } = GetCvmDockerComposeRequestSchema.parse(request);
1442
1728
  return await client.get(`/cvms/${cvmId}/docker-compose.yml`);
1443
1729
  });
1444
1730
 
1445
1731
  // src/actions/cvms/get_cvm_containers_stats.ts
1446
- var import_zod23 = require("zod");
1447
- var ContainerInfoSchema = import_zod23.z.object({
1448
- id: import_zod23.z.string(),
1449
- names: import_zod23.z.array(import_zod23.z.string()),
1450
- image: import_zod23.z.string(),
1451
- image_id: import_zod23.z.string(),
1452
- command: import_zod23.z.string().nullable().optional(),
1453
- created: import_zod23.z.number(),
1454
- state: import_zod23.z.string(),
1455
- status: import_zod23.z.string(),
1456
- log_endpoint: import_zod23.z.string().nullable()
1732
+ var import_zod24 = require("zod");
1733
+ var ContainerInfoSchema = import_zod24.z.object({
1734
+ id: import_zod24.z.string(),
1735
+ names: import_zod24.z.array(import_zod24.z.string()),
1736
+ image: import_zod24.z.string(),
1737
+ image_id: import_zod24.z.string(),
1738
+ command: import_zod24.z.string().nullable().optional(),
1739
+ created: import_zod24.z.number(),
1740
+ state: import_zod24.z.string(),
1741
+ status: import_zod24.z.string(),
1742
+ log_endpoint: import_zod24.z.string().nullable()
1457
1743
  });
1458
- var CvmContainersStatsSchema = import_zod23.z.object({
1459
- is_online: import_zod23.z.boolean(),
1460
- is_public: import_zod23.z.boolean().default(true),
1461
- error: import_zod23.z.string().nullable(),
1462
- docker_compose_file: import_zod23.z.string().nullable(),
1463
- manifest_version: import_zod23.z.number().nullable(),
1464
- version: import_zod23.z.string().nullable(),
1465
- runner: import_zod23.z.string().nullable(),
1466
- features: import_zod23.z.array(import_zod23.z.string()).nullable(),
1467
- containers: import_zod23.z.array(ContainerInfoSchema).nullable()
1744
+ var CvmContainersStatsSchema = import_zod24.z.object({
1745
+ is_online: import_zod24.z.boolean(),
1746
+ is_public: import_zod24.z.boolean().default(true),
1747
+ error: import_zod24.z.string().nullable(),
1748
+ docker_compose_file: import_zod24.z.string().nullable(),
1749
+ manifest_version: import_zod24.z.number().nullable(),
1750
+ version: import_zod24.z.string().nullable(),
1751
+ runner: import_zod24.z.string().nullable(),
1752
+ features: import_zod24.z.array(import_zod24.z.string()).nullable(),
1753
+ containers: import_zod24.z.array(ContainerInfoSchema).nullable()
1468
1754
  });
1469
1755
  var GetCvmContainersStatsRequestSchema = CvmIdSchema;
1470
1756
  var { action: getCvmContainersStats, safeAction: safeGetCvmContainersStats } = defineAction(CvmContainersStatsSchema, async (client, request) => {
@@ -1473,62 +1759,62 @@ var { action: getCvmContainersStats, safeAction: safeGetCvmContainersStats } = d
1473
1759
  });
1474
1760
 
1475
1761
  // src/actions/cvms/get_cvm_attestation.ts
1476
- var import_zod24 = require("zod");
1477
- var CertificateSubjectSchema = import_zod24.z.object({
1478
- common_name: import_zod24.z.string().nullable(),
1479
- organization: import_zod24.z.string().nullable(),
1480
- country: import_zod24.z.string().nullable(),
1481
- state: import_zod24.z.string().nullable(),
1482
- locality: import_zod24.z.string().nullable()
1762
+ var import_zod25 = require("zod");
1763
+ var CertificateSubjectSchema = import_zod25.z.object({
1764
+ common_name: import_zod25.z.string().nullable(),
1765
+ organization: import_zod25.z.string().nullable(),
1766
+ country: import_zod25.z.string().nullable(),
1767
+ state: import_zod25.z.string().nullable(),
1768
+ locality: import_zod25.z.string().nullable()
1483
1769
  });
1484
- var CertificateIssuerSchema = import_zod24.z.object({
1485
- common_name: import_zod24.z.string().nullable(),
1486
- organization: import_zod24.z.string().nullable(),
1487
- country: import_zod24.z.string().nullable()
1770
+ var CertificateIssuerSchema = import_zod25.z.object({
1771
+ common_name: import_zod25.z.string().nullable(),
1772
+ organization: import_zod25.z.string().nullable(),
1773
+ country: import_zod25.z.string().nullable()
1488
1774
  });
1489
- var CertificateSchema = import_zod24.z.object({
1775
+ var CertificateSchema = import_zod25.z.object({
1490
1776
  subject: CertificateSubjectSchema,
1491
1777
  issuer: CertificateIssuerSchema,
1492
- serial_number: import_zod24.z.string(),
1493
- not_before: import_zod24.z.string(),
1778
+ serial_number: import_zod25.z.string(),
1779
+ not_before: import_zod25.z.string(),
1494
1780
  // datetime serialized as ISO string
1495
- not_after: import_zod24.z.string(),
1781
+ not_after: import_zod25.z.string(),
1496
1782
  // datetime serialized as ISO string
1497
- version: import_zod24.z.string(),
1498
- fingerprint: import_zod24.z.string(),
1499
- signature_algorithm: import_zod24.z.string(),
1500
- sans: import_zod24.z.array(import_zod24.z.string()).nullable(),
1501
- is_ca: import_zod24.z.boolean(),
1502
- position_in_chain: import_zod24.z.number().nullable(),
1503
- quote: import_zod24.z.string().nullable(),
1504
- app_id: import_zod24.z.string().nullable().optional(),
1505
- cert_usage: import_zod24.z.string().nullable().optional()
1783
+ version: import_zod25.z.string(),
1784
+ fingerprint: import_zod25.z.string(),
1785
+ signature_algorithm: import_zod25.z.string(),
1786
+ sans: import_zod25.z.array(import_zod25.z.string()).nullable(),
1787
+ is_ca: import_zod25.z.boolean(),
1788
+ position_in_chain: import_zod25.z.number().nullable(),
1789
+ quote: import_zod25.z.string().nullable(),
1790
+ app_id: import_zod25.z.string().nullable().optional(),
1791
+ cert_usage: import_zod25.z.string().nullable().optional()
1506
1792
  });
1507
- var EventLogSchema = import_zod24.z.object({
1508
- imr: import_zod24.z.number(),
1509
- event_type: import_zod24.z.number(),
1510
- digest: import_zod24.z.string(),
1511
- event: import_zod24.z.string(),
1512
- event_payload: import_zod24.z.string()
1793
+ var EventLogSchema = import_zod25.z.object({
1794
+ imr: import_zod25.z.number(),
1795
+ event_type: import_zod25.z.number(),
1796
+ digest: import_zod25.z.string(),
1797
+ event: import_zod25.z.string(),
1798
+ event_payload: import_zod25.z.string()
1513
1799
  });
1514
- var TcbInfoSchema = import_zod24.z.object({
1515
- mrtd: import_zod24.z.string(),
1516
- rootfs_hash: import_zod24.z.string().nullable().optional(),
1517
- rtmr0: import_zod24.z.string(),
1518
- rtmr1: import_zod24.z.string(),
1519
- rtmr2: import_zod24.z.string(),
1520
- rtmr3: import_zod24.z.string(),
1521
- event_log: import_zod24.z.array(EventLogSchema),
1522
- app_compose: import_zod24.z.string()
1800
+ var TcbInfoSchema = import_zod25.z.object({
1801
+ mrtd: import_zod25.z.string(),
1802
+ rootfs_hash: import_zod25.z.string().nullable().optional(),
1803
+ rtmr0: import_zod25.z.string(),
1804
+ rtmr1: import_zod25.z.string(),
1805
+ rtmr2: import_zod25.z.string(),
1806
+ rtmr3: import_zod25.z.string(),
1807
+ event_log: import_zod25.z.array(EventLogSchema),
1808
+ app_compose: import_zod25.z.string()
1523
1809
  });
1524
- var CvmAttestationSchema = import_zod24.z.object({
1525
- name: import_zod24.z.string().nullable(),
1526
- is_online: import_zod24.z.boolean(),
1527
- is_public: import_zod24.z.boolean().default(true),
1528
- error: import_zod24.z.string().nullable(),
1529
- app_certificates: import_zod24.z.array(CertificateSchema).nullable(),
1810
+ var CvmAttestationSchema = import_zod25.z.object({
1811
+ name: import_zod25.z.string().nullable(),
1812
+ is_online: import_zod25.z.boolean(),
1813
+ is_public: import_zod25.z.boolean().default(true),
1814
+ error: import_zod25.z.string().nullable(),
1815
+ app_certificates: import_zod25.z.array(CertificateSchema).nullable(),
1530
1816
  tcb_info: TcbInfoSchema.nullable(),
1531
- compose_file: import_zod24.z.string().nullable()
1817
+ compose_file: import_zod25.z.string().nullable()
1532
1818
  });
1533
1819
  var GetCvmAttestationRequestSchema = CvmIdSchema;
1534
1820
  var { action: getCvmAttestation, safeAction: safeGetCvmAttestation } = defineAction(CvmAttestationSchema, async (client, request) => {
@@ -1537,17 +1823,17 @@ var { action: getCvmAttestation, safeAction: safeGetCvmAttestation } = defineAct
1537
1823
  });
1538
1824
 
1539
1825
  // src/actions/cvms/update_cvm_resources.ts
1540
- var import_zod25 = require("zod");
1826
+ var import_zod26 = require("zod");
1541
1827
  var UpdateCvmResourcesRequestSchema = refineCvmId(
1542
1828
  CvmIdObjectSchema.extend({
1543
- vcpu: import_zod25.z.number().optional(),
1544
- memory: import_zod25.z.number().optional(),
1545
- disk_size: import_zod25.z.number().optional(),
1546
- instance_type: import_zod25.z.string().optional(),
1547
- allow_restart: import_zod25.z.boolean().optional()
1829
+ vcpu: import_zod26.z.number().optional(),
1830
+ memory: import_zod26.z.number().optional(),
1831
+ disk_size: import_zod26.z.number().optional(),
1832
+ instance_type: import_zod26.z.string().optional(),
1833
+ allow_restart: import_zod26.z.boolean().optional()
1548
1834
  })
1549
1835
  );
1550
- var { action: updateCvmResources, safeAction: safeUpdateCvmResources } = defineAction(import_zod25.z.void(), async (client, request) => {
1836
+ var { action: updateCvmResources, safeAction: safeUpdateCvmResources } = defineAction(import_zod26.z.void(), async (client, request) => {
1551
1837
  const parsed = UpdateCvmResourcesRequestSchema.parse(request);
1552
1838
  const { cvmId } = CvmIdSchema.parse(parsed);
1553
1839
  const { ...body } = parsed;
@@ -1556,11 +1842,11 @@ var { action: updateCvmResources, safeAction: safeUpdateCvmResources } = defineA
1556
1842
  });
1557
1843
 
1558
1844
  // src/actions/cvms/update_cvm_visibility.ts
1559
- var import_zod26 = require("zod");
1845
+ var import_zod27 = require("zod");
1560
1846
  var UpdateCvmVisibilityRequestSchema = refineCvmId(
1561
1847
  CvmIdObjectSchema.extend({
1562
- public_sysinfo: import_zod26.z.boolean(),
1563
- public_logs: import_zod26.z.boolean()
1848
+ public_sysinfo: import_zod27.z.boolean(),
1849
+ public_logs: import_zod27.z.boolean()
1564
1850
  })
1565
1851
  );
1566
1852
  var { action: updateCvmVisibility, safeAction: safeUpdateCvmVisibility } = defineAction(CvmLegacyDetailSchema, async (client, request) => {
@@ -1570,6 +1856,59 @@ var { action: updateCvmVisibility, safeAction: safeUpdateCvmVisibility } = defin
1570
1856
  return await client.patch(`/cvms/${cvmId}/visibility`, { public_sysinfo, public_logs });
1571
1857
  });
1572
1858
 
1859
+ // src/actions/cvms/get_available_os_images.ts
1860
+ var import_zod28 = require("zod");
1861
+ var OSImageVariantSchema = import_zod28.z.object({
1862
+ name: import_zod28.z.string(),
1863
+ os_image_hash: import_zod28.z.string().nullable(),
1864
+ is_current: import_zod28.z.boolean()
1865
+ });
1866
+ var AvailableOSImageSchema2 = import_zod28.z.object({
1867
+ version: import_zod28.z.union([
1868
+ import_zod28.z.tuple([import_zod28.z.number(), import_zod28.z.number(), import_zod28.z.number(), import_zod28.z.number()]),
1869
+ import_zod28.z.tuple([import_zod28.z.number(), import_zod28.z.number(), import_zod28.z.number()])
1870
+ ]),
1871
+ prod: OSImageVariantSchema.nullable(),
1872
+ dev: OSImageVariantSchema.nullable()
1873
+ });
1874
+ var GetAvailableOSImagesResponseSchema = import_zod28.z.array(AvailableOSImageSchema2);
1875
+ var GetAvailableOSImagesRequestSchema = CvmIdSchema;
1876
+ var { action: getAvailableOsImages, safeAction: safeGetAvailableOsImages } = defineAction(GetAvailableOSImagesResponseSchema, async (client, request) => {
1877
+ const { cvmId } = GetAvailableOSImagesRequestSchema.parse(request);
1878
+ return await client.get(`/cvms/${cvmId}/available-os-images`);
1879
+ });
1880
+
1881
+ // src/actions/cvms/update_os_image.ts
1882
+ var import_zod29 = require("zod");
1883
+ var UpdateOsImageRequestSchema = refineCvmId(
1884
+ CvmIdObjectSchema.extend({
1885
+ os_image_name: import_zod29.z.string().min(1, "OS image name is required")
1886
+ })
1887
+ );
1888
+ var { action: updateOsImage, safeAction: safeUpdateOsImage } = defineAction(import_zod29.z.void(), async (client, request) => {
1889
+ const parsed = UpdateOsImageRequestSchema.parse(request);
1890
+ const { cvmId } = CvmIdSchema.parse(parsed);
1891
+ const { os_image_name } = parsed;
1892
+ await client.patch(`/cvms/${cvmId}/os-image`, { os_image_name });
1893
+ return void 0;
1894
+ });
1895
+
1896
+ // src/actions/cvms/get_cvm_state.ts
1897
+ var import_zod30 = require("zod");
1898
+ var CvmStateSchema = import_zod30.z.object({
1899
+ status: import_zod30.z.string(),
1900
+ derived_status: import_zod30.z.string().optional(),
1901
+ vm_uuid: import_zod30.z.string().optional(),
1902
+ instance_id: import_zod30.z.string().optional(),
1903
+ uptime: import_zod30.z.string().optional()
1904
+ // Add other state fields as needed
1905
+ });
1906
+ var GetCvmStateRequestSchema = CvmIdSchema;
1907
+ var { action: getCvmState, safeAction: safeGetCvmState } = defineAction(CvmStateSchema, async (client, request) => {
1908
+ const { cvmId } = GetCvmStateRequestSchema.parse(request);
1909
+ return await client.get(`/cvms/${cvmId}/state`);
1910
+ });
1911
+
1573
1912
  // src/create-client.ts
1574
1913
  function createClient2(config = {}) {
1575
1914
  const client = createClient(config);
@@ -1622,41 +1961,32 @@ function createClient2(config = {}) {
1622
1961
  safeUpdateCvmResources,
1623
1962
  updateCvmVisibility,
1624
1963
  safeUpdateCvmVisibility,
1964
+ getAvailableOsImages,
1965
+ safeGetAvailableOsImages,
1966
+ updateOsImage,
1967
+ safeUpdateOsImage,
1625
1968
  getKmsInfo,
1626
1969
  safeGetKmsInfo,
1627
1970
  getKmsList,
1628
1971
  safeGetKmsList,
1629
1972
  getAppEnvEncryptPubKey,
1630
- safeGetAppEnvEncryptPubKey
1973
+ safeGetAppEnvEncryptPubKey,
1974
+ nextAppIds,
1975
+ safeNextAppIds,
1976
+ getCvmState,
1977
+ safeGetCvmState
1631
1978
  };
1632
1979
  return client.extend(allActions);
1633
1980
  }
1634
1981
 
1635
1982
  // src/actions/blockchains/deploy_app_auth.ts
1636
- var import_zod27 = require("zod");
1983
+ var import_zod31 = require("zod");
1637
1984
  var import_viem3 = require("viem");
1638
1985
  var import_accounts2 = require("viem/accounts");
1639
1986
 
1640
1987
  // src/utils/index.ts
1641
1988
  var import_encrypt_env_vars = require("@phala/dstack-sdk/encrypt-env-vars");
1642
1989
 
1643
- // src/utils/get_error_message.ts
1644
- function getErrorMessage(error) {
1645
- if (typeof error.detail === "string") {
1646
- return error.detail;
1647
- }
1648
- if (Array.isArray(error.detail)) {
1649
- if (error.detail.length > 0) {
1650
- return error.detail[0]?.msg || "Validation error";
1651
- }
1652
- return "Validation error";
1653
- }
1654
- if (typeof error.detail === "object" && error.detail !== null) {
1655
- return JSON.stringify(error.detail);
1656
- }
1657
- return "Unknown error occurred";
1658
- }
1659
-
1660
1990
  // src/utils/as-hex.ts
1661
1991
  var import_viem = require("viem");
1662
1992
  function asHex(value) {
@@ -2300,25 +2630,25 @@ var kmsAuthAbi = [
2300
2630
  anonymous: false
2301
2631
  }
2302
2632
  ];
2303
- var DeployAppAuthRequestBaseSchema = import_zod27.z.object({
2633
+ var DeployAppAuthRequestBaseSchema = import_zod31.z.object({
2304
2634
  // Chain configuration (conditionally required)
2305
- chain: import_zod27.z.unknown().optional(),
2306
- rpcUrl: import_zod27.z.string().optional(),
2635
+ chain: import_zod31.z.unknown().optional(),
2636
+ rpcUrl: import_zod31.z.string().optional(),
2307
2637
  // Contract configuration (required)
2308
- kmsContractAddress: import_zod27.z.string(),
2638
+ kmsContractAddress: import_zod31.z.string(),
2309
2639
  // Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
2310
- privateKey: import_zod27.z.string().optional(),
2311
- walletClient: import_zod27.z.unknown().optional(),
2640
+ privateKey: import_zod31.z.string().optional(),
2641
+ walletClient: import_zod31.z.unknown().optional(),
2312
2642
  // Public client (optional, will create default if not provided)
2313
- publicClient: import_zod27.z.unknown().optional(),
2643
+ publicClient: import_zod31.z.unknown().optional(),
2314
2644
  // App configuration (optional)
2315
- allowAnyDevice: import_zod27.z.boolean().optional().default(false),
2316
- deviceId: import_zod27.z.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
2317
- composeHash: import_zod27.z.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
2318
- disableUpgrades: import_zod27.z.boolean().optional().default(false),
2645
+ allowAnyDevice: import_zod31.z.boolean().optional().default(false),
2646
+ deviceId: import_zod31.z.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
2647
+ composeHash: import_zod31.z.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
2648
+ disableUpgrades: import_zod31.z.boolean().optional().default(false),
2319
2649
  // Validation configuration (optional)
2320
- skipPrerequisiteChecks: import_zod27.z.boolean().optional().default(false),
2321
- minBalance: import_zod27.z.string().optional()
2650
+ skipPrerequisiteChecks: import_zod31.z.boolean().optional().default(false),
2651
+ minBalance: import_zod31.z.string().optional()
2322
2652
  // ETH amount as string, e.g., "0.01"
2323
2653
  }).passthrough();
2324
2654
  var DeployAppAuthRequestSchema = DeployAppAuthRequestBaseSchema.refine(
@@ -2346,13 +2676,13 @@ var DeployAppAuthRequestSchema = DeployAppAuthRequestBaseSchema.refine(
2346
2676
  path: ["chain"]
2347
2677
  }
2348
2678
  );
2349
- var DeployAppAuthSchema = import_zod27.z.object({
2350
- appId: import_zod27.z.string(),
2351
- appAuthAddress: import_zod27.z.string(),
2352
- deployer: import_zod27.z.string(),
2353
- transactionHash: import_zod27.z.string(),
2354
- blockNumber: import_zod27.z.bigint().optional(),
2355
- gasUsed: import_zod27.z.bigint().optional()
2679
+ var DeployAppAuthSchema = import_zod31.z.object({
2680
+ appId: import_zod31.z.string(),
2681
+ appAuthAddress: import_zod31.z.string(),
2682
+ deployer: import_zod31.z.string(),
2683
+ transactionHash: import_zod31.z.string(),
2684
+ blockNumber: import_zod31.z.bigint().optional(),
2685
+ gasUsed: import_zod31.z.bigint().optional()
2356
2686
  }).passthrough();
2357
2687
  function parseDeploymentResult(receipt, deployer, kmsContractAddress) {
2358
2688
  try {
@@ -2598,7 +2928,7 @@ async function safeDeployAppAuth(request, parameters) {
2598
2928
  }
2599
2929
 
2600
2930
  // src/actions/blockchains/add_compose_hash.ts
2601
- var import_zod28 = require("zod");
2931
+ var import_zod32 = require("zod");
2602
2932
  var import_viem4 = require("viem");
2603
2933
  var import_accounts3 = require("viem/accounts");
2604
2934
  var appAuthAbi = [
@@ -2616,29 +2946,29 @@ var appAuthAbi = [
2616
2946
  anonymous: false
2617
2947
  }
2618
2948
  ];
2619
- var AddComposeHashRequestSchema = import_zod28.z.object({
2949
+ var AddComposeHashRequestSchema = import_zod32.z.object({
2620
2950
  // Chain configuration (conditionally required)
2621
- chain: import_zod28.z.unknown().optional(),
2622
- rpcUrl: import_zod28.z.string().optional(),
2623
- appId: import_zod28.z.string(),
2624
- composeHash: import_zod28.z.string(),
2951
+ chain: import_zod32.z.unknown().optional(),
2952
+ rpcUrl: import_zod32.z.string().optional(),
2953
+ appId: import_zod32.z.string(),
2954
+ composeHash: import_zod32.z.string(),
2625
2955
  // Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
2626
- privateKey: import_zod28.z.string().optional(),
2627
- walletClient: import_zod28.z.unknown().optional(),
2956
+ privateKey: import_zod32.z.string().optional(),
2957
+ walletClient: import_zod32.z.unknown().optional(),
2628
2958
  // Public client (optional, will create default if not provided)
2629
- publicClient: import_zod28.z.unknown().optional(),
2959
+ publicClient: import_zod32.z.unknown().optional(),
2630
2960
  // Validation configuration (optional)
2631
- skipPrerequisiteChecks: import_zod28.z.boolean().optional().default(false),
2632
- minBalance: import_zod28.z.string().optional(),
2961
+ skipPrerequisiteChecks: import_zod32.z.boolean().optional().default(false),
2962
+ minBalance: import_zod32.z.string().optional(),
2633
2963
  // ETH amount as string, e.g., "0.01"
2634
2964
  // Transaction control options
2635
- timeout: import_zod28.z.number().optional().default(12e4),
2636
- retryOptions: import_zod28.z.unknown().optional(),
2637
- signal: import_zod28.z.unknown().optional(),
2965
+ timeout: import_zod32.z.number().optional().default(12e4),
2966
+ retryOptions: import_zod32.z.unknown().optional(),
2967
+ signal: import_zod32.z.unknown().optional(),
2638
2968
  // Progress callbacks
2639
- onTransactionStateChange: import_zod28.z.function().optional(),
2640
- onTransactionSubmitted: import_zod28.z.function().optional(),
2641
- onTransactionConfirmed: import_zod28.z.function().optional()
2969
+ onTransactionStateChange: import_zod32.z.function().optional(),
2970
+ onTransactionSubmitted: import_zod32.z.function().optional(),
2971
+ onTransactionConfirmed: import_zod32.z.function().optional()
2642
2972
  }).passthrough().refine(
2643
2973
  (data) => {
2644
2974
  const hasPrivateKey = !!data.privateKey;
@@ -2662,12 +2992,12 @@ var AddComposeHashRequestSchema = import_zod28.z.object({
2662
2992
  path: ["chain"]
2663
2993
  }
2664
2994
  );
2665
- var AddComposeHashSchema = import_zod28.z.object({
2666
- composeHash: import_zod28.z.string(),
2667
- appId: import_zod28.z.string(),
2668
- transactionHash: import_zod28.z.string(),
2669
- blockNumber: import_zod28.z.bigint().optional(),
2670
- gasUsed: import_zod28.z.bigint().optional()
2995
+ var AddComposeHashSchema = import_zod32.z.object({
2996
+ composeHash: import_zod32.z.string(),
2997
+ appId: import_zod32.z.string(),
2998
+ transactionHash: import_zod32.z.string(),
2999
+ blockNumber: import_zod32.z.bigint().optional(),
3000
+ gasUsed: import_zod32.z.bigint().optional()
2671
3001
  }).passthrough();
2672
3002
  function parseComposeHashResult(receipt, composeHash, appAuthAddress, appId) {
2673
3003
  console.log(receipt.logs);
@@ -2858,6 +3188,200 @@ async function safeAddComposeHash(request, parameters) {
2858
3188
  }
2859
3189
  }
2860
3190
 
3191
+ // src/actions/cvms/watch_cvm_state.ts
3192
+ var import_zod33 = require("zod");
3193
+ var WatchCvmStateParamsSchema = import_zod33.z.object({
3194
+ target: import_zod33.z.string().describe("Target status to wait for (e.g., 'running', 'stopped')"),
3195
+ interval: import_zod33.z.number().min(5).max(30).default(5).describe("Polling interval in seconds"),
3196
+ timeout: import_zod33.z.number().min(10).max(600).default(300).describe("Timeout per attempt in seconds"),
3197
+ maxRetries: import_zod33.z.number().min(0).default(Number.POSITIVE_INFINITY).describe("Maximum number of retry attempts (Infinity for unlimited)"),
3198
+ retryDelay: import_zod33.z.number().min(0).default(5e3).describe("Delay between retries in milliseconds")
3199
+ });
3200
+ var WatchCvmStateRequestSchema = WatchCvmStateParamsSchema;
3201
+ var WatchAbortedError = class extends Error {
3202
+ constructor() {
3203
+ super("Watch operation was aborted");
3204
+ this.name = "WatchAbortedError";
3205
+ }
3206
+ };
3207
+ var MaxRetriesExceededError = class extends Error {
3208
+ constructor(attempts) {
3209
+ super(`Maximum retry attempts (${attempts}) exceeded`);
3210
+ this.attempts = attempts;
3211
+ this.name = "MaxRetriesExceededError";
3212
+ }
3213
+ };
3214
+ function parseSSEEvent(eventType, data) {
3215
+ try {
3216
+ const parsed = JSON.parse(data);
3217
+ return { type: eventType, data: parsed };
3218
+ } catch {
3219
+ return { type: "error", data: { error: "Failed to parse SSE event" } };
3220
+ }
3221
+ }
3222
+ async function watchCvmState(client, request, options = {}) {
3223
+ const { cvmId } = CvmIdSchema.parse(request);
3224
+ const { target, interval, timeout, maxRetries, retryDelay } = WatchCvmStateParamsSchema.parse(request);
3225
+ const { signal, onEvent } = options;
3226
+ let attempt = 0;
3227
+ while (attempt < maxRetries) {
3228
+ if (signal?.aborted) {
3229
+ throw new WatchAbortedError();
3230
+ }
3231
+ attempt++;
3232
+ try {
3233
+ const result = await watchSingleAttempt(
3234
+ client,
3235
+ cvmId,
3236
+ target,
3237
+ interval,
3238
+ timeout,
3239
+ signal,
3240
+ onEvent
3241
+ );
3242
+ if (result) {
3243
+ return result;
3244
+ }
3245
+ if (attempt >= maxRetries) {
3246
+ throw new MaxRetriesExceededError(attempt);
3247
+ }
3248
+ await sleep(retryDelay, signal);
3249
+ } catch (error) {
3250
+ if (signal?.aborted) {
3251
+ throw new WatchAbortedError();
3252
+ }
3253
+ if (error instanceof WatchAbortedError || error instanceof MaxRetriesExceededError) {
3254
+ throw error;
3255
+ }
3256
+ if (attempt >= maxRetries) {
3257
+ throw error;
3258
+ }
3259
+ if (onEvent) {
3260
+ onEvent({
3261
+ type: "error",
3262
+ data: { error: error instanceof Error ? error.message : String(error) }
3263
+ });
3264
+ }
3265
+ await sleep(retryDelay, signal);
3266
+ }
3267
+ }
3268
+ throw new MaxRetriesExceededError(attempt);
3269
+ }
3270
+ async function watchSingleAttempt(client, cvmId, target, interval, timeout, signal, onEvent) {
3271
+ const params = new URLSearchParams({
3272
+ target,
3273
+ interval: String(interval),
3274
+ timeout: String(timeout)
3275
+ });
3276
+ const baseURL = client.config.baseURL || "";
3277
+ const fullUrl = `${baseURL}/cvms/${cvmId}/state?${params.toString()}`;
3278
+ const headers = {
3279
+ Accept: "text/event-stream",
3280
+ "Cache-Control": "no-cache"
3281
+ };
3282
+ if (!client.config.useCookieAuth && client.config.apiKey) {
3283
+ headers["X-API-Key"] = client.config.apiKey;
3284
+ }
3285
+ if (client.config.headers) {
3286
+ Object.entries(client.config.headers).forEach(([key, value]) => {
3287
+ if (typeof value === "string") {
3288
+ headers[key] = value;
3289
+ }
3290
+ });
3291
+ }
3292
+ const response = await client.raw.native(fullUrl, {
3293
+ method: "GET",
3294
+ headers,
3295
+ signal,
3296
+ ...client.config.useCookieAuth ? { credentials: "include" } : {}
3297
+ });
3298
+ if (!response.ok) {
3299
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
3300
+ }
3301
+ if (!response.body) {
3302
+ throw new Error("Response body is null");
3303
+ }
3304
+ return parseSSEStream(response.body, signal, onEvent);
3305
+ }
3306
+ async function parseSSEStream(stream, signal, onEvent) {
3307
+ const reader = stream.getReader();
3308
+ const decoder = new TextDecoder();
3309
+ let buffer = "";
3310
+ let finalState = null;
3311
+ let currentEvent = "";
3312
+ let currentData = "";
3313
+ const processLine = (line) => {
3314
+ if (line.startsWith("event:")) {
3315
+ currentEvent = line.slice(6).trim();
3316
+ } else if (line.startsWith("data:")) {
3317
+ currentData = line.slice(5).trim();
3318
+ } else if (line === "") {
3319
+ if (currentEvent && currentData) {
3320
+ const event = parseSSEEvent(currentEvent, currentData);
3321
+ if (event.type === "state") {
3322
+ finalState = event.data;
3323
+ }
3324
+ onEvent?.(event);
3325
+ if (event.type === "complete") {
3326
+ return "complete";
3327
+ }
3328
+ if (event.type === "timeout") {
3329
+ return "timeout";
3330
+ }
3331
+ }
3332
+ currentEvent = "";
3333
+ currentData = "";
3334
+ }
3335
+ return null;
3336
+ };
3337
+ try {
3338
+ while (true) {
3339
+ if (signal?.aborted) {
3340
+ throw new WatchAbortedError();
3341
+ }
3342
+ const { done, value } = await reader.read();
3343
+ if (done) {
3344
+ break;
3345
+ }
3346
+ buffer += decoder.decode(value, { stream: true });
3347
+ const lines = buffer.split("\n");
3348
+ buffer = lines.pop() || "";
3349
+ for (const line of lines) {
3350
+ const result = processLine(line.trim());
3351
+ if (result === "complete") {
3352
+ return finalState;
3353
+ }
3354
+ if (result === "timeout") {
3355
+ return null;
3356
+ }
3357
+ }
3358
+ }
3359
+ return finalState;
3360
+ } catch (error) {
3361
+ if (error instanceof WatchAbortedError) {
3362
+ throw error;
3363
+ }
3364
+ throw new Error(`SSE stream error: ${error instanceof Error ? error.message : String(error)}`);
3365
+ } finally {
3366
+ reader.releaseLock();
3367
+ }
3368
+ }
3369
+ function sleep(ms, signal) {
3370
+ return new Promise((resolve, reject) => {
3371
+ if (signal?.aborted) {
3372
+ reject(new WatchAbortedError());
3373
+ return;
3374
+ }
3375
+ const timer = setTimeout(resolve, ms);
3376
+ if (signal) {
3377
+ signal.addEventListener("abort", () => {
3378
+ clearTimeout(timer);
3379
+ reject(new WatchAbortedError());
3380
+ });
3381
+ }
3382
+ });
3383
+ }
3384
+
2861
3385
  // src/parse_dotenv.ts
2862
3386
  var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
2863
3387
  function parseEnv(input) {
@@ -2897,7 +3421,9 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
2897
3421
  0 && (module.exports = {
2898
3422
  AddComposeHashSchema,
2899
3423
  ApiErrorSchema,
3424
+ AuthError,
2900
3425
  AvailableNodesSchema,
3426
+ BusinessError,
2901
3427
  CommitCvmComposeFileUpdateRequestSchema,
2902
3428
  CommitCvmComposeFileUpdateSchema,
2903
3429
  CommitCvmProvisionRequestSchema,
@@ -2913,12 +3439,15 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
2913
3439
  CvmNetworkSchema,
2914
3440
  CvmNetworkUrlsSchema,
2915
3441
  CvmNodeSchema,
3442
+ CvmStateSchema,
2916
3443
  CvmSystemInfoSchema,
2917
3444
  DeleteCvmRequestSchema,
2918
3445
  DeployAppAuthRequestSchema,
2919
3446
  DeployAppAuthSchema,
2920
3447
  GetAppEnvEncryptPubKeyRequestSchema,
2921
3448
  GetAppEnvEncryptPubKeySchema,
3449
+ GetAvailableOSImagesRequestSchema,
3450
+ GetAvailableOSImagesResponseSchema,
2922
3451
  GetCvmAttestationRequestSchema,
2923
3452
  GetCvmComposeFileRequestSchema,
2924
3453
  GetCvmContainersStatsRequestSchema,
@@ -2927,6 +3456,7 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
2927
3456
  GetCvmListRequestSchema,
2928
3457
  GetCvmListSchema,
2929
3458
  GetCvmNetworkRequestSchema,
3459
+ GetCvmStateRequestSchema,
2930
3460
  GetCvmStatsRequestSchema,
2931
3461
  GetKmsInfoRequestSchema,
2932
3462
  GetKmsListRequestSchema,
@@ -2936,9 +3466,14 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
2936
3466
  ListInstanceTypesRequestSchema,
2937
3467
  ListWorkspacesSchema,
2938
3468
  ManagedUserSchema,
3469
+ MaxRetriesExceededError,
2939
3470
  NetworkError,
3471
+ NextAppIdsRequestSchema,
3472
+ NextAppIdsSchema,
3473
+ OSImageVariantSchema,
2940
3474
  PaginatedInstanceTypesSchema,
2941
3475
  PaginationMetadataSchema,
3476
+ PhalaCloudError,
2942
3477
  ProvisionCvmComposeFileUpdateRequestSchema,
2943
3478
  ProvisionCvmComposeFileUpdateResultSchema,
2944
3479
  ProvisionCvmRequestSchema,
@@ -2946,15 +3481,21 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
2946
3481
  RequestError,
2947
3482
  RestartCvmRequestSchema,
2948
3483
  SUPPORTED_CHAINS,
3484
+ ServerError,
2949
3485
  ShutdownCvmRequestSchema,
2950
3486
  StartCvmRequestSchema,
2951
3487
  StopCvmRequestSchema,
2952
3488
  TransactionError,
3489
+ UnknownError,
2953
3490
  UpdateCvmResourcesRequestSchema,
2954
3491
  UpdateCvmVisibilityRequestSchema,
3492
+ UpdateOsImageRequestSchema,
2955
3493
  VMSchema,
3494
+ ValidationError,
2956
3495
  VmInfoSchema,
2957
3496
  WalletError,
3497
+ WatchAbortedError,
3498
+ WatchCvmStateRequestSchema,
2958
3499
  WorkspaceResponseSchema,
2959
3500
  addComposeHash,
2960
3501
  addNetwork,
@@ -2981,8 +3522,11 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
2981
3522
  executeTransaction,
2982
3523
  executeTransactionWithRetry,
2983
3524
  extractNetworkClients,
3525
+ formatErrorMessage,
3526
+ formatValidationErrors,
2984
3527
  getAppEnvEncryptPubKey,
2985
3528
  getAvailableNodes,
3529
+ getAvailableOsImages,
2986
3530
  getComposeHash,
2987
3531
  getCurrentUser,
2988
3532
  getCvmAttestation,
@@ -2992,13 +3536,17 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
2992
3536
  getCvmInfo,
2993
3537
  getCvmList,
2994
3538
  getCvmNetwork,
3539
+ getCvmState,
2995
3540
  getCvmStats,
2996
3541
  getErrorMessage,
2997
3542
  getKmsInfo,
2998
3543
  getKmsList,
3544
+ getValidationFields,
2999
3545
  getWorkspace,
3000
3546
  listInstanceTypes,
3001
3547
  listWorkspaces,
3548
+ nextAppIds,
3549
+ parseApiError,
3002
3550
  parseEnv,
3003
3551
  parseEnvVars,
3004
3552
  preprocessAppCompose,
@@ -3013,6 +3561,7 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
3013
3561
  safeDeployAppAuth,
3014
3562
  safeGetAppEnvEncryptPubKey,
3015
3563
  safeGetAvailableNodes,
3564
+ safeGetAvailableOsImages,
3016
3565
  safeGetCurrentUser,
3017
3566
  safeGetCvmAttestation,
3018
3567
  safeGetCvmComposeFile,
@@ -3021,12 +3570,14 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
3021
3570
  safeGetCvmInfo,
3022
3571
  safeGetCvmList,
3023
3572
  safeGetCvmNetwork,
3573
+ safeGetCvmState,
3024
3574
  safeGetCvmStats,
3025
3575
  safeGetKmsInfo,
3026
3576
  safeGetKmsList,
3027
3577
  safeGetWorkspace,
3028
3578
  safeListInstanceTypes,
3029
3579
  safeListWorkspaces,
3580
+ safeNextAppIds,
3030
3581
  safeProvisionCvm,
3031
3582
  safeProvisionCvmComposeFileUpdate,
3032
3583
  safeRestartCvm,
@@ -3035,6 +3586,7 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
3035
3586
  safeStopCvm,
3036
3587
  safeUpdateCvmResources,
3037
3588
  safeUpdateCvmVisibility,
3589
+ safeUpdateOsImage,
3038
3590
  safeValidateActionParameters,
3039
3591
  shutdownCvm,
3040
3592
  sortObject,
@@ -3043,9 +3595,11 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
3043
3595
  switchToNetwork,
3044
3596
  updateCvmResources,
3045
3597
  updateCvmVisibility,
3598
+ updateOsImage,
3046
3599
  validateActionParameters,
3047
3600
  validateNetworkPrerequisites,
3048
3601
  verifyEnvEncryptPublicKey,
3049
3602
  waitForTransactionReceipt,
3603
+ watchCvmState,
3050
3604
  withComposeMethods
3051
3605
  });