import {z} from 'zod' export type UnpauseScheduleRequest = {note?: (string | null) | undefined}; export type CreateApiAgentsAgentIdSchedulesScheduleNameUnpauseArgs = {schedule_name: string, agent_id: string, body: UnpauseScheduleRequest | null}; export type CreateApiAgentsAgentIdSchedulesScheduleNameUnpauseOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const scheduleActionInfo = z.object({task_queue: z.string(), workflow_id_prefix: z.string(), workflow_name: z.string(), workflow_params: z.array(z.unknown()).nullable().optional()}); export const scheduleSpecInfo = z.object({cron_expressions: z.array(z.string()).optional(), end_at: z.string().nullable().optional(), intervals_seconds: z.array(z.number().int()).optional(), start_at: z.string().nullable().optional()}); export const scheduleState = z.enum(["ACTIVE", "PAUSED"]); export const scheduleResponse = z.object({action: scheduleActionInfo, agent_id: z.string(), created_at: z.string().nullable().optional(), last_action_time: z.string().nullable().optional(), name: z.string(), next_action_times: z.array(z.string()).optional(), num_actions_missed: z.number().int().optional(), num_actions_taken: z.number().int().optional(), schedule_id: z.string(), spec: scheduleSpecInfo, state: scheduleState}); 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 }; /** * Unpause Schedule * * POST /agents/{agent_id}/schedules/{schedule_name}/unpause */ export const createApiAgentsAgentIdSchedulesScheduleNameUnpause = async (args: CreateApiAgentsAgentIdSchedulesScheduleNameUnpauseArgs, options: CreateApiAgentsAgentIdSchedulesScheduleNameUnpauseOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/agents/${encodeURIComponent(String(args.agent_id))}/schedules/${encodeURIComponent(String(args.schedule_name))}/unpause${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(scheduleResponse, await res.json()) };