import {z} from 'zod' export type GetApiApiV1ConsoleEvalsRunsEvalRunIdArgs = {eval_run_id: string, 'x-api-key'?: (string | null) | undefined}; export type GetApiApiV1ConsoleEvalsRunsEvalRunIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const evalRunParams = z.object({sample_ids: z.array(z.string()).optional(), layer: z.string().nullable().optional(), tags: z.array(z.string()).optional(), k_override: z.number().int().gte(1).lte(10).nullable().optional(), judge_model: z.string().nullable().optional(), use_judge: z.boolean().optional(), timeout_seconds: z.number().gt(0).nullable().optional(), max_concurrent_samples: z.number().int().gte(1).lte(16).optional()}); export const evalRun = z.object({eval_run_id: z.string(), status: z.string(), name: z.string().nullable().optional(), created_by_email: z.string().nullable().optional(), params: evalRunParams, workflow_id: z.string().nullable().optional(), samples_total: z.number().int(), samples_passed: z.number().int(), samples_failed: z.number().int(), error: z.string().nullable().optional(), created_at: z.string(), started_at: z.string().nullable().optional(), finished_at: 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 Eval Run * * GET /api/v1/console/evals/runs/{eval_run_id} */ export const getApiApiV1ConsoleEvalsRunsEvalRunId = async (args: GetApiApiV1ConsoleEvalsRunsEvalRunIdArgs, options: GetApiApiV1ConsoleEvalsRunsEvalRunIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/console/evals/runs/${encodeURIComponent(String(args.eval_run_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(evalRun, await res.json()) };