import {z} from 'zod' export type LunaMappingConfig = {columns: Array, flatten?: boolean | undefined}; export type LunaDatasetMappings = {input?: (LunaMappingConfig | null) | undefined, output?: (LunaMappingConfig | null) | undefined, label?: (LunaMappingConfig | null) | undefined, evaluator_ground_truth?: (LunaMappingConfig | null) | undefined, metadata?: (LunaMappingConfig | null) | undefined, tools?: (LunaMappingConfig | null) | undefined, documents?: (LunaMappingConfig | null) | undefined, mgt?: {[key: string]: LunaMappingConfig} | undefined}; export type LunaSemanticMapping = {source_column: string, target_field: 'input' | 'output' | 'label' | 'evaluator_ground_truth' | 'metadata' | 'tools' | 'documents' | 'generated_output' | 'ground_truth'}; export type LunaDatasetPreviewRequest = {mappings: LunaDatasetMappings | Array}; export type CreateApiPublicV2DatasetsDatasetIdVersionsVersionIndexPreviewArgs = {dataset_id: unknown, version_index: number, limit?: number | undefined, cursor?: (string | null) | undefined, body: LunaDatasetPreviewRequest}; export type CreateApiPublicV2DatasetsDatasetIdVersionsVersionIndexPreviewOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const lunaPreviewDraftRef = z.object({kind: z.literal("draft").optional(), dataset_id: z.string(), draft_revision: z.string()}); export const lunaPreviewVersionRef = z.object({kind: z.literal("version").optional(), dataset_id: z.string(), version_index: z.number().int().gte(1)}); export const pydanticTypesJsonValue = z.unknown(); export const lunaDatasetPreviewColumn = z.object({key: z.string(), label: z.string(), source_columns: z.array(z.string()), source_column: z.string().nullable().optional(), samples: z.array(pydanticTypesJsonValue).optional(), group: z.string().nullable().optional(), scorer_id: z.string().nullable().optional()}); export const lunaDatasetPreviewRow = z.object({row_ref: z.string(), values: z.record(z.string(), pydanticTypesJsonValue), truncated_columns: z.array(z.string()).optional()}); export const lunaDatasetPreview = z.object({dataset: z.discriminatedUnion("kind", [lunaPreviewDraftRef, lunaPreviewVersionRef]), columns: z.array(lunaDatasetPreviewColumn), rows: z.array(lunaDatasetPreviewRow), total_row_count: z.number().int(), column_count: z.number().int(), next_cursor: 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 }; /** * Preview Dataset Version * * POST /public/v2/datasets/{dataset_id}/versions/{version_index}/preview * * Also accepts auth: ClassicAPIKeyHeader, OAuth2PasswordBearer, HTTPBasic */ export const createApiPublicV2DatasetsDatasetIdVersionsVersionIndexPreview = async (args: CreateApiPublicV2DatasetsDatasetIdVersionsVersionIndexPreviewArgs, options?: CreateApiPublicV2DatasetsDatasetIdVersionsVersionIndexPreviewOptions) => { const {baseUrl = "https://api.galileo.ai", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (APIKeyHeader !== undefined) headers.set("Splunk-AO-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/public/v2/datasets/${encodeURIComponent(String(args.dataset_id))}/versions/${encodeURIComponent(String(args.version_index))}/preview${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(lunaDatasetPreview, await res.json()) };