import {z} from 'zod' export type GetApiApiPublicV2EvaluationsEvaluationIdRowsArgs = {evaluation_id: number, workspace_id?: number | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiApiPublicV2EvaluationsEvaluationIdRowsOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const datasetRowCell = z.object({type: z.literal("dataset"), value: z.unknown()}); export const evaluationRowCell = z.object({type: z.literal("eval"), status: z.string(), value: z.unknown(), error_message: z.string().nullable().optional()}); export const evaluationRowsResponse = z.object({success: z.literal(true), message: z.string().optional(), columns: z.array(z.string()), page: z.number().int(), per_page: z.number().int(), pages: z.number().int(), total: z.number().int(), rows: z.array(z.array(z.union([datasetRowCell, evaluationRowCell])))}); 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 Evaluation Rows * * GET /api/public/v2/evaluations/{evaluation_id}/rows */ export const getApiApiPublicV2EvaluationsEvaluationIdRows = async (args: GetApiApiPublicV2EvaluationsEvaluationIdRowsArgs, options: GetApiApiPublicV2EvaluationsEvaluationIdRowsOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.workspace_id != null) query.append("workspace_id", String(args.workspace_id)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v2/evaluations/${encodeURIComponent(String(args.evaluation_id))}/rows${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(evaluationRowsResponse, await res.json()) };