Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit 248c90e

Browse files
feat(api): api update
1 parent 8eadca2 commit 248c90e

6 files changed

Lines changed: 108 additions & 34 deletions

File tree

‎.stats.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 8
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hdr-parth-agrawal%2Ffirecracker-manager-07b6a4a1a7515802531be41461e4d9b4badad13e93492f5a408d54f51693d717.yml
3-
openapi_spec_hash: aba885b7687af21c2151833c9d7a2dab
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hdr-parth-agrawal%2Ffirecracker-manager-fc1351bc8599fc6873d1be7f16ed805907442c3a50f68659b312076be10bd5d0.yml
3+
openapi_spec_hash: 15a3d34206ed2dca0702a8a3291e1d7b
44
config_hash: ba476ff7e5c71b83e72ad86fcb01beeb

‎api.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ Types:
66
- <code><a href="./src/resources/vm.ts">NewRootRequest</a></code>
77
- <code><a href="./src/resources/vm.ts">NewVmResponse</a></code>
88
- <code><a href="./src/resources/vm.ts">Vm</a></code>
9-
- <code><a href="./src/resources/vm.ts">VmCommitResponse</a></code>
109
- <code><a href="./src/resources/vm.ts">VmDeleteResponse</a></code>
1110
- <code><a href="./src/resources/vm.ts">VmFromCommitRequest</a></code>
1211
- <code><a href="./src/resources/vm.ts">VmSSHKeyResponse</a></code>
1312
- <code><a href="./src/resources/vm.ts">VmUpdateStateRequest</a></code>
1413
- <code><a href="./src/resources/vm.ts">VmListResponse</a></code>
14+
- <code><a href="./src/resources/vm.ts">VmCommitResponse</a></code>
1515

1616
Methods:
1717

1818
- <code title="get /vms">client.vm.<a href="./src/resources/vm.ts">list</a>() -> VmListResponse</code>
19-
- <code title="delete /vm/{vm_id}">client.vm.<a href="./src/resources/vm.ts">delete</a>(vmID) -> VmDeleteResponse</code>
19+
- <code title="delete /vm/{vm_id}">client.vm.<a href="./src/resources/vm.ts">delete</a>(vmID, { ...params }) -> VmDeleteResponse</code>
2020
- <code title="post /vm/{vm_id}/branch">client.vm.<a href="./src/resources/vm.ts">branch</a>(vmID) -> NewVmResponse</code>
21-
- <code title="post /vm/{vm_id}/commit">client.vm.<a href="./src/resources/vm.ts">commit</a>(vmID) -> VmCommitResponse</code>
21+
- <code title="post /vm/{vm_id}/commit">client.vm.<a href="./src/resources/vm.ts">commit</a>(vmID, { ...params }) -> VmCommitResponse</code>
2222
- <code title="post /vm/new_root">client.vm.<a href="./src/resources/vm.ts">createRoot</a>({ ...params }) -> NewVmResponse</code>
2323
- <code title="get /vm/{vm_id}/ssh_key">client.vm.<a href="./src/resources/vm.ts">getSSHKey</a>(vmID) -> VmSSHKeyResponse</code>
2424
- <code title="post /vm/from_commit">client.vm.<a href="./src/resources/vm.ts">restoreFromCommit</a>({ ...params }) -> NewVmResponse</code>

