import {z} from 'zod' export type IngestionStatus = 'discovered' | 'queued' | 'ingesting' | 'ingested' | 'stale' | 'expired' | 'failed' | 'not_required'; export type GetApiV1WorkspacesWorkspaceIdFilesArgs = {workspace_id: string, path_prefix?: (string | null) | undefined, ingestion_status?: (Array | null) | undefined, categories?: (Array | null) | undefined, file_types?: (Array | null) | undefined, modified_after?: (string | null) | undefined, modified_before?: (string | null) | undefined, cursor?: (string | null) | undefined, limit?: number | undefined}; export type GetApiV1WorkspacesWorkspaceIdFilesOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const coverage = z.object({labels_required: z.array(z.string()).optional(), request_access_hint: z.string().nullable().optional(), restricted_candidates: z.number().int().optional()}); export const accessLabelSource = z.enum(["inherited", "classified", "mirrored"]); export const ingestionStatus = z.enum(["discovered", "queued", "ingesting", "ingested", "stale", "expired", "failed", "not_required"]); export const file = z.object({access_label: z.string().nullable().optional(), access_label_source: accessLabelSource.nullable().optional(), category: z.string().nullable().optional(), created_at: z.string(), expires_at: z.string().nullable().optional(), file_id: z.string(), file_name: z.string(), file_type: z.string(), graph_inclusion: z.enum(["auto", "include", "exclude"]).optional(), ingested_at: z.string().nullable().optional(), ingested_hash: z.string().nullable().optional(), ingestion_status: ingestionStatus, labels: z.record(z.string(), z.string()).optional(), observed_hash: z.string(), path: z.string(), size_bytes: z.number().int(), updated_at: z.string(), version: z.number().int(), workspace_id: z.string()}); export const fileListPage = z.object({coverage: coverage.optional(), items: z.array(file), next_cursor: z.string().nullable().optional(), total_count: z.number().int()}); 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 * * GET /v1/workspaces/{workspace_id}/files */ export const getApiV1WorkspacesWorkspaceIdFiles = async (args: GetApiV1WorkspacesWorkspaceIdFilesArgs, options?: GetApiV1WorkspacesWorkspaceIdFilesOptions) => { const {baseUrl = "https://ndi-api.nace.ai", fetch: fetchFn = fetch, APIKeyHeader} = 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.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.workspace_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(fileListPage, await res.json()) };