import {z} from 'zod' export type GetApiV1WorkflowsSchedulesScheduleIdArgs = {schedule_id: string}; export type GetApiV1WorkflowsSchedulesScheduleIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const scheduleRange = z.object({start: z.number().int(), end: z.number().int().optional(), step: z.number().int().optional()}); export const scheduleCalendar = z.object({second: z.array(scheduleRange).optional(), minute: z.array(scheduleRange).optional(), hour: z.array(scheduleRange).optional(), day_of_month: z.array(scheduleRange).optional(), month: z.array(scheduleRange).optional(), year: z.array(scheduleRange).optional(), day_of_week: z.array(scheduleRange).optional(), comment: z.string().nullable().optional()}); export const scheduleInterval = z.object({every: z.string(), offset: z.string().nullable().optional()}); export const scheduleOverlapPolicy = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6)]); export const schedulePolicy = z.object({catchup_window_seconds: z.number().int().optional(), overlap: scheduleOverlapPolicy.optional(), pause_on_failure: z.boolean().optional()}); export const scheduleFutureExecution = z.object({scheduled_at: z.string()}); export const scheduleRecentExecution = z.object({scheduled_at: z.string(), started_at: z.string(), execution_id: z.string()}); export const scheduleDefinitionOutput = z.object({input: z.unknown(), calendars: z.array(scheduleCalendar).optional(), intervals: z.array(scheduleInterval).optional(), cron_expressions: z.array(z.string()).optional(), skip: z.array(scheduleCalendar).optional(), start_at: z.string().nullable().optional(), end_at: z.string().nullable().optional(), jitter: z.string().nullable().optional(), time_zone_name: z.string().nullable().optional(), policy: schedulePolicy.optional(), schedule_id: z.string(), remaining_executions: z.number().int().nullable().optional(), workflow_name: z.string(), deployment_name: z.string().nullable().optional(), paused: z.boolean(), note: z.string().nullable().optional(), future_executions: z.array(scheduleFutureExecution).optional(), recent_executions: z.array(scheduleRecentExecution).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 Schedule * * GET /v1/workflows/schedules/{schedule_id} */ export const getApiV1WorkflowsSchedulesScheduleId = async (args: GetApiV1WorkflowsSchedulesScheduleIdArgs, options?: GetApiV1WorkflowsSchedulesScheduleIdOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workflows/schedules/${encodeURIComponent(String(args.schedule_id))}${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(scheduleDefinitionOutput, await res.json()) };