koishi-plugin-best-cave 2.7.33 → 2.7.35

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.
Files changed (2) hide show
  1. package/lib/index.js +24 -11
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1118,12 +1118,12 @@ var AIManager = class {
1118
1118
  * @description 用于分析的 AI 系统提示词。
1119
1119
  */
1120
1120
  ANALYSIS_SYSTEM_PROMPT = `你需要分析给定的内容,并按照以下规则进行评分、分类和提取内容中的关键词。
1121
- 你的回复必须且只能是一个JSON对象,禁止含有任何其他内容,例如{"rating": 88,"type": "Game","keywords": ["Minecraft", "Nether"]}。`;
1121
+ 你的回复必须且只能是一个JSON对象,禁止含有解释说明等其他文字,只包含rating、type和keywords,例如{"rating": 88,"type": "Game","keywords": ["Minecraft", "Nether"]}。`;
1122
1122
  /**
1123
1123
  * @description 用于查重的 AI 系统提示词。
1124
1124
  */
1125
1125
  DUPLICATE_SYSTEM_PROMPT = `你需要比较给定的“新内容”与“候选内容”,识别内容语义或核心思想重复的候选内容。
1126
- 你的回复必须且只能是一个JSON数组,禁止含有任何其他内容,只包含重复项ID,例如[1, 2],若无重复,则返回[]。`;
1126
+ 你的回复必须且只能是一个JSON数组,禁止含有解释说明等其他文字,只包含重复项ID,例如[1, 2],若无重复,则返回[]。`;
1127
1127
  /**
1128
1128
  * @description 注册与 AI 功能相关的管理命令。
1129
1129
  * @param {any} cave - \`cave\` 命令的实例,用于挂载子命令。
@@ -1366,18 +1366,31 @@ ${candidatesText}`;
1366
1366
  const response = await this.http.post(fullUrl, payload, { headers, timeout: 6e5 });
1367
1367
  const content = response?.choices?.[0]?.message?.content;
1368
1368
  if (!content?.trim()) throw new Error();
1369
- try {
1370
- const jsonBlockMatch = content.match(/```json\s*([\s\S]*?)\s*```/i);
1371
- const jsonString = jsonBlockMatch ? jsonBlockMatch[1] : content;
1372
- this.failureCount = 0;
1373
- return JSON.parse(jsonString);
1374
- } catch (e) {
1375
- this.logger.error("原始响应:", JSON.stringify(response, null, 2));
1376
- throw new Error();
1369
+ const potentialStrings = /* @__PURE__ */ new Set();
1370
+ const jsonBlockMatch = content.match(/```json\s*([\s\S]*?)\s*```/i);
1371
+ if (jsonBlockMatch?.[1]) potentialStrings.add(jsonBlockMatch[1]);
1372
+ const firstBrace = content.indexOf("{");
1373
+ const lastBrace = content.lastIndexOf("}");
1374
+ const firstBracket = content.indexOf("[");
1375
+ const lastBracket = content.lastIndexOf("]");
1376
+ if (firstBrace !== -1 && (firstBracket === -1 || firstBrace < firstBracket)) {
1377
+ if (lastBrace > firstBrace) potentialStrings.add(content.substring(firstBrace, lastBrace + 1));
1378
+ } else if (firstBracket !== -1) {
1379
+ if (lastBracket > firstBracket) potentialStrings.add(content.substring(firstBracket, lastBracket + 1));
1380
+ }
1381
+ potentialStrings.add(content);
1382
+ for (const jsonString of potentialStrings) {
1383
+ try {
1384
+ const result = JSON.parse(jsonString);
1385
+ this.failureCount = 0;
1386
+ return result;
1387
+ } catch (e) {
1388
+ }
1377
1389
  }
1390
+ this.logger.error("原始响应:", JSON.stringify(response, null, 2));
1391
+ throw new Error();
1378
1392
  } catch (error) {
1379
1393
  this.failureCount++;
1380
- this.logger.warn(`请求失败: ${error.message}`);
1381
1394
  if (this.failureCount >= 3) this.retryTime = Date.now() + 6e4;
1382
1395
  throw error;
1383
1396
  }
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.33",
4
+ "version": "2.7.35",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],