import z from "zod"; import { ChatMentionSchema } from "./chat"; import { VisibilitySchema } from "./util"; export type AgentIcon = { type: "emoji"; value: string; style?: Record; }; export const AgentInstructionsSchema = z.object({ role: z.string().optional(), systemPrompt: z.string().optional(), mentions: z.array(ChatMentionSchema).optional(), }); export const AgentCreateSchema = z .object({ name: z.string().min(1).max(100), description: z.string().max(8000).optional(), icon: z .object({ type: z.literal("emoji"), value: z.string(), style: z.record(z.string(), z.string()).optional(), }) .optional(), userId: z.string(), instructions: AgentInstructionsSchema, visibility: VisibilitySchema.optional().default("private"), }) .strip(); export const AgentUpdateSchema = z .object({ name: z.string().min(1).max(100).optional(), description: z.string().max(8000).optional(), icon: z .object({ type: z.literal("emoji"), value: z.string(), style: z.record(z.string(), z.string()).optional(), }) .optional(), instructions: AgentInstructionsSchema.optional(), visibility: VisibilitySchema.optional(), }) .strip(); export const AgentQuerySchema = z.object({ type: z.enum(["all", "mine", "shared", "bookmarked"]).default("all"), filters: z.string().optional(), limit: z.coerce.number().min(1).max(100).default(50), }); export type AgentVisibility = z.infer; export type AgentSummary = { id: string; name: string; description?: string; icon?: AgentIcon; userId: string; visibility: AgentVisibility; createdAt: Date; updatedAt: Date; userName?: string; userAvatar?: string; isBookmarked?: boolean; }; export type Agent = AgentSummary & { instructions: z.infer; }; export type AgentRepository = { insertAgent(agent: z.infer): Promise; selectAgentById(id: string, userId: string): Promise; selectAgentsByUserId(userId: string): Promise; updateAgent( id: string, userId: string, agent: z.infer, ): Promise; deleteAgent(id: string, userId: string): Promise; selectAgents( currentUserId: string, filters?: ("all" | "mine" | "shared" | "bookmarked")[], limit?: number, ): Promise; checkAccess( agentId: string, userId: string, destructive?: boolean, ): Promise; }; export const AgentGenerateSchema = z.object({ name: z.string().describe("Agent name"), description: z.string().describe("Agent description"), instructions: z.string().describe("Agent instructions"), role: z.string().describe("Agent role"), tools: z .array(z.string()) .describe("Agent allowed tools name") .optional() .default([]), });