import {z} from 'zod' export type GetApiApiV2ProjectsProjectIdEvaluationCriteriaArgs = {project_id: string, page?: number | undefined, page_size?: number | undefined}; export type GetApiApiV2ProjectsProjectIdEvaluationCriteriaOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const targetType = z.enum(["prompt", "agent"]); export const evaluationCriteriaInfo = z.object({id: z.string(), name: z.string(), type: z.string(), target_type: targetType, target_id: z.string(), latest_version_id: z.string().nullable(), is_enabled: z.boolean(), llm_eval_enabled: z.boolean()}); export const paginationInfo = z.object({page: z.number().int(), page_size: z.number().int(), has_next: z.boolean()}); export const getApiApiV2ProjectsProjectIdEvaluationCriteriaResponse = z.object({data: z.array(evaluationCriteriaInfo), pagination: paginationInfo}); 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 Criteria * * GET /api/v2/projects/{project_id}/evaluation-criteria */ export const getApiApiV2ProjectsProjectIdEvaluationCriteria = async (args: GetApiApiV2ProjectsProjectIdEvaluationCriteriaArgs, options: GetApiApiV2ProjectsProjectIdEvaluationCriteriaOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = 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.page_size != null) query.append("page_size", String(args.page_size)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/projects/${encodeURIComponent(String(args.project_id))}/evaluation-criteria${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(getApiApiV2ProjectsProjectIdEvaluationCriteriaResponse, await res.json()) };