diff --git a/openapi.json b/openapi.json index b431bfd..b8c6e7e 100644 --- a/openapi.json +++ b/openapi.json @@ -747,6 +747,57 @@ ], "title": "VMStartResponse" }, + "VMUpdateHibernationTimeoutRequest": { + "properties": { + "hibernation_timeout_seconds": { + "description": "The new hibernation timeout in seconds.\n\nMust be greater than 0 and less than or equal to 86400 (24 hours).\n", + "example": 300, + "maximum": 86400, + "minimum": 1, + "type": "integer" + } + }, + "required": ["hibernation_timeout_seconds"], + "title": "VMUpdateHibernationTimeoutRequest", + "type": "object" + }, + "VMUpdateHibernationTimeoutResponse": { + "allOf": [ + { + "properties": { + "errors": { + "items": [ + { + "oneOf": [ + { "type": "string" }, + { "additionalProperties": true, "type": "object" } + ], + "title": "Error" + } + ], + "type": "array" + }, + "success": { "type": "boolean" } + }, + "title": "Response", + "type": "object" + }, + { + "properties": { + "data": { + "properties": { + "hibernation_timeout_seconds": { "type": "integer" }, + "id": { "type": "string" } + }, + "required": ["id", "hibernation_timeout_seconds"], + "type": "object" + } + }, + "type": "object" + } + ], + "title": "VMUpdateHibernationTimeoutResponse" + }, "VMUpdateSpecsRequest": { "properties": { "tier": { @@ -1181,6 +1232,49 @@ "tags": ["vm"] } }, + "/vm/{id}/hibernation_timeout": { + "put": { + "callbacks": {}, + "description": "Updates the hibernation timeout of a running VM.\n\nThis endpoint can only be used on VMs that belong to your team's workspace.\nThe new timeout must be greater than 0 and less than or equal to 86400 seconds (24 hours).\n", + "operationId": "vm/update_hibernation_timeout", + "parameters": [ + { + "description": "Sandbox ID", + "example": "new", + "in": "path", + "name": "id", + "required": true, + "schema": { "type": "string" } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/VMUpdateHibernationTimeoutRequest" + } + } + }, + "description": "VM Update Hibernation Timeout Request", + "required": false + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/VMUpdateHibernationTimeoutResponse" + } + } + }, + "description": "VM Update Hibernation Timeout Response" + } + }, + "security": [{ "authorization": ["vm:manage"] }], + "summary": "Update VM Hibernation Timeout", + "tags": ["vm"] + } + }, "/vm/{id}/shutdown": { "post": { "callbacks": {}, @@ -1220,6 +1314,47 @@ "tags": ["vm"] } }, + "/vm/{id}/specs": { + "put": { + "callbacks": {}, + "description": "Updates the specifications (CPU, memory, storage) of a running VM.\n\nThis endpoint can only be used on VMs that belong to your team's workspace.\nThe new tier must not exceed your team's maximum allowed tier.\n", + "operationId": "vm/update_specs", + "parameters": [ + { + "description": "Sandbox ID", + "example": "new", + "in": "path", + "name": "id", + "required": true, + "schema": { "type": "string" } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/VMUpdateSpecsRequest" } + } + }, + "description": "VM Update Specs Request", + "required": false + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/VMUpdateSpecsResponse" + } + } + }, + "description": "VM Update Specs Response" + } + }, + "security": [{ "authorization": ["vm:manage"] }], + "summary": "Update VM Specs", + "tags": ["vm"] + } + }, "/vm/{id}/start": { "post": { "callbacks": {}, @@ -1263,7 +1398,7 @@ "post": { "callbacks": {}, "description": "Updates the specifications (CPU, memory, storage) of a running VM.\n\nThis endpoint can only be used on VMs that belong to your team's workspace.\nThe new tier must not exceed your team's maximum allowed tier.\n", - "operationId": "vm/update_specs", + "operationId": "vm/update_specs (2)", "parameters": [ { "description": "Sandbox ID", diff --git a/src/client/sdk.gen.ts b/src/client/sdk.gen.ts index 6bd98a4..db5daed 100644 --- a/src/client/sdk.gen.ts +++ b/src/client/sdk.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts import { createClient, createConfig, type OptionsLegacyParser } from '@hey-api/client-fetch'; -import type { MetaInfoError, MetaInfoResponse, WorkspaceCreateData, WorkspaceCreateError, WorkspaceCreateResponse2, TokenCreateData, TokenCreateError, TokenCreateResponse2, TokenUpdateData, TokenUpdateError, TokenUpdateResponse2, SandboxListData, SandboxListError, SandboxListResponse2, SandboxCreateData, SandboxCreateError, SandboxCreateResponse2, SandboxGetData, SandboxGetError, SandboxGetResponse2, SandboxForkData, SandboxForkError, SandboxForkResponse2, VmHibernateData, VmHibernateError, VmHibernateResponse, VmShutdownData, VmShutdownError, VmShutdownResponse, VmStartData, VmStartError, VmStartResponse, VmUpdateSpecsData, VmUpdateSpecsError, VmUpdateSpecsResponse } from './types.gen'; +import type { MetaInfoError, MetaInfoResponse, WorkspaceCreateData, WorkspaceCreateError, WorkspaceCreateResponse2, TokenCreateData, TokenCreateError, TokenCreateResponse2, TokenUpdateData, TokenUpdateError, TokenUpdateResponse2, SandboxListData, SandboxListError, SandboxListResponse2, SandboxCreateData, SandboxCreateError, SandboxCreateResponse2, SandboxGetData, SandboxGetError, SandboxGetResponse2, SandboxForkData, SandboxForkError, SandboxForkResponse2, VmHibernateData, VmHibernateError, VmHibernateResponse, VmUpdateHibernationTimeoutData, VmUpdateHibernationTimeoutError, VmUpdateHibernationTimeoutResponse, VmShutdownData, VmShutdownError, VmShutdownResponse, VmUpdateSpecsData, VmUpdateSpecsError, VmUpdateSpecsResponse, VmStartData, VmStartError, VmStartResponse, VmUpdateSpecs2Data, VmUpdateSpecs2Error, VmUpdateSpecs2Response } from './types.gen'; export const client = createClient(createConfig()); @@ -118,6 +118,21 @@ export const vmHibernate = (options: Optio }); }; +/** + * Update VM Hibernation Timeout + * Updates the hibernation timeout of a running VM. + * + * This endpoint can only be used on VMs that belong to your team's workspace. + * The new timeout must be greater than 0 and less than or equal to 86400 seconds (24 hours). + * + */ +export const vmUpdateHibernationTimeout = (options: OptionsLegacyParser) => { + return (options?.client ?? client).put({ + ...options, + url: '/vm/{id}/hibernation_timeout' + }); +}; + /** * Shutdown a VM * Stops a running VM, ending all currently running processes @@ -135,6 +150,21 @@ export const vmShutdown = (options: Option }); }; +/** + * Update VM Specs + * Updates the specifications (CPU, memory, storage) of a running VM. + * + * This endpoint can only be used on VMs that belong to your team's workspace. + * The new tier must not exceed your team's maximum allowed tier. + * + */ +export const vmUpdateSpecs = (options: OptionsLegacyParser) => { + return (options?.client ?? client).put({ + ...options, + url: '/vm/{id}/specs' + }); +}; + /** * Start a VM * Start a virtual machine for the sandbox (devbox) with the given ID @@ -162,8 +192,8 @@ export const vmStart = (options: OptionsLe * The new tier must not exceed your team's maximum allowed tier. * */ -export const vmUpdateSpecs = (options: OptionsLegacyParser) => { - return (options?.client ?? client).post({ +export const vmUpdateSpecs2 = (options: OptionsLegacyParser) => { + return (options?.client ?? client).post({ ...options, url: '/vm/{id}/update_specs' }); diff --git a/src/client/types.gen.ts b/src/client/types.gen.ts index 66d3f61..915521e 100644 --- a/src/client/types.gen.ts +++ b/src/client/types.gen.ts @@ -390,6 +390,28 @@ export type VMStartResponse = { }; }; +export type VMUpdateHibernationTimeoutRequest = { + /** + * The new hibernation timeout in seconds. + * + * Must be greater than 0 and less than or equal to 86400 (24 hours). + * + */ + hibernation_timeout_seconds: number; +}; + +export type VMUpdateHibernationTimeoutResponse = { + errors?: Array<((string | { + [key: string]: unknown; +}))>; + success?: boolean; +} & { + data?: { + hibernation_timeout_seconds: number; + id: string; + }; +}; + export type VMUpdateSpecsRequest = { /** * Determines which specs to update the VM with. @@ -555,6 +577,23 @@ export type VmHibernateResponse = (VMHibernateResponse); export type VmHibernateError = unknown; +export type VmUpdateHibernationTimeoutData = { + /** + * VM Update Hibernation Timeout Request + */ + body?: VMUpdateHibernationTimeoutRequest; + path: { + /** + * Sandbox ID + */ + id: string; + }; +}; + +export type VmUpdateHibernationTimeoutResponse = (VMUpdateHibernationTimeoutResponse); + +export type VmUpdateHibernationTimeoutError = unknown; + export type VmShutdownData = { /** * VM Shutdown Request @@ -572,6 +611,23 @@ export type VmShutdownResponse = (VMShutdownResponse); export type VmShutdownError = unknown; +export type VmUpdateSpecsData = { + /** + * VM Update Specs Request + */ + body?: VMUpdateSpecsRequest; + path: { + /** + * Sandbox ID + */ + id: string; + }; +}; + +export type VmUpdateSpecsResponse = (VMUpdateSpecsResponse); + +export type VmUpdateSpecsError = unknown; + export type VmStartData = { /** * VM Start Request @@ -589,7 +645,7 @@ export type VmStartResponse = (VMStartResponse); export type VmStartError = unknown; -export type VmUpdateSpecsData = { +export type VmUpdateSpecs2Data = { /** * VM Update Specs Request */ @@ -602,6 +658,6 @@ export type VmUpdateSpecsData = { }; }; -export type VmUpdateSpecsResponse = (VMUpdateSpecsResponse); +export type VmUpdateSpecs2Response = (VMUpdateSpecsResponse); -export type VmUpdateSpecsError = unknown; \ No newline at end of file +export type VmUpdateSpecs2Error = unknown; \ No newline at end of file diff --git a/src/sandbox-client.ts b/src/sandbox-client.ts index 63f8960..c6fb14f 100644 --- a/src/sandbox-client.ts +++ b/src/sandbox-client.ts @@ -7,6 +7,7 @@ import { vmHibernate, vmShutdown, vmStart, + vmUpdateHibernationTimeout, vmUpdateSpecs, } from "./client"; import { Sandbox } from "./sandbox"; @@ -371,6 +372,28 @@ export class SandboxClient { handleResponse(response, `Failed to update sandbox tier ${id}`); } + /** + * Updates the hibernation timeout of a sandbox. + * + * @param id The ID of the sandbox to update + * @param timeoutSeconds The new hibernation timeout in seconds + */ + async updateHibernationTimeout( + id: string, + timeoutSeconds: number + ): Promise { + const response = await vmUpdateHibernationTimeout({ + client: this.apiClient, + path: { id }, + body: { hibernation_timeout_seconds: timeoutSeconds }, + }); + + handleResponse( + response, + `Failed to update hibernation timeout for sandbox ${id}` + ); + } + private async connectToSandbox( id: string, startVm: () => Promise< diff --git a/src/sandbox.ts b/src/sandbox.ts index 6fb2de3..136b1e0 100644 --- a/src/sandbox.ts +++ b/src/sandbox.ts @@ -245,4 +245,13 @@ export class Sandbox extends SandboxWithoutClient { public async updateTier(tier: VMTier): Promise { await this.sandboxClient.updateTier(this.id, tier); } + + /** + * Updates the hibernation timeout of a sandbox. + * + * @param timeoutSeconds The new hibernation timeout in seconds + */ + public async updateHibernationTimeout(timeoutSeconds: number): Promise { + await this.sandboxClient.updateHibernationTimeout(this.id, timeoutSeconds); + } }