import {z} from 'zod' export type EvaluationStatus = 'running' | 'completed' | 'failed' | 'cancelled'; export type EvaluationTool = 'diamond' | 'promptfoo' | 'garak' | 'pyrit'; export type GetApiV1EvaluationSummariesArgs = {team_id: string, agent_id?: (string | null) | undefined, status?: (EvaluationStatus | null) | undefined, harness_type?: ('standard' | 'custom' | null) | undefined, tested_by?: (EvaluationTool | null) | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiV1EvaluationSummariesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const evaluationSummaryResponse = z.object({id: z.string(), team_id: z.string(), agent_id: z.string(), tested_by: z.string(), status: z.string(), reliability_score: z.number().nullable().optional(), security_score: z.number().nullable().optional(), safety_score: z.number().nullable().optional(), overall_score: z.number().nullable().optional(), pillar_details: z.record(z.string(), z.unknown()).optional(), harness_names: z.array(z.string()).optional(), harness_type: z.string().nullable().optional(), resource_version: z.string().nullable().optional(), created_by: z.string().nullable().optional(), created_at: z.number().int(), completed_at: z.number().int().nullable().optional(), request_params: z.record(z.string(), z.unknown()).nullable().optional()}); export const evaluationSummaryListResponse = z.object({results: z.array(evaluationSummaryResponse), total: z.number().int(), limit: z.number().int(), offset: z.number().int()}); 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 Evaluation Summaries * * GET /v1/evaluation-summaries/ */ export const getApiV1EvaluationSummaries = async (args: GetApiV1EvaluationSummariesArgs, options: GetApiV1EvaluationSummariesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.team_id != null) query.append("team_id", String(args.team_id)) if (args.agent_id != null) query.append("agent_id", String(args.agent_id)) if (args.status != null) query.append("status", String(args.status)) if (args.harness_type != null) query.append("harness_type", String(args.harness_type)) if (args.tested_by != null) query.append("tested_by", String(args.tested_by)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/evaluation-summaries/${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(evaluationSummaryListResponse, await res.json()) };