import {z} from 'zod' export type PatchApiApiV2ProjectsProjectIdEvaluationCriteriaCodeCriteriaIdArgs = {project_id: string, criteria_id: string, body: {name?: (string | null) | undefined, description?: (string | null) | undefined, sample_rate?: (number | null) | undefined, generate_insights?: (boolean | null) | undefined}}; export type PatchApiApiV2ProjectsProjectIdEvaluationCriteriaCodeCriteriaIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const targetType = z.enum(["prompt", "agent"]); export const autoEvalCriteriaType = z.enum(["1-5", "1-3", "1-100", "yes-no", "multi-select", "text", "auto-categorization", "code-bool", "code-float"]); export const codeEvalVersionSummary = z.object({id: z.string(), version_number: z.number().int(), eval_code: z.string().nullable(), is_deployed: z.boolean(), created_at: z.string()}); export const patchApiApiV2ProjectsProjectIdEvaluationCriteriaCodeCriteriaIdResponse = z.object({id: z.string(), name: z.string(), description: z.string().nullable(), target_type: targetType, target_id: z.string(), criteria_type: autoEvalCriteriaType, sample_rate: z.number().nullable(), is_enabled: z.boolean(), generate_insights: z.boolean(), deployed_version: codeEvalVersionSummary, latest_version: codeEvalVersionSummary}); 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 }; /** * Update Code Evaluation Criteria * * PATCH /api/v2/projects/{project_id}/evaluation-criteria/code/{criteria_id} */ export const patchApiApiV2ProjectsProjectIdEvaluationCriteriaCodeCriteriaId = async (args: PatchApiApiV2ProjectsProjectIdEvaluationCriteriaCodeCriteriaIdArgs, options: PatchApiApiV2ProjectsProjectIdEvaluationCriteriaCodeCriteriaIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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/code/${encodeURIComponent(String(args.criteria_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiApiV2ProjectsProjectIdEvaluationCriteriaCodeCriteriaIdResponse, await res.json()) };