koishi-plugin-aka-ai-generator 0.8.0 → 0.8.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 +65 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1777,6 +1777,12 @@ function parseStyleCommandModifiers(argv, imgParam, modelMappingIndex) {
|
|
|
1777
1777
|
flagCandidates.push(token);
|
|
1778
1778
|
index++;
|
|
1779
1779
|
}
|
|
1780
|
+
const debugInfo = {
|
|
1781
|
+
flagCandidates,
|
|
1782
|
+
modelMappingKeys: Array.from(modelMappingIndex.keys()),
|
|
1783
|
+
argsList: argsList.slice(0, 10)
|
|
1784
|
+
// 只取前10个避免太长
|
|
1785
|
+
};
|
|
1780
1786
|
for (const arg of flagCandidates) {
|
|
1781
1787
|
if (!arg.startsWith("-")) continue;
|
|
1782
1788
|
const key = normalizeSuffix(arg);
|
|
@@ -1784,9 +1790,13 @@ function parseStyleCommandModifiers(argv, imgParam, modelMappingIndex) {
|
|
|
1784
1790
|
const mapping = modelMappingIndex.get(key);
|
|
1785
1791
|
if (mapping) {
|
|
1786
1792
|
modifiers.modelMapping = mapping;
|
|
1793
|
+
console.log("[parseStyleCommandModifiers] 找到模型映射", { arg, key, mapping, debugInfo });
|
|
1787
1794
|
break;
|
|
1788
1795
|
}
|
|
1789
1796
|
}
|
|
1797
|
+
if (!modifiers.modelMapping && flagCandidates.some((f) => f.startsWith("-"))) {
|
|
1798
|
+
console.log("[parseStyleCommandModifiers] 未找到模型映射", debugInfo);
|
|
1799
|
+
}
|
|
1790
1800
|
return modifiers;
|
|
1791
1801
|
}
|
|
1792
1802
|
__name(parseStyleCommandModifiers, "parseStyleCommandModifiers");
|
|
@@ -2828,9 +2838,11 @@ ${messages.join("\n")}`;
|
|
|
2828
2838
|
logger.info(`已注册视频风格命令: ${style.commandName}`);
|
|
2829
2839
|
}
|
|
2830
2840
|
}
|
|
2831
|
-
ctx.command(`${COMMANDS.TXT_TO_IMG} [prompt:text]`, "根据文字描述生成图像").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async (
|
|
2841
|
+
ctx.command(`${COMMANDS.TXT_TO_IMG} [prompt:text]`, "根据文字描述生成图像").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async (argv, prompt) => {
|
|
2842
|
+
const { session, options } = argv;
|
|
2832
2843
|
if (!session?.userId) return "会话无效";
|
|
2833
2844
|
const numImages = options?.num || config.defaultNumImages;
|
|
2845
|
+
const modifiers = parseStyleCommandModifiers(argv, prompt, modelMappingIndex);
|
|
2834
2846
|
const userName = session.username || session.userId || "未知用户";
|
|
2835
2847
|
const limitCheck = await userManager.checkAndReserveQuota(session.userId, userName, numImages, config);
|
|
2836
2848
|
if (!limitCheck.allowed) {
|
|
@@ -2839,12 +2851,25 @@ ${messages.join("\n")}`;
|
|
|
2839
2851
|
const requestContext = {
|
|
2840
2852
|
numImages
|
|
2841
2853
|
};
|
|
2842
|
-
|
|
2854
|
+
if (modifiers.modelMapping?.provider) {
|
|
2855
|
+
requestContext.provider = modifiers.modelMapping.provider;
|
|
2856
|
+
}
|
|
2857
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2858
|
+
requestContext.modelId = modifiers.modelMapping.modelId;
|
|
2859
|
+
}
|
|
2860
|
+
const displayInfo = {};
|
|
2861
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2862
|
+
displayInfo.modelId = modifiers.modelMapping.modelId;
|
|
2863
|
+
displayInfo.modelDescription = modifiers.modelMapping.suffix || modifiers.modelMapping.modelId;
|
|
2864
|
+
}
|
|
2865
|
+
return processImageWithTimeout(session, prompt, "", COMMANDS.TXT_TO_IMG, requestContext, displayInfo, "text");
|
|
2843
2866
|
});
|
|
2844
|
-
ctx.command(`${COMMANDS.IMG_TO_IMG} [img:text]`, "使用自定义prompt进行图像处理").option("num", "-n <num:number> 生成图片数量 (1-4)").option("multiple", "-m 允许多图输入").action(async (
|
|
2867
|
+
ctx.command(`${COMMANDS.IMG_TO_IMG} [img:text]`, "使用自定义prompt进行图像处理").option("num", "-n <num:number> 生成图片数量 (1-4)").option("multiple", "-m 允许多图输入").action(async (argv, img) => {
|
|
2868
|
+
const { session, options } = argv;
|
|
2845
2869
|
if (!session?.userId) return "会话无效";
|
|
2846
2870
|
const numImages = options?.num || config.defaultNumImages;
|
|
2847
2871
|
const mode = options?.multiple ? "multiple" : "single";
|
|
2872
|
+
const modifiers = parseStyleCommandModifiers(argv, img, modelMappingIndex);
|
|
2848
2873
|
const userName = session.username || session.userId || "未知用户";
|
|
2849
2874
|
const limitCheck = await userManager.checkAndReserveQuota(session.userId, userName, numImages, config);
|
|
2850
2875
|
if (!limitCheck.allowed) {
|
|
@@ -2853,11 +2878,24 @@ ${messages.join("\n")}`;
|
|
|
2853
2878
|
const requestContext = {
|
|
2854
2879
|
numImages
|
|
2855
2880
|
};
|
|
2856
|
-
|
|
2881
|
+
if (modifiers.modelMapping?.provider) {
|
|
2882
|
+
requestContext.provider = modifiers.modelMapping.provider;
|
|
2883
|
+
}
|
|
2884
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2885
|
+
requestContext.modelId = modifiers.modelMapping.modelId;
|
|
2886
|
+
}
|
|
2887
|
+
const displayInfo = {};
|
|
2888
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2889
|
+
displayInfo.modelId = modifiers.modelMapping.modelId;
|
|
2890
|
+
displayInfo.modelDescription = modifiers.modelMapping.suffix || modifiers.modelMapping.modelId;
|
|
2891
|
+
}
|
|
2892
|
+
return processImageWithTimeout(session, img, "", COMMANDS.IMG_TO_IMG, requestContext, displayInfo, mode);
|
|
2857
2893
|
});
|
|
2858
|
-
ctx.command(COMMANDS.COMPOSE_IMAGE, "合成多张图片,使用自定义prompt控制合成效果").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async (
|
|
2894
|
+
ctx.command(COMMANDS.COMPOSE_IMAGE, "合成多张图片,使用自定义prompt控制合成效果").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async (argv) => {
|
|
2895
|
+
const { session, options } = argv;
|
|
2859
2896
|
if (!session?.userId) return "会话无效";
|
|
2860
2897
|
const userId = session.userId;
|
|
2898
|
+
const modifiers = parseStyleCommandModifiers(argv, void 0, modelMappingIndex);
|
|
2861
2899
|
if (!userManager.startTask(userId)) {
|
|
2862
2900
|
return "您有一个图像处理任务正在进行中,请等待完成";
|
|
2863
2901
|
}
|
|
@@ -2914,15 +2952,31 @@ ${messages.join("\n")}`;
|
|
|
2914
2952
|
return limitCheck.message;
|
|
2915
2953
|
}
|
|
2916
2954
|
if (isTimeout) throw new Error("命令执行超时");
|
|
2955
|
+
const requestContext = {
|
|
2956
|
+
numImages: imageCount
|
|
2957
|
+
};
|
|
2958
|
+
if (modifiers.modelMapping?.provider) {
|
|
2959
|
+
requestContext.provider = modifiers.modelMapping.provider;
|
|
2960
|
+
}
|
|
2961
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2962
|
+
requestContext.modelId = modifiers.modelMapping.modelId;
|
|
2963
|
+
}
|
|
2917
2964
|
logger.info("开始图片合成处理", {
|
|
2918
2965
|
userId,
|
|
2919
2966
|
imageUrls: collectedImages,
|
|
2920
2967
|
prompt,
|
|
2921
2968
|
numImages: imageCount,
|
|
2922
|
-
imageCount: collectedImages.length
|
|
2969
|
+
imageCount: collectedImages.length,
|
|
2970
|
+
modelMapping: modifiers.modelMapping ? { provider: modifiers.modelMapping.provider, modelId: modifiers.modelMapping.modelId } : null
|
|
2923
2971
|
});
|
|
2924
|
-
|
|
2925
|
-
|
|
2972
|
+
let statusMessage = `开始合成图(${collectedImages.length}张)...`;
|
|
2973
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2974
|
+
statusMessage += `
|
|
2975
|
+
使用模型:${modifiers.modelMapping.suffix || modifiers.modelMapping.modelId}`;
|
|
2976
|
+
}
|
|
2977
|
+
statusMessage += `
|
|
2978
|
+
Prompt: ${prompt}`;
|
|
2979
|
+
await session.send(statusMessage);
|
|
2926
2980
|
const generatedImages = [];
|
|
2927
2981
|
let creditDeducted = false;
|
|
2928
2982
|
const onImageGenerated = /* @__PURE__ */ __name(async (imageUrl, index, total) => {
|
|
@@ -2988,9 +3042,10 @@ Prompt: ${prompt}`);
|
|
|
2988
3042
|
hasCallback: !!onImageGenerated,
|
|
2989
3043
|
imageCount,
|
|
2990
3044
|
promptLength: prompt.length,
|
|
2991
|
-
collectedImagesCount: collectedImages.length
|
|
3045
|
+
collectedImagesCount: collectedImages.length,
|
|
3046
|
+
modelId: requestContext.modelId || "default"
|
|
2992
3047
|
});
|
|
2993
|
-
const resultImages = await requestProviderImages(prompt, collectedImages, imageCount,
|
|
3048
|
+
const resultImages = await requestProviderImages(prompt, collectedImages, imageCount, requestContext, onImageGenerated);
|
|
2994
3049
|
logger.info("requestProviderImages 返回 (COMPOSE_IMAGE)", {
|
|
2995
3050
|
userId,
|
|
2996
3051
|
imagesCount: resultImages.length,
|