import {z} from 'zod' export type GetApiV1RetrieversRetrieverIdExecutionsExecutionIdArgs = {retriever_id: string, execution_id: string}; export type GetApiV1RetrieversRetrieverIdExecutionsExecutionIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, NamespaceHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const degradedEntry = z.object({resource: z.string(), id: z.string().nullable().optional(), reason: z.string(), next_step: z.string(), stage: z.string().nullable().optional()}); export const limitEntry = z.object({name: z.string(), requested: z.number().int(), applied: z.number().int(), ceiling: z.number().int(), stage: z.string().nullable().optional()}); export const stageStatistics = z.object({input_count: z.number().int().gte(0), output_count: z.number().int().gte(0), duration_ms: z.number().gte(0), efficiency: z.number().gte(0), cache_hit: z.boolean().nullable().optional(), stage_cache_hit: z.boolean().nullable().optional(), cached_at: z.number().nullable().optional(), error: z.string().nullable().optional(), llm_calls: z.number().int().gte(0).nullable().optional(), tokens_used: z.number().int().gte(0).nullable().optional(), metadata: z.record(z.string(), z.unknown()).optional()}); export const retrieverExecutionStatistics = z.object({stages: z.record(z.string(), stageStatistics).optional(), total_time_ms: z.number().gte(0).optional(), credits_used: z.number().gte(0).optional(), server_service_ms: z.number().gte(0).nullable().optional()}); export const executionDetail = z.object({retriever_id: z.string().optional(), execution_id: z.string(), status: z.string(), degraded: z.array(degradedEntry).optional(), limits: z.array(limitEntry).nullable().optional(), documents: z.array(z.record(z.string(), z.unknown())).optional(), results: z.array(z.record(z.string(), z.unknown())).optional(), pagination: z.record(z.string(), z.unknown()).optional(), stage_statistics: retrieverExecutionStatistics.optional(), facets: z.array(z.record(z.string(), z.unknown())).nullable().optional(), budget: z.record(z.string(), z.unknown()).optional(), cached_at: z.number().nullable().optional(), completeness: z.record(z.string(), z.string()).nullable().optional(), warnings: z.array(z.string()).optional(), interpretation: z.record(z.string(), z.unknown()).nullable().optional(), error: z.string().nullable().optional(), optimization_applied: z.boolean().optional(), optimization_summary: z.record(z.string(), z.unknown()).nullable().optional(), learned_fusion_context: z.record(z.string(), z.unknown()).nullable().optional(), created_at: z.string().optional(), completed_at: z.string().nullable().optional(), current_stage: z.string().nullable().optional(), stages_completed: z.number().int().gte(0).optional(), total_stages: z.number().int().gte(0).optional(), documents_retained: z.boolean().optional(), total_returned: z.number().int().nullable().optional(), trace_id: z.string().nullable().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 }; /** * Get Execution * * GET /v1/retrievers/{retriever_id}/executions/{execution_id} */ export const getApiV1RetrieversRetrieverIdExecutionsExecutionId = async (args: GetApiV1RetrieversRetrieverIdExecutionsExecutionIdArgs, options?: GetApiV1RetrieversRetrieverIdExecutionsExecutionIdOptions) => { const {baseUrl = "https://api.mixpeek.com", fetch: fetchFn = fetch, BearerAuth, NamespaceHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") 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/${encodeURIComponent(String(args.execution_id))}${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(executionDetail, await res.json()) };