import {z} from 'zod' export type ScheduleRange = {start: number, end?: number | undefined, step?: number | undefined}; export type ScheduleCalendar = {second?: Array | undefined, minute?: Array | undefined, hour?: Array | undefined, day_of_month?: Array | undefined, month?: Array | undefined, year?: Array | undefined, day_of_week?: Array | undefined, comment?: (string | null) | undefined}; export type ScheduleInterval = {every: unknown, offset?: (unknown | null) | undefined}; export type ScheduleOverlapPolicy = 1 | 2 | 3 | 4 | 5 | 6; export type SchedulePolicy = {catchup_window_seconds?: number | undefined, overlap?: ScheduleOverlapPolicy | undefined, pause_on_failure?: boolean | undefined}; export type ScheduleDefinition = {input: unknown, calendars?: Array | undefined, intervals?: Array | undefined, cron_expressions?: Array | undefined, skip?: Array | undefined, start_at?: (string | null) | undefined, end_at?: (string | null) | undefined, jitter?: (unknown | null) | undefined, time_zone_name?: (string | null) | undefined, policy?: SchedulePolicy | undefined, max_executions?: (number | null) | undefined, schedule_id?: (string | null) | undefined}; export type WorkflowScheduleRequest = {schedule: ScheduleDefinition, workflow_registration_id?: (string | null) | undefined, workflow_version_id?: (string | null) | undefined, workflow_identifier?: (string | null) | undefined, workflow_task_queue?: (string | null) | undefined, schedule_id?: (string | null) | undefined, deployment_name?: (string | null) | undefined}; export type CreateApiV1WorkflowsSchedulesArgs = {body: WorkflowScheduleRequest}; export type CreateApiV1WorkflowsSchedulesOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const workflowScheduleResponse = z.object({schedule_id: z.string()}); 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 }; /** * Schedule Workflow * * POST /v1/workflows/schedules */ export const createApiV1WorkflowsSchedules = async (args: CreateApiV1WorkflowsSchedulesArgs, options?: CreateApiV1WorkflowsSchedulesOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workflows/schedules${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(workflowScheduleResponse, await res.json()) };