koishi-plugin-aka-ai-generator 0.7.1 → 0.7.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.d.ts CHANGED
@@ -42,6 +42,9 @@ export interface Config {
42
42
  securityBlockWindow: number;
43
43
  securityBlockWarningThreshold: number;
44
44
  enableVideoGeneration: boolean;
45
+ videoProvider: 'yunwu';
46
+ videoApiKey: string;
47
+ videoApiBase: string;
45
48
  videoModelId: string;
46
49
  videoMaxWaitTime: number;
47
50
  videoCreditsMultiplier: number;
package/lib/index.js CHANGED
@@ -984,41 +984,18 @@ var YunwuVideoProvider = class {
984
984
  async queryTaskStatus(taskId) {
985
985
  const { logger, ctx } = this.config;
986
986
  try {
987
- const possibleEndpoints = [
988
- `/v1/video/${taskId}`,
989
- `/v1/video/status/${taskId}`,
990
- `/v1/videos/generations/${taskId}`
991
- ];
992
- let response = null;
993
- let lastError = null;
994
- for (const endpoint of possibleEndpoints) {
995
- try {
996
- response = await ctx.http.get(
997
- `${this.config.apiBase}${endpoint}`,
998
- {
999
- headers: {
1000
- "Authorization": `Bearer ${this.config.apiKey}`,
1001
- "Accept": "application/json"
1002
- },
1003
- timeout: this.config.apiTimeout * 1e3
1004
- }
1005
- );
1006
- if (response && !response.error) {
1007
- logger?.debug("查询任务状态成功", { taskId, endpoint });
1008
- break;
1009
- }
1010
- } catch (err) {
1011
- lastError = err;
1012
- if (err.response?.status === 404 && possibleEndpoints.indexOf(endpoint) < possibleEndpoints.length - 1) {
1013
- logger?.debug("尝试下一个查询端点", { taskId, endpoint, nextEndpoint: possibleEndpoints[possibleEndpoints.indexOf(endpoint) + 1] });
1014
- continue;
1015
- }
1016
- throw err;
987
+ const endpoint = `/v1/video/${taskId}`;
988
+ logger?.debug("查询任务状态", { taskId, endpoint });
989
+ const response = await ctx.http.get(
990
+ `${this.config.apiBase}${endpoint}`,
991
+ {
992
+ headers: {
993
+ "Authorization": `Bearer ${this.config.apiKey}`,
994
+ "Accept": "application/json"
995
+ },
996
+ timeout: this.config.apiTimeout * 1e3
1017
997
  }
1018
- }
1019
- if (!response) {
1020
- throw lastError || new Error("所有查询端点都失败");
1021
- }
998
+ );
1022
999
  const status = response.status || response.data?.status || "pending";
1023
1000
  const videoUrl = response.video_url || response.url || response.data?.video_url || response.data?.url;
1024
1001
  return {
@@ -1073,6 +1050,8 @@ var YunwuVideoProvider = class {
1073
1050
  try {
1074
1051
  logger?.info("开始生成视频", { prompt, imageUrl, options });
1075
1052
  const taskId = await this.createVideoTask(prompt, imageUrl, options);
1053
+ logger?.debug("任务已创建,等待 3 秒后开始查询", { taskId });
1054
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
1076
1055
  const videoUrl = await this.pollTaskCompletion(taskId, maxWaitTime);
1077
1056
  logger?.info("视频生成完成", { taskId, videoUrl });
1078
1057
  return videoUrl;
@@ -1653,9 +1632,14 @@ var Config = import_koishi2.Schema.intersect([
1653
1632
  prompts: import_koishi2.Schema.array(StyleItemSchema).role("table").default([]).description("属于该类型的 prompt 列表")
1654
1633
  })).role("table").default({}).description("按类型管理的 prompt 组,键名即为分组名称")
1655
1634
  }),
1656
- // 视频生成配置
1635
+ // 视频生成配置(独立于图像生成配置)
1657
1636
  import_koishi2.Schema.object({
1658
1637
  enableVideoGeneration: import_koishi2.Schema.boolean().default(false).description("启用图生成视频功能(消耗较大,需谨慎开启)"),
1638
+ videoProvider: import_koishi2.Schema.union([
1639
+ import_koishi2.Schema.const("yunwu").description("云雾服务")
1640
+ ]).default("yunwu").description("视频生成供应商(目前只支持云雾)"),
1641
+ videoApiKey: import_koishi2.Schema.string().description("视频生成 API 密钥(独立于图像生成配置)").role("secret").default(""),
1642
+ videoApiBase: import_koishi2.Schema.string().default("https://yunwu.ai").description("视频生成 API 地址"),
1659
1643
  videoModelId: import_koishi2.Schema.string().default("sora-2").description("视频生成模型ID (sora-2 或 sora-2-pro)"),
1660
1644
  videoMaxWaitTime: import_koishi2.Schema.number().default(300).min(60).max(600).description("视频生成最大等待时间(秒),超时后可异步查询"),
1661
1645
  videoCreditsMultiplier: import_koishi2.Schema.number().default(5).min(1).max(20).description("视频生成积分倍数(相对于图片生成,默认5倍)"),
@@ -1666,14 +1650,8 @@ var Config = import_koishi2.Schema.intersect([
1666
1650
  aspectRatio: import_koishi2.Schema.string().description("宽高比(如 16:9)")
1667
1651
  })).role("table").default([
1668
1652
  {
1669
- commandName: "慢动作视频",
1670
- prompt: "缓慢流畅的运镜,展现细节和质感",
1671
- duration: 25,
1672
- aspectRatio: "16:9"
1673
- },
1674
- {
1675
- commandName: "快节奏视频",
1676
- prompt: "快速动态的场景变化,充满活力",
1653
+ commandName: "变视频",
1654
+ prompt: "将该图片生成一段符合产品展现的流畅视频",
1677
1655
  duration: 15,
1678
1656
  aspectRatio: "16:9"
1679
1657
  }
@@ -1703,16 +1681,22 @@ function apply(ctx, config) {
1703
1681
  const modelMappingIndex = buildModelMappingIndex(config.modelMappings);
1704
1682
  let videoProvider = null;
1705
1683
  if (config.enableVideoGeneration) {
1706
- videoProvider = new YunwuVideoProvider({
1707
- apiKey: config.yunwuApiKey,
1708
- modelId: config.videoModelId,
1709
- apiBase: "https://yunwu.ai",
1710
- apiTimeout: config.apiTimeout,
1711
- logLevel: config.logLevel,
1712
- logger,
1713
- ctx
1714
- });
1715
- logger.info(`视频生成功能已启用 (模型: ${config.videoModelId})`);
1684
+ if (!config.videoApiKey) {
1685
+ logger.warn("视频生成功能已启用,但未配置视频 API 密钥,视频功能将不可用");
1686
+ } else if (config.videoProvider !== "yunwu") {
1687
+ logger.warn(`视频生成供应商 ${config.videoProvider} 暂不支持,仅支持 yunwu`);
1688
+ } else {
1689
+ videoProvider = new YunwuVideoProvider({
1690
+ apiKey: config.videoApiKey,
1691
+ modelId: config.videoModelId,
1692
+ apiBase: config.videoApiBase,
1693
+ apiTimeout: config.apiTimeout,
1694
+ logLevel: config.logLevel,
1695
+ logger,
1696
+ ctx
1697
+ });
1698
+ logger.info(`视频生成功能已启用 (供应商: ${config.videoProvider}, 模型: ${config.videoModelId}, API: ${config.videoApiBase})`);
1699
+ }
1716
1700
  }
1717
1701
  const styleDefinitions = collectStyleDefinitions();
1718
1702
  function collectStyleDefinitions() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-aka-ai-generator",
3
3
  "description": "自用AI生成插件(GPTGod & Yunwu)",
4
- "version": "0.7.1",
4
+ "version": "0.7.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [