koishi-plugin-best-cave 2.7.33 → 2.7.34

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 +22 -9
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -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.34",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],