import {z} from 'zod' export type CreatePublicApiAutomationRequestDtoSchema0 = string | number | boolean | Array | {[key: string]: CreatePublicApiAutomationRequestDtoSchema0} | null; export type CreatePublicApiAutomationRequestDto = {name: string, prompt: string, effort?: ('low' | 'medium' | 'high' | 'xhigh' | 'max' | null) | undefined, enabled?: boolean | undefined, visibility?: ('private' | 'team') | undefined, trigger: 'schedule' | 'webhook', type: 'recurring' | 'one_time', cron?: string | undefined, timezone?: string | undefined, runAt?: string | undefined, triggerProvider?: 'composio' | undefined, triggerEvent?: string | undefined, triggerApp?: string | undefined, triggerConfig?: {[key: string]: CreatePublicApiAutomationRequestDtoSchema0} | undefined}; export type CreateApiV1AutomationsArgs = {'Idempotency-Key'?: string | undefined, body: CreatePublicApiAutomationRequestDto}; export type CreateApiV1AutomationsOptions = {baseUrl?: string | undefined, personalApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getPublicApiAutomationResponseDtoSchema0: z.ZodType = z.union([z.string(), z.number(), z.boolean(), z.array(z.lazy(() => getPublicApiAutomationResponseDtoSchema0)), z.record(z.string(), z.lazy(() => getPublicApiAutomationResponseDtoSchema0))]).nullable(); export const getPublicApiAutomationResponseDto = z.object({automation: z.object({id: z.string(), name: z.string(), prompt: z.string(), effort: z.enum(["low", "medium", "high", "xhigh", "max"]).nullable(), enabled: z.boolean(), trigger: z.enum(["schedule", "webhook"]), type: z.enum(["recurring", "one_time"]), cron: z.string().nullable(), timezone: z.string(), runAt: z.string().nullable(), nextRunAt: z.string().nullable(), triggerProvider: z.literal("composio").nullable(), triggerEvent: z.string().nullable(), triggerApp: z.string().nullable(), triggerConfig: z.record(z.string(), getPublicApiAutomationResponseDtoSchema0).nullable(), taskId: z.string().nullable(), visibility: z.enum(["private", "team"]), lastRunAt: z.string().nullable(), lastStatus: z.enum(["running", "completed", "failed", "skipped"]).nullable(), runCount: z.number().int().gte(0).lte(9007199254740991), createdAt: z.string(), updatedAt: 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 }; /** * Create an automation * * POST /v1/automations * * Also accepts auth: adamId */ export const createApiV1Automations = async (args: CreateApiV1AutomationsArgs, options?: CreateApiV1AutomationsOptions) => { const {baseUrl = "https://api.adam.new", fetch: fetchFn = fetch, personalApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (personalApiKey !== undefined) headers.set('authorization', `Bearer ${personalApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/automations${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(getPublicApiAutomationResponseDto, await res.json()) };