feat(shared): define harness protocols

This commit is contained in:
Wenxin Duan
2026-09-07 15:23:12 +08:00
parent 98baf9aee7
commit e87c68f3ad
9 changed files with 380 additions and 1 deletions
+39
View File
@@ -0,0 +1,39 @@
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<typeof MessageInputSchema>;
export type ImageAttachment = z.infer<typeof ImageAttachmentSchema>;