import {z} from 'zod' export type GetApiApiOrgIdPipelinesHistoryArgs = {org_id: string, pipeline_id?: string | undefined, start_time?: number | undefined, end_time?: number | undefined, from?: number | undefined, size?: number | undefined, sort_by?: string | undefined, sort_order?: string | undefined}; export type GetApiApiOrgIdPipelinesHistoryOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const pipelineHistoryEntry = z.object({delay_in_secs: z.number().int().nullable().optional(), end_time: z.number().int(), error: z.string().nullable().optional(), evaluation_took_in_secs: z.number().nullable().optional(), is_partial: z.boolean().nullable().optional(), is_realtime: z.boolean(), is_silenced: z.boolean(), org: z.string(), pipeline_name: z.string(), query_took: z.number().int().nullable().optional(), retries: z.number().int(), source_node: z.string().nullable().optional(), start_time: z.number().int(), status: z.string(), success_response: z.string().nullable().optional(), timestamp: z.number().int()}); export const pipelineHistoryResponse = z.object({from: z.number().int(), hits: z.array(pipelineHistoryEntry), size: z.number().int(), total: z.number().int().gte(0)}); 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 pipeline execution history * * GET /api/{org_id}/pipelines/history */ export const getApiApiOrgIdPipelinesHistory = async (args: GetApiApiOrgIdPipelinesHistoryArgs, options: GetApiApiOrgIdPipelinesHistoryOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pipeline_id != null) query.append("pipeline_id", String(args.pipeline_id)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.from != null) query.append("from", String(args.from)) if (args.size != null) query.append("size", String(args.size)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/pipelines/history${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(pipelineHistoryResponse, await res.json()) };