Skip to content

Commit 09b9fa5

Browse files
newfish-cmykc121914yuCopilot
authored
chat log soft delete (#6110)
* chat log soft delete * perf: history api * add history test * Update packages/web/i18n/en/app.json Co-authored-by: Copilot <[email protected]> * zod parse error * fix: ts --------- Co-authored-by: archer <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 463b02d commit 09b9fa5

File tree

48 files changed

+1830
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1830
-251
lines changed

document/content/docs/upgrading/4-14/4145.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: 'FastGPT V4.14.5 更新说明'
66

77
## 🚀 新增内容
88

9-
9+
1. 对话记录使用侧改成软删除,增加从日志管理里删除对话记录。
1010

1111
## ⚙️ 优化
1212

document/data/doc-last-modified.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"document/content/docs/protocol/terms.en.mdx": "2025-12-15T23:36:54+08:00",
103103
"document/content/docs/protocol/terms.mdx": "2025-12-15T23:36:54+08:00",
104104
"document/content/docs/toc.en.mdx": "2025-08-04T13:42:36+08:00",
105-
"document/content/docs/toc.mdx": "2025-12-09T23:33:32+08:00",
105+
"document/content/docs/toc.mdx": "2025-12-17T17:44:38+08:00",
106106
"document/content/docs/upgrading/4-10/4100.mdx": "2025-08-02T19:38:37+08:00",
107107
"document/content/docs/upgrading/4-10/4101.mdx": "2025-09-08T20:07:20+08:00",
108108
"document/content/docs/upgrading/4-11/4110.mdx": "2025-08-05T23:20:39+08:00",
@@ -120,6 +120,7 @@
120120
"document/content/docs/upgrading/4-14/4142.mdx": "2025-11-18T19:27:14+08:00",
121121
"document/content/docs/upgrading/4-14/4143.mdx": "2025-11-26T20:52:05+08:00",
122122
"document/content/docs/upgrading/4-14/4144.mdx": "2025-12-16T14:56:04+08:00",
123+
"document/content/docs/upgrading/4-14/4145.mdx": "2025-12-17T17:44:38+08:00",
123124
"document/content/docs/upgrading/4-8/40.mdx": "2025-08-02T19:38:37+08:00",
124125
"document/content/docs/upgrading/4-8/41.mdx": "2025-08-02T19:38:37+08:00",
125126
"document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00",

packages/global/common/file/api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OutLinkChatAuthProps } from '../../support/permission/chat.d';
1+
import type { OutLinkChatAuthProps } from '../../support/permission/chat';
22

