import {z} from 'zod' export type GetApiProjectsProjectIdComputeVmsInstancesArgs = {project_id: string, ids?: string | undefined, names?: string | undefined, types?: string | undefined, locations?: string | undefined, states?: string | undefined, nvlink_domain_ids?: string | undefined, limit?: string | undefined, sort?: string | undefined, next_token?: string | undefined, prev_token?: string | undefined}; export type GetApiProjectsProjectIdComputeVmsInstancesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const attachedDiskV1 = z.object({attachment_type: z.string(), block_size: z.number().int(), created_at: z.string(), id: z.string(), location: z.string(), mode: z.string(), name: z.string(), serial_number: z.string(), size: z.string(), type: z.string(), updated_at: z.string()}); export const hostChannelAdapter = z.object({guid: z.string(), ib_network_id: z.string(), ib_partition_id: z.string(), transport_network_id: z.string(), transport_partition_id: z.string(), type: z.string()}); export const privateIPv4Address = z.object({address: z.string()}); export const publicIPv4Address = z.object({address: z.string(), id: z.string(), type: z.string()}); export const iPAddresses = z.object({private_ipv4: privateIPv4Address, public_ipv4: publicIPv4Address}); export const networkInterface = z.object({external_dns_name: z.string(), id: z.string(), interface_type: z.string(), ips: z.array(iPAddresses), mac_address: z.string(), name: z.string(), network: z.string(), subnet: z.string()}); export const virtualizationFeatures = z.object({nested_virtualization: z.boolean().optional()}); export const instanceV1 = z.object({billing_type: z.string().optional(), commitment_end: z.string().optional(), commitment_period: z.number().int().optional(), created_at: z.string(), disks: z.array(attachedDiskV1), host_channel_adapters: z.array(hostChannelAdapter), id: z.string(), instance_group_id: z.string().optional(), instance_template_id: z.string().optional(), location: z.string(), maintenance_policy: z.enum(["manual", "stop-vm", "unspecified"]), name: z.string(), network_interfaces: z.array(networkInterface), nvlink_domain_id: z.string().optional(), pod_id: z.string().optional(), project_id: z.string(), reservation_id: z.string().optional(), state: z.string(), type: z.string(), updated_at: z.string(), virtualization_features: virtualizationFeatures.optional()}); export const listInstancesResponseV1 = z.object({items: z.array(instanceV1), next_page_token: z.string().optional(), prev_page_token: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Lists all VMs in the project and returns their details. * * GET /projects/{project_id}/compute/vms/instances */ export const getApiProjectsProjectIdComputeVmsInstances = async (args: GetApiProjectsProjectIdComputeVmsInstancesArgs, options?: GetApiProjectsProjectIdComputeVmsInstancesOptions) => { const {baseUrl = "https://api.cloud.crusoe.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ids != null) query.append("ids", String(args.ids)) if (args.names != null) query.append("names", String(args.names)) if (args.types != null) query.append("types", String(args.types)) if (args.locations != null) query.append("locations", String(args.locations)) if (args.states != null) query.append("states", String(args.states)) if (args.nvlink_domain_ids != null) query.append("nvlink_domain_ids", String(args.nvlink_domain_ids)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.next_token != null) query.append("next_token", String(args.next_token)) if (args.prev_token != null) query.append("prev_token", String(args.prev_token)) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/compute/vms/instances${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(listInstancesResponseV1, await res.json()) };