import {z} from 'zod' export type ExperimentResultRowSortBody = 'dataset' | 'dispersion_desc'; export type GetApiApiOrgIdExperimentsExperimentIdRowsArgs = {org_id: string, experiment_id: string, page?: number | undefined, pageSize?: number | undefined, sort?: ExperimentResultRowSortBody | undefined, highDispersionOnly?: boolean | undefined}; export type GetApiApiOrgIdExperimentsExperimentIdRowsOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const experimentResultRowPaginationBody = z.object({hasMore: z.boolean(), page: z.number().int().gte(0), pageSize: z.number().int().gte(0), totalRows: z.number().int().gte(0)}); export const experimentDimensionDispersionBody = z.object({consensus: z.unknown(), normalized: z.number().nullable().optional(), outlierTrialIndex: z.number().int().gte(0).nullable().optional(), rawStd: z.number().nullable().optional(), scorerId: z.string(), scorerVersion: z.number().int(), trialCount: z.number().int().gte(0)}); export const experimentRowDispersionBody = z.object({dimensions: z.array(experimentDimensionDispersionBody), high: z.boolean(), logicalId: z.string(), maxNormalized: z.number().nullable().optional(), outlierTrialIndex: z.number().int().gte(0).nullable().optional(), rowId: z.string()}); export const experimentScoreOutcomesBody = z.object({completed: z.number().int().gte(0), failed: z.number().int().gte(0), pending: z.number().int().gte(0), scored: z.number().int().gte(0), skipped: z.number().int().gte(0), total: z.number().int().gte(0), unscored: z.number().int().gte(0)}); export const experimentScoreSummaryBody = z.object({errorCount: z.number().int().gte(0), name: z.string(), noReferenceCount: z.number().int().gte(0), noTraceCount: z.number().int().gte(0), pendingCount: z.number().int().gte(0), sampleCount: z.number().int().gte(0), scoreConfigId: z.string().nullable().optional(), scoreConfigName: z.string().nullable().optional(), scoreConfigVersion: z.number().int().nullable().optional(), scorerId: z.string(), scorerVersion: z.number().int(), skippedCount: z.number().int().gte(0), value: z.unknown()}); export const experimentSlotStatusBody = z.enum(["pending", "running", "scoring", "completed", "skipped", "task_failed", "score_failed"]); export const experimentTaskOutcomesBody = z.object({failed: z.number().int().gte(0), pending: z.number().int().gte(0), skipped: z.number().int().gte(0), succeeded: z.number().int().gte(0), total: z.number().int().gte(0)}); export const experimentResultRowBody = z.object({dispersion: experimentRowDispersionBody.nullable().optional(), errorMessage: z.string().nullable().optional(), expectedOutput: z.unknown(), input: z.unknown(), logicalId: z.string(), output: z.unknown(), p50LatencyMs: z.number().int().gte(0).nullable().optional(), rowId: z.string(), rowIndex: z.number().int().gte(0), scoreOutcomes: experimentScoreOutcomesBody, scoreSummaries: z.array(experimentScoreSummaryBody), status: experimentSlotStatusBody, taskOutcomes: experimentTaskOutcomesBody, trialCount: z.number().int().gte(0)}); export const experimentResultRowPageResponseBody = z.object({pagination: experimentResultRowPaginationBody, rows: z.array(experimentResultRowBody)}); 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 pinned Dataset cases with trial-level evidence reduced to row aggregates. * * GET /api/{org_id}/experiments/{experiment_id}/rows */ export const getApiApiOrgIdExperimentsExperimentIdRows = async (args: GetApiApiOrgIdExperimentsExperimentIdRowsArgs, options: GetApiApiOrgIdExperimentsExperimentIdRowsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.highDispersionOnly != null) query.append("highDispersionOnly", String(args.highDispersionOnly)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/experiments/${encodeURIComponent(String(args.experiment_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(experimentResultRowPageResponseBody, await res.json()) };