import {z} from 'zod' export type GetApiV1ExperimentsExperimentIdReportsArgs = {experiment_id: string, limit?: number | undefined, cursor?: (string | null) | undefined}; export type GetApiV1ExperimentsExperimentIdReportsOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const reportSourceKind = z.enum(["agent_run", "auto_agent_run", "experiment"]); export const reportSource = z.object({kind: reportSourceKind, id: z.string()}); export const reportTimestamps = z.object({created_at: z.string(), started_at: z.string().nullable().optional(), completed_at: z.string().nullable().optional()}); export const reportSourceField = z.enum(["report", "final_report", "data_curation_report", "system_deficiencies", "deliverables_json", "curation_report"]); export const reportFieldProvenance = z.object({source_kind: reportSourceKind, source_id: z.string(), source_field: reportSourceField}); export const reportItemProvenance = z.object({structured: reportFieldProvenance.nullable(), final: reportFieldProvenance.nullable().optional(), curation: reportFieldProvenance.nullable().optional(), system_deficiencies: reportFieldProvenance.nullable().optional()}); export const reportItem = z.object({source: reportSource, status: z.string(), timestamps: reportTimestamps, structured: z.record(z.string(), z.unknown()).nullable().optional(), final: z.string().nullable().optional(), curation: z.string().nullable().optional(), system_deficiencies: z.string().nullable().optional(), provenance: reportItemProvenance}); export const experimentReportPage = z.object({items: z.array(reportItem), next_cursor: z.string().nullable().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 }; /** * List reports produced by an Experiment * * GET /v1/experiments/{experiment_id}/reports * * Also accepts auth: BearerAuth */ export const getApiV1ExperimentsExperimentIdReports = async (args: GetApiV1ExperimentsExperimentIdReportsArgs, options: GetApiV1ExperimentsExperimentIdReportsOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/experiments/${encodeURIComponent(String(args.experiment_id))}/reports${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(experimentReportPage, await res.json()) };