koishi-plugin-best-cave 2.7.13 → 2.7.14

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.
@@ -78,7 +78,7 @@ export declare class AIManager {
78
78
  * @description 为一批回声洞准备内容,并向 AI 发送单个请求以获取所有分析结果。
79
79
  * @param {CaveObject[]} caves - 要分析的回声洞对象数组。
80
80
  * @param {Map<string, Buffer>} [mediaBufferMap] - 可选的媒体文件名到其缓冲区的映射。
81
- * @returns {Promise<AnalysisResult[]>} 一个 Promise,解析为 AI 返回的分析结果数组。
81
+ * @returns {Promise<CaveMetaObject[]>} 一个 Promise,解析为 AI 返回的分析结果数组。
82
82
  */
83
83
  private getAnalyses;
84
84
  /**
package/lib/index.js CHANGED
@@ -1149,7 +1149,7 @@ var AIManager = class {
1149
1149
  const results = await this.getAnalyses(caves, mediaMap);
1150
1150
  if (!results?.length) return 0;
1151
1151
  const caveMetaObjects = results.map((res) => ({
1152
- cave: res.id,
1152
+ cave: res.cave,
1153
1153
  keywords: res.keywords || [],
1154
1154
  description: res.description || "",
1155
1155
  rating: Math.max(0, Math.min(100, res.rating || 0))
@@ -1190,7 +1190,7 @@ var AIManager = class {
1190
1190
  * @description 为一批回声洞准备内容,并向 AI 发送单个请求以获取所有分析结果。
1191
1191
  * @param {CaveObject[]} caves - 要分析的回声洞对象数组。
1192
1192
  * @param {Map<string, Buffer>} [mediaBufferMap] - 可选的媒体文件名到其缓冲区的映射。
1193
- * @returns {Promise<AnalysisResult[]>} 一个 Promise,解析为 AI 返回的分析结果数组。
1193
+ * @returns {Promise<CaveMetaObject[]>} 一个 Promise,解析为 AI 返回的分析结果数组。
1194
1194
  */
1195
1195
  async getAnalyses(caves, mediaBufferMap) {
1196
1196
  const batchPayload = await Promise.all(caves.map(async (cave) => {
@@ -1214,7 +1214,12 @@ var AIManager = class {
1214
1214
  const userMessage = { role: "user", content: JSON.stringify(nonEmptyPayload) };
1215
1215
  const analysePrompt = `你是一位内容分析专家。请使用中文,分析我以JSON格式提供的一组内容,为每一项内容总结关键词、概括内容并评分。你的回复必须且只能是一个包裹在 \`\`\`json ... \`\`\` 代码块中的有效 JSON 对象。该JSON对象应有一个 "analyses" 键,其值为一个数组。数组中的每个对象都必须包含 "id" (整数), "keywords" (字符串数组), "description" (字符串), 和 "rating" (0-100的整数)。`;
1216
1216
  const response = await this.requestAI([userMessage], analysePrompt);
1217
- return response.analyses || [];
1217
+ return (response.analyses || []).map((res) => ({
1218
+ cave: res.id,
1219
+ keywords: res.keywords,
1220
+ description: res.description,
1221
+ rating: res.rating
1222
+ }));
1218
1223
  }
1219
1224
  /**
1220
1225
  * @description 封装了向 OpenAI 兼容的 API 发送请求的底层逻辑,并稳健地解析 JSON 响应。
@@ -1247,10 +1252,10 @@ var AIManager = class {
1247
1252
  this.requestCount++;
1248
1253
  const response = await this.http.post(fullUrl, payload, { headers, timeout: 9e4 });
1249
1254
  const content = response.choices?.[0]?.message?.content;
1250
- if (typeof content !== "string" || !content.trim()) throw new Error("响应无效");
1255
+ this.logger.info("原始响应:", content);
1251
1256
  try {
1252
1257
  const jsonRegex = /```json\s*([\s\S]*?)\s*```/;
1253
- const match = content.match(jsonRegex);
1258
+ const match = content?.match(jsonRegex);
1254
1259
  let jsonString = "";
1255
1260
  if (match && match[1]) {
1256
1261
  jsonString = match[1];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "功能强大、高度可定制的回声洞。支持丰富的媒体类型、内容查重、人工审核、用户昵称、数据迁移以及本地/S3 双重文件存储后端。",
4
- "version": "2.7.13",
4
+ "version": "2.7.14",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],