koishi-plugin-best-cave 2.7.26 → 2.7.27

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.
@@ -40,15 +40,6 @@ export declare class AIManager {
40
40
  * @param {any} cave - 主命令的实例,用于挂载子命令。
41
41
  */
42
42
  registerCommands(cave: any): void;
43
- /**
44
- * @description 递归处理和分析回声洞批次,失败时按 1/5 拆分以定位问题。
45
- * @param {CaveObject[]} caves - 当前要处理的回声洞对象数组。
46
- * @param {number} totalCaves - 要分析的回声洞总数。
47
- * @param {{ count: number }} progress - 用于跟踪总体进度的计数器对象。
48
- * @returns {Promise<number>} 成功分析的回声洞数量。
49
- * @private
50
- */
51
- private processCaveBatch;
52
43
  /**
53
44
  * @description 对新提交的内容执行 AI 驱动的查重检查。
54
45
  * @param {StoredElement[]} newElements - 新提交的内容元素数组。
package/lib/index.js CHANGED
@@ -1154,16 +1154,33 @@ var AIManager = class {
1154
1154
  if (cavesToAnalyze.length === 0) return "无需分析回声洞";
1155
1155
  await session.send(`开始分析 ${cavesToAnalyze.length} 个回声洞...`);
1156
1156
  let successCount = 0;
1157
- const totalToAnalyze = cavesToAnalyze.length;
1158
- const progress = { count: 0 };
1159
- const batchSize = 25;
1160
- for (let i = 0; i < cavesToAnalyze.length; i += batchSize) {
1161
- const batch = cavesToAnalyze.slice(i, i + batchSize);
1157
+ let failedCount = 0;
1158
+ let consecutiveFailures = 0;
1159
+ for (let i = 0; i < cavesToAnalyze.length; i += 25) {
1160
+ const batch = cavesToAnalyze.slice(i, i + 25);
1162
1161
  this.logger.info(`[${i + 1}/${cavesToAnalyze.length}] 正在分析 ${batch.length} 个回声洞...`);
1163
- successCount += await this.processCaveBatch(batch, totalToAnalyze, progress);
1162
+ const analysisPromises = batch.map((cave2) => this.analyze([cave2]));
1163
+ const results = await Promise.allSettled(analysisPromises);
1164
+ const successfulAnalyses = [];
1165
+ for (let j = 0; j < results.length; j++) {
1166
+ const result = results[j];
1167
+ const cave2 = batch[j];
1168
+ if (result.status === "fulfilled" && result.value.length > 0) {
1169
+ successfulAnalyses.push(result.value[0]);
1170
+ consecutiveFailures = 0;
1171
+ } else {
1172
+ failedCount++;
1173
+ consecutiveFailures++;
1174
+ if (result.status === "rejected") this.logger.error(`分析回声洞(${cave2.id})失败:`, result.reason);
1175
+ }
1176
+ }
1177
+ if (successfulAnalyses.length > 0) {
1178
+ await this.ctx.database.upsert("cave_meta", successfulAnalyses);
1179
+ successCount += successfulAnalyses.length;
1180
+ }
1181
+ if (consecutiveFailures >= 3) break;
1164
1182
  }
1165
- const failedCount = totalToAnalyze - successCount;
1166
- if (failedCount > 0) return `已分析 ${successCount} 个回声洞(失败 ${failedCount} 个)`;
1183
+ return `已分析 ${successCount} 个回声洞(失败 ${failedCount} 个)`;
1167
1184
  } catch (error) {
1168
1185
  this.logger.error("分析回声洞失败:", error);
1169
1186
  return `操作失败: ${error.message}`;
@@ -1217,38 +1234,6 @@ var AIManager = class {
1217
1234
  }
1218
1235
  });
1219
1236
  }
1220
- /**
1221
- * @description 递归处理和分析回声洞批次,失败时按 1/5 拆分以定位问题。
1222
- * @param {CaveObject[]} caves - 当前要处理的回声洞对象数组。
1223
- * @param {number} totalCaves - 要分析的回声洞总数。
1224
- * @param {{ count: number }} progress - 用于跟踪总体进度的计数器对象。
1225
- * @returns {Promise<number>} 成功分析的回声洞数量。
1226
- * @private
1227
- */
1228
- async processCaveBatch(caves, totalCaves, progress) {
1229
- if (caves.length === 0) return 0;
1230
- this.logger.info(`[${progress.count + 1}/${totalCaves}] 正在分析回声洞(${caves.map((c) => c.id).join("|")})...`);
1231
- try {
1232
- const analyses = await this.analyze(caves);
1233
- if (analyses.length > 0) await this.ctx.database.upsert("cave_meta", analyses);
1234
- progress.count += caves.length;
1235
- return analyses.length;
1236
- } catch (error) {
1237
- if (caves.length > 1) {
1238
- const subBatches = [];
1239
- const subBatchSize = Math.ceil(caves.length / 5);
1240
- for (let i = 0; i < caves.length; i += subBatchSize) subBatches.push(caves.slice(i, i + subBatchSize));
1241
- const processingPromises = subBatches.map((subBatch) => this.processCaveBatch(subBatch, totalCaves, progress));
1242
- const results = await Promise.all(processingPromises);
1243
- return results.reduce((sum, count) => sum + count, 0);
1244
- } else {
1245
- const failedCave = caves[0];
1246
- progress.count++;
1247
- this.logger.error(`[${progress.count}/${totalCaves}] 分析回声洞(${failedCave.id})失败:`, error);
1248
- return 0;
1249
- }
1250
- }
1251
- }
1252
1237
  /**
1253
1238
  * @description 对新提交的内容执行 AI 驱动的查重检查。
1254
1239
  * @param {StoredElement[]} newElements - 新提交的内容元素数组。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "功能强大、高度可定制的回声洞插件。支持丰富的媒体类型、内容查重、AI分析、人工审核、用户昵称、数据迁移以及本地/S3 双重文件存储后端。",
4
- "version": "2.7.26",
4
+ "version": "2.7.27",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],