33
export type preUploadImgProps = OutLinkChatAuthProps & {
44
// expiredTime?: Date;

packages/global/core/app/logs/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const AppLogKeysEnumMap = {
3737
};
3838

3939
export const DefaultAppLogKeys = [
40-
{ key: AppLogKeysEnum.SOURCE, enable: true },
40+
{ key: AppLogKeysEnum.SOURCE, enable: false },
4141
{ key: AppLogKeysEnum.USER, enable: true },
4242
{ key: AppLogKeysEnum.TITLE, enable: true },
4343
{ key: AppLogKeysEnum.SESSION_ID, enable: false },

packages/global/core/chat/type.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export type ChatSchemaType = {
5151
hasBadFeedback?: boolean;
5252
hasUnreadGoodFeedback?: boolean;
5353
hasUnreadBadFeedback?: boolean;
54+
55+
deleteTime?: Date | null;
5456
};
5557

5658
export type ChatWithAppSchema = Omit<ChatSchemaType, 'appId'> & {
@@ -197,7 +199,7 @@ export type HistoryItemType = {
197199
};
198200
export type ChatHistoryItemType = HistoryItemType & {
199201
appId: string;
200-
top: boolean;
202+
top?: boolean;
201203
};
202204

203205
/* ------- response data ------------ */

packages/global/openapi/api.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { z } from 'zod';
22

33
export const PaginationSchema = z.object({
4-
pageSize: z.union([z.number(), z.string()]),
4+
pageSize: z.union([z.number(), z.string()]).optional(),
55
offset: z.union([z.number(), z.string()]).optional(),
66
pageNum: z.union([z.number(), z.string()]).optional()
77
});
8+
export type PaginationType = z.infer<typeof PaginationSchema>;
9+
10+
export const PaginationResponseSchema = <T extends z.ZodTypeAny>(itemSchema: T) =>
11+
z.object({
12+
total: z.number().optional().default(0),
13+
list: z.array(itemSchema).optional().default([])
14+
});
15+
export type PaginationResponseType<T extends z.ZodTypeAny> = z.infer<
16+
ReturnType<typeof PaginationResponseSchema<T>>
17+
>;

packages/global/openapi/core/app/log/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const ChatLogItemSchema = z.object({
3434
title: z.string().optional().meta({ example: '用户对话', description: '对话标题' }),
3535
customTitle: z.string().nullish().meta({ example: '自定义标题', description: '自定义对话标题' }),
3636
source: z.enum(ChatSourceEnum).meta({ example: ChatSourceEnum.api, description: '对话来源' }),
37-
sourceName: z.string().optional().meta({ example: 'API调用', description: '来源名称' }),
37+
sourceName: z.string().nullish().meta({ example: 'API调用', description: '来源名称' }),
3838
updateTime: z.date().meta({ example: '2024-01-01T00:30:00.000Z', description: '更新时间' }),
3939
createTime: z.date().meta({ example: '2024-01-01T00:00:00.000Z', description: '创建时间' }),
4040
messageCount: z.int().nullish().meta({ example: 10, description: '消息数量' }),
@@ -50,7 +50,7 @@ export const ChatLogItemSchema = z.object({
5050
totalPoints: z.number().nullish().meta({ example: 150.5, description: '总积分消耗' }),
5151
outLinkUid: z.string().nullish().meta({ example: 'outLink123', description: '外链用户 ID' }),
5252
tmbId: z.string().nullish().meta({ example: 'tmb123', description: '团队成员 ID' }),
53-
sourceMember: SourceMemberSchema.optional().meta({ description: '来源成员信息' }),
53+
sourceMember: SourceMemberSchema.nullish().meta({ description: '来源成员信息' }),
5454
versionName: z.string().nullish().meta({ example: 'v1.0.0', description: '版本名称' }),
5555
region: z.string().nullish().meta({ example: '中国', description: '区域' })
5656
});

packages/global/openapi/core/chat/feedback/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ export const UpdateUserFeedbackBodySchema = z.object({
105105
example: 'data123',
106106
description: '消息数据 ID'
107107
}),
108-
userGoodFeedback: z.string().optional().nullable().meta({
108+
userGoodFeedback: z.string().nullish().meta({
109109
example: '回答很好',
110110
description: '用户好评反馈内容'
111111
}),
112-
userBadFeedback: z.string().optional().nullable().meta({
112+
userBadFeedback: z.string().nullish().meta({
113113
example: '回答不准确',
114114
description: '用户差评反馈内容'
115115
})
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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>;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import type { OpenAPIPath } from '../../../type';
2+
import { TagsMap } from '../../../tag';
3+
import {
4+
GetHistoriesBodySchema,
5+
GetHistoriesResponseSchema,
6+
UpdateHistoryBodySchema,
7+
ChatBatchDeleteBodySchema,
8+
DelChatHistorySchema,
9+
ClearChatHistoriesSchema
10+
} from './api';
11+
12+
export const ChatHistoryPath: OpenAPIPath = {
13+
'/core/chat/history/getHistories': {
14+
post: {
15+
summary: '获取对话历史列表',
16+
description: '分页获取指定应用的对话历史记录',
17+
tags: [TagsMap.chatHistory],
18+
requestBody: {
19+
content: {
20+
'application/json': {
21+
schema: GetHistoriesBodySchema
22+
}
23+
}
24+
},
25+
responses: {
26+
200: {
27+
description: '成功获取对话历史列表',
28+
content: {
29+
'application/json': {
30+
schema: GetHistoriesResponseSchema
31+
}
32+
}
33+
}
34+
}
35+
}
36+
},
37+
'/core/chat/history/updateHistory': {
38+
put: {
39+
summary: '修改对话历史',
40+
description: '修改对话历史的标题、自定义标题或置顶状态',
41+
tags: [TagsMap.chatHistory],
42+
requestBody: {
43+
content: {
44+
'application/json': {
45+
schema: UpdateHistoryBodySchema
46+
}
47+
}
48+
},
49+
responses: {
50+
200: {
51+
description: '成功修改对话历史'
52+
}
53+
}
54+
}
55+
},
56+
'/core/chat/history/delHistory': {
57+
delete: {
58+
summary: '删除单个对话历史',
59+
description: '软删除指定的单个对话记录',
60+
tags: [TagsMap.chatHistory],
61+
requestBody: {
62+
content: {
63+
'application/json': {
64+
schema: DelChatHistorySchema
65+
}
66+
}
67+
},
68+
responses: {
69+
200: {
70+
description: '成功删除对话'
71+
}
72+
}
73+
}
74+
},
75+
'/core/chat/history/clearHistories': {
76+
delete: {
77+
summary: '清空应用对话历史',
78+
description: '清空指定应用的所有对话记录(软删除)',
79+
tags: [TagsMap.chatHistory],
80+
requestParams: {
81+
query: ClearChatHistoriesSchema
82+
},
83+
responses: {
84+
200: {
85+
description: '成功清空对话历史'
86+
}
87+
}
88+
}
89+
},
90+
'/core/chat/history/batchDelete': {
91+
post: {
92+
summary: '批量删除对话历史',
93+
description: '批量删除指定应用的多个对话记录(真实删除),需应用日志权限。',
94+
tags: [TagsMap.chatHistory],
95+
requestBody: {
96+
content: {
97+
'application/json': {
98+
schema: ChatBatchDeleteBodySchema
99+
}
100+
}
101+
},
102+
responses: {
103+
200: {
104+
description: '成功删除对话'
105+
}
106+
}
107+
}
108+
}
109+
};

0 commit comments

Comments
 (0)