@phala/cloud 0.1.2 → 0.2.1-beta.1
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/cvms/commit_cvm_provision.d.ts +69 -21
- package/dist/actions/cvms/get_available_os_images.d.ts +217 -0
- package/dist/actions/cvms/get_cvm_list.d.ts +16 -16
- package/dist/actions/cvms/get_cvm_state.d.ts +93 -0
- package/dist/actions/cvms/provision_cvm.d.ts +132 -50
- package/dist/actions/cvms/update_os_image.d.ts +61 -0
- package/dist/actions/cvms/watch_cvm_state.d.ts +157 -0
- package/dist/actions/get_available_nodes.d.ts +11 -11
- package/dist/actions/get_current_user.d.ts +11 -11
- package/dist/actions/index.d.ts +6 -1
- package/dist/actions/kms/get_kms_list.d.ts +4 -4
- package/dist/actions/kms/next_app_ids.d.ts +73 -0
- package/dist/actions/list-instance-types.d.ts +295 -90
- package/dist/create-client.d.ts +81 -7
- package/dist/index.js +650 -219
- package/dist/index.mjs +620 -215
- package/dist/utils/define-action.d.ts +8 -8
- package/dist/utils/errors.d.ts +137 -20
- package/dist/utils/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -12,8 +12,11 @@ var ApiErrorSchema = z.object({
|
|
|
12
12
|
z.object({
|
|
13
13
|
msg: z.string(),
|
|
14
14
|
type: z.string().optional(),
|
|
15
|
-
ctx: z.record(z.unknown()).optional()
|
|
16
|
-
|
|
15
|
+
ctx: z.record(z.unknown()).optional(),
|
|
16
|
+
loc: z.array(z.union([z.string(), z.number()])).optional(),
|
|
17
|
+
input: z.unknown().optional()
|
|
18
|
+
}).passthrough()
|
|
19
|
+
// Allow additional fields
|
|
17
20
|
),
|
|
18
21
|
z.record(z.unknown())
|
|
19
22
|
]).optional(),
|
|
@@ -116,6 +119,9 @@ var UnknownError = class extends PhalaCloudError {
|
|
|
116
119
|
}
|
|
117
120
|
};
|
|
118
121
|
function extractFieldPath(loc) {
|
|
122
|
+
if (!loc || !Array.isArray(loc)) {
|
|
123
|
+
return "unknown";
|
|
124
|
+
}
|
|
119
125
|
const filtered = loc.filter((part) => {
|
|
120
126
|
if (typeof part === "string") {
|
|
121
127
|
return !["body", "query", "path", "header"].includes(part);
|
|
@@ -131,12 +137,21 @@ function parseValidationErrors(detail) {
|
|
|
131
137
|
message: typeof detail === "string" ? detail : "Validation error"
|
|
132
138
|
};
|
|
133
139
|
}
|
|
134
|
-
const errors = detail.map(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
const errors = detail.map(
|
|
141
|
+
(item, index) => {
|
|
142
|
+
const field = extractFieldPath(item.loc);
|
|
143
|
+
let displayField = field;
|
|
144
|
+
if (field === "unknown" && item.type) {
|
|
145
|
+
displayField = item.type === "missing" ? "required field" : item.type;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
field: displayField,
|
|
149
|
+
message: item.msg,
|
|
150
|
+
type: item.type,
|
|
151
|
+
context: item.ctx
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
);
|
|
140
155
|
const count = errors.length;
|
|
141
156
|
const message = count === 1 ? `Validation failed: ${errors[0].message}` : `Validation failed (${count} issue${count > 1 ? "s" : ""})`;
|
|
142
157
|
return { errors, message };
|
|
@@ -179,13 +194,21 @@ function parseApiError(requestError) {
|
|
|
179
194
|
const status = requestError.status ?? 0;
|
|
180
195
|
const statusText = requestError.statusText ?? "Unknown Error";
|
|
181
196
|
const detail = requestError.detail;
|
|
197
|
+
const structured = parseStructuredError(detail);
|
|
198
|
+
if (structured) {
|
|
199
|
+
return new ResourceError(structured.message, {
|
|
200
|
+
status,
|
|
201
|
+
statusText,
|
|
202
|
+
detail,
|
|
203
|
+
errorCode: structured.error_code,
|
|
204
|
+
structuredDetails: structured.details,
|
|
205
|
+
suggestions: structured.suggestions,
|
|
206
|
+
links: structured.links
|
|
207
|
+
});
|
|
208
|
+
}
|
|
182
209
|
const errorType = categorizeErrorType(status);
|
|
183
210
|
const message = extractPrimaryMessage(status, detail, requestError.message);
|
|
184
|
-
const commonData = {
|
|
185
|
-
status,
|
|
186
|
-
statusText,
|
|
187
|
-
detail
|
|
188
|
-
};
|
|
211
|
+
const commonData = { status, statusText, detail };
|
|
189
212
|
if (errorType === "validation" && Array.isArray(detail)) {
|
|
190
213
|
const { errors } = parseValidationErrors(detail);
|
|
191
214
|
return new ValidationError(message, {
|
|
@@ -247,6 +270,67 @@ function getErrorMessage(error) {
|
|
|
247
270
|
}
|
|
248
271
|
return "Unknown error occurred";
|
|
249
272
|
}
|
|
273
|
+
var ResourceError = class extends BusinessError {
|
|
274
|
+
constructor(message, data) {
|
|
275
|
+
super(message, data);
|
|
276
|
+
this.isResourceError = true;
|
|
277
|
+
this.errorCode = data.errorCode;
|
|
278
|
+
this.structuredDetails = data.structuredDetails;
|
|
279
|
+
this.suggestions = data.suggestions;
|
|
280
|
+
this.links = data.links;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
function parseStructuredError(detail) {
|
|
284
|
+
if (!detail || typeof detail !== "object") {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
const obj = detail;
|
|
288
|
+
if (obj.error_code && typeof obj.error_code === "string" && obj.message && typeof obj.message === "string") {
|
|
289
|
+
return {
|
|
290
|
+
error_code: obj.error_code,
|
|
291
|
+
message: obj.message,
|
|
292
|
+
details: obj.details,
|
|
293
|
+
suggestions: obj.suggestions,
|
|
294
|
+
links: obj.links
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
function formatStructuredError(error, options) {
|
|
300
|
+
const { showErrorCode = true, showSuggestions = true, showLinks = true } = options ?? {};
|
|
301
|
+
const parts = [];
|
|
302
|
+
if (showErrorCode && error.errorCode) {
|
|
303
|
+
parts.push(`Error [${error.errorCode}]: ${error.message}`);
|
|
304
|
+
} else {
|
|
305
|
+
parts.push(error.message);
|
|
306
|
+
}
|
|
307
|
+
if (error.structuredDetails && error.structuredDetails.length > 0) {
|
|
308
|
+
parts.push("");
|
|
309
|
+
parts.push("Details:");
|
|
310
|
+
error.structuredDetails.forEach((d) => {
|
|
311
|
+
if (d.message) {
|
|
312
|
+
parts.push(` - ${d.message}`);
|
|
313
|
+
} else if (d.field && d.value !== void 0) {
|
|
314
|
+
parts.push(` - ${d.field}: ${d.value}`);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (showSuggestions && error.suggestions && error.suggestions.length > 0) {
|
|
319
|
+
parts.push("");
|
|
320
|
+
parts.push("Suggestions:");
|
|
321
|
+
error.suggestions.forEach((s) => {
|
|
322
|
+
parts.push(` - ${s}`);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (showLinks && error.links && error.links.length > 0) {
|
|
326
|
+
parts.push("");
|
|
327
|
+
parts.push("Learn more:");
|
|
328
|
+
error.links.forEach((link) => {
|
|
329
|
+
parts.push(` - ${link.label}: ${link.url}`);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
return parts.join("\n");
|
|
333
|
+
}
|
|
250
334
|
|
|
251
335
|
// src/client.ts
|
|
252
336
|
var SUPPORTED_API_VERSIONS = ["2025-05-31", "2025-10-28"];
|
|
@@ -804,10 +888,6 @@ var { action: getAvailableNodes, safeAction: safeGetAvailableNodes } = defineSim
|
|
|
804
888
|
|
|
805
889
|
// src/actions/list-instance-types.ts
|
|
806
890
|
import { z as z5 } from "zod";
|
|
807
|
-
var ListInstanceTypesRequestSchema = z5.object({
|
|
808
|
-
page: z5.number().int().min(1).optional().default(1),
|
|
809
|
-
page_size: z5.number().int().min(1).max(1e3).optional().default(100)
|
|
810
|
-
}).strict();
|
|
811
891
|
var InstanceTypeSchema = z5.object({
|
|
812
892
|
id: z5.string(),
|
|
813
893
|
name: z5.string(),
|
|
@@ -816,22 +896,34 @@ var InstanceTypeSchema = z5.object({
|
|
|
816
896
|
memory_mb: z5.number(),
|
|
817
897
|
hourly_rate: z5.string(),
|
|
818
898
|
requires_gpu: z5.boolean(),
|
|
819
|
-
|
|
820
|
-
|
|
899
|
+
default_disk_size_gb: z5.number().default(20),
|
|
900
|
+
family: z5.string().nullable()
|
|
821
901
|
}).passthrough();
|
|
822
|
-
var
|
|
902
|
+
var FamilyGroupSchema = z5.object({
|
|
903
|
+
name: z5.string(),
|
|
904
|
+
items: z5.array(InstanceTypeSchema),
|
|
905
|
+
total: z5.number()
|
|
906
|
+
}).strict();
|
|
907
|
+
var AllFamiliesResponseSchema = z5.object({
|
|
908
|
+
result: z5.array(FamilyGroupSchema)
|
|
909
|
+
}).strict();
|
|
910
|
+
var FamilyInstanceTypesResponseSchema = z5.object({
|
|
823
911
|
items: z5.array(InstanceTypeSchema),
|
|
824
912
|
total: z5.number(),
|
|
825
|
-
|
|
826
|
-
page_size: z5.number(),
|
|
827
|
-
pages: z5.number()
|
|
913
|
+
family: z5.string()
|
|
828
914
|
}).strict();
|
|
829
|
-
var
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
915
|
+
var ListFamilyInstanceTypesRequestSchema = z5.object({
|
|
916
|
+
family: z5.string()
|
|
917
|
+
}).strict();
|
|
918
|
+
var { action: listAllInstanceTypeFamilies, safeAction: safeListAllInstanceTypeFamilies } = defineAction(
|
|
919
|
+
AllFamiliesResponseSchema,
|
|
920
|
+
async (client) => {
|
|
921
|
+
return await client.get("/instance-types");
|
|
922
|
+
}
|
|
923
|
+
);
|
|
924
|
+
var { action: listFamilyInstanceTypes, safeAction: safeListFamilyInstanceTypes } = defineAction(FamilyInstanceTypesResponseSchema, async (client, request) => {
|
|
925
|
+
const validated = ListFamilyInstanceTypesRequestSchema.parse(request);
|
|
926
|
+
return await client.get(`/instance-types/${validated.family}`);
|
|
835
927
|
});
|
|
836
928
|
|
|
837
929
|
// src/actions/workspaces/list_workspaces.ts
|
|
@@ -1051,6 +1143,7 @@ var ProvisionCvmSchema = z10.object({
|
|
|
1051
1143
|
fmspc: z10.string().nullable().optional(),
|
|
1052
1144
|
device_id: z10.string().nullable().optional(),
|
|
1053
1145
|
os_image_hash: z10.string().nullable().optional(),
|
|
1146
|
+
instance_type: z10.string().nullable().optional(),
|
|
1054
1147
|
teepod_id: z10.number().nullable().optional(),
|
|
1055
1148
|
// Will be transformed to node_id
|
|
1056
1149
|
node_id: z10.number().nullable().optional(),
|
|
@@ -1064,19 +1157,24 @@ var ProvisionCvmSchema = z10.object({
|
|
|
1064
1157
|
});
|
|
1065
1158
|
var ProvisionCvmRequestSchema = z10.object({
|
|
1066
1159
|
node_id: z10.number().optional(),
|
|
1067
|
-
// recommended
|
|
1160
|
+
// recommended - optional, system auto-selects if not specified
|
|
1068
1161
|
teepod_id: z10.number().optional(),
|
|
1069
1162
|
// deprecated, for compatibility
|
|
1163
|
+
region: z10.string().optional(),
|
|
1164
|
+
// optional - region filter for auto-selection
|
|
1070
1165
|
name: z10.string(),
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1166
|
+
instance_type: z10.string().default("tdx.small"),
|
|
1167
|
+
// defaults to "tdx.small"
|
|
1168
|
+
image: z10.string().optional(),
|
|
1169
|
+
vcpu: z10.number().optional(),
|
|
1170
|
+
memory: z10.number().optional(),
|
|
1171
|
+
disk_size: z10.number().optional(),
|
|
1075
1172
|
compose_file: z10.object({
|
|
1076
1173
|
allowed_envs: z10.array(z10.string()).optional(),
|
|
1077
1174
|
pre_launch_script: z10.string().optional(),
|
|
1078
1175
|
docker_compose_file: z10.string().optional(),
|
|
1079
|
-
name: z10.string().optional(),
|
|
1176
|
+
name: z10.string().optional().default(""),
|
|
1177
|
+
// optional with default empty string
|
|
1080
1178
|
kms_enabled: z10.boolean().optional(),
|
|
1081
1179
|
public_logs: z10.boolean().optional(),
|
|
1082
1180
|
public_sysinfo: z10.boolean().optional(),
|
|
@@ -1086,8 +1184,11 @@ var ProvisionCvmRequestSchema = z10.object({
|
|
|
1086
1184
|
// deprecated, for compatibility
|
|
1087
1185
|
}),
|
|
1088
1186
|
listed: z10.boolean().optional(),
|
|
1089
|
-
instance_type: z10.string().nullable().optional(),
|
|
1090
1187
|
kms_id: z10.string().optional(),
|
|
1188
|
+
kms: z10.enum(["PHALA", "ETHEREUM", "BASE"]).optional(),
|
|
1189
|
+
// KMS type selection (defaults to PHALA)
|
|
1190
|
+
kms_contract: z10.string().optional(),
|
|
1191
|
+
// KMS contract address for on-chain KMS
|
|
1091
1192
|
env_keys: z10.array(z10.string()).optional()
|
|
1092
1193
|
}).passthrough();
|
|
1093
1194
|
function handleGatewayCompatibility(appCompose) {
|
|
@@ -1112,7 +1213,8 @@ function handleGatewayCompatibility(appCompose) {
|
|
|
1112
1213
|
};
|
|
1113
1214
|
}
|
|
1114
1215
|
var { action: provisionCvm, safeAction: safeProvisionCvm } = defineAction(ProvisionCvmSchema, async (client, appCompose) => {
|
|
1115
|
-
const
|
|
1216
|
+
const validated = ProvisionCvmRequestSchema.parse(appCompose);
|
|
1217
|
+
const body = handleGatewayCompatibility(validated);
|
|
1116
1218
|
let requestBody = { ...body };
|
|
1117
1219
|
if (typeof body.node_id === "number") {
|
|
1118
1220
|
requestBody = { ...body, teepod_id: body.node_id };
|
|
@@ -1156,7 +1258,7 @@ var CommitCvmProvisionSchema = z11.object({
|
|
|
1156
1258
|
var CommitCvmProvisionRequestSchema = z11.object({
|
|
1157
1259
|
encrypted_env: z11.string().optional().nullable(),
|
|
1158
1260
|
app_id: z11.string(),
|
|
1159
|
-
compose_hash: z11.string()
|
|
1261
|
+
compose_hash: z11.string(),
|
|
1160
1262
|
kms_id: z11.string().optional(),
|
|
1161
1263
|
contract_address: z11.string().optional(),
|
|
1162
1264
|
deployer_address: z11.string().optional(),
|
|
@@ -1369,6 +1471,26 @@ var { action: getAppEnvEncryptPubKey, safeAction: safeGetAppEnvEncryptPubKey } =
|
|
|
1369
1471
|
return await client.get(`/kms/${validatedRequest.kms}/pubkey/${validatedRequest.app_id}`);
|
|
1370
1472
|
});
|
|
1371
1473
|
|
|
1474
|
+
// src/actions/kms/next_app_ids.ts
|
|
1475
|
+
import { z as z18 } from "zod";
|
|
1476
|
+
var NextAppIdsRequestSchema = z18.object({
|
|
1477
|
+
counts: z18.number().int().min(1).max(20).optional().default(1)
|
|
1478
|
+
}).strict();
|
|
1479
|
+
var NextAppIdsSchema = z18.object({
|
|
1480
|
+
app_ids: z18.array(
|
|
1481
|
+
z18.object({
|
|
1482
|
+
app_id: z18.string(),
|
|
1483
|
+
nonce: z18.number().int().min(0)
|
|
1484
|
+
})
|
|
1485
|
+
)
|
|
1486
|
+
}).strict();
|
|
1487
|
+
var { action: nextAppIds, safeAction: safeNextAppIds } = defineAction(NextAppIdsSchema, async (client, payload) => {
|
|
1488
|
+
const validatedRequest = NextAppIdsRequestSchema.parse(payload ?? {});
|
|
1489
|
+
const params = new URLSearchParams();
|
|
1490
|
+
params.append("counts", validatedRequest.counts.toString());
|
|
1491
|
+
return await client.get(`/kms/phala/next_app_id?${params.toString()}`);
|
|
1492
|
+
});
|
|
1493
|
+
|
|
1372
1494
|
// src/actions/cvms/start_cvm.ts
|
|
1373
1495
|
var StartCvmRequestSchema = CvmIdSchema;
|
|
1374
1496
|
var { action: startCvm, safeAction: safeStartCvm } = defineAction(VMSchema, async (client, request) => {
|
|
@@ -1394,10 +1516,10 @@ var { action: shutdownCvm, safeAction: safeShutdownCvm } = defineAction(VMSchema
|
|
|
1394
1516
|
});
|
|
1395
1517
|
|
|
1396
1518
|
// src/actions/cvms/restart_cvm.ts
|
|
1397
|
-
import { z as
|
|
1519
|
+
import { z as z19 } from "zod";
|
|
1398
1520
|
var RestartCvmRequestSchema = refineCvmId(
|
|
1399
1521
|
CvmIdObjectSchema.extend({
|
|
1400
|
-
force:
|
|
1522
|
+
force: z19.boolean().optional()
|
|
1401
1523
|
})
|
|
1402
1524
|
);
|
|
1403
1525
|
var { action: restartCvm, safeAction: safeRestartCvm } = defineAction(VMSchema, async (client, request) => {
|
|
@@ -1408,10 +1530,10 @@ var { action: restartCvm, safeAction: safeRestartCvm } = defineAction(VMSchema,
|
|
|
1408
1530
|
});
|
|
1409
1531
|
|
|
1410
1532
|
// src/actions/cvms/delete_cvm.ts
|
|
1411
|
-
import { z as
|
|
1533
|
+
import { z as z20 } from "zod";
|
|
1412
1534
|
var DeleteCvmRequestSchema = CvmIdSchema;
|
|
1413
1535
|
var { action: deleteCvm, safeAction: safeDeleteCvm } = defineAction(
|
|
1414
|
-
|
|
1536
|
+
z20.void(),
|
|
1415
1537
|
async (client, request) => {
|
|
1416
1538
|
const { cvmId } = DeleteCvmRequestSchema.parse(request);
|
|
1417
1539
|
await client.delete(`/cvms/${cvmId}`);
|
|
@@ -1420,41 +1542,41 @@ var { action: deleteCvm, safeAction: safeDeleteCvm } = defineAction(
|
|
|
1420
1542
|
);
|
|
1421
1543
|
|
|
1422
1544
|
// src/actions/cvms/get_cvm_stats.ts
|
|
1423
|
-
import { z as
|
|
1424
|
-
var DiskInfoSchema =
|
|
1425
|
-
name:
|
|
1426
|
-
mount_point:
|
|
1427
|
-
total_size:
|
|
1428
|
-
free_size:
|
|
1545
|
+
import { z as z21 } from "zod";
|
|
1546
|
+
var DiskInfoSchema = z21.object({
|
|
1547
|
+
name: z21.string(),
|
|
1548
|
+
mount_point: z21.string(),
|
|
1549
|
+
total_size: z21.number(),
|
|
1550
|
+
free_size: z21.number()
|
|
1429
1551
|
});
|
|
1430
|
-
var SystemInfoSchema =
|
|
1431
|
-
os_name:
|
|
1432
|
-
os_version:
|
|
1433
|
-
kernel_version:
|
|
1434
|
-
cpu_model:
|
|
1435
|
-
num_cpus:
|
|
1436
|
-
total_memory:
|
|
1437
|
-
available_memory:
|
|
1438
|
-
used_memory:
|
|
1439
|
-
free_memory:
|
|
1440
|
-
total_swap:
|
|
1441
|
-
used_swap:
|
|
1442
|
-
free_swap:
|
|
1443
|
-
uptime:
|
|
1444
|
-
loadavg_one:
|
|
1445
|
-
loadavg_five:
|
|
1446
|
-
loadavg_fifteen:
|
|
1447
|
-
disks:
|
|
1552
|
+
var SystemInfoSchema = z21.object({
|
|
1553
|
+
os_name: z21.string(),
|
|
1554
|
+
os_version: z21.string(),
|
|
1555
|
+
kernel_version: z21.string(),
|
|
1556
|
+
cpu_model: z21.string(),
|
|
1557
|
+
num_cpus: z21.number(),
|
|
1558
|
+
total_memory: z21.number(),
|
|
1559
|
+
available_memory: z21.number(),
|
|
1560
|
+
used_memory: z21.number(),
|
|
1561
|
+
free_memory: z21.number(),
|
|
1562
|
+
total_swap: z21.number(),
|
|
1563
|
+
used_swap: z21.number(),
|
|
1564
|
+
free_swap: z21.number(),
|
|
1565
|
+
uptime: z21.number(),
|
|
1566
|
+
loadavg_one: z21.number(),
|
|
1567
|
+
loadavg_five: z21.number(),
|
|
1568
|
+
loadavg_fifteen: z21.number(),
|
|
1569
|
+
disks: z21.array(DiskInfoSchema)
|
|
1448
1570
|
});
|
|
1449
|
-
var CvmSystemInfoSchema =
|
|
1450
|
-
is_online:
|
|
1451
|
-
is_public:
|
|
1452
|
-
error:
|
|
1571
|
+
var CvmSystemInfoSchema = z21.object({
|
|
1572
|
+
is_online: z21.boolean(),
|
|
1573
|
+
is_public: z21.boolean().default(false),
|
|
1574
|
+
error: z21.string().nullable(),
|
|
1453
1575
|
sysinfo: SystemInfoSchema.nullable(),
|
|
1454
|
-
status:
|
|
1455
|
-
in_progress:
|
|
1456
|
-
boot_progress:
|
|
1457
|
-
boot_error:
|
|
1576
|
+
status: z21.string().nullable(),
|
|
1577
|
+
in_progress: z21.boolean().default(false),
|
|
1578
|
+
boot_progress: z21.string().nullable(),
|
|
1579
|
+
boot_error: z21.string().nullable()
|
|
1458
1580
|
});
|
|
1459
1581
|
var GetCvmStatsRequestSchema = CvmIdSchema;
|
|
1460
1582
|
var { action: getCvmStats, safeAction: safeGetCvmStats } = defineAction(CvmSystemInfoSchema, async (client, request) => {
|
|
@@ -1463,18 +1585,18 @@ var { action: getCvmStats, safeAction: safeGetCvmStats } = defineAction(CvmSyste
|
|
|
1463
1585
|
});
|
|
1464
1586
|
|
|
1465
1587
|
// src/actions/cvms/get_cvm_network.ts
|
|
1466
|
-
import { z as
|
|
1467
|
-
var CvmNetworkUrlsSchema2 =
|
|
1468
|
-
app:
|
|
1469
|
-
instance:
|
|
1588
|
+
import { z as z22 } from "zod";
|
|
1589
|
+
var CvmNetworkUrlsSchema2 = z22.object({
|
|
1590
|
+
app: z22.string(),
|
|
1591
|
+
instance: z22.string()
|
|
1470
1592
|
});
|
|
1471
|
-
var CvmNetworkSchema =
|
|
1472
|
-
is_online:
|
|
1473
|
-
is_public:
|
|
1474
|
-
error:
|
|
1475
|
-
internal_ip:
|
|
1476
|
-
latest_handshake:
|
|
1477
|
-
public_urls:
|
|
1593
|
+
var CvmNetworkSchema = z22.object({
|
|
1594
|
+
is_online: z22.boolean(),
|
|
1595
|
+
is_public: z22.boolean().default(true),
|
|
1596
|
+
error: z22.string().nullable(),
|
|
1597
|
+
internal_ip: z22.string().nullable(),
|
|
1598
|
+
latest_handshake: z22.string().nullable(),
|
|
1599
|
+
public_urls: z22.array(CvmNetworkUrlsSchema2).nullable()
|
|
1478
1600
|
});
|
|
1479
1601
|
var GetCvmNetworkRequestSchema = CvmIdSchema;
|
|
1480
1602
|
var { action: getCvmNetwork, safeAction: safeGetCvmNetwork } = defineAction(CvmNetworkSchema, async (client, request) => {
|
|
@@ -1483,36 +1605,36 @@ var { action: getCvmNetwork, safeAction: safeGetCvmNetwork } = defineAction(CvmN
|
|
|
1483
1605
|
});
|
|
1484
1606
|
|
|
1485
1607
|
// src/actions/cvms/get_cvm_docker_compose.ts
|
|
1486
|
-
import { z as
|
|
1608
|
+
import { z as z23 } from "zod";
|
|
1487
1609
|
var GetCvmDockerComposeRequestSchema = CvmIdSchema;
|
|
1488
|
-
var { action: getCvmDockerCompose, safeAction: safeGetCvmDockerCompose } = defineAction(
|
|
1610
|
+
var { action: getCvmDockerCompose, safeAction: safeGetCvmDockerCompose } = defineAction(z23.string(), async (client, request) => {
|
|
1489
1611
|
const { cvmId } = GetCvmDockerComposeRequestSchema.parse(request);
|
|
1490
1612
|
return await client.get(`/cvms/${cvmId}/docker-compose.yml`);
|
|
1491
1613
|
});
|
|
1492
1614
|
|
|
1493
1615
|
// src/actions/cvms/get_cvm_containers_stats.ts
|
|
1494
|
-
import { z as
|
|
1495
|
-
var ContainerInfoSchema =
|
|
1496
|
-
id:
|
|
1497
|
-
names:
|
|
1498
|
-
image:
|
|
1499
|
-
image_id:
|
|
1500
|
-
command:
|
|
1501
|
-
created:
|
|
1502
|
-
state:
|
|
1503
|
-
status:
|
|
1504
|
-
log_endpoint:
|
|
1616
|
+
import { z as z24 } from "zod";
|
|
1617
|
+
var ContainerInfoSchema = z24.object({
|
|
1618
|
+
id: z24.string(),
|
|
1619
|
+
names: z24.array(z24.string()),
|
|
1620
|
+
image: z24.string(),
|
|
1621
|
+
image_id: z24.string(),
|
|
1622
|
+
command: z24.string().nullable().optional(),
|
|
1623
|
+
created: z24.number(),
|
|
1624
|
+
state: z24.string(),
|
|
1625
|
+
status: z24.string(),
|
|
1626
|
+
log_endpoint: z24.string().nullable()
|
|
1505
1627
|
});
|
|
1506
|
-
var CvmContainersStatsSchema =
|
|
1507
|
-
is_online:
|
|
1508
|
-
is_public:
|
|
1509
|
-
error:
|
|
1510
|
-
docker_compose_file:
|
|
1511
|
-
manifest_version:
|
|
1512
|
-
version:
|
|
1513
|
-
runner:
|
|
1514
|
-
features:
|
|
1515
|
-
containers:
|
|
1628
|
+
var CvmContainersStatsSchema = z24.object({
|
|
1629
|
+
is_online: z24.boolean(),
|
|
1630
|
+
is_public: z24.boolean().default(true),
|
|
1631
|
+
error: z24.string().nullable(),
|
|
1632
|
+
docker_compose_file: z24.string().nullable(),
|
|
1633
|
+
manifest_version: z24.number().nullable(),
|
|
1634
|
+
version: z24.string().nullable(),
|
|
1635
|
+
runner: z24.string().nullable(),
|
|
1636
|
+
features: z24.array(z24.string()).nullable(),
|
|
1637
|
+
containers: z24.array(ContainerInfoSchema).nullable()
|
|
1516
1638
|
});
|
|
1517
1639
|
var GetCvmContainersStatsRequestSchema = CvmIdSchema;
|
|
1518
1640
|
var { action: getCvmContainersStats, safeAction: safeGetCvmContainersStats } = defineAction(CvmContainersStatsSchema, async (client, request) => {
|
|
@@ -1521,62 +1643,62 @@ var { action: getCvmContainersStats, safeAction: safeGetCvmContainersStats } = d
|
|
|
1521
1643
|
});
|
|
1522
1644
|
|
|
1523
1645
|
// src/actions/cvms/get_cvm_attestation.ts
|
|
1524
|
-
import { z as
|
|
1525
|
-
var CertificateSubjectSchema =
|
|
1526
|
-
common_name:
|
|
1527
|
-
organization:
|
|
1528
|
-
country:
|
|
1529
|
-
state:
|
|
1530
|
-
locality:
|
|
1646
|
+
import { z as z25 } from "zod";
|
|
1647
|
+
var CertificateSubjectSchema = z25.object({
|
|
1648
|
+
common_name: z25.string().nullable(),
|
|
1649
|
+
organization: z25.string().nullable(),
|
|
1650
|
+
country: z25.string().nullable(),
|
|
1651
|
+
state: z25.string().nullable(),
|
|
1652
|
+
locality: z25.string().nullable()
|
|
1531
1653
|
});
|
|
1532
|
-
var CertificateIssuerSchema =
|
|
1533
|
-
common_name:
|
|
1534
|
-
organization:
|
|
1535
|
-
country:
|
|
1654
|
+
var CertificateIssuerSchema = z25.object({
|
|
1655
|
+
common_name: z25.string().nullable(),
|
|
1656
|
+
organization: z25.string().nullable(),
|
|
1657
|
+
country: z25.string().nullable()
|
|
1536
1658
|
});
|
|
1537
|
-
var CertificateSchema =
|
|
1659
|
+
var CertificateSchema = z25.object({
|
|
1538
1660
|
subject: CertificateSubjectSchema,
|
|
1539
1661
|
issuer: CertificateIssuerSchema,
|
|
1540
|
-
serial_number:
|
|
1541
|
-
not_before:
|
|
1662
|
+
serial_number: z25.string(),
|
|
1663
|
+
not_before: z25.string(),
|
|
1542
1664
|
// datetime serialized as ISO string
|
|
1543
|
-
not_after:
|
|
1665
|
+
not_after: z25.string(),
|
|
1544
1666
|
// datetime serialized as ISO string
|
|
1545
|
-
version:
|
|
1546
|
-
fingerprint:
|
|
1547
|
-
signature_algorithm:
|
|
1548
|
-
sans:
|
|
1549
|
-
is_ca:
|
|
1550
|
-
position_in_chain:
|
|
1551
|
-
quote:
|
|
1552
|
-
app_id:
|
|
1553
|
-
cert_usage:
|
|
1667
|
+
version: z25.string(),
|
|
1668
|
+
fingerprint: z25.string(),
|
|
1669
|
+
signature_algorithm: z25.string(),
|
|
1670
|
+
sans: z25.array(z25.string()).nullable(),
|
|
1671
|
+
is_ca: z25.boolean(),
|
|
1672
|
+
position_in_chain: z25.number().nullable(),
|
|
1673
|
+
quote: z25.string().nullable(),
|
|
1674
|
+
app_id: z25.string().nullable().optional(),
|
|
1675
|
+
cert_usage: z25.string().nullable().optional()
|
|
1554
1676
|
});
|
|
1555
|
-
var EventLogSchema =
|
|
1556
|
-
imr:
|
|
1557
|
-
event_type:
|
|
1558
|
-
digest:
|
|
1559
|
-
event:
|
|
1560
|
-
event_payload:
|
|
1677
|
+
var EventLogSchema = z25.object({
|
|
1678
|
+
imr: z25.number(),
|
|
1679
|
+
event_type: z25.number(),
|
|
1680
|
+
digest: z25.string(),
|
|
1681
|
+
event: z25.string(),
|
|
1682
|
+
event_payload: z25.string()
|
|
1561
1683
|
});
|
|
1562
|
-
var TcbInfoSchema =
|
|
1563
|
-
mrtd:
|
|
1564
|
-
rootfs_hash:
|
|
1565
|
-
rtmr0:
|
|
1566
|
-
rtmr1:
|
|
1567
|
-
rtmr2:
|
|
1568
|
-
rtmr3:
|
|
1569
|
-
event_log:
|
|
1570
|
-
app_compose:
|
|
1684
|
+
var TcbInfoSchema = z25.object({
|
|
1685
|
+
mrtd: z25.string(),
|
|
1686
|
+
rootfs_hash: z25.string().nullable().optional(),
|
|
1687
|
+
rtmr0: z25.string(),
|
|
1688
|
+
rtmr1: z25.string(),
|
|
1689
|
+
rtmr2: z25.string(),
|
|
1690
|
+
rtmr3: z25.string(),
|
|
1691
|
+
event_log: z25.array(EventLogSchema),
|
|
1692
|
+
app_compose: z25.string()
|
|
1571
1693
|
});
|
|
1572
|
-
var CvmAttestationSchema =
|
|
1573
|
-
name:
|
|
1574
|
-
is_online:
|
|
1575
|
-
is_public:
|
|
1576
|
-
error:
|
|
1577
|
-
app_certificates:
|
|
1694
|
+
var CvmAttestationSchema = z25.object({
|
|
1695
|
+
name: z25.string().nullable(),
|
|
1696
|
+
is_online: z25.boolean(),
|
|
1697
|
+
is_public: z25.boolean().default(true),
|
|
1698
|
+
error: z25.string().nullable(),
|
|
1699
|
+
app_certificates: z25.array(CertificateSchema).nullable(),
|
|
1578
1700
|
tcb_info: TcbInfoSchema.nullable(),
|
|
1579
|
-
compose_file:
|
|
1701
|
+
compose_file: z25.string().nullable()
|
|
1580
1702
|
});
|
|
1581
1703
|
var GetCvmAttestationRequestSchema = CvmIdSchema;
|
|
1582
1704
|
var { action: getCvmAttestation, safeAction: safeGetCvmAttestation } = defineAction(CvmAttestationSchema, async (client, request) => {
|
|
@@ -1585,17 +1707,17 @@ var { action: getCvmAttestation, safeAction: safeGetCvmAttestation } = defineAct
|
|
|
1585
1707
|
});
|
|
1586
1708
|
|
|
1587
1709
|
// src/actions/cvms/update_cvm_resources.ts
|
|
1588
|
-
import { z as
|
|
1710
|
+
import { z as z26 } from "zod";
|
|
1589
1711
|
var UpdateCvmResourcesRequestSchema = refineCvmId(
|
|
1590
1712
|
CvmIdObjectSchema.extend({
|
|
1591
|
-
vcpu:
|
|
1592
|
-
memory:
|
|
1593
|
-
disk_size:
|
|
1594
|
-
instance_type:
|
|
1595
|
-
allow_restart:
|
|
1713
|
+
vcpu: z26.number().optional(),
|
|
1714
|
+
memory: z26.number().optional(),
|
|
1715
|
+
disk_size: z26.number().optional(),
|
|
1716
|
+
instance_type: z26.string().optional(),
|
|
1717
|
+
allow_restart: z26.boolean().optional()
|
|
1596
1718
|
})
|
|
1597
1719
|
);
|
|
1598
|
-
var { action: updateCvmResources, safeAction: safeUpdateCvmResources } = defineAction(
|
|
1720
|
+
var { action: updateCvmResources, safeAction: safeUpdateCvmResources } = defineAction(z26.void(), async (client, request) => {
|
|
1599
1721
|
const parsed = UpdateCvmResourcesRequestSchema.parse(request);
|
|
1600
1722
|
const { cvmId } = CvmIdSchema.parse(parsed);
|
|
1601
1723
|
const { ...body } = parsed;
|
|
@@ -1604,11 +1726,11 @@ var { action: updateCvmResources, safeAction: safeUpdateCvmResources } = defineA
|
|
|
1604
1726
|
});
|
|
1605
1727
|
|
|
1606
1728
|
// src/actions/cvms/update_cvm_visibility.ts
|
|
1607
|
-
import { z as
|
|
1729
|
+
import { z as z27 } from "zod";
|
|
1608
1730
|
var UpdateCvmVisibilityRequestSchema = refineCvmId(
|
|
1609
1731
|
CvmIdObjectSchema.extend({
|
|
1610
|
-
public_sysinfo:
|
|
1611
|
-
public_logs:
|
|
1732
|
+
public_sysinfo: z27.boolean(),
|
|
1733
|
+
public_logs: z27.boolean()
|
|
1612
1734
|
})
|
|
1613
1735
|
);
|
|
1614
1736
|
var { action: updateCvmVisibility, safeAction: safeUpdateCvmVisibility } = defineAction(CvmLegacyDetailSchema, async (client, request) => {
|
|
@@ -1618,6 +1740,59 @@ var { action: updateCvmVisibility, safeAction: safeUpdateCvmVisibility } = defin
|
|
|
1618
1740
|
return await client.patch(`/cvms/${cvmId}/visibility`, { public_sysinfo, public_logs });
|
|
1619
1741
|
});
|
|
1620
1742
|
|
|
1743
|
+
// src/actions/cvms/get_available_os_images.ts
|
|
1744
|
+
import { z as z28 } from "zod";
|
|
1745
|
+
var OSImageVariantSchema = z28.object({
|
|
1746
|
+
name: z28.string(),
|
|
1747
|
+
os_image_hash: z28.string().nullable(),
|
|
1748
|
+
is_current: z28.boolean()
|
|
1749
|
+
});
|
|
1750
|
+
var AvailableOSImageSchema2 = z28.object({
|
|
1751
|
+
version: z28.union([
|
|
1752
|
+
z28.tuple([z28.number(), z28.number(), z28.number(), z28.number()]),
|
|
1753
|
+
z28.tuple([z28.number(), z28.number(), z28.number()])
|
|
1754
|
+
]),
|
|
1755
|
+
prod: OSImageVariantSchema.nullable(),
|
|
1756
|
+
dev: OSImageVariantSchema.nullable()
|
|
1757
|
+
});
|
|
1758
|
+
var GetAvailableOSImagesResponseSchema = z28.array(AvailableOSImageSchema2);
|
|
1759
|
+
var GetAvailableOSImagesRequestSchema = CvmIdSchema;
|
|
1760
|
+
var { action: getAvailableOsImages, safeAction: safeGetAvailableOsImages } = defineAction(GetAvailableOSImagesResponseSchema, async (client, request) => {
|
|
1761
|
+
const { cvmId } = GetAvailableOSImagesRequestSchema.parse(request);
|
|
1762
|
+
return await client.get(`/cvms/${cvmId}/available-os-images`);
|
|
1763
|
+
});
|
|
1764
|
+
|
|
1765
|
+
// src/actions/cvms/update_os_image.ts
|
|
1766
|
+
import { z as z29 } from "zod";
|
|
1767
|
+
var UpdateOsImageRequestSchema = refineCvmId(
|
|
1768
|
+
CvmIdObjectSchema.extend({
|
|
1769
|
+
os_image_name: z29.string().min(1, "OS image name is required")
|
|
1770
|
+
})
|
|
1771
|
+
);
|
|
1772
|
+
var { action: updateOsImage, safeAction: safeUpdateOsImage } = defineAction(z29.void(), async (client, request) => {
|
|
1773
|
+
const parsed = UpdateOsImageRequestSchema.parse(request);
|
|
1774
|
+
const { cvmId } = CvmIdSchema.parse(parsed);
|
|
1775
|
+
const { os_image_name } = parsed;
|
|
1776
|
+
await client.patch(`/cvms/${cvmId}/os-image`, { os_image_name });
|
|
1777
|
+
return void 0;
|
|
1778
|
+
});
|
|
1779
|
+
|
|
1780
|
+
// src/actions/cvms/get_cvm_state.ts
|
|
1781
|
+
import { z as z30 } from "zod";
|
|
1782
|
+
var CvmStateSchema = z30.object({
|
|
1783
|
+
status: z30.string(),
|
|
1784
|
+
derived_status: z30.string().optional(),
|
|
1785
|
+
vm_uuid: z30.string().optional(),
|
|
1786
|
+
instance_id: z30.string().optional(),
|
|
1787
|
+
uptime: z30.string().optional()
|
|
1788
|
+
// Add other state fields as needed
|
|
1789
|
+
});
|
|
1790
|
+
var GetCvmStateRequestSchema = CvmIdSchema;
|
|
1791
|
+
var { action: getCvmState, safeAction: safeGetCvmState } = defineAction(CvmStateSchema, async (client, request) => {
|
|
1792
|
+
const { cvmId } = GetCvmStateRequestSchema.parse(request);
|
|
1793
|
+
return await client.get(`/cvms/${cvmId}/state`);
|
|
1794
|
+
});
|
|
1795
|
+
|
|
1621
1796
|
// src/create-client.ts
|
|
1622
1797
|
function createClient2(config = {}) {
|
|
1623
1798
|
const client = createClient(config);
|
|
@@ -1626,8 +1801,10 @@ function createClient2(config = {}) {
|
|
|
1626
1801
|
safeGetCurrentUser,
|
|
1627
1802
|
getAvailableNodes,
|
|
1628
1803
|
safeGetAvailableNodes,
|
|
1629
|
-
|
|
1630
|
-
|
|
1804
|
+
listAllInstanceTypeFamilies,
|
|
1805
|
+
safeListAllInstanceTypeFamilies,
|
|
1806
|
+
listFamilyInstanceTypes,
|
|
1807
|
+
safeListFamilyInstanceTypes,
|
|
1631
1808
|
listWorkspaces,
|
|
1632
1809
|
safeListWorkspaces,
|
|
1633
1810
|
getWorkspace,
|
|
@@ -1670,18 +1847,26 @@ function createClient2(config = {}) {
|
|
|
1670
1847
|
safeUpdateCvmResources,
|
|
1671
1848
|
updateCvmVisibility,
|
|
1672
1849
|
safeUpdateCvmVisibility,
|
|
1850
|
+
getAvailableOsImages,
|
|
1851
|
+
safeGetAvailableOsImages,
|
|
1852
|
+
updateOsImage,
|
|
1853
|
+
safeUpdateOsImage,
|
|
1673
1854
|
getKmsInfo,
|
|
1674
1855
|
safeGetKmsInfo,
|
|
1675
1856
|
getKmsList,
|
|
1676
1857
|
safeGetKmsList,
|
|
1677
1858
|
getAppEnvEncryptPubKey,
|
|
1678
|
-
safeGetAppEnvEncryptPubKey
|
|
1859
|
+
safeGetAppEnvEncryptPubKey,
|
|
1860
|
+
nextAppIds,
|
|
1861
|
+
safeNextAppIds,
|
|
1862
|
+
getCvmState,
|
|
1863
|
+
safeGetCvmState
|
|
1679
1864
|
};
|
|
1680
1865
|
return client.extend(allActions);
|
|
1681
1866
|
}
|
|
1682
1867
|
|
|
1683
1868
|
// src/actions/blockchains/deploy_app_auth.ts
|
|
1684
|
-
import { z as
|
|
1869
|
+
import { z as z31 } from "zod";
|
|
1685
1870
|
import {
|
|
1686
1871
|
createPublicClient as createPublicClient2,
|
|
1687
1872
|
createWalletClient as createWalletClient2,
|
|
@@ -2342,25 +2527,25 @@ var kmsAuthAbi = [
|
|
|
2342
2527
|
anonymous: false
|
|
2343
2528
|
}
|
|
2344
2529
|
];
|
|
2345
|
-
var DeployAppAuthRequestBaseSchema =
|
|
2530
|
+
var DeployAppAuthRequestBaseSchema = z31.object({
|
|
2346
2531
|
// Chain configuration (conditionally required)
|
|
2347
|
-
chain:
|
|
2348
|
-
rpcUrl:
|
|
2532
|
+
chain: z31.unknown().optional(),
|
|
2533
|
+
rpcUrl: z31.string().optional(),
|
|
2349
2534
|
// Contract configuration (required)
|
|
2350
|
-
kmsContractAddress:
|
|
2535
|
+
kmsContractAddress: z31.string(),
|
|
2351
2536
|
// Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
|
|
2352
|
-
privateKey:
|
|
2353
|
-
walletClient:
|
|
2537
|
+
privateKey: z31.string().optional(),
|
|
2538
|
+
walletClient: z31.unknown().optional(),
|
|
2354
2539
|
// Public client (optional, will create default if not provided)
|
|
2355
|
-
publicClient:
|
|
2540
|
+
publicClient: z31.unknown().optional(),
|
|
2356
2541
|
// App configuration (optional)
|
|
2357
|
-
allowAnyDevice:
|
|
2358
|
-
deviceId:
|
|
2359
|
-
composeHash:
|
|
2360
|
-
disableUpgrades:
|
|
2542
|
+
allowAnyDevice: z31.boolean().optional().default(false),
|
|
2543
|
+
deviceId: z31.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
|
|
2544
|
+
composeHash: z31.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
|
|
2545
|
+
disableUpgrades: z31.boolean().optional().default(false),
|
|
2361
2546
|
// Validation configuration (optional)
|
|
2362
|
-
skipPrerequisiteChecks:
|
|
2363
|
-
minBalance:
|
|
2547
|
+
skipPrerequisiteChecks: z31.boolean().optional().default(false),
|
|
2548
|
+
minBalance: z31.string().optional()
|
|
2364
2549
|
// ETH amount as string, e.g., "0.01"
|
|
2365
2550
|
}).passthrough();
|
|
2366
2551
|
var DeployAppAuthRequestSchema = DeployAppAuthRequestBaseSchema.refine(
|
|
@@ -2388,13 +2573,13 @@ var DeployAppAuthRequestSchema = DeployAppAuthRequestBaseSchema.refine(
|
|
|
2388
2573
|
path: ["chain"]
|
|
2389
2574
|
}
|
|
2390
2575
|
);
|
|
2391
|
-
var DeployAppAuthSchema =
|
|
2392
|
-
appId:
|
|
2393
|
-
appAuthAddress:
|
|
2394
|
-
deployer:
|
|
2395
|
-
transactionHash:
|
|
2396
|
-
blockNumber:
|
|
2397
|
-
gasUsed:
|
|
2576
|
+
var DeployAppAuthSchema = z31.object({
|
|
2577
|
+
appId: z31.string(),
|
|
2578
|
+
appAuthAddress: z31.string(),
|
|
2579
|
+
deployer: z31.string(),
|
|
2580
|
+
transactionHash: z31.string(),
|
|
2581
|
+
blockNumber: z31.bigint().optional(),
|
|
2582
|
+
gasUsed: z31.bigint().optional()
|
|
2398
2583
|
}).passthrough();
|
|
2399
2584
|
function parseDeploymentResult(receipt, deployer, kmsContractAddress) {
|
|
2400
2585
|
try {
|
|
@@ -2640,7 +2825,7 @@ async function safeDeployAppAuth(request, parameters) {
|
|
|
2640
2825
|
}
|
|
2641
2826
|
|
|
2642
2827
|
// src/actions/blockchains/add_compose_hash.ts
|
|
2643
|
-
import { z as
|
|
2828
|
+
import { z as z32 } from "zod";
|
|
2644
2829
|
import {
|
|
2645
2830
|
createPublicClient as createPublicClient3,
|
|
2646
2831
|
createWalletClient as createWalletClient3,
|
|
@@ -2664,29 +2849,29 @@ var appAuthAbi = [
|
|
|
2664
2849
|
anonymous: false
|
|
2665
2850
|
}
|
|
2666
2851
|
];
|
|
2667
|
-
var AddComposeHashRequestSchema =
|
|
2852
|
+
var AddComposeHashRequestSchema = z32.object({
|
|
2668
2853
|
// Chain configuration (conditionally required)
|
|
2669
|
-
chain:
|
|
2670
|
-
rpcUrl:
|
|
2671
|
-
appId:
|
|
2672
|
-
composeHash:
|
|
2854
|
+
chain: z32.unknown().optional(),
|
|
2855
|
+
rpcUrl: z32.string().optional(),
|
|
2856
|
+
appId: z32.string(),
|
|
2857
|
+
composeHash: z32.string(),
|
|
2673
2858
|
// Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
|
|
2674
|
-
privateKey:
|
|
2675
|
-
walletClient:
|
|
2859
|
+
privateKey: z32.string().optional(),
|
|
2860
|
+
walletClient: z32.unknown().optional(),
|
|
2676
2861
|
// Public client (optional, will create default if not provided)
|
|
2677
|
-
publicClient:
|
|
2862
|
+
publicClient: z32.unknown().optional(),
|
|
2678
2863
|
// Validation configuration (optional)
|
|
2679
|
-
skipPrerequisiteChecks:
|
|
2680
|
-
minBalance:
|
|
2864
|
+
skipPrerequisiteChecks: z32.boolean().optional().default(false),
|
|
2865
|
+
minBalance: z32.string().optional(),
|
|
2681
2866
|
// ETH amount as string, e.g., "0.01"
|
|
2682
2867
|
// Transaction control options
|
|
2683
|
-
timeout:
|
|
2684
|
-
retryOptions:
|
|
2685
|
-
signal:
|
|
2868
|
+
timeout: z32.number().optional().default(12e4),
|
|
2869
|
+
retryOptions: z32.unknown().optional(),
|
|
2870
|
+
signal: z32.unknown().optional(),
|
|
2686
2871
|
// Progress callbacks
|
|
2687
|
-
onTransactionStateChange:
|
|
2688
|
-
onTransactionSubmitted:
|
|
2689
|
-
onTransactionConfirmed:
|
|
2872
|
+
onTransactionStateChange: z32.function().optional(),
|
|
2873
|
+
onTransactionSubmitted: z32.function().optional(),
|
|
2874
|
+
onTransactionConfirmed: z32.function().optional()
|
|
2690
2875
|
}).passthrough().refine(
|
|
2691
2876
|
(data) => {
|
|
2692
2877
|
const hasPrivateKey = !!data.privateKey;
|
|
@@ -2710,12 +2895,12 @@ var AddComposeHashRequestSchema = z28.object({
|
|
|
2710
2895
|
path: ["chain"]
|
|
2711
2896
|
}
|
|
2712
2897
|
);
|
|
2713
|
-
var AddComposeHashSchema =
|
|
2714
|
-
composeHash:
|
|
2715
|
-
appId:
|
|
2716
|
-
transactionHash:
|
|
2717
|
-
blockNumber:
|
|
2718
|
-
gasUsed:
|
|
2898
|
+
var AddComposeHashSchema = z32.object({
|
|
2899
|
+
composeHash: z32.string(),
|
|
2900
|
+
appId: z32.string(),
|
|
2901
|
+
transactionHash: z32.string(),
|
|
2902
|
+
blockNumber: z32.bigint().optional(),
|
|
2903
|
+
gasUsed: z32.bigint().optional()
|
|
2719
2904
|
}).passthrough();
|
|
2720
2905
|
function parseComposeHashResult(receipt, composeHash, appAuthAddress, appId) {
|
|
2721
2906
|
console.log(receipt.logs);
|
|
@@ -2906,6 +3091,200 @@ async function safeAddComposeHash(request, parameters) {
|
|
|
2906
3091
|
}
|
|
2907
3092
|
}
|
|
2908
3093
|
|
|
3094
|
+
// src/actions/cvms/watch_cvm_state.ts
|
|
3095
|
+
import { z as z33 } from "zod";
|
|
3096
|
+
var WatchCvmStateParamsSchema = z33.object({
|
|
3097
|
+
target: z33.string().describe("Target status to wait for (e.g., 'running', 'stopped')"),
|
|
3098
|
+
interval: z33.number().min(5).max(30).default(5).describe("Polling interval in seconds"),
|
|
3099
|
+
timeout: z33.number().min(10).max(600).default(300).describe("Timeout per attempt in seconds"),
|
|
3100
|
+
maxRetries: z33.number().min(0).default(Number.POSITIVE_INFINITY).describe("Maximum number of retry attempts (Infinity for unlimited)"),
|
|
3101
|
+
retryDelay: z33.number().min(0).default(5e3).describe("Delay between retries in milliseconds")
|
|
3102
|
+
});
|
|
3103
|
+
var WatchCvmStateRequestSchema = WatchCvmStateParamsSchema;
|
|
3104
|
+
var WatchAbortedError = class extends Error {
|
|
3105
|
+
constructor() {
|
|
3106
|
+
super("Watch operation was aborted");
|
|
3107
|
+
this.name = "WatchAbortedError";
|
|
3108
|
+
}
|
|
3109
|
+
};
|
|
3110
|
+
var MaxRetriesExceededError = class extends Error {
|
|
3111
|
+
constructor(attempts) {
|
|
3112
|
+
super(`Maximum retry attempts (${attempts}) exceeded`);
|
|
3113
|
+
this.attempts = attempts;
|
|
3114
|
+
this.name = "MaxRetriesExceededError";
|
|
3115
|
+
}
|
|
3116
|
+
};
|
|
3117
|
+
function parseSSEEvent(eventType, data) {
|
|
3118
|
+
try {
|
|
3119
|
+
const parsed = JSON.parse(data);
|
|
3120
|
+
return { type: eventType, data: parsed };
|
|
3121
|
+
} catch {
|
|
3122
|
+
return { type: "error", data: { error: "Failed to parse SSE event" } };
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
async function watchCvmState(client, request, options = {}) {
|
|
3126
|
+
const { cvmId } = CvmIdSchema.parse(request);
|
|
3127
|
+
const { target, interval, timeout, maxRetries, retryDelay } = WatchCvmStateParamsSchema.parse(request);
|
|
3128
|
+
const { signal, onEvent } = options;
|
|
3129
|
+
let attempt = 0;
|
|
3130
|
+
while (attempt < maxRetries) {
|
|
3131
|
+
if (signal?.aborted) {
|
|
3132
|
+
throw new WatchAbortedError();
|
|
3133
|
+
}
|
|
3134
|
+
attempt++;
|
|
3135
|
+
try {
|
|
3136
|
+
const result = await watchSingleAttempt(
|
|
3137
|
+
client,
|
|
3138
|
+
cvmId,
|
|
3139
|
+
target,
|
|
3140
|
+
interval,
|
|
3141
|
+
timeout,
|
|
3142
|
+
signal,
|
|
3143
|
+
onEvent
|
|
3144
|
+
);
|
|
3145
|
+
if (result) {
|
|
3146
|
+
return result;
|
|
3147
|
+
}
|
|
3148
|
+
if (attempt >= maxRetries) {
|
|
3149
|
+
throw new MaxRetriesExceededError(attempt);
|
|
3150
|
+
}
|
|
3151
|
+
await sleep(retryDelay, signal);
|
|
3152
|
+
} catch (error) {
|
|
3153
|
+
if (signal?.aborted) {
|
|
3154
|
+
throw new WatchAbortedError();
|
|
3155
|
+
}
|
|
3156
|
+
if (error instanceof WatchAbortedError || error instanceof MaxRetriesExceededError) {
|
|
3157
|
+
throw error;
|
|
3158
|
+
}
|
|
3159
|
+
if (attempt >= maxRetries) {
|
|
3160
|
+
throw error;
|
|
3161
|
+
}
|
|
3162
|
+
if (onEvent) {
|
|
3163
|
+
onEvent({
|
|
3164
|
+
type: "error",
|
|
3165
|
+
data: { error: error instanceof Error ? error.message : String(error) }
|
|
3166
|
+
});
|
|
3167
|
+
}
|
|
3168
|
+
await sleep(retryDelay, signal);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
throw new MaxRetriesExceededError(attempt);
|
|
3172
|
+
}
|
|
3173
|
+
async function watchSingleAttempt(client, cvmId, target, interval, timeout, signal, onEvent) {
|
|
3174
|
+
const params = new URLSearchParams({
|
|
3175
|
+
target,
|
|
3176
|
+
interval: String(interval),
|
|
3177
|
+
timeout: String(timeout)
|
|
3178
|
+
});
|
|
3179
|
+
const baseURL = client.config.baseURL || "";
|
|
3180
|
+
const fullUrl = `${baseURL}/cvms/${cvmId}/state?${params.toString()}`;
|
|
3181
|
+
const headers = {
|
|
3182
|
+
Accept: "text/event-stream",
|
|
3183
|
+
"Cache-Control": "no-cache"
|
|
3184
|
+
};
|
|
3185
|
+
if (!client.config.useCookieAuth && client.config.apiKey) {
|
|
3186
|
+
headers["X-API-Key"] = client.config.apiKey;
|
|
3187
|
+
}
|
|
3188
|
+
if (client.config.headers) {
|
|
3189
|
+
Object.entries(client.config.headers).forEach(([key, value]) => {
|
|
3190
|
+
if (typeof value === "string") {
|
|
3191
|
+
headers[key] = value;
|
|
3192
|
+
}
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
const response = await client.raw.native(fullUrl, {
|
|
3196
|
+
method: "GET",
|
|
3197
|
+
headers,
|
|
3198
|
+
signal,
|
|
3199
|
+
...client.config.useCookieAuth ? { credentials: "include" } : {}
|
|
3200
|
+
});
|
|
3201
|
+
if (!response.ok) {
|
|
3202
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
3203
|
+
}
|
|
3204
|
+
if (!response.body) {
|
|
3205
|
+
throw new Error("Response body is null");
|
|
3206
|
+
}
|
|
3207
|
+
return parseSSEStream(response.body, signal, onEvent);
|
|
3208
|
+
}
|
|
3209
|
+
async function parseSSEStream(stream, signal, onEvent) {
|
|
3210
|
+
const reader = stream.getReader();
|
|
3211
|
+
const decoder = new TextDecoder();
|
|
3212
|
+
let buffer = "";
|
|
3213
|
+
let finalState = null;
|
|
3214
|
+
let currentEvent = "";
|
|
3215
|
+
let currentData = "";
|
|
3216
|
+
const processLine = (line) => {
|
|
3217
|
+
if (line.startsWith("event:")) {
|
|
3218
|
+
currentEvent = line.slice(6).trim();
|
|
3219
|
+
} else if (line.startsWith("data:")) {
|
|
3220
|
+
currentData = line.slice(5).trim();
|
|
3221
|
+
} else if (line === "") {
|
|
3222
|
+
if (currentEvent && currentData) {
|
|
3223
|
+
const event = parseSSEEvent(currentEvent, currentData);
|
|
3224
|
+
if (event.type === "state") {
|
|
3225
|
+
finalState = event.data;
|
|
3226
|
+
}
|
|
3227
|
+
onEvent?.(event);
|
|
3228
|
+
if (event.type === "complete") {
|
|
3229
|
+
return "complete";
|
|
3230
|
+
}
|
|
3231
|
+
if (event.type === "timeout") {
|
|
3232
|
+
return "timeout";
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
currentEvent = "";
|
|
3236
|
+
currentData = "";
|
|
3237
|
+
}
|
|
3238
|
+
return null;
|
|
3239
|
+
};
|
|
3240
|
+
try {
|
|
3241
|
+
while (true) {
|
|
3242
|
+
if (signal?.aborted) {
|
|
3243
|
+
throw new WatchAbortedError();
|
|
3244
|
+
}
|
|
3245
|
+
const { done, value } = await reader.read();
|
|
3246
|
+
if (done) {
|
|
3247
|
+
break;
|
|
3248
|
+
}
|
|
3249
|
+
buffer += decoder.decode(value, { stream: true });
|
|
3250
|
+
const lines = buffer.split("\n");
|
|
3251
|
+
buffer = lines.pop() || "";
|
|
3252
|
+
for (const line of lines) {
|
|
3253
|
+
const result = processLine(line.trim());
|
|
3254
|
+
if (result === "complete") {
|
|
3255
|
+
return finalState;
|
|
3256
|
+
}
|
|
3257
|
+
if (result === "timeout") {
|
|
3258
|
+
return null;
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
return finalState;
|
|
3263
|
+
} catch (error) {
|
|
3264
|
+
if (error instanceof WatchAbortedError) {
|
|
3265
|
+
throw error;
|
|
3266
|
+
}
|
|
3267
|
+
throw new Error(`SSE stream error: ${error instanceof Error ? error.message : String(error)}`);
|
|
3268
|
+
} finally {
|
|
3269
|
+
reader.releaseLock();
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
function sleep(ms, signal) {
|
|
3273
|
+
return new Promise((resolve, reject) => {
|
|
3274
|
+
if (signal?.aborted) {
|
|
3275
|
+
reject(new WatchAbortedError());
|
|
3276
|
+
return;
|
|
3277
|
+
}
|
|
3278
|
+
const timer = setTimeout(resolve, ms);
|
|
3279
|
+
if (signal) {
|
|
3280
|
+
signal.addEventListener("abort", () => {
|
|
3281
|
+
clearTimeout(timer);
|
|
3282
|
+
reject(new WatchAbortedError());
|
|
3283
|
+
});
|
|
3284
|
+
}
|
|
3285
|
+
});
|
|
3286
|
+
}
|
|
3287
|
+
|
|
2909
3288
|
// src/parse_dotenv.ts
|
|
2910
3289
|
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
2911
3290
|
function parseEnv(input) {
|
|
@@ -2945,6 +3324,7 @@ import { getComposeHash as getComposeHash2 } from "@phala/dstack-sdk/get-compose
|
|
|
2945
3324
|
import { verifyEnvEncryptPublicKey } from "@phala/dstack-sdk/verify-env-encrypt-public-key";
|
|
2946
3325
|
export {
|
|
2947
3326
|
AddComposeHashSchema,
|
|
3327
|
+
AllFamiliesResponseSchema,
|
|
2948
3328
|
ApiErrorSchema,
|
|
2949
3329
|
AuthError,
|
|
2950
3330
|
AvailableNodesSchema,
|
|
@@ -2964,12 +3344,17 @@ export {
|
|
|
2964
3344
|
CvmNetworkSchema,
|
|
2965
3345
|
CvmNetworkUrlsSchema,
|
|
2966
3346
|
CvmNodeSchema,
|
|
3347
|
+
CvmStateSchema,
|
|
2967
3348
|
CvmSystemInfoSchema,
|
|
2968
3349
|
DeleteCvmRequestSchema,
|
|
2969
3350
|
DeployAppAuthRequestSchema,
|
|
2970
3351
|
DeployAppAuthSchema,
|
|
3352
|
+
FamilyGroupSchema,
|
|
3353
|
+
FamilyInstanceTypesResponseSchema,
|
|
2971
3354
|
GetAppEnvEncryptPubKeyRequestSchema,
|
|
2972
3355
|
GetAppEnvEncryptPubKeySchema,
|
|
3356
|
+
GetAvailableOSImagesRequestSchema,
|
|
3357
|
+
GetAvailableOSImagesResponseSchema,
|
|
2973
3358
|
GetCvmAttestationRequestSchema,
|
|
2974
3359
|
GetCvmComposeFileRequestSchema,
|
|
2975
3360
|
GetCvmContainersStatsRequestSchema,
|
|
@@ -2978,17 +3363,21 @@ export {
|
|
|
2978
3363
|
GetCvmListRequestSchema,
|
|
2979
3364
|
GetCvmListSchema,
|
|
2980
3365
|
GetCvmNetworkRequestSchema,
|
|
3366
|
+
GetCvmStateRequestSchema,
|
|
2981
3367
|
GetCvmStatsRequestSchema,
|
|
2982
3368
|
GetKmsInfoRequestSchema,
|
|
2983
3369
|
GetKmsListRequestSchema,
|
|
2984
3370
|
GetKmsListSchema,
|
|
2985
3371
|
InstanceTypeSchema,
|
|
2986
3372
|
KmsInfoSchema,
|
|
2987
|
-
|
|
3373
|
+
ListFamilyInstanceTypesRequestSchema,
|
|
2988
3374
|
ListWorkspacesSchema,
|
|
2989
3375
|
ManagedUserSchema,
|
|
3376
|
+
MaxRetriesExceededError,
|
|
2990
3377
|
NetworkError,
|
|
2991
|
-
|
|
3378
|
+
NextAppIdsRequestSchema,
|
|
3379
|
+
NextAppIdsSchema,
|
|
3380
|
+
OSImageVariantSchema,
|
|
2992
3381
|
PaginationMetadataSchema,
|
|
2993
3382
|
PhalaCloudError,
|
|
2994
3383
|
ProvisionCvmComposeFileUpdateRequestSchema,
|
|
@@ -2996,6 +3385,7 @@ export {
|
|
|
2996
3385
|
ProvisionCvmRequestSchema,
|
|
2997
3386
|
ProvisionCvmSchema,
|
|
2998
3387
|
RequestError,
|
|
3388
|
+
ResourceError,
|
|
2999
3389
|
RestartCvmRequestSchema,
|
|
3000
3390
|
SUPPORTED_CHAINS,
|
|
3001
3391
|
ServerError,
|
|
@@ -3006,10 +3396,13 @@ export {
|
|
|
3006
3396
|
UnknownError,
|
|
3007
3397
|
UpdateCvmResourcesRequestSchema,
|
|
3008
3398
|
UpdateCvmVisibilityRequestSchema,
|
|
3399
|
+
UpdateOsImageRequestSchema,
|
|
3009
3400
|
VMSchema,
|
|
3010
3401
|
ValidationError,
|
|
3011
3402
|
VmInfoSchema,
|
|
3012
3403
|
WalletError,
|
|
3404
|
+
WatchAbortedError,
|
|
3405
|
+
WatchCvmStateRequestSchema,
|
|
3013
3406
|
WorkspaceResponseSchema,
|
|
3014
3407
|
addComposeHash,
|
|
3015
3408
|
addNetwork,
|
|
@@ -3037,9 +3430,11 @@ export {
|
|
|
3037
3430
|
executeTransactionWithRetry,
|
|
3038
3431
|
extractNetworkClients,
|
|
3039
3432
|
formatErrorMessage,
|
|
3433
|
+
formatStructuredError,
|
|
3040
3434
|
formatValidationErrors,
|
|
3041
3435
|
getAppEnvEncryptPubKey,
|
|
3042
3436
|
getAvailableNodes,
|
|
3437
|
+
getAvailableOsImages,
|
|
3043
3438
|
getComposeHash2 as getComposeHash,
|
|
3044
3439
|
getCurrentUser,
|
|
3045
3440
|
getCvmAttestation,
|
|
@@ -3049,14 +3444,17 @@ export {
|
|
|
3049
3444
|
getCvmInfo,
|
|
3050
3445
|
getCvmList,
|
|
3051
3446
|
getCvmNetwork,
|
|
3447
|
+
getCvmState,
|
|
3052
3448
|
getCvmStats,
|
|
3053
3449
|
getErrorMessage,
|
|
3054
3450
|
getKmsInfo,
|
|
3055
3451
|
getKmsList,
|
|
3056
3452
|
getValidationFields,
|
|
3057
3453
|
getWorkspace,
|
|
3058
|
-
|
|
3454
|
+
listAllInstanceTypeFamilies,
|
|
3455
|
+
listFamilyInstanceTypes,
|
|
3059
3456
|
listWorkspaces,
|
|
3457
|
+
nextAppIds,
|
|
3060
3458
|
parseApiError,
|
|
3061
3459
|
parseEnv,
|
|
3062
3460
|
parseEnvVars,
|
|
@@ -3072,6 +3470,7 @@ export {
|
|
|
3072
3470
|
safeDeployAppAuth,
|
|
3073
3471
|
safeGetAppEnvEncryptPubKey,
|
|
3074
3472
|
safeGetAvailableNodes,
|
|
3473
|
+
safeGetAvailableOsImages,
|
|
3075
3474
|
safeGetCurrentUser,
|
|
3076
3475
|
safeGetCvmAttestation,
|
|
3077
3476
|
safeGetCvmComposeFile,
|
|
@@ -3080,12 +3479,15 @@ export {
|
|
|
3080
3479
|
safeGetCvmInfo,
|
|
3081
3480
|
safeGetCvmList,
|
|
3082
3481
|
safeGetCvmNetwork,
|
|
3482
|
+
safeGetCvmState,
|
|
3083
3483
|
safeGetCvmStats,
|
|
3084
3484
|
safeGetKmsInfo,
|
|
3085
3485
|
safeGetKmsList,
|
|
3086
3486
|
safeGetWorkspace,
|
|
3087
|
-
|
|
3487
|
+
safeListAllInstanceTypeFamilies,
|
|
3488
|
+
safeListFamilyInstanceTypes,
|
|
3088
3489
|
safeListWorkspaces,
|
|
3490
|
+
safeNextAppIds,
|
|
3089
3491
|
safeProvisionCvm,
|
|
3090
3492
|
safeProvisionCvmComposeFileUpdate,
|
|
3091
3493
|
safeRestartCvm,
|
|
@@ -3094,6 +3496,7 @@ export {
|
|
|
3094
3496
|
safeStopCvm,
|
|
3095
3497
|
safeUpdateCvmResources,
|
|
3096
3498
|
safeUpdateCvmVisibility,
|
|
3499
|
+
safeUpdateOsImage,
|
|
3097
3500
|
safeValidateActionParameters,
|
|
3098
3501
|
shutdownCvm,
|
|
3099
3502
|
sortObject,
|
|
@@ -3102,9 +3505,11 @@ export {
|
|
|
3102
3505
|
switchToNetwork,
|
|
3103
3506
|
updateCvmResources,
|
|
3104
3507
|
updateCvmVisibility,
|
|
3508
|
+
updateOsImage,
|
|
3105
3509
|
validateActionParameters,
|
|
3106
3510
|
validateNetworkPrerequisites,
|
|
3107
3511
|
verifyEnvEncryptPublicKey,
|
|
3108
3512
|
waitForTransactionReceipt,
|
|
3513
|
+
watchCvmState,
|
|
3109
3514
|
withComposeMethods
|
|
3110
3515
|
};
|