koishi-plugin-best-cave 2.7.14 → 2.7.15
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/lib/index.js +7 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1159,7 +1159,7 @@ var AIManager = class {
|
|
|
1159
1159
|
} catch (error) {
|
|
1160
1160
|
const caveIds = caves.map((c) => c.id).join(", ");
|
|
1161
1161
|
this.logger.error(`分析回声洞 (${caveIds}) 出错:`, error);
|
|
1162
|
-
|
|
1162
|
+
throw error;
|
|
1163
1163
|
}
|
|
1164
1164
|
}
|
|
1165
1165
|
/**
|
|
@@ -1251,11 +1251,14 @@ var AIManager = class {
|
|
|
1251
1251
|
};
|
|
1252
1252
|
this.requestCount++;
|
|
1253
1253
|
const response = await this.http.post(fullUrl, payload, { headers, timeout: 9e4 });
|
|
1254
|
-
const content = response
|
|
1255
|
-
|
|
1254
|
+
const content = response?.choices?.[0]?.message?.content;
|
|
1255
|
+
if (typeof content !== "string" || !content.trim()) {
|
|
1256
|
+
this.logger.error("原始响应:", JSON.stringify(response, null, 2));
|
|
1257
|
+
throw new Error("响应无效");
|
|
1258
|
+
}
|
|
1256
1259
|
try {
|
|
1257
1260
|
const jsonRegex = /```json\s*([\s\S]*?)\s*```/;
|
|
1258
|
-
const match = content
|
|
1261
|
+
const match = content.match(jsonRegex);
|
|
1259
1262
|
let jsonString = "";
|
|
1260
1263
|
if (match && match[1]) {
|
|
1261
1264
|
jsonString = match[1];
|
|
@@ -1265,7 +1268,6 @@ var AIManager = class {
|
|
|
1265
1268
|
return JSON.parse(jsonString);
|
|
1266
1269
|
} catch (error) {
|
|
1267
1270
|
this.logger.error("解析 JSON 失败:", error);
|
|
1268
|
-
this.logger.error("原始响应:", content);
|
|
1269
1271
|
throw new Error("解析失败");
|
|
1270
1272
|
}
|
|
1271
1273
|
}
|