27 lines
890 B
TypeScript
27 lines
890 B
TypeScript
import { z } from "zod";
|
|
import { isValidLlmModelId } from "@/lib/llm/models";
|
|
|
|
export const clientChatAttachmentSchema = z.object({
|
|
type: z.literal("image"),
|
|
url: z.string().trim().min(1).max(2048),
|
|
});
|
|
|
|
export const clientChatMessageSchema = z.object({
|
|
role: z.enum(["user", "assistant"]),
|
|
content: z.string().trim().min(1).max(8000),
|
|
attachments: z.array(clientChatAttachmentSchema).max(3).optional(),
|
|
});
|
|
|
|
export const clientChatModelSchema = z
|
|
.string()
|
|
.refine((value) => isValidLlmModelId(value), "Invalid assistant model");
|
|
|
|
export const clientChatInputSchema = z.object({
|
|
stream: z.boolean().optional(),
|
|
model: clientChatModelSchema.optional(),
|
|
messages: z.array(clientChatMessageSchema).min(1).max(40),
|
|
});
|
|
|
|
export type ClientChatAttachment = z.infer<typeof clientChatAttachmentSchema>;
|
|
export type ClientChatMessage = z.infer<typeof clientChatMessageSchema>;
|