mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-13 14:29:40 +00:00
fix: add missing MongoAppChatLog updates for interactive chat sessions (#5716)
* fix: add missing MongoAppChatLog updates for interactive chat sessions * fix: interactive response not update log * doc --------- Co-authored-by: archer <545436317@qq.com>
This commit is contained in:
@@ -14,6 +14,9 @@ description: 'FastGPT V4.13.1 更新说明'
|
||||
## 🐛 修复
|
||||
|
||||
1. 循环节点中,每轮结束,未清除上一轮交互响应值。
|
||||
2. 交互节点响应后,未更新对话记录统计数据。
|
||||
3. prompt 编辑器,弹窗中的默认值存在显示异常。
|
||||
4. 表单输入,变量名包含.符号时,无法正常输入值。
|
||||
|
||||
## 🔨 插件更新
|
||||
|
||||
|
@@ -101,7 +101,7 @@
|
||||
"document/content/docs/protocol/terms.en.mdx": "2025-08-03T22:37:45+08:00",
|
||||
"document/content/docs/protocol/terms.mdx": "2025-08-03T22:37:45+08:00",
|
||||
"document/content/docs/toc.en.mdx": "2025-08-04T13:42:36+08:00",
|
||||
"document/content/docs/toc.mdx": "2025-09-26T13:18:51+08:00",
|
||||
"document/content/docs/toc.mdx": "2025-09-26T16:01:20+08:00",
|
||||
"document/content/docs/upgrading/4-10/4100.mdx": "2025-08-02T19:38:37+08:00",
|
||||
"document/content/docs/upgrading/4-10/4101.mdx": "2025-09-08T20:07:20+08:00",
|
||||
"document/content/docs/upgrading/4-11/4110.mdx": "2025-08-05T23:20:39+08:00",
|
||||
@@ -111,7 +111,8 @@
|
||||
"document/content/docs/upgrading/4-12/4122.mdx": "2025-09-07T14:41:48+08:00",
|
||||
"document/content/docs/upgrading/4-12/4123.mdx": "2025-09-07T20:55:14+08:00",
|
||||
"document/content/docs/upgrading/4-12/4124.mdx": "2025-09-17T22:29:56+08:00",
|
||||
"document/content/docs/upgrading/4-13/4130.mdx": "2025-09-26T13:23:01+08:00",
|
||||
"document/content/docs/upgrading/4-13/4130.mdx": "2025-09-26T13:32:15+08:00",
|
||||
"document/content/docs/upgrading/4-13/4131.mdx": "2025-09-26T16:01:20+08:00",
|
||||
"document/content/docs/upgrading/4-8/40.mdx": "2025-08-02T19:38:37+08:00",
|
||||
"document/content/docs/upgrading/4-8/41.mdx": "2025-08-02T19:38:37+08:00",
|
||||
"document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00",
|
||||
|
@@ -85,26 +85,48 @@ const formatAiContent = ({
|
||||
};
|
||||
};
|
||||
|
||||
export async function saveChat({
|
||||
chatId,
|
||||
appId,
|
||||
teamId,
|
||||
tmbId,
|
||||
nodes,
|
||||
appChatConfig,
|
||||
variables,
|
||||
isUpdateUseTime,
|
||||
newTitle,
|
||||
source,
|
||||
sourceName,
|
||||
shareId,
|
||||
outLinkUid,
|
||||
userContent,
|
||||
aiContent,
|
||||
durationSeconds,
|
||||
errorMsg,
|
||||
metadata = {}
|
||||
}: Props) {
|
||||
const getChatDataLog = async ({
|
||||
nodeResponses
|
||||
}: {
|
||||
nodeResponses: ReturnType<typeof formatAiContent>['nodeResponses'];
|
||||
}) => {
|
||||
const now = new Date();
|
||||
const fifteenMinutesAgo = new Date(now.getTime() - 15 * 60 * 1000);
|
||||
|
||||
const errorCount = nodeResponses?.some((item) => item.errorText) ? 1 : 0;
|
||||
const totalPoints =
|
||||
nodeResponses?.reduce((sum: number, item: any) => sum + (item.totalPoints || 0), 0) || 0;
|
||||
|
||||
return {
|
||||
fifteenMinutesAgo,
|
||||
errorCount,
|
||||
totalPoints,
|
||||
now
|
||||
};
|
||||
};
|
||||
|
||||
export async function saveChat(props: Props) {
|
||||
const {
|
||||
chatId,
|
||||
appId,
|
||||
teamId,
|
||||
tmbId,
|
||||
nodes,
|
||||
appChatConfig,
|
||||
variables,
|
||||
isUpdateUseTime,
|
||||
newTitle,
|
||||
source,
|
||||
sourceName,
|
||||
shareId,
|
||||
outLinkUid,
|
||||
userContent,
|
||||
aiContent,
|
||||
durationSeconds,
|
||||
errorMsg,
|
||||
metadata = {}
|
||||
} = props;
|
||||
|
||||
if (!chatId || chatId === 'NO_RECORD_HISTORIES') return;
|
||||
|
||||
try {
|
||||
@@ -204,13 +226,10 @@ export async function saveChat({
|
||||
|
||||
// Create chat data log
|
||||
try {
|
||||
const { fifteenMinutesAgo, errorCount, totalPoints, now } = await getChatDataLog({
|
||||
nodeResponses
|
||||
});
|
||||
const userId = String(outLinkUid || tmbId);
|
||||
const now = new Date();
|
||||
const fifteenMinutesAgo = new Date(now.getTime() - 15 * 60 * 1000);
|
||||
|
||||
const errorCount = nodeResponses?.some((item) => item.errorText) ? 1 : 0;
|
||||
const totalPoints =
|
||||
nodeResponses?.reduce((sum: number, item: any) => sum + (item.totalPoints || 0), 0) || 0;
|
||||
|
||||
const hasHistoryChat = await MongoAppChatLog.exists({
|
||||
teamId,
|
||||
@@ -255,7 +274,7 @@ export async function saveChat({
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
addLog.error('update chat log error', error);
|
||||
addLog.error('Push chat log error', error);
|
||||
}
|
||||
|
||||
if (isUpdateUseTime) {
|
||||
@@ -277,7 +296,6 @@ export async function saveChat({
|
||||
export const updateInteractiveChat = async ({
|
||||
teamId,
|
||||
chatId,
|
||||
|
||||
appId,
|
||||
userContent,
|
||||
aiContent,
|
||||
@@ -405,4 +423,36 @@ export const updateInteractiveChat = async ({
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Push chat data logs
|
||||
try {
|
||||
const { fifteenMinutesAgo, errorCount, totalPoints, now } = await getChatDataLog({
|
||||
nodeResponses
|
||||
});
|
||||
|
||||
await MongoAppChatLog.updateOne(
|
||||
{
|
||||
teamId,
|
||||
appId,
|
||||
chatId,
|
||||
updateTime: { $gte: fifteenMinutesAgo }
|
||||
},
|
||||
{
|
||||
$inc: {
|
||||
chatItemCount: 1,
|
||||
errorCount,
|
||||
totalPoints,
|
||||
totalResponseTime: durationSeconds
|
||||
},
|
||||
$set: {
|
||||
updateTime: now
|
||||
}
|
||||
},
|
||||
{
|
||||
...writePrimary
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
addLog.error('update interactive chat log error', error);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user