‎src/client.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import {
2121
NewRootRequest,
2222
NewVmResponse,
2323
Vm,
24+
VmCommitParams,
2425
VmCommitResponse,
2526
VmCreateRootParams,
27+
VmDeleteParams,
2628
VmDeleteResponse,
2729
VmFromCommitRequest,
2830
VmListResponse,
@@ -749,12 +751,14 @@ export declare namespace Vers {
749751
type NewRootRequest as NewRootRequest,
750752
type NewVmResponse as NewVmResponse,
751753
type Vm as Vm,
752-
type VmCommitResponse as VmCommitResponse,
753754
type VmDeleteResponse as VmDeleteResponse,
754755
type VmFromCommitRequest as VmFromCommitRequest,
755756
type VmSSHKeyResponse as VmSSHKeyResponse,
756757
type VmUpdateStateRequest as VmUpdateStateRequest,
757758
type VmListResponse as VmListResponse,
759+
type VmCommitResponse as VmCommitResponse,
760+
type VmDeleteParams as VmDeleteParams,
761+
type VmCommitParams as VmCommitParams,
758762
type VmCreateRootParams as VmCreateRootParams,
759763
type VmRestoreFromCommitParams as VmRestoreFromCommitParams,
760764
type VmUpdateStateParams as VmUpdateStateParams,

‎src/resources/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export {
66
type NewRootRequest,
77
type NewVmResponse,
88
type Vm,
9-
type VmCommitResponse,
109
type VmDeleteResponse,
1110
type VmFromCommitRequest,
1211
type VmSSHKeyResponse,
1312
type VmUpdateStateRequest,
1413
type VmListResponse,
14+
type VmCommitResponse,
15+
type VmDeleteParams,
16+
type VmCommitParams,
1517
type VmCreateRootParams,
1618
type VmRestoreFromCommitParams,
1719
type VmUpdateStateParams,

‎src/resources/vm.ts‎

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,34 @@ export class VmResource extends APIResource {
1111
return this._client.get('/vms', options);
1212
}
1313

14-
delete(vmID: string, options?: RequestOptions): APIPromise<VmDeleteResponse> {
15-
return this._client.delete(path`/vm/${vmID}`, options);
14+
delete(
15+
vmID: string,
16+
params: VmDeleteParams | null | undefined = {},
17+
options?: RequestOptions,
18+
): APIPromise<VmDeleteResponse> {
19+
const { skip_wait_boot } = params ?? {};
20+
return this._client.delete(path`/vm/${vmID}`, { query: { skip_wait_boot }, ...options });
1621
}
1722

1823
branch(vmID: string, options?: RequestOptions): APIPromise<NewVmResponse> {
1924
return this._client.post(path`/vm/${vmID}/branch`, options);
2025
}
2126

22-
commit(vmID: string, options?: RequestOptions): APIPromise<VmCommitResponse> {
23-
return this._client.post(path`/vm/${vmID}/commit`, options);
27+
commit(
28+
vmID: string,
29+
params: VmCommitParams | null | undefined = {},
30+
options?: RequestOptions,
31+
): APIPromise<VmCommitResponse> {
32+
const { keep_paused, skip_wait_boot } = params ?? {};
33+
return this._client.post(path`/vm/${vmID}/commit`, {
34+
query: { keep_paused, skip_wait_boot },
35+
...options,
36+
});
2437
}
2538

26-
createRoot(body: VmCreateRootParams, options?: RequestOptions): APIPromise<NewVmResponse> {
27-
return this._client.post('/vm/new_root', { body, ...options });
39+
createRoot(params: VmCreateRootParams, options?: RequestOptions): APIPromise<NewVmResponse> {
40+
const { wait_boot, ...body } = params;
41+
return this._client.post('/vm/new_root', { query: { wait_boot }, body, ...options });
2842
}
2943

3044
getSSHKey(vmID: string, options?: RequestOptions): APIPromise<VmSSHKeyResponse> {
@@ -35,8 +49,10 @@ export class VmResource extends APIResource {
3549
return this._client.post('/vm/from_commit', { body, ...options });
3650
}
3751

38-
updateState(vmID: string, body: VmUpdateStateParams, options?: RequestOptions): APIPromise<void> {
52+
updateState(vmID: string, params: VmUpdateStateParams, options?: RequestOptions): APIPromise<void> {
53+
const { skip_wait_boot, ...body } = params;
3954
return this._client.patch(path`/vm/${vmID}/state`, {
55+
query: { skip_wait_boot },
4056
body,
4157
...options,
4258
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
@@ -107,31 +123,19 @@ export interface Vm {
107123

108124
owner_id: string;
109125

110-
vm_id: string;
111-
112-
parent?: string | null;
113-
}
114-
115-
/**
116-
* The response body for POST /api/vm/{vm_id}/commit
117-
*/
118-
export interface VmCommitResponse {
119126
/**
120-
* The commit ID, a (v4) UUID
127+
* The state of a VM
121128
*/
122-
commit_id: string;
129+
state: 'booting' | 'running' | 'paused';
123130

124-
/**
125-
* The host architecture, eg: "x86_64" (currently implemented with `uname -m``)
126-
*/
127-
host_architecture: string;
131+
vm_id: string;
128132
}
129133

130134
/**
131135
* Response body for DELETE /api/vm/{vm_id}
132136
*/
133137
export interface VmDeleteResponse {
134-
deleted_ids: Array<string>;
138+
vm_id: string;
135139
}
136140

137141
/**
@@ -169,11 +173,43 @@ export interface VmUpdateStateRequest {
169173

170174
export type VmListResponse = Array<Vm>;
171175

176+
/**
177+
* A summary of a commit, appropriate for displaying on the frontend
178+
*/
179+
export interface VmCommitResponse {
180+
commit_id: string;
181+
}
182+
183+
export interface VmDeleteParams {
184+
/**
185+
* If true, return an error immediately if the VM is still booting. Default: false
186+
*/
187+
skip_wait_boot?: boolean;
188+
}
189+
190+
export interface VmCommitParams {
191+
/**
192+
* If true, keep VM paused after commit
193+
*/
194+
keep_paused?: boolean;
195+
196+
/**
197+
* If true, return an error immediately if the VM is still booting. Default: false
198+
*/
199+
skip_wait_boot?: boolean;
200+
}
201+
172202
export interface VmCreateRootParams {
173203
/**
174-
* Struct representing configuration options common to all VMs
204+
* Body param: Struct representing configuration options common to all VMs
175205
*/
176206
vm_config: VmCreateRootParams.VmConfig;
207+
208+
/**
209+
* Query param: If true, wait for the newly-created VM to finish booting before
210+
* returning. Default: false.
211+
*/
212+
wait_boot?: boolean;
177213
}
178214

179215
export namespace VmCreateRootParams {
@@ -214,9 +250,15 @@ export interface VmRestoreFromCommitParams {
214250

215251
export interface VmUpdateStateParams {
216252
/**
217-
* The requested state for the VM
253+
* Body param: The requested state for the VM
218254
*/
219255
state: 'Paused' | 'Running';
256+
257+
/**
258+
* Query param: If true, error immediately if the VM is not finished booting.
259+
* Defaults to false
260+
*/
261+
skip_wait_boot?: boolean;
220262
}
221263

222264
export declare namespace VmResource {
@@ -225,12 +267,14 @@ export declare namespace VmResource {
225267
type NewRootRequest as NewRootRequest,
226268
type NewVmResponse as NewVmResponse,
227269
type Vm as Vm,
228-
type VmCommitResponse as VmCommitResponse,
229270
type VmDeleteResponse as VmDeleteResponse,
230271
type VmFromCommitRequest as VmFromCommitRequest,
231272
type VmSSHKeyResponse as VmSSHKeyResponse,
232273
type VmUpdateStateRequest as VmUpdateStateRequest,
233274
type VmListResponse as VmListResponse,
275+
type VmCommitResponse as VmCommitResponse,
276+
type VmDeleteParams as VmDeleteParams,
277+
type VmCommitParams as VmCommitParams,
234278
type VmCreateRootParams as VmCreateRootParams,
235279
type VmRestoreFromCommitParams as VmRestoreFromCommitParams,
236280
type VmUpdateStateParams as VmUpdateStateParams,

‎tests/api-resources/vm.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ describe('resource vm', () => {
3232
expect(dataAndResponse.response).toBe(rawResponse);
3333
});
3434

35+
// Prism tests are disabled
36+
test.skip('delete: request options and params are passed correctly', async () => {
37+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
38+
await expect(
39+
client.vm.delete('vm_id', { skip_wait_boot: true }, { path: '/_stainless_unknown_path' }),
40+
).rejects.toThrow(Vers.NotFoundError);
41+
});
42+
3543
// Prism tests are disabled
3644
test.skip('branch', async () => {
3745
const responsePromise = client.vm.branch('vm_id');
@@ -56,6 +64,18 @@ describe('resource vm', () => {
5664
expect(dataAndResponse.response).toBe(rawResponse);
5765
});
5866

67+
// Prism tests are disabled
68+
test.skip('commit: request options and params are passed correctly', async () => {
69+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
70+
await expect(
71+
client.vm.commit(
72+
'vm_id',
73+
{ keep_paused: true, skip_wait_boot: true },
74+
{ path: '/_stainless_unknown_path' },
75+
),
76+
).rejects.toThrow(Vers.NotFoundError);
77+
});
78+
5979
// Prism tests are disabled
6080
test.skip('createRoot: only required params', async () => {
6181
const responsePromise = client.vm.createRoot({ vm_config: {} });
@@ -78,6 +98,7 @@ describe('resource vm', () => {
7898
mem_size_mib: 0,
7999
vcpu_count: 0,
80100
},
101+
wait_boot: true,
81102
});
82103
});
83104

@@ -128,6 +149,9 @@ describe('resource vm', () => {
128149

129150
// Prism tests are disabled
130151
test.skip('updateState: required and optional params', async () => {
131-
const response = await client.vm.updateState('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { state: 'Paused' });
152+
const response = await client.vm.updateState('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
153+
state: 'Paused',
154+
skip_wait_boot: true,
155+
});
132156
});
133157
});

0 commit comments

Comments
 (0)