koishi-plugin-aka-ai-generator 0.0.4 → 0.0.5

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 +38 -2
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -415,6 +415,34 @@ var GptGodProvider = class {
415
415
  }
416
416
  );
417
417
  logger.success("GPTGod 图像编辑 API 调用成功");
418
+ if (response?.choices?.length > 0) {
419
+ const firstChoice = response.choices[0];
420
+ const messageContent = firstChoice.message?.content;
421
+ let errorMessage = "";
422
+ if (typeof messageContent === "string") {
423
+ errorMessage = messageContent;
424
+ } else if (Array.isArray(messageContent)) {
425
+ const textParts = messageContent.filter((part) => part?.type === "text" && part?.text).map((part) => part.text).join(" ");
426
+ errorMessage = textParts;
427
+ } else if (messageContent?.text) {
428
+ errorMessage = messageContent.text;
429
+ }
430
+ if (errorMessage && (errorMessage.includes("PROHIBITED_CONTENT") || errorMessage.includes("blocked by Google Gemini") || errorMessage.includes("prohibited under official usage policies") || errorMessage.toLowerCase().includes("content is prohibited"))) {
431
+ logger.error("内容被 Google Gemini 政策拦截", {
432
+ errorMessage: errorMessage.substring(0, 200),
433
+ finishReason: firstChoice.finish_reason
434
+ });
435
+ throw new Error("内容被安全策略拦截");
436
+ }
437
+ if (errorMessage && (errorMessage.toLowerCase().includes("error") || errorMessage.toLowerCase().includes("failed") || errorMessage.toLowerCase().includes("blocked")) && !errorMessage.match(/https?:\/\//)) {
438
+ logger.error("API 返回错误消息", {
439
+ errorMessage: errorMessage.substring(0, 200),
440
+ finishReason: firstChoice.finish_reason
441
+ });
442
+ const shortError = errorMessage.length > 50 ? errorMessage.substring(0, 50) + "..." : errorMessage;
443
+ throw new Error(`处理失败:${shortError}`);
444
+ }
445
+ }
418
446
  if (this.config.logLevel === "debug") {
419
447
  logger.debug("GPTGod API 响应结构", {
420
448
  hasChoices: !!response?.choices,
@@ -435,6 +463,14 @@ var GptGodProvider = class {
435
463
  warnData.responsePreview = JSON.stringify(response).substring(0, 500);
436
464
  }
437
465
  logger.warn("生成的图片数量不足", warnData);
466
+ if (images.length === 0 && response?.choices?.[0]?.message?.content) {
467
+ const content = response.choices[0].message.content;
468
+ const contentText = typeof content === "string" ? content : Array.isArray(content) ? content.map((p) => p?.text || "").join(" ") : "";
469
+ if (contentText && !contentText.match(/https?:\/\//)) {
470
+ const shortError = contentText.length > 50 ? contentText.substring(0, 50) + "..." : contentText;
471
+ throw new Error(`生成失败:${shortError}`);
472
+ }
473
+ }
438
474
  }
439
475
  return images;
440
476
  } catch (error) {
@@ -950,7 +986,7 @@ function apply(ctx, config) {
950
986
  if (activeTasks.has(userId)) {
951
987
  return "您有一个图像处理任务正在进行中,请等待完成";
952
988
  }
953
- await session.send('请发送一张图片和prompt,支持两种方式:\n1. 同时发送:[图片] + prompt描述\n2. 分步发送:先发送一张图片,再发送prompt文字\n\n例如:[图片] 让这张图片变成油画风格\n\n注意:本功能仅支持处理一张图片,多张图片请使用"合成图像"命令');
989
+ await session.send('图片+描述\n\n多张图片使用"合成图像"指令');
954
990
  const collectedImages = [];
955
991
  let prompt = "";
956
992
  while (true) {
@@ -1055,7 +1091,7 @@ Prompt: ${prompt}`);
1055
1091
  if (activeTasks.has(userId)) {
1056
1092
  return "您有一个图像处理任务正在进行中,请等待完成";
1057
1093
  }
1058
- await session.send("请发送多张图片和prompt,支持两种方式:\n1. 同时发送:[图片1] [图片2]... + prompt描述\n2. 分步发送:先发送多张图片,再发送prompt文字\n\n例如:[图片1] [图片2] 将这两张图片合成一张");
1094
+ await session.send("多张图片+描述");
1059
1095
  const collectedImages = [];
1060
1096
  let prompt = "";
1061
1097
  while (true) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-aka-ai-generator",
3
3
  "description": "自用AI生成插件(GPTGod & Yunwu)",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [