import {z} from 'zod' export type GetApiApiV1AutomationsIdReviewsHealthArgs = {id: string, type?: string | undefined, status?: string | undefined, trigger?: string | undefined, triggeredBy?: string | undefined, sourceRef?: string | undefined, batchId?: string | undefined, exampleId?: string | undefined, exampleIdContains?: string | undefined, from?: string | undefined, to?: string | undefined, completedAfter?: string | undefined, completedBefore?: string | undefined, experiments?: string | undefined, bucket?: ('day' | 'week' | 'month') | undefined, rollingWindow?: number | undefined, minRollingReviews?: number | undefined}; export type GetApiApiV1AutomationsIdReviewsHealthOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const runReviewHealthConfidence = z.object({lower: z.number().nullable(), upper: z.number().nullable(), method: z.literal("wilson")}); export const runReviewHealthSummary = z.object({totalRuns: z.number().int().gte(-9007199254740991).lte(9007199254740991), reviewedRuns: z.number().int().gte(-9007199254740991).lte(9007199254740991), reviewCoverage: z.number().nullable(), correctReviews: z.number().int().gte(-9007199254740991).lte(9007199254740991), incorrectReviews: z.number().int().gte(-9007199254740991).lte(9007199254740991), nitReviews: z.number().int().gte(-9007199254740991).lte(9007199254740991), reviewedCorrectness: z.number().nullable(), confidence: runReviewHealthConfidence}); export const runReviewHealthBucket = z.object({start: z.string(), end: z.string(), totalRuns: z.number().int().gte(-9007199254740991).lte(9007199254740991), reviewedRuns: z.number().int().gte(-9007199254740991).lte(9007199254740991), reviewCoverage: z.number().nullable(), correctReviews: z.number().int().gte(-9007199254740991).lte(9007199254740991), incorrectReviews: z.number().int().gte(-9007199254740991).lte(9007199254740991), nitReviews: z.number().int().gte(-9007199254740991).lte(9007199254740991), reviewedCorrectness: z.number().nullable()}); export const runReviewHealthRollingPoint = z.object({at: z.string(), reviewedRuns: z.number().int().gte(-9007199254740991).lte(9007199254740991), correctReviews: z.number().int().gte(-9007199254740991).lte(9007199254740991), reviewedCorrectness: z.number(), confidenceLower: z.number(), confidenceUpper: z.number(), totalRunsInWindow: z.number().int().gte(-9007199254740991).lte(9007199254740991), reviewCoverage: z.number()}); export const runReviewHealthResponse = z.object({timeRange: z.object({from: z.string(), to: z.string()}), granularity: z.object({bucket: z.enum(["day", "week", "month"]), rollingWindow: z.number().int().gte(-9007199254740991).lte(9007199254740991), minRollingReviews: z.number().int().gte(-9007199254740991).lte(9007199254740991)}), summary: runReviewHealthSummary, buckets: z.array(runReviewHealthBucket), rolling: z.array(runReviewHealthRollingPoint)}); 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 automation review health * * GET /api/v1/automations/{id}/reviews/health */ export const getApiApiV1AutomationsIdReviewsHealth = async (args: GetApiApiV1AutomationsIdReviewsHealthArgs, options?: GetApiApiV1AutomationsIdReviewsHealthOptions) => { const {baseUrl = "https://studio.eigenpal.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.status != null) query.append("status", String(args.status)) if (args.trigger != null) query.append("trigger", String(args.trigger)) if (args.triggeredBy != null) query.append("triggeredBy", String(args.triggeredBy)) if (args.sourceRef != null) query.append("sourceRef", String(args.sourceRef)) if (args.batchId != null) query.append("batchId", String(args.batchId)) if (args.exampleId != null) query.append("exampleId", String(args.exampleId)) if (args.exampleIdContains != null) query.append("exampleIdContains", String(args.exampleIdContains)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.completedAfter != null) query.append("completedAfter", String(args.completedAfter)) if (args.completedBefore != null) query.append("completedBefore", String(args.completedBefore)) if (args.experiments != null) query.append("experiments", String(args.experiments)) if (args.bucket != null) query.append("bucket", String(args.bucket)) if (args.rollingWindow != null) query.append("rollingWindow", String(args.rollingWindow)) if (args.minRollingReviews != null) query.append("minRollingReviews", String(args.minRollingReviews)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/automations/${encodeURIComponent(String(args.id))}/reviews/health${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(runReviewHealthResponse, await res.json()) };