import {z} from 'zod' export type CollectionUpdateRequest = {name?: string | undefined, description?: string | undefined, rag_type?: ('auto' | 'llm_only' | 'rag' | 'hyde1' | 'hyde2' | 'rag+' | 'all_data') | undefined}; export type PatchApiCollectionsCollectionIdArgs = {collection_id: string, body: CollectionUpdateRequest}; export type PatchApiCollectionsCollectionIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const metadata = z.record(z.string(), z.unknown()); export const collection = z.object({id: z.string(), name: z.string(), description: z.string(), description_auto_generated: z.boolean().optional(), description_generated_at: z.string().optional(), description_dirty_at: z.string().optional(), description_generation_started_at: z.string().optional(), embedding_model: z.string(), document_count: z.number().int(), document_size: z.number().int(), created_at: z.string(), updated_at: z.string(), user_count: z.number().int(), is_public: z.boolean(), username: z.string(), sessions_count: z.number().int(), status: z.string(), prompt_template_id: z.string().optional(), thumbnail: z.string().optional(), size_limit: z.number().int().optional(), expiry_date: z.string().optional(), inactivity_interval: z.number().int().optional(), rag_type: z.enum(["auto", "llm_only", "rag", "hyde1", "hyde2", "rag+", "all_data"]).optional(), metadata_dict: metadata.optional(), workspace: z.string().optional(), has_default_guardrails: z.boolean().optional(), vex_encryption: z.enum(["enabled", "disabled", "null"]).nullable().optional(), exempt_from_chat_expiry: z.boolean().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 }; /** * Updates attributes of an existing collection. * * PATCH /collections/{collection_id} */ export const patchApiCollectionsCollectionId = async (args: PatchApiCollectionsCollectionIdArgs, options?: PatchApiCollectionsCollectionIdOptions) => { const {baseUrl = "https://h2ogpte.genai.h2o.ai/api/v1", fetch: fetchFn = fetch, bearerAuth} = 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}`) const url = `${baseUrl.replace(/\/+$/, '')}/collections/${encodeURIComponent(String(args.collection_id))}${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(collection, await res.json()) };