import {z} from 'zod' export type GetApiApiV1AnnotationsAnnotationIdArgs = {annotation_id: string}; export type GetApiApiV1AnnotationsAnnotationIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const annotationPointGeometryOutput = z.object({type: z.literal("point"), x: z.string(), y: z.string()}); export const annotationRectGeometryOutput = z.object({x: z.string(), y: z.string(), w: z.string(), h: z.string(), type: z.literal("rect")}); export const rectShapeOutput = z.object({x: z.string(), y: z.string(), w: z.string(), h: z.string()}); export const annotationCalloutGeometryOutput = z.object({type: z.literal("callout"), rect: rectShapeOutput, leader: z.array(z.array(z.unknown()))}); export const annotationPolylineGeometryOutput = z.object({type: z.literal("polyline"), points: z.array(z.array(z.unknown()))}); export const annotationPolygonGeometryOutput = z.object({type: z.literal("polygon"), points: z.array(z.array(z.unknown()))}); export const annotationInkGeometryOutput = z.object({type: z.literal("ink"), strokes: z.array(z.array(z.array(z.unknown())))}); export const annotationQuadsGeometryOutput = z.object({type: z.literal("quads"), quads: z.array(z.array(z.string()))}); export const borderEffect = z.object({cloudy: z.union([z.literal(1), z.literal(2)])}); export const annotationFontOutput = z.object({family: z.string().optional(), size_pts: z.string().optional(), color: z.string().nullable().optional(), align: z.enum(["left", "center", "right"]).optional()}); export const annotationStyleOutput = z.object({stroke_color: z.string().optional(), stroke_opacity: z.string().optional(), fill_color: z.string().nullable().optional(), fill_opacity: z.string().optional(), stroke_width: z.string().optional(), dash: z.array(z.string()).nullable().optional(), border_effect: borderEffect.nullable().optional(), line_endings: z.array(z.unknown()).nullable().optional(), font: annotationFontOutput.nullable().optional(), blend: z.enum(["normal", "multiply"]).optional(), rotation: z.string().optional(), stamp_attachment_id: z.string().nullable().optional()}); export const sourceSummary = z.object({origin: z.string().nullable().optional(), nm: z.string().nullable().optional(), import_id: z.string().nullable().optional()}); export const annotation = z.object({id: z.string(), project_id: z.string(), page_id: z.string(), kind: z.enum(["note", "text", "callout", "line", "polyline", "rect", "ellipse", "polygon", "ink", "highlight", "stamp"]), geometry: z.discriminatedUnion("type", [annotationPointGeometryOutput, annotationRectGeometryOutput, annotationCalloutGeometryOutput, annotationPolylineGeometryOutput, annotationPolygonGeometryOutput, annotationInkGeometryOutput, annotationQuadsGeometryOutput]), style: annotationStyleOutput, subject: z.string().nullable(), contents: z.string().nullable(), status: z.enum(["accepted", "rejected", "completed", "cancelled"]).nullable(), author_id: z.string().nullable(), author_name: z.string(), author_kind: z.enum(["user", "agent", "imported"]), visibility: z.enum(["private", "project"]), locked: z.boolean(), bbox_x: z.string(), bbox_y: z.string(), bbox_w: z.string(), bbox_h: z.string(), display_kind: z.string(), row_version: z.number().int(), created_at: z.string(), updated_at: z.string(), deleted_at: z.string().nullable(), source: sourceSummary.nullable().optional()}); export const annotationReply = z.object({id: z.string(), annotation_id: z.string(), parent_reply_id: z.string().nullable(), entry_kind: z.enum(["comment", "status_change"]), body: z.string().nullable(), new_status: z.enum(["accepted", "rejected", "completed", "cancelled"]).nullable(), author_id: z.string().nullable(), author_name: z.string(), author_kind: z.enum(["user", "agent", "imported"]), created_at: z.string(), updated_at: z.string(), deleted_at: z.string().nullable(), source: sourceSummary.nullable().optional()}); export const linkDestRect = z.object({x: z.number(), y: z.number(), w: z.number().gt(0), h: z.number().gt(0)}); export const linkDest = z.object({rect: linkDestRect, zoom: z.number().gt(0).nullable().optional()}); export const linkNav = z.object({drawing_id: z.string(), page_id: z.string(), page_number: z.number().int()}); export const annotationLink = z.object({id: z.string(), annotation_id: z.string(), target_kind: z.enum(["condition", "measurement", "page", "url"]), condition_id: z.string().nullable(), measurement_id: z.string().nullable(), target_page_id: z.string().nullable(), url: z.string().nullable(), label: z.string(), dest: linkDest.nullable(), position: z.number().int(), created_by: z.string().nullable(), created_at: z.string(), stale: z.boolean(), nav: linkNav.nullable()}); export const annotationAttachment = z.object({id: z.string(), annotation_id: z.string(), content_type: z.string(), byte_size: z.number().int(), sha256: z.string(), filename: z.string(), state: z.enum(["pending", "confirmed"]), created_by: z.string().nullable(), created_at: z.string()}); export const annotationDetailResponse = z.object({annotation: annotation, replies: z.array(annotationReply), links: z.array(annotationLink), attachments: z.array(annotationAttachment)}); 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 Annotation * * GET /api/v1/annotations/{annotation_id} */ export const getApiApiV1AnnotationsAnnotationId = async (args: GetApiApiV1AnnotationsAnnotationIdArgs, options: GetApiApiV1AnnotationsAnnotationIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/annotations/${encodeURIComponent(String(args.annotation_id))}${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(annotationDetailResponse, await res.json()) };