import {z} from 'zod' export type GetApiApiPublicV2EvaluationsArgs = {workspace_id?: number | undefined, name?: string | undefined, status?: ('active' | 'deleted' | 'all') | undefined, include_runs?: boolean | undefined, page?: number | undefined, per_page?: number | undefined, created_by_email?: string | undefined, created_after?: string | undefined, created_before?: string | undefined, updated_after?: string | undefined, updated_before?: string | undefined, external_source?: string | undefined, external_id?: string | undefined, sort_by?: ('created_at' | 'updated_at' | 'name' | 'id') | undefined, sort_order?: ('asc' | 'desc') | undefined}; export type GetApiApiPublicV2EvaluationsOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const externalId = z.object({source: z.string().min(1).max(128), external_id: z.string().min(1).max(512)}); export const evaluation = z.object({id: z.number().int(), name: z.string(), comment: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), workspace_id: z.number().int(), folder_id: z.number().int().nullable().optional(), user_id: z.number().int().nullable().optional(), dataset_id: z.number().int().nullable().optional(), is_blueprint: z.boolean().optional(), tags: z.object({}).nullable().optional(), deleted: z.boolean().optional(), parent_report_id: z.number().int().nullable().optional(), score_configuration: z.object({}).nullable().optional(), runs: z.array(z.object({id: z.number().int().optional(), name: z.string().optional(), comment: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), workspace_id: z.number().int().optional(), folder_id: z.number().int().nullable().optional(), user_id: z.number().int().nullable().optional(), dataset_id: z.number().int().nullable().optional(), is_blueprint: z.boolean().optional(), tags: z.object({}).nullable().optional(), deleted: z.boolean().optional(), parent_report_id: z.number().int().nullable().optional(), score_configuration: z.object({}).nullable().optional(), score: z.object({}).nullable().optional(), score_matrix: z.array(z.unknown()).nullable().optional(), score_calculation_error: z.string().nullable().optional(), status: z.enum(["RUNNING", "COMPLETED"]).optional(), stats: z.object({status_counts: z.object({}).optional()}).optional()})).optional(), external_ids: z.array(externalId).optional()}); export const getApiApiPublicV2EvaluationsResponse = z.object({success: z.boolean(), message: z.string(), evaluations: z.array(evaluation), page: z.number().int(), per_page: z.number().int(), total: z.number().int(), pages: 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 Evaluations * * GET /api/public/v2/evaluations */ export const getApiApiPublicV2Evaluations = async (args: GetApiApiPublicV2EvaluationsArgs, options: GetApiApiPublicV2EvaluationsOptions) => { 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.name != null) query.append("name", String(args.name)) if (args.status != null) query.append("status", String(args.status)) if (args.include_runs != null) query.append("include_runs", String(args.include_runs)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.created_by_email != null) query.append("created_by_email", String(args.created_by_email)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.updated_before != null) query.append("updated_before", String(args.updated_before)) if (args.external_source != null) query.append("external_source", String(args.external_source)) if (args.external_id != null) query.append("external_id", String(args.external_id)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v2/evaluations${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(getApiApiPublicV2EvaluationsResponse, await res.json()) };