koishi-plugin-aka-ai-generator 0.3.1 → 0.3.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.d.ts +0 -1
- package/lib/index.js +17 -118
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -753,12 +753,8 @@ var COMMANDS = {
|
|
|
753
753
|
IMAGE_COMMANDS: "图像指令"
|
|
754
754
|
};
|
|
755
755
|
var StyleItemSchema = import_koishi.Schema.object({
|
|
756
|
-
commandName: import_koishi.Schema.string().required().description("
|
|
757
|
-
prompt: import_koishi.Schema.string().role("textarea", { rows: 4 }).required().description("生成 prompt")
|
|
758
|
-
mode: import_koishi.Schema.union([
|
|
759
|
-
import_koishi.Schema.const("single").description("单图模式"),
|
|
760
|
-
import_koishi.Schema.const("multiple").description("多图模式")
|
|
761
|
-
]).default("single").description("图片输入模式")
|
|
756
|
+
commandName: import_koishi.Schema.string().required().description("命令名称").role("table-cell", { width: 100 }),
|
|
757
|
+
prompt: import_koishi.Schema.string().role("textarea", { rows: 4 }).required().description("生成 prompt")
|
|
762
758
|
});
|
|
763
759
|
var Config = import_koishi.Schema.intersect([
|
|
764
760
|
import_koishi.Schema.object({
|
|
@@ -805,13 +801,11 @@ var Config = import_koishi.Schema.intersect([
|
|
|
805
801
|
styles: import_koishi.Schema.array(StyleItemSchema).role("table").default([
|
|
806
802
|
{
|
|
807
803
|
commandName: "变手办",
|
|
808
|
-
prompt: "将这张照片变成手办模型。在它后面放置一个印有图像主体的盒子,桌子上有一台电脑显示Blender建模过程。在盒子前面添加一个圆形塑料底座,角色手办站在上面。如果可能的话,将场景设置在室内"
|
|
809
|
-
mode: "single"
|
|
804
|
+
prompt: "将这张照片变成手办模型。在它后面放置一个印有图像主体的盒子,桌子上有一台电脑显示Blender建模过程。在盒子前面添加一个圆形塑料底座,角色手办站在上面。如果可能的话,将场景设置在室内"
|
|
810
805
|
},
|
|
811
806
|
{
|
|
812
807
|
commandName: "变写实",
|
|
813
|
-
prompt: "请根据用户提供的图片,在严格保持主体身份、外观特征与姿态不变的前提下,生成一张照片级真实感的超写实摄影作品。要求:1. 采用专业相机拍摄(如佳能EOS R5),使用85mm f/1.4人像镜头,呈现柯达Portra 400胶片质感,8K超高清画质,HDR高动态范围,电影级打光效果;2. 画面应具有照片级真实感、超现实主义风格和高细节表现,确保光影、皮肤质感、服饰纹理与背景环境都贴近真实世界;3. 使用自然光影营造真实氛围,呈现raw and natural的原始自然感,具有authentic film snapshot的真实胶片质感;4. 整体需具备tactile feel触感质感和simulated texture模拟纹理细节,可以适度优化噪点与瑕疵,但不要改变主体特征或添加额外元素;5. 整体效果需像专业摄影棚拍摄的真实照片,具有电影级画质;6. 如果主体是人物脸部,脸部生成效果应参考欧美混血白人精致美丽帅气英俊的外观特征进行生成,保持精致立体的五官轮廓、健康光泽的肌肤质感、优雅的气质和自然的表情,确保面部特征协调美观。"
|
|
814
|
-
mode: "single"
|
|
808
|
+
prompt: "请根据用户提供的图片,在严格保持主体身份、外观特征与姿态不变的前提下,生成一张照片级真实感的超写实摄影作品。要求:1. 采用专业相机拍摄(如佳能EOS R5),使用85mm f/1.4人像镜头,呈现柯达Portra 400胶片质感,8K超高清画质,HDR高动态范围,电影级打光效果;2. 画面应具有照片级真实感、超现实主义风格和高细节表现,确保光影、皮肤质感、服饰纹理与背景环境都贴近真实世界;3. 使用自然光影营造真实氛围,呈现raw and natural的原始自然感,具有authentic film snapshot的真实胶片质感;4. 整体需具备tactile feel触感质感和simulated texture模拟纹理细节,可以适度优化噪点与瑕疵,但不要改变主体特征或添加额外元素;5. 整体效果需像专业摄影棚拍摄的真实照片,具有电影级画质;6. 如果主体是人物脸部,脸部生成效果应参考欧美混血白人精致美丽帅气英俊的外观特征进行生成,保持精致立体的五官轮廓、健康光泽的肌肤质感、优雅的气质和自然的表情,确保面部特征协调美观。"
|
|
815
809
|
}
|
|
816
810
|
]).description("自定义风格命令配置")
|
|
817
811
|
}),
|
|
@@ -1426,7 +1420,7 @@ ${infoParts.join("\n")}`;
|
|
|
1426
1420
|
if (styleDefinitions.length > 0) {
|
|
1427
1421
|
for (const style of styleDefinitions) {
|
|
1428
1422
|
if (style.commandName && style.prompt) {
|
|
1429
|
-
ctx.command(`${style.commandName} [img:text]`, "图像风格转换").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async (argv, img) => {
|
|
1423
|
+
ctx.command(`${style.commandName} [img:text]`, "图像风格转换").option("num", "-n <num:number> 生成图片数量 (1-4)").option("multiple", "-m 允许多图输入").action(async (argv, img) => {
|
|
1430
1424
|
const { session, options } = argv;
|
|
1431
1425
|
if (!session?.userId) return "会话无效";
|
|
1432
1426
|
const modifiers = parseStyleCommandModifiers(argv, img);
|
|
@@ -1465,7 +1459,7 @@ ${infoParts.join("\n")}`;
|
|
|
1465
1459
|
displayInfo.modelId = modifiers.modelMapping.modelId;
|
|
1466
1460
|
displayInfo.modelDescription = modifiers.modelMapping.suffix || modifiers.modelMapping.modelId;
|
|
1467
1461
|
}
|
|
1468
|
-
const mode =
|
|
1462
|
+
const mode = options?.multiple ? "multiple" : "single";
|
|
1469
1463
|
return processImageWithTimeout(session, img, mergedPrompt, style.commandName, requestContext, displayInfo, mode);
|
|
1470
1464
|
});
|
|
1471
1465
|
logger.info(`已注册命令: ${style.commandName}`);
|
|
@@ -1484,113 +1478,18 @@ ${infoParts.join("\n")}`;
|
|
|
1484
1478
|
};
|
|
1485
1479
|
return processImageWithTimeout(session, prompt, "", COMMANDS.TXT_TO_IMG, requestContext, {}, "text");
|
|
1486
1480
|
});
|
|
1487
|
-
ctx.command(COMMANDS.IMG_TO_IMG
|
|
1481
|
+
ctx.command(`${COMMANDS.IMG_TO_IMG} [img:text]`, "使用自定义prompt进行图像处理").option("num", "-n <num:number> 生成图片数量 (1-4)").option("multiple", "-m 允许多图输入").action(async ({ session, options }, img) => {
|
|
1488
1482
|
if (!session?.userId) return "会话无效";
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
while (true) {
|
|
1500
|
-
const msg = await session.prompt(6e4);
|
|
1501
|
-
if (!msg) {
|
|
1502
|
-
return "等待超时,请重试";
|
|
1503
|
-
}
|
|
1504
|
-
const elements = import_koishi.h.parse(msg);
|
|
1505
|
-
const images = import_koishi.h.select(elements, "img");
|
|
1506
|
-
const textElements = import_koishi.h.select(elements, "text");
|
|
1507
|
-
const text = textElements.map((el) => el.attrs.content).join(" ").trim();
|
|
1508
|
-
if (images.length > 0) {
|
|
1509
|
-
if (collectedImages.length > 0) {
|
|
1510
|
-
return '本功能仅支持处理一张图片,如需合成多张图片请使用"合成图"命令';
|
|
1511
|
-
}
|
|
1512
|
-
if (images.length > 1) {
|
|
1513
|
-
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"合成图"命令';
|
|
1514
|
-
}
|
|
1515
|
-
for (const img of images) {
|
|
1516
|
-
collectedImages.push(img.attrs.src);
|
|
1517
|
-
}
|
|
1518
|
-
if (text) {
|
|
1519
|
-
prompt = text;
|
|
1520
|
-
break;
|
|
1521
|
-
}
|
|
1522
|
-
await session.send("请发送描述");
|
|
1523
|
-
continue;
|
|
1524
|
-
}
|
|
1525
|
-
if (text) {
|
|
1526
|
-
if (collectedImages.length === 0) {
|
|
1527
|
-
return "未检测到图片,请先发送图片";
|
|
1528
|
-
}
|
|
1529
|
-
prompt = text;
|
|
1530
|
-
break;
|
|
1531
|
-
}
|
|
1532
|
-
return "未检测到有效内容,请重新发送";
|
|
1533
|
-
}
|
|
1534
|
-
if (collectedImages.length === 0) {
|
|
1535
|
-
return "未检测到图片,请重新发送";
|
|
1536
|
-
}
|
|
1537
|
-
if (collectedImages.length > 1) {
|
|
1538
|
-
return '本功能仅支持处理一张图片,检测到多张图片。如需合成多张图片请使用"合成图"命令';
|
|
1539
|
-
}
|
|
1540
|
-
if (!prompt) {
|
|
1541
|
-
return "未检测到prompt描述,请重新发送";
|
|
1542
|
-
}
|
|
1543
|
-
const imageUrl = collectedImages[0];
|
|
1544
|
-
const imageCount = options?.num || config.defaultNumImages;
|
|
1545
|
-
if (imageCount < 1 || imageCount > 4) {
|
|
1546
|
-
return "生成数量必须在 1-4 之间";
|
|
1547
|
-
}
|
|
1548
|
-
const limitCheck = await checkDailyLimit(userId, imageCount);
|
|
1549
|
-
if (!limitCheck.allowed) {
|
|
1550
|
-
return limitCheck.message;
|
|
1551
|
-
}
|
|
1552
|
-
logger.info("开始自定义图像处理", {
|
|
1553
|
-
userId,
|
|
1554
|
-
imageUrl,
|
|
1555
|
-
prompt,
|
|
1556
|
-
numImages: imageCount
|
|
1557
|
-
});
|
|
1558
|
-
await session.send(`开始处理图片(自定义prompt)...
|
|
1559
|
-
Prompt: ${prompt}`);
|
|
1560
|
-
try {
|
|
1561
|
-
activeTasks.set(userId, "processing");
|
|
1562
|
-
const resultImages = await requestProviderImages(prompt, imageUrl, imageCount);
|
|
1563
|
-
if (resultImages.length === 0) {
|
|
1564
|
-
activeTasks.delete(userId);
|
|
1565
|
-
return "图像处理失败:未能生成图片";
|
|
1566
|
-
}
|
|
1567
|
-
await session.send("图像处理完成!");
|
|
1568
|
-
for (let i = 0; i < resultImages.length; i++) {
|
|
1569
|
-
await session.send(import_koishi.h.image(resultImages[i]));
|
|
1570
|
-
if (resultImages.length > 1 && i < resultImages.length - 1) {
|
|
1571
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
await recordUserUsage(session, COMMANDS.IMG_TO_IMG, resultImages.length);
|
|
1575
|
-
activeTasks.delete(userId);
|
|
1576
|
-
} catch (error) {
|
|
1577
|
-
activeTasks.delete(userId);
|
|
1578
|
-
logger.error("自定义图像处理失败", { userId, error });
|
|
1579
|
-
if (error?.message) {
|
|
1580
|
-
return `图像处理失败:${error.message}`;
|
|
1581
|
-
}
|
|
1582
|
-
return "图像处理失败,请稍后重试";
|
|
1583
|
-
}
|
|
1584
|
-
})(),
|
|
1585
|
-
new Promise(
|
|
1586
|
-
(_, reject) => setTimeout(() => reject(new Error("命令执行超时")), config.commandTimeout * 1e3)
|
|
1587
|
-
)
|
|
1588
|
-
]).catch((error) => {
|
|
1589
|
-
const userId = session.userId;
|
|
1590
|
-
if (userId) activeTasks.delete(userId);
|
|
1591
|
-
logger.error("自定义图像处理超时或失败", { userId, error });
|
|
1592
|
-
return error.message === "命令执行超时" ? "图像处理超时,请重试" : `图像处理失败:${error.message}`;
|
|
1593
|
-
});
|
|
1483
|
+
const numImages = options?.num || config.defaultNumImages;
|
|
1484
|
+
const mode = options?.multiple ? "multiple" : "single";
|
|
1485
|
+
const limitCheck = await checkDailyLimit(session.userId, numImages);
|
|
1486
|
+
if (!limitCheck.allowed) {
|
|
1487
|
+
return limitCheck.message;
|
|
1488
|
+
}
|
|
1489
|
+
const requestContext = {
|
|
1490
|
+
numImages
|
|
1491
|
+
};
|
|
1492
|
+
return processImageWithTimeout(session, img, "", COMMANDS.IMG_TO_IMG, requestContext, {}, mode);
|
|
1594
1493
|
});
|
|
1595
1494
|
ctx.command(COMMANDS.COMPOSE_IMAGE, "合成多张图片,使用自定义prompt控制合成效果").option("num", "-n <num:number> 生成图片数量 (1-4)").action(async ({ session, options }) => {
|
|
1596
1495
|
if (!session?.userId) return "会话无效";
|