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

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 +51 -3
  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,9 +463,20 @@ 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) {
477
+ if (error?.message && (error.message.includes("内容被安全策略拦截") || error.message.includes("生成失败") || error.message.includes("处理失败"))) {
478
+ throw error;
479
+ }
441
480
  logger.error("GPTGod 图像编辑 API 调用失败", {
442
481
  message: error?.message || "未知错误",
443
482
  code: error?.code,
@@ -530,7 +569,7 @@ var Config = import_koishi.Schema.intersect([
530
569
  {
531
570
  commandName: "变写实",
532
571
  commandDescription: "以真实摄影风格重建主体",
533
- prompt: "请根据用户提供的图片,在保持主体身份、外观与姿态的前提下生成一张超写实的摄影作品。确保光影、皮肤质感、服饰纹理与背景环境都贴近真实世界,可以适度优化噪点与瑕疵,但不要改变主体特征或添加额外元素,整体效果需像专业摄影棚拍摄。",
572
+ prompt: "请根据用户提供的图片,在保持主体身份、外观与姿态的前提下生成一张超写实的摄影作品。采用Ultra-realistic 3D rendered风格,确保光影、皮肤质感、服饰纹理与背景环境都贴近真实世界。画面应呈现raw and natural的原始自然感,具有authentic film snapshot的真实胶片质感。使用strong contrast between light and dark营造强烈明暗对比,产生deep shadows深阴影效果。整体需具备tactile feel触感质感和simulated texture模拟纹理细节,可以适度优化噪点与瑕疵,但不要改变主体特征或添加额外元素,整体效果需像专业摄影棚拍摄的真实照片。",
534
573
  enabled: true
535
574
  },
536
575
  {
@@ -918,6 +957,9 @@ function apply(ctx, config) {
918
957
  } catch (error) {
919
958
  activeTasks.delete(userId);
920
959
  logger.error("图像处理失败", { userId, error });
960
+ if (error?.message && (error.message.includes("内容被安全策略拦截") || error.message.includes("生成失败") || error.message.includes("处理失败"))) {
961
+ return error.message;
962
+ }
921
963
  return "图像处理失败,请稍后重试";
922
964
  }
923
965
  }
@@ -950,7 +992,7 @@ function apply(ctx, config) {
950
992
  if (activeTasks.has(userId)) {
951
993
  return "您有一个图像处理任务正在进行中,请等待完成";
952
994
  }
953
- await session.send('请发送一张图片和prompt,支持两种方式:\n1. 同时发送:[图片] + prompt描述\n2. 分步发送:先发送一张图片,再发送prompt文字\n\n例如:[图片] 让这张图片变成油画风格\n\n注意:本功能仅支持处理一张图片,多张图片请使用"合成图像"命令');
995
+ await session.send('图片+描述\n\n多张图片使用"合成图像"指令');
954
996
  const collectedImages = [];
955
997
  let prompt = "";
956
998
  while (true) {
@@ -1029,6 +1071,9 @@ Prompt: ${prompt}`);
1029
1071
  } catch (error) {
1030
1072
  activeTasks.delete(userId);
1031
1073
  logger.error("自定义图像处理失败", { userId, error });
1074
+ if (error?.message && (error.message.includes("内容被安全策略拦截") || error.message.includes("生成失败") || error.message.includes("处理失败"))) {
1075
+ return error.message;
1076
+ }
1032
1077
  return "图像处理失败,请稍后重试";
1033
1078
  }
1034
1079
  })(),
@@ -1055,7 +1100,7 @@ Prompt: ${prompt}`);
1055
1100
  if (activeTasks.has(userId)) {
1056
1101
  return "您有一个图像处理任务正在进行中,请等待完成";
1057
1102
  }
1058
- await session.send("请发送多张图片和prompt,支持两种方式:\n1. 同时发送:[图片1] [图片2]... + prompt描述\n2. 分步发送:先发送多张图片,再发送prompt文字\n\n例如:[图片1] [图片2] 将这两张图片合成一张");
1103
+ await session.send("多张图片+描述");
1059
1104
  const collectedImages = [];
1060
1105
  let prompt = "";
1061
1106
  while (true) {
@@ -1125,6 +1170,9 @@ Prompt: ${prompt}`);
1125
1170
  } catch (error) {
1126
1171
  activeTasks.delete(userId);
1127
1172
  logger.error("图片合成失败", { userId, error });
1173
+ if (error?.message && (error.message.includes("内容被安全策略拦截") || error.message.includes("生成失败") || error.message.includes("处理失败"))) {
1174
+ return error.message;
1175
+ }
1128
1176
  return "图片合成失败,请稍后重试";
1129
1177
  }
1130
1178
  })(),
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.6",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [