koishi-plugin-aka-ai-generator 0.6.6 → 0.6.8
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 +20 -82
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1182,16 +1182,13 @@ var Config = import_koishi2.Schema.intersect([
|
|
|
1182
1182
|
import_koishi2.Schema.const("gptgod").description("GPTGod 服务"),
|
|
1183
1183
|
import_koishi2.Schema.const("gemini").description("Google Gemini 原生")
|
|
1184
1184
|
]).default("yunwu").description("图像生成供应商"),
|
|
1185
|
-
|
|
1186
|
-
yunwuApiKey: import_koishi2.Schema.string().description("云雾API密钥").role("secret").default(""),
|
|
1185
|
+
yunwuApiKey: import_koishi2.Schema.string().description("云雾API密钥").role("secret").required(),
|
|
1187
1186
|
yunwuModelId: import_koishi2.Schema.string().default("gemini-2.5-flash-image").description("云雾图像生成模型ID"),
|
|
1188
1187
|
gptgodApiKey: import_koishi2.Schema.string().description("GPTGod API 密钥").role("secret").default(""),
|
|
1189
1188
|
gptgodModelId: import_koishi2.Schema.string().default("nano-banana").description("GPTGod 模型ID"),
|
|
1190
1189
|
geminiApiKey: import_koishi2.Schema.string().description("Gemini API 密钥").role("secret").default(""),
|
|
1191
1190
|
geminiModelId: import_koishi2.Schema.string().default("gemini-2.5-flash").description("Gemini 模型ID"),
|
|
1192
|
-
geminiApiBase: import_koishi2.Schema.string().default("https://generativelanguage.googleapis.com").description("Gemini API 基础地址")
|
|
1193
|
-
}),
|
|
1194
|
-
import_koishi2.Schema.object({
|
|
1191
|
+
geminiApiBase: import_koishi2.Schema.string().default("https://generativelanguage.googleapis.com").description("Gemini API 基础地址"),
|
|
1195
1192
|
modelMappings: import_koishi2.Schema.array(import_koishi2.Schema.object({
|
|
1196
1193
|
suffix: import_koishi2.Schema.string().required().description("指令后缀(例如 4K,对应输入 -4K)"),
|
|
1197
1194
|
provider: import_koishi2.Schema.union([
|
|
@@ -1242,15 +1239,6 @@ var Config = import_koishi2.Schema.intersect([
|
|
|
1242
1239
|
]);
|
|
1243
1240
|
function apply(ctx, config) {
|
|
1244
1241
|
const logger = ctx.logger("aka-ai-generator");
|
|
1245
|
-
if (config.provider === "yunwu" && !config.yunwuApiKey) {
|
|
1246
|
-
throw new Error('当选择"云雾 Gemini 服务"时,云雾API密钥为必填项');
|
|
1247
|
-
}
|
|
1248
|
-
if (config.provider === "gptgod" && !config.gptgodApiKey) {
|
|
1249
|
-
throw new Error('当选择"GPTGod 服务"时,GPTGod API 密钥为必填项');
|
|
1250
|
-
}
|
|
1251
|
-
if (config.provider === "gemini" && !config.geminiApiKey) {
|
|
1252
|
-
throw new Error('当选择"Google Gemini 原生"时,Gemini API 密钥为必填项');
|
|
1253
|
-
}
|
|
1254
1242
|
const userManager = new UserManager(ctx.baseDir, logger);
|
|
1255
1243
|
function getProviderInstance(providerType, modelId) {
|
|
1256
1244
|
return createImageProvider({
|
|
@@ -1526,18 +1514,13 @@ function apply(ctx, config) {
|
|
|
1526
1514
|
if (!userManager.startTask(userId)) {
|
|
1527
1515
|
return "您有一个图像处理任务正在进行中,请等待完成";
|
|
1528
1516
|
}
|
|
1529
|
-
let taskLockReleased = false;
|
|
1530
1517
|
try {
|
|
1531
1518
|
const imageCount = requestContext?.numImages || config.defaultNumImages;
|
|
1532
1519
|
if (imageCount < 1 || imageCount > 4) {
|
|
1533
|
-
userManager.endTask(userId);
|
|
1534
|
-
taskLockReleased = true;
|
|
1535
1520
|
return "生成数量必须在 1-4 之间";
|
|
1536
1521
|
}
|
|
1537
1522
|
const inputResult = await getInputData(session, img, mode);
|
|
1538
1523
|
if ("error" in inputResult) {
|
|
1539
|
-
userManager.endTask(userId);
|
|
1540
|
-
taskLockReleased = true;
|
|
1541
1524
|
return inputResult.error;
|
|
1542
1525
|
}
|
|
1543
1526
|
if (checkTimeout && checkTimeout()) throw new Error("命令执行超时");
|
|
@@ -1551,23 +1534,17 @@ function apply(ctx, config) {
|
|
|
1551
1534
|
await session.send("请发送画面描述");
|
|
1552
1535
|
const promptMsg = await session.prompt(3e4);
|
|
1553
1536
|
if (!promptMsg) {
|
|
1554
|
-
userManager.endTask(userId);
|
|
1555
|
-
taskLockReleased = true;
|
|
1556
1537
|
return "未检测到描述,操作已取消";
|
|
1557
1538
|
}
|
|
1558
1539
|
const elements = import_koishi2.h.parse(promptMsg);
|
|
1559
1540
|
const images2 = import_koishi2.h.select(elements, "img");
|
|
1560
1541
|
if (images2.length > 0) {
|
|
1561
|
-
userManager.endTask(userId);
|
|
1562
|
-
taskLockReleased = true;
|
|
1563
1542
|
return "检测到图片,本功能仅支持文字输入";
|
|
1564
1543
|
}
|
|
1565
1544
|
const text = import_koishi2.h.select(elements, "text").map((e) => e.attrs.content).join(" ").trim();
|
|
1566
1545
|
if (text) {
|
|
1567
1546
|
finalPrompt = text;
|
|
1568
1547
|
} else {
|
|
1569
|
-
userManager.endTask(userId);
|
|
1570
|
-
taskLockReleased = true;
|
|
1571
1548
|
return "未检测到有效文字描述,操作已取消";
|
|
1572
1549
|
}
|
|
1573
1550
|
}
|
|
@@ -1601,41 +1578,19 @@ ${infoParts.join("\n")}`;
|
|
|
1601
1578
|
const images = await requestProviderImages(finalPrompt, imageUrls, imageCount, requestContext);
|
|
1602
1579
|
if (checkTimeout && checkTimeout()) throw new Error("命令执行超时");
|
|
1603
1580
|
if (images.length === 0) {
|
|
1604
|
-
userManager.endTask(userId);
|
|
1605
|
-
taskLockReleased = true;
|
|
1606
1581
|
return "图像处理失败:未能生成图片";
|
|
1607
1582
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
await
|
|
1614
|
-
for (let i = 0; i < images.length; i++) {
|
|
1615
|
-
try {
|
|
1616
|
-
await Promise.race([
|
|
1617
|
-
session.send(import_koishi2.h.image(images[i])),
|
|
1618
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error("SendTimeout")), 2e4))
|
|
1619
|
-
]);
|
|
1620
|
-
} catch (err) {
|
|
1621
|
-
logger.warn(`图片发送可能超时 (用户: ${userId}): ${err instanceof Error ? err.message : String(err)}`);
|
|
1622
|
-
}
|
|
1623
|
-
if (images.length > 1 && i < images.length - 1) {
|
|
1624
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
} catch (err) {
|
|
1628
|
-
logger.error(`异步发送图片时出错 (用户: ${userId}):`, err);
|
|
1629
|
-
} finally {
|
|
1630
|
-
userManager.endTask(userId);
|
|
1583
|
+
await session.send("图像处理完成!");
|
|
1584
|
+
for (let i = 0; i < images.length; i++) {
|
|
1585
|
+
if (checkTimeout && checkTimeout()) break;
|
|
1586
|
+
await session.send(import_koishi2.h.image(images[i]));
|
|
1587
|
+
if (images.length > 1 && i < images.length - 1) {
|
|
1588
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
1631
1589
|
}
|
|
1632
|
-
});
|
|
1633
|
-
return resultMessage;
|
|
1634
|
-
} catch (error) {
|
|
1635
|
-
if (!taskLockReleased) {
|
|
1636
|
-
userManager.endTask(userId);
|
|
1637
1590
|
}
|
|
1638
|
-
|
|
1591
|
+
await recordUserUsage(session, styleName, images.length);
|
|
1592
|
+
} finally {
|
|
1593
|
+
userManager.endTask(userId);
|
|
1639
1594
|
}
|
|
1640
1595
|
}
|
|
1641
1596
|
__name(processImage, "processImage");
|
|
@@ -1787,34 +1742,17 @@ Prompt: ${prompt}`);
|
|
|
1787
1742
|
if (resultImages.length === 0) {
|
|
1788
1743
|
return "图片合成失败:未能生成图片";
|
|
1789
1744
|
}
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
try {
|
|
1797
|
-
await Promise.race([
|
|
1798
|
-
session.send(import_koishi2.h.image(resultImages[i])),
|
|
1799
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error("SendTimeout")), 2e4))
|
|
1800
|
-
]);
|
|
1801
|
-
} catch (err) {
|
|
1802
|
-
logger.warn(`图片合成发送可能超时 (用户: ${userId}): ${err instanceof Error ? err.message : String(err)}`);
|
|
1803
|
-
}
|
|
1804
|
-
if (resultImages.length > 1 && i < resultImages.length - 1) {
|
|
1805
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
} catch (err) {
|
|
1809
|
-
logger.error(`异步发送合成图片时出错 (用户: ${userId}):`, err);
|
|
1810
|
-
} finally {
|
|
1811
|
-
userManager.endTask(userId);
|
|
1745
|
+
await session.send("图片合成完成!");
|
|
1746
|
+
for (let i = 0; i < resultImages.length; i++) {
|
|
1747
|
+
if (isTimeout) break;
|
|
1748
|
+
await session.send(import_koishi2.h.image(resultImages[i]));
|
|
1749
|
+
if (resultImages.length > 1 && i < resultImages.length - 1) {
|
|
1750
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
1812
1751
|
}
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
}
|
|
1752
|
+
}
|
|
1753
|
+
await recordUserUsage(session, COMMANDS.COMPOSE_IMAGE, resultImages.length);
|
|
1754
|
+
} finally {
|
|
1816
1755
|
userManager.endTask(userId);
|
|
1817
|
-
throw error;
|
|
1818
1756
|
}
|
|
1819
1757
|
})(),
|
|
1820
1758
|
new Promise(
|