import {z} from 'zod' 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 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 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 RateLimitTier = 'standard' | 'elevated' | 'enterprise' | 'unlimited'; export type RateLimitConfig = {enabled?: boolean | undefined, tier?: RateLimitTier | undefined, requests_per_minute?: (number | null) | undefined, requests_per_hour?: (number | null) | undefined, requests_per_day?: (number | null) | undefined, max_results_per_query?: number | undefined, enable_ip_limits?: boolean | undefined, max_requests_per_ip_hour?: (number | null) | undefined}; export type UpdatePublishedRetrieverRequest = {display_config?: (DisplayConfigInput | null) | undefined, rate_limit_config?: (RateLimitConfig | null) | undefined, password_secret_name?: (string | null) | undefined, is_active?: (boolean | null) | undefined, tags?: (Array | null) | undefined, category?: (string | null) | undefined}; export type PatchApiV1RetrieversRetrieverIdPublishArgs = {retriever_id: string, body: UpdatePublishedRetrieverRequest}; export type PatchApiV1RetrieversRetrieverIdPublishOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, NamespaceHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const structuredDataConfig = z.object({type: z.string().optional(), additional_properties: z.record(z.string(), z.unknown()).optional()}); export const sEOConfig = z.object({meta_title: z.string().max(60).nullable().optional(), meta_description: z.string().max(160).nullable().optional(), keywords: z.array(z.string()).optional(), og_image_url: z.string().nullable().optional(), og_image_alt: z.string().max(200).nullable().optional(), og_type: z.string().optional(), twitter_card: z.string().optional(), twitter_site: z.string().nullable().optional(), twitter_creator: z.string().nullable().optional(), robots: z.string().optional(), canonical_url: z.string().nullable().optional(), site_name: z.string().optional(), author: z.string().nullable().optional(), locale: z.string().optional(), logo_url: z.string().nullable().optional(), favicon_url: z.string().nullable().optional(), structured_data: structuredDataConfig.optional()}); export const markdownContent = z.object({title: z.string().min(1).max(200), content: z.string().min(1).max(50000)}); export const themeConfig = z.object({primary_color: z.string().optional(), secondary_color: z.string().nullable().optional(), font_family: z.string().optional(), background_color: z.string().optional(), text_color: z.string().optional(), heading_font_family: z.string().nullable().optional(), surface_color: z.string().nullable().optional(), muted_color: z.string().nullable().optional(), border_color: z.string().nullable().optional(), border_radius: z.string().nullable().optional(), card_style: z.string().nullable().optional(), card_hover_effect: z.string().nullable().optional()}); 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 inputRenderingConfigOutput = z.object({field_name: z.string(), field_schema: retrieverInputSchemaFieldOutput, input_type: z.string().optional(), label: z.string(), placeholder: z.string().nullable().optional(), helper_text: z.string().nullable().optional(), suggestions: z.array(z.string()).nullable().optional(), required: z.boolean().optional(), order: z.number().int().gte(0).optional()}); export const layoutConfig = z.object({mode: z.string().optional(), columns: z.number().int().gte(1).lte(6).optional(), gap: z.string().optional(), full_width: z.boolean().optional()}); export const resultCardProperties = z.object({layout: z.string().optional(), show_thumbnail: z.boolean().optional(), thumbnail_aspect_ratio: z.string().optional(), thumbnail_fit: z.string().optional(), show_score: z.boolean().optional(), truncate_title: z.number().int().gte(1).nullable().optional(), truncate_description: z.number().int().gte(1).nullable().optional(), field_order: z.array(z.string()).optional(), show_find_similar: z.boolean().optional(), card_click_action: z.string().optional(), thumbnail_field: z.string().nullable().optional(), title_field: z.string().nullable().optional(), card_fields: z.array(z.string()).nullable().optional(), modal_fields: z.array(z.string()).nullable().optional(), card_style: z.string().nullable().optional()}); export const componentsConfig = z.object({show_hero: z.boolean().optional(), show_search: z.boolean().optional(), show_filters: z.boolean().optional(), show_results_header: z.boolean().optional(), result_layout: z.string().optional(), result_card: resultCardProperties.nullable().optional()}); export const fieldFormatType = z.enum(["text", "image", "date", "number", "url", "boolean", "array", "object"]); export const fieldFormatOptions = z.object({label: z.string().nullable().optional(), show_empty: z.boolean().optional(), truncate_chars: z.number().int().gte(1).nullable().optional(), width: z.number().int().gte(1).nullable().optional(), height: z.number().int().gte(1).nullable().optional(), lazy_load: z.boolean().optional(), aspect_ratio: z.string().nullable().optional(), object_fit: z.string().optional(), date_format: z.string().optional(), decimals: z.number().int().gte(0).nullable().optional(), prefix: z.string().nullable().optional(), suffix: z.string().nullable().optional(), open_in_new_tab: z.boolean().optional(), show_domain: z.boolean().optional(), true_label: z.string().optional(), false_label: z.string().optional(), separator: z.string().optional(), max_items: z.number().int().gte(1).nullable().optional()}); export const fieldConfig = z.object({format: fieldFormatType, format_options: fieldFormatOptions.optional()}); export const customCTA = z.object({label: z.string().min(1).max(50), markdown_content: z.string().min(1).max(50000)}); export const externalLink = z.object({name: z.string().min(1).max(100), url: z.string().min(1).max(2048)}); export const displayConfigOutput = z.object({title: z.string(), description: z.string().nullable().optional(), logo_url: z.string().nullable().optional(), icon_base64: z.string().max(300000).nullable().optional(), seo: sEOConfig.nullable().optional(), markdowns: z.array(markdownContent).optional(), theme: themeConfig.optional(), inputs: z.array(inputRenderingConfigOutput), layout: layoutConfig.optional(), exposed_fields: z.array(z.string()), components: componentsConfig.optional(), field_config: z.record(z.string(), fieldConfig).optional(), custom_cta: customCTA.nullable().optional(), external_links: z.array(externalLink).optional(), template_type: z.string().nullable().optional(), field_mappings: z.record(z.string(), z.string()).nullable().optional(), extensions: z.record(z.string(), z.unknown()).nullable().optional(), retriever_config: z.record(z.string(), z.unknown()).nullable().optional()}).and(z.record(z.string(), z.unknown())); export const rateLimitTier = z.enum(["standard", "elevated", "enterprise", "unlimited"]); export const rateLimitConfig = z.object({enabled: z.boolean().optional(), tier: rateLimitTier.optional(), requests_per_minute: z.number().int().gte(1).nullable().optional(), requests_per_hour: z.number().int().gte(1).nullable().optional(), requests_per_day: z.number().int().gte(1).nullable().optional(), max_results_per_query: z.number().int().gte(1).lte(1000).optional(), enable_ip_limits: z.boolean().optional(), max_requests_per_ip_hour: z.number().int().gte(1).nullable().optional()}); export const retrieverMetadata = z.object({stages: z.array(z.record(z.string(), z.unknown())).optional(), collections: z.array(z.record(z.string(), z.unknown())).optional(), capabilities: z.record(z.string(), z.unknown()).optional()}); export const publishedRetrieverResponse = z.object({retriever_id: z.string(), public_id: z.string(), public_name: z.string(), description: z.string().nullable().optional(), icon_base64: z.string().nullable().optional(), public_api_key: z.string().nullable().optional(), display_config: displayConfigOutput, rate_limit_config: rateLimitConfig, password_protected: z.boolean(), is_active: z.boolean(), retriever_metadata: retrieverMetadata.nullable().optional(), tags: z.array(z.string()).optional(), category: z.string().nullable().optional(), created_at: z.string(), updated_at: 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 }; /** * Update Published Retriever * * PATCH /v1/retrievers/{retriever_id}/publish */ export const patchApiV1RetrieversRetrieverIdPublish = async (args: PatchApiV1RetrieversRetrieverIdPublishArgs, options?: PatchApiV1RetrieversRetrieverIdPublishOptions) => { 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))}/publish${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(publishedRetrieverResponse, await res.json()) };