import {z} from 'zod' export type GetApiSandboxesSandboxNameSchedulesArgs = {limit?: number | undefined, cursor?: string | undefined, sort?: ('createdAt:desc' | 'createdAt:asc' | 'name:asc' | 'name:desc') | undefined, q?: string | undefined, type?: ('cron' | 'at') | undefined}; export type GetApiSandboxesSandboxNameSchedulesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const sandboxScheduleInput = z.object({command: z.string().optional(), env: z.record(z.string(), z.string()).optional(), keepAlive: z.boolean().optional(), name: z.string().optional(), timeout: z.number().int().optional(), workingDir: z.string().optional()}); export const sandboxScheduleEntry = z.object({createdAt: z.string().optional(), id: z.string().optional(), input: sandboxScheduleInput.optional(), maxExecutions: z.number().int().optional(), type: z.enum(["cron", "at", "sleep"]).optional(), value: z.string().optional()}); export const paginationMeta = z.object({hasMore: z.boolean().optional(), nextCursor: z.string().optional(), total: z.number().int().optional()}); export const sandboxScheduleEntryList = z.object({data: z.array(sandboxScheduleEntry).optional(), meta: paginationMeta.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 }; /** * List Sandbox Schedules * * GET /sandboxes/{sandboxName}/schedules * * Also accepts auth: ApiKeyAuth */ export const getApiSandboxesSandboxNameSchedules = async (args: GetApiSandboxesSandboxNameSchedulesArgs, options?: GetApiSandboxesSandboxNameSchedulesOptions) => { const {baseUrl = "https://api.blaxel.ai/v0", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.q != null) query.append("q", String(args.q)) if (args.type != null) query.append("type", String(args.type)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/sandboxes/${encodeURIComponent(String(args.sandboxName))}/schedules${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(sandboxScheduleEntryList, await res.json()) };