import {z} from 'zod' export type CreateApiAgentsAgentIdSchedulesScheduleIdResumeArgs = {agent_id: string, schedule_id: string}; export type CreateApiAgentsAgentIdSchedulesScheduleIdResumeOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const runTargetCapabilities = z.object({accessibility: z.boolean().optional()}); export const runTarget = z.object({capabilities: runTargetCapabilities.optional(), device_class: z.literal("phone"), ownership: z.enum(["dedicated", "shared"]).optional(), phone_id: z.string().optional(), platform: z.literal("android").optional()}); export const agentScheduleRunTemplate = z.object({network: z.enum(["restricted", "internet"]).optional(), revision_id: z.string().optional(), targets: z.array(runTarget).nullable().optional(), variables: z.record(z.string(), z.unknown()).optional()}); export const agentSchedule = z.object({agent_id: z.string(), created_at: z.string(), cron_expression: z.string(), end_at: z.string().optional(), id: z.string(), last_run_id: z.string().optional(), name: z.string(), next_run_at: z.string().optional(), overlap_policy: z.enum(["skip", "queue"]), run_template: agentScheduleRunTemplate, start_at: z.string().optional(), state: z.enum(["active", "paused", "ended"]), time_zone: z.string(), updated_at: 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 }; /** * Resume a schedule * * POST /agents/{agent_id}/schedules/{schedule_id}:resume */ export const createApiAgentsAgentIdSchedulesScheduleIdResume = async (args: CreateApiAgentsAgentIdSchedulesScheduleIdResumeArgs, options?: CreateApiAgentsAgentIdSchedulesScheduleIdResumeOptions) => { const {baseUrl = "https://api.axilio.ai/api/v1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("X-Axilio-Api-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/agents/${encodeURIComponent(String(args.agent_id))}/schedules/${encodeURIComponent(String(args.schedule_id))}:resume${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(agentSchedule, await res.json()) };