@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
|
@@ -1,47 +1,112 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type Client } from "../../client";
|
|
3
3
|
/**
|
|
4
|
-
* Provision a CVM
|
|
4
|
+
* Provision a CVM
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* Performs a pre-deployment eligibility check, validating whether the requested resources
|
|
7
|
+
* are available and the user has sufficient permissions to deploy. Returns provision data
|
|
8
|
+
* including `app_id`, encryption public key (`app_env_encrypt_pubkey`), and `compose_hash`
|
|
9
|
+
* required for the subsequent `commitCvmProvision` call.
|
|
10
|
+
*
|
|
11
|
+
* ## Automatic Resource Selection
|
|
12
|
+
*
|
|
13
|
+
* The new matching engine automatically selects optimal resources based on your requirements:
|
|
14
|
+
* - **Node Selection**: Specify `node_id` or `region`, or omit both for automatic best-match selection
|
|
15
|
+
* - **OS Image**: Specify exact image name or let system choose the latest stable version
|
|
16
|
+
* - **KMS**: Choose KMS type via `kms` parameter (defaults to PHALA) or specify `kms_id` directly
|
|
7
17
|
*
|
|
8
18
|
* @example
|
|
9
19
|
* ```typescript
|
|
10
|
-
* import { createClient,
|
|
20
|
+
* import { createClient, provisionCvm, commitCvmProvision } from '@phala/cloud'
|
|
11
21
|
*
|
|
12
22
|
* const client = createClient();
|
|
13
|
-
* const nodes = await getAvailableNodes(client);
|
|
14
|
-
* const node = nodes.nodes[0];
|
|
15
23
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* image: leechael/phala-cloud-bun-starter:latest
|
|
21
|
-
* container_name: demo
|
|
22
|
-
* ports:
|
|
23
|
-
* - "3000:3000"
|
|
24
|
-
* volumes:
|
|
25
|
-
* - /var/run/tappd.sock:/var/run/tappd.sock
|
|
26
|
-
*`;
|
|
27
|
-
*
|
|
28
|
-
* const app_compose = {
|
|
29
|
-
* name: 'my-app',
|
|
30
|
-
* node_id: node.node_id,
|
|
31
|
-
* image: node.images[0].name,
|
|
32
|
-
* vcpu: 1,
|
|
33
|
-
* memory: 1024,
|
|
34
|
-
* disk_size: 10,
|
|
24
|
+
* // Example 1: Minimal configuration with auto-selection
|
|
25
|
+
* const provision = await provisionCvm(client, {
|
|
26
|
+
* name: 'my-app', // Unique in workspace level
|
|
27
|
+
* instance_type: 'tdx.small',
|
|
35
28
|
* compose_file: {
|
|
36
|
-
* docker_compose_file:
|
|
37
|
-
*
|
|
29
|
+
* docker_compose_file: `
|
|
30
|
+
* services:
|
|
31
|
+
* demo:
|
|
32
|
+
* image: leechael/phala-cloud-bun-starter:latest
|
|
33
|
+
* ports:
|
|
34
|
+
* - "80:3000"
|
|
35
|
+
* volumes:
|
|
36
|
+
* - /var/run/dstack.sock:/var/run/dstack.sock
|
|
37
|
+
* `,
|
|
38
38
|
* },
|
|
39
|
-
* };
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Example 2: With region preference
|
|
42
|
+
* const provision = await provisionCvm(client, {
|
|
43
|
+
* name: 'my-app',
|
|
44
|
+
* instance_type: 'tdx.medium',
|
|
45
|
+
* region: 'us-east', // Filter by region
|
|
46
|
+
* compose_file: { /* ... *\/ },
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Example 3: With specific node and KMS type
|
|
50
|
+
* const provision = await provisionCvm(client, {
|
|
51
|
+
* name: 'my-app',
|
|
52
|
+
* node_id: 123, // Specific node
|
|
53
|
+
* kms: 'PHALA', // KMS type (PHALA, BASE, ETHERUEM)
|
|
54
|
+
* disk_size: 40,
|
|
55
|
+
* image: 'dstack-0.5.5',
|
|
56
|
+
* compose_file: { /* ... *\/ },
|
|
57
|
+
* });
|
|
40
58
|
*
|
|
41
|
-
*
|
|
42
|
-
* console.log(
|
|
59
|
+
* console.log(provision.app_id);
|
|
60
|
+
* console.log(provision.compose_hash); // Required for commitCvmProvision
|
|
43
61
|
* ```
|
|
44
62
|
*
|
|
63
|
+
* ## Required Parameters
|
|
64
|
+
*
|
|
65
|
+
* - **name**: CVM instance name
|
|
66
|
+
* - **compose_file**: Docker Compose configuration with `docker_compose_file` field
|
|
67
|
+
*
|
|
68
|
+
* ## Optional Parameters
|
|
69
|
+
*
|
|
70
|
+
* ### Instance Type
|
|
71
|
+
* - **instance_type**: Instance type identifier (default: "tdx.small")
|
|
72
|
+
* - Use `listAllInstanceTypeFamilies()` or `listFamilyInstanceTypes()` to discover available types
|
|
73
|
+
* - Examples: "tdx.small", "tdx.medium", "tdx.large"
|
|
74
|
+
* - Omit to use the default small instance type
|
|
75
|
+
*
|
|
76
|
+
* ### Node Selection (all optional - system auto-selects if omitted)
|
|
77
|
+
* - **node_id**: Specific node ID to deploy on
|
|
78
|
+
* - **region**: Region preference (e.g., "us-east", "eu-west")
|
|
79
|
+
* - If both omitted, system automatically selects the best available node
|
|
80
|
+
*
|
|
81
|
+
* ### OS Image Selection
|
|
82
|
+
* - **image**: OS image name (optional)
|
|
83
|
+
* - Omit to let the system automatically select the latest stable image
|
|
84
|
+
* - Specify a specific image name if needed (e.g., "dstack-0.5.5")
|
|
85
|
+
*
|
|
86
|
+
* ### KMS Configuration
|
|
87
|
+
* - **kms**: KMS type - "PHALA" (default), "ETHEREUM", or "BASE"
|
|
88
|
+
* - **kms_contract**: (Advanced) Specific KMS contract address
|
|
89
|
+
* - Omit to let the system automatically select an appropriate KMS contract
|
|
90
|
+
* - Specify only when: migrating KMS contracts, or selecting a specific contract on networks with multiple deployments
|
|
91
|
+
*
|
|
92
|
+
* ### Other Options
|
|
93
|
+
* - **disk_size**: Disk size in GB (optional)
|
|
94
|
+
* - Each instance type has a default disk size
|
|
95
|
+
* - Specify only if you need a different size than the default
|
|
96
|
+
* - **env_keys**: List of allowed environment variable keys
|
|
97
|
+
* - **listed**: Whether the CVM is publicly listed (default: true)
|
|
98
|
+
*
|
|
99
|
+
* ## Returns
|
|
100
|
+
*
|
|
101
|
+
* Provision data object containing:
|
|
102
|
+
* - **app_id**: Application identifier (required for commit step)
|
|
103
|
+
* - **app_env_encrypt_pubkey**: Public key for encrypting environment variables
|
|
104
|
+
* - **compose_hash**: Hash identifying this provision (required for commit step)
|
|
105
|
+
* - **device_id**: Device identifier for attestation
|
|
106
|
+
* - **fmspc**: Firmware Security Patch Configuration value
|
|
107
|
+
* - **os_image_hash**: Hash of the selected OS image
|
|
108
|
+
* - **instance_type**: The matched instance type identifier
|
|
109
|
+
*
|
|
45
110
|
* ## Safe Version
|
|
46
111
|
*
|
|
47
112
|
* Use `safeProvisionCvm` for error handling without exceptions:
|
|
@@ -50,6 +115,7 @@ import { type Client } from "../../client";
|
|
|
50
115
|
* const result = await safeProvisionCvm(client, app_compose);
|
|
51
116
|
* if (result.success) {
|
|
52
117
|
* console.log(result.data.app_id);
|
|
118
|
+
* console.log(result.data.compose_hash);
|
|
53
119
|
* } else {
|
|
54
120
|
* console.error('Failed to provision CVM:', result.error.message);
|
|
55
121
|
* }
|
|
@@ -62,6 +128,7 @@ export declare const ProvisionCvmSchema: z.ZodEffects<z.ZodObject<{
|
|
|
62
128
|
fmspc: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
129
|
device_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
64
130
|
os_image_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
131
|
+
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
65
132
|
teepod_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
66
133
|
node_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
67
134
|
kms_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -72,6 +139,7 @@ export declare const ProvisionCvmSchema: z.ZodEffects<z.ZodObject<{
|
|
|
72
139
|
fmspc: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
73
140
|
device_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
74
141
|
os_image_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
142
|
+
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
75
143
|
teepod_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
76
144
|
node_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
77
145
|
kms_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -82,6 +150,7 @@ export declare const ProvisionCvmSchema: z.ZodEffects<z.ZodObject<{
|
|
|
82
150
|
fmspc: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
83
151
|
device_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
84
152
|
os_image_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
153
|
+
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
85
154
|
teepod_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
86
155
|
node_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
87
156
|
kms_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -92,6 +161,7 @@ export declare const ProvisionCvmSchema: z.ZodEffects<z.ZodObject<{
|
|
|
92
161
|
fmspc: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
93
162
|
device_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
94
163
|
os_image_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
164
|
+
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
95
165
|
teepod_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
96
166
|
node_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
97
167
|
kms_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -102,6 +172,7 @@ export declare const ProvisionCvmSchema: z.ZodEffects<z.ZodObject<{
|
|
|
102
172
|
fmspc: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
103
173
|
device_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
104
174
|
os_image_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
175
|
+
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
105
176
|
teepod_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
106
177
|
node_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
107
178
|
kms_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -110,23 +181,25 @@ export type ProvisionCvm = z.infer<typeof ProvisionCvmSchema>;
|
|
|
110
181
|
export declare const ProvisionCvmRequestSchema: z.ZodObject<{
|
|
111
182
|
node_id: z.ZodOptional<z.ZodNumber>;
|
|
112
183
|
teepod_id: z.ZodOptional<z.ZodNumber>;
|
|
184
|
+
region: z.ZodOptional<z.ZodString>;
|
|
113
185
|
name: z.ZodString;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
186
|
+
instance_type: z.ZodDefault<z.ZodString>;
|
|
187
|
+
image: z.ZodOptional<z.ZodString>;
|
|
188
|
+
vcpu: z.ZodOptional<z.ZodNumber>;
|
|
189
|
+
memory: z.ZodOptional<z.ZodNumber>;
|
|
190
|
+
disk_size: z.ZodOptional<z.ZodNumber>;
|
|
118
191
|
compose_file: z.ZodObject<{
|
|
119
192
|
allowed_envs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
120
193
|
pre_launch_script: z.ZodOptional<z.ZodString>;
|
|
121
194
|
docker_compose_file: z.ZodOptional<z.ZodString>;
|
|
122
|
-
name: z.ZodOptional<z.ZodString
|
|
195
|
+
name: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
123
196
|
kms_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
124
197
|
public_logs: z.ZodOptional<z.ZodBoolean>;
|
|
125
198
|
public_sysinfo: z.ZodOptional<z.ZodBoolean>;
|
|
126
199
|
gateway_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
127
200
|
tproxy_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
128
201
|
}, "strip", z.ZodTypeAny, {
|
|
129
|
-
name
|
|
202
|
+
name: string;
|
|
130
203
|
public_sysinfo?: boolean | undefined;
|
|
131
204
|
public_logs?: boolean | undefined;
|
|
132
205
|
docker_compose_file?: string | undefined;
|
|
@@ -147,29 +220,32 @@ export declare const ProvisionCvmRequestSchema: z.ZodObject<{
|
|
|
147
220
|
tproxy_enabled?: boolean | undefined;
|
|
148
221
|
}>;
|
|
149
222
|
listed: z.ZodOptional<z.ZodBoolean>;
|
|
150
|
-
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
151
223
|
kms_id: z.ZodOptional<z.ZodString>;
|
|
224
|
+
kms: z.ZodOptional<z.ZodEnum<["PHALA", "ETHEREUM", "BASE"]>>;
|
|
225
|
+
kms_contract: z.ZodOptional<z.ZodString>;
|
|
152
226
|
env_keys: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
153
227
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
154
228
|
node_id: z.ZodOptional<z.ZodNumber>;
|
|
155
229
|
teepod_id: z.ZodOptional<z.ZodNumber>;
|
|
230
|
+
region: z.ZodOptional<z.ZodString>;
|
|
156
231
|
name: z.ZodString;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
232
|
+
instance_type: z.ZodDefault<z.ZodString>;
|
|
233
|
+
image: z.ZodOptional<z.ZodString>;
|
|
234
|
+
vcpu: z.ZodOptional<z.ZodNumber>;
|
|
235
|
+
memory: z.ZodOptional<z.ZodNumber>;
|
|
236
|
+
disk_size: z.ZodOptional<z.ZodNumber>;
|
|
161
237
|
compose_file: z.ZodObject<{
|
|
162
238
|
allowed_envs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
163
239
|
pre_launch_script: z.ZodOptional<z.ZodString>;
|
|
164
240
|
docker_compose_file: z.ZodOptional<z.ZodString>;
|
|
165
|
-
name: z.ZodOptional<z.ZodString
|
|
241
|
+
name: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
166
242
|
kms_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
167
243
|
public_logs: z.ZodOptional<z.ZodBoolean>;
|
|
168
244
|
public_sysinfo: z.ZodOptional<z.ZodBoolean>;
|
|
169
245
|
gateway_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
170
246
|
tproxy_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
171
247
|
}, "strip", z.ZodTypeAny, {
|
|
172
|
-
name
|
|
248
|
+
name: string;
|
|
173
249
|
public_sysinfo?: boolean | undefined;
|
|
174
250
|
public_logs?: boolean | undefined;
|
|
175
251
|
docker_compose_file?: string | undefined;
|
|
@@ -190,29 +266,32 @@ export declare const ProvisionCvmRequestSchema: z.ZodObject<{
|
|
|
190
266
|
tproxy_enabled?: boolean | undefined;
|
|
191
267
|
}>;
|
|
192
268
|
listed: z.ZodOptional<z.ZodBoolean>;
|
|
193
|
-
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
194
269
|
kms_id: z.ZodOptional<z.ZodString>;
|
|
270
|
+
kms: z.ZodOptional<z.ZodEnum<["PHALA", "ETHEREUM", "BASE"]>>;
|
|
271
|
+
kms_contract: z.ZodOptional<z.ZodString>;
|
|
195
272
|
env_keys: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
196
273
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
197
274
|
node_id: z.ZodOptional<z.ZodNumber>;
|
|
198
275
|
teepod_id: z.ZodOptional<z.ZodNumber>;
|
|
276
|
+
region: z.ZodOptional<z.ZodString>;
|
|
199
277
|
name: z.ZodString;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
278
|
+
instance_type: z.ZodDefault<z.ZodString>;
|
|
279
|
+
image: z.ZodOptional<z.ZodString>;
|
|
280
|
+
vcpu: z.ZodOptional<z.ZodNumber>;
|
|
281
|
+
memory: z.ZodOptional<z.ZodNumber>;
|
|
282
|
+
disk_size: z.ZodOptional<z.ZodNumber>;
|
|
204
283
|
compose_file: z.ZodObject<{
|
|
205
284
|
allowed_envs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
206
285
|
pre_launch_script: z.ZodOptional<z.ZodString>;
|
|
207
286
|
docker_compose_file: z.ZodOptional<z.ZodString>;
|
|
208
|
-
name: z.ZodOptional<z.ZodString
|
|
287
|
+
name: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
209
288
|
kms_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
210
289
|
public_logs: z.ZodOptional<z.ZodBoolean>;
|
|
211
290
|
public_sysinfo: z.ZodOptional<z.ZodBoolean>;
|
|
212
291
|
gateway_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
213
292
|
tproxy_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
214
293
|
}, "strip", z.ZodTypeAny, {
|
|
215
|
-
name
|
|
294
|
+
name: string;
|
|
216
295
|
public_sysinfo?: boolean | undefined;
|
|
217
296
|
public_logs?: boolean | undefined;
|
|
218
297
|
docker_compose_file?: string | undefined;
|
|
@@ -233,8 +312,9 @@ export declare const ProvisionCvmRequestSchema: z.ZodObject<{
|
|
|
233
312
|
tproxy_enabled?: boolean | undefined;
|
|
234
313
|
}>;
|
|
235
314
|
listed: z.ZodOptional<z.ZodBoolean>;
|
|
236
|
-
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
237
315
|
kms_id: z.ZodOptional<z.ZodString>;
|
|
316
|
+
kms: z.ZodOptional<z.ZodEnum<["PHALA", "ETHEREUM", "BASE"]>>;
|
|
317
|
+
kms_contract: z.ZodOptional<z.ZodString>;
|
|
238
318
|
env_keys: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
239
319
|
}, z.ZodTypeAny, "passthrough">>;
|
|
240
320
|
export type ProvisionCvmRequest = z.infer<typeof ProvisionCvmRequestSchema> & {
|
|
@@ -254,6 +334,7 @@ declare const provisionCvm: {
|
|
|
254
334
|
fmspc: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
255
335
|
device_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
256
336
|
os_image_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
337
|
+
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
257
338
|
teepod_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
258
339
|
node_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
259
340
|
kms_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -272,6 +353,7 @@ declare const provisionCvm: {
|
|
|
272
353
|
fmspc: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
273
354
|
device_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
274
355
|
os_image_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
356
|
+
instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
275
357
|
teepod_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
276
358
|
node_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
277
359
|
kms_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Update CVM OS image
|
|
4
|
+
*
|
|
5
|
+
* This action initiates an asynchronous OS image update operation.
|
|
6
|
+
* The CVM will be shut down, the OS image updated, and then restarted.
|
|
7
|
+
* This operation may take several minutes to complete.
|
|
8
|
+
*
|
|
9
|
+
* Returns 202 Accepted as the operation runs asynchronously.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createClient, updateOsImage } from '@phala/cloud'
|
|
14
|
+
*
|
|
15
|
+
* const client = createClient();
|
|
16
|
+
* await updateOsImage(client, {
|
|
17
|
+
* id: 'my-cvm-id',
|
|
18
|
+
* os_image_name: 'prod-0.3.5'
|
|
19
|
+
* });
|
|
20
|
+
* console.log('OS image update initiated');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const UpdateOsImageRequestSchema: z.ZodEffects<z.ZodObject<{
|
|
24
|
+
id: z.ZodOptional<z.ZodString>;
|
|
25
|
+
uuid: z.ZodOptional<z.ZodString>;
|
|
26
|
+
app_id: z.ZodOptional<z.ZodString>;
|
|
27
|
+
instance_id: z.ZodOptional<z.ZodString>;
|
|
28
|
+
} & {
|
|
29
|
+
os_image_name: z.ZodString;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
os_image_name: string;
|
|
32
|
+
id?: string | undefined;
|
|
33
|
+
app_id?: string | undefined;
|
|
34
|
+
instance_id?: string | undefined;
|
|
35
|
+
uuid?: string | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
os_image_name: string;
|
|
38
|
+
id?: string | undefined;
|
|
39
|
+
app_id?: string | undefined;
|
|
40
|
+
instance_id?: string | undefined;
|
|
41
|
+
uuid?: string | undefined;
|
|
42
|
+
}>, any, any>;
|
|
43
|
+
export type UpdateOsImageRequest = z.infer<typeof UpdateOsImageRequestSchema>;
|
|
44
|
+
declare const updateOsImage: {
|
|
45
|
+
(client: import("../..").BaseClient, params?: any): Promise<void>;
|
|
46
|
+
<T extends z.ZodTypeAny>(client: import("../..").BaseClient, params?: any, parameters?: {
|
|
47
|
+
schema: T;
|
|
48
|
+
} | undefined): Promise<z.TypeOf<T>>;
|
|
49
|
+
(client: import("../..").BaseClient, params?: any, parameters?: {
|
|
50
|
+
schema: false;
|
|
51
|
+
} | undefined): Promise<unknown>;
|
|
52
|
+
}, safeUpdateOsImage: {
|
|
53
|
+
(client: import("../..").BaseClient, params?: any): Promise<import("../..").SafeResult<void>>;
|
|
54
|
+
<T extends z.ZodTypeAny>(client: import("../..").BaseClient, params?: any, parameters?: {
|
|
55
|
+
schema: T;
|
|
56
|
+
} | undefined): Promise<import("../..").SafeResult<z.TypeOf<T>>>;
|
|
57
|
+
(client: import("../..").BaseClient, params?: any, parameters?: {
|
|
58
|
+
schema: false;
|
|
59
|
+
} | undefined): Promise<import("../..").SafeResult<unknown>>;
|
|
60
|
+
};
|
|
61
|
+
export { updateOsImage, safeUpdateOsImage };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Client } from "../../client";
|
|
3
|
+
import { type CvmIdInput } from "../../types/cvm_id";
|
|
4
|
+
import { type CvmState } from "./get_cvm_state";
|
|
5
|
+
/**
|
|
6
|
+
* SSE event data structures
|
|
7
|
+
*/
|
|
8
|
+
type SSEStateEvent = {
|
|
9
|
+
type: "state";
|
|
10
|
+
data: CvmState;
|
|
11
|
+
};
|
|
12
|
+
type SSECompleteEvent = {
|
|
13
|
+
type: "complete";
|
|
14
|
+
data: {
|
|
15
|
+
status: string;
|
|
16
|
+
elapsed: number;
|
|
17
|
+
target: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type SSETimeoutEvent = {
|
|
21
|
+
type: "timeout";
|
|
22
|
+
data: {
|
|
23
|
+
error: string;
|
|
24
|
+
elapsed: number;
|
|
25
|
+
target: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
type SSEErrorEvent = {
|
|
29
|
+
type: "error";
|
|
30
|
+
data: {
|
|
31
|
+
error: string;
|
|
32
|
+
elapsed?: number;
|
|
33
|
+
message?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type SSEEvent = SSEStateEvent | SSECompleteEvent | SSETimeoutEvent | SSEErrorEvent;
|
|
37
|
+
/**
|
|
38
|
+
* Watch CVM state request input (before transformation)
|
|
39
|
+
*/
|
|
40
|
+
export type WatchCvmStateRequest = CvmIdInput & {
|
|
41
|
+
target: string;
|
|
42
|
+
interval?: number;
|
|
43
|
+
timeout?: number;
|
|
44
|
+
maxRetries?: number;
|
|
45
|
+
retryDelay?: number;
|
|
46
|
+
};
|
|
47
|
+
export declare const WatchCvmStateRequestSchema: z.ZodObject<{
|
|
48
|
+
target: z.ZodString;
|
|
49
|
+
interval: z.ZodDefault<z.ZodNumber>;
|
|
50
|
+
timeout: z.ZodDefault<z.ZodNumber>;
|
|
51
|
+
maxRetries: z.ZodDefault<z.ZodNumber>;
|
|
52
|
+
retryDelay: z.ZodDefault<z.ZodNumber>;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
timeout: number;
|
|
55
|
+
retryDelay: number;
|
|
56
|
+
maxRetries: number;
|
|
57
|
+
target: string;
|
|
58
|
+
interval: number;
|
|
59
|
+
}, {
|
|
60
|
+
target: string;
|
|
61
|
+
timeout?: number | undefined;
|
|
62
|
+
retryDelay?: number | undefined;
|
|
63
|
+
maxRetries?: number | undefined;
|
|
64
|
+
interval?: number | undefined;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Options for watch operation
|
|
68
|
+
*/
|
|
69
|
+
export interface WatchCvmStateOptions {
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
onEvent?: (event: SSEEvent) => void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Error thrown when watch operation is aborted
|
|
75
|
+
*/
|
|
76
|
+
export declare class WatchAbortedError extends Error {
|
|
77
|
+
constructor();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Error thrown when max retries exceeded
|
|
81
|
+
*/
|
|
82
|
+
export declare class MaxRetriesExceededError extends Error {
|
|
83
|
+
readonly attempts: number;
|
|
84
|
+
constructor(attempts: number);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Watch CVM state changes using Server-Sent Events (SSE)
|
|
88
|
+
*
|
|
89
|
+
* This action streams state updates from the backend until the target status is reached,
|
|
90
|
+
* timeout occurs, or an error happens. It automatically retries on timeout/error up to
|
|
91
|
+
* maxRetries times, providing unlimited watch capability.
|
|
92
|
+
*
|
|
93
|
+
* Key features:
|
|
94
|
+
* - Streams real-time state updates via SSE
|
|
95
|
+
* - Automatic retry on timeout (backend max 600s, but SDK can retry infinitely)
|
|
96
|
+
* - AbortController support for cancellation
|
|
97
|
+
* - Callback for each SSE event
|
|
98
|
+
* - Resolves with final state when target reached
|
|
99
|
+
*
|
|
100
|
+
* @param client - The API client
|
|
101
|
+
* @param request - Request parameters
|
|
102
|
+
* @param request.id - CVM ID (or use uuid, app_id, instance_id)
|
|
103
|
+
* @param request.target - Target status to wait for (e.g., "running")
|
|
104
|
+
* @param request.interval - Polling interval in seconds (5-30, default: 5)
|
|
105
|
+
* @param request.timeout - Timeout per attempt in seconds (10-600, default: 300)
|
|
106
|
+
* @param request.maxRetries - Max retry attempts (default: Infinity)
|
|
107
|
+
* @param request.retryDelay - Delay between retries in ms (default: 5000)
|
|
108
|
+
* @param options - Optional behavior parameters
|
|
109
|
+
* @param options.signal - AbortSignal for cancellation
|
|
110
|
+
* @param options.onEvent - Callback invoked for each SSE event
|
|
111
|
+
* @returns Promise that resolves with final CVM state when target is reached
|
|
112
|
+
*
|
|
113
|
+
* @throws {WatchAbortedError} If operation is aborted via signal
|
|
114
|
+
* @throws {MaxRetriesExceededError} If max retries exceeded without reaching target
|
|
115
|
+
* @throws {Error} For other unexpected errors
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // Basic usage: wait for CVM to reach "running" status
|
|
120
|
+
* const state = await watchCvmState(client, {
|
|
121
|
+
* id: "cvm-123",
|
|
122
|
+
* target: "running"
|
|
123
|
+
* })
|
|
124
|
+
* console.log("CVM is now running!")
|
|
125
|
+
*
|
|
126
|
+
* // With event callback and abort controller
|
|
127
|
+
* const controller = new AbortController()
|
|
128
|
+
* try {
|
|
129
|
+
* const state = await watchCvmState(
|
|
130
|
+
* client,
|
|
131
|
+
* {
|
|
132
|
+
* id: "cvm-123",
|
|
133
|
+
* target: "running",
|
|
134
|
+
* interval: 10,
|
|
135
|
+
* maxRetries: 5
|
|
136
|
+
* },
|
|
137
|
+
* {
|
|
138
|
+
* signal: controller.signal,
|
|
139
|
+
* onEvent: (event) => {
|
|
140
|
+
* if (event.type === "state") {
|
|
141
|
+
* console.log("Current status:", event.data.status)
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* }
|
|
145
|
+
* )
|
|
146
|
+
* } catch (error) {
|
|
147
|
+
* if (error instanceof WatchAbortedError) {
|
|
148
|
+
* console.log("Watch cancelled")
|
|
149
|
+
* }
|
|
150
|
+
* }
|
|
151
|
+
*
|
|
152
|
+
* // Cancel after 30 seconds
|
|
153
|
+
* setTimeout(() => controller.abort(), 30000)
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare function watchCvmState(client: Client, request: WatchCvmStateRequest, options?: WatchCvmStateOptions): Promise<CvmState>;
|
|
157
|
+
export {};
|
|
@@ -637,6 +637,12 @@ export type TeepodCapacity = z.infer<typeof TeepodCapacitySchema>;
|
|
|
637
637
|
export type ResourceThreshold = z.infer<typeof ResourceThresholdSchema>;
|
|
638
638
|
export type AvailableNodes = z.infer<typeof AvailableNodesSchema>;
|
|
639
639
|
declare const getAvailableNodes: {
|
|
640
|
+
(client: Client, parameters: {
|
|
641
|
+
schema: false;
|
|
642
|
+
}): Promise<unknown>;
|
|
643
|
+
<T extends z.ZodTypeAny>(client: Client, parameters: {
|
|
644
|
+
schema: T;
|
|
645
|
+
}): Promise<z.TypeOf<T>>;
|
|
640
646
|
(client: Client): Promise<z.objectOutputType<{
|
|
641
647
|
tier: z.ZodString;
|
|
642
648
|
capacity: z.ZodObject<{
|
|
@@ -788,13 +794,13 @@ declare const getAvailableNodes: {
|
|
|
788
794
|
gateway_app_id: z.ZodEffects<z.ZodNullable<z.ZodString>, `0x${string}`, string | null>;
|
|
789
795
|
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
790
796
|
}, z.ZodTypeAny, "passthrough">>;
|
|
791
|
-
|
|
792
|
-
schema: T;
|
|
793
|
-
}): Promise<z.TypeOf<T>>;
|
|
797
|
+
}, safeGetAvailableNodes: {
|
|
794
798
|
(client: Client, parameters: {
|
|
795
799
|
schema: false;
|
|
796
|
-
}): Promise<unknown
|
|
797
|
-
|
|
800
|
+
}): Promise<import("..").SafeResult<unknown>>;
|
|
801
|
+
<T extends z.ZodTypeAny>(client: Client, parameters: {
|
|
802
|
+
schema: T;
|
|
803
|
+
}): Promise<import("..").SafeResult<z.TypeOf<T>>>;
|
|
798
804
|
(client: Client): Promise<import("..").SafeResult<z.objectOutputType<{
|
|
799
805
|
tier: z.ZodString;
|
|
800
806
|
capacity: z.ZodObject<{
|
|
@@ -946,11 +952,5 @@ declare const getAvailableNodes: {
|
|
|
946
952
|
gateway_app_id: z.ZodEffects<z.ZodNullable<z.ZodString>, `0x${string}`, string | null>;
|
|
947
953
|
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
948
954
|
}, z.ZodTypeAny, "passthrough">>>;
|
|
949
|
-
<T extends z.ZodTypeAny>(client: Client, parameters: {
|
|
950
|
-
schema: T;
|
|
951
|
-
}): Promise<import("..").SafeResult<z.TypeOf<T>>>;
|
|
952
|
-
(client: Client, parameters: {
|
|
953
|
-
schema: false;
|
|
954
|
-
}): Promise<import("..").SafeResult<unknown>>;
|
|
955
955
|
};
|
|
956
956
|
export { getAvailableNodes, safeGetAvailableNodes };
|
|
@@ -85,6 +85,12 @@ export declare const CurrentUserSchema: z.ZodObject<{
|
|
|
85
85
|
}, z.ZodTypeAny, "passthrough">>;
|
|
86
86
|
export type CurrentUser = z.infer<typeof CurrentUserSchema>;
|
|
87
87
|
declare const getCurrentUser: {
|
|
88
|
+
(client: Client, parameters: {
|
|
89
|
+
schema: false;
|
|
90
|
+
}): Promise<unknown>;
|
|
91
|
+
<T extends z.ZodTypeAny>(client: Client, parameters: {
|
|
92
|
+
schema: T;
|
|
93
|
+
}): Promise<z.TypeOf<T>>;
|
|
88
94
|
(client: Client): Promise<z.objectOutputType<{
|
|
89
95
|
username: z.ZodString;
|
|
90
96
|
email: z.ZodString;
|
|
@@ -94,13 +100,13 @@ declare const getCurrentUser: {
|
|
|
94
100
|
team_name: z.ZodString;
|
|
95
101
|
team_tier: z.ZodString;
|
|
96
102
|
}, z.ZodTypeAny, "passthrough">>;
|
|
97
|
-
|
|
98
|
-
schema: T;
|
|
99
|
-
}): Promise<z.TypeOf<T>>;
|
|
103
|
+
}, safeGetCurrentUser: {
|
|
100
104
|
(client: Client, parameters: {
|
|
101
105
|
schema: false;
|
|
102
|
-
}): Promise<unknown
|
|
103
|
-
|
|
106
|
+
}): Promise<import("..").SafeResult<unknown>>;
|
|
107
|
+
<T extends z.ZodTypeAny>(client: Client, parameters: {
|
|
108
|
+
schema: T;
|
|
109
|
+
}): Promise<import("..").SafeResult<z.TypeOf<T>>>;
|
|
104
110
|
(client: Client): Promise<import("..").SafeResult<z.objectOutputType<{
|
|
105
111
|
username: z.ZodString;
|
|
106
112
|
email: z.ZodString;
|
|
@@ -110,11 +116,5 @@ declare const getCurrentUser: {
|
|
|
110
116
|
team_name: z.ZodString;
|
|
111
117
|
team_tier: z.ZodString;
|
|
112
118
|
}, z.ZodTypeAny, "passthrough">>>;
|
|
113
|
-
<T extends z.ZodTypeAny>(client: Client, parameters: {
|
|
114
|
-
schema: T;
|
|
115
|
-
}): Promise<import("..").SafeResult<z.TypeOf<T>>>;
|
|
116
|
-
(client: Client, parameters: {
|
|
117
|
-
schema: false;
|
|
118
|
-
}): Promise<import("..").SafeResult<unknown>>;
|
|
119
119
|
};
|
|
120
120
|
export { getCurrentUser, safeGetCurrentUser };
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -12,9 +12,10 @@ export { getCvmInfo, safeGetCvmInfo, CvmLegacyDetailSchema, GetCvmInfoRequestSch
|
|
|
12
12
|
export { getCvmList, safeGetCvmList, GetCvmListSchema, GetCvmListRequestSchema, type GetCvmListRequest, type GetCvmListResponse, } from "./cvms/get_cvm_list";
|
|
13
13
|
export { getKmsInfo, safeGetKmsInfo, GetKmsInfoRequestSchema, type GetKmsInfoRequest, } from "./kms/get_kms_info";
|
|
14
14
|
export { getKmsList, safeGetKmsList, GetKmsListSchema, GetKmsListRequestSchema, type GetKmsListRequest, type GetKmsListResponse, } from "./kms/get_kms_list";
|
|
15
|
+
export { nextAppIds, safeNextAppIds, NextAppIdsSchema, NextAppIdsRequestSchema, type NextAppIdsRequest, type NextAppIds, } from "./kms/next_app_ids";
|
|
15
16
|
export { listWorkspaces, safeListWorkspaces, WorkspaceResponseSchema, ListWorkspacesSchema, PaginationMetadataSchema, type WorkspaceResponse, type ListWorkspaces, type PaginationMetadata, type ListWorkspacesRequest, } from "./workspaces/list_workspaces";
|
|
16
17
|
export { getWorkspace, safeGetWorkspace, } from "./workspaces/get_workspace";
|
|
17
|
-
export {
|
|
18
|
+
export { listAllInstanceTypeFamilies, safeListAllInstanceTypeFamilies, listFamilyInstanceTypes, safeListFamilyInstanceTypes, AllFamiliesResponseSchema, FamilyInstanceTypesResponseSchema, FamilyGroupSchema, InstanceTypeSchema, ListFamilyInstanceTypesRequestSchema, type AllFamiliesResponse, type FamilyInstanceTypesResponse, type FamilyGroup, type InstanceType, type ListFamilyInstanceTypesRequest, } from "./list-instance-types";
|
|
18
19
|
export { startCvm, safeStartCvm, StartCvmRequestSchema, type StartCvmRequest, } from "./cvms/start_cvm";
|
|
19
20
|
export { shutdownCvm, safeShutdownCvm, ShutdownCvmRequestSchema, type ShutdownCvmRequest, } from "./cvms/shutdown_cvm";
|
|
20
21
|
export { stopCvm, safeStopCvm, StopCvmRequestSchema, type StopCvmRequest, } from "./cvms/stop_cvm";
|
|
@@ -23,7 +24,11 @@ export { deleteCvm, safeDeleteCvm, DeleteCvmRequestSchema, type DeleteCvmRequest
|
|
|
23
24
|
export { getCvmStats, safeGetCvmStats, CvmSystemInfoSchema, GetCvmStatsRequestSchema, type GetCvmStatsRequest, type CvmSystemInfo, } from "./cvms/get_cvm_stats";
|
|
24
25
|
export { getCvmContainersStats, safeGetCvmContainersStats, CvmContainersStatsSchema, GetCvmContainersStatsRequestSchema, type GetCvmContainersStatsRequest, type CvmContainersStats, } from "./cvms/get_cvm_containers_stats";
|
|
25
26
|
export { getCvmNetwork, safeGetCvmNetwork, CvmNetworkSchema, GetCvmNetworkRequestSchema, type GetCvmNetworkRequest, type CvmNetwork, } from "./cvms/get_cvm_network";
|
|
27
|
+
export { getCvmState, safeGetCvmState, CvmStateSchema, GetCvmStateRequestSchema, type GetCvmStateRequest, type CvmState, } from "./cvms/get_cvm_state";
|
|
28
|
+
export { watchCvmState, WatchCvmStateRequestSchema, type WatchCvmStateRequest, type WatchCvmStateOptions, type SSEEvent, WatchAbortedError, MaxRetriesExceededError, } from "./cvms/watch_cvm_state";
|
|
26
29
|
export { getCvmAttestation, safeGetCvmAttestation, CvmAttestationSchema, GetCvmAttestationRequestSchema, type GetCvmAttestationRequest, type CvmAttestation, } from "./cvms/get_cvm_attestation";
|
|
27
30
|
export { getCvmDockerCompose, safeGetCvmDockerCompose, GetCvmDockerComposeRequestSchema, type GetCvmDockerComposeRequest, } from "./cvms/get_cvm_docker_compose";
|
|
28
31
|
export { updateCvmResources, safeUpdateCvmResources, UpdateCvmResourcesRequestSchema, type UpdateCvmResourcesRequest, } from "./cvms/update_cvm_resources";
|
|
29
32
|
export { updateCvmVisibility, safeUpdateCvmVisibility, UpdateCvmVisibilityRequestSchema, type UpdateCvmVisibilityRequest, } from "./cvms/update_cvm_visibility";
|
|
33
|
+
export { getAvailableOsImages, safeGetAvailableOsImages, OSImageVariantSchema, GetAvailableOSImagesResponseSchema, GetAvailableOSImagesRequestSchema, type OSImageVariant, type GetAvailableOSImagesResponse, type GetAvailableOSImagesRequest, } from "./cvms/get_available_os_images";
|
|
34
|
+
export { updateOsImage, safeUpdateOsImage, UpdateOsImageRequestSchema, type UpdateOsImageRequest, } from "./cvms/update_os_image";
|