-
Notifications
You must be signed in to change notification settings - Fork 7k
chat log soft delete #6110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
chat log soft delete #6110
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca56ac4
chat log soft delete
newfish-cmyk 54b4192
perf: history api
c121914yu 005d6ed
add history test
c121914yu f96b018
Update packages/web/i18n/en/app.json
c121914yu 5f70f6c
zod parse error
c121914yu 8d625d8
fix: ts
c121914yu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ description: 'FastGPT V4.14.5 更新说明' | |
|
|
||
| ## 🚀 新增内容 | ||
|
|
||
|
|
||
| 1. 对话记录使用侧改成软删除,增加从日志管理里删除对话记录。 | ||
|
|
||
| ## ⚙️ 优化 | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| export const PaginationSchema = z.object({ | ||
| pageSize: z.union([z.number(), z.string()]), | ||
| pageSize: z.union([z.number(), z.string()]).optional(), | ||
| offset: z.union([z.number(), z.string()]).optional(), | ||
| pageNum: z.union([z.number(), z.string()]).optional() | ||
| }); | ||
| export type PaginationType = z.infer<typeof PaginationSchema>; | ||
|
|
||
| export const PaginationResponseSchema = <T extends z.ZodTypeAny>(itemSchema: T) => | ||
| z.object({ | ||
| total: z.number().optional().default(0), | ||
| list: z.array(itemSchema).optional().default([]) | ||
| }); | ||
| export type PaginationResponseType<T extends z.ZodTypeAny> = z.infer< | ||
| ReturnType<typeof PaginationResponseSchema<T>> | ||
| >; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import z from 'zod'; | ||
| import { ObjectIdSchema } from '../../../../common/type/mongo'; | ||
| import { OutLinkChatAuthSchema } from '../../../../support/permission/chat'; | ||
| import { ChatSourceEnum } from '../../../../core/chat/constants'; | ||
| import { PaginationSchema, PaginationResponseSchema } from '../../../api'; | ||
|
|
||
| // Get chat histories schema | ||
| export const GetHistoriesBodySchema = PaginationSchema.and( | ||
| OutLinkChatAuthSchema.and( | ||
| z.object({ | ||
| appId: ObjectIdSchema.optional().describe('应用ID'), | ||
| source: z.enum(ChatSourceEnum).optional().describe('对话来源'), | ||
| startCreateTime: z.string().optional().describe('创建时间开始'), | ||
| endCreateTime: z.string().optional().describe('创建时间结束'), | ||
| startUpdateTime: z.string().optional().describe('更新时间开始'), | ||
| endUpdateTime: z.string().optional().describe('更新时间结束') | ||
| }) | ||
| ) | ||
| ); | ||
| export type GetHistoriesBodyType = z.infer<typeof GetHistoriesBodySchema>; | ||
| export const GetHistoriesResponseSchema = PaginationResponseSchema( | ||
| z.object({ | ||
| chatId: z.string(), | ||
| updateTime: z.date(), | ||
| appId: z.string(), | ||
| customTitle: z.string().optional(), | ||
| title: z.string(), | ||
| top: z.boolean().optional() | ||
| }) | ||
| ); | ||
| export type GetHistoriesResponseType = z.infer<typeof GetHistoriesResponseSchema>; | ||
|
|
||
| // Update chat history schema | ||
| export const UpdateHistoryBodySchema = OutLinkChatAuthSchema.and( | ||
| z.object({ | ||
| appId: ObjectIdSchema.describe('应用ID'), | ||
| chatId: z.string().min(1).describe('对话ID'), | ||
| title: z.string().optional().describe('标题'), | ||
| customTitle: z.string().optional().describe('自定义标题'), | ||
| top: z.boolean().optional().describe('是否置顶') | ||
| }) | ||
| ); | ||
| export type UpdateHistoryBodyType = z.infer<typeof UpdateHistoryBodySchema>; | ||
|
|
||
| // Delete single chat history schema | ||
| export const DelChatHistorySchema = OutLinkChatAuthSchema.and( | ||
| z.object({ | ||
| appId: ObjectIdSchema.describe('应用ID'), | ||
| chatId: z.string().min(1).describe('对话ID') | ||
| }) | ||
| ); | ||
| export type DelChatHistoryType = z.infer<typeof DelChatHistorySchema>; | ||
|
|
||
| // Clear all chat histories schema | ||
| export const ClearChatHistoriesSchema = OutLinkChatAuthSchema.and( | ||
| z.object({ | ||
| appId: ObjectIdSchema.describe('应用ID') | ||
| }) | ||
| ); | ||
| export type ClearChatHistoriesType = z.infer<typeof ClearChatHistoriesSchema>; | ||
|
|
||
| // Batch delete chat histories schema (for log manager) | ||
| export const ChatBatchDeleteBodySchema = z.object({ | ||
| appId: ObjectIdSchema, | ||
| chatIds: z | ||
| .array(z.string().min(1)) | ||
| .min(1) | ||
| .meta({ | ||
| description: '对话ID列表', | ||
| example: ['chat_123456', 'chat_789012'] | ||
| }) | ||
| }); | ||
| export type ChatBatchDeleteBodyType = z.infer<typeof ChatBatchDeleteBodySchema>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import type { OpenAPIPath } from '../../../type'; | ||
| import { TagsMap } from '../../../tag'; | ||
| import { | ||
| GetHistoriesBodySchema, | ||
| GetHistoriesResponseSchema, | ||
| UpdateHistoryBodySchema, | ||
| ChatBatchDeleteBodySchema, | ||
| DelChatHistorySchema, | ||
| ClearChatHistoriesSchema | ||
| } from './api'; | ||
|
|
||
| export const ChatHistoryPath: OpenAPIPath = { | ||
| '/core/chat/history/getHistories': { | ||
| post: { | ||
| summary: '获取对话历史列表', | ||
| description: '分页获取指定应用的对话历史记录', | ||
| tags: [TagsMap.chatHistory], | ||
| requestBody: { | ||
| content: { | ||
| 'application/json': { | ||
| schema: GetHistoriesBodySchema | ||
| } | ||
| } | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| description: '成功获取对话历史列表', | ||
| content: { | ||
| 'application/json': { | ||
| schema: GetHistoriesResponseSchema | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| '/core/chat/history/updateHistory': { | ||
| put: { | ||
| summary: '修改对话历史', | ||
| description: '修改对话历史的标题、自定义标题或置顶状态', | ||
| tags: [TagsMap.chatHistory], | ||
| requestBody: { | ||
| content: { | ||
| 'application/json': { | ||
| schema: UpdateHistoryBodySchema | ||
| } | ||
| } | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| description: '成功修改对话历史' | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| '/core/chat/history/delHistory': { | ||
| delete: { | ||
| summary: '删除单个对话历史', | ||
| description: '软删除指定的单个对话记录', | ||
| tags: [TagsMap.chatHistory], | ||
| requestBody: { | ||
| content: { | ||
| 'application/json': { | ||
| schema: DelChatHistorySchema | ||
| } | ||
| } | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| description: '成功删除对话' | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| '/core/chat/history/clearHistories': { | ||
| delete: { | ||
| summary: '清空应用对话历史', | ||
| description: '清空指定应用的所有对话记录(软删除)', | ||
| tags: [TagsMap.chatHistory], | ||
| requestParams: { | ||
| query: ClearChatHistoriesSchema | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| description: '成功清空对话历史' | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| '/core/chat/history/batchDelete': { | ||
| post: { | ||
| summary: '批量删除对话历史', | ||
| description: '批量删除指定应用的多个对话记录(真实删除),需应用日志权限。', | ||
| tags: [TagsMap.chatHistory], | ||
| requestBody: { | ||
| content: { | ||
| 'application/json': { | ||
| schema: ChatBatchDeleteBodySchema | ||
| } | ||
| } | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| description: '成功删除对话' | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import z from 'zod'; | ||
|
|
||
| export const ShareChatAuthSchema = z.object({ | ||
| shareId: z.string().optional().describe('分享链接ID'), | ||
| outLinkUid: z.string().optional().describe('外链用户ID') | ||
| }); | ||
| export type ShareChatAuthProps = z.infer<typeof ShareChatAuthSchema>; | ||
|
|
||
| export const TeamChatAuthSchema = z.object({ | ||
| teamId: z.string().optional().describe('团队ID'), | ||
| teamToken: z.string().optional().describe('团队Token') | ||
| }); | ||
| export type TeamChatAuthProps = z.infer<typeof TeamChatAuthSchema>; | ||
|
|
||
| export const OutLinkChatAuthSchema = ShareChatAuthSchema.and(TeamChatAuthSchema); | ||
| export type OutLinkChatAuthProps = z.infer<typeof OutLinkChatAuthSchema>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.