Skip to content

Commit fd2e0bd

Browse files
authored
fix: toolresponse result (#5760)
* doc * fix: toolresponse result * fix: mongo watch * remove log
1 parent af88002 commit fd2e0bd

File tree

9 files changed

+67
-30
lines changed

9 files changed

+67
-30
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ description: 'FastGPT V4.13.1 更新说明'
1515
## 🐛 修复
1616

1717
1. LLM 模型默认支持图片,导致请求错误。
18+
2. Mongo 多副本切换时候,watch 未重新触发。
1819

1920
## 🔨 插件更新
2021

21-
1. Perplexity search 工具。
22-
2. Base64转文件工具。
23-
3. MiniMax TTS 文件生成工具。
24-
4. Openrouter nano banana 绘图工具。
25-
5. 系统工具支持配置是否需要在 Worker 中运行。
22+
1. 新增:Perplexity search 工具。
23+
2. 新增:Base64转文件工具。
24+
3. 新增:MiniMax TTS 文件生成工具。
25+
4. 新增:Openrouter nano banana 绘图工具。
26+
5. 新增:Redis 缓存操作工具。
27+
6. 新增:Tavily search 工具。
28+
7. 新增:硅基流动 qwen-image 和 qwen-image-edit 工具。
29+
8. 新增:飞书多维表格操作套件。
30+
9. 新增:Youtube 字幕提取。
31+
10. 系统工具支持配置是否需要在 Worker 中运行。

document/data/doc-last-modified.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"document/content/docs/upgrading/4-12/4124.mdx": "2025-09-17T22:29:56+08:00",
114114
"document/content/docs/upgrading/4-13/4130.mdx": "2025-09-30T16:00:10+08:00",
115115
"document/content/docs/upgrading/4-13/4131.mdx": "2025-09-30T15:47:06+08:00",
116-
"document/content/docs/upgrading/4-13/4132.mdx": "2025-10-12T00:04:51+08:00",
116+
"document/content/docs/upgrading/4-13/4132.mdx": "2025-10-13T16:16:59+08:00",
117117
"document/content/docs/upgrading/4-8/40.mdx": "2025-08-02T19:38:37+08:00",
118118
"document/content/docs/upgrading/4-8/41.mdx": "2025-08-02T19:38:37+08:00",
119119
"document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00",

packages/service/common/mongo/init.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ const maxConnecting = Math.max(30, Number(process.env.DB_MAX_LINK || 20));
77
/**
88
* connect MongoDB and init data
99
*/
10-
export async function connectMongo(db: Mongoose, url: string): Promise<Mongoose> {
10+
export async function connectMongo(props: {
11+
db: Mongoose;
12+
url: string;
13+
connectedCb?: () => void;
14+
}): Promise<Mongoose> {
15+
const { db, url, connectedCb } = props;
16+
1117
/* Connecting, connected will return */
1218
if (db.connection.readyState !== 0) {
1319
return db;
@@ -31,7 +37,7 @@ export async function connectMongo(db: Mongoose, url: string): Promise<Mongoose>
3137
RemoveListeners();
3238
await db.disconnect();
3339
await delay(1000);
34-
await connectMongo(db, url);
40+
await connectMongo(props);
3541
}
3642
} catch (error) {}
3743
});
@@ -42,7 +48,7 @@ export async function connectMongo(db: Mongoose, url: string): Promise<Mongoose>
4248
RemoveListeners();
4349
await db.disconnect();
4450
await delay(1000);
45-
await connectMongo(db, url);
51+
await connectMongo(props);
4652
}
4753
} catch (error) {}
4854
});
@@ -60,16 +66,18 @@ export async function connectMongo(db: Mongoose, url: string): Promise<Mongoose>
6066
retryReads: true
6167
};
6268

63-
db.connect(url, options);
64-
69+
await db.connect(url, options);
6570
console.log('mongo connected');
71+
72+
connectedCb?.();
73+
6674
return db;
6775
} catch (error) {
6876
addLog.error('Mongo connect error', error);
6977

7078
await db.disconnect();
7179

7280
await delay(1000);
73-
return connectMongo(db, url);
81+
return connectMongo(props);
7482
}
7583
}

