import {z} from 'zod' export type GetApiApiScheduledJobsNamespaceJobIdArgs = {namespace: string, jobId: string}; export type GetApiApiScheduledJobsNamespaceJobIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiScheduledJobsNamespaceJobIdResponse = z.object({id: z.string(), createdAt: z.string(), schedule: z.string(), suspend: z.boolean(), suspendReason: z.string().optional(), concurrency: z.boolean(), status: z.object({lastJob: z.object({id: z.string(), at: z.string()}).nullable(), nextJobRunAt: z.string()}), type: z.literal("scheduled-job"), owner: z.object({id: z.string().min(24).max(24), name: z.string(), avatarUrl: z.string(), type: z.enum(["user", "org"])}), initiator: z.object({id: z.string().min(24).max(24), name: z.string(), avatarUrl: z.string(), type: z.enum(["user", "org"])}).optional(), jobSpec: z.object({spaceId: z.string().optional(), dockerImage: z.string().optional(), timeout: z.number().optional(), environment: z.record(z.string(), z.string()), command: z.array(z.string()).optional(), arguments: z.array(z.string()).optional(), arch: z.enum(["amd64", "arm64"]).optional(), flavor: z.enum(["cpu-basic", "cpu-upgrade", "cpu-performance", "cpu-xl", "sprx8", "zero-a10g", "t4-small", "t4-medium", "l4x1", "l4x4", "l40sx1", "l40sx4", "l40sx8", "a10g-small", "a10g-large", "a10g-largex2", "a10g-largex4", "a100-large", "a100x4", "a100x8", "h200", "h200x2", "h200x4", "h200x8", "rtx-pro-6000", "rtx-pro-6000x2", "rtx-pro-6000x4", "rtx-pro-6000x8", "inf2x6"]), resourceGroupId: z.string().optional(), retry: z.number().optional(), startedAt: z.string().optional(), finishedAt: z.string().optional(), durations: z.object({schedulingSecs: z.number().optional(), runningSecs: z.number().optional(), totalSecs: z.number().optional()}).optional(), volumes: z.array(z.object({type: z.string(), source: z.string(), mountPath: z.string(), revision: z.string().optional(), readOnly: z.boolean().optional(), path: z.string().optional()})).optional(), expose: z.object({ports: z.array(z.number().int().gte(1).lte(65535)), portsPublic: z.array(z.number().int().gte(1).lte(65535)).optional()}).optional(), network: z.object({group: z.string().max(46), aliases: z.array(z.string().max(34))}).optional(), resourceGroup: z.object({id: z.string().min(24).max(24), name: z.string(), numUsers: z.number().optional()}).optional(), secrets: z.array(z.string()).optional(), labels: z.record(z.string(), z.string()).optional(), hfToken: z.object({ownerName: z.string(), orgName: z.string().optional(), tokenRole: z.enum(["read", "write", "fineGrained"]).optional(), tokenId: z.string().min(24).max(24).optional(), settingsUrl: z.string().optional()}).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 }; /** * Get scheduled job * * GET /api/scheduled-jobs/{namespace}/{jobId} */ export const getApiApiScheduledJobsNamespaceJobId = async (args: GetApiApiScheduledJobsNamespaceJobIdArgs, options?: GetApiApiScheduledJobsNamespaceJobIdOptions) => { const {baseUrl = "https://huggingface.co", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/scheduled-jobs/${encodeURIComponent(String(args.namespace))}/${encodeURIComponent(String(args.jobId))}${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(getApiApiScheduledJobsNamespaceJobIdResponse, await res.json()) };