koishi-plugin-aka-ai-generator 0.2.0 → 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 +74 -23
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -671,19 +671,50 @@ function apply(ctx, config) {
671
671
  return map;
672
672
  }
673
673
  __name(buildModelMappingIndex, "buildModelMappingIndex");
674
- function parseStyleCommandModifiers(argv) {
675
- const allArgs = [...argv.args || []].map((arg) => typeof arg === "string" ? arg.trim() : "").filter(Boolean);
676
- if (!allArgs.length && !argv.rest) return {};
677
- const modifiers = {};
678
- let remainingArgs = [...allArgs];
679
- const promptIndex = remainingArgs.findIndex((arg) => arg.toLowerCase().startsWith("-prompt:"));
680
- if (promptIndex >= 0) {
681
- const [promptToken, ...afterPrompt] = remainingArgs.slice(promptIndex);
682
- const promptHead = promptToken.substring(promptToken.indexOf(":") + 1);
683
- modifiers.customPromptSuffix = [promptHead, ...afterPrompt].join(" ").trim();
684
- remainingArgs = remainingArgs.slice(0, promptIndex);
685
- }
686
- for (const arg of remainingArgs) {
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 {};
686
+ const modifiers = { customAdditions: [] };
687
+ const flagCandidates = [];
688
+ let index = 0;
689
+ while (index < argsList.length) {
690
+ const token = argsList[index];
691
+ if (!token) {
692
+ index++;
693
+ continue;
694
+ }
695
+ const lower = token.toLowerCase();
696
+ if (lower.startsWith("-prompt:")) {
697
+ const promptHead = token.substring(token.indexOf(":") + 1);
698
+ const restTokens = argsList.slice(index + 1);
699
+ modifiers.customPromptSuffix = [promptHead, ...restTokens].join(" ").trim();
700
+ break;
701
+ }
702
+ if (lower === "-add") {
703
+ index++;
704
+ const additionTokens = [];
705
+ while (index < argsList.length && !argsList[index].startsWith("-")) {
706
+ additionTokens.push(argsList[index]);
707
+ index++;
708
+ }
709
+ if (additionTokens.length) {
710
+ modifiers.customAdditions.push(additionTokens.join(" "));
711
+ }
712
+ continue;
713
+ }
714
+ flagCandidates.push(token);
715
+ index++;
716
+ }
717
+ for (const arg of flagCandidates) {
687
718
  if (!arg.startsWith("-")) continue;
688
719
  const key = normalizeSuffix(arg);
689
720
  if (!key) continue;
@@ -1007,9 +1038,9 @@ function apply(ctx, config) {
1007
1038
  return await providerInstance.generateImages(prompt, imageUrls, numImages);
1008
1039
  }
1009
1040
  __name(requestProviderImages, "requestProviderImages");
1010
- async function processImageWithTimeout(session, img, prompt, styleName, requestContext) {
1041
+ async function processImageWithTimeout(session, img, prompt, styleName, requestContext, displayInfo) {
1011
1042
  return Promise.race([
1012
- processImage(session, img, prompt, styleName, requestContext),
1043
+ processImage(session, img, prompt, styleName, requestContext, displayInfo),
1013
1044
  new Promise(
1014
1045
  (_, reject) => setTimeout(() => reject(new Error("命令执行超时")), config.commandTimeout * 1e3)
1015
1046
  )
@@ -1021,7 +1052,7 @@ function apply(ctx, config) {
1021
1052
  });
1022
1053
  }
1023
1054
  __name(processImageWithTimeout, "processImageWithTimeout");
1024
- async function processImage(session, img, prompt, styleName, requestContext) {
1055
+ async function processImage(session, img, prompt, styleName, requestContext, displayInfo) {
1025
1056
  const userId = session.userId;
1026
1057
  if (activeTasks.has(userId)) {
1027
1058
  return "您有一个图像处理任务正在进行中,请等待完成";
@@ -1045,7 +1076,21 @@ function apply(ctx, config) {
1045
1076
  provider: providerType,
1046
1077
  modelId: providerModelId
1047
1078
  });
1048
- 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);
1049
1094
  try {
1050
1095
  activeTasks.set(userId, "processing");
1051
1096
  const images = await requestProviderImages(prompt, imageUrl, imageCount, requestContext);
@@ -1082,11 +1127,14 @@ function apply(ctx, config) {
1082
1127
  if (!limitCheck.allowed) {
1083
1128
  return limitCheck.message;
1084
1129
  }
1085
- const modifiers = parseStyleCommandModifiers(argv);
1130
+ const modifiers = parseStyleCommandModifiers(argv, img);
1086
1131
  const promptSegments = [style.prompt];
1087
1132
  if (modifiers.modelMapping?.promptSuffix) {
1088
1133
  promptSegments.push(modifiers.modelMapping.promptSuffix);
1089
1134
  }
1135
+ if (modifiers.customAdditions?.length) {
1136
+ promptSegments.push(...modifiers.customAdditions);
1137
+ }
1090
1138
  if (modifiers.customPromptSuffix) {
1091
1139
  promptSegments.push(modifiers.customPromptSuffix);
1092
1140
  }
@@ -1100,12 +1148,15 @@ function apply(ctx, config) {
1100
1148
  if (modifiers.modelMapping?.modelId) {
1101
1149
  requestContext.modelId = modifiers.modelMapping.modelId;
1102
1150
  }
1103
- if (modifiers.modelMapping?.description) {
1104
- await session.send(`已启用 ${modifiers.modelMapping.description} 配置`);
1105
- } else if (modifiers.modelMapping?.suffix) {
1106
- 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;
1107
1158
  }
1108
- return processImageWithTimeout(session, img, mergedPrompt, style.commandName, requestContext);
1159
+ return processImageWithTimeout(session, img, mergedPrompt, style.commandName, requestContext, displayInfo);
1109
1160
  });
1110
1161
  logger.info(`已注册命令: ${style.commandName}`);
1111
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.0",
4
+ "version": "0.2.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [