import { z } from "zod"; export const EntityIdSchema = z.string().regex(/^[a-z]+_[a-zA-Z0-9_-]+$/); export const AttachmentIdSchema = z.string().regex(/^att_[a-zA-Z0-9_-]+$/); export const MessageInputSchema = z.object({ text: z.string().max(100_000).default(""), attachmentIds: z.array(AttachmentIdSchema).max(4).default([]), }).strict().superRefine((value, context) => { if (value.text.trim().length === 0 && value.attachmentIds.length === 0) { context.addIssue({ code: "custom", path: ["text"], message: "A message requires text or at least one attachment", }); } if (new Set(value.attachmentIds).size !== value.attachmentIds.length) { context.addIssue({ code: "custom", path: ["attachmentIds"], message: "Attachment IDs must be unique", }); } }); export const ImageAttachmentSchema = z.object({ attachmentId: AttachmentIdSchema, sessionId: z.string().regex(/^ses_[a-zA-Z0-9_-]+$/), name: z.string().trim().min(1).max(255), mediaType: z.enum(["image/jpeg", "image/png", "image/webp"]), byteSize: z.int().positive(), width: z.int().positive(), height: z.int().positive(), status: z.literal("ready"), }).strict(); export type MessageInput = z.infer; export type ImageAttachment = z.infer;