import {z} from 'zod' export type GetApiApiV1DatasetsDatasetIdArgs = {dataset_id: string}; export type GetApiApiV1DatasetsDatasetIdOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const publicDatasetColumnMappingDto = z.object({prompt: z.string().nullable(), completion: z.string().nullable(), chat: z.string().nullable(), context: z.array(z.string()), image: z.string().nullable()}); export const publicDatasetEvaluationSummaryDto = z.object({grade_before: z.string().nullable(), grade_after: z.string().nullable(), score_before: z.number().nullable(), score_after: z.number().nullable(), improvement_percent: z.number().nullable()}); export const publicDatasetProgressDto = z.object({percent: z.number().int().nullable(), processed_rows: z.number().int().nullable(), total_rows: z.number().int().nullable()}); export const publicDatasetErrorDataDto = z.object({message: z.string().nullable(), code: z.string().nullable(), level: z.enum(["error", "warning"]).nullable()}); export const publicDatasetDto = z.object({dataset_id: z.string(), kind: z.enum(["uploaded", "combined", "invented", "augmented", "translated", "localized", "extended"]).nullable(), source_dataset_id: z.string().nullable(), name: z.string().nullable(), status: z.enum(["pending", "running", "succeeded", "failed"]), created_at: z.string(), created_by_user_id: z.string().nullable(), updated_at: z.string(), row_count: z.number().int().nullable(), configured_column_mapping: publicDatasetColumnMappingDto.nullable(), evaluation_summary: publicDatasetEvaluationSummaryDto.nullable(), run_id: z.string().nullable(), progress: publicDatasetProgressDto.nullable(), error_data: publicDatasetErrorDataDto.nullable(), image_column_formats: z.record(z.string(), z.enum(["embedded_bytes", "url", "file_reference"])).nullable()}); 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 a dataset by ID * * GET /api/v1/datasets/{dataset_id} */ export const getApiApiV1DatasetsDatasetId = async (args: GetApiApiV1DatasetsDatasetIdArgs, options: GetApiApiV1DatasetsDatasetIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/datasets/${encodeURIComponent(String(args.dataset_id))}${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(publicDatasetDto, await res.json()) };