import {z} from 'zod' export type GetApiApiV0ComponentsComponentIdSchematicValidationsArgs = {component_id: string, vc_id: string}; export type GetApiApiV0ComponentsComponentIdSchematicValidationsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const bboxConnectivitySummary = z.object({ok: z.number().int().optional(), unwired: z.number().int().optional(), port_mismatch: z.number().int().optional(), total: z.number().int().optional()}); export const bboxConnectivityEntity = z.object({entity_id: z.string(), status: z.enum(["ok", "unwired", "port_mismatch"]), port_count: z.number().int(), incident_segment_count: z.number().int(), reason: z.string().nullable().optional()}); export const bboxConnectivityReport = z.object({summary: bboxConnectivitySummary.optional(), entities: z.array(bboxConnectivityEntity).optional()}); export const textCompletionSummary = z.object({ok: z.number().int().optional(), missing: z.number().int().optional(), total: z.number().int().optional()}); export const textCompletionEntity = z.object({entity_id: z.string(), entity_type: z.enum(["node", "annotation"]), subtype: z.string(), status: z.enum(["ok", "missing"]), reason: z.string().nullable().optional()}); export const textCompletionReport = z.object({required_subtypes: z.array(z.string()).optional(), summary: textCompletionSummary.optional(), entities: z.array(textCompletionEntity).optional()}); export const validationReport = z.object({bbox_connectivity: bboxConnectivityReport, text_completion: textCompletionReport}); 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 }; /** * Run annotation-completeness validations * * GET /api/v0/components/{component_id}/schematic/validations */ export const getApiApiV0ComponentsComponentIdSchematicValidations = async (args: GetApiApiV0ComponentsComponentIdSchematicValidationsArgs, options: GetApiApiV0ComponentsComponentIdSchematicValidationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.vc_id != null) query.append("vc_id", String(args.vc_id)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v0/components/${encodeURIComponent(String(args.component_id))}/schematic/validations${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(validationReport, await res.json()) };