import {z} from 'zod' export type ListExecutionsRequest = {filters?: ({[key: string]: unknown} | null) | undefined, sorts?: (Array<{[key: string]: unknown}> | null) | undefined, status?: (string | null) | undefined}; export type CreateApiV1RetrieversRetrieverIdExecutionsListArgs = {retriever_id: string, limit?: (number | null) | undefined, page_size?: (number | null) | undefined, offset?: (number | null) | undefined, page?: (number | null) | undefined, cursor?: (string | null) | undefined, next_cursor?: (string | null) | undefined, after?: (string | null) | undefined, include_total?: boolean | undefined, body: ListExecutionsRequest}; export type CreateApiV1RetrieversRetrieverIdExecutionsListOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, NamespaceHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const retrieverExecutionSummary = z.object({execution_id: z.string(), status: z.string(), created_at: z.string(), completed_at: z.string().nullable().optional(), duration_ms: z.number().gte(0), credits_used: z.number().gte(0), total_processed: z.number().int().gte(0), total_returned: z.number().int().gte(0), cache_hit_rate: z.number().gte(0).lte(1).nullable().optional(), inputs_hash: z.string().nullable().optional(), query_summary: z.string().nullable().optional(), trace_id: z.string().nullable().optional()}); export const paginationMetadata = z.object({total: z.number().int().gte(0), limit: z.number().int().gte(0), offset: z.number().int().gte(0), has_next: z.boolean()}); export const listExecutionsResponse = z.object({results: z.array(retrieverExecutionSummary).optional(), pagination: paginationMetadata}); 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 Executions * * POST /v1/retrievers/{retriever_id}/executions/list */ export const createApiV1RetrieversRetrieverIdExecutionsList = async (args: CreateApiV1RetrieversRetrieverIdExecutionsListArgs, options?: CreateApiV1RetrieversRetrieverIdExecutionsListOptions) => { const {baseUrl = "https://api.mixpeek.com", fetch: fetchFn = fetch, BearerAuth, NamespaceHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.page != null) query.append("page", String(args.page)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.next_cursor != null) query.append("next_cursor", String(args.next_cursor)) if (args.after != null) query.append("after", String(args.after)) if (args.include_total != null) query.append("include_total", String(args.include_total)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) if (NamespaceHeader !== undefined) headers.set("X-Namespace", NamespaceHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/retrievers/${encodeURIComponent(String(args.retriever_id))}/executions/list${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(listExecutionsResponse, await res.json()) };