import {z} from 'zod' export type GetApiV1AiAgentsTasksArgs = {projectId?: string | undefined, branchId?: string | undefined, status?: ('RUNNING' | 'STOPPED' | 'STOPPING' | 'ERRORED') | undefined, createdAfter?: string | undefined, createdBefore?: string | undefined, page?: number | undefined, size?: number | undefined}; export type GetApiV1AiAgentsTasksOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const taskSummary = z.object({agentName: z.string().optional(), branchId: z.string().optional(), createdAt: z.string().optional(), description: z.string().optional(), mode: z.enum(["PLAN", "ACT"]).optional(), modifiedAt: z.string().optional(), projectId: z.string().optional(), status: z.enum(["RUNNING", "STOPPED", "STOPPING", "ERRORED"]).optional(), taskId: z.string().optional()}); export const getTasksResponse = z.object({page: z.number().int().optional(), size: z.number().int().optional(), tasks: z.array(taskSummary).optional(), total: z.number().int().optional()}); 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 AI Agent Tasks * * GET /v1/ai/agents/tasks */ export const getApiV1AiAgentsTasks = async (args: GetApiV1AiAgentsTasksArgs, options?: GetApiV1AiAgentsTasksOptions) => { const {baseUrl = "https://eu1.api.matillion.com/dpc", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.branchId != null) query.append("branchId", String(args.branchId)) if (args.status != null) query.append("status", String(args.status)) if (args.createdAfter != null) query.append("createdAfter", String(args.createdAfter)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ai/agents/tasks${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(getTasksResponse, await res.json()) };