import {z} from 'zod' export type GetApiDocumentsV1JobsArgs = {cursor?: string | undefined, limit?: number | undefined, direction?: ('next' | 'prev') | undefined, filename?: string | undefined, job_id?: string | undefined, dataset_name?: string | undefined, status?: ('failure' | 'pending' | 'processing' | 'successful') | undefined, created_after?: string | undefined, created_before?: string | undefined, updated_after?: string | undefined, updated_before?: string | undefined}; export type GetApiDocumentsV1JobsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const jobStatus = z.enum(["failure", "pending", "processing", "successful"]); export const pageJobListItem = z.object({items: z.array(z.object({id: z.string(), status: jobStatus, fileName: z.string().nullable().optional(), fileId: z.string().nullable().optional(), traceId: z.string().nullable().optional(), datasetId: z.string().nullable().optional(), message: z.string().nullable().optional(), pagesParsed: z.number().int().nullable().optional(), createdAt: z.string(), updatedAt: z.string(), finishedAt: z.string().nullable().optional()})), hasMore: z.boolean(), prevCursor: z.string().nullable().optional(), nextCursor: z.string().nullable().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 }; /** * GET /documents/v1/jobs */ export const getApiDocumentsV1Jobs = async (args: GetApiDocumentsV1JobsArgs, options?: GetApiDocumentsV1JobsOptions) => { const {baseUrl = "https://api.tensorlake.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.direction != null) query.append("direction", String(args.direction)) if (args.filename != null) query.append("filename", String(args.filename)) if (args.job_id != null) query.append("job_id", String(args.job_id)) if (args.dataset_name != null) query.append("dataset_name", String(args.dataset_name)) if (args.status != null) query.append("status", String(args.status)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.updated_before != null) query.append("updated_before", String(args.updated_before)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/documents/v1/jobs${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(pageJobListItem, await res.json()) };