import {z} from 'zod' export type CreateApiExperimentalReviewRunsIdRetryArgs = {id: string, Authorization?: string | undefined}; export type CreateApiExperimentalReviewRunsIdRetryOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiExperimentalReviewRunsIdRetryResponse = z.object({links: z.object({self: z.string()}), data: z.object({id: z.string(), type: z.literal("review-run"), attributes: z.object({workflowId: z.string().nullable(), status: z.union([z.literal("pending"), z.literal("completed"), z.literal("failed")]), metadata: z.object({tier: z.union([z.literal("anonymous"), z.literal("authed_free")]), pathLabel: z.string().optional(), source: z.string().optional(), subject: z.union([z.object({type: z.literal("tile_skill"), name: z.string(), path: z.string(), tileRef: z.string(), registryUrl: z.string()}), z.object({type: z.literal("skill"), name: z.string(), path: z.string().optional()})]).optional(), reusedFromReviewRunId: z.string().optional()}).and(z.record(z.string(), z.unknown())), createdAt: z.string(), updatedAt: z.string(), progress: z.object({queue: z.union([z.literal("preparing"), z.literal("queued"), z.literal("active"), z.literal("finishing")]), recipes: z.array(z.object({name: z.string(), waiting: z.number().int().gte(0), running: z.number().int().gte(0), completed: z.number().int().gte(0)})), summary: z.object({label: z.string(), total: z.number().int().gte(0).optional(), completed: z.number().int().gte(0), failed: z.number().int().gte(0)}).optional(), units: z.array(z.object({name: z.string(), percent: z.number().int().gte(0).lte(100), waiting: z.boolean()})).optional()}).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 }; /** * Deprecated — use `POST /experimental/reviews/{id}/retry` instead. Retries a failed review run by creating a new run with the same config. * * POST /experimental/review-runs/{id}/retry */ export const createApiExperimentalReviewRunsIdRetry = async (args: CreateApiExperimentalReviewRunsIdRetryArgs, options?: CreateApiExperimentalReviewRunsIdRetryOptions) => { const {baseUrl = "https://api.tessl.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/experimental/review-runs/${encodeURIComponent(String(args.id))}/retry${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiExperimentalReviewRunsIdRetryResponse, await res.json()) };