@phala/cloud 0.2.5 → 0.2.8

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.mjs CHANGED
@@ -56,13 +56,14 @@ var RequestError = class _RequestError extends PhalaCloudError {
56
56
  static fromFetchError(error) {
57
57
  const parseResult = ApiErrorSchema.safeParse(error.data);
58
58
  if (parseResult.success) {
59
+ const detail = parseResult.data.detail ?? (error.data && typeof error.data === "object" && "error_code" in error.data ? error.data : void 0);
59
60
  return new _RequestError(error.message, {
60
61
  status: error.status ?? void 0,
61
62
  statusText: error.statusText ?? void 0,
62
63
  data: error.data,
63
64
  request: error.request ?? void 0,
64
65
  response: error.response ?? void 0,
65
- detail: parseResult.data.detail,
66
+ detail,
66
67
  code: parseResult.data.code ?? void 0,
67
68
  type: parseResult.data.type ?? void 0
68
69
  });
@@ -331,6 +332,12 @@ function formatStructuredError(error, options) {
331
332
  }
332
333
  return parts.join("\n");
333
334
  }
335
+ function isConflictError(error) {
336
+ return error.status === 409;
337
+ }
338
+ function isAppIdConflictError(error) {
339
+ return error instanceof ResourceError && error.errorCode === "ERR-03-007";
340
+ }
334
341
 
335
342
  // src/client.ts
336
343
  var SUPPORTED_API_VERSIONS = [
@@ -394,8 +401,20 @@ var Client = class _Client {
394
401
  headers: requestHeaders,
395
402
  ...useCookieAuth ? { credentials: "include" } : {},
396
403
  ...fetchOptions,
397
- // Log request in cURL format
404
+ // Strip Content-Type for FormData so the browser/runtime sets
405
+ // the correct multipart/form-data boundary automatically.
406
+ // This runs after ofetch merges instance and per-request headers,
407
+ // so deleting here is final.
398
408
  onRequest({ request, options }) {
409
+ if (options.body instanceof FormData) {
410
+ const h = options.headers;
411
+ if (h instanceof Headers) {
412
+ h.delete("content-type");
413
+ } else if (h && typeof h === "object" && !Array.isArray(h)) {
414
+ delete h["Content-Type"];
415
+ delete h["content-type"];
416
+ }
417
+ }
399
418
  if (logger.enabled) {
400
419
  const method = options.method || "GET";
401
420
  const url = typeof request === "string" ? request : request.url;
@@ -527,16 +546,28 @@ var Client = class _Client {
527
546
  throw phalaCloudError;
528
547
  }
529
548
  }
549
+ /**
550
+ * Build request options, stripping Content-Type when body is FormData
551
+ * so the browser/runtime sets the correct multipart boundary automatically.
552
+ */
553
+ // biome-ignore lint/suspicious/noExplicitAny: ofetch generic variance
554
+ buildRequestOptions(method, body, options) {
555
+ const opts = { ...options, method, body };
556
+ if (body instanceof FormData) {
557
+ const existing = opts.headers;
558
+ opts.headers = {
559
+ ...existing,
560
+ "Content-Type": ""
561
+ };
562
+ }
563
+ return opts;
564
+ }
530
565
  /**
531
566
  * Perform POST request (throws PhalaCloudError on error)
532
567
  */
533
568
  async post(request, body, options) {
534
569
  try {
535
- return await this.fetchInstance(request, {
536
- ...options,
537
- method: "POST",
538
- body
539
- });
570
+ return await this.fetchInstance(request, this.buildRequestOptions("POST", body, options));
540
571
  } catch (error) {
541
572
  const requestError = this.convertToRequestError(error);
542
573
  const phalaCloudError = this.emitError(requestError);
@@ -548,11 +579,7 @@ var Client = class _Client {
548
579
  */
549
580
  async put(request, body, options) {
550
581
  try {
551
- return await this.fetchInstance(request, {
552
- ...options,
553
- method: "PUT",
554
- body
555
- });
582
+ return await this.fetchInstance(request, this.buildRequestOptions("PUT", body, options));
556
583
  } catch (error) {
557
584
  const requestError = this.convertToRequestError(error);
558
585
  const phalaCloudError = this.emitError(requestError);
@@ -564,11 +591,7 @@ var Client = class _Client {
564
591
  */
565
592
  async patch(request, body, options) {
566
593
  try {
567
- return await this.fetchInstance(request, {
568
- ...options,
569
- method: "PATCH",
570
- body
571
- });
594
+ return await this.fetchInstance(request, this.buildRequestOptions("PATCH", body, options));
572
595
  } catch (error) {
573
596
  const requestError = this.convertToRequestError(error);
574
597
  const phalaCloudError = this.emitError(requestError);
@@ -1222,7 +1245,7 @@ var CvmOsInfoV20260121Schema = z9.object({
1222
1245
  is_dev: z9.boolean().nullable().optional(),
1223
1246
  os_image_hash: z9.string().nullable().optional()
1224
1247
  });
1225
- var CvmKmsInfoV20260121Schema = z9.object({
1248
+ var CvmKmsInfoV20260121BaseSchema = z9.object({
1226
1249
  chain_id: z9.number().int().nullable().optional(),
1227
1250
  dstack_kms_address: z9.string().nullable().optional(),
1228
1251
  dstack_app_address: z9.string().nullable().optional(),
@@ -1230,6 +1253,15 @@ var CvmKmsInfoV20260121Schema = z9.object({
1230
1253
  rpc_endpoint: z9.string().nullable().optional(),
1231
1254
  encrypted_env_pubkey: z9.string().nullable().optional()
1232
1255
  });
1256
+ var CvmKmsInfoV20260121Schema = CvmKmsInfoV20260121BaseSchema.transform((data) => {
1257
+ if (data.chain_id != null) {
1258
+ const chain = SUPPORTED_CHAINS[data.chain_id];
1259
+ if (chain) {
1260
+ return { ...data, chain };
1261
+ }
1262
+ }
1263
+ return data;
1264
+ });
1233
1265
  var CvmProgressInfoV20260121Schema = z9.object({
1234
1266
  target: z9.string().nullable().optional(),
1235
1267
  started_at: z9.string().nullable().optional(),
@@ -1745,7 +1777,8 @@ var ProvisionCvmComposeFileUpdateResultSchema = z15.object({
1745
1777
  app_id: z15.string().nullable(),
1746
1778
  device_id: z15.string().nullable(),
1747
1779
  compose_hash: z15.string(),
1748
- kms_info: KmsInfoSchema.nullable().optional()
1780
+ kms_info: KmsInfoSchema.nullable().optional(),
1781
+ compose_hash_registered: z15.boolean().optional().default(false)
1749
1782
  }).passthrough();
1750
1783
  var { action: provisionCvmComposeFileUpdate, safeAction: safeProvisionCvmComposeFileUpdate } = defineAction(ProvisionCvmComposeFileUpdateResultSchema, async (client, request) => {
1751
1784
  const validatedRequest = ProvisionCvmComposeFileUpdateRequestSchema.parse(request);
@@ -1852,14 +1885,24 @@ var { action: updateCvmEnvs, safeAction: safeUpdateCvmEnvs } = defineAction(Upda
1852
1885
  const detail = error.detail;
1853
1886
  if (detail && typeof detail === "object") {
1854
1887
  const detailObj = detail;
1855
- return {
1856
- status: "precondition_required",
1857
- message: detailObj.message || "Compose hash verification required",
1858
- compose_hash: detailObj.compose_hash,
1859
- app_id: detailObj.app_id,
1860
- device_id: detailObj.device_id,
1861
- kms_info: detailObj.kms_info
1862
- };
1888
+ const detailsArray = detailObj.details;
1889
+ if (detailsArray && Array.isArray(detailsArray)) {
1890
+ const fieldMap = new Map(detailsArray.map((d) => [d.field, d.value]));
1891
+ const composeHash = fieldMap.get("compose_hash");
1892
+ const appId = fieldMap.get("app_id");
1893
+ const deviceId = fieldMap.get("device_id");
1894
+ const kmsInfo = fieldMap.get("kms_info");
1895
+ if (composeHash && appId) {
1896
+ return {
1897
+ status: "precondition_required",
1898
+ message: detailObj.message || "Compose hash verification required",
1899
+ compose_hash: composeHash,
1900
+ app_id: appId,
1901
+ device_id: deviceId || "",
1902
+ kms_info: kmsInfo
1903
+ };
1904
+ }
1905
+ }
1863
1906
  }
1864
1907
  }
1865
1908
  throw error;
@@ -1926,14 +1969,24 @@ var { action: updateDockerCompose, safeAction: safeUpdateDockerCompose } = defin
1926
1969
  const detail = error.detail;
1927
1970
  if (detail && typeof detail === "object") {
1928
1971
  const detailObj = detail;
1929
- return {
1930
- status: "precondition_required",
1931
- message: detailObj.message || "Compose hash verification required",
1932
- compose_hash: detailObj.compose_hash,
1933
- app_id: detailObj.app_id,
1934
- device_id: detailObj.device_id,
1935
- kms_info: detailObj.kms_info
1936
- };
1972
+ const detailsArray = detailObj.details;
1973
+ if (detailsArray && Array.isArray(detailsArray)) {
1974
+ const fieldMap = new Map(detailsArray.map((d) => [d.field, d.value]));
1975
+ const composeHash = fieldMap.get("compose_hash");
1976
+ const appId = fieldMap.get("app_id");
1977
+ const deviceId = fieldMap.get("device_id");
1978
+ const kmsInfo = fieldMap.get("kms_info");
1979
+ if (composeHash && appId) {
1980
+ return {
1981
+ status: "precondition_required",
1982
+ message: detailObj.message || "Compose hash verification required",
1983
+ compose_hash: composeHash,
1984
+ app_id: appId,
1985
+ device_id: deviceId || "",
1986
+ kms_info: kmsInfo
1987
+ };
1988
+ }
1989
+ }
1937
1990
  }
1938
1991
  }
1939
1992
  throw error;
@@ -2000,14 +2053,24 @@ var { action: updatePreLaunchScript, safeAction: safeUpdatePreLaunchScript } = d
2000
2053
  const detail = error.detail;
2001
2054
  if (detail && typeof detail === "object") {
2002
2055
  const detailObj = detail;
2003
- return {
2004
- status: "precondition_required",
2005
- message: detailObj.message || "Compose hash verification required",
2006
- compose_hash: detailObj.compose_hash,
2007
- app_id: detailObj.app_id,
2008
- device_id: detailObj.device_id,
2009
- kms_info: detailObj.kms_info
2010
- };
2056
+ const detailsArray = detailObj.details;
2057
+ if (detailsArray && Array.isArray(detailsArray)) {
2058
+ const fieldMap = new Map(detailsArray.map((d) => [d.field, d.value]));
2059
+ const composeHash = fieldMap.get("compose_hash");
2060
+ const appId = fieldMap.get("app_id");
2061
+ const deviceId = fieldMap.get("device_id");
2062
+ const kmsInfo = fieldMap.get("kms_info");
2063
+ if (composeHash && appId) {
2064
+ return {
2065
+ status: "precondition_required",
2066
+ message: detailObj.message || "Compose hash verification required",
2067
+ compose_hash: composeHash,
2068
+ app_id: appId,
2069
+ device_id: deviceId || "",
2070
+ kms_info: kmsInfo
2071
+ };
2072
+ }
2073
+ }
2011
2074
  }
2012
2075
  }
2013
2076
  throw error;
@@ -2859,6 +2922,51 @@ function asHex(value) {
2859
2922
  throw new Error(`Invalid hex value: ${value}`);
2860
2923
  }
2861
2924
 
2925
+ // src/utils/error_codes.ts
2926
+ var ErrorCodes = {
2927
+ // Module 01: CVM Preflight & Compose Hash
2928
+ NODE_NOT_FOUND: "ERR-01-001",
2929
+ COMPOSE_FILE_REQUIRED: "ERR-01-002",
2930
+ INVALID_COMPOSE_FILE: "ERR-01-003",
2931
+ DUPLICATE_CVM_NAME: "ERR-01-004",
2932
+ HASH_REGISTRATION_REQUIRED: "ERR-01-005",
2933
+ HASH_INVALID_OR_EXPIRED: "ERR-01-006",
2934
+ TX_VERIFICATION_FAILED: "ERR-01-007",
2935
+ HASH_NOT_ALLOWED: "ERR-01-008",
2936
+ // Module 02: Inventory
2937
+ INSTANCE_TYPE_NOT_FOUND: "ERR-02-001",
2938
+ RESOURCE_NOT_AVAILABLE: "ERR-02-002",
2939
+ INSUFFICIENT_VCPU: "ERR-02-003",
2940
+ INSUFFICIENT_MEMORY: "ERR-02-004",
2941
+ INSUFFICIENT_SLOTS: "ERR-02-005",
2942
+ GPU_ALLOCATION_ERROR: "ERR-02-006",
2943
+ INSUFFICIENT_GPU: "ERR-02-007",
2944
+ INVALID_REQUEST: "ERR-02-008",
2945
+ INCOMPATIBLE_CONFIG: "ERR-02-009",
2946
+ IMAGE_NOT_FOUND: "ERR-02-010",
2947
+ KMS_NOT_FOUND: "ERR-02-011",
2948
+ TEEPOD_NOT_ACCESSIBLE: "ERR-02-012",
2949
+ OS_IMAGE_NOT_COMPATIBLE: "ERR-02-013",
2950
+ NODE_CAPACITY_NOT_CONFIGURED: "ERR-02-014",
2951
+ QUOTA_EXCEEDED: "ERR-02-015",
2952
+ // Module 03: CVM Operations
2953
+ CVM_NOT_FOUND: "ERR-03-001",
2954
+ MULTIPLE_CVMS_SAME_NAME: "ERR-03-002",
2955
+ CVM_NOT_IN_WORKSPACE: "ERR-03-003",
2956
+ CVM_ACCESS_DENIED: "ERR-03-005",
2957
+ REPLICA_IMAGE_NOT_AVAILABLE: "ERR-03-006",
2958
+ CVM_APP_ID_CONFLICT: "ERR-03-007",
2959
+ // Module 04: Workspace
2960
+ INSUFFICIENT_BALANCE: "ERR-04-001",
2961
+ MAX_CVM_LIMIT: "ERR-04-002",
2962
+ RESOURCE_LIMIT_EXCEEDED: "ERR-04-003",
2963
+ // Module 05: Credentials
2964
+ TOKEN_LIMIT_EXCEEDED: "ERR-05-001",
2965
+ TOKEN_RATE_LIMIT: "ERR-05-002",
2966
+ // Module 06: Auth
2967
+ OAUTH_EMAIL_INVALID: "ERR-06-001"
2968
+ };
2969
+
2862
2970
  // src/utils/network.ts
2863
2971
  var NetworkError = class extends Error {
2864
2972
  constructor(message, code, details) {
@@ -3997,6 +4105,24 @@ async function addComposeHash(request, parameters) {
3997
4105
  );
3998
4106
  }
3999
4107
  }
4108
+ const contractOwner = await publicClient.readContract({
4109
+ address: appAuthAddress,
4110
+ abi: [
4111
+ {
4112
+ inputs: [],
4113
+ name: "owner",
4114
+ outputs: [{ type: "address" }],
4115
+ stateMutability: "view",
4116
+ type: "function"
4117
+ }
4118
+ ],
4119
+ functionName: "owner"
4120
+ });
4121
+ if (contractOwner.toLowerCase() !== address.toLowerCase()) {
4122
+ throw new Error(
4123
+ `Sender ${address} is not the owner of contract ${appAuthAddress}. Contract owner is ${contractOwner}.`
4124
+ );
4125
+ }
4000
4126
  const addComposeHashOperation = async (clients) => {
4001
4127
  const hash = await clients.walletClient.writeContract({
4002
4128
  address: appAuthAddress,
@@ -4114,6 +4240,24 @@ var dstackAppAbi = [
4114
4240
  stateMutability: "view",
4115
4241
  type: "function"
4116
4242
  },
4243
+ {
4244
+ inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
4245
+ name: "allowedComposeHashes",
4246
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
4247
+ stateMutability: "view",
4248
+ type: "function"
4249
+ },
4250
+ // ── Errors ───────────────────────────────────────────────────────
4251
+ {
4252
+ inputs: [{ internalType: "address", name: "owner", type: "address" }],
4253
+ name: "OwnableInvalidOwner",
4254
+ type: "error"
4255
+ },
4256
+ {
4257
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
4258
+ name: "OwnableUnauthorizedAccount",
4259
+ type: "error"
4260
+ },
4117
4261
  // ── Events ───────────────────────────────────────────────────────
4118
4262
  {
4119
4263
  anonymous: false,
@@ -4199,17 +4343,21 @@ async function addDevice(request, parameters) {
4199
4343
  let chainId;
4200
4344
  if (privateKey) {
4201
4345
  const account = privateKeyToAccount4(privateKey);
4202
- publicClient = providedPublicClient ? providedPublicClient : createPublicClient4({ chain, transport: http4(rpcUrl) });
4346
+ const transport = http4(rpcUrl, { timeout });
4347
+ publicClient = providedPublicClient ? providedPublicClient : createPublicClient4({ chain, transport });
4203
4348
  walletClient = createWalletClient4({
4204
4349
  account,
4205
4350
  chain,
4206
- transport: http4(rpcUrl)
4351
+ transport
4207
4352
  });
4208
4353
  address = account.address;
4209
4354
  chainId = chain.id;
4210
4355
  } else if (providedWalletClient) {
4211
4356
  walletClient = providedWalletClient;
4212
- publicClient = providedPublicClient ? providedPublicClient : createPublicClient4({ chain, transport: http4(rpcUrl) });
4357
+ publicClient = providedPublicClient ? providedPublicClient : createPublicClient4({
4358
+ chain,
4359
+ transport: http4(rpcUrl, { timeout })
4360
+ });
4213
4361
  if (!walletClient.account?.address) {
4214
4362
  throw new Error("WalletClient must have an account with address");
4215
4363
  }
@@ -4248,6 +4396,16 @@ async function addDevice(request, parameters) {
4248
4396
  );
4249
4397
  }
4250
4398
  }
4399
+ const contractOwner = await publicClient.readContract({
4400
+ address: contractAddress,
4401
+ abi: dstackAppAbi,
4402
+ functionName: "owner"
4403
+ });
4404
+ if (contractOwner.toLowerCase() !== address.toLowerCase()) {
4405
+ throw new Error(
4406
+ `Sender ${address} is not the owner of contract ${contractAddress}. Contract owner is ${contractOwner}.`
4407
+ );
4408
+ }
4251
4409
  const addDeviceOperation = async (clients) => {
4252
4410
  return clients.walletClient.writeContract({
4253
4411
  address: contractAddress,
@@ -4375,17 +4533,21 @@ async function removeDevice(request, parameters) {
4375
4533
  let chainId;
4376
4534
  if (privateKey) {
4377
4535
  const account = privateKeyToAccount5(privateKey);
4378
- publicClient = providedPublicClient ? providedPublicClient : createPublicClient5({ chain, transport: http5(rpcUrl) });
4536
+ const transport = http5(rpcUrl, { timeout });
4537
+ publicClient = providedPublicClient ? providedPublicClient : createPublicClient5({ chain, transport });
4379
4538
  walletClient = createWalletClient5({
4380
4539
  account,
4381
4540
  chain,
4382
- transport: http5(rpcUrl)
4541
+ transport
4383
4542
  });
4384
4543
  address = account.address;
4385
4544
  chainId = chain.id;
4386
4545
  } else if (providedWalletClient) {
4387
4546
  walletClient = providedWalletClient;
4388
- publicClient = providedPublicClient ? providedPublicClient : createPublicClient5({ chain, transport: http5(rpcUrl) });
4547
+ publicClient = providedPublicClient ? providedPublicClient : createPublicClient5({
4548
+ chain,
4549
+ transport: http5(rpcUrl, { timeout })
4550
+ });
4389
4551
  if (!walletClient.account?.address) {
4390
4552
  throw new Error("WalletClient must have an account with address");
4391
4553
  }
@@ -4550,17 +4712,21 @@ async function setAllowAnyDevice(request, parameters) {
4550
4712
  let chainId;
4551
4713
  if (privateKey) {
4552
4714
  const account = privateKeyToAccount6(privateKey);
4553
- publicClient = providedPublicClient ? providedPublicClient : createPublicClient6({ chain, transport: http6(rpcUrl) });
4715
+ const transport = http6(rpcUrl, { timeout });
4716
+ publicClient = providedPublicClient ? providedPublicClient : createPublicClient6({ chain, transport });
4554
4717
  walletClient = createWalletClient6({
4555
4718
  account,
4556
4719
  chain,
4557
- transport: http6(rpcUrl)
4720
+ transport
4558
4721
  });
4559
4722
  address = account.address;
4560
4723
  chainId = chain.id;
4561
4724
  } else if (providedWalletClient) {
4562
4725
  walletClient = providedWalletClient;
4563
- publicClient = providedPublicClient ? providedPublicClient : createPublicClient6({ chain, transport: http6(rpcUrl) });
4726
+ publicClient = providedPublicClient ? providedPublicClient : createPublicClient6({
4727
+ chain,
4728
+ transport: http6(rpcUrl, { timeout })
4729
+ });
4564
4730
  if (!walletClient.account?.address) {
4565
4731
  throw new Error("WalletClient must have an account with address");
4566
4732
  }
@@ -4763,6 +4929,97 @@ async function safeCheckDeviceAllowed(request) {
4763
4929
  }
4764
4930
  }
4765
4931
 
4932
+ // src/actions/blockchains/check_compose_hash_allowed.ts
4933
+ import { createPublicClient as createPublicClient9, http as http9 } from "viem";
4934
+ async function checkComposeHashAllowed(request) {
4935
+ const { chain, rpcUrl, appAddress, composeHash, publicClient: providedPublicClient } = request;
4936
+ const contractAddress = appAddress.startsWith("0x") ? appAddress : `0x${appAddress}`;
4937
+ const composeHashHex = asHex(composeHash);
4938
+ const publicClient = providedPublicClient ? providedPublicClient : (() => {
4939
+ if (!chain) throw new Error("Chain is required when publicClient is not provided");
4940
+ return createPublicClient9({ chain, transport: http9(rpcUrl) });
4941
+ })();
4942
+ const allowed = await publicClient.readContract({
4943
+ address: contractAddress,
4944
+ abi: dstackAppAbi,
4945
+ functionName: "allowedComposeHashes",
4946
+ args: [composeHashHex]
4947
+ });
4948
+ return allowed;
4949
+ }
4950
+ async function safeCheckComposeHashAllowed(request) {
4951
+ try {
4952
+ const result = await checkComposeHashAllowed(request);
4953
+ return { success: true, data: result };
4954
+ } catch (error) {
4955
+ const errorMessage = error instanceof Error ? error.message : "Unknown blockchain error";
4956
+ return {
4957
+ success: false,
4958
+ error: { isRequestError: true, message: errorMessage, status: 500, detail: errorMessage }
4959
+ };
4960
+ }
4961
+ }
4962
+
4963
+ // src/actions/blockchains/check_on_chain_prerequisites.ts
4964
+ import { createPublicClient as createPublicClient10, http as http10 } from "viem";
4965
+ async function checkOnChainPrerequisites(request) {
4966
+ const {
4967
+ chain,
4968
+ rpcUrl,
4969
+ appAddress,
4970
+ deviceId,
4971
+ composeHash,
4972
+ publicClient: providedPublicClient
4973
+ } = request;
4974
+ const contractAddress = appAddress.startsWith("0x") ? appAddress : `0x${appAddress}`;
4975
+ const deviceIdHex = asHex(deviceId);
4976
+ const composeHashHex = asHex(composeHash);
4977
+ const publicClient = providedPublicClient ? providedPublicClient : (() => {
4978
+ if (!chain) throw new Error("Chain is required when publicClient is not provided");
4979
+ return createPublicClient10({ chain, transport: http10(rpcUrl) });
4980
+ })();
4981
+ const calls = [
4982
+ {
4983
+ address: contractAddress,
4984
+ abi: dstackAppAbi,
4985
+ functionName: "allowAnyDevice"
4986
+ },
4987
+ {
4988
+ address: contractAddress,
4989
+ abi: dstackAppAbi,
4990
+ functionName: "allowedDeviceIds",
4991
+ args: [deviceIdHex]
4992
+ },
4993
+ {
4994
+ address: contractAddress,
4995
+ abi: dstackAppAbi,
4996
+ functionName: "allowedComposeHashes",
4997
+ args: [composeHashHex]
4998
+ }
4999
+ ];
5000
+ const multicallResults = await publicClient.multicall({ contracts: calls });
5001
+ const allowAnyDevice = multicallResults[0]?.status === "success" && multicallResults[0]?.result === true;
5002
+ const deviceIdAllowed = multicallResults[1]?.status === "success" && multicallResults[1]?.result === true;
5003
+ const composeHashAllowed = multicallResults[2]?.status === "success" && multicallResults[2]?.result === true;
5004
+ return {
5005
+ allowAnyDevice,
5006
+ deviceAllowed: allowAnyDevice || deviceIdAllowed,
5007
+ composeHashAllowed
5008
+ };
5009
+ }
5010
+ async function safeCheckOnChainPrerequisites(request) {
5011
+ try {
5012
+ const result = await checkOnChainPrerequisites(request);
5013
+ return { success: true, data: result };
5014
+ } catch (error) {
5015
+ const errorMessage = error instanceof Error ? error.message : "Unknown blockchain error";
5016
+ return {
5017
+ success: false,
5018
+ error: { isRequestError: true, message: errorMessage, status: 500, detail: errorMessage }
5019
+ };
5020
+ }
5021
+ }
5022
+
4766
5023
  // src/actions/workspaces/get_workspace_nodes.ts
4767
5024
  import { z as z54 } from "zod";
4768
5025
  var NodeRefSchema2 = NodeRefSchema;
@@ -5020,22 +5277,177 @@ function sleep(ms, signal) {
5020
5277
  });
5021
5278
  }
5022
5279
 
5023
- // src/actions/cvms/refresh_cvm_instance_id.ts
5280
+ // src/actions/cvms/patch_cvm.ts
5024
5281
  import { z as z58 } from "zod";
5025
- var InstanceIdRefreshResultSchema = z58.object({
5026
- cvm_id: z58.number().int(),
5027
- identifier: z58.string(),
5028
- status: z58.enum(["updated", "unchanged", "skipped", "conflict", "error"]),
5029
- old_instance_id: z58.string().nullable().optional(),
5030
- new_instance_id: z58.string().nullable().optional(),
5031
- source: z58.enum(["teepod_state", "teepod_info", "gateway", "none"]),
5032
- verified_with_gateway: z58.boolean(),
5033
- reason: z58.string().nullable().optional()
5282
+ var PatchCvmRequestSchema = refineCvmId(
5283
+ CvmIdObjectSchema.extend({
5284
+ // Compose-hash-affecting fields
5285
+ docker_compose_file: z58.string().optional(),
5286
+ pre_launch_script: z58.string().optional(),
5287
+ allowed_envs: z58.array(z58.string()).optional(),
5288
+ // Visibility
5289
+ public_logs: z58.boolean().optional(),
5290
+ public_sysinfo: z58.boolean().optional(),
5291
+ public_tcbinfo: z58.boolean().optional(),
5292
+ // Non-compose-hash config
5293
+ encrypted_env: z58.string().optional(),
5294
+ user_config: z58.string().optional(),
5295
+ gpus: z58.object({
5296
+ count: z58.number(),
5297
+ product_name: z58.string().optional()
5298
+ }).optional(),
5299
+ // Resources
5300
+ vcpu: z58.number().optional(),
5301
+ memory: z58.number().optional(),
5302
+ disk_size: z58.number().optional(),
5303
+ // OS image
5304
+ image: z58.string().optional(),
5305
+ // Shutdown behavior
5306
+ shutdown_timeout: z58.number().optional(),
5307
+ allow_force_stop: z58.boolean().optional(),
5308
+ // Prepare-only mode (for multisig workflows)
5309
+ prepareOnly: z58.boolean().optional()
5310
+ })
5311
+ );
5312
+ var PatchCvmAcceptedSchema = z58.object({
5313
+ requiresOnChainHash: z58.literal(false),
5314
+ correlationId: z58.string()
5315
+ });
5316
+ var PatchCvmHashRequiredSchema = z58.object({
5317
+ requiresOnChainHash: z58.literal(true),
5318
+ composeHash: z58.string(),
5319
+ appId: z58.string(),
5320
+ deviceId: z58.string(),
5321
+ kmsInfo: KmsInfoSchema,
5322
+ commitToken: z58.string().optional(),
5323
+ commitUrl: z58.string().optional(),
5324
+ apiCommitUrl: z58.string().optional(),
5325
+ onchainStatus: z58.object({
5326
+ compose_hash_allowed: z58.boolean(),
5327
+ device_id_allowed: z58.boolean(),
5328
+ is_allowed: z58.boolean()
5329
+ }).optional()
5330
+ });
5331
+ var PatchCvmResultSchema = z58.discriminatedUnion("requiresOnChainHash", [
5332
+ PatchCvmAcceptedSchema,
5333
+ PatchCvmHashRequiredSchema
5334
+ ]);
5335
+ function extractDetailsMap(detail) {
5336
+ const map = {};
5337
+ if (!detail || typeof detail !== "object") return map;
5338
+ const obj = detail;
5339
+ const details = obj.details;
5340
+ if (!Array.isArray(details)) return map;
5341
+ for (const item of details) {
5342
+ if (item && typeof item === "object" && "field" in item && "value" in item) {
5343
+ map[item.field] = item.value;
5344
+ }
5345
+ }
5346
+ return map;
5347
+ }
5348
+ var { action: patchCvm, safeAction: safePatchCvm } = defineAction(PatchCvmResultSchema, async (client, request) => {
5349
+ const parsed = PatchCvmRequestSchema.parse(request);
5350
+ const { cvmId } = CvmIdSchema.parse(parsed);
5351
+ const { id, uuid, app_id, instance_id, name, prepareOnly, ...body } = parsed;
5352
+ try {
5353
+ const response = prepareOnly ? await client.patch(`/cvms/${cvmId}`, body, {
5354
+ headers: { "X-Prepare-Only": "true" }
5355
+ }) : await client.patch(`/cvms/${cvmId}`, body);
5356
+ return {
5357
+ requiresOnChainHash: false,
5358
+ correlationId: response.correlation_id
5359
+ };
5360
+ } catch (error) {
5361
+ if (error instanceof PhalaCloudError && error.status === 465) {
5362
+ const details = extractDetailsMap(error.detail);
5363
+ return {
5364
+ requiresOnChainHash: true,
5365
+ composeHash: details.compose_hash,
5366
+ appId: String(details.app_id),
5367
+ deviceId: details.device_id,
5368
+ kmsInfo: details.kms_info,
5369
+ commitToken: details.commit_token,
5370
+ commitUrl: details.commit_url,
5371
+ apiCommitUrl: details.api_commit_url,
5372
+ onchainStatus: details.onchain_status
5373
+ };
5374
+ }
5375
+ throw error;
5376
+ }
5377
+ });
5378
+
5379
+ // src/actions/cvms/confirm_cvm_patch.ts
5380
+ import { z as z59 } from "zod";
5381
+ var ConfirmCvmPatchRequestSchema = refineCvmId(
5382
+ CvmIdObjectSchema.extend({
5383
+ composeHash: z59.string().describe("Compose hash from patchCvm Phase 1 response"),
5384
+ transactionHash: z59.string().describe("Transaction hash proving on-chain registration")
5385
+ })
5386
+ );
5387
+ var ConfirmCvmPatchResultSchema = z59.object({
5388
+ correlationId: z59.string()
5389
+ });
5390
+ var { action: confirmCvmPatch, safeAction: safeConfirmCvmPatch } = defineAction(ConfirmCvmPatchResultSchema, async (client, request) => {
5391
+ const parsed = ConfirmCvmPatchRequestSchema.parse(request);
5392
+ const { cvmId } = CvmIdSchema.parse(parsed);
5393
+ const response = await client.patch(
5394
+ `/cvms/${cvmId}`,
5395
+ {},
5396
+ {
5397
+ headers: {
5398
+ "X-Compose-Hash": parsed.composeHash,
5399
+ "X-Transaction-Hash": parsed.transactionHash
5400
+ }
5401
+ }
5402
+ );
5403
+ return {
5404
+ correlationId: response.correlation_id
5405
+ };
5406
+ });
5407
+
5408
+ // src/actions/cvms/commit_cvm_update.ts
5409
+ import { z as z60 } from "zod";
5410
+ var CommitCvmUpdateRequestSchema = refineCvmId(
5411
+ CvmIdObjectSchema.extend({
5412
+ token: z60.string().describe("One-time commit token from prepare-only flow"),
5413
+ composeHash: z60.string().describe("Compose hash from Phase 1 response"),
5414
+ transactionHash: z60.string().describe("Transaction hash proving on-chain registration")
5415
+ })
5416
+ );
5417
+ var CommitCvmUpdateResultSchema = z60.object({
5418
+ correlationId: z60.string(),
5419
+ status: z60.string()
5420
+ });
5421
+ var { action: commitCvmUpdate, safeAction: safeCommitCvmUpdate } = defineAction(CommitCvmUpdateResultSchema, async (client, request) => {
5422
+ const parsed = CommitCvmUpdateRequestSchema.parse(request);
5423
+ const { cvmId } = CvmIdSchema.parse(parsed);
5424
+ const response = await client.post(`/cvms/${cvmId}/commit-update`, {
5425
+ token: parsed.token,
5426
+ compose_hash: parsed.composeHash,
5427
+ transaction_hash: parsed.transactionHash
5428
+ });
5429
+ return {
5430
+ correlationId: response.correlation_id,
5431
+ status: response.status
5432
+ };
5433
+ });
5434
+
5435
+ // src/actions/cvms/refresh_cvm_instance_id.ts
5436
+ import { z as z61 } from "zod";
5437
+ var InstanceIdRefreshResultSchema = z61.object({
5438
+ cvm_id: z61.number().int(),
5439
+ identifier: z61.string(),
5440
+ status: z61.enum(["updated", "unchanged", "skipped", "conflict", "error"]),
5441
+ old_instance_id: z61.string().nullable().optional(),
5442
+ new_instance_id: z61.string().nullable().optional(),
5443
+ source: z61.enum(["teepod_state", "teepod_info", "gateway", "none"]),
5444
+ verified_with_gateway: z61.boolean(),
5445
+ reason: z61.string().nullable().optional()
5034
5446
  });
5035
5447
  var RefreshCvmInstanceIdRequestSchema = refineCvmId(
5036
5448
  CvmIdObjectSchema.extend({
5037
- overwrite: z58.boolean().optional(),
5038
- dry_run: z58.boolean().optional()
5449
+ overwrite: z61.boolean().optional(),
5450
+ dry_run: z61.boolean().optional()
5039
5451
  })
5040
5452
  );
5041
5453
  var { action: refreshCvmInstanceId, safeAction: safeRefreshCvmInstanceId } = defineAction(InstanceIdRefreshResultSchema, async (client, request) => {
@@ -5049,24 +5461,24 @@ var { action: refreshCvmInstanceId, safeAction: safeRefreshCvmInstanceId } = def
5049
5461
  });
5050
5462
 
5051
5463
  // src/actions/cvms/refresh_cvm_instance_ids.ts
5052
- import { z as z59 } from "zod";
5053
- var RefreshCvmInstanceIdsRequestSchema = z59.object({
5054
- cvm_ids: z59.array(z59.string()).optional(),
5055
- running_only: z59.boolean().optional(),
5056
- missing_only: z59.boolean().optional(),
5057
- overwrite: z59.boolean().optional(),
5058
- limit: z59.number().int().min(1).max(500).optional(),
5059
- dry_run: z59.boolean().optional()
5464
+ import { z as z62 } from "zod";
5465
+ var RefreshCvmInstanceIdsRequestSchema = z62.object({
5466
+ cvm_ids: z62.array(z62.string()).optional(),
5467
+ running_only: z62.boolean().optional(),
5468
+ missing_only: z62.boolean().optional(),
5469
+ overwrite: z62.boolean().optional(),
5470
+ limit: z62.number().int().min(1).max(500).optional(),
5471
+ dry_run: z62.boolean().optional()
5060
5472
  }).strict();
5061
- var RefreshCvmInstanceIdsResponseSchema = z59.object({
5062
- total: z59.number().int(),
5063
- scanned: z59.number().int(),
5064
- updated: z59.number().int(),
5065
- unchanged: z59.number().int(),
5066
- skipped: z59.number().int(),
5067
- conflicts: z59.number().int(),
5068
- errors: z59.number().int(),
5069
- items: z59.array(InstanceIdRefreshResultSchema)
5473
+ var RefreshCvmInstanceIdsResponseSchema = z62.object({
5474
+ total: z62.number().int(),
5475
+ scanned: z62.number().int(),
5476
+ updated: z62.number().int(),
5477
+ unchanged: z62.number().int(),
5478
+ skipped: z62.number().int(),
5479
+ conflicts: z62.number().int(),
5480
+ errors: z62.number().int(),
5481
+ items: z62.array(InstanceIdRefreshResultSchema)
5070
5482
  });
5071
5483
  var { action: refreshCvmInstanceIds, safeAction: safeRefreshCvmInstanceIds } = defineAction(RefreshCvmInstanceIdsResponseSchema, async (client, request) => {
5072
5484
  const parsed = RefreshCvmInstanceIdsRequestSchema.parse(request);
@@ -5074,21 +5486,21 @@ var { action: refreshCvmInstanceIds, safeAction: safeRefreshCvmInstanceIds } = d
5074
5486
  });
5075
5487
 
5076
5488
  // src/actions/cvms/get_cvm_status_batch.ts
5077
- import { z as z60 } from "zod";
5078
- var CvmStatusSchema = z60.object({
5079
- vm_uuid: z60.string(),
5080
- status: z60.string(),
5081
- uptime: z60.string().nullable().optional(),
5082
- in_progress: z60.boolean(),
5083
- boot_progress: z60.string().nullable().optional(),
5084
- boot_error: z60.string().nullable().optional(),
5085
- operation_type: z60.string().nullable().optional(),
5086
- operation_started_at: z60.string().nullable().optional(),
5087
- correlation_id: z60.string().nullable().optional()
5088
- });
5089
- var GetCvmStatusBatchResponseSchema = z60.record(z60.string(), CvmStatusSchema);
5090
- var GetCvmStatusBatchRequestSchema = z60.object({
5091
- vmUuids: z60.array(z60.string())
5489
+ import { z as z63 } from "zod";
5490
+ var CvmStatusSchema = z63.object({
5491
+ vm_uuid: z63.string(),
5492
+ status: z63.string(),
5493
+ uptime: z63.string().nullable().optional(),
5494
+ in_progress: z63.boolean(),
5495
+ boot_progress: z63.string().nullable().optional(),
5496
+ boot_error: z63.string().nullable().optional(),
5497
+ operation_type: z63.string().nullable().optional(),
5498
+ operation_started_at: z63.string().nullable().optional(),
5499
+ correlation_id: z63.string().nullable().optional()
5500
+ });
5501
+ var GetCvmStatusBatchResponseSchema = z63.record(z63.string(), CvmStatusSchema);
5502
+ var GetCvmStatusBatchRequestSchema = z63.object({
5503
+ vmUuids: z63.array(z63.string())
5092
5504
  });
5093
5505
  var { action: getCvmStatusBatch, safeAction: safeGetCvmStatusBatch } = defineAction(GetCvmStatusBatchResponseSchema, async (client, request) => {
5094
5506
  const { vmUuids } = GetCvmStatusBatchRequestSchema.parse(request);
@@ -5096,11 +5508,11 @@ var { action: getCvmStatusBatch, safeAction: safeGetCvmStatusBatch } = defineAct
5096
5508
  });
5097
5509
 
5098
5510
  // src/actions/cvms/get_cvm_user_config.ts
5099
- import { z as z61 } from "zod";
5100
- var CvmUserConfigSchema = z61.object({
5101
- hostname: z61.string().nullable().optional(),
5102
- ssh_authorized_keys: z61.array(z61.string()).default([]),
5103
- default_gateway_domain: z61.string().nullable().optional()
5511
+ import { z as z64 } from "zod";
5512
+ var CvmUserConfigSchema = z64.object({
5513
+ hostname: z64.string().nullable().optional(),
5514
+ ssh_authorized_keys: z64.array(z64.string()).default([]),
5515
+ default_gateway_domain: z64.string().nullable().optional()
5104
5516
  });
5105
5517
  var GetCvmUserConfigRequestSchema = CvmIdSchema;
5106
5518
  var { action: getCvmUserConfig, safeAction: safeGetCvmUserConfig } = defineAction(CvmUserConfigSchema, async (client, request) => {
@@ -5108,20 +5520,78 @@ var { action: getCvmUserConfig, safeAction: safeGetCvmUserConfig } = defineActio
5108
5520
  return await client.get(`/cvms/${cvmId}/user_config`);
5109
5521
  });
5110
5522
 
5523
+ // src/actions/cvms/check_cvm_is_allowed.ts
5524
+ import { z as z65 } from "zod";
5525
+ var IsAllowedResultSchema = z65.object({
5526
+ cvm_id: z65.number().optional(),
5527
+ app_contract_address: z65.string(),
5528
+ compose_hash: z65.string(),
5529
+ device_id: z65.string(),
5530
+ compose_hash_allowed: z65.boolean(),
5531
+ allow_any_device: z65.boolean(),
5532
+ device_id_allowed: z65.boolean().nullable().optional(),
5533
+ is_allowed: z65.boolean(),
5534
+ error: z65.string().nullable().optional()
5535
+ });
5536
+ var CheckCvmIsAllowedInputSchema = z65.object({
5537
+ cvmId: z65.string().min(1),
5538
+ compose_hash: z65.string().optional(),
5539
+ node_id: z65.number().optional(),
5540
+ device_id: z65.string().optional()
5541
+ });
5542
+ var CheckCvmIsAllowedRequestSchema = CheckCvmIsAllowedInputSchema;
5543
+ var { action: checkCvmIsAllowed, safeAction: safeCheckCvmIsAllowed } = defineAction(IsAllowedResultSchema, async (client, request) => {
5544
+ const { cvmId, ...body } = CheckCvmIsAllowedRequestSchema.parse(request);
5545
+ return await client.post(`/cvms/${cvmId}/is-allowed`, body);
5546
+ });
5547
+
5548
+ // src/actions/apps/check_app_is_allowed.ts
5549
+ import { z as z66 } from "zod";
5550
+ var CheckAppIsAllowedRequestSchema = z66.object({
5551
+ appId: z66.string().min(1),
5552
+ compose_hash: z66.string(),
5553
+ node_id: z66.number().optional(),
5554
+ device_id: z66.string().optional(),
5555
+ chain_id: z66.number().optional()
5556
+ });
5557
+ var { action: checkAppIsAllowed, safeAction: safeCheckAppIsAllowed } = defineAction(IsAllowedResultSchema, async (client, request) => {
5558
+ const { appId, ...body } = CheckAppIsAllowedRequestSchema.parse(request);
5559
+ return await client.post(`/apps/${appId}/is-allowed`, body);
5560
+ });
5561
+
5562
+ // src/actions/apps/check_app_cvms_is_allowed.ts
5563
+ import { z as z67 } from "zod";
5564
+ var AppCvmsBatchIsAllowedResponseSchema = z67.object({
5565
+ is_onchain: z67.boolean(),
5566
+ results: z67.array(IsAllowedResultSchema.extend({ cvm_id: z67.number() })).default([]),
5567
+ total: z67.number().default(0),
5568
+ allowed_count: z67.number().default(0),
5569
+ denied_count: z67.number().default(0),
5570
+ error_count: z67.number().default(0),
5571
+ skipped_cvm_ids: z67.array(z67.number()).default([])
5572
+ });
5573
+ var CheckAppCvmsIsAllowedRequestSchema = z67.object({
5574
+ appId: z67.string().min(1)
5575
+ });
5576
+ var { action: checkAppCvmsIsAllowed, safeAction: safeCheckAppCvmsIsAllowed } = defineAction(AppCvmsBatchIsAllowedResponseSchema, async (client, request) => {
5577
+ const { appId } = CheckAppCvmsIsAllowedRequestSchema.parse(request);
5578
+ return await client.post(`/apps/${appId}/cvms/is-allowed`, {});
5579
+ });
5580
+
5111
5581
  // src/actions/apps/get_app_list.ts
5112
- import { z as z62 } from "zod";
5113
- var GetAppListRequestSchema = z62.object({
5114
- page: z62.number().int().min(1).optional(),
5115
- page_size: z62.number().int().min(1).max(100).optional(),
5116
- search: z62.string().optional(),
5117
- status: z62.array(z62.string()).optional(),
5118
- listed: z62.boolean().optional(),
5119
- base_image: z62.string().optional(),
5120
- instance_type: z62.string().optional(),
5121
- kms_slug: z62.string().optional(),
5122
- kms_type: z62.string().optional(),
5123
- node: z62.string().optional(),
5124
- region: z62.string().optional()
5582
+ import { z as z68 } from "zod";
5583
+ var GetAppListRequestSchema = z68.object({
5584
+ page: z68.number().int().min(1).optional(),
5585
+ page_size: z68.number().int().min(1).max(100).optional(),
5586
+ search: z68.string().optional(),
5587
+ status: z68.array(z68.string()).optional(),
5588
+ listed: z68.boolean().optional(),
5589
+ base_image: z68.string().optional(),
5590
+ instance_type: z68.string().optional(),
5591
+ kms_slug: z68.string().optional(),
5592
+ kms_type: z68.string().optional(),
5593
+ node: z68.string().optional(),
5594
+ region: z68.string().optional()
5125
5595
  }).strict();
5126
5596
  function getSchemaForVersion4(version) {
5127
5597
  return version === "2025-10-28" ? DstackAppListResponseV20251028Schema : DstackAppListResponseV20260121Schema;
@@ -5151,9 +5621,9 @@ async function safeGetAppList(client, request) {
5151
5621
  }
5152
5622
 
5153
5623
  // src/actions/apps/get_app_info.ts
5154
- import { z as z63 } from "zod";
5155
- var GetAppInfoRequestSchema = z63.object({
5156
- appId: z63.string().min(1)
5624
+ import { z as z69 } from "zod";
5625
+ var GetAppInfoRequestSchema = z69.object({
5626
+ appId: z69.string().min(1)
5157
5627
  }).strict();
5158
5628
  function getSchemaForVersion5(version) {
5159
5629
  return version === "2025-10-28" ? DstackAppWithCvmResponseV20251028Schema : DstackAppWithCvmResponseV20260121Schema;
@@ -5183,12 +5653,12 @@ async function safeGetAppInfo(client, request) {
5183
5653
  }
5184
5654
 
5185
5655
  // src/actions/apps/get_app_cvms.ts
5186
- import { z as z64 } from "zod";
5187
- var GetAppCvmsRequestSchema = z64.object({
5188
- appId: z64.string().min(1)
5656
+ import { z as z70 } from "zod";
5657
+ var GetAppCvmsRequestSchema = z70.object({
5658
+ appId: z70.string().min(1)
5189
5659
  }).strict();
5190
5660
  function getSchemaForVersion6(version) {
5191
- return version === "2025-10-28" ? z64.array(CvmInfoV20251028Schema) : z64.array(CvmInfoV20260121Schema);
5661
+ return version === "2025-10-28" ? z70.array(CvmInfoV20251028Schema) : z70.array(CvmInfoV20260121Schema);
5192
5662
  }
5193
5663
  async function getAppCvms(client, request) {
5194
5664
  const { appId } = GetAppCvmsRequestSchema.parse(request);
@@ -5215,23 +5685,23 @@ async function safeGetAppCvms(client, request) {
5215
5685
  }
5216
5686
 
5217
5687
  // src/actions/apps/get_app_device_allowlist.ts
5218
- import { z as z65 } from "zod";
5219
- var DeviceAllowlistItemSchema = z65.object({
5220
- device_id: z65.string(),
5221
- node_name: z65.string().nullable(),
5222
- cvm_ids: z65.array(z65.number()),
5223
- allowed_onchain: z65.boolean(),
5224
- status: z65.string()
5225
- });
5226
- var DeviceAllowlistResponseSchema = z65.object({
5227
- is_onchain_kms: z65.boolean(),
5228
- allow_any_device: z65.boolean().nullable().optional(),
5229
- chain_id: z65.number().nullable().optional(),
5230
- app_contract_address: z65.string().nullable().optional(),
5231
- devices: z65.array(DeviceAllowlistItemSchema).optional().default([])
5232
- });
5233
- var GetAppDeviceAllowlistRequestSchema = z65.object({
5234
- appId: z65.string().min(1)
5688
+ import { z as z71 } from "zod";
5689
+ var DeviceAllowlistItemSchema = z71.object({
5690
+ device_id: z71.string(),
5691
+ node_name: z71.string().nullable(),
5692
+ cvm_ids: z71.array(z71.number()),
5693
+ allowed_onchain: z71.boolean(),
5694
+ status: z71.string()
5695
+ });
5696
+ var DeviceAllowlistResponseSchema = z71.object({
5697
+ is_onchain_kms: z71.boolean(),
5698
+ allow_any_device: z71.boolean().nullable().optional(),
5699
+ chain_id: z71.number().nullable().optional(),
5700
+ app_contract_address: z71.string().nullable().optional(),
5701
+ devices: z71.array(DeviceAllowlistItemSchema).optional().default([])
5702
+ });
5703
+ var GetAppDeviceAllowlistRequestSchema = z71.object({
5704
+ appId: z71.string().min(1)
5235
5705
  }).strict();
5236
5706
  async function getAppDeviceAllowlist(client, request) {
5237
5707
  const { appId } = GetAppDeviceAllowlistRequestSchema.parse(request);
@@ -5257,11 +5727,11 @@ async function safeGetAppDeviceAllowlist(client, request) {
5257
5727
  }
5258
5728
 
5259
5729
  // src/actions/apps/get_app_revisions.ts
5260
- import { z as z66 } from "zod";
5261
- var GetAppRevisionsRequestSchema = z66.object({
5262
- appId: z66.string().min(1),
5263
- page: z66.number().int().min(1).optional(),
5264
- page_size: z66.number().int().min(1).max(1e3).optional()
5730
+ import { z as z72 } from "zod";
5731
+ var GetAppRevisionsRequestSchema = z72.object({
5732
+ appId: z72.string().min(1),
5733
+ page: z72.number().int().min(1).optional(),
5734
+ page_size: z72.number().int().min(1).max(1e3).optional()
5265
5735
  }).strict();
5266
5736
  async function getAppRevisions(client, request) {
5267
5737
  const { appId, ...params } = GetAppRevisionsRequestSchema.parse(request);
@@ -5287,11 +5757,11 @@ async function safeGetAppRevisions(client, request) {
5287
5757
  }
5288
5758
 
5289
5759
  // src/actions/apps/get_app_revision_detail.ts
5290
- import { z as z67 } from "zod";
5291
- var GetAppRevisionDetailRequestSchema = z67.object({
5292
- appId: z67.string().min(1),
5293
- revisionId: z67.string().min(1),
5294
- rawComposeFile: z67.boolean().optional()
5760
+ import { z as z73 } from "zod";
5761
+ var GetAppRevisionDetailRequestSchema = z73.object({
5762
+ appId: z73.string().min(1),
5763
+ revisionId: z73.string().min(1),
5764
+ rawComposeFile: z73.boolean().optional()
5295
5765
  }).strict();
5296
5766
  async function getAppRevisionDetail(client, request) {
5297
5767
  const { appId, revisionId, rawComposeFile } = GetAppRevisionDetailRequestSchema.parse(request);
@@ -5318,15 +5788,15 @@ async function safeGetAppRevisionDetail(client, request) {
5318
5788
  }
5319
5789
 
5320
5790
  // src/actions/apps/get_app_filter_options.ts
5321
- import { z as z68 } from "zod";
5322
- var AppFilterOptionsSchema = z68.object({
5323
- statuses: z68.array(z68.string()),
5324
- image_versions: z68.array(z68.string()),
5325
- instance_types: z68.array(z68.string()),
5326
- kms_slugs: z68.array(z68.string()),
5327
- kms_types: z68.array(z68.string()),
5328
- regions: z68.array(z68.string()),
5329
- nodes: z68.array(z68.string())
5791
+ import { z as z74 } from "zod";
5792
+ var AppFilterOptionsSchema = z74.object({
5793
+ statuses: z74.array(z74.string()),
5794
+ image_versions: z74.array(z74.string()),
5795
+ instance_types: z74.array(z74.string()),
5796
+ kms_slugs: z74.array(z74.string()),
5797
+ kms_types: z74.array(z74.string()),
5798
+ regions: z74.array(z74.string()),
5799
+ nodes: z74.array(z74.string())
5330
5800
  });
5331
5801
  async function getAppFilterOptions(client) {
5332
5802
  const response = await client.get("/apps/filter-options");
@@ -5351,47 +5821,47 @@ async function safeGetAppFilterOptions(client) {
5351
5821
  }
5352
5822
 
5353
5823
  // src/actions/apps/get_app_attestation.ts
5354
- import { z as z69 } from "zod";
5355
- var KmsInfoSchema2 = z69.object({
5356
- contract_address: z69.string(),
5357
- chain_id: z69.string().nullable(),
5358
- version: z69.string(),
5359
- url: z69.string(),
5360
- gateway_app_id: z69.string().nullable(),
5361
- gateway_app_url: z69.string(),
5362
- kms_type: z69.string()
5363
- });
5364
- var GuestAgentInfoSchema = z69.object({
5365
- app_id: z69.string().optional(),
5366
- instance_id: z69.string().optional(),
5367
- app_name: z69.string().optional(),
5368
- device_id: z69.string().optional()
5824
+ import { z as z75 } from "zod";
5825
+ var KmsInfoSchema2 = z75.object({
5826
+ contract_address: z75.string(),
5827
+ chain_id: z75.string().nullable(),
5828
+ version: z75.string(),
5829
+ url: z75.string(),
5830
+ gateway_app_id: z75.string().nullable(),
5831
+ gateway_app_url: z75.string(),
5832
+ kms_type: z75.string()
5833
+ });
5834
+ var GuestAgentInfoSchema = z75.object({
5835
+ app_id: z75.string().optional(),
5836
+ instance_id: z75.string().optional(),
5837
+ app_name: z75.string().optional(),
5838
+ device_id: z75.string().optional()
5369
5839
  }).passthrough().nullable();
5370
- var AppAttestationInstanceSchema = z69.object({
5371
- vm_uuid: z69.string().nullable().optional(),
5372
- name: z69.string().optional(),
5373
- instance_id: z69.string().nullable().optional(),
5374
- status: z69.string().optional(),
5375
- image_version: z69.string().nullable().optional(),
5376
- quote: z69.string().nullable().optional(),
5377
- ppid: z69.string().optional(),
5378
- device_id: z69.string().optional(),
5840
+ var AppAttestationInstanceSchema = z75.object({
5841
+ vm_uuid: z75.string().nullable().optional(),
5842
+ name: z75.string().optional(),
5843
+ instance_id: z75.string().nullable().optional(),
5844
+ status: z75.string().optional(),
5845
+ image_version: z75.string().nullable().optional(),
5846
+ quote: z75.string().nullable().optional(),
5847
+ ppid: z75.string().optional(),
5848
+ device_id: z75.string().optional(),
5379
5849
  tcb_info: TcbInfoSchema.nullable().optional(),
5380
- app_certificates: z69.array(CertificateSchema).nullable().optional(),
5381
- compose_file: z69.string().nullable().optional(),
5382
- error: z69.string().nullable().optional()
5850
+ app_certificates: z75.array(CertificateSchema).nullable().optional(),
5851
+ compose_file: z75.string().nullable().optional(),
5852
+ error: z75.string().nullable().optional()
5383
5853
  });
5384
- var AppAttestationResponseSchema = z69.object({
5385
- app_id: z69.string(),
5386
- contract_address: z69.string(),
5854
+ var AppAttestationResponseSchema = z75.object({
5855
+ app_id: z75.string(),
5856
+ contract_address: z75.string(),
5387
5857
  kms_info: KmsInfoSchema2,
5388
- instances: z69.array(AppAttestationInstanceSchema),
5858
+ instances: z75.array(AppAttestationInstanceSchema),
5389
5859
  kms_guest_agent_info: GuestAgentInfoSchema,
5390
5860
  gateway_guest_agent_info: GuestAgentInfoSchema,
5391
- qemu_version: z69.string().nullable()
5861
+ qemu_version: z75.string().nullable()
5392
5862
  });
5393
- var GetAppAttestationRequestSchema = z69.object({
5394
- appId: z69.string().min(1)
5863
+ var GetAppAttestationRequestSchema = z75.object({
5864
+ appId: z75.string().min(1)
5395
5865
  }).strict();
5396
5866
  var { action: getAppAttestation, safeAction: safeGetAppAttestation } = defineAction(AppAttestationResponseSchema, async (client, request) => {
5397
5867
  const { appId } = GetAppAttestationRequestSchema.parse(request);
@@ -5442,6 +5912,7 @@ export {
5442
5912
  ApiErrorSchema,
5443
5913
  AppAttestationInstanceSchema,
5444
5914
  AppAttestationResponseSchema,
5915
+ AppCvmsBatchIsAllowedResponseSchema,
5445
5916
  AppFilterOptionsSchema,
5446
5917
  AppProfileSchema,
5447
5918
  AppRevisionDetailResponseSchema,
@@ -5455,10 +5926,15 @@ export {
5455
5926
  CertificateIssuerSchema,
5456
5927
  CertificateSchema,
5457
5928
  CertificateSubjectSchema,
5929
+ CheckAppCvmsIsAllowedRequestSchema,
5930
+ CheckAppIsAllowedRequestSchema,
5931
+ CheckCvmIsAllowedRequestSchema,
5458
5932
  CommitCvmComposeFileUpdateRequestSchema,
5459
5933
  CommitCvmComposeFileUpdateSchema,
5460
5934
  CommitCvmProvisionRequestSchema,
5461
5935
  CommitCvmProvisionSchema,
5936
+ CommitCvmUpdateRequestSchema,
5937
+ ConfirmCvmPatchRequestSchema,
5462
5938
  CreateSshKeyRequestSchema,
5463
5939
  CreditsInfoSchema,
5464
5940
  CurrentUserV20251028Schema as CurrentUserSchema,
@@ -5500,6 +5976,7 @@ export {
5500
5976
  DstackAppMinimalResponseV20260121Schema,
5501
5977
  DstackAppWithCvmResponseV20251028Schema,
5502
5978
  DstackAppWithCvmResponseV20260121Schema,
5979
+ ErrorCodes,
5503
5980
  EventLogSchema,
5504
5981
  FamilyGroupSchema,
5505
5982
  FamilyInstanceTypesResponseSchema,
@@ -5541,6 +6018,7 @@ export {
5541
6018
  ImportGithubProfileResponseSchema,
5542
6019
  InstanceIdRefreshResultSchema,
5543
6020
  InstanceTypeSchema,
6021
+ IsAllowedResultSchema,
5544
6022
  KmsInfoSchema,
5545
6023
  KmsTypeSchema,
5546
6024
  ListFamilyInstanceTypesRequestSchema,
@@ -5564,6 +6042,8 @@ export {
5564
6042
  PaginatedCvmInfosV20251028Schema,
5565
6043
  PaginatedCvmInfosV20260121Schema,
5566
6044
  PaginationMetadataSchema,
6045
+ PatchCvmRequestSchema,
6046
+ PatchCvmResultSchema,
5567
6047
  PhalaCloudError,
5568
6048
  ProvisionCvmComposeFileUpdateRequestSchema,
5569
6049
  ProvisionCvmComposeFileUpdateResultSchema,
@@ -5617,11 +6097,18 @@ export {
5617
6097
  addNetwork,
5618
6098
  asHex,
5619
6099
  autoCreateClients,
6100
+ checkAppCvmsIsAllowed,
6101
+ checkAppIsAllowed,
5620
6102
  checkBalance,
6103
+ checkComposeHashAllowed,
6104
+ checkCvmIsAllowed,
5621
6105
  checkDeviceAllowed,
5622
6106
  checkNetworkStatus,
6107
+ checkOnChainPrerequisites,
5623
6108
  commitCvmComposeFileUpdate,
5624
6109
  commitCvmProvision,
6110
+ commitCvmUpdate,
6111
+ confirmCvmPatch,
5625
6112
  convertToHostname,
5626
6113
  createClient as createBaseClient,
5627
6114
  createClient2 as createClient,
@@ -5684,6 +6171,8 @@ export {
5684
6171
  getWorkspaceNodes,
5685
6172
  getWorkspaceQuotas,
5686
6173
  importGithubProfileSshKeys,
6174
+ isAppIdConflictError,
6175
+ isConflictError,
5687
6176
  isValidHostname,
5688
6177
  listAllInstanceTypeFamilies,
5689
6178
  listFamilyInstanceTypes,
@@ -5693,6 +6182,7 @@ export {
5693
6182
  parseApiError,
5694
6183
  parseEnv,
5695
6184
  parseEnvVars,
6185
+ patchCvm,
5696
6186
  preprocessAppCompose,
5697
6187
  provisionCvm,
5698
6188
  provisionCvmComposeFileUpdate,
@@ -5704,9 +6194,16 @@ export {
5704
6194
  restartCvm,
5705
6195
  safeAddComposeHash,
5706
6196
  safeAddDevice,
6197
+ safeCheckAppCvmsIsAllowed,
6198
+ safeCheckAppIsAllowed,
6199
+ safeCheckComposeHashAllowed,
6200
+ safeCheckCvmIsAllowed,
5707
6201
  safeCheckDeviceAllowed,
6202
+ safeCheckOnChainPrerequisites,
5708
6203
  safeCommitCvmComposeFileUpdate,
5709
6204
  safeCommitCvmProvision,
6205
+ safeCommitCvmUpdate,
6206
+ safeConfirmCvmPatch,
5710
6207
  safeCreateSshKey,
5711
6208
  safeDeleteCvm,
5712
6209
  safeDeleteSshKey,
@@ -5749,6 +6246,7 @@ export {
5749
6246
  safeListSshKeys,
5750
6247
  safeListWorkspaces,
5751
6248
  safeNextAppIds,
6249
+ safePatchCvm,
5752
6250
  safeProvisionCvm,
5753
6251
  safeProvisionCvmComposeFileUpdate,
5754
6252
  safeRefreshCvmInstanceId,