packages/service/core/ai/config/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export const getSystemModelConfig = async (model: string): Promise<SystemModelIt
236236
export const watchSystemModelUpdate = () => {
237237
const changeStream = MongoSystemModel.watch();
238238

239-
changeStream.on(
239+
return changeStream.on(
240240
'change',
241241
debounce(async () => {
242242
try {

packages/service/core/workflow/dispatch/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,13 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
633633
this.chatNodeUsages = this.chatNodeUsages.concat(nodeDispatchUsages);
634634
}
635635

636-
if (toolResponses !== undefined && toolResponses !== null) {
637-
if (Array.isArray(toolResponses) && toolResponses.length === 0) return;
638-
if (
639-
!Array.isArray(toolResponses) &&
636+
if (
637+
(toolResponses !== undefined && toolResponses !== null) ||
638+
(Array.isArray(toolResponses) && toolResponses.length > 0) ||
639+
(!Array.isArray(toolResponses) &&
640640
typeof toolResponses === 'object' &&
641-
Object.keys(toolResponses).length === 0
642-
)
643-
return;
641+
Object.keys(toolResponses).length > 0)
642+
) {
644643
this.toolRunResponse = toolResponses;
645644
}
646645

projects/app/src/instrumentation.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ export async function register() {
4747
initGlobalVariables();
4848

4949
// Connect to MongoDB
50-
await connectMongo(connectionMongo, MONGO_URL);
51-
connectMongo(connectionLogMongo, MONGO_LOG_URL);
50+
await connectMongo({
51+
db: connectionMongo,
52+
url: MONGO_URL,
53+
connectedCb: () => startMongoWatch()
54+
});
55+
connectMongo({
56+
db: connectionLogMongo,
57+
url: MONGO_LOG_URL
58+
});
5259

5360
//init system config;init vector database;init root user
5461
await Promise.all([getInitConfig(), initVectorStore(), initRootUser(), loadSystemModels()]);
@@ -60,7 +67,6 @@ export async function register() {
6067
initAppTemplateTypes()
6168
]);
6269

63-
startMongoWatch();
6470
startCron();
6571
startTrainingQueue(true);
6672
trackTimerProcess();

projects/app/src/pages/api/core/app/version/publish.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,11 @@ async function handler(req: ApiRequestProps<PostPublishAppProps>, res: NextApiRe
116116
}
117117

118118
export default NextAPI(handler);
119+
120+
export const config = {
121+
api: {
122+
bodyParser: {
123+
sizeLimit: '5mb'
124+
}
125+
}
126+
};

projects/app/src/service/common/system/volumnMongoWatch.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@ import { getAppTemplatesAndLoadThem } from '@fastgpt/service/core/app/templates/
77
import { watchSystemModelUpdate } from '@fastgpt/service/core/ai/config/utils';
88
import { SystemConfigsTypeEnum } from '@fastgpt/global/common/system/config/constants';
99

10+
const changeStreams: any[] = [];
11+
1012
export const startMongoWatch = async () => {
11-
reloadConfigWatch();
12-
createDatasetTrainingMongoWatch();
13-
refetchAppTemplates();
14-
watchSystemModelUpdate();
13+
cleanupMongoWatch();
14+
console.log('Watch mongo db start');
15+
changeStreams.push(reloadConfigWatch());
16+
changeStreams.push(createDatasetTrainingMongoWatch());
17+
changeStreams.push(refetchAppTemplates());
18+
changeStreams.push(watchSystemModelUpdate());
1519
};
1620

1721
const reloadConfigWatch = () => {
1822
const changeStream = MongoSystemConfigs.watch();
1923

20-
changeStream.on('change', async (change) => {
24+
return changeStream.on('change', async (change) => {
2125
try {
2226
if (
2327
change.operationType === 'update' ||
@@ -36,7 +40,7 @@ const reloadConfigWatch = () => {
3640
const refetchAppTemplates = () => {
3741
const changeStream = MongoAppTemplate.watch();
3842

39-
changeStream.on(
43+
return changeStream.on(
4044
'change',
4145
debounce(async (change) => {
4246
setTimeout(() => {
@@ -47,3 +51,9 @@ const refetchAppTemplates = () => {
4751
}, 500)
4852
);
4953
};
54+
55+
const cleanupMongoWatch = () => {
56+
changeStreams.forEach((changeStream) => {
57+
changeStream?.close();
58+
});
59+
};

projects/app/src/service/core/dataset/training/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { datasetParseQueue } from '../queues/datasetParse';
88
export const createDatasetTrainingMongoWatch = () => {
99
const changeStream = MongoDatasetTraining.watch();
1010

11-
changeStream.on('change', async (change) => {
11+
return changeStream.on('change', async (change) => {
1212
try {
1313
if (change.operationType === 'insert') {
1414
const fullDocument = change.fullDocument as DatasetTrainingSchemaType;

0 commit comments

Comments
 (0)