import {z} from 'zod' export type GetApiV1PublicSuitesSuiteIdProblemsArgs = {suite_id: number, include_embeddings?: boolean | undefined}; export type GetApiV1PublicSuitesSuiteIdProblemsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const safeEnvironmentMetadata = z.object({display_name: z.string(), catalog_epoch: z.string(), contract_version: z.string(), runtime_version: z.string(), result_schema_version: z.string()}); export const suitePublic = z.object({suite_id: z.number().int(), suite_version: z.number().int(), is_active: z.boolean(), execution_kind: z.enum(["legacy_shoppingbench", "envpack"]).optional(), environment: safeEnvironmentMetadata.nullable().optional(), benchmark_name: z.string().nullable().optional(), benchmark_number: z.number().int().nullable().optional()}); export const problemPublic = z.object({problem_id: z.string(), suite_id: z.number().int(), metadata: z.record(z.string(), z.unknown()).optional()}); export const qualifyingTaskRead = z.object({task_id: z.string(), family: z.string(), goal_text: z.string()}); export const suiteWithProblemsResponse = z.object({suite: suitePublic, problems: z.array(problemPublic), qualifying_tasks: z.array(qualifyingTaskRead).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 }; /** * Get suite problems * * GET /v1/public/suites/{suite_id}/problems */ export const getApiV1PublicSuitesSuiteIdProblems = async (args: GetApiV1PublicSuitesSuiteIdProblemsArgs, options: GetApiV1PublicSuitesSuiteIdProblemsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_embeddings != null) query.append("include_embeddings", String(args.include_embeddings)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/public/suites/${encodeURIComponent(String(args.suite_id))}/problems${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(suiteWithProblemsResponse, await res.json()) };