import {z} from 'zod' export type GetApiV1WorkspacesIdFilesArgs = {id: string, path_prefix?: string | undefined, ingestion_status?: (Array<'discovered' | 'queued' | 'ingesting' | 'ingested' | 'stale' | 'expired' | 'failed' | 'not_required'>) | undefined, categories?: Array | undefined, file_types?: Array | undefined, modified_after?: string | undefined, modified_before?: string | undefined, limit?: number | undefined, cursor?: string | undefined}; export type GetApiV1WorkspacesIdFilesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const workspaceFile = z.object({file_id: z.string(), workspace_id: z.string(), path: z.string(), file_name: z.string().optional(), file_type: z.string().optional(), size_bytes: z.number().int().optional(), version: z.number().int().optional(), observed_hash: z.string().nullable().optional(), ingested_hash: z.string().nullable().optional(), ingestion_status: z.enum(["discovered", "queued", "ingesting", "ingested", "stale", "expired", "failed", "not_required"]).optional(), ingested_at: z.string().nullable().optional(), category: z.string().nullable().optional(), access_label: z.string().nullable().optional(), access_label_source: z.string().nullable().optional(), graph_inclusion: z.enum(["auto", "include", "exclude"]).optional(), expires_at: z.string().nullable().optional(), labels: z.record(z.string(), z.string()).optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).and(z.record(z.string(), z.unknown())); export const workspaceFileList = z.object({items: z.array(workspaceFile), next_cursor: z.string().nullable(), total_count: z.number().int().nullable().optional(), coverage: z.record(z.string(), z.unknown()).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 workspace files * * GET /v1/workspaces/{id}/files */ export const getApiV1WorkspacesIdFiles = async (args: GetApiV1WorkspacesIdFilesArgs, options?: GetApiV1WorkspacesIdFilesOptions) => { const {baseUrl = "https://console.nace.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.path_prefix != null) query.append("path_prefix", String(args.path_prefix)) for (const item of args.ingestion_status ?? []) query.append("ingestion_status", String(item)) for (const item of args.categories ?? []) query.append("categories", String(item)) for (const item of args.file_types ?? []) query.append("file_types", String(item)) if (args.modified_after != null) query.append("modified_after", String(args.modified_after)) if (args.modified_before != null) query.append("modified_before", String(args.modified_before)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.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(workspaceFileList, await res.json()) };