import {z} from 'zod' export type GetApiV1WorkspacesWorkspaceIdAgentsAgentIdSchedulesArgs = {workspaceId: string, agentId: string, limit?: number | undefined, cursor?: string | undefined, prefix?: string | undefined, query?: string | undefined, labels?: string | undefined, sortOrder?: string | undefined, includeInfo?: boolean | undefined}; export type GetApiV1WorkspacesWorkspaceIdAgentsAgentIdSchedulesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const resourceMetadata = z.object({id: z.string(), accountId: z.string(), workspaceId: z.string(), name: z.string(), externalId: z.string().optional(), labels: z.record(z.string(), z.string()).optional(), profileId: z.string(), createdAt: z.string(), updatedAt: z.string().optional()}); export const scheduleRange = z.object({start: z.number().int().optional(), end: z.number().int().optional(), step: z.number().int().optional()}); export const scheduleCalendar = z.object({second: z.array(scheduleRange).optional(), minute: z.array(scheduleRange).optional(), hour: z.array(scheduleRange).optional(), dayOfMonth: z.array(scheduleRange).optional(), month: z.array(scheduleRange).optional(), dayOfWeek: z.array(scheduleRange).optional(), comment: z.string().optional()}); export const scheduleInterval = z.object({every: z.string().optional(), offset: z.string().optional()}); export const agentScheduleSpecSchedule = z.object({calendars: z.array(scheduleCalendar).optional(), intervals: z.array(scheduleInterval).optional(), timezone: z.string().optional()}); export const agentScheduleSpec = z.object({schedule: agentScheduleSpecSchedule, overlapPolicy: z.enum(["OVERLAP_POLICY_UNSPECIFIED", "OVERLAP_POLICY_ALLOW", "OVERLAP_POLICY_SKIP"]).optional(), firstUserMessage: z.string().optional(), variationId: z.string().optional(), systemPromptData: z.object({}).optional(), firstUserMessageData: z.object({}).optional()}); export const accountResourceMetadata = z.object({id: z.string(), accountId: z.string(), name: z.string(), externalId: z.string().optional(), labels: z.record(z.string(), z.string()).optional(), profileId: z.string(), createdAt: z.string().optional()}); export const profileSpec = z.object({email: z.string().optional(), name: z.string().optional(), type: z.enum(["PROFILE_TYPE_UNSPECIFIED", "PROFILE_TYPE_USER", "PROFILE_TYPE_API_KEY", "PROFILE_TYPE_SYSTEM"])}); export const profile = z.object({metadata: accountResourceMetadata, spec: profileSpec}); export const agentScheduleInfo = z.object({nextFireAt: z.string().optional(), lastFireAt: z.string().optional(), lastObjectiveId: z.string().optional(), lastSkippedAt: z.string().optional(), lastSkipReason: z.string().optional(), totalFires: z.number().int().optional(), createdBy: profile.optional()}); export const agentSchedule = z.object({metadata: resourceMetadata, spec: agentScheduleSpec, info: agentScheduleInfo.optional(), state: z.enum(["STATE_UNSPECIFIED", "STATE_ACTIVE", "STATE_PAUSED", "STATE_ARCHIVED"])}); export const page = z.object({nextCursor: z.string().optional()}); export const listAgentSchedulesResponse = z.object({items: z.array(agentSchedule).optional(), pagination: page.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 schedules * * GET /v1/workspaces/{workspaceId}/agents/{agentId}/schedules */ export const getApiV1WorkspacesWorkspaceIdAgentsAgentIdSchedules = async (args: GetApiV1WorkspacesWorkspaceIdAgentsAgentIdSchedulesArgs, options?: GetApiV1WorkspacesWorkspaceIdAgentsAgentIdSchedulesOptions) => { const {baseUrl = "https://api.cadenya.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.prefix != null) query.append("prefix", String(args.prefix)) if (args.query != null) query.append("query", String(args.query)) if (args.labels != null) query.append("labels", String(args.labels)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (args.includeInfo != null) query.append("includeInfo", String(args.includeInfo)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.workspaceId))}/agents/${encodeURIComponent(String(args.agentId))}/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(listAgentSchedulesResponse, await res.json()) };