import {z} from 'zod' export type GetApiApiV1ProjectsProjectIdVerificationArgs = {project_id: string, rev?: (string | null) | undefined}; export type GetApiApiV1ProjectsProjectIdVerificationOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const verificationReason = z.object({code: z.string(), context: z.record(z.string(), z.unknown()).optional()}); export const verificationCheck = z.object({condition_ref: z.string().nullable(), condition_name: z.string(), result_key: z.string(), printed: z.string().nullable(), computed: z.string().nullable(), delta: z.string().nullable(), ok: z.boolean()}); export const verificationPage = z.object({page_id: z.string(), drawing_id: z.string(), drawing_name: z.string(), page_number: z.number().int(), sheet_number: z.string().nullable(), sheet_title: z.string().nullable(), synthetic: z.boolean().optional(), status: z.enum(["confirmed", "corrected", "failed-gate", "needs-scale", "auto-passed"]), gate_status: z.enum(["passed", "needs_scale", "failed"]), reasons: z.array(verificationReason), checks: z.array(verificationCheck), confirmed_at: z.string().nullable(), confirmed_source: z.enum(["user", "auto"]).nullable(), correction_summary: z.record(z.string(), z.number().int()).nullable(), color_ambiguity_flagged_at: z.string().nullable(), note: z.string().nullable(), sheet_type: z.string().nullable(), sheet_type_source: z.enum(["llm", "user"]).nullable(), page_type: z.string().nullable().optional(), can_confirm: z.boolean(), blockers: z.array(verificationReason)}); export const verificationCounts = z.object({confirmed: z.number().int().optional(), corrected: z.number().int().optional(), "failed-gate": z.number().int().optional(), "needs-scale": z.number().int().optional(), "auto-passed": z.number().int().optional()}); export const projectVerificationResponse = z.object({pages: z.array(verificationPage), counts: verificationCounts, flagged: z.number().int()}); 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 Project Verification * * GET /api/v1/projects/{project_id}/verification */ export const getApiApiV1ProjectsProjectIdVerification = async (args: GetApiApiV1ProjectsProjectIdVerificationArgs, options: GetApiApiV1ProjectsProjectIdVerificationOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.rev != null) query.append("rev", String(args.rev)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.project_id))}/verification${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(projectVerificationResponse, await res.json()) };