import {z} from 'zod' export type GetApiV1TasksTaskIdMessagesArgs = {cursor?: string | undefined, limit?: number | undefined, taskId: string}; export type GetApiV1TasksTaskIdMessagesOptions = {baseUrl?: string | undefined, personalApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const listPublicApiTaskMessagesResponseDtoSchema0: z.ZodType = z.union([z.string(), z.number(), z.boolean(), z.array(z.lazy(() => listPublicApiTaskMessagesResponseDtoSchema0)), z.record(z.string(), z.lazy(() => listPublicApiTaskMessagesResponseDtoSchema0))]).nullable(); export const listPublicApiTaskMessagesResponseDto = z.object({messages: z.array(z.object({id: z.string(), role: z.enum(["user", "assistant"]), parts: z.array(z.union([z.object({type: z.literal("reasoning"), text: z.string()}), z.object({type: z.literal("text"), text: z.string()}), z.object({type: z.literal("file"), id: z.string().nullable(), versionId: z.string().optional(), name: z.string().nullable(), mediaType: z.string(), downloadUrl: z.string()}), z.object({type: z.literal("source_url"), sourceId: z.string(), url: z.string(), title: z.string().nullable()}), z.object({type: z.literal("source_document"), sourceId: z.string(), mediaType: z.string(), title: z.string(), filename: z.string().nullable()}), z.object({type: z.literal("reasoning_file"), mediaType: z.string(), url: z.string()}), z.object({type: z.literal("data"), name: z.string(), id: z.string().nullable(), data: listPublicApiTaskMessagesResponseDtoSchema0}), z.object({type: z.literal("custom"), kind: z.string(), providerMetadata: listPublicApiTaskMessagesResponseDtoSchema0.optional()}), z.object({type: z.literal("step_start")}), z.object({type: z.literal("tool_call"), toolCallId: z.string(), name: z.string(), input: listPublicApiTaskMessagesResponseDtoSchema0.optional()}), z.object({type: z.literal("tool_result"), toolCallId: z.string(), name: z.string(), status: z.literal("success"), output: listPublicApiTaskMessagesResponseDtoSchema0.optional()}), z.object({type: z.literal("tool_result"), toolCallId: z.string(), name: z.string(), status: z.literal("error"), error: z.string().optional()}), z.object({type: z.literal("tool_result"), toolCallId: z.string(), name: z.string(), status: z.literal("denied")})])), createdAt: z.string()})), nextCursor: z.array(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 }; /** * List a task's messages * * GET /v1/tasks/{taskId}/messages * * Also accepts auth: adamId */ export const getApiV1TasksTaskIdMessages = async (args: GetApiV1TasksTaskIdMessagesArgs, options?: GetApiV1TasksTaskIdMessagesOptions) => { 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 (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (personalApiKey !== undefined) headers.set('authorization', `Bearer ${personalApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/tasks/${encodeURIComponent(String(args.taskId))}/messages${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(listPublicApiTaskMessagesResponseDto, await res.json()) };