import {z} from 'zod' export type ListsListDocumentsRequest = {corpusId?: number | undefined, numResults?: number | undefined, pageKey?: string | undefined, metadataFilter?: string | undefined}; export type CreateApiV1ListDocumentsArgs = {'customer-id': number, timeout?: string | undefined, body: ListsListDocumentsRequest}; export type CreateApiV1ListDocumentsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const comvectaraAttribute = z.object({name: z.string().optional(), value: z.string().optional()}); export const listDocumentsResponseDocumentInfo = z.object({id: z.string().optional(), metadata: z.array(comvectaraAttribute).optional()}); export const listsListDocumentsResponse = z.object({document: z.array(listDocumentsResponseDocumentInfo).optional(), nextPageKey: z.string().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 }; /** * Lists information about each document ingested into the corpus including the Document ID and metadata. This is useful for managing the lifecycle of documents and a quick way to check which documents are already in the index. * * POST /v1/list-documents * * Also accepts auth: oAuth */ export const createApiV1ListDocuments = async (args: CreateApiV1ListDocumentsArgs, options?: CreateApiV1ListDocumentsOptions) => { const {baseUrl = "https://api.vectara.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['customer-id'] != null) headers.set("customer-id", String(args['customer-id'])) if (args.timeout != null) headers.set("timeout", String(args.timeout)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/list-documents${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(listsListDocumentsResponse, await res.json()) };