import {z} from 'zod' export type GetApiV1AgentsWorkflowPermanentIdSchedulesArgs = {workflow_permanent_id: string}; export type GetApiV1AgentsWorkflowPermanentIdSchedulesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const oneTimeDispatchStatus = z.enum(["pending", "fired", "canceled", "failed"]); export const workflowSchedule = z.object({workflow_schedule_id: z.string(), organization_id: z.string(), workflow_permanent_id: z.string(), cron_expression: z.string().nullable().optional(), interval_seconds: z.number().int().nullable().optional(), first_fire_at: z.string().nullable().optional(), run_at: z.string().nullable().optional(), dispatch_status: oneTimeDispatchStatus.nullable().optional(), workflow_run_id: z.string().nullable().optional(), timezone: z.string(), enabled: z.boolean(), parameters: z.record(z.string(), z.unknown()).nullable().optional(), temporal_schedule_id: z.string().nullable().optional(), name: z.string().nullable().optional(), description: z.string().nullable().optional(), created_by: z.string().nullable().optional(), created_at: z.string(), modified_at: z.string(), deleted_at: z.string().nullable().optional()}); export const workflowScheduleListResponse = z.object({schedules: z.array(workflowSchedule)}); 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 schedules for an agent * * GET /v1/agents/{workflow_permanent_id}/schedules */ export const getApiV1AgentsWorkflowPermanentIdSchedules = async (args: GetApiV1AgentsWorkflowPermanentIdSchedulesArgs, options?: GetApiV1AgentsWorkflowPermanentIdSchedulesOptions) => { const {baseUrl = "https://api.skyvern.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/agents/${encodeURIComponent(String(args.workflow_permanent_id))}/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(workflowScheduleListResponse, await res.json()) };