import {z} from 'zod' export type CreateApiProjectsProjectIdEvalRunsRunIdJudgeBacktestArgs = {'x-mcpjam-eval-vocabulary'?: ('1' | '2') | undefined, projectId: string, runId: string, body: {rubric: {instructions?: string | undefined, criteria?: (Array<{id: string, label: string, description?: string | undefined, required?: boolean | undefined}>) | undefined} | null, continuation?: {cursor: number, sourceHash: string, reservationId: string} | undefined}}; export type CreateApiProjectsProjectIdEvalRunsRunIdJudgeBacktestOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiProjectsProjectIdEvalRunsRunIdJudgeBacktestResponse = z.object({ok: z.boolean().optional(), cases: z.array(z.object({})).optional(), cursor: z.number().int().optional(), sourceHash: z.string().optional(), reservationId: z.string().optional(), isDone: z.boolean().optional()}); 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 }; /** * Preview draft judge grading on one recorded iteration * * POST /projects/{projectId}/eval-runs/{runId}/judge/backtest */ export const createApiProjectsProjectIdEvalRunsRunIdJudgeBacktest = async (args: CreateApiProjectsProjectIdEvalRunsRunIdJudgeBacktestArgs, options?: CreateApiProjectsProjectIdEvalRunsRunIdJudgeBacktestOptions) => { const {baseUrl = "https://app.mcpjam.com/api/v1", 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 (args['x-mcpjam-eval-vocabulary'] != null) headers.set("x-mcpjam-eval-vocabulary", String(args['x-mcpjam-eval-vocabulary'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.projectId))}/eval-runs/${encodeURIComponent(String(args.runId))}/judge/backtest${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(createApiProjectsProjectIdEvalRunsRunIdJudgeBacktestResponse, await res.json()) };