import {z} from 'zod' export type GetApiV2AgentsAgentIdSchedulesArgs = {agent_id: string}; export type GetApiV2AgentsAgentIdSchedulesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2AgentsAgentIdSchedulesResponse = z.object({schedules: z.array(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 }; /** * List Agent Schedules * * GET /v2/agents/{agent_id}/schedules */ export const getApiV2AgentsAgentIdSchedules = async (args: GetApiV2AgentsAgentIdSchedulesArgs, options?: GetApiV2AgentsAgentIdSchedulesOptions) => { const {baseUrl = "https://api.duvo.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV2AgentsAgentIdSchedulesResponse, await res.json()) };