import {z} from 'zod' export type GetApiApiV2ProjectsProjectIdEvaluationCriteriaIdCriteriaIdArgs = {project_id: string, criteria_id: string}; export type GetApiApiV2ProjectsProjectIdEvaluationCriteriaIdCriteriaIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const targetType = z.enum(["prompt", "agent"]); export const getApiApiV2ProjectsProjectIdEvaluationCriteriaIdCriteriaIdResponse = 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 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 Evaluation Criteria * * GET /api/v2/projects/{project_id}/evaluation-criteria/id/{criteria_id} */ export const getApiApiV2ProjectsProjectIdEvaluationCriteriaIdCriteriaId = async (args: GetApiApiV2ProjectsProjectIdEvaluationCriteriaIdCriteriaIdArgs, options: GetApiApiV2ProjectsProjectIdEvaluationCriteriaIdCriteriaIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/projects/${encodeURIComponent(String(args.project_id))}/evaluation-criteria/id/${encodeURIComponent(String(args.criteria_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(getApiApiV2ProjectsProjectIdEvaluationCriteriaIdCriteriaIdResponse, await res.json()) };