smart-image-scraper-mcp 2.9.3 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/services/orchestrator.js +25 -7
package/package.json
CHANGED
|
@@ -403,7 +403,7 @@ export class Orchestrator {
|
|
|
403
403
|
const options = { size, safeSearch, aspect, targetSize, fit, position };
|
|
404
404
|
|
|
405
405
|
const startTime = Date.now();
|
|
406
|
-
|
|
406
|
+
let keywords = this.parseKeywords(query);
|
|
407
407
|
|
|
408
408
|
if (keywords.length === 0) {
|
|
409
409
|
return {
|
|
@@ -412,6 +412,13 @@ export class Orchestrator {
|
|
|
412
412
|
};
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
+
// 限制最大关键词数量为 10 个,避免阻塞
|
|
416
|
+
const MAX_KEYWORDS = 10;
|
|
417
|
+
if (keywords.length > MAX_KEYWORDS) {
|
|
418
|
+
logger.warn(`Too many keywords (${keywords.length}), limiting to ${MAX_KEYWORDS}`);
|
|
419
|
+
keywords = keywords.slice(0, MAX_KEYWORDS);
|
|
420
|
+
}
|
|
421
|
+
|
|
415
422
|
logger.info(`Starting task: mode=${mode}, keywords=${keywords.join(', ')}, count=${count}, source=${source}`);
|
|
416
423
|
|
|
417
424
|
// 根据模式选择处理函数
|
|
@@ -419,12 +426,23 @@ export class Orchestrator {
|
|
|
419
426
|
? this.processKeywordLink.bind(this)
|
|
420
427
|
: this.processKeywordDownload.bind(this);
|
|
421
428
|
|
|
422
|
-
//
|
|
423
|
-
const results =
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
429
|
+
// 串行处理关键词,避免阻塞事件循环
|
|
430
|
+
const results = [];
|
|
431
|
+
for (const keyword of keywords) {
|
|
432
|
+
try {
|
|
433
|
+
const result = await processFunc(keyword, count, source, options);
|
|
434
|
+
results.push(result);
|
|
435
|
+
// 让出事件循环,确保 MCP 通信不被阻塞
|
|
436
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
437
|
+
} catch (error) {
|
|
438
|
+
results.push({
|
|
439
|
+
keyword,
|
|
440
|
+
success: false,
|
|
441
|
+
error: error.message,
|
|
442
|
+
duration: 0,
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
428
446
|
|
|
429
447
|
// 汇总结果
|
|
430
448
|
const successResults = results.filter(r => r.success);
|