import {z} from 'zod' export type CreateApiV2AgentsAgentIdSchedulesArgs = {agent_id: string, body: {enabled: boolean, frequency: 'every_5_minutes' | 'every_15_minutes' | 'hourly' | 'daily' | 'workday' | 'weekly' | 'monthly' | 'custom', time?: (string | null) | undefined, timezone: string, day?: ('monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday' | null) | undefined, day_of_month?: (number | null) | undefined, cron?: (string | null) | undefined, recurring?: (boolean | null) | undefined}}; export type CreateApiV2AgentsAgentIdSchedulesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2AgentsAgentIdSchedulesResponse = z.object({id: z.string(), build_id: z.string(), agent_id: z.string(), user_id: z.string(), enabled: z.boolean(), frequency: z.enum(["every_5_minutes", "every_15_minutes", "hourly", "daily", "workday", "weekly", "monthly", "custom"]), time: z.string().nullable(), timezone: z.string(), day: z.string().nullable(), day_of_month: z.number().nullable(), cron: z.string().nullable(), source: z.string().nullable(), task: z.string().nullable(), recurring: z.boolean().nullable(), auto_disabled_at: z.string().nullable(), auto_disabled_reason: z.string().nullable(), consecutive_missing_connection_failures: z.number().int().gte(0).lte(9007199254740991), first_missing_connection_failure_at: z.string().nullable(), last_missing_connection_failure_at: z.string().nullable(), created_at: z.string(), updated_at: z.string(), user_name: z.string().nullable().optional(), user_email: z.string().nullable().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 }; /** * Create Schedule * * POST /v2/agents/{agent_id}/schedules */ export const createApiV2AgentsAgentIdSchedules = async (args: CreateApiV2AgentsAgentIdSchedulesArgs, options?: CreateApiV2AgentsAgentIdSchedulesOptions) => { const {baseUrl = "https://api.duvo.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/agents/${encodeURIComponent(String(args.agent_id))}/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(createApiV2AgentsAgentIdSchedulesResponse, await res.json()) };