import {z} from 'zod' export type StageType = 'filter' | 'sort' | 'reduce' | 'apply' | 'enrich'; export type StageConfigInput = {stage_name: string, stage_type?: (StageType | null) | undefined, config: {[key: string]: unknown}, batch_size?: (string | null) | undefined, description?: (string | null) | undefined, on_error?: (string | null) | undefined, output_alias?: (string | null) | undefined}; export type RetrieverInputSchemaFieldType = 'string' | 'number' | 'integer' | 'float' | 'boolean' | 'object' | 'array' | 'date' | 'datetime' | 'text' | 'image' | 'audio' | 'video' | 'pdf' | 'excel' | 'document_reference'; export type RetrieverInputSchemaFieldInput = {type: RetrieverInputSchemaFieldType, default: unknown, items?: (RetrieverInputSchemaFieldInput | null) | undefined, properties?: ({[key: string]: RetrieverInputSchemaFieldInput} | null) | undefined, examples?: (Array | null) | undefined, description?: (string | null) | undefined, enum?: (Array | null) | undefined, required?: (boolean | null) | undefined} | {[key: string]: unknown}; export type BudgetLimits = {max_credits?: (number | null) | undefined, max_time_ms?: (number | null) | undefined}; export type StructuredDataConfig = {type?: string | undefined, additional_properties?: {[key: string]: unknown} | undefined}; export type SEOConfig = {meta_title?: (string | null) | undefined, meta_description?: (string | null) | undefined, keywords?: Array | undefined, og_image_url?: (string | null) | undefined, og_image_alt?: (string | null) | undefined, og_type?: string | undefined, twitter_card?: string | undefined, twitter_site?: (string | null) | undefined, twitter_creator?: (string | null) | undefined, robots?: string | undefined, canonical_url?: (string | null) | undefined, site_name?: string | undefined, author?: (string | null) | undefined, locale?: string | undefined, logo_url?: (string | null) | undefined, favicon_url?: (string | null) | undefined, structured_data?: StructuredDataConfig | undefined}; export type MarkdownContent = {title: string, content: string}; export type ThemeConfig = {primary_color?: string | undefined, secondary_color?: (string | null) | undefined, font_family?: string | undefined, background_color?: string | undefined, text_color?: string | undefined, heading_font_family?: (string | null) | undefined, surface_color?: (string | null) | undefined, muted_color?: (string | null) | undefined, border_color?: (string | null) | undefined, border_radius?: (string | null) | undefined, card_style?: (string | null) | undefined, card_hover_effect?: (string | null) | undefined}; export type InputRenderingConfigInput = {field_name: string, field_schema: RetrieverInputSchemaFieldInput, input_type?: string | undefined, label: string, placeholder?: (string | null) | undefined, helper_text?: (string | null) | undefined, suggestions?: (Array | null) | undefined, required?: boolean | undefined, order?: number | undefined}; export type LayoutConfig = {mode?: string | undefined, columns?: number | undefined, gap?: string | undefined, full_width?: boolean | undefined}; export type ResultCardProperties = {layout?: string | undefined, show_thumbnail?: boolean | undefined, thumbnail_aspect_ratio?: string | undefined, thumbnail_fit?: string | undefined, show_score?: boolean | undefined, truncate_title?: (number | null) | undefined, truncate_description?: (number | null) | undefined, field_order?: Array | undefined, show_find_similar?: boolean | undefined, card_click_action?: string | undefined, thumbnail_field?: (string | null) | undefined, title_field?: (string | null) | undefined, card_fields?: (Array | null) | undefined, modal_fields?: (Array | null) | undefined, card_style?: (string | null) | undefined}; export type ComponentsConfig = {show_hero?: boolean | undefined, show_search?: boolean | undefined, show_filters?: boolean | undefined, show_results_header?: boolean | undefined, result_layout?: string | undefined, result_card?: (ResultCardProperties | null) | undefined}; export type FieldFormatType = 'text' | 'image' | 'date' | 'number' | 'url' | 'boolean' | 'array' | 'object'; export type FieldFormatOptions = {label?: (string | null) | undefined, show_empty?: boolean | undefined, truncate_chars?: (number | null) | undefined, width?: (number | null) | undefined, height?: (number | null) | undefined, lazy_load?: boolean | undefined, aspect_ratio?: (string | null) | undefined, object_fit?: string | undefined, date_format?: string | undefined, decimals?: (number | null) | undefined, prefix?: (string | null) | undefined, suffix?: (string | null) | undefined, open_in_new_tab?: boolean | undefined, show_domain?: boolean | undefined, true_label?: string | undefined, false_label?: string | undefined, separator?: string | undefined, max_items?: (number | null) | undefined}; export type FieldConfig = {format: FieldFormatType, format_options?: FieldFormatOptions | undefined}; export type CustomCTA = {label: string, markdown_content: string}; export type ExternalLink = {name: string, url: string}; export type DisplayConfigInput = {title: string, description?: (string | null) | undefined, logo_url?: (string | null) | undefined, icon_base64?: (string | null) | undefined, seo?: (SEOConfig | null) | undefined, markdowns?: Array | undefined, theme?: ThemeConfig | undefined, inputs: Array, layout?: LayoutConfig | undefined, exposed_fields: Array, components?: ComponentsConfig | undefined, field_config?: {[key: string]: FieldConfig} | undefined, custom_cta?: (CustomCTA | null) | undefined, external_links?: Array | undefined, template_type?: (string | null) | undefined, field_mappings?: ({[key: string]: string} | null) | undefined, extensions?: ({[key: string]: unknown} | null) | undefined, retriever_config?: ({[key: string]: unknown} | null) | undefined} | {[key: string]: unknown}; export type CloneRetrieverRequest = {retriever_name: string, description?: (string | null) | undefined, collection_identifiers?: (Array | null) | undefined, stages?: (Array | null) | undefined, input_schema?: ({[key: string]: RetrieverInputSchemaFieldInput} | null) | undefined, budget_limits?: (BudgetLimits | null) | undefined, tags?: (Array | null) | undefined, display_config?: (DisplayConfigInput | null) | undefined}; export type CreateApiV1RetrieversRetrieverIdCloneArgs = {retriever_id: string, body: CloneRetrieverRequest}; export type CreateApiV1RetrieversRetrieverIdCloneOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, NamespaceHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const stageType = z.enum(["filter", "sort", "reduce", "apply", "enrich"]); export const stageConfigOutput = z.object({stage_name: z.string().min(1), stage_type: stageType.nullable().optional(), config: z.record(z.string(), z.unknown()), batch_size: z.string().nullable().optional(), description: z.string().nullable().optional(), on_error: z.string().nullable().optional(), output_alias: z.string().nullable().optional(), parameters: z.record(z.string(), z.unknown())}); export const retrieverInputSchemaFieldType = z.enum(["string", "number", "integer", "float", "boolean", "object", "array", "date", "datetime", "text", "image", "audio", "video", "pdf", "excel", "document_reference"]); export const retrieverInputSchemaFieldOutput: z.ZodType = z.object({type: retrieverInputSchemaFieldType, default: z.unknown(), items: z.lazy(() => retrieverInputSchemaFieldOutput.nullable().optional()), properties: z.record(z.string(), z.lazy(() => retrieverInputSchemaFieldOutput)).nullable().optional(), examples: z.array(z.unknown()).nullable().optional(), description: z.string().nullable().optional(), enum: z.array(z.unknown()).nullable().optional(), required: z.boolean().nullable().optional()}).and(z.record(z.string(), z.unknown())); export const budgetLimits = z.object({max_credits: z.number().gte(0).nullable().optional(), max_time_ms: z.number().int().gte(0).nullable().optional()}); export const featureAddress = z.object({scheme: z.string().optional(), extractor: z.string(), version: z.string(), output: z.string().nullable().optional()}); export const retrieverConfig = z.object({retriever_id: z.string().optional(), retriever_name: z.string().min(1), description: z.string().nullable().optional(), collection_ids: z.array(z.string()).optional(), stages: z.array(stageConfigOutput), input_schema: z.record(z.string(), retrieverInputSchemaFieldOutput).optional(), budget_limits: budgetLimits.optional(), feature_dependencies: z.array(featureAddress).nullable().optional(), tags: z.array(z.string()).optional(), metadata: z.record(z.string(), z.unknown()).optional(), display_config: z.record(z.string(), z.unknown()).nullable().optional(), version: z.number().int().gte(1).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), created_by: z.string().nullable().optional(), updated_by: z.string().nullable().optional(), fusion: z.string().nullable(), collection_identifiers: z.array(z.string())}); export const cloneRetrieverResponse = z.object({retriever: retrieverConfig, source_retriever_id: z.string()}); 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 }; /** * Clone Retriever * * POST /v1/retrievers/{retriever_id}/clone */ export const createApiV1RetrieversRetrieverIdClone = async (args: CreateApiV1RetrieversRetrieverIdCloneArgs, options?: CreateApiV1RetrieversRetrieverIdCloneOptions) => { 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 (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))}/clone${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(cloneRetrieverResponse, await res.json()) };