@phala/cloud 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/cvms/get_cvm_init_scripts.d.ts +6 -1
- package/dist/actions/cvms/log-time.d.ts +5 -0
- package/dist/actions/cvms/logs.d.ts +64 -0
- package/dist/actions/cvms/patch_cvm.d.ts +7 -0
- package/dist/actions/cvms/provision_cvm.d.ts +3 -0
- package/dist/actions/cvms/put_cvm_init_scripts.d.ts +150 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/create-client.d.ts +129 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1066 -344
- package/dist/index.mjs +1052 -344
- package/dist/types/app_info_v20260121.d.ts +12 -0
- package/dist/types/cvm_info_v20251028.d.ts +1 -1
- package/dist/types/cvm_info_v20260121.d.ts +7 -0
- package/dist/user-agent.d.ts +30 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -417,6 +417,34 @@ function isAppIdConflictError(error) {
|
|
|
417
417
|
return error instanceof ResourceError && error.errorCode === "ERR-03-007";
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
+
// src/user-agent.ts
|
|
421
|
+
function runtimeToken(runtime) {
|
|
422
|
+
const deno = runtime.Deno?.version?.deno;
|
|
423
|
+
if (typeof deno === "string" && deno.length > 0) {
|
|
424
|
+
return `deno/${deno}`;
|
|
425
|
+
}
|
|
426
|
+
const bun = runtime.Bun?.version;
|
|
427
|
+
if (typeof bun === "string" && bun.length > 0) {
|
|
428
|
+
return `bun/${bun}`;
|
|
429
|
+
}
|
|
430
|
+
const node = runtime.process?.versions?.node;
|
|
431
|
+
if (typeof node === "string" && node.length > 0) {
|
|
432
|
+
return `node/${node}`;
|
|
433
|
+
}
|
|
434
|
+
if (runtime.navigator?.userAgent === "Cloudflare-Workers") {
|
|
435
|
+
return "workerd";
|
|
436
|
+
}
|
|
437
|
+
return void 0;
|
|
438
|
+
}
|
|
439
|
+
function defaultUserAgent(runtime = globalThis) {
|
|
440
|
+
if (runtime.window !== void 0 && runtime.document !== void 0) {
|
|
441
|
+
return void 0;
|
|
442
|
+
}
|
|
443
|
+
const product = "phala-cloud-sdk-js/0.6.0";
|
|
444
|
+
const token = runtimeToken(runtime);
|
|
445
|
+
return token ? `${product} ${token}` : product;
|
|
446
|
+
}
|
|
447
|
+
|
|
420
448
|
// src/client.ts
|
|
421
449
|
var SUPPORTED_API_VERSIONS = [
|
|
422
450
|
"2025-10-28",
|
|
@@ -476,6 +504,10 @@ var Client = class _Client {
|
|
|
476
504
|
...fetchOptions
|
|
477
505
|
} = this.config;
|
|
478
506
|
const requestHeaders = new Headers({ "Content-Type": "application/json" });
|
|
507
|
+
const userAgent = defaultUserAgent();
|
|
508
|
+
if (userAgent) {
|
|
509
|
+
requestHeaders.set("User-Agent", userAgent);
|
|
510
|
+
}
|
|
479
511
|
new Headers(headers).forEach((value, key) => requestHeaders.set(key, value));
|
|
480
512
|
requestHeaders.set("X-Phala-Version", version);
|
|
481
513
|
if (!useCookieAuth && apiKey) {
|
|
@@ -1027,7 +1059,8 @@ var CvmInfoV20251028Schema = z5.object({
|
|
|
1027
1059
|
status: z5.string(),
|
|
1028
1060
|
in_progress: z5.boolean().default(false),
|
|
1029
1061
|
dapp_dashboard_url: z5.string().nullable(),
|
|
1030
|
-
|
|
1062
|
+
/** Presigned serial log URL; expires shortly after it is issued. */
|
|
1063
|
+
syslog_endpoint: z5.string().nullable().describe("Presigned serial log URL that expires shortly after issuance."),
|
|
1031
1064
|
allow_upgrade: z5.boolean().default(false),
|
|
1032
1065
|
project_id: z5.string().nullable(),
|
|
1033
1066
|
project_type: z5.string().nullable(),
|
|
@@ -1064,7 +1097,8 @@ var CvmDetailV20251028Schema = z5.object({
|
|
|
1064
1097
|
public_logs: z5.boolean().optional().default(false),
|
|
1065
1098
|
managed_env: z5.boolean().optional().default(false),
|
|
1066
1099
|
dapp_dashboard_url: z5.string().optional().nullable(),
|
|
1067
|
-
|
|
1100
|
+
/** Presigned serial log URL; expires shortly after it is issued. */
|
|
1101
|
+
syslog_endpoint: z5.string().nullable().optional().describe("Optional presigned serial log URL that expires shortly after issuance."),
|
|
1068
1102
|
kms_info: KmsInfoSchema.optional().nullable(),
|
|
1069
1103
|
contract_address: z5.string().optional().nullable(),
|
|
1070
1104
|
deployer_address: z5.string().optional().nullable(),
|
|
@@ -1163,10 +1197,18 @@ var CvmGatewayInfoV20260121Schema = z6.object({
|
|
|
1163
1197
|
cname: z6.string().nullable().optional()
|
|
1164
1198
|
});
|
|
1165
1199
|
var CvmLogUrlsV20260121Schema = z6.object({
|
|
1166
|
-
serial
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1200
|
+
/** Presigned serial log URL; expires shortly after it is issued. */
|
|
1201
|
+
serial: z6.string().nullable().optional().describe("Optional presigned serial log URL that expires shortly after issuance."),
|
|
1202
|
+
/** Presigned stdout log URL; expires shortly after it is issued. */
|
|
1203
|
+
stdout: z6.string().nullable().optional().describe("Optional presigned stdout log URL that expires shortly after issuance."),
|
|
1204
|
+
/** Presigned stderr log URL; expires shortly after it is issued. */
|
|
1205
|
+
stderr: z6.string().nullable().optional().describe("Optional presigned stderr log URL that expires shortly after issuance."),
|
|
1206
|
+
/** Container URL base without query; present only when public logs and a VM UUID exist. */
|
|
1207
|
+
container_log_base: z6.string().nullable().optional().describe("Optional container log URL base without query parameters."),
|
|
1208
|
+
/** Container URL auth query; present only when public logs and a VM UUID exist. */
|
|
1209
|
+
auth_query: z6.string().nullable().optional().describe(
|
|
1210
|
+
"Optional container log auth query; null when public logs or VM UUID are unavailable."
|
|
1211
|
+
)
|
|
1170
1212
|
});
|
|
1171
1213
|
var DeviceIdEntrySchema = z6.object({
|
|
1172
1214
|
device_id: z6.string(),
|
|
@@ -1773,7 +1815,9 @@ var ProvisionCvmRequestSchema = z10.object({
|
|
|
1773
1815
|
storage_discard: z10.boolean().nullable().optional(),
|
|
1774
1816
|
event_log_version: z10.union([z10.literal(1), z10.literal(2)]).nullable().optional(),
|
|
1775
1817
|
snapshotter: z10.enum(["overlayfs", "stargz"]).nullable().optional(),
|
|
1776
|
-
verity_volumes: z10.array(VerityVolumeSchema).nullable().optional()
|
|
1818
|
+
verity_volumes: z10.array(VerityVolumeSchema).nullable().optional(),
|
|
1819
|
+
// Raw guest init scripts. Platform slugs use init_scripts instead.
|
|
1820
|
+
init_script: z10.union([z10.string(), z10.array(z10.string())]).optional()
|
|
1777
1821
|
}).passthrough().superRefine((data, ctx) => {
|
|
1778
1822
|
validateComposePayloadSize(data.docker_compose_file, data.pre_launch_script, ctx);
|
|
1779
1823
|
}).optional(),
|
|
@@ -5212,7 +5256,8 @@ var ContainerInfoSchema = z43.object({
|
|
|
5212
5256
|
created: z43.number(),
|
|
5213
5257
|
state: z43.string(),
|
|
5214
5258
|
status: z43.string(),
|
|
5215
|
-
|
|
5259
|
+
/** Presigned container log URL that expires shortly after it is issued. */
|
|
5260
|
+
log_endpoint: z43.string().nullable().describe("Presigned container log URL that expires shortly after issuance.")
|
|
5216
5261
|
});
|
|
5217
5262
|
var CvmContainersStatsSchema = z43.object({
|
|
5218
5263
|
is_online: z43.boolean(),
|
|
@@ -5630,6 +5675,8 @@ var PatchCvmRequestSchema = refineCvmId(
|
|
|
5630
5675
|
compose: ComposePatchSchema.optional(),
|
|
5631
5676
|
// Platform init scripts this CVM runs, replacing the current set
|
|
5632
5677
|
init_scripts: z49.array(InitScriptSlugSchema).optional(),
|
|
5678
|
+
// Raw guest init scripts, replacing the current set. System admins only.
|
|
5679
|
+
init_script: z49.array(z49.string()).optional(),
|
|
5633
5680
|
// Confirms turning on docker_cleanup or requirements.ephemeral_data_disk,
|
|
5634
5681
|
// which erase data on every boot
|
|
5635
5682
|
confirm_data_wipe: z49.boolean().optional(),
|
|
@@ -6365,7 +6412,8 @@ var CvmInitScriptSchema = z66.object({
|
|
|
6365
6412
|
reason: z66.string().nullable().optional()
|
|
6366
6413
|
});
|
|
6367
6414
|
var CvmInitScriptsSchema = z66.object({
|
|
6368
|
-
items: z66.array(CvmInitScriptSchema)
|
|
6415
|
+
items: z66.array(CvmInitScriptSchema),
|
|
6416
|
+
has_custom_scripts: z66.boolean()
|
|
6369
6417
|
});
|
|
6370
6418
|
var GetCvmInitScriptsRequestSchema = CvmIdSchema;
|
|
6371
6419
|
var { action: getCvmInitScripts, safeAction: safeGetCvmInitScripts } = defineAction(CvmInitScriptsSchema, async (client, request) => {
|
|
@@ -6373,22 +6421,78 @@ var { action: getCvmInitScripts, safeAction: safeGetCvmInitScripts } = defineAct
|
|
|
6373
6421
|
return await client.get(`/cvms/${cvmId}/init-scripts`);
|
|
6374
6422
|
});
|
|
6375
6423
|
|
|
6376
|
-
// src/actions/
|
|
6424
|
+
// src/actions/cvms/put_cvm_init_scripts.ts
|
|
6377
6425
|
import { z as z67 } from "zod";
|
|
6378
|
-
var
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6426
|
+
var PutCvmInitScriptsRequestSchema = refineCvmId(
|
|
6427
|
+
CvmIdObjectSchema.extend({
|
|
6428
|
+
scripts: z67.array(z67.string()).max(5),
|
|
6429
|
+
prepareOnly: z67.boolean().optional()
|
|
6430
|
+
})
|
|
6431
|
+
);
|
|
6432
|
+
function extractDetailsMap2(detail) {
|
|
6433
|
+
const map = {};
|
|
6434
|
+
if (!detail || typeof detail !== "object") return map;
|
|
6435
|
+
const obj = detail;
|
|
6436
|
+
const details = obj.details;
|
|
6437
|
+
if (!Array.isArray(details)) return map;
|
|
6438
|
+
for (const item of details) {
|
|
6439
|
+
if (item && typeof item === "object" && "field" in item && "value" in item) {
|
|
6440
|
+
map[item.field] = item.value;
|
|
6441
|
+
}
|
|
6442
|
+
}
|
|
6443
|
+
return map;
|
|
6444
|
+
}
|
|
6445
|
+
var { action: putCvmInitScripts, safeAction: safePutCvmInitScripts } = defineAction(PatchCvmResultSchema, async (client, request) => {
|
|
6446
|
+
const parsed = PutCvmInitScriptsRequestSchema.parse(request);
|
|
6447
|
+
const { cvmId } = CvmIdSchema.parse(parsed);
|
|
6448
|
+
try {
|
|
6449
|
+
const response = parsed.prepareOnly ? await client.put(
|
|
6450
|
+
`/cvms/${cvmId}/init-scripts`,
|
|
6451
|
+
{ scripts: parsed.scripts },
|
|
6452
|
+
{ headers: { "X-Prepare-Only": "true" } }
|
|
6453
|
+
) : await client.put(
|
|
6454
|
+
`/cvms/${cvmId}/init-scripts`,
|
|
6455
|
+
{ scripts: parsed.scripts }
|
|
6456
|
+
);
|
|
6457
|
+
return {
|
|
6458
|
+
requiresOnChainHash: false,
|
|
6459
|
+
correlationId: response.correlation_id ?? ""
|
|
6460
|
+
};
|
|
6461
|
+
} catch (error) {
|
|
6462
|
+
if (error instanceof PhalaCloudError && error.status === 465) {
|
|
6463
|
+
const details = extractDetailsMap2(error.detail);
|
|
6464
|
+
return {
|
|
6465
|
+
requiresOnChainHash: true,
|
|
6466
|
+
composeHash: details.compose_hash,
|
|
6467
|
+
appId: String(details.app_id),
|
|
6468
|
+
deviceId: details.device_id,
|
|
6469
|
+
kmsInfo: details.kms_info,
|
|
6470
|
+
commitToken: details.commit_token,
|
|
6471
|
+
commitUrl: details.commit_url,
|
|
6472
|
+
apiCommitUrl: details.api_commit_url,
|
|
6473
|
+
onchainStatus: details.onchain_status
|
|
6474
|
+
};
|
|
6475
|
+
}
|
|
6476
|
+
throw error;
|
|
6477
|
+
}
|
|
6478
|
+
});
|
|
6479
|
+
|
|
6480
|
+
// src/actions/ssh_keys/list_ssh_keys.ts
|
|
6481
|
+
import { z as z68 } from "zod";
|
|
6482
|
+
var SshKeySchema = z68.object({
|
|
6483
|
+
id: z68.string(),
|
|
6484
|
+
user_id: z68.string(),
|
|
6485
|
+
name: z68.string(),
|
|
6486
|
+
public_key: z68.string(),
|
|
6487
|
+
fingerprint: z68.string(),
|
|
6488
|
+
key_type: z68.string(),
|
|
6489
|
+
source: z68.string(),
|
|
6490
|
+
key_metadata: z68.record(z68.string(), z68.unknown()).nullable().optional(),
|
|
6491
|
+
last_synced_at: z68.string().nullable().optional(),
|
|
6492
|
+
created_at: z68.string(),
|
|
6493
|
+
updated_at: z68.string()
|
|
6494
|
+
});
|
|
6495
|
+
var ListSshKeysResponseSchema = z68.array(SshKeySchema);
|
|
6392
6496
|
async function listSshKeys(client) {
|
|
6393
6497
|
const response = await client.get("/user/ssh-keys");
|
|
6394
6498
|
return ListSshKeysResponseSchema.parse(response);
|
|
@@ -6412,15 +6516,15 @@ async function safeListSshKeys(client) {
|
|
|
6412
6516
|
}
|
|
6413
6517
|
|
|
6414
6518
|
// src/actions/ssh_keys/import_github_profile.ts
|
|
6415
|
-
import { z as
|
|
6416
|
-
var ImportGithubProfileRequestSchema =
|
|
6417
|
-
github_username:
|
|
6519
|
+
import { z as z69 } from "zod";
|
|
6520
|
+
var ImportGithubProfileRequestSchema = z69.object({
|
|
6521
|
+
github_username: z69.string().min(1)
|
|
6418
6522
|
});
|
|
6419
|
-
var ImportGithubProfileResponseSchema =
|
|
6420
|
-
github_username:
|
|
6421
|
-
keys_added:
|
|
6422
|
-
keys_skipped:
|
|
6423
|
-
errors:
|
|
6523
|
+
var ImportGithubProfileResponseSchema = z69.object({
|
|
6524
|
+
github_username: z69.string(),
|
|
6525
|
+
keys_added: z69.number().int(),
|
|
6526
|
+
keys_skipped: z69.number().int(),
|
|
6527
|
+
errors: z69.array(z69.string()).default([])
|
|
6424
6528
|
});
|
|
6425
6529
|
var { action: importGithubProfileSshKeys, safeAction: safeImportGithubProfileSshKeys } = defineAction(
|
|
6426
6530
|
ImportGithubProfileResponseSchema,
|
|
@@ -6431,10 +6535,10 @@ var { action: importGithubProfileSshKeys, safeAction: safeImportGithubProfileSsh
|
|
|
6431
6535
|
);
|
|
6432
6536
|
|
|
6433
6537
|
// src/actions/ssh_keys/create_ssh_key.ts
|
|
6434
|
-
import { z as
|
|
6435
|
-
var CreateSshKeyRequestSchema =
|
|
6436
|
-
name:
|
|
6437
|
-
public_key:
|
|
6538
|
+
import { z as z70 } from "zod";
|
|
6539
|
+
var CreateSshKeyRequestSchema = z70.object({
|
|
6540
|
+
name: z70.string().min(1),
|
|
6541
|
+
public_key: z70.string().min(1)
|
|
6438
6542
|
});
|
|
6439
6543
|
var { action: createSshKey, safeAction: safeCreateSshKey } = defineAction(SshKeySchema, async (client, request) => {
|
|
6440
6544
|
const { name, public_key } = CreateSshKeyRequestSchema.parse(request);
|
|
@@ -6442,24 +6546,24 @@ var { action: createSshKey, safeAction: safeCreateSshKey } = defineAction(SshKey
|
|
|
6442
6546
|
});
|
|
6443
6547
|
|
|
6444
6548
|
// src/actions/ssh_keys/delete_ssh_key.ts
|
|
6445
|
-
import { z as
|
|
6446
|
-
var DeleteSshKeyRequestSchema =
|
|
6447
|
-
keyId:
|
|
6549
|
+
import { z as z71 } from "zod";
|
|
6550
|
+
var DeleteSshKeyRequestSchema = z71.object({
|
|
6551
|
+
keyId: z71.string().min(1)
|
|
6448
6552
|
});
|
|
6449
|
-
var { action: deleteSshKey, safeAction: safeDeleteSshKey } = defineAction(
|
|
6553
|
+
var { action: deleteSshKey, safeAction: safeDeleteSshKey } = defineAction(z71.void(), async (client, request) => {
|
|
6450
6554
|
const { keyId } = DeleteSshKeyRequestSchema.parse(request);
|
|
6451
6555
|
await client.delete(`/user/ssh-keys/${keyId}`);
|
|
6452
6556
|
return void 0;
|
|
6453
6557
|
});
|
|
6454
6558
|
|
|
6455
6559
|
// src/actions/ssh_keys/sync_github_ssh_keys.ts
|
|
6456
|
-
import { z as
|
|
6457
|
-
var SyncGithubSshKeysResponseSchema =
|
|
6458
|
-
synced_count:
|
|
6459
|
-
keys_added:
|
|
6460
|
-
keys_updated:
|
|
6461
|
-
keys_removed:
|
|
6462
|
-
errors:
|
|
6560
|
+
import { z as z72 } from "zod";
|
|
6561
|
+
var SyncGithubSshKeysResponseSchema = z72.object({
|
|
6562
|
+
synced_count: z72.number().int(),
|
|
6563
|
+
keys_added: z72.number().int(),
|
|
6564
|
+
keys_updated: z72.number().int(),
|
|
6565
|
+
keys_removed: z72.number().int(),
|
|
6566
|
+
errors: z72.array(z72.string()).default([])
|
|
6463
6567
|
});
|
|
6464
6568
|
var { action: syncGithubSshKeys, safeAction: safeSyncGithubSshKeys } = defineSimpleAction(
|
|
6465
6569
|
SyncGithubSshKeysResponseSchema,
|
|
@@ -6469,20 +6573,20 @@ var { action: syncGithubSshKeys, safeAction: safeSyncGithubSshKeys } = defineSim
|
|
|
6469
6573
|
);
|
|
6470
6574
|
|
|
6471
6575
|
// src/actions/ssh_keys/get_cvm_ssh_keys.ts
|
|
6472
|
-
import { z as
|
|
6473
|
-
var CvmSshKeySchema =
|
|
6474
|
-
id:
|
|
6475
|
-
owner_user_id:
|
|
6476
|
-
owner_username:
|
|
6477
|
-
added_by_user_id:
|
|
6478
|
-
name:
|
|
6479
|
-
public_key:
|
|
6480
|
-
fingerprint:
|
|
6481
|
-
key_type:
|
|
6482
|
-
});
|
|
6483
|
-
var CvmSshKeysResponseSchema =
|
|
6484
|
-
keys:
|
|
6485
|
-
restart_required:
|
|
6576
|
+
import { z as z73 } from "zod";
|
|
6577
|
+
var CvmSshKeySchema = z73.object({
|
|
6578
|
+
id: z73.string(),
|
|
6579
|
+
owner_user_id: z73.string(),
|
|
6580
|
+
owner_username: z73.string(),
|
|
6581
|
+
added_by_user_id: z73.string(),
|
|
6582
|
+
name: z73.string(),
|
|
6583
|
+
public_key: z73.string(),
|
|
6584
|
+
fingerprint: z73.string(),
|
|
6585
|
+
key_type: z73.string()
|
|
6586
|
+
});
|
|
6587
|
+
var CvmSshKeysResponseSchema = z73.object({
|
|
6588
|
+
keys: z73.array(CvmSshKeySchema),
|
|
6589
|
+
restart_required: z73.boolean()
|
|
6486
6590
|
});
|
|
6487
6591
|
var GetCvmSshKeysRequestSchema = CvmIdSchema;
|
|
6488
6592
|
var { action: getCvmSshKeys, safeAction: safeGetCvmSshKeys } = defineAction(CvmSshKeysResponseSchema, async (client, request) => {
|
|
@@ -6491,12 +6595,12 @@ var { action: getCvmSshKeys, safeAction: safeGetCvmSshKeys } = defineAction(CvmS
|
|
|
6491
6595
|
});
|
|
6492
6596
|
|
|
6493
6597
|
// src/actions/ssh_keys/update_cvm_ssh_keys.ts
|
|
6494
|
-
import { z as
|
|
6598
|
+
import { z as z74 } from "zod";
|
|
6495
6599
|
var UpdateCvmSshKeysRequestSchema = refineCvmId(
|
|
6496
6600
|
CvmIdObjectSchema.extend({
|
|
6497
|
-
ssh_key_ids:
|
|
6498
|
-
usernames:
|
|
6499
|
-
apply_now:
|
|
6601
|
+
ssh_key_ids: z74.array(z74.string()),
|
|
6602
|
+
usernames: z74.array(z74.string()).optional(),
|
|
6603
|
+
apply_now: z74.boolean().optional()
|
|
6500
6604
|
})
|
|
6501
6605
|
);
|
|
6502
6606
|
var { action: updateCvmSshKeys, safeAction: safeUpdateCvmSshKeys } = defineAction(CvmSshKeysResponseSchema, async (client, request) => {
|
|
@@ -6510,9 +6614,9 @@ var { action: updateCvmSshKeys, safeAction: safeUpdateCvmSshKeys } = defineActio
|
|
|
6510
6614
|
});
|
|
6511
6615
|
|
|
6512
6616
|
// src/actions/api_tokens/revoke_current_api_token.ts
|
|
6513
|
-
import { z as
|
|
6617
|
+
import { z as z75 } from "zod";
|
|
6514
6618
|
var { action: revokeCurrentApiToken, safeAction: safeRevokeCurrentApiToken } = defineSimpleAction(
|
|
6515
|
-
|
|
6619
|
+
z75.void(),
|
|
6516
6620
|
async (client) => {
|
|
6517
6621
|
await client.delete("/tokens/self");
|
|
6518
6622
|
return void 0;
|
|
@@ -6520,34 +6624,34 @@ var { action: revokeCurrentApiToken, safeAction: safeRevokeCurrentApiToken } = d
|
|
|
6520
6624
|
);
|
|
6521
6625
|
|
|
6522
6626
|
// src/actions/cvms/check_cvm_is_allowed.ts
|
|
6523
|
-
import { z as
|
|
6524
|
-
var IsAllowedResultBaseSchema =
|
|
6525
|
-
app_contract_address:
|
|
6526
|
-
compose_hash:
|
|
6527
|
-
device_id:
|
|
6528
|
-
compose_hash_allowed:
|
|
6529
|
-
allow_any_device:
|
|
6530
|
-
device_id_allowed:
|
|
6531
|
-
is_allowed:
|
|
6532
|
-
error:
|
|
6627
|
+
import { z as z76 } from "zod";
|
|
6628
|
+
var IsAllowedResultBaseSchema = z76.object({
|
|
6629
|
+
app_contract_address: z76.string(),
|
|
6630
|
+
compose_hash: z76.string(),
|
|
6631
|
+
device_id: z76.string(),
|
|
6632
|
+
compose_hash_allowed: z76.boolean(),
|
|
6633
|
+
allow_any_device: z76.boolean(),
|
|
6634
|
+
device_id_allowed: z76.boolean().nullable().optional(),
|
|
6635
|
+
is_allowed: z76.boolean(),
|
|
6636
|
+
error: z76.string().nullable().optional()
|
|
6533
6637
|
});
|
|
6534
6638
|
var IsAllowedResultV20260121Schema = IsAllowedResultBaseSchema.extend({
|
|
6535
|
-
cvm_id:
|
|
6639
|
+
cvm_id: z76.number().optional()
|
|
6536
6640
|
});
|
|
6537
6641
|
var IsAllowedResultV20260522Schema = IsAllowedResultBaseSchema.extend({
|
|
6538
|
-
cvm_id:
|
|
6642
|
+
cvm_id: z76.string().optional()
|
|
6539
6643
|
});
|
|
6540
|
-
var IsAllowedResultAnySchema =
|
|
6644
|
+
var IsAllowedResultAnySchema = z76.union([
|
|
6541
6645
|
IsAllowedResultV20260121Schema,
|
|
6542
6646
|
IsAllowedResultV20260522Schema
|
|
6543
6647
|
]);
|
|
6544
6648
|
var IsAllowedResultSchema = IsAllowedResultV20260522Schema;
|
|
6545
6649
|
var CheckCvmIsAllowedInputSchema = placementRequest(
|
|
6546
|
-
|
|
6547
|
-
cvmId:
|
|
6548
|
-
compose_hash:
|
|
6549
|
-
node:
|
|
6550
|
-
device_id:
|
|
6650
|
+
z76.object({
|
|
6651
|
+
cvmId: z76.string().min(1),
|
|
6652
|
+
compose_hash: z76.string().optional(),
|
|
6653
|
+
node: z76.string().min(1).optional(),
|
|
6654
|
+
device_id: z76.string().optional()
|
|
6551
6655
|
})
|
|
6552
6656
|
);
|
|
6553
6657
|
var CheckCvmIsAllowedRequestSchema = CheckCvmIsAllowedInputSchema;
|
|
@@ -6579,14 +6683,14 @@ async function safeCheckCvmIsAllowed(client, request) {
|
|
|
6579
6683
|
}
|
|
6580
6684
|
|
|
6581
6685
|
// src/actions/apps/check_app_is_allowed.ts
|
|
6582
|
-
import { z as
|
|
6686
|
+
import { z as z77 } from "zod";
|
|
6583
6687
|
var CheckAppIsAllowedRequestSchema = placementRequest(
|
|
6584
|
-
|
|
6585
|
-
appId:
|
|
6586
|
-
compose_hash:
|
|
6587
|
-
node:
|
|
6588
|
-
device_id:
|
|
6589
|
-
chain_id:
|
|
6688
|
+
z77.object({
|
|
6689
|
+
appId: z77.string().min(1),
|
|
6690
|
+
compose_hash: z77.string(),
|
|
6691
|
+
node: z77.string().min(1).optional(),
|
|
6692
|
+
device_id: z77.string().optional(),
|
|
6693
|
+
chain_id: z77.number().optional()
|
|
6590
6694
|
})
|
|
6591
6695
|
);
|
|
6592
6696
|
var { action: checkAppIsAllowed, safeAction: safeCheckAppIsAllowed } = defineAction(IsAllowedResultSchema, async (client, request) => {
|
|
@@ -6595,29 +6699,29 @@ var { action: checkAppIsAllowed, safeAction: safeCheckAppIsAllowed } = defineAct
|
|
|
6595
6699
|
});
|
|
6596
6700
|
|
|
6597
6701
|
// src/actions/apps/check_app_cvms_is_allowed.ts
|
|
6598
|
-
import { z as
|
|
6599
|
-
var AppCvmsBatchIsAllowedResponseBaseSchema =
|
|
6600
|
-
is_onchain:
|
|
6601
|
-
total:
|
|
6602
|
-
allowed_count:
|
|
6603
|
-
denied_count:
|
|
6604
|
-
error_count:
|
|
6702
|
+
import { z as z78 } from "zod";
|
|
6703
|
+
var AppCvmsBatchIsAllowedResponseBaseSchema = z78.object({
|
|
6704
|
+
is_onchain: z78.boolean(),
|
|
6705
|
+
total: z78.number().default(0),
|
|
6706
|
+
allowed_count: z78.number().default(0),
|
|
6707
|
+
denied_count: z78.number().default(0),
|
|
6708
|
+
error_count: z78.number().default(0)
|
|
6605
6709
|
});
|
|
6606
6710
|
var AppCvmsBatchIsAllowedResponseV20260121Schema = AppCvmsBatchIsAllowedResponseBaseSchema.extend({
|
|
6607
|
-
results:
|
|
6608
|
-
skipped_cvm_ids:
|
|
6711
|
+
results: z78.array(IsAllowedResultV20260121Schema.extend({ cvm_id: z78.number() })).default([]),
|
|
6712
|
+
skipped_cvm_ids: z78.array(z78.number()).default([])
|
|
6609
6713
|
});
|
|
6610
6714
|
var AppCvmsBatchIsAllowedResponseV20260522Schema = AppCvmsBatchIsAllowedResponseBaseSchema.extend({
|
|
6611
|
-
results:
|
|
6612
|
-
skipped_cvm_ids:
|
|
6715
|
+
results: z78.array(IsAllowedResultV20260522Schema.extend({ cvm_id: z78.string() })).default([]),
|
|
6716
|
+
skipped_cvm_ids: z78.array(z78.string()).default([])
|
|
6613
6717
|
});
|
|
6614
|
-
var AppCvmsBatchIsAllowedResponseAnySchema =
|
|
6718
|
+
var AppCvmsBatchIsAllowedResponseAnySchema = z78.union([
|
|
6615
6719
|
AppCvmsBatchIsAllowedResponseV20260121Schema,
|
|
6616
6720
|
AppCvmsBatchIsAllowedResponseV20260522Schema
|
|
6617
6721
|
]);
|
|
6618
6722
|
var AppCvmsBatchIsAllowedResponseSchema = AppCvmsBatchIsAllowedResponseV20260522Schema;
|
|
6619
|
-
var CheckAppCvmsIsAllowedRequestSchema =
|
|
6620
|
-
appId:
|
|
6723
|
+
var CheckAppCvmsIsAllowedRequestSchema = z78.object({
|
|
6724
|
+
appId: z78.string().min(1)
|
|
6621
6725
|
});
|
|
6622
6726
|
function getSchemaForVersion9(version) {
|
|
6623
6727
|
if (version === "2026-01-21") return AppCvmsBatchIsAllowedResponseV20260121Schema;
|
|
@@ -6649,64 +6753,40 @@ async function safeCheckAppCvmsIsAllowed(client, request) {
|
|
|
6649
6753
|
}
|
|
6650
6754
|
|
|
6651
6755
|
// src/actions/apps/get_app_list.ts
|
|
6652
|
-
import { z as
|
|
6756
|
+
import { z as z81 } from "zod";
|
|
6653
6757
|
|
|
6654
6758
|
// src/types/app_info_v20251028.ts
|
|
6655
|
-
import { z as
|
|
6656
|
-
var CvmBasicInfoV20251028Schema =
|
|
6657
|
-
vm_uuid:
|
|
6658
|
-
app_id:
|
|
6659
|
-
name:
|
|
6660
|
-
status:
|
|
6661
|
-
vcpu:
|
|
6662
|
-
memory:
|
|
6663
|
-
disk_size:
|
|
6664
|
-
teepod_id:
|
|
6665
|
-
teepod_name:
|
|
6666
|
-
region_identifier:
|
|
6667
|
-
kms_type:
|
|
6668
|
-
instance_type:
|
|
6669
|
-
listed:
|
|
6670
|
-
base_image:
|
|
6671
|
-
kms_slug:
|
|
6759
|
+
import { z as z79 } from "zod";
|
|
6760
|
+
var CvmBasicInfoV20251028Schema = z79.object({
|
|
6761
|
+
vm_uuid: z79.string().nullable(),
|
|
6762
|
+
app_id: z79.string(),
|
|
6763
|
+
name: z79.string().default(""),
|
|
6764
|
+
status: z79.string(),
|
|
6765
|
+
vcpu: z79.number().int(),
|
|
6766
|
+
memory: z79.number().int(),
|
|
6767
|
+
disk_size: z79.number().int(),
|
|
6768
|
+
teepod_id: z79.number().int(),
|
|
6769
|
+
teepod_name: z79.string(),
|
|
6770
|
+
region_identifier: z79.string().nullable().optional(),
|
|
6771
|
+
kms_type: z79.string().nullable().optional(),
|
|
6772
|
+
instance_type: z79.string().nullable().optional(),
|
|
6773
|
+
listed: z79.boolean().nullable().optional(),
|
|
6774
|
+
base_image: z79.string().nullable().optional(),
|
|
6775
|
+
kms_slug: z79.string().nullable().optional(),
|
|
6672
6776
|
/** @deprecated Identifies a KMS node, not the on-chain KMS contract. Use kms_contract_id. */
|
|
6673
|
-
kms_id:
|
|
6674
|
-
kms_contract_id:
|
|
6675
|
-
instance_id:
|
|
6777
|
+
kms_id: z79.string().nullable().optional(),
|
|
6778
|
+
kms_contract_id: z79.string().nullable().optional(),
|
|
6779
|
+
instance_id: z79.string().nullable().optional(),
|
|
6676
6780
|
machine_info: MachineInfoV20251028Schema.nullable().optional(),
|
|
6677
|
-
updated_at:
|
|
6678
|
-
});
|
|
6679
|
-
var AppProfileSchema = z78.object({
|
|
6680
|
-
display_name: z78.string().nullable().optional(),
|
|
6681
|
-
avatar_url: z78.string().nullable().optional(),
|
|
6682
|
-
description: z78.string().nullable().optional(),
|
|
6683
|
-
custom_domain: z78.string().nullable().optional()
|
|
6684
|
-
});
|
|
6685
|
-
var DstackAppFullResponseV20251028Schema = z78.object({
|
|
6686
|
-
id: z78.string(),
|
|
6687
|
-
name: z78.string(),
|
|
6688
|
-
app_id: z78.string(),
|
|
6689
|
-
app_provision_type: z78.string().nullable().optional(),
|
|
6690
|
-
app_icon_url: z78.string().nullable().optional(),
|
|
6691
|
-
created_at: z78.string(),
|
|
6692
|
-
kms_type: z78.string(),
|
|
6693
|
-
profile: AppProfileSchema.nullable().optional(),
|
|
6694
|
-
current_cvm: CvmBasicInfoV20251028Schema.nullable().optional(),
|
|
6695
|
-
cvms: z78.array(CvmBasicInfoV20251028Schema).default([]),
|
|
6696
|
-
cvm_count: z78.number().int().default(0)
|
|
6781
|
+
updated_at: z79.string().nullable().optional()
|
|
6697
6782
|
});
|
|
6698
|
-
var
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
total: z78.number().int(),
|
|
6704
|
-
total_pages: z78.number().int()
|
|
6783
|
+
var AppProfileSchema = z79.object({
|
|
6784
|
+
display_name: z79.string().nullable().optional(),
|
|
6785
|
+
avatar_url: z79.string().nullable().optional(),
|
|
6786
|
+
description: z79.string().nullable().optional(),
|
|
6787
|
+
custom_domain: z79.string().nullable().optional()
|
|
6705
6788
|
});
|
|
6706
|
-
|
|
6707
|
-
// src/types/app_info_v20260121.ts
|
|
6708
|
-
import { z as z79 } from "zod";
|
|
6709
|
-
var DstackAppFullResponseV20260121Schema = z79.object({
|
|
6789
|
+
var DstackAppFullResponseV20251028Schema = z79.object({
|
|
6710
6790
|
id: z79.string(),
|
|
6711
6791
|
name: z79.string(),
|
|
6712
6792
|
app_id: z79.string(),
|
|
@@ -6714,46 +6794,70 @@ var DstackAppFullResponseV20260121Schema = z79.object({
|
|
|
6714
6794
|
app_icon_url: z79.string().nullable().optional(),
|
|
6715
6795
|
created_at: z79.string(),
|
|
6716
6796
|
kms_type: z79.string(),
|
|
6717
|
-
profile:
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6797
|
+
profile: AppProfileSchema.nullable().optional(),
|
|
6798
|
+
current_cvm: CvmBasicInfoV20251028Schema.nullable().optional(),
|
|
6799
|
+
cvms: z79.array(CvmBasicInfoV20251028Schema).default([]),
|
|
6800
|
+
cvm_count: z79.number().int().default(0)
|
|
6801
|
+
});
|
|
6802
|
+
var DstackAppWithCvmResponseV20251028Schema = DstackAppFullResponseV20251028Schema;
|
|
6803
|
+
var DstackAppListResponseV20251028Schema = z79.object({
|
|
6804
|
+
dstack_apps: z79.array(DstackAppWithCvmResponseV20251028Schema),
|
|
6805
|
+
page: z79.number().int(),
|
|
6806
|
+
page_size: z79.number().int(),
|
|
6807
|
+
total: z79.number().int(),
|
|
6808
|
+
total_pages: z79.number().int()
|
|
6809
|
+
});
|
|
6810
|
+
|
|
6811
|
+
// src/types/app_info_v20260121.ts
|
|
6812
|
+
import { z as z80 } from "zod";
|
|
6813
|
+
var DstackAppFullResponseV20260121Schema = z80.object({
|
|
6814
|
+
id: z80.string(),
|
|
6815
|
+
name: z80.string(),
|
|
6816
|
+
app_id: z80.string(),
|
|
6817
|
+
app_provision_type: z80.string().nullable().optional(),
|
|
6818
|
+
app_icon_url: z80.string().nullable().optional(),
|
|
6819
|
+
created_at: z80.string(),
|
|
6820
|
+
kms_type: z80.string(),
|
|
6821
|
+
profile: z80.object({
|
|
6822
|
+
display_name: z80.string().nullable().optional(),
|
|
6823
|
+
avatar_url: z80.string().nullable().optional(),
|
|
6824
|
+
description: z80.string().nullable().optional(),
|
|
6825
|
+
custom_domain: z80.string().nullable().optional()
|
|
6722
6826
|
}).nullable().optional(),
|
|
6723
6827
|
current_cvm: CvmInfoV20260121Schema.nullable().optional(),
|
|
6724
|
-
cvms:
|
|
6725
|
-
cvm_count:
|
|
6828
|
+
cvms: z80.array(CvmInfoV20260121Schema).default([]),
|
|
6829
|
+
cvm_count: z80.number().int().default(0)
|
|
6726
6830
|
});
|
|
6727
6831
|
var DstackAppFullResponseV20260522Schema = DstackAppFullResponseV20260121Schema.extend({
|
|
6728
6832
|
current_cvm: CvmInfoV20260522Schema.nullable().optional(),
|
|
6729
|
-
cvms:
|
|
6833
|
+
cvms: z80.array(CvmInfoV20260522Schema).default([])
|
|
6730
6834
|
});
|
|
6731
6835
|
var DstackAppWithCvmResponseV20260121Schema = DstackAppFullResponseV20260121Schema;
|
|
6732
6836
|
var DstackAppWithCvmResponseV20260522Schema = DstackAppFullResponseV20260522Schema;
|
|
6733
|
-
var DstackAppListResponseV20260121Schema =
|
|
6734
|
-
dstack_apps:
|
|
6735
|
-
page:
|
|
6736
|
-
page_size:
|
|
6737
|
-
total:
|
|
6738
|
-
total_pages:
|
|
6837
|
+
var DstackAppListResponseV20260121Schema = z80.object({
|
|
6838
|
+
dstack_apps: z80.array(DstackAppWithCvmResponseV20260121Schema),
|
|
6839
|
+
page: z80.number().int(),
|
|
6840
|
+
page_size: z80.number().int(),
|
|
6841
|
+
total: z80.number().int(),
|
|
6842
|
+
total_pages: z80.number().int()
|
|
6739
6843
|
});
|
|
6740
6844
|
var DstackAppListResponseV20260522Schema = DstackAppListResponseV20260121Schema.extend({
|
|
6741
|
-
dstack_apps:
|
|
6845
|
+
dstack_apps: z80.array(DstackAppWithCvmResponseV20260522Schema)
|
|
6742
6846
|
});
|
|
6743
6847
|
|
|
6744
6848
|
// src/actions/apps/get_app_list.ts
|
|
6745
|
-
var GetAppListRequestSchema =
|
|
6746
|
-
page:
|
|
6747
|
-
page_size:
|
|
6748
|
-
search:
|
|
6749
|
-
status:
|
|
6750
|
-
listed:
|
|
6751
|
-
base_image:
|
|
6752
|
-
instance_type:
|
|
6753
|
-
kms_slug:
|
|
6754
|
-
kms_type:
|
|
6755
|
-
node:
|
|
6756
|
-
region:
|
|
6849
|
+
var GetAppListRequestSchema = z81.object({
|
|
6850
|
+
page: z81.number().int().min(1).optional(),
|
|
6851
|
+
page_size: z81.number().int().min(1).max(100).optional(),
|
|
6852
|
+
search: z81.string().optional(),
|
|
6853
|
+
status: z81.array(z81.string()).optional(),
|
|
6854
|
+
listed: z81.boolean().optional(),
|
|
6855
|
+
base_image: z81.string().optional(),
|
|
6856
|
+
instance_type: z81.string().optional(),
|
|
6857
|
+
kms_slug: z81.string().optional(),
|
|
6858
|
+
kms_type: z81.string().optional(),
|
|
6859
|
+
node: z81.string().optional(),
|
|
6860
|
+
region: z81.string().optional()
|
|
6757
6861
|
}).strict();
|
|
6758
6862
|
function getSchemaForVersion10(version) {
|
|
6759
6863
|
if (version === "2025-10-28") return DstackAppListResponseV20251028Schema;
|
|
@@ -6785,9 +6889,9 @@ async function safeGetAppList(client, request) {
|
|
|
6785
6889
|
}
|
|
6786
6890
|
|
|
6787
6891
|
// src/actions/apps/get_app_info.ts
|
|
6788
|
-
import { z as
|
|
6789
|
-
var GetAppInfoRequestSchema =
|
|
6790
|
-
appId:
|
|
6892
|
+
import { z as z82 } from "zod";
|
|
6893
|
+
var GetAppInfoRequestSchema = z82.object({
|
|
6894
|
+
appId: z82.string().min(1)
|
|
6791
6895
|
}).strict();
|
|
6792
6896
|
function getSchemaForVersion11(version) {
|
|
6793
6897
|
if (version === "2025-10-28") return DstackAppWithCvmResponseV20251028Schema;
|
|
@@ -6819,14 +6923,14 @@ async function safeGetAppInfo(client, request) {
|
|
|
6819
6923
|
}
|
|
6820
6924
|
|
|
6821
6925
|
// src/actions/apps/get_app_cvms.ts
|
|
6822
|
-
import { z as
|
|
6823
|
-
var GetAppCvmsRequestSchema =
|
|
6824
|
-
appId:
|
|
6926
|
+
import { z as z83 } from "zod";
|
|
6927
|
+
var GetAppCvmsRequestSchema = z83.object({
|
|
6928
|
+
appId: z83.string().min(1)
|
|
6825
6929
|
}).strict();
|
|
6826
6930
|
function getSchemaForVersion12(version) {
|
|
6827
|
-
if (version === "2025-10-28") return
|
|
6828
|
-
if (version === "2026-01-21") return
|
|
6829
|
-
return
|
|
6931
|
+
if (version === "2025-10-28") return z83.array(CvmInfoV20251028Schema);
|
|
6932
|
+
if (version === "2026-01-21") return z83.array(CvmInfoV20260121Schema);
|
|
6933
|
+
return z83.array(CvmInfoV20260522Schema);
|
|
6830
6934
|
}
|
|
6831
6935
|
async function getAppCvms(client, request) {
|
|
6832
6936
|
const { appId } = GetAppCvmsRequestSchema.parse(request);
|
|
@@ -6853,18 +6957,18 @@ async function safeGetAppCvms(client, request) {
|
|
|
6853
6957
|
}
|
|
6854
6958
|
|
|
6855
6959
|
// src/actions/apps/create_app_instance.ts
|
|
6856
|
-
import { z as
|
|
6960
|
+
import { z as z84 } from "zod";
|
|
6857
6961
|
var CreateAppInstanceRequestSchema = placementRequest(
|
|
6858
|
-
|
|
6859
|
-
appId:
|
|
6860
|
-
name:
|
|
6861
|
-
node:
|
|
6862
|
-
docker_compose_file:
|
|
6863
|
-
pre_launch_script:
|
|
6864
|
-
encrypted_env:
|
|
6865
|
-
compose_hash:
|
|
6866
|
-
token:
|
|
6867
|
-
transaction_hash:
|
|
6962
|
+
z84.object({
|
|
6963
|
+
appId: z84.string().min(1),
|
|
6964
|
+
name: z84.string().optional(),
|
|
6965
|
+
node: z84.string().min(1).optional(),
|
|
6966
|
+
docker_compose_file: z84.string().optional(),
|
|
6967
|
+
pre_launch_script: z84.string().optional(),
|
|
6968
|
+
encrypted_env: z84.string().optional(),
|
|
6969
|
+
compose_hash: z84.string().optional(),
|
|
6970
|
+
token: z84.string().optional(),
|
|
6971
|
+
transaction_hash: z84.string().optional()
|
|
6868
6972
|
}).strict()
|
|
6869
6973
|
);
|
|
6870
6974
|
var { action: createAppInstance, safeAction: safeCreateAppInstance } = defineAction(VMSchema, async (client, request) => {
|
|
@@ -6874,36 +6978,36 @@ var { action: createAppInstance, safeAction: safeCreateAppInstance } = defineAct
|
|
|
6874
6978
|
});
|
|
6875
6979
|
|
|
6876
6980
|
// src/actions/apps/get_app_device_allowlist.ts
|
|
6877
|
-
import { z as
|
|
6878
|
-
var DeviceAllowlistItemBaseSchema =
|
|
6879
|
-
device_id:
|
|
6880
|
-
node_name:
|
|
6881
|
-
allowed_onchain:
|
|
6882
|
-
status:
|
|
6981
|
+
import { z as z85 } from "zod";
|
|
6982
|
+
var DeviceAllowlistItemBaseSchema = z85.object({
|
|
6983
|
+
device_id: z85.string(),
|
|
6984
|
+
node_name: z85.string().nullable(),
|
|
6985
|
+
allowed_onchain: z85.boolean(),
|
|
6986
|
+
status: z85.string()
|
|
6883
6987
|
});
|
|
6884
6988
|
var DeviceAllowlistItemV20260121Schema = DeviceAllowlistItemBaseSchema.extend({
|
|
6885
|
-
cvm_ids:
|
|
6989
|
+
cvm_ids: z85.array(z85.number())
|
|
6886
6990
|
});
|
|
6887
6991
|
var DeviceAllowlistItemV20260522Schema = DeviceAllowlistItemBaseSchema.extend({
|
|
6888
|
-
cvm_ids:
|
|
6992
|
+
cvm_ids: z85.array(z85.string())
|
|
6889
6993
|
});
|
|
6890
|
-
var DeviceAllowlistResponseBaseSchema =
|
|
6891
|
-
is_onchain_kms:
|
|
6892
|
-
allow_any_device:
|
|
6893
|
-
chain_id:
|
|
6894
|
-
app_contract_address:
|
|
6994
|
+
var DeviceAllowlistResponseBaseSchema = z85.object({
|
|
6995
|
+
is_onchain_kms: z85.boolean(),
|
|
6996
|
+
allow_any_device: z85.boolean().nullable().optional(),
|
|
6997
|
+
chain_id: z85.number().nullable().optional(),
|
|
6998
|
+
app_contract_address: z85.string().nullable().optional()
|
|
6895
6999
|
});
|
|
6896
7000
|
var DeviceAllowlistResponseV20260121Schema = DeviceAllowlistResponseBaseSchema.extend({
|
|
6897
|
-
devices:
|
|
7001
|
+
devices: z85.array(DeviceAllowlistItemV20260121Schema).optional().default([])
|
|
6898
7002
|
});
|
|
6899
7003
|
var DeviceAllowlistResponseV20260522Schema = DeviceAllowlistResponseBaseSchema.extend({
|
|
6900
|
-
devices:
|
|
7004
|
+
devices: z85.array(DeviceAllowlistItemV20260522Schema).optional().default([])
|
|
6901
7005
|
});
|
|
6902
|
-
var DeviceAllowlistItemAnySchema =
|
|
7006
|
+
var DeviceAllowlistItemAnySchema = z85.union([
|
|
6903
7007
|
DeviceAllowlistItemV20260121Schema,
|
|
6904
7008
|
DeviceAllowlistItemV20260522Schema
|
|
6905
7009
|
]);
|
|
6906
|
-
var DeviceAllowlistResponseAnySchema =
|
|
7010
|
+
var DeviceAllowlistResponseAnySchema = z85.union([
|
|
6907
7011
|
DeviceAllowlistResponseV20260121Schema,
|
|
6908
7012
|
DeviceAllowlistResponseV20260522Schema
|
|
6909
7013
|
]);
|
|
@@ -6911,8 +7015,8 @@ function getSchemaForVersion13(version) {
|
|
|
6911
7015
|
if (version === "2026-01-21") return DeviceAllowlistResponseV20260121Schema;
|
|
6912
7016
|
return DeviceAllowlistResponseV20260522Schema;
|
|
6913
7017
|
}
|
|
6914
|
-
var GetAppDeviceAllowlistRequestSchema =
|
|
6915
|
-
appId:
|
|
7018
|
+
var GetAppDeviceAllowlistRequestSchema = z85.object({
|
|
7019
|
+
appId: z85.string().min(1)
|
|
6916
7020
|
}).strict();
|
|
6917
7021
|
async function getAppDeviceAllowlist(client, request) {
|
|
6918
7022
|
const { appId } = GetAppDeviceAllowlistRequestSchema.parse(request);
|
|
@@ -6940,57 +7044,57 @@ async function safeGetAppDeviceAllowlist(client, request) {
|
|
|
6940
7044
|
}
|
|
6941
7045
|
|
|
6942
7046
|
// src/actions/apps/get_app_revisions.ts
|
|
6943
|
-
import { z as
|
|
7047
|
+
import { z as z87 } from "zod";
|
|
6944
7048
|
|
|
6945
7049
|
// src/types/app_revision.ts
|
|
6946
|
-
import { z as
|
|
6947
|
-
var CvmRefSchema =
|
|
6948
|
-
object_type:
|
|
6949
|
-
id:
|
|
6950
|
-
name:
|
|
6951
|
-
app_id:
|
|
6952
|
-
vm_uuid:
|
|
6953
|
-
});
|
|
6954
|
-
var AppRevisionResponseSchema =
|
|
6955
|
-
revision_id:
|
|
6956
|
-
app_id:
|
|
6957
|
-
vm_uuid:
|
|
6958
|
-
compose_hash:
|
|
6959
|
-
created_at:
|
|
6960
|
-
trace_id:
|
|
6961
|
-
operation_type:
|
|
7050
|
+
import { z as z86 } from "zod";
|
|
7051
|
+
var CvmRefSchema = z86.object({
|
|
7052
|
+
object_type: z86.literal("cvm"),
|
|
7053
|
+
id: z86.string().nullable().optional(),
|
|
7054
|
+
name: z86.string().nullable().optional(),
|
|
7055
|
+
app_id: z86.string().nullable().optional(),
|
|
7056
|
+
vm_uuid: z86.string().nullable().optional()
|
|
7057
|
+
});
|
|
7058
|
+
var AppRevisionResponseSchema = z86.object({
|
|
7059
|
+
revision_id: z86.string(),
|
|
7060
|
+
app_id: z86.string(),
|
|
7061
|
+
vm_uuid: z86.string(),
|
|
7062
|
+
compose_hash: z86.string(),
|
|
7063
|
+
created_at: z86.string(),
|
|
7064
|
+
trace_id: z86.string().nullable().optional(),
|
|
7065
|
+
operation_type: z86.string(),
|
|
6962
7066
|
triggered_by: UserRefSchema.nullable().optional(),
|
|
6963
7067
|
cvm: CvmRefSchema.nullable().optional(),
|
|
6964
7068
|
workspace: WorkspaceRefSchema.nullable().optional()
|
|
6965
7069
|
});
|
|
6966
|
-
var AppRevisionDetailResponseSchema =
|
|
6967
|
-
revision_id:
|
|
6968
|
-
app_id:
|
|
6969
|
-
vm_uuid:
|
|
6970
|
-
compose_hash:
|
|
6971
|
-
compose_file:
|
|
6972
|
-
encrypted_env:
|
|
6973
|
-
user_config:
|
|
6974
|
-
created_at:
|
|
6975
|
-
trace_id:
|
|
6976
|
-
operation_type:
|
|
7070
|
+
var AppRevisionDetailResponseSchema = z86.object({
|
|
7071
|
+
revision_id: z86.string(),
|
|
7072
|
+
app_id: z86.string(),
|
|
7073
|
+
vm_uuid: z86.string(),
|
|
7074
|
+
compose_hash: z86.string(),
|
|
7075
|
+
compose_file: z86.union([z86.record(z86.string(), z86.any()), z86.string()]).nullable().optional(),
|
|
7076
|
+
encrypted_env: z86.string(),
|
|
7077
|
+
user_config: z86.string(),
|
|
7078
|
+
created_at: z86.string(),
|
|
7079
|
+
trace_id: z86.string().nullable().optional(),
|
|
7080
|
+
operation_type: z86.string(),
|
|
6977
7081
|
triggered_by: UserRefSchema.nullable().optional(),
|
|
6978
7082
|
cvm: CvmRefSchema.nullable().optional(),
|
|
6979
7083
|
workspace: WorkspaceRefSchema.nullable().optional()
|
|
6980
7084
|
});
|
|
6981
|
-
var AppRevisionsResponseSchema =
|
|
6982
|
-
revisions:
|
|
6983
|
-
total:
|
|
6984
|
-
page:
|
|
6985
|
-
page_size:
|
|
6986
|
-
total_pages:
|
|
7085
|
+
var AppRevisionsResponseSchema = z86.object({
|
|
7086
|
+
revisions: z86.array(AppRevisionResponseSchema),
|
|
7087
|
+
total: z86.number().int(),
|
|
7088
|
+
page: z86.number().int(),
|
|
7089
|
+
page_size: z86.number().int(),
|
|
7090
|
+
total_pages: z86.number().int()
|
|
6987
7091
|
});
|
|
6988
7092
|
|
|
6989
7093
|
// src/actions/apps/get_app_revisions.ts
|
|
6990
|
-
var GetAppRevisionsRequestSchema =
|
|
6991
|
-
appId:
|
|
6992
|
-
page:
|
|
6993
|
-
page_size:
|
|
7094
|
+
var GetAppRevisionsRequestSchema = z87.object({
|
|
7095
|
+
appId: z87.string().min(1),
|
|
7096
|
+
page: z87.number().int().min(1).optional(),
|
|
7097
|
+
page_size: z87.number().int().min(1).max(1e3).optional()
|
|
6994
7098
|
}).strict();
|
|
6995
7099
|
async function getAppRevisions(client, request) {
|
|
6996
7100
|
const { appId, ...params } = GetAppRevisionsRequestSchema.parse(request);
|
|
@@ -7016,11 +7120,11 @@ async function safeGetAppRevisions(client, request) {
|
|
|
7016
7120
|
}
|
|
7017
7121
|
|
|
7018
7122
|
// src/actions/apps/get_app_revision_detail.ts
|
|
7019
|
-
import { z as
|
|
7020
|
-
var GetAppRevisionDetailRequestSchema =
|
|
7021
|
-
appId:
|
|
7022
|
-
revisionId:
|
|
7023
|
-
rawComposeFile:
|
|
7123
|
+
import { z as z88 } from "zod";
|
|
7124
|
+
var GetAppRevisionDetailRequestSchema = z88.object({
|
|
7125
|
+
appId: z88.string().min(1),
|
|
7126
|
+
revisionId: z88.string().min(1),
|
|
7127
|
+
rawComposeFile: z88.boolean().optional()
|
|
7024
7128
|
}).strict();
|
|
7025
7129
|
async function getAppRevisionDetail(client, request) {
|
|
7026
7130
|
const { appId, revisionId, rawComposeFile } = GetAppRevisionDetailRequestSchema.parse(request);
|
|
@@ -7047,15 +7151,15 @@ async function safeGetAppRevisionDetail(client, request) {
|
|
|
7047
7151
|
}
|
|
7048
7152
|
|
|
7049
7153
|
// src/actions/apps/get_app_filter_options.ts
|
|
7050
|
-
import { z as
|
|
7051
|
-
var AppFilterOptionsSchema =
|
|
7052
|
-
statuses:
|
|
7053
|
-
image_versions:
|
|
7054
|
-
instance_types:
|
|
7055
|
-
kms_slugs:
|
|
7056
|
-
kms_types:
|
|
7057
|
-
regions:
|
|
7058
|
-
nodes:
|
|
7154
|
+
import { z as z89 } from "zod";
|
|
7155
|
+
var AppFilterOptionsSchema = z89.object({
|
|
7156
|
+
statuses: z89.array(z89.string()),
|
|
7157
|
+
image_versions: z89.array(z89.string()),
|
|
7158
|
+
instance_types: z89.array(z89.string()),
|
|
7159
|
+
kms_slugs: z89.array(z89.string()),
|
|
7160
|
+
kms_types: z89.array(z89.string()),
|
|
7161
|
+
regions: z89.array(z89.string()),
|
|
7162
|
+
nodes: z89.array(z89.string())
|
|
7059
7163
|
});
|
|
7060
7164
|
async function getAppFilterOptions(client) {
|
|
7061
7165
|
const response = await client.get("/apps/filter-options");
|
|
@@ -7080,53 +7184,53 @@ async function safeGetAppFilterOptions(client) {
|
|
|
7080
7184
|
}
|
|
7081
7185
|
|
|
7082
7186
|
// src/actions/apps/get_app_attestation.ts
|
|
7083
|
-
import { z as
|
|
7084
|
-
var KmsInfoSchema2 =
|
|
7085
|
-
contract_address:
|
|
7086
|
-
chain_id:
|
|
7087
|
-
version:
|
|
7088
|
-
url:
|
|
7089
|
-
gateway_app_id:
|
|
7090
|
-
gateway_app_url:
|
|
7091
|
-
kms_type:
|
|
7092
|
-
});
|
|
7093
|
-
var GuestAgentInfoSchema =
|
|
7094
|
-
app_id:
|
|
7095
|
-
instance_id:
|
|
7096
|
-
app_name:
|
|
7097
|
-
device_id:
|
|
7187
|
+
import { z as z90 } from "zod";
|
|
7188
|
+
var KmsInfoSchema2 = z90.object({
|
|
7189
|
+
contract_address: z90.string(),
|
|
7190
|
+
chain_id: z90.number().nullable(),
|
|
7191
|
+
version: z90.string(),
|
|
7192
|
+
url: z90.string(),
|
|
7193
|
+
gateway_app_id: z90.string().nullable(),
|
|
7194
|
+
gateway_app_url: z90.string(),
|
|
7195
|
+
kms_type: z90.string()
|
|
7196
|
+
});
|
|
7197
|
+
var GuestAgentInfoSchema = z90.object({
|
|
7198
|
+
app_id: z90.string().optional(),
|
|
7199
|
+
instance_id: z90.string().optional(),
|
|
7200
|
+
app_name: z90.string().optional(),
|
|
7201
|
+
device_id: z90.string().optional()
|
|
7098
7202
|
}).passthrough().nullable();
|
|
7099
|
-
var AppAttestationInstanceSchema =
|
|
7100
|
-
vm_uuid:
|
|
7101
|
-
name:
|
|
7102
|
-
instance_id:
|
|
7103
|
-
status:
|
|
7104
|
-
image_version:
|
|
7105
|
-
quote:
|
|
7106
|
-
ppid:
|
|
7107
|
-
ppid_sha256:
|
|
7108
|
-
device_id:
|
|
7109
|
-
fmspc:
|
|
7110
|
-
tee_tcb_svn:
|
|
7111
|
-
mr_config_id:
|
|
7112
|
-
cpusvn:
|
|
7113
|
-
pcesvn:
|
|
7203
|
+
var AppAttestationInstanceSchema = z90.object({
|
|
7204
|
+
vm_uuid: z90.string().nullable().optional(),
|
|
7205
|
+
name: z90.string().optional(),
|
|
7206
|
+
instance_id: z90.string().nullable().optional(),
|
|
7207
|
+
status: z90.string().optional(),
|
|
7208
|
+
image_version: z90.string().nullable().optional(),
|
|
7209
|
+
quote: z90.string().nullable().optional(),
|
|
7210
|
+
ppid: z90.string().optional(),
|
|
7211
|
+
ppid_sha256: z90.string().nullable().optional(),
|
|
7212
|
+
device_id: z90.string().optional(),
|
|
7213
|
+
fmspc: z90.string().nullable().optional(),
|
|
7214
|
+
tee_tcb_svn: z90.string().nullable().optional(),
|
|
7215
|
+
mr_config_id: z90.string().nullable().optional(),
|
|
7216
|
+
cpusvn: z90.string().nullable().optional(),
|
|
7217
|
+
pcesvn: z90.number().nullable().optional(),
|
|
7114
7218
|
tcb_info: TcbInfoSchema.nullable().optional(),
|
|
7115
|
-
app_certificates:
|
|
7116
|
-
compose_file:
|
|
7117
|
-
error:
|
|
7219
|
+
app_certificates: z90.array(CertificateSchema).nullable().optional(),
|
|
7220
|
+
compose_file: z90.string().nullable().optional(),
|
|
7221
|
+
error: z90.string().nullable().optional()
|
|
7118
7222
|
});
|
|
7119
|
-
var AppAttestationResponseSchema =
|
|
7120
|
-
app_id:
|
|
7121
|
-
contract_address:
|
|
7223
|
+
var AppAttestationResponseSchema = z90.object({
|
|
7224
|
+
app_id: z90.string(),
|
|
7225
|
+
contract_address: z90.string(),
|
|
7122
7226
|
kms_info: KmsInfoSchema2,
|
|
7123
|
-
instances:
|
|
7227
|
+
instances: z90.array(AppAttestationInstanceSchema),
|
|
7124
7228
|
kms_guest_agent_info: GuestAgentInfoSchema,
|
|
7125
7229
|
gateway_guest_agent_info: GuestAgentInfoSchema,
|
|
7126
|
-
qemu_version:
|
|
7230
|
+
qemu_version: z90.string().nullable()
|
|
7127
7231
|
});
|
|
7128
|
-
var GetAppAttestationRequestSchema =
|
|
7129
|
-
appId:
|
|
7232
|
+
var GetAppAttestationRequestSchema = z90.object({
|
|
7233
|
+
appId: z90.string().min(1)
|
|
7130
7234
|
}).strict();
|
|
7131
7235
|
var { action: getAppAttestation, safeAction: safeGetAppAttestation } = defineAction(AppAttestationResponseSchema, async (client, request) => {
|
|
7132
7236
|
const { appId } = GetAppAttestationRequestSchema.parse(request);
|
|
@@ -7134,17 +7238,17 @@ var { action: getAppAttestation, safeAction: safeGetAppAttestation } = defineAct
|
|
|
7134
7238
|
});
|
|
7135
7239
|
|
|
7136
7240
|
// src/actions/apps/app_launch_token.ts
|
|
7137
|
-
import { z as
|
|
7138
|
-
var AppLaunchTokenSchema =
|
|
7241
|
+
import { z as z91 } from "zod";
|
|
7242
|
+
var AppLaunchTokenSchema = z91.object({
|
|
7139
7243
|
/** The app's new launch token. Returned only here, once. */
|
|
7140
|
-
launch_token:
|
|
7244
|
+
launch_token: z91.string(),
|
|
7141
7245
|
/** Value for `requirements.launch_token_hash` of every CVM of the app. */
|
|
7142
|
-
launch_token_hash:
|
|
7246
|
+
launch_token_hash: z91.string()
|
|
7143
7247
|
});
|
|
7144
|
-
var SetAppLaunchTokenRequestSchema =
|
|
7145
|
-
appId:
|
|
7248
|
+
var SetAppLaunchTokenRequestSchema = z91.object({
|
|
7249
|
+
appId: z91.string().min(1),
|
|
7146
7250
|
/** Token to set (at least 32 bytes). Omit to have Phala Cloud generate one. */
|
|
7147
|
-
launchToken:
|
|
7251
|
+
launchToken: z91.string().optional()
|
|
7148
7252
|
});
|
|
7149
7253
|
var { action: setAppLaunchToken, safeAction: safeSetAppLaunchToken } = defineAction(AppLaunchTokenSchema, async (client, request) => {
|
|
7150
7254
|
const { appId, launchToken } = SetAppLaunchTokenRequestSchema.parse(request);
|
|
@@ -7153,36 +7257,36 @@ var { action: setAppLaunchToken, safeAction: safeSetAppLaunchToken } = defineAct
|
|
|
7153
7257
|
launchToken === void 0 ? {} : { launch_token: launchToken }
|
|
7154
7258
|
);
|
|
7155
7259
|
});
|
|
7156
|
-
var ClearAppLaunchTokenRequestSchema =
|
|
7157
|
-
appId:
|
|
7260
|
+
var ClearAppLaunchTokenRequestSchema = z91.object({
|
|
7261
|
+
appId: z91.string().min(1)
|
|
7158
7262
|
});
|
|
7159
|
-
var { action: clearAppLaunchToken, safeAction: safeClearAppLaunchToken } = defineAction(
|
|
7263
|
+
var { action: clearAppLaunchToken, safeAction: safeClearAppLaunchToken } = defineAction(z91.void(), async (client, request) => {
|
|
7160
7264
|
const { appId } = ClearAppLaunchTokenRequestSchema.parse(request);
|
|
7161
7265
|
await client.delete(`/apps/${appId}/launch-token`);
|
|
7162
7266
|
return void 0;
|
|
7163
7267
|
});
|
|
7164
7268
|
|
|
7165
7269
|
// src/actions/os_images/get_os_images.ts
|
|
7166
|
-
import { z as
|
|
7167
|
-
var OSImagePublicSchema =
|
|
7168
|
-
name:
|
|
7169
|
-
slug:
|
|
7170
|
-
version:
|
|
7171
|
-
os_image_hash:
|
|
7172
|
-
is_dev:
|
|
7173
|
-
requires_gpu:
|
|
7270
|
+
import { z as z92 } from "zod";
|
|
7271
|
+
var OSImagePublicSchema = z92.object({
|
|
7272
|
+
name: z92.string(),
|
|
7273
|
+
slug: z92.string(),
|
|
7274
|
+
version: z92.string(),
|
|
7275
|
+
os_image_hash: z92.string().nullable(),
|
|
7276
|
+
is_dev: z92.boolean(),
|
|
7277
|
+
requires_gpu: z92.boolean()
|
|
7174
7278
|
}).passthrough();
|
|
7175
|
-
var GetOsImagesRequestSchema =
|
|
7176
|
-
page:
|
|
7177
|
-
page_size:
|
|
7178
|
-
is_dev:
|
|
7279
|
+
var GetOsImagesRequestSchema = z92.object({
|
|
7280
|
+
page: z92.number().int().min(1).optional(),
|
|
7281
|
+
page_size: z92.number().int().min(1).optional(),
|
|
7282
|
+
is_dev: z92.boolean().optional()
|
|
7179
7283
|
}).strict();
|
|
7180
|
-
var GetOsImagesResponseSchema =
|
|
7181
|
-
items:
|
|
7182
|
-
total:
|
|
7183
|
-
page:
|
|
7184
|
-
page_size:
|
|
7185
|
-
pages:
|
|
7284
|
+
var GetOsImagesResponseSchema = z92.object({
|
|
7285
|
+
items: z92.array(OSImagePublicSchema),
|
|
7286
|
+
total: z92.number(),
|
|
7287
|
+
page: z92.number(),
|
|
7288
|
+
page_size: z92.number(),
|
|
7289
|
+
pages: z92.number()
|
|
7186
7290
|
}).passthrough();
|
|
7187
7291
|
var { action: getOsImages, safeAction: safeGetOsImages } = defineAction(GetOsImagesResponseSchema, async (client, request) => {
|
|
7188
7292
|
const validatedRequest = GetOsImagesRequestSchema.parse(request ?? {});
|
|
@@ -7218,6 +7322,8 @@ var additionalActions = {
|
|
|
7218
7322
|
safeUpdateCvmAnnotations,
|
|
7219
7323
|
getCvmInitScripts,
|
|
7220
7324
|
safeGetCvmInitScripts,
|
|
7325
|
+
putCvmInitScripts,
|
|
7326
|
+
safePutCvmInitScripts,
|
|
7221
7327
|
setAppLaunchToken,
|
|
7222
7328
|
safeSetAppLaunchToken,
|
|
7223
7329
|
clearAppLaunchToken,
|
|
@@ -7383,6 +7489,594 @@ function buildClient(client) {
|
|
|
7383
7489
|
return extended;
|
|
7384
7490
|
}
|
|
7385
7491
|
|
|
7492
|
+
// src/actions/cvms/log-time.ts
|
|
7493
|
+
var DURATION_SECONDS = {
|
|
7494
|
+
s: 1,
|
|
7495
|
+
m: 60,
|
|
7496
|
+
h: 60 * 60,
|
|
7497
|
+
d: 24 * 60 * 60
|
|
7498
|
+
};
|
|
7499
|
+
function parseRfc3339(value) {
|
|
7500
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|([+-])(\d{2}):(\d{2}))$/.exec(
|
|
7501
|
+
value
|
|
7502
|
+
);
|
|
7503
|
+
if (!match) return void 0;
|
|
7504
|
+
const year = Number(match[1]);
|
|
7505
|
+
const month = Number(match[2]);
|
|
7506
|
+
const day = Number(match[3]);
|
|
7507
|
+
const hour = Number(match[4]);
|
|
7508
|
+
const minute = Number(match[5]);
|
|
7509
|
+
const second = Number(match[6]);
|
|
7510
|
+
const fraction = match[7];
|
|
7511
|
+
const sign = match[9];
|
|
7512
|
+
const offsetHour = Number(match[10] ?? 0);
|
|
7513
|
+
const offsetMinute = Number(match[11] ?? 0);
|
|
7514
|
+
const lastDateOfMonth = /* @__PURE__ */ new Date(0);
|
|
7515
|
+
lastDateOfMonth.setUTCFullYear(year, month, 0);
|
|
7516
|
+
const daysInMonth = lastDateOfMonth.getUTCDate();
|
|
7517
|
+
if (year < 1 || month < 1 || month > 12 || day < 1 || day > daysInMonth || hour > 23 || minute > 59 || second > 59 || offsetHour > 23 || offsetMinute > 59) {
|
|
7518
|
+
return void 0;
|
|
7519
|
+
}
|
|
7520
|
+
const fractionalMilliseconds = fraction ? Number(`0.${fraction}`) * 1e3 : 0;
|
|
7521
|
+
const offset = sign === "+" ? 1 : sign === "-" ? -1 : 0;
|
|
7522
|
+
const offsetMilliseconds = offset * (offsetHour * 60 + offsetMinute) * 6e4;
|
|
7523
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
7524
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
7525
|
+
date.setUTCHours(hour, minute, second, 0);
|
|
7526
|
+
return date.getTime() + fractionalMilliseconds - offsetMilliseconds;
|
|
7527
|
+
}
|
|
7528
|
+
function parseLogTime(value, nowMs) {
|
|
7529
|
+
if (/^-?\d+$/.test(value)) {
|
|
7530
|
+
const seconds = Number(value);
|
|
7531
|
+
const milliseconds = seconds * 1e3;
|
|
7532
|
+
if (Number.isSafeInteger(seconds) && Number.isSafeInteger(milliseconds)) {
|
|
7533
|
+
return milliseconds;
|
|
7534
|
+
}
|
|
7535
|
+
}
|
|
7536
|
+
const relative = /^(\d+)([smhd])$/.exec(value);
|
|
7537
|
+
if (relative) {
|
|
7538
|
+
const unit = relative[2];
|
|
7539
|
+
if (!unit || !(unit in DURATION_SECONDS)) {
|
|
7540
|
+
throw new Error(
|
|
7541
|
+
`Invalid log time '${value}'. Use RFC3339, Unix seconds, or a relative duration such as 10m.`
|
|
7542
|
+
);
|
|
7543
|
+
}
|
|
7544
|
+
const duration = Number(relative[1]) * (DURATION_SECONDS[unit] ?? 0);
|
|
7545
|
+
const milliseconds = nowMs - duration * 1e3;
|
|
7546
|
+
if (Number.isFinite(milliseconds) && Number.isSafeInteger(Math.floor(milliseconds / 1e3))) {
|
|
7547
|
+
return milliseconds;
|
|
7548
|
+
}
|
|
7549
|
+
}
|
|
7550
|
+
const rfc3339 = parseRfc3339(value);
|
|
7551
|
+
if (rfc3339 !== void 0) return rfc3339;
|
|
7552
|
+
throw new Error(
|
|
7553
|
+
`Invalid log time '${value}'. Use RFC3339, Unix seconds, or a relative duration such as 10m.`
|
|
7554
|
+
);
|
|
7555
|
+
}
|
|
7556
|
+
function resolveLogTimeWindow(since, until, nowMs = Date.now()) {
|
|
7557
|
+
const resolvedSince = since === void 0 ? void 0 : typeof since === "number" ? Math.floor(since) : Math.floor(parseLogTime(since, nowMs) / 1e3);
|
|
7558
|
+
const resolvedUntil = until === void 0 ? void 0 : typeof until === "number" ? Math.ceil(until) : Math.ceil(parseLogTime(until, nowMs) / 1e3);
|
|
7559
|
+
if (resolvedSince !== void 0 && !Number.isSafeInteger(resolvedSince) || resolvedUntil !== void 0 && !Number.isSafeInteger(resolvedUntil)) {
|
|
7560
|
+
throw new Error("Log time is outside the supported Unix seconds range.");
|
|
7561
|
+
}
|
|
7562
|
+
return {
|
|
7563
|
+
...resolvedSince === void 0 ? {} : { since: resolvedSince },
|
|
7564
|
+
...resolvedUntil === void 0 ? {} : { until: resolvedUntil }
|
|
7565
|
+
};
|
|
7566
|
+
}
|
|
7567
|
+
|
|
7568
|
+
// src/actions/cvms/logs.ts
|
|
7569
|
+
var CVM_LOGS_INFO_API_VERSION = "2026-01-21";
|
|
7570
|
+
var LOG_ERROR_HTTP_STATUS = {
|
|
7571
|
+
"ERR-17-001": 400,
|
|
7572
|
+
"ERR-17-002": 401,
|
|
7573
|
+
"ERR-17-003": 401,
|
|
7574
|
+
"ERR-17-004": 404,
|
|
7575
|
+
"ERR-17-005": 409,
|
|
7576
|
+
"ERR-17-006": 409,
|
|
7577
|
+
"ERR-17-007": 404,
|
|
7578
|
+
"ERR-17-008": 502,
|
|
7579
|
+
"ERR-17-009": 502,
|
|
7580
|
+
"ERR-17-010": 504,
|
|
7581
|
+
"ERR-17-011": 429,
|
|
7582
|
+
"ERR-17-012": 503,
|
|
7583
|
+
"ERR-17-013": 404
|
|
7584
|
+
};
|
|
7585
|
+
function logErrorHttpStatus(code) {
|
|
7586
|
+
return LOG_ERROR_HTTP_STATUS[code];
|
|
7587
|
+
}
|
|
7588
|
+
var LogAccessError = class extends ResourceError {
|
|
7589
|
+
constructor(options) {
|
|
7590
|
+
const details = options.code ? `${options.code}: ${options.message}` : options.message;
|
|
7591
|
+
const suggestionText = options.suggestions?.length ? `
|
|
7592
|
+
Suggestions:
|
|
7593
|
+
${options.suggestions.map((suggestion) => `- ${suggestion}`).join("\n")}` : "";
|
|
7594
|
+
const status = options.httpStatus ?? (options.code ? logErrorHttpStatus(options.code) : void 0) ?? 0;
|
|
7595
|
+
super(`${details}${suggestionText}`, {
|
|
7596
|
+
status,
|
|
7597
|
+
statusText: "",
|
|
7598
|
+
errorCode: options.code,
|
|
7599
|
+
suggestions: options.suggestions ? [...options.suggestions] : void 0
|
|
7600
|
+
});
|
|
7601
|
+
this.name = "LogAccessError";
|
|
7602
|
+
this.code = options.code;
|
|
7603
|
+
this.httpStatus = status || void 0;
|
|
7604
|
+
this.suggestions = options.suggestions ? [...options.suggestions] : [];
|
|
7605
|
+
}
|
|
7606
|
+
};
|
|
7607
|
+
function resolveCvmId(id) {
|
|
7608
|
+
return CvmIdSchema.parse(typeof id === "string" ? { id } : id).cvmId;
|
|
7609
|
+
}
|
|
7610
|
+
function buildLogUrl(baseUrl, options) {
|
|
7611
|
+
const params = [];
|
|
7612
|
+
if (options.since !== void 0) params.push(`since=${options.since}`);
|
|
7613
|
+
if (options.until !== void 0) params.push(`until=${options.until}`);
|
|
7614
|
+
if (options.follow) params.push("follow=true");
|
|
7615
|
+
if (options.tail !== void 0) params.push(`tail=${options.tail}`);
|
|
7616
|
+
if (options.timestamps) params.push("timestamps=true");
|
|
7617
|
+
if (options.ansi) params.push("ansi=true");
|
|
7618
|
+
if (options.format) params.push(`format=${options.format}`);
|
|
7619
|
+
const sep = baseUrl.includes("?") ? "&" : "?";
|
|
7620
|
+
return params.length > 0 ? `${baseUrl}${sep}${params.join("&")}` : baseUrl;
|
|
7621
|
+
}
|
|
7622
|
+
async function streamResponse(response, onData) {
|
|
7623
|
+
const reader = response.body?.getReader();
|
|
7624
|
+
if (!reader) throw new Error("No response body available for streaming");
|
|
7625
|
+
const decoder = new TextDecoder();
|
|
7626
|
+
let buffer = "";
|
|
7627
|
+
let finished = false;
|
|
7628
|
+
try {
|
|
7629
|
+
while (true) {
|
|
7630
|
+
const { done, value } = await reader.read();
|
|
7631
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
7632
|
+
let newline = buffer.indexOf("\n");
|
|
7633
|
+
while (newline >= 0) {
|
|
7634
|
+
const line = buffer.slice(0, newline + 1);
|
|
7635
|
+
buffer = buffer.slice(newline + 1);
|
|
7636
|
+
const content = line.replace(/\r?\n$/, "");
|
|
7637
|
+
if (content !== "[vmm heartbeat]" && content !== "[teepod heartbeat]") {
|
|
7638
|
+
throwTextStreamError(content);
|
|
7639
|
+
onData(line);
|
|
7640
|
+
}
|
|
7641
|
+
newline = buffer.indexOf("\n");
|
|
7642
|
+
}
|
|
7643
|
+
if (done) {
|
|
7644
|
+
finished = true;
|
|
7645
|
+
break;
|
|
7646
|
+
}
|
|
7647
|
+
}
|
|
7648
|
+
if (buffer && buffer !== "[vmm heartbeat]" && buffer !== "[teepod heartbeat]") {
|
|
7649
|
+
throwTextStreamError(buffer);
|
|
7650
|
+
onData(buffer);
|
|
7651
|
+
}
|
|
7652
|
+
} finally {
|
|
7653
|
+
if (!finished) await reader.cancel().catch(() => {
|
|
7654
|
+
});
|
|
7655
|
+
reader.releaseLock();
|
|
7656
|
+
}
|
|
7657
|
+
}
|
|
7658
|
+
async function throwResponseError(response) {
|
|
7659
|
+
const body = await response.text();
|
|
7660
|
+
let envelope;
|
|
7661
|
+
try {
|
|
7662
|
+
envelope = JSON.parse(body);
|
|
7663
|
+
} catch {
|
|
7664
|
+
envelope = {};
|
|
7665
|
+
}
|
|
7666
|
+
const suggestions = Array.isArray(envelope.suggestions) ? envelope.suggestions.filter((item) => typeof item === "string") : [];
|
|
7667
|
+
throw new LogAccessError({
|
|
7668
|
+
code: typeof envelope.error_code === "string" ? envelope.error_code : void 0,
|
|
7669
|
+
message: typeof envelope.message === "string" ? envelope.message : `HTTP ${response.status} ${response.statusText}`,
|
|
7670
|
+
httpStatus: response.status,
|
|
7671
|
+
suggestions
|
|
7672
|
+
});
|
|
7673
|
+
}
|
|
7674
|
+
function throwTextStreamError(line) {
|
|
7675
|
+
const match = /^\[error\] (ERR-17-\d{3}) (.*)$/.exec(line.trim());
|
|
7676
|
+
const code = match?.[1];
|
|
7677
|
+
const message = match?.[2];
|
|
7678
|
+
if (code && message !== void 0) throw new LogAccessError({ code, message });
|
|
7679
|
+
}
|
|
7680
|
+
function parseTimestampedMessage(message) {
|
|
7681
|
+
const match = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})) (.*)$/s.exec(
|
|
7682
|
+
message
|
|
7683
|
+
);
|
|
7684
|
+
if (!match) return {};
|
|
7685
|
+
const time = Date.parse(match[1]);
|
|
7686
|
+
if (!Number.isFinite(time)) return {};
|
|
7687
|
+
return {
|
|
7688
|
+
timestamp: match[1],
|
|
7689
|
+
second: Math.floor(time / 1e3),
|
|
7690
|
+
message: match[2]
|
|
7691
|
+
};
|
|
7692
|
+
}
|
|
7693
|
+
function formatFollowContainerEntry(entry, includeTimestamps) {
|
|
7694
|
+
if (includeTimestamps) return { channel: entry.channel, message: entry.message };
|
|
7695
|
+
const timestamp = parseTimestampedMessage(entry.message);
|
|
7696
|
+
return {
|
|
7697
|
+
channel: entry.channel,
|
|
7698
|
+
message: timestamp.timestamp ? timestamp.message ?? "" : entry.message
|
|
7699
|
+
};
|
|
7700
|
+
}
|
|
7701
|
+
function parseStructuredLogLineToEntry(line) {
|
|
7702
|
+
const trimmed = line.trim();
|
|
7703
|
+
if (!trimmed) return null;
|
|
7704
|
+
let parsed;
|
|
7705
|
+
try {
|
|
7706
|
+
parsed = JSON.parse(trimmed);
|
|
7707
|
+
} catch {
|
|
7708
|
+
throw new LogAccessError({ message: "Invalid NDJSON log record." });
|
|
7709
|
+
}
|
|
7710
|
+
if (typeof parsed.error_code === "string") {
|
|
7711
|
+
throw new LogAccessError({
|
|
7712
|
+
code: parsed.error_code,
|
|
7713
|
+
message: typeof parsed.message === "string" ? parsed.message : "The log stream ended with an error.",
|
|
7714
|
+
suggestions: Array.isArray(parsed.suggestions) ? parsed.suggestions.filter((item) => typeof item === "string") : []
|
|
7715
|
+
});
|
|
7716
|
+
}
|
|
7717
|
+
if (parsed.channel !== "stdout" && parsed.channel !== "stderr" || typeof parsed.message !== "string") {
|
|
7718
|
+
throw new LogAccessError({ message: "Invalid NDJSON log record." });
|
|
7719
|
+
}
|
|
7720
|
+
const entry = {
|
|
7721
|
+
channel: parsed.channel,
|
|
7722
|
+
message: parsed.message
|
|
7723
|
+
};
|
|
7724
|
+
const timestamp = parseTimestampedMessage(entry.message).timestamp;
|
|
7725
|
+
if (timestamp) entry.timestamp = timestamp;
|
|
7726
|
+
return entry;
|
|
7727
|
+
}
|
|
7728
|
+
function parseStructuredLogsToEntries(input) {
|
|
7729
|
+
const entries = [];
|
|
7730
|
+
for (const line of input.split(/\r?\n/)) {
|
|
7731
|
+
const entry = parseStructuredLogLineToEntry(line);
|
|
7732
|
+
if (entry) entries.push(entry);
|
|
7733
|
+
}
|
|
7734
|
+
return entries;
|
|
7735
|
+
}
|
|
7736
|
+
async function streamNdjsonEntriesResponse(response, onEntry) {
|
|
7737
|
+
const reader = response.body?.getReader();
|
|
7738
|
+
if (!reader) throw new Error("No response body available for streaming");
|
|
7739
|
+
const decoder = new TextDecoder();
|
|
7740
|
+
let buffer = "";
|
|
7741
|
+
let finished = false;
|
|
7742
|
+
try {
|
|
7743
|
+
while (true) {
|
|
7744
|
+
const { done, value } = await reader.read();
|
|
7745
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
7746
|
+
let newline = buffer.indexOf("\n");
|
|
7747
|
+
while (newline >= 0) {
|
|
7748
|
+
const entry = parseStructuredLogLineToEntry(buffer.slice(0, newline));
|
|
7749
|
+
if (entry) onEntry(entry);
|
|
7750
|
+
buffer = buffer.slice(newline + 1);
|
|
7751
|
+
newline = buffer.indexOf("\n");
|
|
7752
|
+
}
|
|
7753
|
+
if (done) {
|
|
7754
|
+
finished = true;
|
|
7755
|
+
break;
|
|
7756
|
+
}
|
|
7757
|
+
}
|
|
7758
|
+
if (buffer.trim()) {
|
|
7759
|
+
const entry = parseStructuredLogLineToEntry(buffer);
|
|
7760
|
+
if (entry) onEntry(entry);
|
|
7761
|
+
}
|
|
7762
|
+
} finally {
|
|
7763
|
+
if (!finished) await reader.cancel().catch(() => {
|
|
7764
|
+
});
|
|
7765
|
+
reader.releaseLock();
|
|
7766
|
+
}
|
|
7767
|
+
}
|
|
7768
|
+
function assertSupportedNodeLogOptions(options) {
|
|
7769
|
+
const unsupported = [
|
|
7770
|
+
options.timestamps && "timestamps",
|
|
7771
|
+
options.since !== void 0 && "since",
|
|
7772
|
+
options.until !== void 0 && "until",
|
|
7773
|
+
options.format === "ndjson" && "format=ndjson"
|
|
7774
|
+
].filter((option) => Boolean(option));
|
|
7775
|
+
if (unsupported.length > 0) {
|
|
7776
|
+
throw new Error(`${unsupported.join(", ")} not supported for serial/stdout/stderr logs`);
|
|
7777
|
+
}
|
|
7778
|
+
if (options.ansi && options.format === "ndjson") {
|
|
7779
|
+
throw new LogAccessError({
|
|
7780
|
+
code: "ERR-17-001",
|
|
7781
|
+
message: "ansi is valid only with format=text"
|
|
7782
|
+
});
|
|
7783
|
+
}
|
|
7784
|
+
}
|
|
7785
|
+
async function getCvmInfoLogs(client, cvmId) {
|
|
7786
|
+
return await client.get(`/cvms/${cvmId}`, {
|
|
7787
|
+
headers: { "X-Phala-Version": CVM_LOGS_INFO_API_VERSION }
|
|
7788
|
+
});
|
|
7789
|
+
}
|
|
7790
|
+
async function getCvmLogEndpoint(client, id, channel) {
|
|
7791
|
+
const cvmId = resolveCvmId(id);
|
|
7792
|
+
const info = await getCvmInfoLogs(client, cvmId);
|
|
7793
|
+
const endpoint = info.logs?.[channel];
|
|
7794
|
+
if (!endpoint) {
|
|
7795
|
+
throw new Error(`No ${channel} log endpoint available for CVM '${cvmId}'`);
|
|
7796
|
+
}
|
|
7797
|
+
return endpoint;
|
|
7798
|
+
}
|
|
7799
|
+
async function getContainerLogEndpoint(client, id, containerName, matchContainerIdPrefix = true) {
|
|
7800
|
+
const cvmId = resolveCvmId(id);
|
|
7801
|
+
const composition = await client.get(`/cvms/${cvmId}/composition`);
|
|
7802
|
+
if (!composition.containers?.length) {
|
|
7803
|
+
throw new Error(`No containers found for CVM '${cvmId}'`);
|
|
7804
|
+
}
|
|
7805
|
+
let containers = composition.containers;
|
|
7806
|
+
if (containerName) {
|
|
7807
|
+
containers = containers.filter((c) => {
|
|
7808
|
+
const matchedByName = c.names.some((n) => n === containerName || n === `/${containerName}`);
|
|
7809
|
+
if (matchedByName) return true;
|
|
7810
|
+
if (!matchContainerIdPrefix) return false;
|
|
7811
|
+
return c.id.startsWith(containerName);
|
|
7812
|
+
});
|
|
7813
|
+
if (!containers.length) {
|
|
7814
|
+
throw new Error(`Container '${containerName}' not found in CVM '${cvmId}'`);
|
|
7815
|
+
}
|
|
7816
|
+
}
|
|
7817
|
+
const container = containers.find((c) => c.log_endpoint);
|
|
7818
|
+
if (!container?.log_endpoint) {
|
|
7819
|
+
throw new Error(`No log endpoints available for CVM '${cvmId}'`);
|
|
7820
|
+
}
|
|
7821
|
+
return container.log_endpoint;
|
|
7822
|
+
}
|
|
7823
|
+
function waitForReconnect(signal, delayMs) {
|
|
7824
|
+
if (signal?.aborted) return Promise.resolve();
|
|
7825
|
+
return new Promise((resolve) => {
|
|
7826
|
+
const timeout = setTimeout(() => {
|
|
7827
|
+
signal?.removeEventListener("abort", onAbort);
|
|
7828
|
+
resolve();
|
|
7829
|
+
}, delayMs);
|
|
7830
|
+
const onAbort = () => {
|
|
7831
|
+
clearTimeout(timeout);
|
|
7832
|
+
signal?.removeEventListener("abort", onAbort);
|
|
7833
|
+
resolve();
|
|
7834
|
+
};
|
|
7835
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
7836
|
+
});
|
|
7837
|
+
}
|
|
7838
|
+
function getErrorHttpStatus(error) {
|
|
7839
|
+
if (typeof error !== "object" || error === null) return void 0;
|
|
7840
|
+
if ("httpStatus" in error && typeof error.httpStatus === "number") {
|
|
7841
|
+
return error.httpStatus;
|
|
7842
|
+
}
|
|
7843
|
+
if ("status" in error && typeof error.status === "number") {
|
|
7844
|
+
return error.status;
|
|
7845
|
+
}
|
|
7846
|
+
return void 0;
|
|
7847
|
+
}
|
|
7848
|
+
async function followLogRequests(resolveUrl, consume, signal, refreshCvm) {
|
|
7849
|
+
let failureCount = 0;
|
|
7850
|
+
let expiredRetries = 0;
|
|
7851
|
+
while (!signal?.aborted) {
|
|
7852
|
+
try {
|
|
7853
|
+
const url = await resolveUrl();
|
|
7854
|
+
if (signal?.aborted) return;
|
|
7855
|
+
const response = await fetch(url, { signal });
|
|
7856
|
+
if (!response.ok) await throwResponseError(response);
|
|
7857
|
+
failureCount = 0;
|
|
7858
|
+
await consume(response);
|
|
7859
|
+
expiredRetries = 0;
|
|
7860
|
+
if (signal?.aborted) return;
|
|
7861
|
+
} catch (error) {
|
|
7862
|
+
if (signal?.aborted || error instanceof Error && error.name === "AbortError") {
|
|
7863
|
+
return;
|
|
7864
|
+
}
|
|
7865
|
+
let retryError = error;
|
|
7866
|
+
if (error instanceof LogAccessError && error.code === "ERR-17-003") {
|
|
7867
|
+
expiredRetries += 1;
|
|
7868
|
+
if (expiredRetries > 3) throw error;
|
|
7869
|
+
try {
|
|
7870
|
+
await refreshCvm?.();
|
|
7871
|
+
continue;
|
|
7872
|
+
} catch (refreshError) {
|
|
7873
|
+
retryError = refreshError;
|
|
7874
|
+
}
|
|
7875
|
+
}
|
|
7876
|
+
const status = getErrorHttpStatus(retryError);
|
|
7877
|
+
if (status !== void 0 && status < 500) throw retryError;
|
|
7878
|
+
if (retryError instanceof LogAccessError && status === void 0) {
|
|
7879
|
+
throw retryError;
|
|
7880
|
+
}
|
|
7881
|
+
failureCount += 1;
|
|
7882
|
+
if (failureCount >= 5) throw retryError;
|
|
7883
|
+
const delayMs = Math.min(250 * 2 ** (failureCount - 1), 5e3);
|
|
7884
|
+
await waitForReconnect(signal, delayMs);
|
|
7885
|
+
}
|
|
7886
|
+
}
|
|
7887
|
+
}
|
|
7888
|
+
async function fetchCvmChannelLogs(client, id, channel, options = {}) {
|
|
7889
|
+
assertSupportedNodeLogOptions(options);
|
|
7890
|
+
const times = resolveLogTimeWindow(options.since, options.until);
|
|
7891
|
+
const baseUrl = await getCvmLogEndpoint(client, id, channel);
|
|
7892
|
+
const url = buildLogUrl(baseUrl, {
|
|
7893
|
+
since: times.since,
|
|
7894
|
+
until: times.until,
|
|
7895
|
+
tail: options.tail,
|
|
7896
|
+
ansi: options.ansi
|
|
7897
|
+
});
|
|
7898
|
+
const response = await fetch(url, { signal: options.signal });
|
|
7899
|
+
if (!response.ok) await throwResponseError(response);
|
|
7900
|
+
return response.text();
|
|
7901
|
+
}
|
|
7902
|
+
async function streamCvmChannelLogs(client, id, channel, onData, options = {}, signal) {
|
|
7903
|
+
assertSupportedNodeLogOptions(options);
|
|
7904
|
+
const abort = signal ?? options.signal;
|
|
7905
|
+
const times = resolveLogTimeWindow(options.since, options.until);
|
|
7906
|
+
let firstRequest = true;
|
|
7907
|
+
await followLogRequests(
|
|
7908
|
+
async () => {
|
|
7909
|
+
const baseUrl = await getCvmLogEndpoint(client, id, channel);
|
|
7910
|
+
const tail = firstRequest ? options.tail : 0;
|
|
7911
|
+
firstRequest = false;
|
|
7912
|
+
return buildLogUrl(baseUrl, {
|
|
7913
|
+
since: times.since,
|
|
7914
|
+
until: times.until,
|
|
7915
|
+
tail,
|
|
7916
|
+
follow: true,
|
|
7917
|
+
ansi: options.ansi
|
|
7918
|
+
});
|
|
7919
|
+
},
|
|
7920
|
+
(response) => streamResponse(response, onData),
|
|
7921
|
+
abort,
|
|
7922
|
+
async () => {
|
|
7923
|
+
await getCvmInfoLogs(client, resolveCvmId(id));
|
|
7924
|
+
}
|
|
7925
|
+
);
|
|
7926
|
+
}
|
|
7927
|
+
async function fetchContainerLogsEntries(client, id, options = {}) {
|
|
7928
|
+
const times = resolveLogTimeWindow(options.since, options.until);
|
|
7929
|
+
const baseUrl = await getContainerLogEndpoint(
|
|
7930
|
+
client,
|
|
7931
|
+
id,
|
|
7932
|
+
options.container,
|
|
7933
|
+
options.matchContainerIdPrefix ?? true
|
|
7934
|
+
);
|
|
7935
|
+
const url = buildLogUrl(baseUrl, {
|
|
7936
|
+
...times,
|
|
7937
|
+
tail: options.tail,
|
|
7938
|
+
timestamps: options.timestamps,
|
|
7939
|
+
ansi: options.ansi,
|
|
7940
|
+
format: options.format ?? "ndjson"
|
|
7941
|
+
});
|
|
7942
|
+
const response = await fetch(url, { signal: options.signal });
|
|
7943
|
+
if (!response.ok) await throwResponseError(response);
|
|
7944
|
+
return parseStructuredLogsToEntries(await response.text());
|
|
7945
|
+
}
|
|
7946
|
+
async function fetchContainerLogs(client, id, options = {}) {
|
|
7947
|
+
const entries = await fetchContainerLogsEntries(client, id, {
|
|
7948
|
+
...options,
|
|
7949
|
+
format: "ndjson"
|
|
7950
|
+
});
|
|
7951
|
+
return entries.map((entry) => entry.message === "" ? "\n" : entry.message).join("");
|
|
7952
|
+
}
|
|
7953
|
+
async function streamContainerLogsEntries(client, id, onEntry, options = {}, signal) {
|
|
7954
|
+
const abort = signal ?? options.signal;
|
|
7955
|
+
const times = resolveLogTimeWindow(options.since, options.until);
|
|
7956
|
+
const cursor = { since: times.since, boundaryCounts: /* @__PURE__ */ new Map() };
|
|
7957
|
+
let replayCounts = /* @__PURE__ */ new Map();
|
|
7958
|
+
let firstRequest = true;
|
|
7959
|
+
const buildRequestUrl = async () => {
|
|
7960
|
+
const baseUrl = await getContainerLogEndpoint(
|
|
7961
|
+
client,
|
|
7962
|
+
id,
|
|
7963
|
+
options.container,
|
|
7964
|
+
options.matchContainerIdPrefix ?? true
|
|
7965
|
+
);
|
|
7966
|
+
const tail = firstRequest ? options.tail : void 0;
|
|
7967
|
+
firstRequest = false;
|
|
7968
|
+
replayCounts = new Map(cursor.boundaryCounts);
|
|
7969
|
+
return buildLogUrl(baseUrl, {
|
|
7970
|
+
since: cursor.since,
|
|
7971
|
+
until: times.until,
|
|
7972
|
+
tail,
|
|
7973
|
+
follow: true,
|
|
7974
|
+
timestamps: true,
|
|
7975
|
+
format: "ndjson"
|
|
7976
|
+
});
|
|
7977
|
+
};
|
|
7978
|
+
await followLogRequests(
|
|
7979
|
+
buildRequestUrl,
|
|
7980
|
+
(response) => streamNdjsonEntriesResponse(response, (entry) => {
|
|
7981
|
+
const timestamp = parseTimestampedMessage(entry.message);
|
|
7982
|
+
if (timestamp.second === void 0 || !timestamp.timestamp) {
|
|
7983
|
+
onEntry(formatFollowContainerEntry(entry, options.timestamps ?? false));
|
|
7984
|
+
return;
|
|
7985
|
+
}
|
|
7986
|
+
const key = JSON.stringify([entry.channel, entry.message]);
|
|
7987
|
+
if (cursor.boundarySecond !== void 0 && timestamp.second < cursor.boundarySecond) {
|
|
7988
|
+
onEntry(formatFollowContainerEntry(entry, options.timestamps ?? false));
|
|
7989
|
+
return;
|
|
7990
|
+
}
|
|
7991
|
+
if (timestamp.second === cursor.boundarySecond) {
|
|
7992
|
+
const replayCount = replayCounts.get(key) ?? 0;
|
|
7993
|
+
if (replayCount > 0) {
|
|
7994
|
+
replayCounts.set(key, replayCount - 1);
|
|
7995
|
+
return;
|
|
7996
|
+
}
|
|
7997
|
+
} else if (cursor.boundarySecond === void 0 || timestamp.second > cursor.boundarySecond) {
|
|
7998
|
+
cursor.boundarySecond = timestamp.second;
|
|
7999
|
+
cursor.boundaryCounts.clear();
|
|
8000
|
+
}
|
|
8001
|
+
cursor.since = Math.max(cursor.since ?? timestamp.second, timestamp.second);
|
|
8002
|
+
cursor.boundaryCounts.set(key, (cursor.boundaryCounts.get(key) ?? 0) + 1);
|
|
8003
|
+
onEntry(formatFollowContainerEntry(entry, options.timestamps ?? false));
|
|
8004
|
+
}),
|
|
8005
|
+
abort,
|
|
8006
|
+
async () => {
|
|
8007
|
+
await getCvmInfoLogs(client, resolveCvmId(id));
|
|
8008
|
+
}
|
|
8009
|
+
);
|
|
8010
|
+
}
|
|
8011
|
+
async function streamContainerLogs(client, id, onData, options = {}, signal) {
|
|
8012
|
+
return streamContainerLogsEntries(
|
|
8013
|
+
client,
|
|
8014
|
+
id,
|
|
8015
|
+
(entry) => onData(entry.message === "" ? "\n" : entry.message),
|
|
8016
|
+
options,
|
|
8017
|
+
signal
|
|
8018
|
+
);
|
|
8019
|
+
}
|
|
8020
|
+
async function fetchCvmLogs(client, id, source, options = {}) {
|
|
8021
|
+
if (source.type === "node") {
|
|
8022
|
+
return fetchCvmChannelLogs(client, id, source.channel, options);
|
|
8023
|
+
}
|
|
8024
|
+
if (options.format === "ndjson") {
|
|
8025
|
+
return fetchContainerLogsEntries(client, id, {
|
|
8026
|
+
...options,
|
|
8027
|
+
container: source.name,
|
|
8028
|
+
matchContainerIdPrefix: source.matchContainerIdPrefix
|
|
8029
|
+
});
|
|
8030
|
+
}
|
|
8031
|
+
return fetchContainerLogs(client, id, {
|
|
8032
|
+
...options,
|
|
8033
|
+
container: source.name,
|
|
8034
|
+
matchContainerIdPrefix: source.matchContainerIdPrefix
|
|
8035
|
+
});
|
|
8036
|
+
}
|
|
8037
|
+
async function* followCvmLogs(client, id, source, options = {}) {
|
|
8038
|
+
const pending = [];
|
|
8039
|
+
let wake;
|
|
8040
|
+
let done = false;
|
|
8041
|
+
let error;
|
|
8042
|
+
const push = (item) => {
|
|
8043
|
+
pending.push(item);
|
|
8044
|
+
wake?.();
|
|
8045
|
+
};
|
|
8046
|
+
const run = source.type === "node" ? streamCvmChannelLogs(client, id, source.channel, push, options, options.signal) : streamContainerLogsEntries(
|
|
8047
|
+
client,
|
|
8048
|
+
id,
|
|
8049
|
+
push,
|
|
8050
|
+
{
|
|
8051
|
+
...options,
|
|
8052
|
+
container: source.name,
|
|
8053
|
+
matchContainerIdPrefix: source.matchContainerIdPrefix
|
|
8054
|
+
},
|
|
8055
|
+
options.signal
|
|
8056
|
+
);
|
|
8057
|
+
void run.then(
|
|
8058
|
+
() => {
|
|
8059
|
+
done = true;
|
|
8060
|
+
wake?.();
|
|
8061
|
+
},
|
|
8062
|
+
(reason) => {
|
|
8063
|
+
error = reason;
|
|
8064
|
+
done = true;
|
|
8065
|
+
wake?.();
|
|
8066
|
+
}
|
|
8067
|
+
);
|
|
8068
|
+
while (!done || pending.length > 0) {
|
|
8069
|
+
if (pending.length > 0) {
|
|
8070
|
+
yield pending.shift();
|
|
8071
|
+
continue;
|
|
8072
|
+
}
|
|
8073
|
+
await new Promise((resolve) => {
|
|
8074
|
+
wake = resolve;
|
|
8075
|
+
});
|
|
8076
|
+
}
|
|
8077
|
+
if (error) throw error;
|
|
8078
|
+
}
|
|
8079
|
+
|
|
7386
8080
|
// src/parse_dotenv.ts
|
|
7387
8081
|
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
7388
8082
|
function parseEnv(input) {
|
|
@@ -7585,6 +8279,7 @@ export {
|
|
|
7585
8279
|
ListKmsContractsSchema,
|
|
7586
8280
|
ListSshKeysResponseSchema,
|
|
7587
8281
|
ListWorkspacesSchema,
|
|
8282
|
+
LogAccessError,
|
|
7588
8283
|
LooseAppComposeSchema,
|
|
7589
8284
|
MAX_COMPOSE_PAYLOAD_BYTES,
|
|
7590
8285
|
MAX_INIT_SCRIPTS,
|
|
@@ -7615,6 +8310,7 @@ export {
|
|
|
7615
8310
|
ProvisionCvmComposeFileUpdateResultSchema,
|
|
7616
8311
|
ProvisionCvmRequestSchema,
|
|
7617
8312
|
ProvisionCvmSchema,
|
|
8313
|
+
PutCvmInitScriptsRequestSchema,
|
|
7618
8314
|
QuotaMetricSchema,
|
|
7619
8315
|
RefreshCvmInstanceIdRequestSchema,
|
|
7620
8316
|
RefreshCvmInstanceIdsRequestSchema,
|
|
@@ -7711,6 +8407,11 @@ export {
|
|
|
7711
8407
|
executeTransaction,
|
|
7712
8408
|
executeTransactionWithRetry,
|
|
7713
8409
|
extractNetworkClients,
|
|
8410
|
+
fetchContainerLogs,
|
|
8411
|
+
fetchContainerLogsEntries,
|
|
8412
|
+
fetchCvmChannelLogs,
|
|
8413
|
+
fetchCvmLogs,
|
|
8414
|
+
followCvmLogs,
|
|
7714
8415
|
formatErrorMessage,
|
|
7715
8416
|
formatStructuredError,
|
|
7716
8417
|
formatStructuredErrorDetailValue,
|
|
@@ -7740,6 +8441,7 @@ export {
|
|
|
7740
8441
|
getCvmInfo,
|
|
7741
8442
|
getCvmInitScripts,
|
|
7742
8443
|
getCvmList,
|
|
8444
|
+
getCvmLogEndpoint,
|
|
7743
8445
|
getCvmNetwork,
|
|
7744
8446
|
getCvmPreLaunchScript,
|
|
7745
8447
|
getCvmSshKeys,
|
|
@@ -7781,11 +8483,13 @@ export {
|
|
|
7781
8483
|
preprocessAppCompose,
|
|
7782
8484
|
provisionCvm,
|
|
7783
8485
|
provisionCvmComposeFileUpdate,
|
|
8486
|
+
putCvmInitScripts,
|
|
7784
8487
|
refineCvmId,
|
|
7785
8488
|
refreshCvmInstanceId,
|
|
7786
8489
|
refreshCvmInstanceIds,
|
|
7787
8490
|
removeDevice,
|
|
7788
8491
|
replicateCvm,
|
|
8492
|
+
resolveLogTimeWindow,
|
|
7789
8493
|
restartCvm,
|
|
7790
8494
|
revokeCurrentApiToken,
|
|
7791
8495
|
safeAddComposeHash,
|
|
@@ -7855,6 +8559,7 @@ export {
|
|
|
7855
8559
|
safePatchCvm,
|
|
7856
8560
|
safeProvisionCvm,
|
|
7857
8561
|
safeProvisionCvmComposeFileUpdate,
|
|
8562
|
+
safePutCvmInitScripts,
|
|
7858
8563
|
safeRefreshCvmInstanceId,
|
|
7859
8564
|
safeRefreshCvmInstanceIds,
|
|
7860
8565
|
safeRemoveDevice,
|
|
@@ -7883,6 +8588,9 @@ export {
|
|
|
7883
8588
|
sortObject,
|
|
7884
8589
|
startCvm,
|
|
7885
8590
|
stopCvm,
|
|
8591
|
+
streamContainerLogs,
|
|
8592
|
+
streamContainerLogsEntries,
|
|
8593
|
+
streamCvmChannelLogs,
|
|
7886
8594
|
switchToNetwork,
|
|
7887
8595
|
syncGithubSshKeys,
|
|
7888
8596
|
updateCvmAnnotations,
|