Skip to content

Commit 5a2ba5a

Browse files
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 <[email protected]>
1 parent ce3556c commit 5a2ba5a

File tree

3 files changed

+84
-30
lines changed

3 files changed

+84
-30
lines changed

document/content/docs/upgrading/4-13/4131.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ description: 'FastGPT V4.13.1 更新说明'
1414
## 🐛 修复
1515

1616
1. 循环节点中,每轮结束,未清除上一轮交互响应值。
17+
2. 交互节点响应后,未更新对话记录统计数据。
18+
3. prompt 编辑器,弹窗中的默认值存在显示异常。
19+
4. 表单输入,变量名包含.符号时,无法正常输入值。
1720

1821
## 🔨 插件更新
1922

document/data/doc-last-modified.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"document/content/docs/protocol/terms.en.mdx": "2025-08-03T22:37:45+08:00",
102102
"document/content/docs/protocol/terms.mdx": "2025-08-03T22:37:45+08:00",
103103
"document/content/docs/toc.en.mdx": "2025-08-04T13:42:36+08:00",
104-
"document/content/docs/toc.mdx": "2025-09-26T13:18:51+08:00",
104+
"document/content/docs/toc.mdx": "2025-09-26T16:01:20+08:00",
105105
"document/content/docs/upgrading/4-10/4100.mdx": "2025-08-02T19:38:37+08:00",
106106
"document/content/docs/upgrading/4-10/4101.mdx": "2025-09-08T20:07:20+08:00",
107107
"document/content/docs/upgrading/4-11/4110.mdx": "2025-08-05T23:20:39+08:00",
@@ -111,7 +111,8 @@
111111
"document/content/docs/upgrading/4-12/4122.mdx": "2025-09-07T14:41:48+08:00",
112112
"document/content/docs/upgrading/4-12/4123.mdx": "2025-09-07T20:55:14+08:00",
113113
"document/content/docs/upgrading/4-12/4124.mdx": "2025-09-17T22:29:56+08:00",
114-
"document/content/docs/upgrading/4-13/4130.mdx": "2025-09-26T13:23:01+08:00",
114+
"document/content/docs/upgrading/4-13/4130.mdx": "2025-09-26T13:32:15+08:00",
115+
"document/content/docs/upgrading/4-13/4131.mdx": "2025-09-26T16:01:20+08:00",
115116
"document/content/docs/upgrading/4-8/40.mdx": "2025-08-02T19:38:37+08:00",
116117
"document/content/docs/upgrading/4-8/41.mdx": "2025-08-02T19:38:37+08:00",
117118
"document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00",

packages/service/core/chat/saveChat.ts

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,48 @@ const formatAiContent = ({
8585
};
8686
};
8787

88-
export async function saveChat({
89-
chatId,
90-
appId,
91-
teamId,
92-
tmbId,
93-
nodes,
94-
appChatConfig,
95-
variables,
96-
isUpdateUseTime,
97-
newTitle,
98-
source,
99-
sourceName,
100-
shareId,
101-
outLinkUid,
102-
userContent,
103-
aiContent,
104-
durationSeconds,
105-
errorMsg,
106-
metadata = {}
107-
}: Props) {
88+
const getChatDataLog = async ({
89+
nodeResponses
90+
}: {
91+
nodeResponses: ReturnType<typeof formatAiContent>['nodeResponses'];
92+
}) => {
93+
const now = new Date();
94+
const fifteenMinutesAgo = new Date(now.getTime() - 15 * 60 * 1000);
95+
96+
const errorCount = nodeResponses?.some((item) => item.errorText) ? 1 : 0;
97+
const totalPoints =
98+
nodeResponses?.reduce((sum: number, item: any) => sum + (item.totalPoints || 0), 0) || 0;
99+
100+
return {
101+
fifteenMinutesAgo,
102+
errorCount,
103+
totalPoints,
104+
now
105+
};
106+
};
107+
108+
export async function saveChat(props: Props) {
109+
const {
110+
chatId,
111+
appId,
112+
teamId,
113+
tmbId,
114+
nodes,
115+
appChatConfig,
116+
variables,
117+
isUpdateUseTime,
118+
newTitle,
119+
source,
120+
sourceName,
121+
shareId,
122+
outLinkUid,
123+
userContent,
124+
aiContent,
125+
durationSeconds,
126+
errorMsg,
127+
metadata = {}
128+
} = props;
129+
108130
if (!chatId || chatId === 'NO_RECORD_HISTORIES') return;
109131

110132
try {
@@ -204,13 +226,10 @@ export async function saveChat({
204226

205227
// Create chat data log
206228
try {
229+
const { fifteenMinutesAgo, errorCount, totalPoints, now } = await getChatDataLog({
230+
nodeResponses
231+
});
207232
const userId = String(outLinkUid || tmbId);
208-
const now = new Date();
209-
const fifteenMinutesAgo = new Date(now.getTime() - 15 * 60 * 1000);
210-
211-
const errorCount = nodeResponses?.some((item) => item.errorText) ? 1 : 0;
212-
const totalPoints =
213-
nodeResponses?.reduce((sum: number, item: any) => sum + (item.totalPoints || 0), 0) || 0;
214233

215234
const hasHistoryChat = await MongoAppChatLog.exists({
216235
teamId,
@@ -255,7 +274,7 @@ export async function saveChat({
255274
}
256275
);
257276
} catch (error) {
258-
addLog.error('update chat log error', error);
277+
addLog.error('Push chat log error', error);
259278
}
260279

261280
if (isUpdateUseTime) {
@@ -277,7 +296,6 @@ export async function saveChat({
277296
export const updateInteractiveChat = async ({
278297
teamId,
279298
chatId,
280-
281299
appId,
282300
userContent,
283301
aiContent,
@@ -405,4 +423,36 @@ export const updateInteractiveChat = async ({
405423
);
406424
}
407425
});
426+
427+
// Push chat data logs
428+
try {
429+
const { fifteenMinutesAgo, errorCount, totalPoints, now } = await getChatDataLog({
430+
nodeResponses
431+
});
432+
433+
await MongoAppChatLog.updateOne(
434+
{
435+
teamId,
436+
appId,
437+
chatId,
438+
updateTime: { $gte: fifteenMinutesAgo }
439+
},
440+
{
441+
$inc: {
442+
chatItemCount: 1,
443+
errorCount,
444+
totalPoints,
445+
totalResponseTime: durationSeconds
446+
},
447+
$set: {
448+
updateTime: now
449+
}
450+
},
451+
{
452+
...writePrimary
453+
}
454+
);
455+
} catch (error) {
456+
addLog.error('update interactive chat log error', error);
457+
}
408458
};

0 commit comments

Comments
 (0)