import {z} from 'zod' export type RestartEvaluationRequest = {comment?: string | undefined, custom_instructions?: string | undefined, model_id?: string | undefined}; export type CreateApiEvaluationsEvaluationIdRestartArgs = {evaluation_id: string, body: RestartEvaluationRequest}; export type CreateApiEvaluationsEvaluationIdRestartOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const evaluationDetails = z.object({_id: z.string(), name: z.string(), data: z.array(z.object({})).optional(), user_id: z.string(), skill: z.object({_id: z.string().optional(), name: z.string().optional()}), dataset: z.object({_id: z.string().optional(), name: z.string().optional()}), model: z.object({_id: z.string().optional(), name: z.string().optional(), model_name: z.string().optional(), provider: z.string().optional()}), status: z.enum(["in progress", "terminated", "pending", "failed"]), progress: z.number().gte(0).lte(100), score: z.number().gte(0).lte(100), nb_questions: z.number().int(), is_child: z.boolean(), comment: z.string().optional(), custom_instructions: z.string().optional(), createdAt: z.string(), updatedAt: z.string(), __v: z.number().int().optional()}); export const createEvaluationResponse = z.object({evaluation: evaluationDetails, message: z.string()}); 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 }; /** * Restart an evaluation * * POST /evaluations/{evaluation_id}/restart */ export const createApiEvaluationsEvaluationIdRestart = async (args: CreateApiEvaluationsEvaluationIdRestartArgs, options?: CreateApiEvaluationsEvaluationIdRestartOptions) => { const {baseUrl = "https://apis.smartly.ai", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/evaluations/${encodeURIComponent(String(args.evaluation_id))}/restart${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createEvaluationResponse, await res.json()) };