import {z} from 'zod' export type GetApiApiV1VaultProjectsProjectIdFilesArgs = {project_id: string, cursor?: string | undefined, limit?: number | undefined, name?: string | undefined, content_type?: Array | undefined, processing_status?: (Array<'UPLOADED' | 'PROCESSING' | 'READY_TO_QUERY' | 'READY_TO_REVIEW' | 'RECOVERABLE_FAILURE' | 'UNRECOVERABLE_FAILURE'>) | undefined, uploaded_after?: number | undefined, uploaded_before?: number | undefined, sort_by?: ('name' | 'uploaded_at' | 'size') | undefined, sort_order?: ('asc' | 'desc') | undefined}; export type GetApiApiV1VaultProjectsProjectIdFilesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const projectFile = z.object({id: z.string(), name: z.string(), content_type: z.string().nullable().optional(), processing_status: z.enum(["UPLOADED", "PROCESSING", "READY_TO_QUERY", "READY_TO_REVIEW", "RECOVERABLE_FAILURE", "UNRECOVERABLE_FAILURE"]), size: z.number().int(), uploaded_at: z.number().int()}); export const projectFilesPagination = z.object({page_size: z.number().int(), has_more: z.boolean(), next_cursor: z.string().nullable().optional(), total_count: z.number().int()}); export const getApiApiV1VaultProjectsProjectIdFilesResponse = z.object({response: z.object({content: z.object({files: z.array(projectFile).optional(), pagination: projectFilesPagination.optional()}).optional()}).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 }; /** * List Files in a Vault Project * * GET /api/v1/vault/projects/{project_id}/files */ export const getApiApiV1VaultProjectsProjectIdFiles = async (args: GetApiApiV1VaultProjectsProjectIdFilesArgs, options?: GetApiApiV1VaultProjectsProjectIdFilesOptions) => { const {baseUrl = "https://api.harvey.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.name != null) query.append("name", String(args.name)) for (const item of args.content_type ?? []) query.append("content_type", String(item)) for (const item of args.processing_status ?? []) query.append("processing_status", String(item)) if (args.uploaded_after != null) query.append("uploaded_after", String(args.uploaded_after)) if (args.uploaded_before != null) query.append("uploaded_before", String(args.uploaded_before)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/vault/projects/${encodeURIComponent(String(args.project_id))}/files${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1VaultProjectsProjectIdFilesResponse, await res.json()) };