import {z} from 'zod' export type OffsetPaginationParams = {method?: 'offset' | undefined, page_size?: number | undefined, page_number?: number | undefined}; export type CursorPaginationParams = {method?: 'cursor' | undefined, limit?: number | undefined, cursor?: (string | null) | undefined}; export type ScrollPaginationParams = {method?: 'scroll' | undefined, limit?: number | undefined, scroll_id?: (string | null) | undefined, scroll_ttl?: number | undefined}; export type KeysetPaginationParams = {method?: 'keyset' | undefined, limit?: number | undefined, after?: ({[key: string]: unknown} | null) | undefined}; export type ReadConsistencyOption = {mode: 'strong' | 'eventual', max_staleness_ms?: (number | null) | undefined}; export type RetrieverExecutionRequest = {inputs?: {[key: string]: unknown} | undefined, filters?: ({[key: string]: unknown} | null) | undefined, pagination?: (OffsetPaginationParams | CursorPaginationParams | ScrollPaginationParams | KeysetPaginationParams) | undefined, limit?: (number | null) | undefined, stream?: boolean | undefined, expand?: (Array | null) | undefined, skip_cache?: boolean | undefined, return_presigned_urls?: boolean | undefined, return_vectors?: boolean | undefined, write_token?: (string | null) | undefined, consistency?: (ReadConsistencyOption | null) | undefined}; export type CreateApiV1PublicRetrieversPublicNameExecuteArgs = {public_name: string, return_presigned_urls?: boolean | undefined, 'X-Public-API-Key'?: (string | null) | undefined, 'X-Retriever-Password'?: (string | null) | undefined, body: RetrieverExecutionRequest}; export type CreateApiV1PublicRetrieversPublicNameExecuteOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1PublicRetrieversPublicNameExecuteResponse = z.unknown(); 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 }; /** * Execute Public Retriever * * POST /v1/public/retrievers/{public_name}/execute */ export const createApiV1PublicRetrieversPublicNameExecute = async (args: CreateApiV1PublicRetrieversPublicNameExecuteArgs, options?: CreateApiV1PublicRetrieversPublicNameExecuteOptions) => { const {baseUrl = "https://api.mixpeek.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.return_presigned_urls != null) query.append("return_presigned_urls", String(args.return_presigned_urls)) if (args['X-Public-API-Key'] != null) headers.set("X-Public-API-Key", String(args['X-Public-API-Key'])) if (args['X-Retriever-Password'] != null) headers.set("X-Retriever-Password", String(args['X-Retriever-Password'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/public/retrievers/${encodeURIComponent(String(args.public_name))}/execute${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(createApiV1PublicRetrieversPublicNameExecuteResponse, await res.json()) };