import {z} from 'zod' export type GetApiWorkflowArgs = {object_status?: (number | null) | undefined, parent_uuid?: (string | null) | undefined, name_contains?: (string | null) | undefined, public?: (boolean | null) | undefined, starred?: (boolean | null) | undefined, project_uuid?: (string | null) | undefined, page?: number | undefined, size?: number | undefined, sort?: (string | null) | undefined, object_type?: (string | null) | undefined, access_token?: (string | null) | undefined}; export type GetApiWorkflowOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const workflow = z.object({name: z.string().nullable().optional(), parent_uuid: z.string().nullable().optional(), notes: z.string().nullable().optional(), starred: z.boolean().nullable().optional(), public: z.boolean().nullable().optional(), shared_with_rowan: z.boolean().nullable().optional(), object_type: z.string(), object_data: z.object({}).nullable().optional(), email_when_complete: z.boolean().nullable().optional(), max_credits: z.number().int().nullable().optional(), created_at: z.string(), updated_at: z.string().nullable().optional(), started_at: z.string().nullable().optional(), completed_at: z.string().nullable().optional(), queued_at: z.string().nullable().optional(), deleted_at: z.string().nullable().optional(), uuid: z.string(), elapsed: z.number().nullable().optional(), credits_charged: z.number(), object_status: z.number().int().nullable().optional(), object_logfile: z.string(), is_free: z.boolean().optional(), user_uuid: z.string().nullable().optional(), resubmitted_from_uuid: z.string().nullable().optional(), submission_group_uuid: z.string().nullable().optional(), run_by_username: z.string().nullable().optional(), public_until: z.string().nullable().optional(), compute_hardware: z.string().nullable().optional(), execution_backend: z.enum(["modal", "aws"]).nullable().optional(), retry_count: z.number().int().optional(), is_temporarily_public: z.boolean()}); export const workflowList = z.object({workflows: z.array(workflow), num_pages: z.number().int().gt(0)}); 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 Workflows * * GET /workflow */ export const getApiWorkflow = async (args: GetApiWorkflowArgs, options: GetApiWorkflowOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() const cookies: string[] = [] headers.set('accept', "application/json") if (args.object_status != null) query.append("object_status", String(args.object_status)) if (args.parent_uuid != null) query.append("parent_uuid", String(args.parent_uuid)) if (args.name_contains != null) query.append("name_contains", String(args.name_contains)) if (args.public != null) query.append("public", String(args.public)) if (args.starred != null) query.append("starred", String(args.starred)) if (args.project_uuid != null) query.append("project_uuid", String(args.project_uuid)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.object_type != null) query.append("object_type", String(args.object_type)) if (args.access_token != null) cookies.push("access_token=" + encodeURIComponent(String(args.access_token))) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) if (cookies.length > 0) headers.set('cookie', cookies.join('; ')) const url = `${baseUrl.replace(/\/+$/, '')}/workflow${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(workflowList, await res.json()) };