koishi-plugin-aka-ai-image-generator 0.2.0
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/README.md +37 -0
- package/dist/index.d.ts +216 -0
- package/dist/index.js +3413 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# koishi-plugin-aka-ai-image-generator
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/koishi-plugin-aka-ai-image-generator)
|
|
4
|
+
|
|
5
|
+
自用 AI 图像生成插件 V2(image-only)。
|
|
6
|
+
|
|
7
|
+
> 范围:仅图像生成。视频生成不在本插件范围内。
|
|
8
|
+
|
|
9
|
+
## 支持的供应商
|
|
10
|
+
|
|
11
|
+
- 云雾(自适应:Gemini / OpenAI 协议)
|
|
12
|
+
- GPT God
|
|
13
|
+
- Google Gemini 官方
|
|
14
|
+
- Grok(xAI,可经云雾中转)
|
|
15
|
+
- OpenAI 兼容(任意符合 OpenAI Images API 的端点)
|
|
16
|
+
- OpenAI 官方 GPT Image
|
|
17
|
+
|
|
18
|
+
## 命令(v0.2.0 MVP)
|
|
19
|
+
|
|
20
|
+
| 命令 | 别名 | 说明 |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| `aig.文生图 <prompt>` | `aig.t2i` | 纯文字描述生成图片 |
|
|
23
|
+
| `aig.图生图 [img] <prompt>` | `aig.i2i` | 单张图片 + 修改描述 |
|
|
24
|
+
| `aig.图像额度` | `aig.quota` | 查询当前用户额度 |
|
|
25
|
+
|
|
26
|
+
支持的修饰符(紧跟在命令后):
|
|
27
|
+
|
|
28
|
+
- `--n <数量>` 一次生成图片数量
|
|
29
|
+
- `--model <模型>` 覆盖默认模型
|
|
30
|
+
- `--ar <宽高比>` 例如 `1:1`、`16:9`
|
|
31
|
+
- `--res <分辨率>` 例如 `1024x1024`
|
|
32
|
+
|
|
33
|
+
## 状态
|
|
34
|
+
|
|
35
|
+
- v0.1.x:架构骨架(Provider Registry + Tagged Union Schema + 6 个图像 Provider)
|
|
36
|
+
- v0.2.0:MVP(Service + 简化版 Orchestrator + 文生图 / 图生图 / 额度查询命令)
|
|
37
|
+
- v0.3.x(计划,Phase 5):完整命令族(合成图 / 风格迁移 / 改姿势 / 修改设计 / 变像素 / 充值 / 参数指令)+ ChatLuna 桥接 + 用户数据迁移工具
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import * as koishi from 'koishi';
|
|
2
|
+
import { Context, Schema } from 'koishi';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 图像生成参数
|
|
6
|
+
*
|
|
7
|
+
* 与 v1 的 ImageGenerationOptions 兼容,但移除了对 ProviderConfig 的依赖。
|
|
8
|
+
* 配置通过构造函数注入而非选项字段传递,保持本结构精简。
|
|
9
|
+
*/
|
|
10
|
+
interface ImageGenerationOptions {
|
|
11
|
+
/** 分辨率预设:'1k' / '2k' / '4k' 或自定义 'WIDTHxHEIGHT'(如 '1024x1536') */
|
|
12
|
+
resolution?: '1k' | '2k' | '4k' | `${number}x${number}`;
|
|
13
|
+
/** 宽高比预设;当未指定 resolution 时由各 Provider 映射到具体尺寸 */
|
|
14
|
+
aspectRatio?: '1:1' | '4:3' | '16:9' | '9:16' | '3:2' | '2:3';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 流式回调:每生成一张图片就触发一次。
|
|
18
|
+
*
|
|
19
|
+
* - imageUrl 可能是远程 URL,也可能是 data:image/...;base64,... 的内嵌格式
|
|
20
|
+
* - index 从 0 开始
|
|
21
|
+
* - total 是请求的总张数(不一定等于最终成功生成数)
|
|
22
|
+
*/
|
|
23
|
+
type ImageGeneratedCallback = (imageUrl: string, index: number, total: number) => void | Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* 图像供应商(统一接口)
|
|
26
|
+
*
|
|
27
|
+
* v2 相比 v1 的变化:
|
|
28
|
+
* - 移除 ProviderConfig 字段(由具体子类构造函数管理)
|
|
29
|
+
* - 错误统一抛出 ProviderError 子类(见 ./errors.ts)
|
|
30
|
+
* - 通过基类 BaseImageProvider 共享 timeout / retry / 错误处理逻辑
|
|
31
|
+
*/
|
|
32
|
+
interface ImageProvider$1 {
|
|
33
|
+
/** Provider 标识,例如 'openai-images' / 'gemini' / 'gptgod' */
|
|
34
|
+
readonly name: string;
|
|
35
|
+
/**
|
|
36
|
+
* 生成图像
|
|
37
|
+
*
|
|
38
|
+
* @param prompt 提示词
|
|
39
|
+
* @param imageUrls 输入图片:空数组/空字符串表示文生图;否则为图生图(编辑)
|
|
40
|
+
* @param numImages 期望生成数量
|
|
41
|
+
* @param options 生成参数(分辨率/宽高比)
|
|
42
|
+
* @param onImageGenerated 流式回调(每张生成完即调用)
|
|
43
|
+
*/
|
|
44
|
+
generateImages(prompt: string, imageUrls: string | string[], numImages: number, options?: ImageGenerationOptions, onImageGenerated?: ImageGeneratedCallback): Promise<string[]>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Provider 工厂函数签名(registry 使用)
|
|
48
|
+
*
|
|
49
|
+
* @param ctx Koishi 上下文
|
|
50
|
+
* @param config 通过 Schema 验证后的 Provider 凭证 + 模型字段
|
|
51
|
+
*/
|
|
52
|
+
type ProviderFactory = (ctx: Context, config: Record<string, unknown>) => ImageProvider$1;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Provider 注册表(7.11.4 节)
|
|
56
|
+
*
|
|
57
|
+
* 设计要点:
|
|
58
|
+
* - 注册表实例是无状态的(只持有工厂引用)
|
|
59
|
+
* - 实际 ImageProvider 实例通过 createProvider 即时构造,由调用方决定缓存策略
|
|
60
|
+
* - 名字大小写不敏感
|
|
61
|
+
*
|
|
62
|
+
* 使用示例:
|
|
63
|
+
* ```ts
|
|
64
|
+
* const registry = new ProviderRegistry()
|
|
65
|
+
* registry.register('openai-images', (ctx, cfg) => new OpenAIImagesProvider({ ctx, ...cfg }))
|
|
66
|
+
* const provider = registry.createProvider('openai-images', ctx, cfg)
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare class ProviderRegistry {
|
|
70
|
+
private readonly factories;
|
|
71
|
+
/**
|
|
72
|
+
* 注册一个 Provider 工厂。重复注册会覆盖前一次。
|
|
73
|
+
*/
|
|
74
|
+
register(name: string, factory: ProviderFactory): void;
|
|
75
|
+
/**
|
|
76
|
+
* 注销一个 Provider。
|
|
77
|
+
*/
|
|
78
|
+
unregister(name: string): boolean;
|
|
79
|
+
/** 列出所有已注册 Provider 名(按注册顺序) */
|
|
80
|
+
list(): string[];
|
|
81
|
+
/** 是否已注册 */
|
|
82
|
+
has(name: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* 创建一个 Provider 实例。
|
|
85
|
+
*
|
|
86
|
+
* @throws 当 name 未注册时抛出
|
|
87
|
+
*/
|
|
88
|
+
createProvider(name: string, ctx: Context, config: Record<string, unknown>): ImageProvider$1;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 配置选项中的「供应商」枚举(Schema 用于 Tagged Union 标签字段)。
|
|
93
|
+
*
|
|
94
|
+
* 与 ProviderType 的差异:这是**用户配置层**的标签,背后映射到一个或多个
|
|
95
|
+
* ProviderRegistry 中的实际 provider 名(例如 'yunwu' 标签 → 'yunwu-adaptive' provider)。
|
|
96
|
+
*/
|
|
97
|
+
type ImageProvider = 'yunwu' | 'gptgod' | 'gemini' | 'grok' | 'openai' | 'gpt-official';
|
|
98
|
+
/** 云雾 Provider 的协议格式选择 */
|
|
99
|
+
type ApiFormat = 'gemini' | 'openai';
|
|
100
|
+
interface ModelMappingConfig {
|
|
101
|
+
suffix: string;
|
|
102
|
+
modelId: string;
|
|
103
|
+
provider?: ImageProvider;
|
|
104
|
+
apiFormat?: ApiFormat;
|
|
105
|
+
/** 是否为受限模型,仅模型白名单内的用户可调用 */
|
|
106
|
+
restricted?: boolean;
|
|
107
|
+
}
|
|
108
|
+
interface StyleConfig {
|
|
109
|
+
commandName: string;
|
|
110
|
+
description?: string;
|
|
111
|
+
prompt: string;
|
|
112
|
+
aliases?: string[];
|
|
113
|
+
keywords?: string[];
|
|
114
|
+
examples?: string[];
|
|
115
|
+
category?: string;
|
|
116
|
+
whenToUse?: string;
|
|
117
|
+
}
|
|
118
|
+
interface StyleGroupConfig {
|
|
119
|
+
prompts: StyleConfig[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* V2 配置 Schema —— Phase 3 Batch D 终稿(image-only)。
|
|
124
|
+
*
|
|
125
|
+
* 设计要点:
|
|
126
|
+
* - **Tagged Union**:`Schema.intersect([base, Schema.union([...])])`,每个分支只声明自己用到的字段,
|
|
127
|
+
* 不再使用 v1 的 `.hidden()` 反模式。
|
|
128
|
+
* - **范围**:仅图像生成。所有视频相关字段 / Schema 已移除。
|
|
129
|
+
* - **运行期类型**:`Config` interface 与 Schema 保持一致;可被 v1 的 cherry-pick 文件
|
|
130
|
+
* (UserManager / prompt-timeout)继续使用。
|
|
131
|
+
*
|
|
132
|
+
* 顶层布局(按用户视觉优先级排序):
|
|
133
|
+
* ① 图像供应商(Tagged Union 主体)
|
|
134
|
+
* ② 图像生成(风格预设 styles + styleGroups + 基础显示设置)
|
|
135
|
+
* ③ 模型映射
|
|
136
|
+
* ④ 限流与配额
|
|
137
|
+
* ⑤ 安全策略
|
|
138
|
+
* ⑥ 管理员设置
|
|
139
|
+
* ⑦ ChatLuna 集成
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
interface Config$1 {
|
|
143
|
+
provider: ImageProvider;
|
|
144
|
+
yunwuApiKey?: string;
|
|
145
|
+
yunwuModelId?: string;
|
|
146
|
+
yunwuApiFormat?: ApiFormat;
|
|
147
|
+
yunwuApiBase?: string;
|
|
148
|
+
gptgodApiKey?: string;
|
|
149
|
+
gptgodModelId?: string;
|
|
150
|
+
geminiApiKey?: string;
|
|
151
|
+
geminiModelId?: string;
|
|
152
|
+
geminiApiBase?: string;
|
|
153
|
+
grokApiKey?: string;
|
|
154
|
+
grokModelId?: string;
|
|
155
|
+
grokApiBase?: string;
|
|
156
|
+
openaiApiKey?: string;
|
|
157
|
+
openaiModelId?: string;
|
|
158
|
+
openaiApiBase?: string;
|
|
159
|
+
gptOfficialApiKey?: string;
|
|
160
|
+
gptOfficialModelId?: string;
|
|
161
|
+
gptOfficialApiBase?: string;
|
|
162
|
+
styles: StyleConfig[];
|
|
163
|
+
styleGroups?: Record<string, StyleGroupConfig>;
|
|
164
|
+
showQuotaInImageCommands: boolean;
|
|
165
|
+
defaultNumImages: number;
|
|
166
|
+
modelMappings?: ModelMappingConfig[];
|
|
167
|
+
dailyFreeLimit: number;
|
|
168
|
+
unlimitedPlatforms: string[];
|
|
169
|
+
rateLimitWindow: number;
|
|
170
|
+
rateLimitMax: number;
|
|
171
|
+
securityBlockWindow: number;
|
|
172
|
+
securityBlockWarningThreshold: number;
|
|
173
|
+
adminUsers: string[];
|
|
174
|
+
permanentMembers: string[];
|
|
175
|
+
modelWhitelistUsers: string[];
|
|
176
|
+
logLevel: 'info' | 'debug';
|
|
177
|
+
chatlunaEnabled: boolean;
|
|
178
|
+
chatlunaContextInjectionEnabled: boolean;
|
|
179
|
+
chatlunaContextHistorySize: number;
|
|
180
|
+
chatlunaContextTtlSeconds: number;
|
|
181
|
+
apiTimeout: number;
|
|
182
|
+
}
|
|
183
|
+
declare const Config$1: Schema<Config$1>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* V2 插件入口(aka-ai-image-generator) —— 仅图像生成。
|
|
187
|
+
*
|
|
188
|
+
* Phase 4 MVP 接线:
|
|
189
|
+
* - ProviderRegistry:模块级单例,注册 6 个 image-only Provider 工厂
|
|
190
|
+
* - UserManager:用户配额 / 限流 / 安全计数(cherry-pick 自 v1)
|
|
191
|
+
* - AiImageGeneratorService:核心服务(Provider 实例化 + 配额 + 用量 + 图像记忆)
|
|
192
|
+
* - ImageGenerationOrchestrator:MVP 编排(文生图 + 图生图,命令级超时)
|
|
193
|
+
* - 命令族:aig.文生图 / aig.图生图 / aig.图像额度
|
|
194
|
+
*
|
|
195
|
+
* 配置热重载:通过 ctx.scope.update 风格的 acceptor 处理;本入口在变更时同步
|
|
196
|
+
* 更新闭包内的 currentConfig,并调用 `service.updateConfig(next)`。
|
|
197
|
+
*
|
|
198
|
+
* Phase 5 计划:
|
|
199
|
+
* - 迁移工具 + 文档(v1 → v2 用户数据迁移)
|
|
200
|
+
* - ChatLuna 桥接(manager/runtime/context-injection/tools)
|
|
201
|
+
* - 完整命令族:合成图、风格迁移、改姿势、修改设计、变像素、充值、参数指令
|
|
202
|
+
* - 发布到 npm
|
|
203
|
+
*
|
|
204
|
+
* 注:本插件**不包含视频生成**功能,相关代码 / 配置 / 文档全部不在 v2 范围内。
|
|
205
|
+
*/
|
|
206
|
+
declare const name = "aka-ai-image-generator";
|
|
207
|
+
type Config = Config$1;
|
|
208
|
+
declare const Config: koishi.Schema<Config$1>;
|
|
209
|
+
/**
|
|
210
|
+
* 暴露给同插件其它模块(如未来的 ChatLuna bridge)的注册表入口。
|
|
211
|
+
* 不通过 ctx.set() 暴露,避免污染全局服务命名空间。
|
|
212
|
+
*/
|
|
213
|
+
declare function getProviderRegistry(): ProviderRegistry;
|
|
214
|
+
declare function apply(ctx: Context, config: Config): void;
|
|
215
|
+
|
|
216
|
+
export { Config, apply, getProviderRegistry, name };
|