|
| 1 | +import z from 'zod'; |
| 2 | +import { ObjectIdSchema } from '../../../../common/type/mongo'; |
| 3 | +import { OutLinkChatAuthSchema } from '../../../../support/permission/chat'; |
| 4 | +import { ChatSourceEnum } from '../../../../core/chat/constants'; |
| 5 | +import { PaginationSchema, PaginationResponseSchema } from '../../../api'; |
| 6 | + |
| 7 | +// Get chat histories schema |
| 8 | +export const GetHistoriesBodySchema = PaginationSchema.and( |
| 9 | + OutLinkChatAuthSchema.and( |
| 10 | + z.object({ |
| 11 | + appId: ObjectIdSchema.optional().describe('应用ID'), |
| 12 | + source: z.enum(ChatSourceEnum).optional().describe('对话来源'), |
| 13 | + startCreateTime: z.string().optional().describe('创建时间开始'), |
| 14 | + endCreateTime: z.string().optional().describe('创建时间结束'), |
| 15 | + startUpdateTime: z.string().optional().describe('更新时间开始'), |
| 16 | + endUpdateTime: z.string().optional().describe('更新时间结束') |
| 17 | + }) |
| 18 | + ) |
| 19 | +); |
| 20 | +export type GetHistoriesBodyType = z.infer<typeof GetHistoriesBodySchema>; |
| 21 | +export const GetHistoriesResponseSchema = PaginationResponseSchema( |
| 22 | + z.object({ |
| 23 | + chatId: z.string(), |
| 24 | + updateTime: z.date(), |
| 25 | + appId: z.string(), |
| 26 | + customTitle: z.string().optional(), |
| 27 | + title: z.string(), |
| 28 | + top: z.boolean().optional() |
| 29 | + }) |
| 30 | +); |
| 31 | +export type GetHistoriesResponseType = z.infer<typeof GetHistoriesResponseSchema>; |
| 32 | + |
| 33 | +// Update chat history schema |
| 34 | +export const UpdateHistoryBodySchema = OutLinkChatAuthSchema.and( |
| 35 | + z.object({ |
| 36 | + appId: ObjectIdSchema.describe('应用ID'), |
| 37 | + chatId: z.string().min(1).describe('对话ID'), |
| 38 | + title: z.string().optional().describe('标题'), |
| 39 | + customTitle: z.string().optional().describe('自定义标题'), |
| 40 | + top: z.boolean().optional().describe('是否置顶') |
| 41 | + }) |
| 42 | +); |
| 43 | +export type UpdateHistoryBodyType = z.infer<typeof UpdateHistoryBodySchema>; |
| 44 | + |
| 45 | +// Delete single chat history schema |
| 46 | +export const DelChatHistorySchema = OutLinkChatAuthSchema.and( |
| 47 | + z.object({ |
| 48 | + appId: ObjectIdSchema.describe('应用ID'), |
| 49 | + chatId: z.string().min(1).describe('对话ID') |
| 50 | + }) |
| 51 | +); |
| 52 | +export type DelChatHistoryType = z.infer<typeof DelChatHistorySchema>; |
| 53 | + |
| 54 | +// Clear all chat histories schema |
| 55 | +export const ClearChatHistoriesSchema = OutLinkChatAuthSchema.and( |
| 56 | + z.object({ |
| 57 | + appId: ObjectIdSchema.describe('应用ID') |
| 58 | + }) |
| 59 | +); |
| 60 | +export type ClearChatHistoriesType = z.infer<typeof ClearChatHistoriesSchema>; |
| 61 | + |
| 62 | +// Batch delete chat histories schema (for log manager) |
| 63 | +export const ChatBatchDeleteBodySchema = z.object({ |
| 64 | + appId: ObjectIdSchema, |
| 65 | + chatIds: z |
| 66 | + .array(z.string().min(1)) |
| 67 | + .min(1) |
| 68 | + .meta({ |
| 69 | + description: '对话ID列表', |
| 70 | + example: ['chat_123456', 'chat_789012'] |
| 71 | + }) |
| 72 | +}); |
| 73 | +export type ChatBatchDeleteBodyType = z.infer<typeof ChatBatchDeleteBodySchema>; |
0 commit comments