@phala/cloud 0.2.4 → 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/actions/apps/check_app_cvms_is_allowed.d.ts +164 -0
- package/dist/actions/apps/check_app_is_allowed.d.ts +109 -0
- package/dist/actions/apps/get_app_attestation.d.ts +963 -0
- package/dist/actions/apps/get_app_device_allowlist.d.ts +108 -0
- package/dist/actions/blockchains/abi/dstack_app.d.ts +131 -0
- package/dist/actions/blockchains/add_device.d.ts +62 -0
- package/dist/actions/blockchains/check_compose_hash_allowed.d.ts +43 -0
- package/dist/actions/blockchains/check_device_allowed.d.ts +44 -0
- package/dist/actions/blockchains/check_on_chain_prerequisites.d.ts +59 -0
- package/dist/actions/blockchains/get_allowed_devices.d.ts +65 -0
- package/dist/actions/blockchains/remove_device.d.ts +62 -0
- package/dist/actions/blockchains/set_allow_any_device.d.ts +62 -0
- package/dist/actions/cvms/check_cvm_is_allowed.d.ts +145 -0
- package/dist/actions/cvms/commit_cvm_provision.d.ts +19 -0
- package/dist/actions/cvms/commit_cvm_update.d.ts +100 -0
- package/dist/actions/cvms/confirm_cvm_patch.d.ts +92 -0
- package/dist/actions/cvms/get_cvm_attestation.d.ts +220 -0
- package/dist/actions/cvms/get_cvm_compose_file.d.ts +16 -0
- package/dist/actions/cvms/patch_cvm.d.ts +447 -0
- package/dist/actions/cvms/provision_cvm.d.ts +26 -1
- package/dist/actions/cvms/provision_cvm_compose_file_update.d.ts +26 -0
- package/dist/actions/cvms/refresh_cvm_instance_id.d.ts +93 -0
- package/dist/actions/cvms/refresh_cvm_instance_ids.d.ts +194 -0
- package/dist/actions/cvms/replicate_cvm.d.ts +126 -0
- package/dist/actions/cvms/restart_cvm.d.ts +2 -2
- package/dist/actions/cvms/shutdown_cvm.d.ts +2 -2
- package/dist/actions/cvms/start_cvm.d.ts +2 -2
- package/dist/actions/cvms/stop_cvm.d.ts +2 -2
- package/dist/actions/index.d.ts +22 -1
- package/dist/actions/kms/get_kms_onchain_detail.d.ts +688 -0
- package/dist/actions/os_images/get_os_images.d.ts +217 -0
- package/dist/actions/workspaces/get_workspace.d.ts +2 -0
- package/dist/actions/workspaces/list_workspaces.d.ts +18 -0
- package/dist/client.d.ts +5 -0
- package/dist/create-client.d.ts +30 -0
- package/dist/index.js +1909 -365
- package/dist/index.mjs +1843 -363
- package/dist/types/app_compose.d.ts +5 -0
- package/dist/types/app_info_v20260121.d.ts +158 -6
- package/dist/types/cvm_info.d.ts +3 -3
- package/dist/types/cvm_info_v20260121.d.ts +82 -4
- package/dist/utils/error_codes.d.ts +48 -0
- package/dist/utils/errors.d.ts +9 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/verify-webhook.d.ts +35 -0
- package/dist/webhook.d.ts +11 -0
- package/dist/webhook.js +68 -0
- package/dist/webhook.mjs +40 -0
- package/package.json +7 -2
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
|
|
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
|
-
//
|
|
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);
|
|
@@ -1066,7 +1089,8 @@ var WorkspaceResponseSchema = z7.object({
|
|
|
1066
1089
|
tier: z7.string(),
|
|
1067
1090
|
role: z7.string(),
|
|
1068
1091
|
is_default: z7.boolean(),
|
|
1069
|
-
created_at: z7.string()
|
|
1092
|
+
created_at: z7.string(),
|
|
1093
|
+
confidential_models_enabled: z7.boolean().optional()
|
|
1070
1094
|
}).passthrough();
|
|
1071
1095
|
var PaginationMetadataSchema = z7.object({
|
|
1072
1096
|
has_more: z7.boolean(),
|
|
@@ -1221,7 +1245,7 @@ var CvmOsInfoV20260121Schema = z9.object({
|
|
|
1221
1245
|
is_dev: z9.boolean().nullable().optional(),
|
|
1222
1246
|
os_image_hash: z9.string().nullable().optional()
|
|
1223
1247
|
});
|
|
1224
|
-
var
|
|
1248
|
+
var CvmKmsInfoV20260121BaseSchema = z9.object({
|
|
1225
1249
|
chain_id: z9.number().int().nullable().optional(),
|
|
1226
1250
|
dstack_kms_address: z9.string().nullable().optional(),
|
|
1227
1251
|
dstack_app_address: z9.string().nullable().optional(),
|
|
@@ -1229,6 +1253,15 @@ var CvmKmsInfoV20260121Schema = z9.object({
|
|
|
1229
1253
|
rpc_endpoint: z9.string().nullable().optional(),
|
|
1230
1254
|
encrypted_env_pubkey: z9.string().nullable().optional()
|
|
1231
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
|
+
});
|
|
1232
1265
|
var CvmProgressInfoV20260121Schema = z9.object({
|
|
1233
1266
|
target: z9.string().nullable().optional(),
|
|
1234
1267
|
started_at: z9.string().nullable().optional(),
|
|
@@ -1255,6 +1288,7 @@ var CvmInfoV20260121Schema = z9.object({
|
|
|
1255
1288
|
name: z9.string(),
|
|
1256
1289
|
app_id: z9.string().nullable().optional(),
|
|
1257
1290
|
vm_uuid: z9.string().nullable().optional(),
|
|
1291
|
+
instance_id: z9.string().nullable().optional(),
|
|
1258
1292
|
resource: CvmResourceInfoV20260121Schema,
|
|
1259
1293
|
node_info: NodeRefSchema.nullable().optional(),
|
|
1260
1294
|
os: CvmOsInfoV20260121Schema.nullable().optional(),
|
|
@@ -1271,6 +1305,7 @@ var CvmInfoV20260121Schema = z9.object({
|
|
|
1271
1305
|
public_tcbinfo: z9.boolean().optional(),
|
|
1272
1306
|
gateway_enabled: z9.boolean().optional(),
|
|
1273
1307
|
secure_time: z9.boolean().optional(),
|
|
1308
|
+
listed: z9.boolean().optional().default(false),
|
|
1274
1309
|
storage_fs: z9.string().optional(),
|
|
1275
1310
|
workspace: WorkspaceRefSchema.nullable().optional(),
|
|
1276
1311
|
creator: UserRefSchema.nullable().optional()
|
|
@@ -1495,6 +1530,7 @@ var LooseAppComposeSchema = z12.object({
|
|
|
1495
1530
|
public_logs: z12.boolean().optional(),
|
|
1496
1531
|
public_sysinfo: z12.boolean().optional(),
|
|
1497
1532
|
tproxy_enabled: z12.boolean().optional(),
|
|
1533
|
+
storage_fs: z12.enum(["ext4", "zfs"]).optional(),
|
|
1498
1534
|
pre_launch_script: z12.string().optional(),
|
|
1499
1535
|
env_pubkey: z12.string().optional(),
|
|
1500
1536
|
salt: z12.string().optional().nullable()
|
|
@@ -1551,8 +1587,9 @@ var ProvisionCvmRequestSchema = z13.object({
|
|
|
1551
1587
|
public_sysinfo: z13.boolean().optional(),
|
|
1552
1588
|
gateway_enabled: z13.boolean().optional(),
|
|
1553
1589
|
// recommended
|
|
1554
|
-
tproxy_enabled: z13.boolean().optional()
|
|
1590
|
+
tproxy_enabled: z13.boolean().optional(),
|
|
1555
1591
|
// deprecated, for compatibility
|
|
1592
|
+
storage_fs: z13.enum(["ext4", "zfs"]).optional()
|
|
1556
1593
|
}).superRefine((data, ctx) => {
|
|
1557
1594
|
validateComposePayloadSize(data.docker_compose_file, data.pre_launch_script, ctx);
|
|
1558
1595
|
}),
|
|
@@ -1740,7 +1777,8 @@ var ProvisionCvmComposeFileUpdateResultSchema = z15.object({
|
|
|
1740
1777
|
app_id: z15.string().nullable(),
|
|
1741
1778
|
device_id: z15.string().nullable(),
|
|
1742
1779
|
compose_hash: z15.string(),
|
|
1743
|
-
kms_info: KmsInfoSchema.nullable().optional()
|
|
1780
|
+
kms_info: KmsInfoSchema.nullable().optional(),
|
|
1781
|
+
compose_hash_registered: z15.boolean().optional().default(false)
|
|
1744
1782
|
}).passthrough();
|
|
1745
1783
|
var { action: provisionCvmComposeFileUpdate, safeAction: safeProvisionCvmComposeFileUpdate } = defineAction(ProvisionCvmComposeFileUpdateResultSchema, async (client, request) => {
|
|
1746
1784
|
const validatedRequest = ProvisionCvmComposeFileUpdateRequestSchema.parse(request);
|
|
@@ -1847,14 +1885,24 @@ var { action: updateCvmEnvs, safeAction: safeUpdateCvmEnvs } = defineAction(Upda
|
|
|
1847
1885
|
const detail = error.detail;
|
|
1848
1886
|
if (detail && typeof detail === "object") {
|
|
1849
1887
|
const detailObj = detail;
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
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
|
+
}
|
|
1858
1906
|
}
|
|
1859
1907
|
}
|
|
1860
1908
|
throw error;
|
|
@@ -1921,14 +1969,24 @@ var { action: updateDockerCompose, safeAction: safeUpdateDockerCompose } = defin
|
|
|
1921
1969
|
const detail = error.detail;
|
|
1922
1970
|
if (detail && typeof detail === "object") {
|
|
1923
1971
|
const detailObj = detail;
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
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
|
+
}
|
|
1932
1990
|
}
|
|
1933
1991
|
}
|
|
1934
1992
|
throw error;
|
|
@@ -1995,14 +2053,24 @@ var { action: updatePreLaunchScript, safeAction: safeUpdatePreLaunchScript } = d
|
|
|
1995
2053
|
const detail = error.detail;
|
|
1996
2054
|
if (detail && typeof detail === "object") {
|
|
1997
2055
|
const detailObj = detail;
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
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
|
+
}
|
|
2006
2074
|
}
|
|
2007
2075
|
}
|
|
2008
2076
|
throw error;
|
|
@@ -2101,7 +2169,7 @@ var VMSchema = z25.object({
|
|
|
2101
2169
|
vm_uuid: z25.string().nullable(),
|
|
2102
2170
|
instance_id: z25.string().nullable(),
|
|
2103
2171
|
app_url: z25.string().optional().nullable(),
|
|
2104
|
-
base_image: z25.string().nullable(),
|
|
2172
|
+
base_image: z25.string().optional().nullable(),
|
|
2105
2173
|
vcpu: z25.number(),
|
|
2106
2174
|
memory: z25.number(),
|
|
2107
2175
|
disk_size: z25.number(),
|
|
@@ -2519,6 +2587,66 @@ var { action: syncGithubSshKeys, safeAction: safeSyncGithubSshKeys } = defineSim
|
|
|
2519
2587
|
}
|
|
2520
2588
|
);
|
|
2521
2589
|
|
|
2590
|
+
// src/actions/os_images/get_os_images.ts
|
|
2591
|
+
import { z as z43 } from "zod";
|
|
2592
|
+
var OSImagePublicSchema = z43.object({
|
|
2593
|
+
name: z43.string(),
|
|
2594
|
+
slug: z43.string(),
|
|
2595
|
+
version: z43.string(),
|
|
2596
|
+
os_image_hash: z43.string().nullable(),
|
|
2597
|
+
is_dev: z43.boolean(),
|
|
2598
|
+
requires_gpu: z43.boolean()
|
|
2599
|
+
}).passthrough();
|
|
2600
|
+
var GetOsImagesRequestSchema = z43.object({
|
|
2601
|
+
page: z43.number().int().min(1).optional(),
|
|
2602
|
+
page_size: z43.number().int().min(1).optional(),
|
|
2603
|
+
is_dev: z43.boolean().optional()
|
|
2604
|
+
}).strict();
|
|
2605
|
+
var GetOsImagesResponseSchema = z43.object({
|
|
2606
|
+
items: z43.array(OSImagePublicSchema),
|
|
2607
|
+
total: z43.number(),
|
|
2608
|
+
page: z43.number(),
|
|
2609
|
+
page_size: z43.number(),
|
|
2610
|
+
pages: z43.number()
|
|
2611
|
+
}).passthrough();
|
|
2612
|
+
var { action: getOsImages, safeAction: safeGetOsImages } = defineAction(GetOsImagesResponseSchema, async (client, request) => {
|
|
2613
|
+
const validatedRequest = GetOsImagesRequestSchema.parse(request ?? {});
|
|
2614
|
+
return await client.get("/os-images", { params: validatedRequest });
|
|
2615
|
+
});
|
|
2616
|
+
|
|
2617
|
+
// src/actions/kms/get_kms_onchain_detail.ts
|
|
2618
|
+
import { z as z44 } from "zod";
|
|
2619
|
+
var OnChainDeviceSchema = z44.object({
|
|
2620
|
+
device_id: z44.string(),
|
|
2621
|
+
node_name: z44.string().nullable().optional(),
|
|
2622
|
+
on_chain_allowed: z44.boolean().nullable()
|
|
2623
|
+
}).passthrough();
|
|
2624
|
+
var OnChainOsImageSchema = z44.object({
|
|
2625
|
+
name: z44.string(),
|
|
2626
|
+
version: z44.string(),
|
|
2627
|
+
os_image_hash: z44.string().nullable(),
|
|
2628
|
+
on_chain_allowed: z44.boolean().nullable()
|
|
2629
|
+
}).passthrough();
|
|
2630
|
+
var OnChainKmsContractSchema = z44.object({
|
|
2631
|
+
contract_address: z44.string(),
|
|
2632
|
+
chain_id: z44.number(),
|
|
2633
|
+
chain_name: z44.string(),
|
|
2634
|
+
devices: z44.array(OnChainDeviceSchema),
|
|
2635
|
+
os_images: z44.array(OnChainOsImageSchema)
|
|
2636
|
+
}).passthrough();
|
|
2637
|
+
var GetKmsOnChainDetailResponseSchema = z44.object({
|
|
2638
|
+
chain_name: z44.string(),
|
|
2639
|
+
chain_id: z44.number(),
|
|
2640
|
+
contracts: z44.array(OnChainKmsContractSchema)
|
|
2641
|
+
}).passthrough();
|
|
2642
|
+
var GetKmsOnChainDetailRequestSchema = z44.object({
|
|
2643
|
+
chain: z44.string()
|
|
2644
|
+
}).strict();
|
|
2645
|
+
var { action: getKmsOnChainDetail, safeAction: safeGetKmsOnChainDetail } = defineAction(GetKmsOnChainDetailResponseSchema, async (client, request) => {
|
|
2646
|
+
const { chain } = GetKmsOnChainDetailRequestSchema.parse(request);
|
|
2647
|
+
return await client.get(`/kms/on-chain/${chain}`);
|
|
2648
|
+
});
|
|
2649
|
+
|
|
2522
2650
|
// src/create-client.ts
|
|
2523
2651
|
function createClient2(config = {}) {
|
|
2524
2652
|
const client = createClient(config);
|
|
@@ -2604,167 +2732,171 @@ function createClient2(config = {}) {
|
|
|
2604
2732
|
deleteSshKey,
|
|
2605
2733
|
safeDeleteSshKey,
|
|
2606
2734
|
syncGithubSshKeys,
|
|
2607
|
-
safeSyncGithubSshKeys
|
|
2735
|
+
safeSyncGithubSshKeys,
|
|
2736
|
+
getOsImages,
|
|
2737
|
+
safeGetOsImages,
|
|
2738
|
+
getKmsOnChainDetail,
|
|
2739
|
+
safeGetKmsOnChainDetail
|
|
2608
2740
|
};
|
|
2609
2741
|
return client.extend(allActions);
|
|
2610
2742
|
}
|
|
2611
2743
|
|
|
2612
2744
|
// src/types/app_info_v20251028.ts
|
|
2613
|
-
import { z as
|
|
2614
|
-
var CvmBasicInfoV20251028Schema =
|
|
2615
|
-
vm_uuid:
|
|
2616
|
-
app_id:
|
|
2617
|
-
name:
|
|
2618
|
-
status:
|
|
2619
|
-
vcpu:
|
|
2620
|
-
memory:
|
|
2621
|
-
disk_size:
|
|
2622
|
-
teepod_id:
|
|
2623
|
-
teepod_name:
|
|
2624
|
-
region_identifier:
|
|
2625
|
-
kms_type:
|
|
2626
|
-
instance_type:
|
|
2627
|
-
listed:
|
|
2628
|
-
base_image:
|
|
2629
|
-
kms_slug:
|
|
2630
|
-
kms_id:
|
|
2631
|
-
instance_id:
|
|
2745
|
+
import { z as z45 } from "zod";
|
|
2746
|
+
var CvmBasicInfoV20251028Schema = z45.object({
|
|
2747
|
+
vm_uuid: z45.string().nullable(),
|
|
2748
|
+
app_id: z45.string(),
|
|
2749
|
+
name: z45.string().default(""),
|
|
2750
|
+
status: z45.string(),
|
|
2751
|
+
vcpu: z45.number().int(),
|
|
2752
|
+
memory: z45.number().int(),
|
|
2753
|
+
disk_size: z45.number().int(),
|
|
2754
|
+
teepod_id: z45.number().int(),
|
|
2755
|
+
teepod_name: z45.string(),
|
|
2756
|
+
region_identifier: z45.string().nullable().optional(),
|
|
2757
|
+
kms_type: z45.string().nullable().optional(),
|
|
2758
|
+
instance_type: z45.string().nullable().optional(),
|
|
2759
|
+
listed: z45.boolean().nullable().optional(),
|
|
2760
|
+
base_image: z45.string().nullable().optional(),
|
|
2761
|
+
kms_slug: z45.string().nullable().optional(),
|
|
2762
|
+
kms_id: z45.string().nullable().optional(),
|
|
2763
|
+
instance_id: z45.string().nullable().optional(),
|
|
2632
2764
|
machine_info: MachineInfoV20251028Schema.nullable().optional(),
|
|
2633
|
-
updated_at:
|
|
2765
|
+
updated_at: z45.string().nullable().optional()
|
|
2634
2766
|
});
|
|
2635
|
-
var AppProfileSchema =
|
|
2636
|
-
display_name:
|
|
2637
|
-
avatar_url:
|
|
2638
|
-
description:
|
|
2639
|
-
custom_domain:
|
|
2767
|
+
var AppProfileSchema = z45.object({
|
|
2768
|
+
display_name: z45.string().nullable().optional(),
|
|
2769
|
+
avatar_url: z45.string().nullable().optional(),
|
|
2770
|
+
description: z45.string().nullable().optional(),
|
|
2771
|
+
custom_domain: z45.string().nullable().optional()
|
|
2640
2772
|
});
|
|
2641
|
-
var DstackAppFullResponseV20251028Schema =
|
|
2642
|
-
id:
|
|
2643
|
-
name:
|
|
2644
|
-
app_id:
|
|
2645
|
-
app_provision_type:
|
|
2646
|
-
app_icon_url:
|
|
2647
|
-
created_at:
|
|
2648
|
-
kms_type:
|
|
2773
|
+
var DstackAppFullResponseV20251028Schema = z45.object({
|
|
2774
|
+
id: z45.string(),
|
|
2775
|
+
name: z45.string(),
|
|
2776
|
+
app_id: z45.string(),
|
|
2777
|
+
app_provision_type: z45.string().nullable().optional(),
|
|
2778
|
+
app_icon_url: z45.string().nullable().optional(),
|
|
2779
|
+
created_at: z45.string(),
|
|
2780
|
+
kms_type: z45.string(),
|
|
2649
2781
|
profile: AppProfileSchema.nullable().optional(),
|
|
2650
2782
|
current_cvm: CvmBasicInfoV20251028Schema.nullable().optional(),
|
|
2651
|
-
cvms:
|
|
2652
|
-
cvm_count:
|
|
2653
|
-
});
|
|
2654
|
-
var DstackAppMinimalResponseV20251028Schema =
|
|
2655
|
-
id:
|
|
2656
|
-
app_id:
|
|
2657
|
-
name:
|
|
2658
|
-
app_provision_type:
|
|
2659
|
-
app_icon_url:
|
|
2660
|
-
created_at:
|
|
2661
|
-
kms_type:
|
|
2662
|
-
current_cvm:
|
|
2663
|
-
cvms:
|
|
2664
|
-
cvm_count:
|
|
2665
|
-
});
|
|
2666
|
-
var DstackAppWithCvmResponseV20251028Schema =
|
|
2783
|
+
cvms: z45.array(CvmBasicInfoV20251028Schema).default([]),
|
|
2784
|
+
cvm_count: z45.number().int().default(0)
|
|
2785
|
+
});
|
|
2786
|
+
var DstackAppMinimalResponseV20251028Schema = z45.object({
|
|
2787
|
+
id: z45.null().optional(),
|
|
2788
|
+
app_id: z45.string(),
|
|
2789
|
+
name: z45.null().optional(),
|
|
2790
|
+
app_provision_type: z45.null().optional(),
|
|
2791
|
+
app_icon_url: z45.null().optional(),
|
|
2792
|
+
created_at: z45.null().optional(),
|
|
2793
|
+
kms_type: z45.null().optional(),
|
|
2794
|
+
current_cvm: z45.null().optional(),
|
|
2795
|
+
cvms: z45.null().optional(),
|
|
2796
|
+
cvm_count: z45.null().optional()
|
|
2797
|
+
});
|
|
2798
|
+
var DstackAppWithCvmResponseV20251028Schema = z45.union([
|
|
2667
2799
|
DstackAppFullResponseV20251028Schema,
|
|
2668
2800
|
DstackAppMinimalResponseV20251028Schema
|
|
2669
2801
|
]);
|
|
2670
|
-
var DstackAppListResponseV20251028Schema =
|
|
2671
|
-
dstack_apps:
|
|
2672
|
-
page:
|
|
2673
|
-
page_size:
|
|
2674
|
-
total:
|
|
2675
|
-
total_pages:
|
|
2802
|
+
var DstackAppListResponseV20251028Schema = z45.object({
|
|
2803
|
+
dstack_apps: z45.array(DstackAppWithCvmResponseV20251028Schema),
|
|
2804
|
+
page: z45.number().int(),
|
|
2805
|
+
page_size: z45.number().int(),
|
|
2806
|
+
total: z45.number().int(),
|
|
2807
|
+
total_pages: z45.number().int()
|
|
2676
2808
|
});
|
|
2677
2809
|
|
|
2678
2810
|
// src/types/app_info_v20260121.ts
|
|
2679
|
-
import { z as
|
|
2680
|
-
var DstackAppFullResponseV20260121Schema =
|
|
2681
|
-
id:
|
|
2682
|
-
name:
|
|
2683
|
-
app_id:
|
|
2684
|
-
app_provision_type:
|
|
2685
|
-
app_icon_url:
|
|
2686
|
-
created_at:
|
|
2687
|
-
kms_type:
|
|
2688
|
-
profile:
|
|
2689
|
-
display_name:
|
|
2690
|
-
avatar_url:
|
|
2691
|
-
description:
|
|
2692
|
-
custom_domain:
|
|
2811
|
+
import { z as z46 } from "zod";
|
|
2812
|
+
var DstackAppFullResponseV20260121Schema = z46.object({
|
|
2813
|
+
id: z46.string(),
|
|
2814
|
+
name: z46.string(),
|
|
2815
|
+
app_id: z46.string(),
|
|
2816
|
+
app_provision_type: z46.string().nullable().optional(),
|
|
2817
|
+
app_icon_url: z46.string().nullable().optional(),
|
|
2818
|
+
created_at: z46.string(),
|
|
2819
|
+
kms_type: z46.string(),
|
|
2820
|
+
profile: z46.object({
|
|
2821
|
+
display_name: z46.string().nullable().optional(),
|
|
2822
|
+
avatar_url: z46.string().nullable().optional(),
|
|
2823
|
+
description: z46.string().nullable().optional(),
|
|
2824
|
+
custom_domain: z46.string().nullable().optional()
|
|
2693
2825
|
}).nullable().optional(),
|
|
2694
2826
|
current_cvm: CvmInfoV20260121Schema.nullable().optional(),
|
|
2695
|
-
cvms:
|
|
2696
|
-
cvm_count:
|
|
2697
|
-
});
|
|
2698
|
-
var DstackAppMinimalResponseV20260121Schema =
|
|
2699
|
-
id:
|
|
2700
|
-
app_id:
|
|
2701
|
-
name:
|
|
2702
|
-
app_provision_type:
|
|
2703
|
-
app_icon_url:
|
|
2704
|
-
created_at:
|
|
2705
|
-
kms_type:
|
|
2706
|
-
current_cvm:
|
|
2707
|
-
cvms:
|
|
2708
|
-
cvm_count:
|
|
2709
|
-
});
|
|
2710
|
-
var DstackAppWithCvmResponseV20260121Schema =
|
|
2827
|
+
cvms: z46.array(CvmInfoV20260121Schema).default([]),
|
|
2828
|
+
cvm_count: z46.number().int().default(0)
|
|
2829
|
+
});
|
|
2830
|
+
var DstackAppMinimalResponseV20260121Schema = z46.object({
|
|
2831
|
+
id: z46.null().optional(),
|
|
2832
|
+
app_id: z46.string(),
|
|
2833
|
+
name: z46.null().optional(),
|
|
2834
|
+
app_provision_type: z46.null().optional(),
|
|
2835
|
+
app_icon_url: z46.null().optional(),
|
|
2836
|
+
created_at: z46.null().optional(),
|
|
2837
|
+
kms_type: z46.null().optional(),
|
|
2838
|
+
current_cvm: z46.null().optional(),
|
|
2839
|
+
cvms: z46.null().optional(),
|
|
2840
|
+
cvm_count: z46.null().optional()
|
|
2841
|
+
});
|
|
2842
|
+
var DstackAppWithCvmResponseV20260121Schema = z46.union([
|
|
2711
2843
|
DstackAppFullResponseV20260121Schema,
|
|
2712
2844
|
DstackAppMinimalResponseV20260121Schema
|
|
2713
2845
|
]);
|
|
2714
|
-
var DstackAppListResponseV20260121Schema =
|
|
2715
|
-
dstack_apps:
|
|
2716
|
-
page:
|
|
2717
|
-
page_size:
|
|
2718
|
-
total:
|
|
2719
|
-
total_pages:
|
|
2846
|
+
var DstackAppListResponseV20260121Schema = z46.object({
|
|
2847
|
+
dstack_apps: z46.array(DstackAppWithCvmResponseV20260121Schema),
|
|
2848
|
+
page: z46.number().int(),
|
|
2849
|
+
page_size: z46.number().int(),
|
|
2850
|
+
total: z46.number().int(),
|
|
2851
|
+
total_pages: z46.number().int()
|
|
2720
2852
|
});
|
|
2721
2853
|
|
|
2722
2854
|
// src/types/app_revision.ts
|
|
2723
|
-
import { z as
|
|
2724
|
-
var CvmRefSchema =
|
|
2725
|
-
object_type:
|
|
2726
|
-
id:
|
|
2727
|
-
name:
|
|
2728
|
-
app_id:
|
|
2729
|
-
vm_uuid:
|
|
2730
|
-
});
|
|
2731
|
-
var AppRevisionResponseSchema =
|
|
2732
|
-
revision_id:
|
|
2733
|
-
app_id:
|
|
2734
|
-
vm_uuid:
|
|
2735
|
-
compose_hash:
|
|
2736
|
-
created_at:
|
|
2737
|
-
trace_id:
|
|
2738
|
-
operation_type:
|
|
2855
|
+
import { z as z47 } from "zod";
|
|
2856
|
+
var CvmRefSchema = z47.object({
|
|
2857
|
+
object_type: z47.literal("cvm"),
|
|
2858
|
+
id: z47.string().nullable().optional(),
|
|
2859
|
+
name: z47.string().nullable().optional(),
|
|
2860
|
+
app_id: z47.string().nullable().optional(),
|
|
2861
|
+
vm_uuid: z47.string().nullable().optional()
|
|
2862
|
+
});
|
|
2863
|
+
var AppRevisionResponseSchema = z47.object({
|
|
2864
|
+
revision_id: z47.string(),
|
|
2865
|
+
app_id: z47.string(),
|
|
2866
|
+
vm_uuid: z47.string(),
|
|
2867
|
+
compose_hash: z47.string(),
|
|
2868
|
+
created_at: z47.string(),
|
|
2869
|
+
trace_id: z47.string().nullable().optional(),
|
|
2870
|
+
operation_type: z47.string(),
|
|
2739
2871
|
triggered_by: UserRefSchema.nullable().optional(),
|
|
2740
2872
|
cvm: CvmRefSchema.nullable().optional(),
|
|
2741
2873
|
workspace: WorkspaceRefSchema.nullable().optional()
|
|
2742
2874
|
});
|
|
2743
|
-
var AppRevisionDetailResponseSchema =
|
|
2744
|
-
revision_id:
|
|
2745
|
-
app_id:
|
|
2746
|
-
vm_uuid:
|
|
2747
|
-
compose_hash:
|
|
2748
|
-
compose_file:
|
|
2749
|
-
encrypted_env:
|
|
2750
|
-
user_config:
|
|
2751
|
-
created_at:
|
|
2752
|
-
trace_id:
|
|
2753
|
-
operation_type:
|
|
2875
|
+
var AppRevisionDetailResponseSchema = z47.object({
|
|
2876
|
+
revision_id: z47.string(),
|
|
2877
|
+
app_id: z47.string(),
|
|
2878
|
+
vm_uuid: z47.string(),
|
|
2879
|
+
compose_hash: z47.string(),
|
|
2880
|
+
compose_file: z47.union([z47.record(z47.any()), z47.string()]).nullable().optional(),
|
|
2881
|
+
encrypted_env: z47.string(),
|
|
2882
|
+
user_config: z47.string(),
|
|
2883
|
+
created_at: z47.string(),
|
|
2884
|
+
trace_id: z47.string().nullable().optional(),
|
|
2885
|
+
operation_type: z47.string(),
|
|
2754
2886
|
triggered_by: UserRefSchema.nullable().optional(),
|
|
2755
2887
|
cvm: CvmRefSchema.nullable().optional(),
|
|
2756
2888
|
workspace: WorkspaceRefSchema.nullable().optional()
|
|
2757
2889
|
});
|
|
2758
|
-
var AppRevisionsResponseSchema =
|
|
2759
|
-
revisions:
|
|
2760
|
-
total:
|
|
2761
|
-
page:
|
|
2762
|
-
page_size:
|
|
2763
|
-
total_pages:
|
|
2890
|
+
var AppRevisionsResponseSchema = z47.object({
|
|
2891
|
+
revisions: z47.array(AppRevisionResponseSchema),
|
|
2892
|
+
total: z47.number().int(),
|
|
2893
|
+
page: z47.number().int(),
|
|
2894
|
+
page_size: z47.number().int(),
|
|
2895
|
+
total_pages: z47.number().int()
|
|
2764
2896
|
});
|
|
2765
2897
|
|
|
2766
2898
|
// src/actions/blockchains/deploy_app_auth.ts
|
|
2767
|
-
import { z as
|
|
2899
|
+
import { z as z48 } from "zod";
|
|
2768
2900
|
import {
|
|
2769
2901
|
createPublicClient as createPublicClient2,
|
|
2770
2902
|
createWalletClient as createWalletClient2,
|
|
@@ -2790,6 +2922,51 @@ function asHex(value) {
|
|
|
2790
2922
|
throw new Error(`Invalid hex value: ${value}`);
|
|
2791
2923
|
}
|
|
2792
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
|
+
|
|
2793
2970
|
// src/utils/network.ts
|
|
2794
2971
|
var NetworkError = class extends Error {
|
|
2795
2972
|
constructor(message, code, details) {
|
|
@@ -3425,25 +3602,25 @@ var kmsAuthAbi = [
|
|
|
3425
3602
|
anonymous: false
|
|
3426
3603
|
}
|
|
3427
3604
|
];
|
|
3428
|
-
var DeployAppAuthRequestBaseSchema =
|
|
3605
|
+
var DeployAppAuthRequestBaseSchema = z48.object({
|
|
3429
3606
|
// Chain configuration (conditionally required)
|
|
3430
|
-
chain:
|
|
3431
|
-
rpcUrl:
|
|
3607
|
+
chain: z48.unknown().optional(),
|
|
3608
|
+
rpcUrl: z48.string().optional(),
|
|
3432
3609
|
// Contract configuration (required)
|
|
3433
|
-
kmsContractAddress:
|
|
3610
|
+
kmsContractAddress: z48.string(),
|
|
3434
3611
|
// Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
|
|
3435
|
-
privateKey:
|
|
3436
|
-
walletClient:
|
|
3612
|
+
privateKey: z48.string().optional(),
|
|
3613
|
+
walletClient: z48.unknown().optional(),
|
|
3437
3614
|
// Public client (optional, will create default if not provided)
|
|
3438
|
-
publicClient:
|
|
3615
|
+
publicClient: z48.unknown().optional(),
|
|
3439
3616
|
// App configuration (optional)
|
|
3440
|
-
allowAnyDevice:
|
|
3441
|
-
deviceId:
|
|
3442
|
-
composeHash:
|
|
3443
|
-
disableUpgrades:
|
|
3617
|
+
allowAnyDevice: z48.boolean().optional().default(false),
|
|
3618
|
+
deviceId: z48.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
|
|
3619
|
+
composeHash: z48.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
|
|
3620
|
+
disableUpgrades: z48.boolean().optional().default(false),
|
|
3444
3621
|
// Validation configuration (optional)
|
|
3445
|
-
skipPrerequisiteChecks:
|
|
3446
|
-
minBalance:
|
|
3622
|
+
skipPrerequisiteChecks: z48.boolean().optional().default(false),
|
|
3623
|
+
minBalance: z48.string().optional()
|
|
3447
3624
|
// ETH amount as string, e.g., "0.01"
|
|
3448
3625
|
}).passthrough();
|
|
3449
3626
|
var DeployAppAuthRequestSchema = DeployAppAuthRequestBaseSchema.refine(
|
|
@@ -3471,13 +3648,13 @@ var DeployAppAuthRequestSchema = DeployAppAuthRequestBaseSchema.refine(
|
|
|
3471
3648
|
path: ["chain"]
|
|
3472
3649
|
}
|
|
3473
3650
|
);
|
|
3474
|
-
var DeployAppAuthSchema =
|
|
3475
|
-
appId:
|
|
3476
|
-
appAuthAddress:
|
|
3477
|
-
deployer:
|
|
3478
|
-
transactionHash:
|
|
3479
|
-
blockNumber:
|
|
3480
|
-
gasUsed:
|
|
3651
|
+
var DeployAppAuthSchema = z48.object({
|
|
3652
|
+
appId: z48.string(),
|
|
3653
|
+
appAuthAddress: z48.string(),
|
|
3654
|
+
deployer: z48.string(),
|
|
3655
|
+
transactionHash: z48.string(),
|
|
3656
|
+
blockNumber: z48.bigint().optional(),
|
|
3657
|
+
gasUsed: z48.bigint().optional()
|
|
3481
3658
|
}).passthrough();
|
|
3482
3659
|
function parseDeploymentResult(receipt, deployer, kmsContractAddress) {
|
|
3483
3660
|
try {
|
|
@@ -3723,7 +3900,7 @@ async function safeDeployAppAuth(request, parameters) {
|
|
|
3723
3900
|
}
|
|
3724
3901
|
|
|
3725
3902
|
// src/actions/blockchains/add_compose_hash.ts
|
|
3726
|
-
import { z as
|
|
3903
|
+
import { z as z49 } from "zod";
|
|
3727
3904
|
import {
|
|
3728
3905
|
createPublicClient as createPublicClient3,
|
|
3729
3906
|
createWalletClient as createWalletClient3,
|
|
@@ -3747,29 +3924,29 @@ var appAuthAbi = [
|
|
|
3747
3924
|
anonymous: false
|
|
3748
3925
|
}
|
|
3749
3926
|
];
|
|
3750
|
-
var AddComposeHashRequestSchema =
|
|
3927
|
+
var AddComposeHashRequestSchema = z49.object({
|
|
3751
3928
|
// Chain configuration (conditionally required)
|
|
3752
|
-
chain:
|
|
3753
|
-
rpcUrl:
|
|
3754
|
-
appId:
|
|
3755
|
-
composeHash:
|
|
3929
|
+
chain: z49.unknown().optional(),
|
|
3930
|
+
rpcUrl: z49.string().optional(),
|
|
3931
|
+
appId: z49.string(),
|
|
3932
|
+
composeHash: z49.string(),
|
|
3756
3933
|
// Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
|
|
3757
|
-
privateKey:
|
|
3758
|
-
walletClient:
|
|
3934
|
+
privateKey: z49.string().optional(),
|
|
3935
|
+
walletClient: z49.unknown().optional(),
|
|
3759
3936
|
// Public client (optional, will create default if not provided)
|
|
3760
|
-
publicClient:
|
|
3937
|
+
publicClient: z49.unknown().optional(),
|
|
3761
3938
|
// Validation configuration (optional)
|
|
3762
|
-
skipPrerequisiteChecks:
|
|
3763
|
-
minBalance:
|
|
3939
|
+
skipPrerequisiteChecks: z49.boolean().optional().default(false),
|
|
3940
|
+
minBalance: z49.string().optional(),
|
|
3764
3941
|
// ETH amount as string, e.g., "0.01"
|
|
3765
3942
|
// Transaction control options
|
|
3766
|
-
timeout:
|
|
3767
|
-
retryOptions:
|
|
3768
|
-
signal:
|
|
3943
|
+
timeout: z49.number().optional().default(12e4),
|
|
3944
|
+
retryOptions: z49.unknown().optional(),
|
|
3945
|
+
signal: z49.unknown().optional(),
|
|
3769
3946
|
// Progress callbacks
|
|
3770
|
-
onTransactionStateChange:
|
|
3771
|
-
onTransactionSubmitted:
|
|
3772
|
-
onTransactionConfirmed:
|
|
3947
|
+
onTransactionStateChange: z49.function().optional(),
|
|
3948
|
+
onTransactionSubmitted: z49.function().optional(),
|
|
3949
|
+
onTransactionConfirmed: z49.function().optional()
|
|
3773
3950
|
}).passthrough().refine(
|
|
3774
3951
|
(data) => {
|
|
3775
3952
|
const hasPrivateKey = !!data.privateKey;
|
|
@@ -3793,12 +3970,12 @@ var AddComposeHashRequestSchema = z47.object({
|
|
|
3793
3970
|
path: ["chain"]
|
|
3794
3971
|
}
|
|
3795
3972
|
);
|
|
3796
|
-
var AddComposeHashSchema =
|
|
3797
|
-
composeHash:
|
|
3798
|
-
appId:
|
|
3799
|
-
transactionHash:
|
|
3800
|
-
blockNumber:
|
|
3801
|
-
gasUsed:
|
|
3973
|
+
var AddComposeHashSchema = z49.object({
|
|
3974
|
+
composeHash: z49.string(),
|
|
3975
|
+
appId: z49.string(),
|
|
3976
|
+
transactionHash: z49.string(),
|
|
3977
|
+
blockNumber: z49.bigint().optional(),
|
|
3978
|
+
gasUsed: z49.bigint().optional()
|
|
3802
3979
|
}).passthrough();
|
|
3803
3980
|
function parseComposeHashResult(receipt, composeHash, appAuthAddress, appId) {
|
|
3804
3981
|
console.log(receipt.logs);
|
|
@@ -3928,6 +4105,24 @@ async function addComposeHash(request, parameters) {
|
|
|
3928
4105
|
);
|
|
3929
4106
|
}
|
|
3930
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
|
+
}
|
|
3931
4126
|
const addComposeHashOperation = async (clients) => {
|
|
3932
4127
|
const hash = await clients.walletClient.writeContract({
|
|
3933
4128
|
address: appAuthAddress,
|
|
@@ -3989,100 +4184,950 @@ async function safeAddComposeHash(request, parameters) {
|
|
|
3989
4184
|
}
|
|
3990
4185
|
}
|
|
3991
4186
|
|
|
3992
|
-
// src/actions/
|
|
3993
|
-
import { z as
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
pages: z48.number()
|
|
4002
|
-
}).passthrough();
|
|
4003
|
-
var { action: getWorkspaceNodes, safeAction: safeGetWorkspaceNodes } = defineAction(GetWorkspaceNodesSchema, async (client, request) => {
|
|
4004
|
-
const { teamSlug, page, pageSize } = request;
|
|
4005
|
-
const queryParams = new URLSearchParams();
|
|
4006
|
-
if (page !== void 0) queryParams.append("page", page.toString());
|
|
4007
|
-
if (pageSize !== void 0) queryParams.append("page_size", pageSize.toString());
|
|
4008
|
-
const url = queryParams.toString() ? `/workspaces/${teamSlug}/nodes?${queryParams.toString()}` : `/workspaces/${teamSlug}/nodes`;
|
|
4009
|
-
return await client.get(url);
|
|
4010
|
-
});
|
|
4187
|
+
// src/actions/blockchains/add_device.ts
|
|
4188
|
+
import { z as z50 } from "zod";
|
|
4189
|
+
import {
|
|
4190
|
+
createPublicClient as createPublicClient4,
|
|
4191
|
+
createWalletClient as createWalletClient4,
|
|
4192
|
+
http as http4,
|
|
4193
|
+
parseEther as parseEther3
|
|
4194
|
+
} from "viem";
|
|
4195
|
+
import { privateKeyToAccount as privateKeyToAccount4 } from "viem/accounts";
|
|
4011
4196
|
|
|
4012
|
-
// src/actions/
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
}
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
}
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4197
|
+
// src/actions/blockchains/abi/dstack_app.ts
|
|
4198
|
+
var dstackAppAbi = [
|
|
4199
|
+
// ── Write functions ──────────────────────────────────────────────
|
|
4200
|
+
{
|
|
4201
|
+
inputs: [{ internalType: "bytes32", name: "deviceId", type: "bytes32" }],
|
|
4202
|
+
name: "addDevice",
|
|
4203
|
+
outputs: [],
|
|
4204
|
+
stateMutability: "nonpayable",
|
|
4205
|
+
type: "function"
|
|
4206
|
+
},
|
|
4207
|
+
{
|
|
4208
|
+
inputs: [{ internalType: "bytes32", name: "deviceId", type: "bytes32" }],
|
|
4209
|
+
name: "removeDevice",
|
|
4210
|
+
outputs: [],
|
|
4211
|
+
stateMutability: "nonpayable",
|
|
4212
|
+
type: "function"
|
|
4213
|
+
},
|
|
4214
|
+
{
|
|
4215
|
+
inputs: [{ internalType: "bool", name: "_allowAnyDevice", type: "bool" }],
|
|
4216
|
+
name: "setAllowAnyDevice",
|
|
4217
|
+
outputs: [],
|
|
4218
|
+
stateMutability: "nonpayable",
|
|
4219
|
+
type: "function"
|
|
4220
|
+
},
|
|
4221
|
+
// ── Read functions ───────────────────────────────────────────────
|
|
4222
|
+
{
|
|
4223
|
+
inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
4224
|
+
name: "allowedDeviceIds",
|
|
4225
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
4226
|
+
stateMutability: "view",
|
|
4227
|
+
type: "function"
|
|
4228
|
+
},
|
|
4229
|
+
{
|
|
4230
|
+
inputs: [],
|
|
4231
|
+
name: "allowAnyDevice",
|
|
4232
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
4233
|
+
stateMutability: "view",
|
|
4234
|
+
type: "function"
|
|
4235
|
+
},
|
|
4236
|
+
{
|
|
4237
|
+
inputs: [],
|
|
4238
|
+
name: "owner",
|
|
4239
|
+
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
4240
|
+
stateMutability: "view",
|
|
4241
|
+
type: "function"
|
|
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
|
+
},
|
|
4261
|
+
// ── Events ───────────────────────────────────────────────────────
|
|
4262
|
+
{
|
|
4263
|
+
anonymous: false,
|
|
4264
|
+
inputs: [{ indexed: false, internalType: "bytes32", name: "deviceId", type: "bytes32" }],
|
|
4265
|
+
name: "DeviceAdded",
|
|
4266
|
+
type: "event"
|
|
4267
|
+
},
|
|
4268
|
+
{
|
|
4269
|
+
anonymous: false,
|
|
4270
|
+
inputs: [{ indexed: false, internalType: "bytes32", name: "deviceId", type: "bytes32" }],
|
|
4271
|
+
name: "DeviceRemoved",
|
|
4272
|
+
type: "event"
|
|
4273
|
+
},
|
|
4274
|
+
{
|
|
4275
|
+
anonymous: false,
|
|
4276
|
+
inputs: [{ indexed: false, internalType: "bool", name: "allowAny", type: "bool" }],
|
|
4277
|
+
name: "AllowAnyDeviceSet",
|
|
4278
|
+
type: "event"
|
|
4279
|
+
}
|
|
4280
|
+
];
|
|
4040
4281
|
|
|
4041
|
-
// src/actions/
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4282
|
+
// src/actions/blockchains/add_device.ts
|
|
4283
|
+
var AddDeviceRequestSchema = z50.object({
|
|
4284
|
+
chain: z50.unknown().optional(),
|
|
4285
|
+
rpcUrl: z50.string().optional(),
|
|
4286
|
+
appAddress: z50.string(),
|
|
4287
|
+
deviceId: z50.string(),
|
|
4288
|
+
privateKey: z50.string().optional(),
|
|
4289
|
+
walletClient: z50.unknown().optional(),
|
|
4290
|
+
publicClient: z50.unknown().optional(),
|
|
4291
|
+
skipPrerequisiteChecks: z50.boolean().optional().default(false),
|
|
4292
|
+
minBalance: z50.string().optional(),
|
|
4293
|
+
timeout: z50.number().optional().default(12e4),
|
|
4294
|
+
retryOptions: z50.unknown().optional(),
|
|
4295
|
+
signal: z50.unknown().optional(),
|
|
4296
|
+
onTransactionStateChange: z50.function().optional(),
|
|
4297
|
+
onTransactionSubmitted: z50.function().optional(),
|
|
4298
|
+
onTransactionConfirmed: z50.function().optional()
|
|
4299
|
+
}).passthrough().refine((data) => !!data.privateKey !== !!data.walletClient, {
|
|
4300
|
+
message: "Either 'privateKey' or 'walletClient' must be provided, but not both",
|
|
4301
|
+
path: ["privateKey", "walletClient"]
|
|
4302
|
+
}).refine(
|
|
4303
|
+
(data) => {
|
|
4304
|
+
if (!!data.publicClient && !!data.walletClient) return true;
|
|
4305
|
+
return !!data.chain;
|
|
4306
|
+
},
|
|
4307
|
+
{
|
|
4308
|
+
message: "Chain is required when publicClient or walletClient is not provided",
|
|
4309
|
+
path: ["chain"]
|
|
4055
4310
|
}
|
|
4056
|
-
|
|
4057
|
-
var
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4311
|
+
);
|
|
4312
|
+
var AddDeviceSchema = z50.object({
|
|
4313
|
+
appAddress: z50.string(),
|
|
4314
|
+
deviceId: z50.string(),
|
|
4315
|
+
transactionHash: z50.string(),
|
|
4316
|
+
blockNumber: z50.bigint().optional(),
|
|
4317
|
+
gasUsed: z50.bigint().optional()
|
|
4318
|
+
}).passthrough();
|
|
4319
|
+
async function addDevice(request, parameters) {
|
|
4320
|
+
const validatedRequest = AddDeviceRequestSchema.parse(request);
|
|
4321
|
+
const {
|
|
4322
|
+
chain,
|
|
4323
|
+
rpcUrl,
|
|
4324
|
+
appAddress,
|
|
4325
|
+
deviceId,
|
|
4326
|
+
privateKey,
|
|
4327
|
+
walletClient: providedWalletClient,
|
|
4328
|
+
publicClient: providedPublicClient,
|
|
4329
|
+
timeout = 12e4,
|
|
4330
|
+
retryOptions,
|
|
4331
|
+
signal,
|
|
4332
|
+
onTransactionStateChange,
|
|
4333
|
+
onTransactionSubmitted,
|
|
4334
|
+
onTransactionConfirmed,
|
|
4335
|
+
skipPrerequisiteChecks = false,
|
|
4336
|
+
minBalance
|
|
4337
|
+
} = validatedRequest;
|
|
4338
|
+
const contractAddress = appAddress.startsWith("0x") ? appAddress : `0x${appAddress}`;
|
|
4339
|
+
const deviceIdHex = asHex(deviceId);
|
|
4340
|
+
let publicClient;
|
|
4341
|
+
let walletClient;
|
|
4342
|
+
let address;
|
|
4343
|
+
let chainId;
|
|
4344
|
+
if (privateKey) {
|
|
4345
|
+
const account = privateKeyToAccount4(privateKey);
|
|
4346
|
+
const transport = http4(rpcUrl, { timeout });
|
|
4347
|
+
publicClient = providedPublicClient ? providedPublicClient : createPublicClient4({ chain, transport });
|
|
4348
|
+
walletClient = createWalletClient4({
|
|
4349
|
+
account,
|
|
4350
|
+
chain,
|
|
4351
|
+
transport
|
|
4352
|
+
});
|
|
4353
|
+
address = account.address;
|
|
4354
|
+
chainId = chain.id;
|
|
4355
|
+
} else if (providedWalletClient) {
|
|
4356
|
+
walletClient = providedWalletClient;
|
|
4357
|
+
publicClient = providedPublicClient ? providedPublicClient : createPublicClient4({
|
|
4358
|
+
chain,
|
|
4359
|
+
transport: http4(rpcUrl, { timeout })
|
|
4360
|
+
});
|
|
4361
|
+
if (!walletClient.account?.address) {
|
|
4362
|
+
throw new Error("WalletClient must have an account with address");
|
|
4363
|
+
}
|
|
4364
|
+
address = walletClient.account.address;
|
|
4365
|
+
chainId = chain ? chain.id : await walletClient.getChainId();
|
|
4366
|
+
} else {
|
|
4367
|
+
throw new Error("Either privateKey or walletClient must be provided");
|
|
4062
4368
|
}
|
|
4063
|
-
};
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
const
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4369
|
+
const networkClients = { publicClient, walletClient, address, chainId };
|
|
4370
|
+
const transactionTracker = createTransactionTracker();
|
|
4371
|
+
if (onTransactionStateChange && typeof onTransactionStateChange === "function") {
|
|
4372
|
+
const pollStatus = () => {
|
|
4373
|
+
onTransactionStateChange(transactionTracker.status);
|
|
4374
|
+
if (!transactionTracker.isComplete) {
|
|
4375
|
+
setTimeout(pollStatus, 100);
|
|
4376
|
+
}
|
|
4377
|
+
};
|
|
4378
|
+
setTimeout(pollStatus, 10);
|
|
4070
4379
|
}
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
const
|
|
4084
|
-
|
|
4085
|
-
|
|
4380
|
+
if (!skipPrerequisiteChecks) {
|
|
4381
|
+
const requirements = {
|
|
4382
|
+
targetChainId: chainId,
|
|
4383
|
+
minBalance: minBalance ? parseEther3(minBalance) : parseEther3("0.001")
|
|
4384
|
+
};
|
|
4385
|
+
const validation = await validateNetworkPrerequisites(networkClients, requirements);
|
|
4386
|
+
if (!validation.networkValid) {
|
|
4387
|
+
throw new Error(
|
|
4388
|
+
`Network mismatch: Expected chain ${requirements.targetChainId}, but wallet is on chain ${validation.details.currentChainId}`
|
|
4389
|
+
);
|
|
4390
|
+
}
|
|
4391
|
+
if (!validation.balanceValid) {
|
|
4392
|
+
const requiredEth = Number(requirements.minBalance) / 1e18;
|
|
4393
|
+
const currentEth = Number(validation.details.balance) / 1e18;
|
|
4394
|
+
throw new Error(
|
|
4395
|
+
`Insufficient balance: Required ${requiredEth} ETH, but account has ${currentEth.toFixed(6)} ETH`
|
|
4396
|
+
);
|
|
4397
|
+
}
|
|
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
|
+
}
|
|
4409
|
+
const addDeviceOperation = async (clients) => {
|
|
4410
|
+
return clients.walletClient.writeContract({
|
|
4411
|
+
address: contractAddress,
|
|
4412
|
+
abi: dstackAppAbi,
|
|
4413
|
+
functionName: "addDevice",
|
|
4414
|
+
args: [deviceIdHex],
|
|
4415
|
+
account: clients.walletClient.account || clients.address,
|
|
4416
|
+
chain: chain || null
|
|
4417
|
+
});
|
|
4418
|
+
};
|
|
4419
|
+
const transactionResult = retryOptions ? await executeTransactionWithRetry(
|
|
4420
|
+
addDeviceOperation,
|
|
4421
|
+
networkClients,
|
|
4422
|
+
[],
|
|
4423
|
+
{
|
|
4424
|
+
timeout,
|
|
4425
|
+
confirmations: 1,
|
|
4426
|
+
onSubmitted: onTransactionSubmitted,
|
|
4427
|
+
onConfirmed: onTransactionConfirmed,
|
|
4428
|
+
signal
|
|
4429
|
+
},
|
|
4430
|
+
retryOptions
|
|
4431
|
+
) : await transactionTracker.execute(addDeviceOperation, networkClients, [], {
|
|
4432
|
+
timeout,
|
|
4433
|
+
confirmations: 1,
|
|
4434
|
+
onSubmitted: onTransactionSubmitted,
|
|
4435
|
+
onConfirmed: onTransactionConfirmed,
|
|
4436
|
+
signal
|
|
4437
|
+
});
|
|
4438
|
+
const result = {
|
|
4439
|
+
appAddress: contractAddress,
|
|
4440
|
+
deviceId: deviceIdHex,
|
|
4441
|
+
transactionHash: transactionResult.receipt.transactionHash,
|
|
4442
|
+
blockNumber: transactionResult.receipt.blockNumber,
|
|
4443
|
+
gasUsed: transactionResult.receipt.gasUsed
|
|
4444
|
+
};
|
|
4445
|
+
if (parameters?.schema === false) {
|
|
4446
|
+
return result;
|
|
4447
|
+
}
|
|
4448
|
+
const schema = parameters?.schema || AddDeviceSchema;
|
|
4449
|
+
return schema.parse(result);
|
|
4450
|
+
}
|
|
4451
|
+
async function safeAddDevice(request, parameters) {
|
|
4452
|
+
try {
|
|
4453
|
+
const result = await addDevice(request, parameters);
|
|
4454
|
+
return { success: true, data: result };
|
|
4455
|
+
} catch (error) {
|
|
4456
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown blockchain error";
|
|
4457
|
+
return {
|
|
4458
|
+
success: false,
|
|
4459
|
+
error: { isRequestError: true, message: errorMessage, status: 500, detail: errorMessage }
|
|
4460
|
+
};
|
|
4461
|
+
}
|
|
4462
|
+
}
|
|
4463
|
+
|
|
4464
|
+
// src/actions/blockchains/remove_device.ts
|
|
4465
|
+
import { z as z51 } from "zod";
|
|
4466
|
+
import {
|
|
4467
|
+
createPublicClient as createPublicClient5,
|
|
4468
|
+
createWalletClient as createWalletClient5,
|
|
4469
|
+
http as http5,
|
|
4470
|
+
parseEther as parseEther4
|
|
4471
|
+
} from "viem";
|
|
4472
|
+
import { privateKeyToAccount as privateKeyToAccount5 } from "viem/accounts";
|
|
4473
|
+
var RemoveDeviceRequestSchema = z51.object({
|
|
4474
|
+
chain: z51.unknown().optional(),
|
|
4475
|
+
rpcUrl: z51.string().optional(),
|
|
4476
|
+
appAddress: z51.string(),
|
|
4477
|
+
deviceId: z51.string(),
|
|
4478
|
+
privateKey: z51.string().optional(),
|
|
4479
|
+
walletClient: z51.unknown().optional(),
|
|
4480
|
+
publicClient: z51.unknown().optional(),
|
|
4481
|
+
skipPrerequisiteChecks: z51.boolean().optional().default(false),
|
|
4482
|
+
minBalance: z51.string().optional(),
|
|
4483
|
+
timeout: z51.number().optional().default(12e4),
|
|
4484
|
+
retryOptions: z51.unknown().optional(),
|
|
4485
|
+
signal: z51.unknown().optional(),
|
|
4486
|
+
onTransactionStateChange: z51.function().optional(),
|
|
4487
|
+
onTransactionSubmitted: z51.function().optional(),
|
|
4488
|
+
onTransactionConfirmed: z51.function().optional()
|
|
4489
|
+
}).passthrough().refine((data) => !!data.privateKey !== !!data.walletClient, {
|
|
4490
|
+
message: "Either 'privateKey' or 'walletClient' must be provided, but not both",
|
|
4491
|
+
path: ["privateKey", "walletClient"]
|
|
4492
|
+
}).refine(
|
|
4493
|
+
(data) => {
|
|
4494
|
+
if (!!data.publicClient && !!data.walletClient) return true;
|
|
4495
|
+
return !!data.chain;
|
|
4496
|
+
},
|
|
4497
|
+
{
|
|
4498
|
+
message: "Chain is required when publicClient or walletClient is not provided",
|
|
4499
|
+
path: ["chain"]
|
|
4500
|
+
}
|
|
4501
|
+
);
|
|
4502
|
+
var RemoveDeviceSchema = z51.object({
|
|
4503
|
+
appAddress: z51.string(),
|
|
4504
|
+
deviceId: z51.string(),
|
|
4505
|
+
transactionHash: z51.string(),
|
|
4506
|
+
blockNumber: z51.bigint().optional(),
|
|
4507
|
+
gasUsed: z51.bigint().optional()
|
|
4508
|
+
}).passthrough();
|
|
4509
|
+
async function removeDevice(request, parameters) {
|
|
4510
|
+
const validatedRequest = RemoveDeviceRequestSchema.parse(request);
|
|
4511
|
+
const {
|
|
4512
|
+
chain,
|
|
4513
|
+
rpcUrl,
|
|
4514
|
+
appAddress,
|
|
4515
|
+
deviceId,
|
|
4516
|
+
privateKey,
|
|
4517
|
+
walletClient: providedWalletClient,
|
|
4518
|
+
publicClient: providedPublicClient,
|
|
4519
|
+
timeout = 12e4,
|
|
4520
|
+
retryOptions,
|
|
4521
|
+
signal,
|
|
4522
|
+
onTransactionStateChange,
|
|
4523
|
+
onTransactionSubmitted,
|
|
4524
|
+
onTransactionConfirmed,
|
|
4525
|
+
skipPrerequisiteChecks = false,
|
|
4526
|
+
minBalance
|
|
4527
|
+
} = validatedRequest;
|
|
4528
|
+
const contractAddress = appAddress.startsWith("0x") ? appAddress : `0x${appAddress}`;
|
|
4529
|
+
const deviceIdHex = asHex(deviceId);
|
|
4530
|
+
let publicClient;
|
|
4531
|
+
let walletClient;
|
|
4532
|
+
let address;
|
|
4533
|
+
let chainId;
|
|
4534
|
+
if (privateKey) {
|
|
4535
|
+
const account = privateKeyToAccount5(privateKey);
|
|
4536
|
+
const transport = http5(rpcUrl, { timeout });
|
|
4537
|
+
publicClient = providedPublicClient ? providedPublicClient : createPublicClient5({ chain, transport });
|
|
4538
|
+
walletClient = createWalletClient5({
|
|
4539
|
+
account,
|
|
4540
|
+
chain,
|
|
4541
|
+
transport
|
|
4542
|
+
});
|
|
4543
|
+
address = account.address;
|
|
4544
|
+
chainId = chain.id;
|
|
4545
|
+
} else if (providedWalletClient) {
|
|
4546
|
+
walletClient = providedWalletClient;
|
|
4547
|
+
publicClient = providedPublicClient ? providedPublicClient : createPublicClient5({
|
|
4548
|
+
chain,
|
|
4549
|
+
transport: http5(rpcUrl, { timeout })
|
|
4550
|
+
});
|
|
4551
|
+
if (!walletClient.account?.address) {
|
|
4552
|
+
throw new Error("WalletClient must have an account with address");
|
|
4553
|
+
}
|
|
4554
|
+
address = walletClient.account.address;
|
|
4555
|
+
chainId = chain ? chain.id : await walletClient.getChainId();
|
|
4556
|
+
} else {
|
|
4557
|
+
throw new Error("Either privateKey or walletClient must be provided");
|
|
4558
|
+
}
|
|
4559
|
+
const networkClients = { publicClient, walletClient, address, chainId };
|
|
4560
|
+
const transactionTracker = createTransactionTracker();
|
|
4561
|
+
if (onTransactionStateChange && typeof onTransactionStateChange === "function") {
|
|
4562
|
+
const pollStatus = () => {
|
|
4563
|
+
onTransactionStateChange(transactionTracker.status);
|
|
4564
|
+
if (!transactionTracker.isComplete) {
|
|
4565
|
+
setTimeout(pollStatus, 100);
|
|
4566
|
+
}
|
|
4567
|
+
};
|
|
4568
|
+
setTimeout(pollStatus, 10);
|
|
4569
|
+
}
|
|
4570
|
+
if (!skipPrerequisiteChecks) {
|
|
4571
|
+
const requirements = {
|
|
4572
|
+
targetChainId: chainId,
|
|
4573
|
+
minBalance: minBalance ? parseEther4(minBalance) : parseEther4("0.001")
|
|
4574
|
+
};
|
|
4575
|
+
const validation = await validateNetworkPrerequisites(networkClients, requirements);
|
|
4576
|
+
if (!validation.networkValid) {
|
|
4577
|
+
throw new Error(
|
|
4578
|
+
`Network mismatch: Expected chain ${requirements.targetChainId}, but wallet is on chain ${validation.details.currentChainId}`
|
|
4579
|
+
);
|
|
4580
|
+
}
|
|
4581
|
+
if (!validation.balanceValid) {
|
|
4582
|
+
const requiredEth = Number(requirements.minBalance) / 1e18;
|
|
4583
|
+
const currentEth = Number(validation.details.balance) / 1e18;
|
|
4584
|
+
throw new Error(
|
|
4585
|
+
`Insufficient balance: Required ${requiredEth} ETH, but account has ${currentEth.toFixed(6)} ETH`
|
|
4586
|
+
);
|
|
4587
|
+
}
|
|
4588
|
+
}
|
|
4589
|
+
const removeDeviceOperation = async (clients) => {
|
|
4590
|
+
return clients.walletClient.writeContract({
|
|
4591
|
+
address: contractAddress,
|
|
4592
|
+
abi: dstackAppAbi,
|
|
4593
|
+
functionName: "removeDevice",
|
|
4594
|
+
args: [deviceIdHex],
|
|
4595
|
+
account: clients.walletClient.account || clients.address,
|
|
4596
|
+
chain: chain || null
|
|
4597
|
+
});
|
|
4598
|
+
};
|
|
4599
|
+
const transactionResult = retryOptions ? await executeTransactionWithRetry(
|
|
4600
|
+
removeDeviceOperation,
|
|
4601
|
+
networkClients,
|
|
4602
|
+
[],
|
|
4603
|
+
{
|
|
4604
|
+
timeout,
|
|
4605
|
+
confirmations: 1,
|
|
4606
|
+
onSubmitted: onTransactionSubmitted,
|
|
4607
|
+
onConfirmed: onTransactionConfirmed,
|
|
4608
|
+
signal
|
|
4609
|
+
},
|
|
4610
|
+
retryOptions
|
|
4611
|
+
) : await transactionTracker.execute(removeDeviceOperation, networkClients, [], {
|
|
4612
|
+
timeout,
|
|
4613
|
+
confirmations: 1,
|
|
4614
|
+
onSubmitted: onTransactionSubmitted,
|
|
4615
|
+
onConfirmed: onTransactionConfirmed,
|
|
4616
|
+
signal
|
|
4617
|
+
});
|
|
4618
|
+
const result = {
|
|
4619
|
+
appAddress: contractAddress,
|
|
4620
|
+
deviceId: deviceIdHex,
|
|
4621
|
+
transactionHash: transactionResult.receipt.transactionHash,
|
|
4622
|
+
blockNumber: transactionResult.receipt.blockNumber,
|
|
4623
|
+
gasUsed: transactionResult.receipt.gasUsed
|
|
4624
|
+
};
|
|
4625
|
+
if (parameters?.schema === false) {
|
|
4626
|
+
return result;
|
|
4627
|
+
}
|
|
4628
|
+
const schema = parameters?.schema || RemoveDeviceSchema;
|
|
4629
|
+
return schema.parse(result);
|
|
4630
|
+
}
|
|
4631
|
+
async function safeRemoveDevice(request, parameters) {
|
|
4632
|
+
try {
|
|
4633
|
+
const result = await removeDevice(request, parameters);
|
|
4634
|
+
return { success: true, data: result };
|
|
4635
|
+
} catch (error) {
|
|
4636
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown blockchain error";
|
|
4637
|
+
return {
|
|
4638
|
+
success: false,
|
|
4639
|
+
error: { isRequestError: true, message: errorMessage, status: 500, detail: errorMessage }
|
|
4640
|
+
};
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4644
|
+
// src/actions/blockchains/set_allow_any_device.ts
|
|
4645
|
+
import { z as z52 } from "zod";
|
|
4646
|
+
import {
|
|
4647
|
+
createPublicClient as createPublicClient6,
|
|
4648
|
+
createWalletClient as createWalletClient6,
|
|
4649
|
+
http as http6,
|
|
4650
|
+
parseEther as parseEther5
|
|
4651
|
+
} from "viem";
|
|
4652
|
+
import { privateKeyToAccount as privateKeyToAccount6 } from "viem/accounts";
|
|
4653
|
+
var SetAllowAnyDeviceRequestSchema = z52.object({
|
|
4654
|
+
chain: z52.unknown().optional(),
|
|
4655
|
+
rpcUrl: z52.string().optional(),
|
|
4656
|
+
appAddress: z52.string(),
|
|
4657
|
+
allow: z52.boolean(),
|
|
4658
|
+
privateKey: z52.string().optional(),
|
|
4659
|
+
walletClient: z52.unknown().optional(),
|
|
4660
|
+
publicClient: z52.unknown().optional(),
|
|
4661
|
+
skipPrerequisiteChecks: z52.boolean().optional().default(false),
|
|
4662
|
+
minBalance: z52.string().optional(),
|
|
4663
|
+
timeout: z52.number().optional().default(12e4),
|
|
4664
|
+
retryOptions: z52.unknown().optional(),
|
|
4665
|
+
signal: z52.unknown().optional(),
|
|
4666
|
+
onTransactionStateChange: z52.function().optional(),
|
|
4667
|
+
onTransactionSubmitted: z52.function().optional(),
|
|
4668
|
+
onTransactionConfirmed: z52.function().optional()
|
|
4669
|
+
}).passthrough().refine((data) => !!data.privateKey !== !!data.walletClient, {
|
|
4670
|
+
message: "Either 'privateKey' or 'walletClient' must be provided, but not both",
|
|
4671
|
+
path: ["privateKey", "walletClient"]
|
|
4672
|
+
}).refine(
|
|
4673
|
+
(data) => {
|
|
4674
|
+
if (!!data.publicClient && !!data.walletClient) return true;
|
|
4675
|
+
return !!data.chain;
|
|
4676
|
+
},
|
|
4677
|
+
{
|
|
4678
|
+
message: "Chain is required when publicClient or walletClient is not provided",
|
|
4679
|
+
path: ["chain"]
|
|
4680
|
+
}
|
|
4681
|
+
);
|
|
4682
|
+
var SetAllowAnyDeviceSchema = z52.object({
|
|
4683
|
+
appAddress: z52.string(),
|
|
4684
|
+
allow: z52.boolean(),
|
|
4685
|
+
transactionHash: z52.string(),
|
|
4686
|
+
blockNumber: z52.bigint().optional(),
|
|
4687
|
+
gasUsed: z52.bigint().optional()
|
|
4688
|
+
}).passthrough();
|
|
4689
|
+
async function setAllowAnyDevice(request, parameters) {
|
|
4690
|
+
const validatedRequest = SetAllowAnyDeviceRequestSchema.parse(request);
|
|
4691
|
+
const {
|
|
4692
|
+
chain,
|
|
4693
|
+
rpcUrl,
|
|
4694
|
+
appAddress,
|
|
4695
|
+
allow,
|
|
4696
|
+
privateKey,
|
|
4697
|
+
walletClient: providedWalletClient,
|
|
4698
|
+
publicClient: providedPublicClient,
|
|
4699
|
+
timeout = 12e4,
|
|
4700
|
+
retryOptions,
|
|
4701
|
+
signal,
|
|
4702
|
+
onTransactionStateChange,
|
|
4703
|
+
onTransactionSubmitted,
|
|
4704
|
+
onTransactionConfirmed,
|
|
4705
|
+
skipPrerequisiteChecks = false,
|
|
4706
|
+
minBalance
|
|
4707
|
+
} = validatedRequest;
|
|
4708
|
+
const contractAddress = appAddress.startsWith("0x") ? appAddress : `0x${appAddress}`;
|
|
4709
|
+
let publicClient;
|
|
4710
|
+
let walletClient;
|
|
4711
|
+
let address;
|
|
4712
|
+
let chainId;
|
|
4713
|
+
if (privateKey) {
|
|
4714
|
+
const account = privateKeyToAccount6(privateKey);
|
|
4715
|
+
const transport = http6(rpcUrl, { timeout });
|
|
4716
|
+
publicClient = providedPublicClient ? providedPublicClient : createPublicClient6({ chain, transport });
|
|
4717
|
+
walletClient = createWalletClient6({
|
|
4718
|
+
account,
|
|
4719
|
+
chain,
|
|
4720
|
+
transport
|
|
4721
|
+
});
|
|
4722
|
+
address = account.address;
|
|
4723
|
+
chainId = chain.id;
|
|
4724
|
+
} else if (providedWalletClient) {
|
|
4725
|
+
walletClient = providedWalletClient;
|
|
4726
|
+
publicClient = providedPublicClient ? providedPublicClient : createPublicClient6({
|
|
4727
|
+
chain,
|
|
4728
|
+
transport: http6(rpcUrl, { timeout })
|
|
4729
|
+
});
|
|
4730
|
+
if (!walletClient.account?.address) {
|
|
4731
|
+
throw new Error("WalletClient must have an account with address");
|
|
4732
|
+
}
|
|
4733
|
+
address = walletClient.account.address;
|
|
4734
|
+
chainId = chain ? chain.id : await walletClient.getChainId();
|
|
4735
|
+
} else {
|
|
4736
|
+
throw new Error("Either privateKey or walletClient must be provided");
|
|
4737
|
+
}
|
|
4738
|
+
const networkClients = { publicClient, walletClient, address, chainId };
|
|
4739
|
+
const transactionTracker = createTransactionTracker();
|
|
4740
|
+
if (onTransactionStateChange && typeof onTransactionStateChange === "function") {
|
|
4741
|
+
const pollStatus = () => {
|
|
4742
|
+
onTransactionStateChange(transactionTracker.status);
|
|
4743
|
+
if (!transactionTracker.isComplete) {
|
|
4744
|
+
setTimeout(pollStatus, 100);
|
|
4745
|
+
}
|
|
4746
|
+
};
|
|
4747
|
+
setTimeout(pollStatus, 10);
|
|
4748
|
+
}
|
|
4749
|
+
if (!skipPrerequisiteChecks) {
|
|
4750
|
+
const requirements = {
|
|
4751
|
+
targetChainId: chainId,
|
|
4752
|
+
minBalance: minBalance ? parseEther5(minBalance) : parseEther5("0.001")
|
|
4753
|
+
};
|
|
4754
|
+
const validation = await validateNetworkPrerequisites(networkClients, requirements);
|
|
4755
|
+
if (!validation.networkValid) {
|
|
4756
|
+
throw new Error(
|
|
4757
|
+
`Network mismatch: Expected chain ${requirements.targetChainId}, but wallet is on chain ${validation.details.currentChainId}`
|
|
4758
|
+
);
|
|
4759
|
+
}
|
|
4760
|
+
if (!validation.balanceValid) {
|
|
4761
|
+
const requiredEth = Number(requirements.minBalance) / 1e18;
|
|
4762
|
+
const currentEth = Number(validation.details.balance) / 1e18;
|
|
4763
|
+
throw new Error(
|
|
4764
|
+
`Insufficient balance: Required ${requiredEth} ETH, but account has ${currentEth.toFixed(6)} ETH`
|
|
4765
|
+
);
|
|
4766
|
+
}
|
|
4767
|
+
}
|
|
4768
|
+
const setAllowAnyOperation = async (clients) => {
|
|
4769
|
+
return clients.walletClient.writeContract({
|
|
4770
|
+
address: contractAddress,
|
|
4771
|
+
abi: dstackAppAbi,
|
|
4772
|
+
functionName: "setAllowAnyDevice",
|
|
4773
|
+
args: [allow],
|
|
4774
|
+
account: clients.walletClient.account || clients.address,
|
|
4775
|
+
chain: chain || null
|
|
4776
|
+
});
|
|
4777
|
+
};
|
|
4778
|
+
const transactionResult = retryOptions ? await executeTransactionWithRetry(
|
|
4779
|
+
setAllowAnyOperation,
|
|
4780
|
+
networkClients,
|
|
4781
|
+
[],
|
|
4782
|
+
{
|
|
4783
|
+
timeout,
|
|
4784
|
+
confirmations: 1,
|
|
4785
|
+
onSubmitted: onTransactionSubmitted,
|
|
4786
|
+
onConfirmed: onTransactionConfirmed,
|
|
4787
|
+
signal
|
|
4788
|
+
},
|
|
4789
|
+
retryOptions
|
|
4790
|
+
) : await transactionTracker.execute(setAllowAnyOperation, networkClients, [], {
|
|
4791
|
+
timeout,
|
|
4792
|
+
confirmations: 1,
|
|
4793
|
+
onSubmitted: onTransactionSubmitted,
|
|
4794
|
+
onConfirmed: onTransactionConfirmed,
|
|
4795
|
+
signal
|
|
4796
|
+
});
|
|
4797
|
+
const result = {
|
|
4798
|
+
appAddress: contractAddress,
|
|
4799
|
+
allow,
|
|
4800
|
+
transactionHash: transactionResult.receipt.transactionHash,
|
|
4801
|
+
blockNumber: transactionResult.receipt.blockNumber,
|
|
4802
|
+
gasUsed: transactionResult.receipt.gasUsed
|
|
4803
|
+
};
|
|
4804
|
+
if (parameters?.schema === false) {
|
|
4805
|
+
return result;
|
|
4806
|
+
}
|
|
4807
|
+
const schema = parameters?.schema || SetAllowAnyDeviceSchema;
|
|
4808
|
+
return schema.parse(result);
|
|
4809
|
+
}
|
|
4810
|
+
async function safeSetAllowAnyDevice(request, parameters) {
|
|
4811
|
+
try {
|
|
4812
|
+
const result = await setAllowAnyDevice(request, parameters);
|
|
4813
|
+
return { success: true, data: result };
|
|
4814
|
+
} catch (error) {
|
|
4815
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown blockchain error";
|
|
4816
|
+
return {
|
|
4817
|
+
success: false,
|
|
4818
|
+
error: { isRequestError: true, message: errorMessage, status: 500, detail: errorMessage }
|
|
4819
|
+
};
|
|
4820
|
+
}
|
|
4821
|
+
}
|
|
4822
|
+
|
|
4823
|
+
// src/actions/blockchains/get_allowed_devices.ts
|
|
4824
|
+
import { z as z53 } from "zod";
|
|
4825
|
+
import { createPublicClient as createPublicClient7, http as http7 } from "viem";
|
|
4826
|
+
var GetAllowedDevicesSchema = z53.object({
|
|
4827
|
+
appAddress: z53.string(),
|
|
4828
|
+
owner: z53.string(),
|
|
4829
|
+
allowAnyDevice: z53.boolean(),
|
|
4830
|
+
devices: z53.array(z53.string())
|
|
4831
|
+
});
|
|
4832
|
+
async function getAllowedDevices(request) {
|
|
4833
|
+
const { chain, rpcUrl, appAddress, deviceIds, publicClient: providedPublicClient } = request;
|
|
4834
|
+
const contractAddress = appAddress.startsWith("0x") ? appAddress : `0x${appAddress}`;
|
|
4835
|
+
const publicClient = providedPublicClient ? providedPublicClient : (() => {
|
|
4836
|
+
if (!chain) throw new Error("Chain is required when publicClient is not provided");
|
|
4837
|
+
return createPublicClient7({ chain, transport: http7(rpcUrl) });
|
|
4838
|
+
})();
|
|
4839
|
+
const [allowAnyDevice, owner] = await Promise.all([
|
|
4840
|
+
publicClient.readContract({
|
|
4841
|
+
address: contractAddress,
|
|
4842
|
+
abi: dstackAppAbi,
|
|
4843
|
+
functionName: "allowAnyDevice"
|
|
4844
|
+
}),
|
|
4845
|
+
publicClient.readContract({
|
|
4846
|
+
address: contractAddress,
|
|
4847
|
+
abi: dstackAppAbi,
|
|
4848
|
+
functionName: "owner"
|
|
4849
|
+
})
|
|
4850
|
+
]);
|
|
4851
|
+
if (allowAnyDevice) {
|
|
4852
|
+
return {
|
|
4853
|
+
appAddress: contractAddress,
|
|
4854
|
+
owner,
|
|
4855
|
+
allowAnyDevice: true,
|
|
4856
|
+
devices: deviceIds.map((id) => asHex(id))
|
|
4857
|
+
};
|
|
4858
|
+
}
|
|
4859
|
+
let devices;
|
|
4860
|
+
if (deviceIds.length === 0) {
|
|
4861
|
+
devices = [];
|
|
4862
|
+
} else {
|
|
4863
|
+
const calls = deviceIds.map((deviceId) => ({
|
|
4864
|
+
address: contractAddress,
|
|
4865
|
+
abi: dstackAppAbi,
|
|
4866
|
+
functionName: "allowedDeviceIds",
|
|
4867
|
+
args: [asHex(deviceId)]
|
|
4868
|
+
}));
|
|
4869
|
+
const multicallResults = await publicClient.multicall({ contracts: calls });
|
|
4870
|
+
devices = deviceIds.map((deviceId, i) => ({
|
|
4871
|
+
deviceId: asHex(deviceId),
|
|
4872
|
+
allowed: multicallResults[i]?.status === "success" && multicallResults[i]?.result === true
|
|
4873
|
+
})).filter((r) => r.allowed).map((r) => r.deviceId);
|
|
4874
|
+
}
|
|
4875
|
+
return {
|
|
4876
|
+
appAddress: contractAddress,
|
|
4877
|
+
owner,
|
|
4878
|
+
allowAnyDevice: false,
|
|
4879
|
+
devices
|
|
4880
|
+
};
|
|
4881
|
+
}
|
|
4882
|
+
async function safeGetAllowedDevices(request) {
|
|
4883
|
+
try {
|
|
4884
|
+
const result = await getAllowedDevices(request);
|
|
4885
|
+
return { success: true, data: result };
|
|
4886
|
+
} catch (error) {
|
|
4887
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown blockchain error";
|
|
4888
|
+
return {
|
|
4889
|
+
success: false,
|
|
4890
|
+
error: { isRequestError: true, message: errorMessage, status: 500, detail: errorMessage }
|
|
4891
|
+
};
|
|
4892
|
+
}
|
|
4893
|
+
}
|
|
4894
|
+
|
|
4895
|
+
// src/actions/blockchains/check_device_allowed.ts
|
|
4896
|
+
import { createPublicClient as createPublicClient8, http as http8 } from "viem";
|
|
4897
|
+
async function checkDeviceAllowed(request) {
|
|
4898
|
+
const { chain, rpcUrl, appAddress, deviceId, publicClient: providedPublicClient } = request;
|
|
4899
|
+
const contractAddress = appAddress.startsWith("0x") ? appAddress : `0x${appAddress}`;
|
|
4900
|
+
const deviceIdHex = asHex(deviceId);
|
|
4901
|
+
const publicClient = providedPublicClient ? providedPublicClient : (() => {
|
|
4902
|
+
if (!chain) throw new Error("Chain is required when publicClient is not provided");
|
|
4903
|
+
return createPublicClient8({ chain, transport: http8(rpcUrl) });
|
|
4904
|
+
})();
|
|
4905
|
+
const allowAny = await publicClient.readContract({
|
|
4906
|
+
address: contractAddress,
|
|
4907
|
+
abi: dstackAppAbi,
|
|
4908
|
+
functionName: "allowAnyDevice"
|
|
4909
|
+
});
|
|
4910
|
+
if (allowAny) return true;
|
|
4911
|
+
const allowed = await publicClient.readContract({
|
|
4912
|
+
address: contractAddress,
|
|
4913
|
+
abi: dstackAppAbi,
|
|
4914
|
+
functionName: "allowedDeviceIds",
|
|
4915
|
+
args: [deviceIdHex]
|
|
4916
|
+
});
|
|
4917
|
+
return allowed;
|
|
4918
|
+
}
|
|
4919
|
+
async function safeCheckDeviceAllowed(request) {
|
|
4920
|
+
try {
|
|
4921
|
+
const result = await checkDeviceAllowed(request);
|
|
4922
|
+
return { success: true, data: result };
|
|
4923
|
+
} catch (error) {
|
|
4924
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown blockchain error";
|
|
4925
|
+
return {
|
|
4926
|
+
success: false,
|
|
4927
|
+
error: { isRequestError: true, message: errorMessage, status: 500, detail: errorMessage }
|
|
4928
|
+
};
|
|
4929
|
+
}
|
|
4930
|
+
}
|
|
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
|
+
|
|
5023
|
+
// src/actions/workspaces/get_workspace_nodes.ts
|
|
5024
|
+
import { z as z54 } from "zod";
|
|
5025
|
+
var NodeRefSchema2 = NodeRefSchema;
|
|
5026
|
+
var NodeInfoSchema = NodeRefSchema2;
|
|
5027
|
+
var GetWorkspaceNodesSchema = z54.object({
|
|
5028
|
+
items: z54.array(NodeRefSchema2),
|
|
5029
|
+
total: z54.number(),
|
|
5030
|
+
page: z54.number(),
|
|
5031
|
+
page_size: z54.number(),
|
|
5032
|
+
pages: z54.number()
|
|
5033
|
+
}).passthrough();
|
|
5034
|
+
var { action: getWorkspaceNodes, safeAction: safeGetWorkspaceNodes } = defineAction(GetWorkspaceNodesSchema, async (client, request) => {
|
|
5035
|
+
const { teamSlug, page, pageSize } = request;
|
|
5036
|
+
const queryParams = new URLSearchParams();
|
|
5037
|
+
if (page !== void 0) queryParams.append("page", page.toString());
|
|
5038
|
+
if (pageSize !== void 0) queryParams.append("page_size", pageSize.toString());
|
|
5039
|
+
const url = queryParams.toString() ? `/workspaces/${teamSlug}/nodes?${queryParams.toString()}` : `/workspaces/${teamSlug}/nodes`;
|
|
5040
|
+
return await client.get(url);
|
|
5041
|
+
});
|
|
5042
|
+
|
|
5043
|
+
// src/actions/workspaces/get_workspace_quotas.ts
|
|
5044
|
+
import { z as z55 } from "zod";
|
|
5045
|
+
var QuotaMetricSchema = z55.object({
|
|
5046
|
+
limit: z55.number(),
|
|
5047
|
+
remaining: z55.number()
|
|
5048
|
+
}).passthrough();
|
|
5049
|
+
var WorkspaceQuotasSchema = z55.object({
|
|
5050
|
+
vm_slots: QuotaMetricSchema,
|
|
5051
|
+
vcpu: QuotaMetricSchema,
|
|
5052
|
+
memory_mb: QuotaMetricSchema,
|
|
5053
|
+
disk_gb: QuotaMetricSchema
|
|
5054
|
+
}).passthrough();
|
|
5055
|
+
var WorkspaceReservedGpuQuotaSchema = z55.object({
|
|
5056
|
+
gpus: QuotaMetricSchema,
|
|
5057
|
+
in_use: z55.number(),
|
|
5058
|
+
misconfigured: z55.number()
|
|
5059
|
+
}).passthrough();
|
|
5060
|
+
var GetWorkspaceQuotasSchema = z55.object({
|
|
5061
|
+
team_slug: z55.string(),
|
|
5062
|
+
tier: z55.string(),
|
|
5063
|
+
quotas: WorkspaceQuotasSchema,
|
|
5064
|
+
reserved_nodes: QuotaMetricSchema,
|
|
5065
|
+
reserved_gpu: WorkspaceReservedGpuQuotaSchema,
|
|
5066
|
+
as_of: z55.string()
|
|
5067
|
+
}).passthrough();
|
|
5068
|
+
var { action: getWorkspaceQuotas, safeAction: safeGetWorkspaceQuotas } = defineAction(GetWorkspaceQuotasSchema, async (client, request) => {
|
|
5069
|
+
return await client.get(`/workspaces/${request.teamSlug}/quotas`);
|
|
5070
|
+
});
|
|
5071
|
+
|
|
5072
|
+
// src/actions/cvms/replicate_cvm.ts
|
|
5073
|
+
import { z as z56 } from "zod";
|
|
5074
|
+
var ReplicateCvmRequestSchema = refineCvmId(
|
|
5075
|
+
CvmIdObjectSchema.extend({
|
|
5076
|
+
node_id: z56.number().optional()
|
|
5077
|
+
})
|
|
5078
|
+
);
|
|
5079
|
+
var { action: replicateCvm, safeAction: safeReplicateCvm } = defineAction(VMSchema, async (client, request) => {
|
|
5080
|
+
const parsed = ReplicateCvmRequestSchema.parse(request);
|
|
5081
|
+
const { cvmId } = CvmIdSchema.parse(parsed);
|
|
5082
|
+
const { node_id } = parsed;
|
|
5083
|
+
return await client.post(`/cvms/${cvmId}/replicas`, { node_id });
|
|
5084
|
+
});
|
|
5085
|
+
|
|
5086
|
+
// src/actions/cvms/watch_cvm_state.ts
|
|
5087
|
+
import { z as z57 } from "zod";
|
|
5088
|
+
var WatchCvmStateParamsSchema = z57.object({
|
|
5089
|
+
target: z57.string().describe("Target status to wait for (e.g., 'running', 'stopped')"),
|
|
5090
|
+
interval: z57.number().min(5).max(30).default(5).describe("Polling interval in seconds"),
|
|
5091
|
+
timeout: z57.number().min(10).max(600).default(300).describe("Timeout per attempt in seconds"),
|
|
5092
|
+
maxRetries: z57.number().min(0).default(Number.POSITIVE_INFINITY).describe("Maximum number of retry attempts (Infinity for unlimited)"),
|
|
5093
|
+
retryDelay: z57.number().min(0).default(5e3).describe("Delay between retries in milliseconds")
|
|
5094
|
+
});
|
|
5095
|
+
var WatchCvmStateRequestSchema = WatchCvmStateParamsSchema;
|
|
5096
|
+
var WatchAbortedError = class extends Error {
|
|
5097
|
+
constructor() {
|
|
5098
|
+
super("Watch operation was aborted");
|
|
5099
|
+
this.name = "WatchAbortedError";
|
|
5100
|
+
}
|
|
5101
|
+
};
|
|
5102
|
+
var MaxRetriesExceededError = class extends Error {
|
|
5103
|
+
constructor(attempts) {
|
|
5104
|
+
super(`Maximum retry attempts (${attempts}) exceeded`);
|
|
5105
|
+
this.attempts = attempts;
|
|
5106
|
+
this.name = "MaxRetriesExceededError";
|
|
5107
|
+
}
|
|
5108
|
+
};
|
|
5109
|
+
function parseSSEEvent(eventType, data) {
|
|
5110
|
+
try {
|
|
5111
|
+
const parsed = JSON.parse(data);
|
|
5112
|
+
return { type: eventType, data: parsed };
|
|
5113
|
+
} catch {
|
|
5114
|
+
return { type: "error", data: { error: "Failed to parse SSE event" } };
|
|
5115
|
+
}
|
|
5116
|
+
}
|
|
5117
|
+
async function watchCvmState(client, request, options = {}) {
|
|
5118
|
+
const { cvmId } = CvmIdSchema.parse(request);
|
|
5119
|
+
const { target, interval, timeout, maxRetries, retryDelay } = WatchCvmStateParamsSchema.parse(request);
|
|
5120
|
+
const { signal, onEvent } = options;
|
|
5121
|
+
let attempt = 0;
|
|
5122
|
+
while (attempt < maxRetries) {
|
|
5123
|
+
if (signal?.aborted) {
|
|
5124
|
+
throw new WatchAbortedError();
|
|
5125
|
+
}
|
|
5126
|
+
attempt++;
|
|
5127
|
+
try {
|
|
5128
|
+
const result = await watchSingleAttempt(
|
|
5129
|
+
client,
|
|
5130
|
+
cvmId,
|
|
4086
5131
|
target,
|
|
4087
5132
|
interval,
|
|
4088
5133
|
timeout,
|
|
@@ -4232,22 +5277,230 @@ function sleep(ms, signal) {
|
|
|
4232
5277
|
});
|
|
4233
5278
|
}
|
|
4234
5279
|
|
|
5280
|
+
// src/actions/cvms/patch_cvm.ts
|
|
5281
|
+
import { z as z58 } from "zod";
|
|
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()
|
|
5446
|
+
});
|
|
5447
|
+
var RefreshCvmInstanceIdRequestSchema = refineCvmId(
|
|
5448
|
+
CvmIdObjectSchema.extend({
|
|
5449
|
+
overwrite: z61.boolean().optional(),
|
|
5450
|
+
dry_run: z61.boolean().optional()
|
|
5451
|
+
})
|
|
5452
|
+
);
|
|
5453
|
+
var { action: refreshCvmInstanceId, safeAction: safeRefreshCvmInstanceId } = defineAction(InstanceIdRefreshResultSchema, async (client, request) => {
|
|
5454
|
+
const parsed = RefreshCvmInstanceIdRequestSchema.parse(request);
|
|
5455
|
+
const { cvmId } = CvmIdSchema.parse(parsed);
|
|
5456
|
+
const { overwrite, dry_run } = parsed;
|
|
5457
|
+
return await client.patch(`/cvms/${cvmId}/instance-id`, {
|
|
5458
|
+
overwrite,
|
|
5459
|
+
dry_run
|
|
5460
|
+
});
|
|
5461
|
+
});
|
|
5462
|
+
|
|
5463
|
+
// src/actions/cvms/refresh_cvm_instance_ids.ts
|
|
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()
|
|
5472
|
+
}).strict();
|
|
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)
|
|
5482
|
+
});
|
|
5483
|
+
var { action: refreshCvmInstanceIds, safeAction: safeRefreshCvmInstanceIds } = defineAction(RefreshCvmInstanceIdsResponseSchema, async (client, request) => {
|
|
5484
|
+
const parsed = RefreshCvmInstanceIdsRequestSchema.parse(request);
|
|
5485
|
+
return await client.patch("/cvms/instance-ids", parsed);
|
|
5486
|
+
});
|
|
5487
|
+
|
|
4235
5488
|
// src/actions/cvms/get_cvm_status_batch.ts
|
|
4236
|
-
import { z as
|
|
4237
|
-
var CvmStatusSchema =
|
|
4238
|
-
vm_uuid:
|
|
4239
|
-
status:
|
|
4240
|
-
uptime:
|
|
4241
|
-
in_progress:
|
|
4242
|
-
boot_progress:
|
|
4243
|
-
boot_error:
|
|
4244
|
-
operation_type:
|
|
4245
|
-
operation_started_at:
|
|
4246
|
-
correlation_id:
|
|
4247
|
-
});
|
|
4248
|
-
var GetCvmStatusBatchResponseSchema =
|
|
4249
|
-
var GetCvmStatusBatchRequestSchema =
|
|
4250
|
-
vmUuids:
|
|
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())
|
|
4251
5504
|
});
|
|
4252
5505
|
var { action: getCvmStatusBatch, safeAction: safeGetCvmStatusBatch } = defineAction(GetCvmStatusBatchResponseSchema, async (client, request) => {
|
|
4253
5506
|
const { vmUuids } = GetCvmStatusBatchRequestSchema.parse(request);
|
|
@@ -4255,11 +5508,11 @@ var { action: getCvmStatusBatch, safeAction: safeGetCvmStatusBatch } = defineAct
|
|
|
4255
5508
|
});
|
|
4256
5509
|
|
|
4257
5510
|
// src/actions/cvms/get_cvm_user_config.ts
|
|
4258
|
-
import { z as
|
|
4259
|
-
var CvmUserConfigSchema =
|
|
4260
|
-
hostname:
|
|
4261
|
-
ssh_authorized_keys:
|
|
4262
|
-
default_gateway_domain:
|
|
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()
|
|
4263
5516
|
});
|
|
4264
5517
|
var GetCvmUserConfigRequestSchema = CvmIdSchema;
|
|
4265
5518
|
var { action: getCvmUserConfig, safeAction: safeGetCvmUserConfig } = defineAction(CvmUserConfigSchema, async (client, request) => {
|
|
@@ -4267,20 +5520,78 @@ var { action: getCvmUserConfig, safeAction: safeGetCvmUserConfig } = defineActio
|
|
|
4267
5520
|
return await client.get(`/cvms/${cvmId}/user_config`);
|
|
4268
5521
|
});
|
|
4269
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
|
+
|
|
4270
5581
|
// src/actions/apps/get_app_list.ts
|
|
4271
|
-
import { z as
|
|
4272
|
-
var GetAppListRequestSchema =
|
|
4273
|
-
page:
|
|
4274
|
-
page_size:
|
|
4275
|
-
search:
|
|
4276
|
-
status:
|
|
4277
|
-
listed:
|
|
4278
|
-
base_image:
|
|
4279
|
-
instance_type:
|
|
4280
|
-
kms_slug:
|
|
4281
|
-
kms_type:
|
|
4282
|
-
node:
|
|
4283
|
-
region:
|
|
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()
|
|
4284
5595
|
}).strict();
|
|
4285
5596
|
function getSchemaForVersion4(version) {
|
|
4286
5597
|
return version === "2025-10-28" ? DstackAppListResponseV20251028Schema : DstackAppListResponseV20260121Schema;
|
|
@@ -4310,9 +5621,9 @@ async function safeGetAppList(client, request) {
|
|
|
4310
5621
|
}
|
|
4311
5622
|
|
|
4312
5623
|
// src/actions/apps/get_app_info.ts
|
|
4313
|
-
import { z as
|
|
4314
|
-
var GetAppInfoRequestSchema =
|
|
4315
|
-
appId:
|
|
5624
|
+
import { z as z69 } from "zod";
|
|
5625
|
+
var GetAppInfoRequestSchema = z69.object({
|
|
5626
|
+
appId: z69.string().min(1)
|
|
4316
5627
|
}).strict();
|
|
4317
5628
|
function getSchemaForVersion5(version) {
|
|
4318
5629
|
return version === "2025-10-28" ? DstackAppWithCvmResponseV20251028Schema : DstackAppWithCvmResponseV20260121Schema;
|
|
@@ -4342,12 +5653,12 @@ async function safeGetAppInfo(client, request) {
|
|
|
4342
5653
|
}
|
|
4343
5654
|
|
|
4344
5655
|
// src/actions/apps/get_app_cvms.ts
|
|
4345
|
-
import { z as
|
|
4346
|
-
var GetAppCvmsRequestSchema =
|
|
4347
|
-
appId:
|
|
5656
|
+
import { z as z70 } from "zod";
|
|
5657
|
+
var GetAppCvmsRequestSchema = z70.object({
|
|
5658
|
+
appId: z70.string().min(1)
|
|
4348
5659
|
}).strict();
|
|
4349
5660
|
function getSchemaForVersion6(version) {
|
|
4350
|
-
return version === "2025-10-28" ?
|
|
5661
|
+
return version === "2025-10-28" ? z70.array(CvmInfoV20251028Schema) : z70.array(CvmInfoV20260121Schema);
|
|
4351
5662
|
}
|
|
4352
5663
|
async function getAppCvms(client, request) {
|
|
4353
5664
|
const { appId } = GetAppCvmsRequestSchema.parse(request);
|
|
@@ -4373,12 +5684,54 @@ async function safeGetAppCvms(client, request) {
|
|
|
4373
5684
|
}
|
|
4374
5685
|
}
|
|
4375
5686
|
|
|
5687
|
+
// src/actions/apps/get_app_device_allowlist.ts
|
|
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)
|
|
5705
|
+
}).strict();
|
|
5706
|
+
async function getAppDeviceAllowlist(client, request) {
|
|
5707
|
+
const { appId } = GetAppDeviceAllowlistRequestSchema.parse(request);
|
|
5708
|
+
const response = await client.get(`/apps/${appId}/device-allowlist`);
|
|
5709
|
+
return DeviceAllowlistResponseSchema.parse(response);
|
|
5710
|
+
}
|
|
5711
|
+
async function safeGetAppDeviceAllowlist(client, request) {
|
|
5712
|
+
try {
|
|
5713
|
+
const data = await getAppDeviceAllowlist(client, request);
|
|
5714
|
+
return { success: true, data };
|
|
5715
|
+
} catch (error) {
|
|
5716
|
+
if (error && typeof error === "object" && ("status" in error || "issues" in error)) {
|
|
5717
|
+
return { success: false, error };
|
|
5718
|
+
}
|
|
5719
|
+
return {
|
|
5720
|
+
success: false,
|
|
5721
|
+
error: {
|
|
5722
|
+
name: "Error",
|
|
5723
|
+
message: error instanceof Error ? error.message : String(error)
|
|
5724
|
+
}
|
|
5725
|
+
};
|
|
5726
|
+
}
|
|
5727
|
+
}
|
|
5728
|
+
|
|
4376
5729
|
// src/actions/apps/get_app_revisions.ts
|
|
4377
|
-
import { z as
|
|
4378
|
-
var GetAppRevisionsRequestSchema =
|
|
4379
|
-
appId:
|
|
4380
|
-
page:
|
|
4381
|
-
page_size:
|
|
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()
|
|
4382
5735
|
}).strict();
|
|
4383
5736
|
async function getAppRevisions(client, request) {
|
|
4384
5737
|
const { appId, ...params } = GetAppRevisionsRequestSchema.parse(request);
|
|
@@ -4404,11 +5757,11 @@ async function safeGetAppRevisions(client, request) {
|
|
|
4404
5757
|
}
|
|
4405
5758
|
|
|
4406
5759
|
// src/actions/apps/get_app_revision_detail.ts
|
|
4407
|
-
import { z as
|
|
4408
|
-
var GetAppRevisionDetailRequestSchema =
|
|
4409
|
-
appId:
|
|
4410
|
-
revisionId:
|
|
4411
|
-
rawComposeFile:
|
|
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()
|
|
4412
5765
|
}).strict();
|
|
4413
5766
|
async function getAppRevisionDetail(client, request) {
|
|
4414
5767
|
const { appId, revisionId, rawComposeFile } = GetAppRevisionDetailRequestSchema.parse(request);
|
|
@@ -4435,15 +5788,15 @@ async function safeGetAppRevisionDetail(client, request) {
|
|
|
4435
5788
|
}
|
|
4436
5789
|
|
|
4437
5790
|
// src/actions/apps/get_app_filter_options.ts
|
|
4438
|
-
import { z as
|
|
4439
|
-
var AppFilterOptionsSchema =
|
|
4440
|
-
statuses:
|
|
4441
|
-
image_versions:
|
|
4442
|
-
instance_types:
|
|
4443
|
-
kms_slugs:
|
|
4444
|
-
kms_types:
|
|
4445
|
-
regions:
|
|
4446
|
-
nodes:
|
|
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())
|
|
4447
5800
|
});
|
|
4448
5801
|
async function getAppFilterOptions(client) {
|
|
4449
5802
|
const response = await client.get("/apps/filter-options");
|
|
@@ -4467,6 +5820,54 @@ async function safeGetAppFilterOptions(client) {
|
|
|
4467
5820
|
}
|
|
4468
5821
|
}
|
|
4469
5822
|
|
|
5823
|
+
// src/actions/apps/get_app_attestation.ts
|
|
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()
|
|
5839
|
+
}).passthrough().nullable();
|
|
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(),
|
|
5849
|
+
tcb_info: TcbInfoSchema.nullable().optional(),
|
|
5850
|
+
app_certificates: z75.array(CertificateSchema).nullable().optional(),
|
|
5851
|
+
compose_file: z75.string().nullable().optional(),
|
|
5852
|
+
error: z75.string().nullable().optional()
|
|
5853
|
+
});
|
|
5854
|
+
var AppAttestationResponseSchema = z75.object({
|
|
5855
|
+
app_id: z75.string(),
|
|
5856
|
+
contract_address: z75.string(),
|
|
5857
|
+
kms_info: KmsInfoSchema2,
|
|
5858
|
+
instances: z75.array(AppAttestationInstanceSchema),
|
|
5859
|
+
kms_guest_agent_info: GuestAgentInfoSchema,
|
|
5860
|
+
gateway_guest_agent_info: GuestAgentInfoSchema,
|
|
5861
|
+
qemu_version: z75.string().nullable()
|
|
5862
|
+
});
|
|
5863
|
+
var GetAppAttestationRequestSchema = z75.object({
|
|
5864
|
+
appId: z75.string().min(1)
|
|
5865
|
+
}).strict();
|
|
5866
|
+
var { action: getAppAttestation, safeAction: safeGetAppAttestation } = defineAction(AppAttestationResponseSchema, async (client, request) => {
|
|
5867
|
+
const { appId } = GetAppAttestationRequestSchema.parse(request);
|
|
5868
|
+
return await client.get(`/apps/${appId}/attestations`);
|
|
5869
|
+
});
|
|
5870
|
+
|
|
4470
5871
|
// src/parse_dotenv.ts
|
|
4471
5872
|
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
4472
5873
|
function parseEnv(input) {
|
|
@@ -4506,8 +5907,12 @@ import { getComposeHash as getComposeHash2 } from "@phala/dstack-sdk/get-compose
|
|
|
4506
5907
|
import { verifyEnvEncryptPublicKey } from "@phala/dstack-sdk/verify-env-encrypt-public-key";
|
|
4507
5908
|
export {
|
|
4508
5909
|
AddComposeHashSchema,
|
|
5910
|
+
AddDeviceSchema,
|
|
4509
5911
|
AllFamiliesResponseSchema,
|
|
4510
5912
|
ApiErrorSchema,
|
|
5913
|
+
AppAttestationInstanceSchema,
|
|
5914
|
+
AppAttestationResponseSchema,
|
|
5915
|
+
AppCvmsBatchIsAllowedResponseSchema,
|
|
4511
5916
|
AppFilterOptionsSchema,
|
|
4512
5917
|
AppProfileSchema,
|
|
4513
5918
|
AppRevisionDetailResponseSchema,
|
|
@@ -4518,10 +5923,18 @@ export {
|
|
|
4518
5923
|
AvailableNodesSchema,
|
|
4519
5924
|
BillingPeriodSchema,
|
|
4520
5925
|
BusinessError,
|
|
5926
|
+
CertificateIssuerSchema,
|
|
5927
|
+
CertificateSchema,
|
|
5928
|
+
CertificateSubjectSchema,
|
|
5929
|
+
CheckAppCvmsIsAllowedRequestSchema,
|
|
5930
|
+
CheckAppIsAllowedRequestSchema,
|
|
5931
|
+
CheckCvmIsAllowedRequestSchema,
|
|
4521
5932
|
CommitCvmComposeFileUpdateRequestSchema,
|
|
4522
5933
|
CommitCvmComposeFileUpdateSchema,
|
|
4523
5934
|
CommitCvmProvisionRequestSchema,
|
|
4524
5935
|
CommitCvmProvisionSchema,
|
|
5936
|
+
CommitCvmUpdateRequestSchema,
|
|
5937
|
+
ConfirmCvmPatchRequestSchema,
|
|
4525
5938
|
CreateSshKeyRequestSchema,
|
|
4526
5939
|
CreditsInfoSchema,
|
|
4527
5940
|
CurrentUserV20251028Schema as CurrentUserSchema,
|
|
@@ -4563,9 +5976,14 @@ export {
|
|
|
4563
5976
|
DstackAppMinimalResponseV20260121Schema,
|
|
4564
5977
|
DstackAppWithCvmResponseV20251028Schema,
|
|
4565
5978
|
DstackAppWithCvmResponseV20260121Schema,
|
|
5979
|
+
ErrorCodes,
|
|
5980
|
+
EventLogSchema,
|
|
4566
5981
|
FamilyGroupSchema,
|
|
4567
5982
|
FamilyInstanceTypesResponseSchema,
|
|
5983
|
+
GetAllowedDevicesSchema,
|
|
5984
|
+
GetAppAttestationRequestSchema,
|
|
4568
5985
|
GetAppCvmsRequestSchema,
|
|
5986
|
+
GetAppDeviceAllowlistRequestSchema,
|
|
4569
5987
|
GetAppEnvEncryptPubKeyRequestSchema,
|
|
4570
5988
|
GetAppEnvEncryptPubKeySchema,
|
|
4571
5989
|
GetAppInfoRequestSchema,
|
|
@@ -4590,11 +6008,17 @@ export {
|
|
|
4590
6008
|
GetKmsInfoRequestSchema,
|
|
4591
6009
|
GetKmsListRequestSchema,
|
|
4592
6010
|
GetKmsListSchema,
|
|
6011
|
+
GetKmsOnChainDetailRequestSchema,
|
|
6012
|
+
GetKmsOnChainDetailResponseSchema,
|
|
6013
|
+
GetOsImagesRequestSchema,
|
|
6014
|
+
GetOsImagesResponseSchema,
|
|
4593
6015
|
GetWorkspaceNodesSchema,
|
|
4594
6016
|
GetWorkspaceQuotasSchema,
|
|
4595
6017
|
ImportGithubProfileRequestSchema,
|
|
4596
6018
|
ImportGithubProfileResponseSchema,
|
|
6019
|
+
InstanceIdRefreshResultSchema,
|
|
4597
6020
|
InstanceTypeSchema,
|
|
6021
|
+
IsAllowedResultSchema,
|
|
4598
6022
|
KmsInfoSchema,
|
|
4599
6023
|
KmsTypeSchema,
|
|
4600
6024
|
ListFamilyInstanceTypesRequestSchema,
|
|
@@ -4610,27 +6034,40 @@ export {
|
|
|
4610
6034
|
NextAppIdsSchema,
|
|
4611
6035
|
NodeInfoSchema,
|
|
4612
6036
|
NodeRefSchema,
|
|
6037
|
+
OSImagePublicSchema,
|
|
4613
6038
|
OSImageVariantSchema,
|
|
6039
|
+
OnChainDeviceSchema,
|
|
6040
|
+
OnChainKmsContractSchema,
|
|
6041
|
+
OnChainOsImageSchema,
|
|
4614
6042
|
PaginatedCvmInfosV20251028Schema,
|
|
4615
6043
|
PaginatedCvmInfosV20260121Schema,
|
|
4616
6044
|
PaginationMetadataSchema,
|
|
6045
|
+
PatchCvmRequestSchema,
|
|
6046
|
+
PatchCvmResultSchema,
|
|
4617
6047
|
PhalaCloudError,
|
|
4618
6048
|
ProvisionCvmComposeFileUpdateRequestSchema,
|
|
4619
6049
|
ProvisionCvmComposeFileUpdateResultSchema,
|
|
4620
6050
|
ProvisionCvmRequestSchema,
|
|
4621
6051
|
ProvisionCvmSchema,
|
|
4622
6052
|
QuotaMetricSchema,
|
|
6053
|
+
RefreshCvmInstanceIdRequestSchema,
|
|
6054
|
+
RefreshCvmInstanceIdsRequestSchema,
|
|
6055
|
+
RefreshCvmInstanceIdsResponseSchema,
|
|
6056
|
+
RemoveDeviceSchema,
|
|
6057
|
+
ReplicateCvmRequestSchema,
|
|
4623
6058
|
RequestError,
|
|
4624
6059
|
ResourceError,
|
|
4625
6060
|
RestartCvmRequestSchema,
|
|
4626
6061
|
SUPPORTED_API_VERSIONS,
|
|
4627
6062
|
SUPPORTED_CHAINS,
|
|
4628
6063
|
ServerError,
|
|
6064
|
+
SetAllowAnyDeviceSchema,
|
|
4629
6065
|
ShutdownCvmRequestSchema,
|
|
4630
6066
|
SshKeySchema,
|
|
4631
6067
|
StartCvmRequestSchema,
|
|
4632
6068
|
StopCvmRequestSchema,
|
|
4633
6069
|
SyncGithubSshKeysResponseSchema,
|
|
6070
|
+
TcbInfoSchema,
|
|
4634
6071
|
TransactionError,
|
|
4635
6072
|
UnknownError,
|
|
4636
6073
|
UpdateCvmEnvsRequestSchema,
|
|
@@ -4656,13 +6093,22 @@ export {
|
|
|
4656
6093
|
WorkspaceReservedGpuQuotaSchema,
|
|
4657
6094
|
WorkspaceResponseSchema,
|
|
4658
6095
|
addComposeHash,
|
|
6096
|
+
addDevice,
|
|
4659
6097
|
addNetwork,
|
|
4660
6098
|
asHex,
|
|
4661
6099
|
autoCreateClients,
|
|
6100
|
+
checkAppCvmsIsAllowed,
|
|
6101
|
+
checkAppIsAllowed,
|
|
4662
6102
|
checkBalance,
|
|
6103
|
+
checkComposeHashAllowed,
|
|
6104
|
+
checkCvmIsAllowed,
|
|
6105
|
+
checkDeviceAllowed,
|
|
4663
6106
|
checkNetworkStatus,
|
|
6107
|
+
checkOnChainPrerequisites,
|
|
4664
6108
|
commitCvmComposeFileUpdate,
|
|
4665
6109
|
commitCvmProvision,
|
|
6110
|
+
commitCvmUpdate,
|
|
6111
|
+
confirmCvmPatch,
|
|
4666
6112
|
convertToHostname,
|
|
4667
6113
|
createClient as createBaseClient,
|
|
4668
6114
|
createClient2 as createClient,
|
|
@@ -4676,6 +6122,7 @@ export {
|
|
|
4676
6122
|
deleteCvm,
|
|
4677
6123
|
deleteSshKey,
|
|
4678
6124
|
deployAppAuth,
|
|
6125
|
+
dstackAppAbi,
|
|
4679
6126
|
dumpAppCompose,
|
|
4680
6127
|
encryptEnvVars2 as encryptEnvVars,
|
|
4681
6128
|
estimateTransactionGas,
|
|
@@ -4688,7 +6135,10 @@ export {
|
|
|
4688
6135
|
formatValidationErrors,
|
|
4689
6136
|
generateDefaultCvmName,
|
|
4690
6137
|
generateFallbackHostname,
|
|
6138
|
+
getAllowedDevices,
|
|
6139
|
+
getAppAttestation,
|
|
4691
6140
|
getAppCvms,
|
|
6141
|
+
getAppDeviceAllowlist,
|
|
4692
6142
|
getAppEnvEncryptPubKey,
|
|
4693
6143
|
getAppFilterOptions,
|
|
4694
6144
|
getAppInfo,
|
|
@@ -4714,11 +6164,15 @@ export {
|
|
|
4714
6164
|
getErrorMessage,
|
|
4715
6165
|
getKmsInfo,
|
|
4716
6166
|
getKmsList,
|
|
6167
|
+
getKmsOnChainDetail,
|
|
6168
|
+
getOsImages,
|
|
4717
6169
|
getValidationFields,
|
|
4718
6170
|
getWorkspace,
|
|
4719
6171
|
getWorkspaceNodes,
|
|
4720
6172
|
getWorkspaceQuotas,
|
|
4721
6173
|
importGithubProfileSshKeys,
|
|
6174
|
+
isAppIdConflictError,
|
|
6175
|
+
isConflictError,
|
|
4722
6176
|
isValidHostname,
|
|
4723
6177
|
listAllInstanceTypeFamilies,
|
|
4724
6178
|
listFamilyInstanceTypes,
|
|
@@ -4728,19 +6182,36 @@ export {
|
|
|
4728
6182
|
parseApiError,
|
|
4729
6183
|
parseEnv,
|
|
4730
6184
|
parseEnvVars,
|
|
6185
|
+
patchCvm,
|
|
4731
6186
|
preprocessAppCompose,
|
|
4732
6187
|
provisionCvm,
|
|
4733
6188
|
provisionCvmComposeFileUpdate,
|
|
4734
6189
|
refineCvmId,
|
|
6190
|
+
refreshCvmInstanceId,
|
|
6191
|
+
refreshCvmInstanceIds,
|
|
6192
|
+
removeDevice,
|
|
6193
|
+
replicateCvm,
|
|
4735
6194
|
restartCvm,
|
|
4736
6195
|
safeAddComposeHash,
|
|
6196
|
+
safeAddDevice,
|
|
6197
|
+
safeCheckAppCvmsIsAllowed,
|
|
6198
|
+
safeCheckAppIsAllowed,
|
|
6199
|
+
safeCheckComposeHashAllowed,
|
|
6200
|
+
safeCheckCvmIsAllowed,
|
|
6201
|
+
safeCheckDeviceAllowed,
|
|
6202
|
+
safeCheckOnChainPrerequisites,
|
|
4737
6203
|
safeCommitCvmComposeFileUpdate,
|
|
4738
6204
|
safeCommitCvmProvision,
|
|
6205
|
+
safeCommitCvmUpdate,
|
|
6206
|
+
safeConfirmCvmPatch,
|
|
4739
6207
|
safeCreateSshKey,
|
|
4740
6208
|
safeDeleteCvm,
|
|
4741
6209
|
safeDeleteSshKey,
|
|
4742
6210
|
safeDeployAppAuth,
|
|
6211
|
+
safeGetAllowedDevices,
|
|
6212
|
+
safeGetAppAttestation,
|
|
4743
6213
|
safeGetAppCvms,
|
|
6214
|
+
safeGetAppDeviceAllowlist,
|
|
4744
6215
|
safeGetAppEnvEncryptPubKey,
|
|
4745
6216
|
safeGetAppFilterOptions,
|
|
4746
6217
|
safeGetAppInfo,
|
|
@@ -4764,6 +6235,8 @@ export {
|
|
|
4764
6235
|
safeGetCvmUserConfig,
|
|
4765
6236
|
safeGetKmsInfo,
|
|
4766
6237
|
safeGetKmsList,
|
|
6238
|
+
safeGetKmsOnChainDetail,
|
|
6239
|
+
safeGetOsImages,
|
|
4767
6240
|
safeGetWorkspace,
|
|
4768
6241
|
safeGetWorkspaceNodes,
|
|
4769
6242
|
safeGetWorkspaceQuotas,
|
|
@@ -4773,9 +6246,15 @@ export {
|
|
|
4773
6246
|
safeListSshKeys,
|
|
4774
6247
|
safeListWorkspaces,
|
|
4775
6248
|
safeNextAppIds,
|
|
6249
|
+
safePatchCvm,
|
|
4776
6250
|
safeProvisionCvm,
|
|
4777
6251
|
safeProvisionCvmComposeFileUpdate,
|
|
6252
|
+
safeRefreshCvmInstanceId,
|
|
6253
|
+
safeRefreshCvmInstanceIds,
|
|
6254
|
+
safeRemoveDevice,
|
|
6255
|
+
safeReplicateCvm,
|
|
4778
6256
|
safeRestartCvm,
|
|
6257
|
+
safeSetAllowAnyDevice,
|
|
4779
6258
|
safeShutdownCvm,
|
|
4780
6259
|
safeStartCvm,
|
|
4781
6260
|
safeStopCvm,
|
|
@@ -4787,6 +6266,7 @@ export {
|
|
|
4787
6266
|
safeUpdateOsImage,
|
|
4788
6267
|
safeUpdatePreLaunchScript,
|
|
4789
6268
|
safeValidateActionParameters,
|
|
6269
|
+
setAllowAnyDevice,
|
|
4790
6270
|
shutdownCvm,
|
|
4791
6271
|
sortObject,
|
|
4792
6272
|
startCvm,
|