import {z} from 'zod' export type GetApiProjectsProjectIdSlurmSlurmClusterIdNodesetsArgs = {project_id: string, slurm_cluster_id: string, name?: string | undefined}; export type GetApiProjectsProjectIdSlurmSlurmClusterIdNodesetsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const slurmNodesetIssue = z.object({code: z.string().optional(), message: z.string().optional()}); export const slurmNodeset = z.object({count: z.number().int(), created_at: z.string().optional(), id: z.string(), issues: z.array(slurmNodesetIssue).optional(), name: z.string(), state: z.enum(["PROVISIONING", "RUNNING", "DELETING", "DELETED", "UPDATING", "UNHEALTHY", "CREATE_FAILED", "DELETE_FAILED"]), subnet_id: z.string().optional(), transport_partition_id: z.string().optional(), type: z.string(), updated_at: z.string().optional(), vm_ssh_public_key: z.string().optional()}); export const listSlurmNodesetsResponse = z.object({items: z.array(slurmNodeset)}); 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 }; /** * Retrieve information about slurm nodesets belonging to a project or cluster. * * GET /projects/{project_id}/slurm/{slurm_cluster_id}/nodesets */ export const getApiProjectsProjectIdSlurmSlurmClusterIdNodesets = async (args: GetApiProjectsProjectIdSlurmSlurmClusterIdNodesetsArgs, options?: GetApiProjectsProjectIdSlurmSlurmClusterIdNodesetsOptions) => { 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.name != null) query.append("name", String(args.name)) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/slurm/${encodeURIComponent(String(args.slurm_cluster_id))}/nodesets${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(listSlurmNodesetsResponse, await res.json()) };