import {z} from 'zod' export type GetApiApiV2ProjectsProjectIdAgentDatasetsDatasetIdTestCasesArgs = {project_id: string, dataset_id: string, page?: number | undefined, page_size?: number | undefined}; export type GetApiApiV2ProjectsProjectIdAgentDatasetsDatasetIdTestCasesOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const jSONValue: z.ZodType = z.union([z.boolean(), z.number().int(), z.number(), z.string(), z.record(z.string(), z.lazy(() => jSONValue)), z.array(z.lazy(() => jSONValue))]).nullable(); export const agentTestCaseResponse = z.object({id: z.string(), input: jSONValue.optional(), output: jSONValue.optional(), metadata: z.record(z.string(), z.union([z.string(), z.number().int(), z.number(), z.boolean()])).nullable().optional()}); export const paginationInfo = z.object({page: z.number().int(), page_size: z.number().int(), has_next: z.boolean()}); export const getApiApiV2ProjectsProjectIdAgentDatasetsDatasetIdTestCasesResponse = z.object({data: z.array(agentTestCaseResponse), pagination: paginationInfo}); 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 }; /** * List Agent Test Cases * * GET /api/v2/projects/{project_id}/agent-datasets/{dataset_id}/test-cases */ export const getApiApiV2ProjectsProjectIdAgentDatasetsDatasetIdTestCases = async (args: GetApiApiV2ProjectsProjectIdAgentDatasetsDatasetIdTestCasesArgs, options: GetApiApiV2ProjectsProjectIdAgentDatasetsDatasetIdTestCasesOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/projects/${encodeURIComponent(String(args.project_id))}/agent-datasets/${encodeURIComponent(String(args.dataset_id))}/test-cases${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(getApiApiV2ProjectsProjectIdAgentDatasetsDatasetIdTestCasesResponse, await res.json()) };