koishi-plugin-aka-ai-generator 0.2.1 → 0.2.3
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.
- package/lib/index.js +59 -18
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -671,14 +671,31 @@ function apply(ctx, config) {
|
|
|
671
671
|
return map;
|
|
672
672
|
}
|
|
673
673
|
__name(buildModelMappingIndex, "buildModelMappingIndex");
|
|
674
|
-
function parseStyleCommandModifiers(argv) {
|
|
675
|
-
const
|
|
676
|
-
|
|
674
|
+
function parseStyleCommandModifiers(argv, imgParam) {
|
|
675
|
+
const session = argv.session;
|
|
676
|
+
let rawText = "";
|
|
677
|
+
if (session?.content) {
|
|
678
|
+
const elements = import_koishi.h.parse(session.content);
|
|
679
|
+
rawText = import_koishi.h.select(elements, "text").map((e) => e.attrs.content).join(" ");
|
|
680
|
+
}
|
|
681
|
+
const argsList = rawText ? rawText.split(/\s+/).filter(Boolean) : [...argv.args || []].map((arg) => typeof arg === "string" ? arg.trim() : "").filter(Boolean);
|
|
682
|
+
if (!rawText) {
|
|
683
|
+
const restStr = typeof argv.rest === "string" ? argv.rest.trim() : "";
|
|
684
|
+
if (restStr) {
|
|
685
|
+
const restParts = restStr.split(/\s+/).filter(Boolean);
|
|
686
|
+
argsList.push(...restParts);
|
|
687
|
+
}
|
|
688
|
+
if (imgParam && typeof imgParam === "string" && !imgParam.startsWith("http") && !imgParam.startsWith("data:")) {
|
|
689
|
+
const imgParts = imgParam.split(/\s+/).filter(Boolean);
|
|
690
|
+
argsList.push(...imgParts);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (!argsList.length) return {};
|
|
677
694
|
const modifiers = { customAdditions: [] };
|
|
678
695
|
const flagCandidates = [];
|
|
679
696
|
let index = 0;
|
|
680
|
-
while (index <
|
|
681
|
-
const token =
|
|
697
|
+
while (index < argsList.length) {
|
|
698
|
+
const token = argsList[index];
|
|
682
699
|
if (!token) {
|
|
683
700
|
index++;
|
|
684
701
|
continue;
|
|
@@ -686,15 +703,22 @@ function apply(ctx, config) {
|
|
|
686
703
|
const lower = token.toLowerCase();
|
|
687
704
|
if (lower.startsWith("-prompt:")) {
|
|
688
705
|
const promptHead = token.substring(token.indexOf(":") + 1);
|
|
689
|
-
const restTokens =
|
|
706
|
+
const restTokens = argsList.slice(index + 1);
|
|
690
707
|
modifiers.customPromptSuffix = [promptHead, ...restTokens].join(" ").trim();
|
|
691
708
|
break;
|
|
692
709
|
}
|
|
693
710
|
if (lower === "-add") {
|
|
694
711
|
index++;
|
|
695
712
|
const additionTokens = [];
|
|
696
|
-
while (index <
|
|
697
|
-
|
|
713
|
+
while (index < argsList.length) {
|
|
714
|
+
const nextToken = argsList[index];
|
|
715
|
+
if (nextToken.startsWith("-")) {
|
|
716
|
+
const key = normalizeSuffix(nextToken);
|
|
717
|
+
if (key && modelMappingIndex.has(key)) break;
|
|
718
|
+
if (nextToken.toLowerCase().startsWith("-prompt:")) break;
|
|
719
|
+
if (nextToken.toLowerCase() === "-add") break;
|
|
720
|
+
}
|
|
721
|
+
additionTokens.push(nextToken);
|
|
698
722
|
index++;
|
|
699
723
|
}
|
|
700
724
|
if (additionTokens.length) {
|
|
@@ -1029,9 +1053,9 @@ function apply(ctx, config) {
|
|
|
1029
1053
|
return await providerInstance.generateImages(prompt, imageUrls, numImages);
|
|
1030
1054
|
}
|
|
1031
1055
|
__name(requestProviderImages, "requestProviderImages");
|
|
1032
|
-
async function processImageWithTimeout(session, img, prompt, styleName, requestContext) {
|
|
1056
|
+
async function processImageWithTimeout(session, img, prompt, styleName, requestContext, displayInfo) {
|
|
1033
1057
|
return Promise.race([
|
|
1034
|
-
processImage(session, img, prompt, styleName, requestContext),
|
|
1058
|
+
processImage(session, img, prompt, styleName, requestContext, displayInfo),
|
|
1035
1059
|
new Promise(
|
|
1036
1060
|
(_, reject) => setTimeout(() => reject(new Error("命令执行超时")), config.commandTimeout * 1e3)
|
|
1037
1061
|
)
|
|
@@ -1043,7 +1067,7 @@ function apply(ctx, config) {
|
|
|
1043
1067
|
});
|
|
1044
1068
|
}
|
|
1045
1069
|
__name(processImageWithTimeout, "processImageWithTimeout");
|
|
1046
|
-
async function processImage(session, img, prompt, styleName, requestContext) {
|
|
1070
|
+
async function processImage(session, img, prompt, styleName, requestContext, displayInfo) {
|
|
1047
1071
|
const userId = session.userId;
|
|
1048
1072
|
if (activeTasks.has(userId)) {
|
|
1049
1073
|
return "您有一个图像处理任务正在进行中,请等待完成";
|
|
@@ -1067,7 +1091,21 @@ function apply(ctx, config) {
|
|
|
1067
1091
|
provider: providerType,
|
|
1068
1092
|
modelId: providerModelId
|
|
1069
1093
|
});
|
|
1070
|
-
|
|
1094
|
+
let statusMessage = `开始处理图片(${styleName})`;
|
|
1095
|
+
const infoParts = [];
|
|
1096
|
+
if (displayInfo?.customAdditions && displayInfo.customAdditions.length > 0) {
|
|
1097
|
+
infoParts.push(`自定义内容:${displayInfo.customAdditions.join(";")}`);
|
|
1098
|
+
}
|
|
1099
|
+
if (displayInfo?.modelId) {
|
|
1100
|
+
const modelDesc = displayInfo.modelDescription || displayInfo.modelId;
|
|
1101
|
+
infoParts.push(`使用模型:${modelDesc}`);
|
|
1102
|
+
}
|
|
1103
|
+
if (infoParts.length > 0) {
|
|
1104
|
+
statusMessage += `
|
|
1105
|
+
${infoParts.join("\n")}`;
|
|
1106
|
+
}
|
|
1107
|
+
statusMessage += "...";
|
|
1108
|
+
await session.send(statusMessage);
|
|
1071
1109
|
try {
|
|
1072
1110
|
activeTasks.set(userId, "processing");
|
|
1073
1111
|
const images = await requestProviderImages(prompt, imageUrl, imageCount, requestContext);
|
|
@@ -1104,7 +1142,7 @@ function apply(ctx, config) {
|
|
|
1104
1142
|
if (!limitCheck.allowed) {
|
|
1105
1143
|
return limitCheck.message;
|
|
1106
1144
|
}
|
|
1107
|
-
const modifiers = parseStyleCommandModifiers(argv);
|
|
1145
|
+
const modifiers = parseStyleCommandModifiers(argv, img);
|
|
1108
1146
|
const promptSegments = [style.prompt];
|
|
1109
1147
|
if (modifiers.modelMapping?.promptSuffix) {
|
|
1110
1148
|
promptSegments.push(modifiers.modelMapping.promptSuffix);
|
|
@@ -1125,12 +1163,15 @@ function apply(ctx, config) {
|
|
|
1125
1163
|
if (modifiers.modelMapping?.modelId) {
|
|
1126
1164
|
requestContext.modelId = modifiers.modelMapping.modelId;
|
|
1127
1165
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1166
|
+
const displayInfo = {};
|
|
1167
|
+
if (modifiers.customAdditions && modifiers.customAdditions.length > 0) {
|
|
1168
|
+
displayInfo.customAdditions = modifiers.customAdditions;
|
|
1169
|
+
}
|
|
1170
|
+
if (modifiers.modelMapping?.modelId) {
|
|
1171
|
+
displayInfo.modelId = modifiers.modelMapping.modelId;
|
|
1172
|
+
displayInfo.modelDescription = modifiers.modelMapping.description || modifiers.modelMapping.suffix || modifiers.modelMapping.modelId;
|
|
1132
1173
|
}
|
|
1133
|
-
return processImageWithTimeout(session, img, mergedPrompt, style.commandName, requestContext);
|
|
1174
|
+
return processImageWithTimeout(session, img, mergedPrompt, style.commandName, requestContext, displayInfo);
|
|
1134
1175
|
});
|
|
1135
1176
|
logger.info(`已注册命令: ${style.commandName}`);
|
|
1136
1177
|
}
|