import {z} from 'zod' export type GetApiProjectsProjectIdSlurmClustersArgs = {project_id: string, names?: Array | undefined, location?: string | undefined, state?: string | undefined, slurm_cluster_ids?: Array | undefined}; export type GetApiProjectsProjectIdSlurmClustersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const slurmClusterIssue = z.object({code: z.string().optional(), message: z.string().optional()}); export const slurmCluster = z.object({home_volume_size: z.string().optional(), location: z.string(), login_node_type: z.string().optional(), login_replicas: z.number().int().gte(1).optional(), name: z.string(), root_ssh_pub_keys: z.array(z.string()), subnet_id: z.string().optional(), issues: z.array(slurmClusterIssue).optional(), login_node_endpoint: z.string().optional(), nodesets: z.array(z.string()).optional(), state: z.enum(["PROVISIONING", "RUNNING", "DELETING", "DELETED", "FAILED", "UPDATING", "UNHEALTHY", "CREATE_FAILED", "DELETE_FAILED"]), created_at: z.string().optional(), id: z.string(), updated_at: z.string().optional(), version: z.string().optional()}); export const listSlurmClustersResponse = z.object({items: z.array(slurmCluster)}); 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 clusters belonging to the project. * * GET /projects/{project_id}/slurm/clusters */ export const getApiProjectsProjectIdSlurmClusters = async (args: GetApiProjectsProjectIdSlurmClustersArgs, options?: GetApiProjectsProjectIdSlurmClustersOptions) => { 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") for (const item of args.names ?? []) query.append("names", String(item)) if (args.location != null) query.append("location", String(args.location)) if (args.state != null) query.append("state", String(args.state)) for (const item of args.slurm_cluster_ids ?? []) query.append("slurm_cluster_ids", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/slurm/clusters${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(listSlurmClustersResponse, await res.json()) };