import {z} from 'zod' export type RunTargetCapabilities = {accessibility?: boolean | undefined}; export type RunTarget = {capabilities?: RunTargetCapabilities | undefined, device_class: 'phone', ownership?: ('dedicated' | 'shared') | undefined, phone_id?: string | undefined, platform?: 'android' | undefined}; export type AgentScheduleRunTemplate = {network?: ('restricted' | 'internet') | undefined, revision_id?: string | undefined, targets?: (Array | null) | undefined, variables?: {[key: string]: unknown} | undefined}; export type AgentScheduleUpdateRequest = {$schema?: string | undefined, cron_expression?: string | undefined, end_at?: (string | null) | undefined, name?: string | undefined, overlap_policy?: ('skip' | 'queue') | undefined, run_template?: AgentScheduleRunTemplate | undefined, start_at?: (string | null) | undefined, time_zone?: string | undefined}; export type PatchApiAgentsAgentIdSchedulesScheduleIdArgs = {agent_id: string, schedule_id: string, body: AgentScheduleUpdateRequest}; export type PatchApiAgentsAgentIdSchedulesScheduleIdOptions = {baseUrl: string, 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({$schema: z.string().optional(), 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 }; /** * Update a schedule * * PATCH /agents/{agent_id}/schedules/{schedule_id} */ export const patchApiAgentsAgentIdSchedulesScheduleId = async (args: PatchApiAgentsAgentIdSchedulesScheduleIdArgs, options: PatchApiAgentsAgentIdSchedulesScheduleIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(agentSchedule, await res.json()) };