koishi-plugin-aka-ai-generator 0.2.1 → 0.2.2

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 +44 -18
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -671,14 +671,23 @@ function apply(ctx, config) {
671
671
  return map;
672
672
  }
673
673
  __name(buildModelMappingIndex, "buildModelMappingIndex");
674
- function parseStyleCommandModifiers(argv) {
675
- const rawArgs = [...argv.args || []].map((arg) => typeof arg === "string" ? arg.trim() : "").filter(Boolean);
676
- if (!rawArgs.length && !argv.rest) return {};
674
+ function parseStyleCommandModifiers(argv, imgParam) {
675
+ const argsList = [...argv.args || []].map((arg) => typeof arg === "string" ? arg.trim() : "").filter(Boolean);
676
+ const restStr = typeof argv.rest === "string" ? argv.rest.trim() : "";
677
+ if (restStr) {
678
+ const restParts = restStr.split(/\s+/).filter(Boolean);
679
+ argsList.push(...restParts);
680
+ }
681
+ if (imgParam && typeof imgParam === "string" && !imgParam.startsWith("http") && !imgParam.startsWith("data:")) {
682
+ const imgParts = imgParam.split(/\s+/).filter(Boolean);
683
+ argsList.push(...imgParts);
684
+ }
685
+ if (!argsList.length) return {};
677
686
  const modifiers = { customAdditions: [] };
678
687
  const flagCandidates = [];
679
688
  let index = 0;
680
- while (index < rawArgs.length) {
681
- const token = rawArgs[index];
689
+ while (index < argsList.length) {
690
+ const token = argsList[index];
682
691
  if (!token) {
683
692
  index++;
684
693
  continue;
@@ -686,15 +695,15 @@ function apply(ctx, config) {
686
695
  const lower = token.toLowerCase();
687
696
  if (lower.startsWith("-prompt:")) {
688
697
  const promptHead = token.substring(token.indexOf(":") + 1);
689
- const restTokens = rawArgs.slice(index + 1);
698
+ const restTokens = argsList.slice(index + 1);
690
699
  modifiers.customPromptSuffix = [promptHead, ...restTokens].join(" ").trim();
691
700
  break;
692
701
  }
693
702
  if (lower === "-add") {
694
703
  index++;
695
704
  const additionTokens = [];
696
- while (index < rawArgs.length && !rawArgs[index].startsWith("-")) {
697
- additionTokens.push(rawArgs[index]);
705
+ while (index < argsList.length && !argsList[index].startsWith("-")) {
706
+ additionTokens.push(argsList[index]);
698
707
  index++;
699
708
  }
700
709
  if (additionTokens.length) {
@@ -1029,9 +1038,9 @@ function apply(ctx, config) {
1029
1038
  return await providerInstance.generateImages(prompt, imageUrls, numImages);
1030
1039
  }
1031
1040
  __name(requestProviderImages, "requestProviderImages");
1032
- async function processImageWithTimeout(session, img, prompt, styleName, requestContext) {
1041
+ async function processImageWithTimeout(session, img, prompt, styleName, requestContext, displayInfo) {
1033
1042
  return Promise.race([
1034
- processImage(session, img, prompt, styleName, requestContext),
1043
+ processImage(session, img, prompt, styleName, requestContext, displayInfo),
1035
1044
  new Promise(
1036
1045
  (_, reject) => setTimeout(() => reject(new Error("命令执行超时")), config.commandTimeout * 1e3)
1037
1046
  )
@@ -1043,7 +1052,7 @@ function apply(ctx, config) {
1043
1052
  });
1044
1053
  }
1045
1054
  __name(processImageWithTimeout, "processImageWithTimeout");
1046
- async function processImage(session, img, prompt, styleName, requestContext) {
1055
+ async function processImage(session, img, prompt, styleName, requestContext, displayInfo) {
1047
1056
  const userId = session.userId;
1048
1057
  if (activeTasks.has(userId)) {
1049
1058
  return "您有一个图像处理任务正在进行中,请等待完成";
@@ -1067,7 +1076,21 @@ function apply(ctx, config) {
1067
1076
  provider: providerType,
1068
1077
  modelId: providerModelId
1069
1078
  });
1070
- await session.send(`开始处理图片(${styleName})...`);
1079
+ let statusMessage = `开始处理图片(${styleName})`;
1080
+ const infoParts = [];
1081
+ if (displayInfo?.customAdditions && displayInfo.customAdditions.length > 0) {
1082
+ infoParts.push(`自定义内容:${displayInfo.customAdditions.join(";")}`);
1083
+ }
1084
+ if (displayInfo?.modelId) {
1085
+ const modelDesc = displayInfo.modelDescription || displayInfo.modelId;
1086
+ infoParts.push(`使用模型:${modelDesc}`);
1087
+ }
1088
+ if (infoParts.length > 0) {
1089
+ statusMessage += `
1090
+ ${infoParts.join("\n")}`;
1091
+ }
1092
+ statusMessage += "...";
1093
+ await session.send(statusMessage);
1071
1094
  try {
1072
1095
  activeTasks.set(userId, "processing");
1073
1096
  const images = await requestProviderImages(prompt, imageUrl, imageCount, requestContext);
@@ -1104,7 +1127,7 @@ function apply(ctx, config) {
1104
1127
  if (!limitCheck.allowed) {
1105
1128
  return limitCheck.message;
1106
1129
  }
1107
- const modifiers = parseStyleCommandModifiers(argv);
1130
+ const modifiers = parseStyleCommandModifiers(argv, img);
1108
1131
  const promptSegments = [style.prompt];
1109
1132
  if (modifiers.modelMapping?.promptSuffix) {
1110
1133
  promptSegments.push(modifiers.modelMapping.promptSuffix);
@@ -1125,12 +1148,15 @@ function apply(ctx, config) {
1125
1148
  if (modifiers.modelMapping?.modelId) {
1126
1149
  requestContext.modelId = modifiers.modelMapping.modelId;
1127
1150
  }
1128
- if (modifiers.modelMapping?.description) {
1129
- await session.send(`已启用 ${modifiers.modelMapping.description} 配置`);
1130
- } else if (modifiers.modelMapping?.suffix) {
1131
- await session.send(`已启用后缀「-${modifiers.modelMapping.suffix}」配置`);
1151
+ const displayInfo = {};
1152
+ if (modifiers.customAdditions && modifiers.customAdditions.length > 0) {
1153
+ displayInfo.customAdditions = modifiers.customAdditions;
1154
+ }
1155
+ if (modifiers.modelMapping?.modelId) {
1156
+ displayInfo.modelId = modifiers.modelMapping.modelId;
1157
+ displayInfo.modelDescription = modifiers.modelMapping.description || modifiers.modelMapping.suffix || modifiers.modelMapping.modelId;
1132
1158
  }
1133
- return processImageWithTimeout(session, img, mergedPrompt, style.commandName, requestContext);
1159
+ return processImageWithTimeout(session, img, mergedPrompt, style.commandName, requestContext, displayInfo);
1134
1160
  });
1135
1161
  logger.info(`已注册命令: ${style.commandName}`);
1136
1162
  }
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.2.1",
4
+ "version": "0.2.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [