import {z} from 'zod' export type GetApiV1AutomationsAutomationIdArgs = {automationId: string}; export type GetApiV1AutomationsAutomationIdOptions = {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 }; /** * Get an automation * * GET /v1/automations/{automationId} * * Also accepts auth: adamId */ export const getApiV1AutomationsAutomationId = async (args: GetApiV1AutomationsAutomationIdArgs, options?: GetApiV1AutomationsAutomationIdOptions) => { const {baseUrl = "https://api.adam.new", fetch: fetchFn = fetch, personalApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (personalApiKey !== undefined) headers.set('authorization', `Bearer ${personalApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/automations/${encodeURIComponent(String(args.automationId))}${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(getPublicApiAutomationResponseDto, await res.json()) };