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:
heheer
2025-09-27 19:43:37 +08:00
committed by GitHub
parent ce3556c240
commit 5a2ba5a340
3 changed files with 84 additions and 30 deletions

View File

@@ -14,6 +14,9 @@ description: 'FastGPT V4.13.1 更新说明'
## 🐛 修复 ## 🐛 修复
1. 循环节点中,每轮结束,未清除上一轮交互响应值。 1. 循环节点中,每轮结束,未清除上一轮交互响应值。
2. 交互节点响应后,未更新对话记录统计数据。
3. prompt 编辑器,弹窗中的默认值存在显示异常。
4. 表单输入,变量名包含.符号时,无法正常输入值。
## 🔨 插件更新 ## 🔨 插件更新

View File

@@ -101,7 +101,7 @@
"document/content/docs/protocol/terms.en.mdx": "2025-08-03T22:37:45+08:00", "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/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.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/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-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", "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/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/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-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/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/41.mdx": "2025-08-02T19:38:37+08:00",
"document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00", "document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00",

View File

@@ -85,26 +85,48 @@ const formatAiContent = ({
}; };
}; };
export async function saveChat({ const getChatDataLog = async ({
chatId, nodeResponses
appId, }: {
teamId, nodeResponses: ReturnType<typeof formatAiContent>['nodeResponses'];
tmbId, }) => {
nodes, const now = new Date();
appChatConfig, const fifteenMinutesAgo = new Date(now.getTime() - 15 * 60 * 1000);
variables,
isUpdateUseTime, const errorCount = nodeResponses?.some((item) => item.errorText) ? 1 : 0;
newTitle, const totalPoints =
source, nodeResponses?.reduce((sum: number, item: any) => sum + (item.totalPoints || 0), 0) || 0;
sourceName,
shareId, return {
outLinkUid, fifteenMinutesAgo,
userContent, errorCount,
aiContent, totalPoints,
durationSeconds, now
errorMsg, };
metadata = {} };
}: Props) {
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; if (!chatId || chatId === 'NO_RECORD_HISTORIES') return;
try { try {
@@ -204,13 +226,10 @@ export async function saveChat({
// Create chat data log // Create chat data log
try { try {
const { fifteenMinutesAgo, errorCount, totalPoints, now } = await getChatDataLog({
nodeResponses
});
const userId = String(outLinkUid || tmbId); 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({ const hasHistoryChat = await MongoAppChatLog.exists({
teamId, teamId,
@@ -255,7 +274,7 @@ export async function saveChat({
} }
); );
} catch (error) { } catch (error) {
addLog.error('update chat log error', error); addLog.error('Push chat log error', error);
} }
if (isUpdateUseTime) { if (isUpdateUseTime) {
@@ -277,7 +296,6 @@ export async function saveChat({
export const updateInteractiveChat = async ({ export const updateInteractiveChat = async ({
teamId, teamId,
chatId, chatId,
appId, appId,
userContent, userContent,
aiContent, 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);
}
}; };