import {z} from 'zod' export type PublicSchedulePayload = {input: unknown, memory_entity_id?: string | undefined, metadata?: {[key: string]: string} | undefined, variables?: {[key: string]: unknown} | undefined}; export type PatchApiV3AgentsAgentKeySchedulesScheduleIdArgs = {agent_key: string, schedule_id: string, body: {agent_tag?: string | undefined, display_name?: string | undefined, expression?: string | undefined, is_active?: boolean | undefined, payload?: PublicSchedulePayload | undefined, type?: 'cron' | undefined}}; export type PatchApiV3AgentsAgentKeySchedulesScheduleIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const publicSchedulePayload = z.object({input: z.unknown(), memory_entity_id: z.string().optional(), metadata: z.record(z.string(), z.string()).optional(), variables: z.record(z.string(), z.unknown()).optional()}); export const patchApiV3AgentsAgentKeySchedulesScheduleIdResponse = z.object({_id: z.string(), agent_key: z.string(), agent_tag: z.string().optional(), created: z.string(), created_by_id: z.string(), display_name: z.string().optional(), expression: z.string(), generation: z.number().int(), is_active: z.boolean(), last_triggered_at: z.string().optional(), payload: publicSchedulePayload, trigger_count: z.number().int(), type: z.enum(["cron", "once", "interval"]), updated: z.string(), updated_by_id: z.string().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 }; /** * Update schedule * * PATCH /v3/agents/{agent_key}/schedules/{schedule_id} */ export const patchApiV3AgentsAgentKeySchedulesScheduleId = async (args: PatchApiV3AgentsAgentKeySchedulesScheduleIdArgs, options?: PatchApiV3AgentsAgentKeySchedulesScheduleIdOptions) => { const {baseUrl = "https://my.orq.ai", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/agents/${encodeURIComponent(String(args.agent_key))}/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(patchApiV3AgentsAgentKeySchedulesScheduleIdResponse, await res.json()) };