import {z} from 'zod' export type UpdateAnnotationReplyRequest = {body: string}; export type PatchApiApiV1AnnotationRepliesReplyIdArgs = {reply_id: string, body: UpdateAnnotationReplyRequest}; export type PatchApiApiV1AnnotationRepliesReplyIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const sourceSummary = z.object({origin: z.string().nullable().optional(), nm: z.string().nullable().optional(), import_id: z.string().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 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 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 replyWriteResponse = z.object({reply: annotationReply, annotation: annotation}); 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 }; /** * Update Annotation Reply * * PATCH /api/v1/annotation-replies/{reply_id} */ export const patchApiApiV1AnnotationRepliesReplyId = async (args: PatchApiApiV1AnnotationRepliesReplyIdArgs, options: PatchApiApiV1AnnotationRepliesReplyIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/annotation-replies/${encodeURIComponent(String(args.reply_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(replyWriteResponse, await res.json()) };