/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type AgentScheduleSpec3 = { type: "cron"; cronExpression: string; timezone?: string | undefined; }; export type AgentScheduleSpec2 = { type: "interval"; intervalSeconds: number; startAt?: Date | undefined; timezone?: string | undefined; }; export type AgentScheduleSpec1 = { type: "once"; runAt: Date; timezone?: string | undefined; }; export type AgentScheduleSpec = | AgentScheduleSpec1 | AgentScheduleSpec2 | AgentScheduleSpec3; /** @internal */ export const AgentScheduleSpec3$inboundSchema: z.ZodType< AgentScheduleSpec3, z.ZodTypeDef, unknown > = z.object({ type: z.literal("cron"), cron_expression: z.string(), timezone: z.string().default("UTC"), }).transform((v) => { return remap$(v, { "cron_expression": "cronExpression", }); }); /** @internal */ export type AgentScheduleSpec3$Outbound = { type: "cron"; cron_expression: string; timezone: string; }; /** @internal */ export const AgentScheduleSpec3$outboundSchema: z.ZodType< AgentScheduleSpec3$Outbound, z.ZodTypeDef, AgentScheduleSpec3 > = z.object({ type: z.literal("cron"), cronExpression: z.string(), timezone: z.string().default("UTC"), }).transform((v) => { return remap$(v, { cronExpression: "cron_expression", }); }); export function agentScheduleSpec3ToJSON( agentScheduleSpec3: AgentScheduleSpec3, ): string { return JSON.stringify( AgentScheduleSpec3$outboundSchema.parse(agentScheduleSpec3), ); } export function agentScheduleSpec3FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => AgentScheduleSpec3$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'AgentScheduleSpec3' from JSON`, ); } /** @internal */ export const AgentScheduleSpec2$inboundSchema: z.ZodType< AgentScheduleSpec2, z.ZodTypeDef, unknown > = z.object({ type: z.literal("interval"), interval_seconds: z.number().int(), start_at: z.string().datetime({ offset: true }).transform(v => new Date(v)) .optional(), timezone: z.string().default("UTC"), }).transform((v) => { return remap$(v, { "interval_seconds": "intervalSeconds", "start_at": "startAt", }); }); /** @internal */ export type AgentScheduleSpec2$Outbound = { type: "interval"; interval_seconds: number; start_at?: string | undefined; timezone: string; }; /** @internal */ export const AgentScheduleSpec2$outboundSchema: z.ZodType< AgentScheduleSpec2$Outbound, z.ZodTypeDef, AgentScheduleSpec2 > = z.object({ type: z.literal("interval"), intervalSeconds: z.number().int(), startAt: z.date().transform(v => v.toISOString()).optional(), timezone: z.string().default("UTC"), }).transform((v) => { return remap$(v, { intervalSeconds: "interval_seconds", startAt: "start_at", }); }); export function agentScheduleSpec2ToJSON( agentScheduleSpec2: AgentScheduleSpec2, ): string { return JSON.stringify( AgentScheduleSpec2$outboundSchema.parse(agentScheduleSpec2), ); } export function agentScheduleSpec2FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => AgentScheduleSpec2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'AgentScheduleSpec2' from JSON`, ); } /** @internal */ export const AgentScheduleSpec1$inboundSchema: z.ZodType< AgentScheduleSpec1, z.ZodTypeDef, unknown > = z.object({ type: z.literal("once"), run_at: z.string().datetime({ offset: true }).transform(v => new Date(v)), timezone: z.string().default("UTC"), }).transform((v) => { return remap$(v, { "run_at": "runAt", }); }); /** @internal */ export type AgentScheduleSpec1$Outbound = { type: "once"; run_at: string; timezone: string; }; /** @internal */ export const AgentScheduleSpec1$outboundSchema: z.ZodType< AgentScheduleSpec1$Outbound, z.ZodTypeDef, AgentScheduleSpec1 > = z.object({ type: z.literal("once"), runAt: z.date().transform(v => v.toISOString()), timezone: z.string().default("UTC"), }).transform((v) => { return remap$(v, { runAt: "run_at", }); }); export function agentScheduleSpec1ToJSON( agentScheduleSpec1: AgentScheduleSpec1, ): string { return JSON.stringify( AgentScheduleSpec1$outboundSchema.parse(agentScheduleSpec1), ); } export function agentScheduleSpec1FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => AgentScheduleSpec1$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'AgentScheduleSpec1' from JSON`, ); } /** @internal */ export const AgentScheduleSpec$inboundSchema: z.ZodType< AgentScheduleSpec, z.ZodTypeDef, unknown > = z.union([ z.lazy(() => AgentScheduleSpec1$inboundSchema), z.lazy(() => AgentScheduleSpec2$inboundSchema), z.lazy(() => AgentScheduleSpec3$inboundSchema), ]); /** @internal */ export type AgentScheduleSpec$Outbound = | AgentScheduleSpec1$Outbound | AgentScheduleSpec2$Outbound | AgentScheduleSpec3$Outbound; /** @internal */ export const AgentScheduleSpec$outboundSchema: z.ZodType< AgentScheduleSpec$Outbound, z.ZodTypeDef, AgentScheduleSpec > = z.union([ z.lazy(() => AgentScheduleSpec1$outboundSchema), z.lazy(() => AgentScheduleSpec2$outboundSchema), z.lazy(() => AgentScheduleSpec3$outboundSchema), ]); export function agentScheduleSpecToJSON( agentScheduleSpec: AgentScheduleSpec, ): string { return JSON.stringify( AgentScheduleSpec$outboundSchema.parse(agentScheduleSpec), ); } export function agentScheduleSpecFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => AgentScheduleSpec$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'AgentScheduleSpec' from JSON`, ); }