import {z} from 'zod' export type GetApiApiV1AdminPartsPartIdAnnotationsArgs = {part_id: string}; export type GetApiApiV1AdminPartsPartIdAnnotationsOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const featureNote = z.object({id: z.string(), note: z.string(), author: z.string(), created_at: z.string()}); export const toleranceSpec = z.object({id: z.string(), tolerance_type: z.string(), data: z.record(z.string(), z.unknown()), created_at: z.string()}); export const reclassification = z.object({id: z.string(), new_type: z.string(), is_confirmation: z.boolean().optional(), reason: z.string().nullable().optional(), created_at: z.string()}); export const dfmAcknowledgment = z.object({id: z.string(), action: z.string(), finding_id: z.string().nullable().optional(), reason: z.string().nullable().optional(), outcome_type: z.string(), created_at: z.string()}); export const calloutSummary = z.object({id: z.string(), callout_type: z.string(), severity: z.string(), title: z.string(), body: z.string().nullable().optional(), state: z.string(), answered: z.boolean(), answer_text: z.string().nullable().optional()}); export const featureAnnotationSummary = z.object({feature_id: z.string(), feature_type: z.string(), feature_subtype: z.string().nullable().optional(), dimensions: z.record(z.string(), z.unknown()), confidence: z.number().nullable().optional(), notes: z.array(featureNote), tolerances: z.array(toleranceSpec), reclassifications: z.array(reclassification), dfm_acknowledgments: z.array(dfmAcknowledgment), callouts: z.array(calloutSummary), has_surface_finish: z.boolean().optional()}); export const designIntentSummary = z.object({purpose: z.string().nullable().optional(), primary_function: z.string().nullable().optional(), environment: z.string().nullable().optional(), critical_features: z.array(z.record(z.string(), z.unknown())), mating_surfaces: z.array(z.record(z.string(), z.unknown())), load_paths: z.array(z.record(z.string(), z.unknown())), tolerance_rationale: z.array(z.record(z.string(), z.unknown())), free_text_notes: z.string().nullable().optional(), interview_status: z.string()}); export const weldSummary = z.object({weld_id: z.string(), edge_id: z.string(), weld_type: z.string(), size_mm: z.number(), length_mm: z.number().nullable().optional(), process: z.string().nullable().optional(), side: z.string().optional(), all_around: z.boolean().optional(), notes: z.string().nullable().optional(), label: z.string(), state: z.string(), source: z.string(), created_at: z.string()}); export const surfaceFinishSummary = z.object({id: z.string(), face_id: z.string(), finish_type: z.string(), ra_um: z.number().nullable().optional(), custom_color_hex: z.string().nullable().optional(), notes: z.string().nullable().optional(), label: z.string(), author: z.string().nullable().optional(), source: z.string(), state: z.string(), is_process_mismatch: z.boolean().optional(), created_at: z.string(), feature_id: z.string().nullable().optional()}); export const edgeToleranceSummary = z.object({id: z.string(), edge_id: z.string(), tolerance_type: z.string(), size_mm: z.number().nullable().optional(), angle_deg: z.number().nullable().optional(), notes: z.string().nullable().optional(), label: z.string(), author: z.string().nullable().optional(), source: z.string(), state: z.string(), created_at: z.string()}); export const partAnnotationBundle = z.object({part_id: z.string(), version_id: z.string(), version_number: z.number().int(), thumbnail_url: z.string().nullable().optional(), annotated_features: z.array(featureAnnotationSummary), unannotated_feature_count: z.number().int(), part_level_notes: z.array(featureNote), design_intent: designIntentSummary.nullable().optional(), welds: z.array(weldSummary).optional(), total_welds: z.number().int().optional(), surface_finishes: z.array(surfaceFinishSummary).optional(), total_surface_finishes: z.number().int().optional(), edge_tolerances: z.array(edgeToleranceSummary).optional(), total_edge_tolerances: z.number().int().optional(), total_notes: z.number().int(), total_tolerances: z.number().int(), total_reclassifications: z.number().int(), total_callouts: 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 Part Annotations * * GET /api/v1/admin/parts/{part_id}/annotations */ export const getApiApiV1AdminPartsPartIdAnnotations = async (args: GetApiApiV1AdminPartsPartIdAnnotationsArgs, options: GetApiApiV1AdminPartsPartIdAnnotationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/admin/parts/${encodeURIComponent(String(args.part_id))}/annotations${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(partAnnotationBundle, await res.json()) };