koishi-plugin-aka-ai-generator 0.8.1 → 0.8.4
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 +79 -33
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1830,42 +1830,43 @@ var Config = import_koishi2.Schema.intersect([
|
|
|
1830
1830
|
import_koishi2.Schema.const("gemini").description("Google Gemini 原生")
|
|
1831
1831
|
]).default("yunwu").description("图像生成供应商")
|
|
1832
1832
|
}).description("🎨 供应商选择"),
|
|
1833
|
-
// ===== 2.
|
|
1833
|
+
// ===== 2. API 配置(根据 provider 条件显示) =====
|
|
1834
1834
|
import_koishi2.Schema.union([
|
|
1835
|
+
// 云雾配置
|
|
1835
1836
|
import_koishi2.Schema.object({
|
|
1836
1837
|
provider: import_koishi2.Schema.const("yunwu").required(),
|
|
1837
1838
|
yunwuApiKey: import_koishi2.Schema.string().role("secret").required().description("云雾 API 密钥"),
|
|
1838
|
-
yunwuModelId: import_koishi2.Schema.string().default("gemini-2.5-flash-image").description("云雾图像生成模型ID")
|
|
1839
|
+
yunwuModelId: import_koishi2.Schema.string().default("gemini-2.5-flash-image").description("云雾图像生成模型ID"),
|
|
1840
|
+
// 其他 provider 的隐藏默认值
|
|
1841
|
+
gptgodApiKey: import_koishi2.Schema.string().role("secret").default("").hidden(),
|
|
1842
|
+
gptgodModelId: import_koishi2.Schema.string().default("nano-banana").hidden(),
|
|
1843
|
+
geminiApiKey: import_koishi2.Schema.string().role("secret").default("").hidden(),
|
|
1844
|
+
geminiModelId: import_koishi2.Schema.string().default("gemini-2.5-flash").hidden(),
|
|
1845
|
+
geminiApiBase: import_koishi2.Schema.string().default("https://generativelanguage.googleapis.com").hidden()
|
|
1839
1846
|
}),
|
|
1840
|
-
|
|
1841
|
-
yunwuApiKey: import_koishi2.Schema.string().role("secret").default("").hidden(),
|
|
1842
|
-
yunwuModelId: import_koishi2.Schema.string().default("gemini-2.5-flash-image").hidden()
|
|
1843
|
-
})
|
|
1844
|
-
]),
|
|
1845
|
-
// ===== 3. GPTGod API 配置(条件显示) =====
|
|
1846
|
-
import_koishi2.Schema.union([
|
|
1847
|
+
// GPTGod 配置
|
|
1847
1848
|
import_koishi2.Schema.object({
|
|
1848
1849
|
provider: import_koishi2.Schema.const("gptgod").required(),
|
|
1849
1850
|
gptgodApiKey: import_koishi2.Schema.string().role("secret").required().description("GPTGod API 密钥"),
|
|
1850
|
-
gptgodModelId: import_koishi2.Schema.string().default("nano-banana").description("GPTGod 模型ID")
|
|
1851
|
+
gptgodModelId: import_koishi2.Schema.string().default("nano-banana").description("GPTGod 模型ID"),
|
|
1852
|
+
// 其他 provider 的隐藏默认值
|
|
1853
|
+
yunwuApiKey: import_koishi2.Schema.string().role("secret").default("").hidden(),
|
|
1854
|
+
yunwuModelId: import_koishi2.Schema.string().default("gemini-2.5-flash-image").hidden(),
|
|
1855
|
+
geminiApiKey: import_koishi2.Schema.string().role("secret").default("").hidden(),
|
|
1856
|
+
geminiModelId: import_koishi2.Schema.string().default("gemini-2.5-flash").hidden(),
|
|
1857
|
+
geminiApiBase: import_koishi2.Schema.string().default("https://generativelanguage.googleapis.com").hidden()
|
|
1851
1858
|
}),
|
|
1852
|
-
|
|
1853
|
-
gptgodApiKey: import_koishi2.Schema.string().role("secret").default("").hidden(),
|
|
1854
|
-
gptgodModelId: import_koishi2.Schema.string().default("nano-banana").hidden()
|
|
1855
|
-
})
|
|
1856
|
-
]),
|
|
1857
|
-
// ===== 4. Gemini API 配置(条件显示) =====
|
|
1858
|
-
import_koishi2.Schema.union([
|
|
1859
|
+
// Gemini 配置
|
|
1859
1860
|
import_koishi2.Schema.object({
|
|
1860
1861
|
provider: import_koishi2.Schema.const("gemini").required(),
|
|
1861
1862
|
geminiApiKey: import_koishi2.Schema.string().role("secret").required().description("Gemini API 密钥"),
|
|
1862
1863
|
geminiModelId: import_koishi2.Schema.string().default("gemini-2.5-flash").description("Gemini 模型ID"),
|
|
1863
|
-
geminiApiBase: import_koishi2.Schema.string().default("https://generativelanguage.googleapis.com").description("Gemini API 基础地址")
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1864
|
+
geminiApiBase: import_koishi2.Schema.string().default("https://generativelanguage.googleapis.com").description("Gemini API 基础地址"),
|
|
1865
|
+
// 其他 provider 的隐藏默认值
|
|
1866
|
+
yunwuApiKey: import_koishi2.Schema.string().role("secret").default("").hidden(),
|
|
1867
|
+
yunwuModelId: import_koishi2.Schema.string().default("gemini-2.5-flash-image").hidden(),
|
|
1868
|
+
gptgodApiKey: import_koishi2.Schema.string().role("secret").default("").hidden(),
|
|
1869
|
+
gptgodModelId: import_koishi2.Schema.string().default("nano-banana").hidden()
|
|
1869
1870
|
})
|
|
1870
1871
|
]),
|
|
1871
1872
|
// ===== 5. 通用设置 =====
|
|
@@ -2838,9 +2839,11 @@ ${messages.join("\n")}`;
|
|
|
2838
2839
|
logger.info(`已注册视频风格命令: ${style.commandName}`);
|
|
2839
2840
|
}
|
|
2840
2841
|
}
|
|
2841
|
-
ctx.command(`${COMMANDS.TXT_TO_IMG} [prompt:text]`, "根据文字描述生成图像").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async (
|
|
2842
|
+
ctx.command(`${COMMANDS.TXT_TO_IMG} [prompt:text]`, "根据文字描述生成图像").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async (argv, prompt) => {
|
|
2843
|
+
const { session, options } = argv;
|
|
2842
2844
|
if (!session?.userId) return "会话无效";
|
|
2843
2845
|
const numImages = options?.num || config.defaultNumImages;
|
|
2846
|
+
const modifiers = parseStyleCommandModifiers(argv, prompt, modelMappingIndex);
|
|
2844
2847
|
const userName = session.username || session.userId || "未知用户";
|
|
2845
2848
|
const limitCheck = await userManager.checkAndReserveQuota(session.userId, userName, numImages, config);
|
|
2846
2849
|
if (!limitCheck.allowed) {
|
|
@@ -2849,12 +2852,25 @@ ${messages.join("\n")}`;
|
|
|
2849
2852
|
const requestContext = {
|
|
2850
2853
|
numImages
|
|
2851
2854
|
};
|
|
2852
|
-
|
|
2855
|
+
if (modifiers.modelMapping?.provider) {
|
|
2856
|
+
requestContext.provider = modifiers.modelMapping.provider;
|
|
2857
|
+
}
|
|
2858
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2859
|
+
requestContext.modelId = modifiers.modelMapping.modelId;
|
|
2860
|
+
}
|
|
2861
|
+
const displayInfo = {};
|
|
2862
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2863
|
+
displayInfo.modelId = modifiers.modelMapping.modelId;
|
|
2864
|
+
displayInfo.modelDescription = modifiers.modelMapping.suffix || modifiers.modelMapping.modelId;
|
|
2865
|
+
}
|
|
2866
|
+
return processImageWithTimeout(session, prompt, "", COMMANDS.TXT_TO_IMG, requestContext, displayInfo, "text");
|
|
2853
2867
|
});
|
|
2854
|
-
ctx.command(`${COMMANDS.IMG_TO_IMG} [img:text]`, "使用自定义prompt进行图像处理").option("num", "-n <num:number> 生成图片数量 (1-4)").option("multiple", "-m 允许多图输入").action(async (
|
|
2868
|
+
ctx.command(`${COMMANDS.IMG_TO_IMG} [img:text]`, "使用自定义prompt进行图像处理").option("num", "-n <num:number> 生成图片数量 (1-4)").option("multiple", "-m 允许多图输入").action(async (argv, img) => {
|
|
2869
|
+
const { session, options } = argv;
|
|
2855
2870
|
if (!session?.userId) return "会话无效";
|
|
2856
2871
|
const numImages = options?.num || config.defaultNumImages;
|
|
2857
2872
|
const mode = options?.multiple ? "multiple" : "single";
|
|
2873
|
+
const modifiers = parseStyleCommandModifiers(argv, img, modelMappingIndex);
|
|
2858
2874
|
const userName = session.username || session.userId || "未知用户";
|
|
2859
2875
|
const limitCheck = await userManager.checkAndReserveQuota(session.userId, userName, numImages, config);
|
|
2860
2876
|
if (!limitCheck.allowed) {
|
|
@@ -2863,11 +2879,24 @@ ${messages.join("\n")}`;
|
|
|
2863
2879
|
const requestContext = {
|
|
2864
2880
|
numImages
|
|
2865
2881
|
};
|
|
2866
|
-
|
|
2882
|
+
if (modifiers.modelMapping?.provider) {
|
|
2883
|
+
requestContext.provider = modifiers.modelMapping.provider;
|
|
2884
|
+
}
|
|
2885
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2886
|
+
requestContext.modelId = modifiers.modelMapping.modelId;
|
|
2887
|
+
}
|
|
2888
|
+
const displayInfo = {};
|
|
2889
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2890
|
+
displayInfo.modelId = modifiers.modelMapping.modelId;
|
|
2891
|
+
displayInfo.modelDescription = modifiers.modelMapping.suffix || modifiers.modelMapping.modelId;
|
|
2892
|
+
}
|
|
2893
|
+
return processImageWithTimeout(session, img, "", COMMANDS.IMG_TO_IMG, requestContext, displayInfo, mode);
|
|
2867
2894
|
});
|
|
2868
|
-
ctx.command(COMMANDS.COMPOSE_IMAGE, "合成多张图片,使用自定义prompt控制合成效果").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async (
|
|
2895
|
+
ctx.command(COMMANDS.COMPOSE_IMAGE, "合成多张图片,使用自定义prompt控制合成效果").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async (argv) => {
|
|
2896
|
+
const { session, options } = argv;
|
|
2869
2897
|
if (!session?.userId) return "会话无效";
|
|
2870
2898
|
const userId = session.userId;
|
|
2899
|
+
const modifiers = parseStyleCommandModifiers(argv, void 0, modelMappingIndex);
|
|
2871
2900
|
if (!userManager.startTask(userId)) {
|
|
2872
2901
|
return "您有一个图像处理任务正在进行中,请等待完成";
|
|
2873
2902
|
}
|
|
@@ -2924,15 +2953,31 @@ ${messages.join("\n")}`;
|
|
|
2924
2953
|
return limitCheck.message;
|
|
2925
2954
|
}
|
|
2926
2955
|
if (isTimeout) throw new Error("命令执行超时");
|
|
2956
|
+
const requestContext = {
|
|
2957
|
+
numImages: imageCount
|
|
2958
|
+
};
|
|
2959
|
+
if (modifiers.modelMapping?.provider) {
|
|
2960
|
+
requestContext.provider = modifiers.modelMapping.provider;
|
|
2961
|
+
}
|
|
2962
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2963
|
+
requestContext.modelId = modifiers.modelMapping.modelId;
|
|
2964
|
+
}
|
|
2927
2965
|
logger.info("开始图片合成处理", {
|
|
2928
2966
|
userId,
|
|
2929
2967
|
imageUrls: collectedImages,
|
|
2930
2968
|
prompt,
|
|
2931
2969
|
numImages: imageCount,
|
|
2932
|
-
imageCount: collectedImages.length
|
|
2970
|
+
imageCount: collectedImages.length,
|
|
2971
|
+
modelMapping: modifiers.modelMapping ? { provider: modifiers.modelMapping.provider, modelId: modifiers.modelMapping.modelId } : null
|
|
2933
2972
|
});
|
|
2934
|
-
|
|
2935
|
-
|
|
2973
|
+
let statusMessage = `开始合成图(${collectedImages.length}张)...`;
|
|
2974
|
+
if (modifiers.modelMapping?.modelId) {
|
|
2975
|
+
statusMessage += `
|
|
2976
|
+
使用模型:${modifiers.modelMapping.suffix || modifiers.modelMapping.modelId}`;
|
|
2977
|
+
}
|
|
2978
|
+
statusMessage += `
|
|
2979
|
+
Prompt: ${prompt}`;
|
|
2980
|
+
await session.send(statusMessage);
|
|
2936
2981
|
const generatedImages = [];
|
|
2937
2982
|
let creditDeducted = false;
|
|
2938
2983
|
const onImageGenerated = /* @__PURE__ */ __name(async (imageUrl, index, total) => {
|
|
@@ -2998,9 +3043,10 @@ Prompt: ${prompt}`);
|
|
|
2998
3043
|
hasCallback: !!onImageGenerated,
|
|
2999
3044
|
imageCount,
|
|
3000
3045
|
promptLength: prompt.length,
|
|
3001
|
-
collectedImagesCount: collectedImages.length
|
|
3046
|
+
collectedImagesCount: collectedImages.length,
|
|
3047
|
+
modelId: requestContext.modelId || "default"
|
|
3002
3048
|
});
|
|
3003
|
-
const resultImages = await requestProviderImages(prompt, collectedImages, imageCount,
|
|
3049
|
+
const resultImages = await requestProviderImages(prompt, collectedImages, imageCount, requestContext, onImageGenerated);
|
|
3004
3050
|
logger.info("requestProviderImages 返回 (COMPOSE_IMAGE)", {
|
|
3005
3051
|
userId,
|
|
3006
3052
|
imagesCount: resultImages.length,
|