import {z} from 'zod' export type ResolvePublicApiTaskInteractionRequestDto = {response: string | {answers: Array<{details?: string | undefined, question: string, selected: Array}>}}; export type CreateApiV1TasksTaskIdInteractionsInteractionIdArgs = {'Idempotency-Key': string, interactionId: string, taskId: string, body: ResolvePublicApiTaskInteractionRequestDto}; export type CreateApiV1TasksTaskIdInteractionsInteractionIdOptions = {baseUrl?: string | undefined, personalApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const resolvePublicApiTaskInteractionResponseDto = z.object({resolved: z.boolean(), task: z.object({id: z.string(), title: z.string(), status: z.enum(["idle", "queued", "running", "awaiting_input", "completed", "cancelled", "failed"]), executionMode: z.enum(["adam", "external"]).optional(), projectId: z.string().nullable(), model: z.object({slug: z.string().min(1).max(64).nullable(), fast: z.boolean(), effort: z.enum(["low", "medium", "high", "xhigh", "max"]).nullable()}).nullable(), pendingInteraction: z.object({id: z.string(), type: z.enum(["question", "approval"]), prompt: z.string().nullable()}).nullable(), 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 }; /** * Answer a task interaction * * POST /v1/tasks/{taskId}/interactions/{interactionId} * * Also accepts auth: adamId */ export const createApiV1TasksTaskIdInteractionsInteractionId = async (args: CreateApiV1TasksTaskIdInteractionsInteractionIdArgs, options?: CreateApiV1TasksTaskIdInteractionsInteractionIdOptions) => { 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/tasks/${encodeURIComponent(String(args.taskId))}/interactions/${encodeURIComponent(String(args.interactionId))}${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(resolvePublicApiTaskInteractionResponseDto, await res.json()) };