cortico-world-imggen 0.3.3 → 0.3.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/README.md +32 -0
- package/describe.json +26 -26
- package/package.json +1 -1
- package/src/config.ts +11 -0
- package/src/library.ts +11 -4
- package/src/studio/studio.html +214 -21
- package/src/tools.ts +29 -38
- package/src/world.ts +1 -1
package/README.md
CHANGED
|
@@ -218,3 +218,35 @@ ONEBOT_TOKEN=<协议端 token> IMGGEN_KEY=<key> IMGGEN_REFS="D:\a.png;D:\b.png"
|
|
|
218
218
|
- 65535 的任务超时后不会自动取回,需要重新生成(不会重复扣费那条路没做)。
|
|
219
219
|
- 工作室页面的「生成」只出图、不发 QQ。
|
|
220
220
|
- 接口不支持参考图时(比如 Kolors),要么把「参考图发送方式」改成 `none`,要么换支持图生图的模型。
|
|
221
|
+
|
|
222
|
+
## 更新日志
|
|
223
|
+
|
|
224
|
+
### 0.3.4
|
|
225
|
+
|
|
226
|
+
- 工作室生成页体验:
|
|
227
|
+
- 常用尺寸一键选(方图 / 头像 / 横屏 / 大横屏 / 手机壁纸 / 21:9)
|
|
228
|
+
- 生成时显示已用秒数,可随时取消
|
|
229
|
+
- 出图后可「再画一张」「存进参考库」「下载」「复制路径」
|
|
230
|
+
- 表单参数存在浏览器本地,刷新/重开页面还在
|
|
231
|
+
- Ctrl+Enter(macOS 为 Cmd+Enter)直接生成
|
|
232
|
+
- 上下文开销:新增「库清单详细度」配置(full / alias / name),默认只列「名字+别名」,库变大时不再线性撑大前缀;`imggen_draw` 与 `imggen_library` 的参数说明去重压缩。本机实测固定开销 2,494 → 2,052 tok(约 -18%)。
|
|
233
|
+
- 修复:`normalizeConfig` 漏拷贝 `libraryDetail`,导致三档切换无效(永远按 alias 渲染)。
|
|
234
|
+
- 兼容性:工具名、参数名、返回结构均未破坏,只做新增与说明压缩。
|
|
235
|
+
|
|
236
|
+
### 0.3.3
|
|
237
|
+
|
|
238
|
+
- 新增 `outfitByContext`(情境穿搭)的写入:`imggen_library` 的 `add` / `update`、工作室页面的「情境穿搭」输入框、`/api/library/add` 与 `/api/library/update` 三个入口都能配,落盘为标准 `entry.json` 字段。
|
|
239
|
+
- `imggen_library` 的 `list` 与 `get` 开始带出「默认服饰」「情境穿搭」;没配就不输出,输出体积不变。
|
|
240
|
+
- 环境提示词新增与「一桌菜」(cortico-world-feast)的联动:让她发图前先查 `feast_life_now`,穿着与场景按日程写。
|
|
241
|
+
- 修复:工作室页面编辑条目时「情境穿搭」不回显。
|
|
242
|
+
|
|
243
|
+
### 0.3.2
|
|
244
|
+
|
|
245
|
+
- 请求体固定发 watermark: false,去掉火山 Seedream 默认盖的「AI生成」水印。
|
|
246
|
+
- 新增工作室「设置」页,API Key 保存到本机 imggen-secret.json,页面只显示尾号。
|
|
247
|
+
- 接口地址支持短名(rk / dashscope / siliconflow / openai),尺寸分隔符按服务商自动转换。
|
|
248
|
+
- 参考图缓存、429/5xx 自动重试、工作室端口兜底。
|
|
249
|
+
|
|
250
|
+
### 0.3.0
|
|
251
|
+
|
|
252
|
+
- 首个公开版本。
|
package/describe.json
CHANGED
|
@@ -2,81 +2,81 @@
|
|
|
2
2
|
"tools": [
|
|
3
3
|
{
|
|
4
4
|
"name": "imggen_draw",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "画一张图存到本地并直接发到 QQ。prompt 只写画面本身,神态/动作/镜头/光线用下面的关键词,别在 prompt 里重复。人物/服饰/场景/道具都填参考库里的名字;to 抄 QQ 消息 meta 里的 conv。回执有路径、尺寸、关键词、参考图和发送结果,「生成失败」开头不算成功;一张几十秒,等回执。",
|
|
6
6
|
"parameters": {
|
|
7
7
|
"type": "object",
|
|
8
8
|
"additionalProperties": false,
|
|
9
9
|
"properties": {
|
|
10
10
|
"prompt": {
|
|
11
11
|
"type": "string",
|
|
12
|
-
"description": "
|
|
12
|
+
"description": "画面:谁在做什么、在哪、什么风格。一到三句。"
|
|
13
13
|
},
|
|
14
14
|
"characters": {
|
|
15
15
|
"type": "array",
|
|
16
16
|
"items": {
|
|
17
17
|
"type": "string"
|
|
18
18
|
},
|
|
19
|
-
"description": "
|
|
19
|
+
"description": "出镜人物(库里的名字,可多个),保证长相一致。"
|
|
20
20
|
},
|
|
21
21
|
"outfits": {
|
|
22
22
|
"type": "array",
|
|
23
23
|
"items": {
|
|
24
24
|
"type": "string"
|
|
25
25
|
},
|
|
26
|
-
"description": "
|
|
26
|
+
"description": "服饰(库里的名字),不填自动搭配。"
|
|
27
27
|
},
|
|
28
28
|
"scene": {
|
|
29
29
|
"type": "string",
|
|
30
|
-
"description": "
|
|
30
|
+
"description": "场景(库里的名字)。"
|
|
31
31
|
},
|
|
32
32
|
"props": {
|
|
33
33
|
"type": "array",
|
|
34
34
|
"items": {
|
|
35
35
|
"type": "string"
|
|
36
36
|
},
|
|
37
|
-
"description": "
|
|
37
|
+
"description": "道具(库里的名字)。"
|
|
38
38
|
},
|
|
39
39
|
"situation": {
|
|
40
40
|
"type": "string",
|
|
41
|
-
"description": "
|
|
41
|
+
"description": "情境(词表里的名字)。"
|
|
42
42
|
},
|
|
43
43
|
"expression": {
|
|
44
44
|
"type": "string",
|
|
45
|
-
"description": "
|
|
45
|
+
"description": "神态(词表里的名字)。"
|
|
46
46
|
},
|
|
47
47
|
"pose": {
|
|
48
48
|
"type": "string",
|
|
49
|
-
"description": "
|
|
49
|
+
"description": "动作(词表里的名字)。"
|
|
50
50
|
},
|
|
51
51
|
"shot": {
|
|
52
52
|
"type": "string",
|
|
53
|
-
"description": "
|
|
53
|
+
"description": "镜头(词表里的名字)。"
|
|
54
54
|
},
|
|
55
55
|
"light": {
|
|
56
56
|
"type": "string",
|
|
57
|
-
"description": "
|
|
57
|
+
"description": "光线(词表里的名字),不填用情境默认。"
|
|
58
58
|
},
|
|
59
59
|
"size": {
|
|
60
60
|
"type": "string",
|
|
61
|
-
"description": "
|
|
61
|
+
"description": "覆盖默认尺寸,如 1024x1024。"
|
|
62
62
|
},
|
|
63
63
|
"count": {
|
|
64
64
|
"type": "integer",
|
|
65
65
|
"minimum": 1,
|
|
66
66
|
"maximum": 4,
|
|
67
|
-
"description": "
|
|
67
|
+
"description": "张数,默认 1;多张更慢更贵。"
|
|
68
68
|
},
|
|
69
69
|
"to": {
|
|
70
70
|
"type": "string",
|
|
71
|
-
"description": "
|
|
71
|
+
"description": "group:<群号> 或 private:<QQ号>;不填用默认目标。"
|
|
72
72
|
},
|
|
73
73
|
"caption": {
|
|
74
74
|
"type": "string",
|
|
75
|
-
"description": "
|
|
75
|
+
"description": "跟图一起发的一句话。"
|
|
76
76
|
},
|
|
77
77
|
"send": {
|
|
78
78
|
"type": "boolean",
|
|
79
|
-
"description": "
|
|
79
|
+
"description": "false = 只生成不发。"
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"required": [
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
149
|
"name": "imggen_library",
|
|
150
|
-
"description": "
|
|
150
|
+
"description": "本地参考库(人物/服饰/场景/道具)。list 看清单,get 看某条设定与参考图,add 存新条目(file 填图片路径或 http 地址),update 改字段,remove 挪进回收站。出图前不确定名字就 list,别猜;对方说「记住这个角色」先拿图片路径再 add。",
|
|
151
151
|
"parameters": {
|
|
152
152
|
"type": "object",
|
|
153
153
|
"additionalProperties": false,
|
|
@@ -175,48 +175,48 @@
|
|
|
175
175
|
},
|
|
176
176
|
"name": {
|
|
177
177
|
"type": "string",
|
|
178
|
-
"description": "
|
|
178
|
+
"description": "条目名(get/update/remove 用;add 时是新条目名)。"
|
|
179
179
|
},
|
|
180
180
|
"description": {
|
|
181
181
|
"type": "string",
|
|
182
|
-
"description": "add/update
|
|
182
|
+
"description": "add/update:外观描述,只写长相或设计,会进提示词。"
|
|
183
183
|
},
|
|
184
184
|
"aliases": {
|
|
185
185
|
"type": "array",
|
|
186
186
|
"items": {
|
|
187
187
|
"type": "string"
|
|
188
188
|
},
|
|
189
|
-
"description": "add/update
|
|
189
|
+
"description": "add/update:别名。"
|
|
190
190
|
},
|
|
191
191
|
"tags": {
|
|
192
192
|
"type": "array",
|
|
193
193
|
"items": {
|
|
194
194
|
"type": "string"
|
|
195
195
|
},
|
|
196
|
-
"description": "add/update
|
|
196
|
+
"description": "add/update:标签。"
|
|
197
197
|
},
|
|
198
198
|
"persona": {
|
|
199
199
|
"type": "string",
|
|
200
|
-
"description": "add/update
|
|
200
|
+
"description": "add/update:人设,只给自己看,不外发。"
|
|
201
201
|
},
|
|
202
202
|
"expressions": {
|
|
203
203
|
"type": "string",
|
|
204
|
-
"description": "add/update
|
|
204
|
+
"description": "add/update:神态特点,会进提示词。"
|
|
205
205
|
},
|
|
206
206
|
"defaultOutfit": {
|
|
207
207
|
"type": "string",
|
|
208
|
-
"description": "add/update
|
|
208
|
+
"description": "add/update:默认服饰(服饰条目名)。"
|
|
209
209
|
},
|
|
210
210
|
"outfitByContext": {
|
|
211
211
|
"type": "object",
|
|
212
212
|
"additionalProperties": {
|
|
213
213
|
"type": "string"
|
|
214
214
|
},
|
|
215
|
-
"description": "add/update
|
|
215
|
+
"description": "add/update:情境→服饰名,如 {\"睡前\":\"睡衣\"};也收 \"睡前=睡衣, 刚睡醒=睡衣\"。只对人物有用。"
|
|
216
216
|
},
|
|
217
217
|
"file": {
|
|
218
218
|
"type": "string",
|
|
219
|
-
"description": "add
|
|
219
|
+
"description": "add:参考图,本地路径或 http(s) 地址。"
|
|
220
220
|
}
|
|
221
221
|
},
|
|
222
222
|
"required": [
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -42,6 +42,8 @@ export interface ImggenConfig {
|
|
|
42
42
|
/* ── 参考库与产物 ── */
|
|
43
43
|
/** 参考库根目录;留空用 <数据目录>/imggen-library。 */
|
|
44
44
|
libraryRoot: string;
|
|
45
|
+
/** 环境提示词里库清单的详细程度:full=别名+标签+神态,alias=名字+别名,name=只名字。 */
|
|
46
|
+
libraryDetail: 'full' | 'alias' | 'name';
|
|
45
47
|
/** 图片保存目录;留空用 <数据目录>/imggen。 */
|
|
46
48
|
saveDir: string;
|
|
47
49
|
|
|
@@ -78,6 +80,7 @@ export const DEFAULTS: ImggenConfig = {
|
|
|
78
80
|
timeoutMs: 180_000,
|
|
79
81
|
maxBytes: 8_000_000,
|
|
80
82
|
libraryRoot: '',
|
|
83
|
+
libraryDetail: 'alias',
|
|
81
84
|
saveDir: '',
|
|
82
85
|
autoSend: false,
|
|
83
86
|
// 发布默认留空:装的人自己填目标,别把别人的 QQ 号写死进包里。
|
|
@@ -124,6 +127,9 @@ export function normalizeConfig(raw: unknown): ImggenConfig {
|
|
|
124
127
|
if (typeof r.requestStyle === 'string' && (STYLES as readonly string[]).includes(r.requestStyle)) {
|
|
125
128
|
c.requestStyle = r.requestStyle as RequestStyle;
|
|
126
129
|
}
|
|
130
|
+
if (r.libraryDetail === 'full' || r.libraryDetail === 'alias' || r.libraryDetail === 'name') {
|
|
131
|
+
c.libraryDetail = r.libraryDetail;
|
|
132
|
+
}
|
|
127
133
|
if (typeof r.refMode === 'string' && (REF_MODES as readonly string[]).includes(r.refMode)) {
|
|
128
134
|
c.refMode = r.refMode as RefMode;
|
|
129
135
|
}
|
|
@@ -192,6 +198,11 @@ export const FIELD_META: Record<string, FieldMeta> = {
|
|
|
192
198
|
description: '留空 = <数据目录>/imggen-library,下面分 characters / outfits / scenes / props 四个子目录',
|
|
193
199
|
'x-path': { kind: 'directory' },
|
|
194
200
|
},
|
|
201
|
+
libraryDetail: {
|
|
202
|
+
title: '库清单详细度',
|
|
203
|
+
description: '写进环境提示词的参考库清单有多细。full=别名+标签+神态(最占上下文),alias=名字+别名(默认,省约 180 tok),name=只名字(库很大时用,细节让她用 imggen_library get 现查)',
|
|
204
|
+
enum: ['full', 'alias', 'name'],
|
|
205
|
+
},
|
|
195
206
|
saveDir: {
|
|
196
207
|
title: '生成图保存目录',
|
|
197
208
|
description: '留空 = <数据目录>/imggen,按日期分子目录',
|
package/src/library.ts
CHANGED
|
@@ -423,16 +423,23 @@ export function addImageToEntry(root: string, category: Category, id: string, sr
|
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
/** 库目录文本,进系统提示:让模型知道库里有什么,别去猜名字。 */
|
|
426
|
-
|
|
426
|
+
/** 库清单的详细程度;alias 是默认档,名字 + 别名,够她挑条目又不占上下文。 */
|
|
427
|
+
export type CatalogDetail = 'full' | 'alias' | 'name';
|
|
428
|
+
|
|
429
|
+
export function catalogText(lib: Library, maxPerCategory = 30, detail: CatalogDetail = 'alias'): string {
|
|
427
430
|
const lines: string[] = [];
|
|
428
431
|
for (const category of CATEGORIES) {
|
|
429
432
|
const entries = lib.byCategory[category];
|
|
430
433
|
if (!entries.length) continue;
|
|
431
434
|
const shown = entries.slice(0, maxPerCategory).map((e) => {
|
|
435
|
+
// name 档:只给名字,细节让她用 imggen_library get 现查。
|
|
436
|
+
if (detail === 'name') return e.images.length ? e.name : e.name + '(无参考图)';
|
|
432
437
|
const bits: string[] = [];
|
|
433
|
-
if (e.aliases.length) bits.push('别名 ' + e.aliases.join('/'));
|
|
434
|
-
if (
|
|
435
|
-
|
|
438
|
+
if (e.aliases.length) bits.push((detail === 'full' ? '别名 ' : '') + e.aliases.join('/'));
|
|
439
|
+
if (detail === 'full') {
|
|
440
|
+
if (e.tags.length) bits.push('标签 ' + e.tags.join('、'));
|
|
441
|
+
if (e.category === 'characters' && e.expressions) bits.push('神态 ' + e.expressions);
|
|
442
|
+
}
|
|
436
443
|
if (e.category === 'characters' && e.defaultOutfit) bits.push('默认服饰 ' + e.defaultOutfit);
|
|
437
444
|
if (e.category === 'characters' && Object.keys(e.outfitByContext).length) {
|
|
438
445
|
bits.push('情境穿搭 ' + formatOutfitByContext(e.outfitByContext));
|
package/src/studio/studio.html
CHANGED
|
@@ -144,12 +144,20 @@
|
|
|
144
144
|
<div class="row"><label>场景</label><select id="t-scene"></select></div>
|
|
145
145
|
<div class="row"><label>道具</label><div class="checklist" id="t-props"></div></div>
|
|
146
146
|
<div class="row"><label>尺寸 / 张数</label>
|
|
147
|
-
<div style="
|
|
147
|
+
<div style="flex:1">
|
|
148
|
+
<div style="display:flex;gap:8px;align-items:center">
|
|
149
|
+
<input type="text" id="t-size" style="max-width:160px">
|
|
150
|
+
<input type="text" id="t-count" style="max-width:80px" value="1" title="一次画几张">
|
|
151
|
+
</div>
|
|
152
|
+
<div class="sizes" id="t-sizes" style="display:flex;gap:6px;flex-wrap:wrap;margin-top:8px"></div>
|
|
153
|
+
</div>
|
|
148
154
|
</div>
|
|
149
155
|
</div>
|
|
150
|
-
<div class="bar" style="margin-top:12px">
|
|
156
|
+
<div class="bar" style="margin-top:12px;display:flex;gap:8px;align-items:center">
|
|
151
157
|
<button class="primary" id="btn-gen">生成</button>
|
|
158
|
+
<button class="ghost" id="btn-cancel" hidden>取消</button>
|
|
152
159
|
<span id="genmsg" class="msg"></span>
|
|
160
|
+
<span style="margin-left:auto;color:var(--dim);font-size:12px">Ctrl+Enter 也能生成</span>
|
|
153
161
|
</div>
|
|
154
162
|
<div id="genout"></div>
|
|
155
163
|
<div id="genprompt"></div>
|
|
@@ -196,12 +204,15 @@ let editing = null;
|
|
|
196
204
|
const $ = (id) => document.getElementById(id);
|
|
197
205
|
const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({'&':'&','<':'<','>':'>','"':'"'}[c]));
|
|
198
206
|
|
|
199
|
-
async function api(path, body) {
|
|
200
|
-
const res = await fetch(path, body === undefined ? {} : {
|
|
201
|
-
method: 'POST',
|
|
207
|
+
async function api(path, body, signal) {
|
|
208
|
+
const res = await fetch(path, body === undefined ? { signal } : {
|
|
209
|
+
method: 'POST',
|
|
210
|
+
headers: { 'content-type': 'application/json' },
|
|
211
|
+
body: JSON.stringify(body),
|
|
212
|
+
signal,
|
|
202
213
|
});
|
|
203
|
-
const data = await res.json();
|
|
204
|
-
if (!res.ok) throw new Error(data.error || ('HTTP ' + res.status));
|
|
214
|
+
const data = await res.json().catch(() => ({}));
|
|
215
|
+
if (!res.ok || data.ok === false) throw new Error(data.error || data.message || ('HTTP ' + res.status));
|
|
205
216
|
return data;
|
|
206
217
|
}
|
|
207
218
|
|
|
@@ -450,17 +461,104 @@ function renderTry() {
|
|
|
450
461
|
fillChecks('t-outfits', state.library.outfits);
|
|
451
462
|
fillChecks('t-props', state.library.props);
|
|
452
463
|
$('t-size').value = state.config.size;
|
|
464
|
+
renderSizePresets();
|
|
465
|
+
restoreParams();
|
|
466
|
+
// 表单改动随手记下来,下次打开还在
|
|
467
|
+
document.querySelectorAll('#tab-try input, #tab-try textarea, #tab-try select').forEach((el) => {
|
|
468
|
+
el.addEventListener('change', saveParams);
|
|
469
|
+
if (el.tagName === 'TEXTAREA' || el.type === 'text') el.addEventListener('blur', saveParams);
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const SIZE_PRESETS = [
|
|
474
|
+
['方图 1024×1024', '1024x1024'],
|
|
475
|
+
['头像 768×768', '768x768'],
|
|
476
|
+
['横屏 1920×1080', '1920x1080'],
|
|
477
|
+
['大横屏 2560×1440', '2560x1440'],
|
|
478
|
+
['手机壁纸 1080×1920', '1080x1920'],
|
|
479
|
+
['宽屏 21:9', '2560x1080'],
|
|
480
|
+
];
|
|
481
|
+
|
|
482
|
+
function renderSizePresets() {
|
|
483
|
+
const box = $('t-sizes');
|
|
484
|
+
if (!box) return;
|
|
485
|
+
box.innerHTML = SIZE_PRESETS.map(([label, value]) =>
|
|
486
|
+
'<button type="button" class="ghost sizechip" data-size="' + value + '" style="font-size:12px;padding:4px 10px">' + esc(label) + '</button>'
|
|
487
|
+
).join('');
|
|
488
|
+
box.querySelectorAll('[data-size]').forEach((b) => {
|
|
489
|
+
b.onclick = () => { $('t-size').value = b.dataset.size; saveParams(); };
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** 生成页的表单参数存一份到浏览器,下次打开还在。 */
|
|
494
|
+
const PARAMS_KEY = 'imggen-try-params';
|
|
495
|
+
function currentParams() {
|
|
496
|
+
return {
|
|
497
|
+
prompt: $('t-prompt').value,
|
|
498
|
+
situation: $('t-situation').value,
|
|
499
|
+
expression: $('t-expression').value,
|
|
500
|
+
pose: $('t-pose').value,
|
|
501
|
+
shot: $('t-shot').value,
|
|
502
|
+
light: $('t-light').value,
|
|
503
|
+
scene: $('t-scene').value,
|
|
504
|
+
size: $('t-size').value,
|
|
505
|
+
count: $('t-count').value,
|
|
506
|
+
characters: checked('t-characters'),
|
|
507
|
+
outfits: checked('t-outfits'),
|
|
508
|
+
props: checked('t-props'),
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function saveParams() {
|
|
512
|
+
try { localStorage.setItem(PARAMS_KEY, JSON.stringify(currentParams())); } catch {}
|
|
513
|
+
}
|
|
514
|
+
function restoreParams() {
|
|
515
|
+
let p = null;
|
|
516
|
+
try { p = JSON.parse(localStorage.getItem(PARAMS_KEY) || 'null'); } catch {}
|
|
517
|
+
if (!p) return;
|
|
518
|
+
if (typeof p.prompt === 'string') $('t-prompt').value = p.prompt;
|
|
519
|
+
for (const k of ['situation', 'expression', 'pose', 'shot', 'light', 'scene']) {
|
|
520
|
+
const el = $('t-' + k);
|
|
521
|
+
if (el && typeof p[k] === 'string' && [...el.options].some((o) => o.value === p[k])) el.value = p[k];
|
|
522
|
+
}
|
|
523
|
+
if (p.size) $('t-size').value = p.size;
|
|
524
|
+
if (p.count) $('t-count').value = p.count;
|
|
525
|
+
for (const [k, id] of [['characters', 't-characters'], ['outfits', 't-outfits'], ['props', 't-props']]) {
|
|
526
|
+
const want = new Set(Array.isArray(p[k]) ? p[k] : []);
|
|
527
|
+
document.querySelectorAll('#' + id + ' input[type=checkbox]').forEach((cb) => { cb.checked = want.has(cb.value); });
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
let generating = null; // { ctrl, t0, timer }
|
|
532
|
+
let lastResult = null; // 上一次成功的结果,供「再画一张 / 存库」用
|
|
533
|
+
|
|
534
|
+
function stopTimer() {
|
|
535
|
+
if (generating) { clearInterval(generating.timer); generating = null; }
|
|
536
|
+
const c = $('btn-cancel');
|
|
537
|
+
if (c) c.hidden = true;
|
|
453
538
|
}
|
|
454
539
|
|
|
455
|
-
|
|
540
|
+
async function doGenerate() {
|
|
541
|
+
if (generating) return; // 防连点
|
|
456
542
|
const prompt = $('t-prompt').value.trim();
|
|
457
543
|
if (!prompt) { alert('先写点什么画面'); return; }
|
|
544
|
+
saveParams();
|
|
545
|
+
|
|
458
546
|
const btn = $('btn-gen');
|
|
547
|
+
const cancel = $('btn-cancel');
|
|
459
548
|
btn.disabled = true;
|
|
549
|
+
if (cancel) cancel.hidden = false;
|
|
460
550
|
$('genmsg').className = 'msg';
|
|
461
|
-
$('genmsg').textContent = '
|
|
551
|
+
$('genmsg').textContent = '生成中… 0 秒';
|
|
462
552
|
$('genout').innerHTML = '';
|
|
463
553
|
$('genprompt').innerHTML = '';
|
|
554
|
+
|
|
555
|
+
const ctrl = new AbortController();
|
|
556
|
+
const t0 = Date.now();
|
|
557
|
+
generating = { ctrl, t0, timer: setInterval(() => {
|
|
558
|
+
const s = Math.round((Date.now() - t0) / 1000);
|
|
559
|
+
$('genmsg').textContent = '生成中… ' + s + ' 秒';
|
|
560
|
+
}, 1000) };
|
|
561
|
+
|
|
464
562
|
try {
|
|
465
563
|
const r = await api('/api/generate', {
|
|
466
564
|
prompt,
|
|
@@ -475,26 +573,121 @@ $('btn-gen').onclick = async () => {
|
|
|
475
573
|
props: checked('t-props'),
|
|
476
574
|
size: $('t-size').value.trim(),
|
|
477
575
|
count: Number($('t-count').value) || 1,
|
|
478
|
-
});
|
|
576
|
+
}, ctrl.signal);
|
|
577
|
+
stopTimer();
|
|
578
|
+
const secs = ((Date.now() - t0) / 1000).toFixed(1);
|
|
479
579
|
if (!r.ok) {
|
|
480
580
|
$('genmsg').className = 'msg err';
|
|
481
581
|
$('genmsg').textContent = r.message || '生成失败';
|
|
482
|
-
|
|
483
|
-
$('genmsg').className = 'msg ok';
|
|
484
|
-
$('genmsg').textContent = r.message;
|
|
485
|
-
$('genout').innerHTML = '<div class="grid" style="margin-top:12px">' +
|
|
486
|
-
(r.images || []).map((i) => '<div class="card" style="cursor:default"><div class="thumb" style="background-image:url(\'' + i.dataUrl + '\')"></div>' +
|
|
487
|
-
'<div class="meta"><div class="sub">' + esc(i.name) + '</div></div></div>').join('') + '</div>';
|
|
488
|
-
if (r.prompt) $('genprompt').innerHTML = '<div class="promptbox">' + esc(r.prompt) + '</div>';
|
|
489
|
-
await load();
|
|
582
|
+
return;
|
|
490
583
|
}
|
|
491
|
-
|
|
492
|
-
$('genmsg').className = 'msg
|
|
493
|
-
$('genmsg').textContent = '
|
|
584
|
+
lastResult = r;
|
|
585
|
+
$('genmsg').className = 'msg ok';
|
|
586
|
+
$('genmsg').textContent = (r.message || '完成') + '(用时 ' + secs + ' 秒)';
|
|
587
|
+
renderResult(r);
|
|
588
|
+
} catch (e) {
|
|
589
|
+
stopTimer();
|
|
590
|
+
const aborted = e && (e.name === 'AbortError' || /abort/i.test(String(e.message || '')));
|
|
591
|
+
$('genmsg').className = aborted ? 'msg' : 'msg err';
|
|
592
|
+
$('genmsg').textContent = aborted ? '已取消(服务端那边可能还在跑,图会存下来)' : ('出错了:' + (e.message || e));
|
|
494
593
|
} finally {
|
|
495
594
|
btn.disabled = false;
|
|
595
|
+
const c = $('btn-cancel');
|
|
596
|
+
if (c) c.hidden = true;
|
|
496
597
|
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function renderResult(r) {
|
|
601
|
+
const imgs = r.images || [];
|
|
602
|
+
const acts = '<div class="bar" style="margin-top:8px;gap:8px">' +
|
|
603
|
+
'<button class="ghost" id="btn-again">再画一张</button>' +
|
|
604
|
+
'<button class="ghost" id="btn-savelib">存进参考库</button>' +
|
|
605
|
+
(imgs[0] ? '<button class="ghost" id="btn-copypath">复制路径</button>' : '') +
|
|
606
|
+
'</div>';
|
|
607
|
+
$('genout').innerHTML = '<div class="grid" style="margin-top:12px">' +
|
|
608
|
+
imgs.map((img, i) =>
|
|
609
|
+
'<div class="card" style="cursor:default"><div class="thumb" style="background-image:url(\'' + img.dataUrl + '\')"></div>' +
|
|
610
|
+
'<div class="meta"><div class="sub">' + esc(img.name) + '</div>' +
|
|
611
|
+
'<a class="sub" style="color:var(--accent);cursor:pointer" data-dl="' + i + '">下载</a></div></div>'
|
|
612
|
+
).join('') + '</div>' + acts +
|
|
613
|
+
(r.prompt ? '<details style="margin-top:12px"><summary style="cursor:pointer;color:var(--dim);font-size:12px">看实际发出去的提示词</summary><pre style="white-space:pre-wrap;font-size:12px;margin-top:8px">' + esc(r.prompt) + '</pre></details>' : '');
|
|
614
|
+
|
|
615
|
+
$('genout').querySelectorAll('[data-dl]').forEach((a) => {
|
|
616
|
+
a.onclick = () => {
|
|
617
|
+
const img = imgs[Number(a.dataset.dl)];
|
|
618
|
+
const link = document.createElement('a');
|
|
619
|
+
link.href = img.dataUrl;
|
|
620
|
+
link.download = img.name || 'imggen.png';
|
|
621
|
+
link.click();
|
|
622
|
+
};
|
|
623
|
+
});
|
|
624
|
+
const again = $('btn-again');
|
|
625
|
+
if (again) again.onclick = () => doGenerate();
|
|
626
|
+
const copypath = $('btn-copypath');
|
|
627
|
+
if (copypath) copypath.onclick = async () => {
|
|
628
|
+
const dir = (state.config.saveDir || '').replace(/[\\/]+$/, '');
|
|
629
|
+
const text = imgs.map((i) => dir + '\\' + i.name).join('\n');
|
|
630
|
+
try { await navigator.clipboard.writeText(text); copypath.textContent = '已复制'; }
|
|
631
|
+
catch { window.prompt('复制这个路径:', text); }
|
|
632
|
+
setTimeout(() => { copypath.textContent = '复制路径'; }, 1500);
|
|
633
|
+
};
|
|
634
|
+
const savelib = $('btn-savelib');
|
|
635
|
+
if (savelib) savelib.onclick = () => openSaveToLibrary(imgs[0]);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** 把刚生成的图直接建成参考库条目。 */
|
|
639
|
+
function openSaveToLibrary(img) {
|
|
640
|
+
if (!img) return;
|
|
641
|
+
const overlay = document.createElement('div');
|
|
642
|
+
overlay.className = 'overlay';
|
|
643
|
+
overlay.innerHTML =
|
|
644
|
+
'<div class="dialog"><h2>存进参考库</h2>' +
|
|
645
|
+
'<div class="row"><label>分类</label><select id="sl-cat">' +
|
|
646
|
+
[['characters', '人物'], ['outfits', '服饰'], ['scenes', '场景'], ['props', '道具']]
|
|
647
|
+
.map(([v, l]) => '<option value="' + v + '">' + l + '</option>').join('') +
|
|
648
|
+
'</select></div>' +
|
|
649
|
+
'<div class="row"><label>名字</label><input type="text" id="sl-name" placeholder="例如 白色围裙装"></div>' +
|
|
650
|
+
'<div class="row"><label>说明</label><textarea id="sl-desc" placeholder="只写长相或设计,不写表情和姿势"></textarea></div>' +
|
|
651
|
+
'<div class="foot"><button class="ghost" id="sl-cancel">取消</button><button class="primary" id="sl-save">保存</button></div></div>';
|
|
652
|
+
document.body.appendChild(overlay);
|
|
653
|
+
const close = () => overlay.remove();
|
|
654
|
+
overlay.addEventListener('click', (ev) => { if (ev.target === overlay) close(); });
|
|
655
|
+
$('sl-cancel').onclick = close;
|
|
656
|
+
$('sl-save').onclick = async () => {
|
|
657
|
+
const name = $('sl-name').value.trim();
|
|
658
|
+
if (!name) { alert('起个名字'); return; }
|
|
659
|
+
$('sl-save').disabled = true;
|
|
660
|
+
try {
|
|
661
|
+
await api('/api/library/add', {
|
|
662
|
+
category: $('sl-cat').value,
|
|
663
|
+
name,
|
|
664
|
+
desc: $('sl-desc').value.trim(),
|
|
665
|
+
files: [{ name: img.name || '生成.png', dataUrl: img.dataUrl }],
|
|
666
|
+
});
|
|
667
|
+
close();
|
|
668
|
+
await load();
|
|
669
|
+
$('genmsg').className = 'msg ok';
|
|
670
|
+
$('genmsg').textContent = '已存进参考库:' + name;
|
|
671
|
+
} catch (e) {
|
|
672
|
+
alert('保存失败:' + e.message);
|
|
673
|
+
$('sl-save').disabled = false;
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
$('btn-gen').onclick = doGenerate;
|
|
679
|
+
$('btn-cancel').onclick = () => {
|
|
680
|
+
if (!generating) return;
|
|
681
|
+
generating.ctrl.abort();
|
|
682
|
+
stopTimer();
|
|
497
683
|
};
|
|
684
|
+
document.addEventListener('keydown', (ev) => {
|
|
685
|
+
if ((ev.ctrlKey || ev.metaKey) && ev.key === 'Enter') {
|
|
686
|
+
if (!$('tab-try') || $('tab-try').hidden) return;
|
|
687
|
+
ev.preventDefault();
|
|
688
|
+
doGenerate();
|
|
689
|
+
}
|
|
690
|
+
});
|
|
498
691
|
|
|
499
692
|
function renderOutputs() {
|
|
500
693
|
const list = state.outputs || [];
|
package/src/tools.ts
CHANGED
|
@@ -25,35 +25,28 @@ export const TOOL_DECLS: ReadonlyArray<ToolSpec> = [
|
|
|
25
25
|
name: 'imggen_draw',
|
|
26
26
|
tags: ['act'],
|
|
27
27
|
description:
|
|
28
|
-
'
|
|
29
|
-
+ '
|
|
30
|
-
+ '
|
|
31
|
-
+ 'keywords:situation(情境)、expression(神态)、pose(动作)、shot(镜头)、light(光线)各填一个词表里的名字。'
|
|
32
|
-
+ 'to 用当前 QQ 消息 meta 里的 conv(group:<群号> 或 private:<QQ号>),原样复制;不填就发到默认目标。'
|
|
33
|
-
+ '回执里有本地路径、尺寸、用了哪些关键词和参考图、发送结果;开头是「生成失败」时不要当作成功。一张图要几十秒,调用后耐心等回执。',
|
|
28
|
+
'画一张图存到本地并直接发到 QQ。prompt 只写画面本身,神态/动作/镜头/光线用下面的关键词,别在 prompt 里重复。'
|
|
29
|
+
+ '人物/服饰/场景/道具都填参考库里的名字;to 抄 QQ 消息 meta 里的 conv。'
|
|
30
|
+
+ '回执有路径、尺寸、关键词、参考图和发送结果,「生成失败」开头不算成功;一张几十秒,等回执。',
|
|
34
31
|
parameters: {
|
|
35
32
|
type: 'object',
|
|
36
33
|
additionalProperties: false,
|
|
37
34
|
properties: {
|
|
38
|
-
prompt: { type: 'string', description: '
|
|
39
|
-
characters: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
count: { type: 'integer', minimum: 1, maximum: 4, description: '要几张,默认 1。多张更贵更慢,除非对方明确要几张。' },
|
|
54
|
-
to: { type: 'string', description: '发送目标:group:<群号> 或 private:<QQ号>。不填用默认目标。' },
|
|
55
|
-
caption: { type: 'string', description: '可选,跟图一起发出的一句话。' },
|
|
56
|
-
send: { type: 'boolean', description: '可选,false 表示只生成不发。' },
|
|
35
|
+
prompt: { type: 'string', description: '画面:谁在做什么、在哪、什么风格。一到三句。' },
|
|
36
|
+
characters: { type: 'array', items: { type: 'string' }, description: '出镜人物(库里的名字,可多个),保证长相一致。' },
|
|
37
|
+
outfits: { type: 'array', items: { type: 'string' }, description: '服饰(库里的名字),不填自动搭配。' },
|
|
38
|
+
scene: { type: 'string', description: '场景(库里的名字)。' },
|
|
39
|
+
props: { type: 'array', items: { type: 'string' }, description: '道具(库里的名字)。' },
|
|
40
|
+
situation: { type: 'string', description: '情境(词表里的名字)。' },
|
|
41
|
+
expression: { type: 'string', description: '神态(词表里的名字)。' },
|
|
42
|
+
pose: { type: 'string', description: '动作(词表里的名字)。' },
|
|
43
|
+
shot: { type: 'string', description: '镜头(词表里的名字)。' },
|
|
44
|
+
light: { type: 'string', description: '光线(词表里的名字),不填用情境默认。' },
|
|
45
|
+
size: { type: 'string', description: '覆盖默认尺寸,如 1024x1024。' },
|
|
46
|
+
count: { type: 'integer', minimum: 1, maximum: 4, description: '张数,默认 1;多张更慢更贵。' },
|
|
47
|
+
to: { type: 'string', description: 'group:<群号> 或 private:<QQ号>;不填用默认目标。' },
|
|
48
|
+
caption: { type: 'string', description: '跟图一起发的一句话。' },
|
|
49
|
+
send: { type: 'boolean', description: 'false = 只生成不发。' },
|
|
57
50
|
},
|
|
58
51
|
required: ['prompt'],
|
|
59
52
|
},
|
|
@@ -92,29 +85,27 @@ export const TOOL_DECLS: ReadonlyArray<ToolSpec> = [
|
|
|
92
85
|
name: 'imggen_library',
|
|
93
86
|
tags: ['read', 'act'],
|
|
94
87
|
description:
|
|
95
|
-
'
|
|
96
|
-
+ '
|
|
97
|
-
+ 'action=remove 把条目挪进回收站(不硬删)。'
|
|
98
|
-
+ '对方发来一张图说「记住这个角色」,先拿到图片路径再 add;只是想出图时用 list 确认名字,别猜。',
|
|
88
|
+
'本地参考库(人物/服饰/场景/道具)。list 看清单,get 看某条设定与参考图,add 存新条目(file 填图片路径或 http 地址),'
|
|
89
|
+
+ 'update 改字段,remove 挪进回收站。出图前不确定名字就 list,别猜;对方说「记住这个角色」先拿图片路径再 add。',
|
|
99
90
|
parameters: {
|
|
100
91
|
type: 'object',
|
|
101
92
|
additionalProperties: false,
|
|
102
93
|
properties: {
|
|
103
94
|
action: { type: 'string', enum: ['list', 'get', 'add', 'update', 'remove'], description: '要做的事。' },
|
|
104
95
|
category: LIBRARY_CATEGORY,
|
|
105
|
-
name: { type: 'string', description: '
|
|
106
|
-
description: { type: 'string', description: 'add/update
|
|
107
|
-
aliases: { type: 'array', items: { type: 'string' }, description: 'add/update
|
|
108
|
-
tags: { type: 'array', items: { type: 'string' }, description: 'add/update
|
|
109
|
-
persona: { type: 'string', description: 'add/update
|
|
110
|
-
expressions: { type: 'string', description: 'add/update
|
|
111
|
-
defaultOutfit: { type: 'string', description: 'add/update
|
|
96
|
+
name: { type: 'string', description: '条目名(get/update/remove 用;add 时是新条目名)。' },
|
|
97
|
+
description: { type: 'string', description: 'add/update:外观描述,只写长相或设计,会进提示词。' },
|
|
98
|
+
aliases: { type: 'array', items: { type: 'string' }, description: 'add/update:别名。' },
|
|
99
|
+
tags: { type: 'array', items: { type: 'string' }, description: 'add/update:标签。' },
|
|
100
|
+
persona: { type: 'string', description: 'add/update:人设,只给自己看,不外发。' },
|
|
101
|
+
expressions: { type: 'string', description: 'add/update:神态特点,会进提示词。' },
|
|
102
|
+
defaultOutfit: { type: 'string', description: 'add/update:默认服饰(服饰条目名)。' },
|
|
112
103
|
outfitByContext: {
|
|
113
104
|
type: 'object',
|
|
114
105
|
additionalProperties: { type: 'string' },
|
|
115
|
-
description: 'add/update
|
|
106
|
+
description: 'add/update:情境→服饰名,如 {"睡前":"睡衣"};也收 "睡前=睡衣, 刚睡醒=睡衣"。只对人物有用。',
|
|
116
107
|
},
|
|
117
|
-
file: { type: 'string', description: 'add
|
|
108
|
+
file: { type: 'string', description: 'add:参考图,本地路径或 http(s) 地址。' },
|
|
118
109
|
},
|
|
119
110
|
required: ['action'],
|
|
120
111
|
},
|
package/src/world.ts
CHANGED
|
@@ -465,7 +465,7 @@ export class ImggenWorld implements World {
|
|
|
465
465
|
'imggen.dir': this.dir(),
|
|
466
466
|
'imggen.target': c.defaultTo || '(没配)',
|
|
467
467
|
'imggen.status': status + ';协议端 ' + (this.ping.ok ? '在线 ' + this.ping.detail : '未连上:' + this.ping.detail),
|
|
468
|
-
'imggen.library': catalogText(lib),
|
|
468
|
+
'imggen.library': catalogText(lib, 30, c.libraryDetail),
|
|
469
469
|
'imggen.keywords': keywordText(presets),
|
|
470
470
|
'imggen.studio': this.studioUrl ?? '(没开)',
|
|
471
471
|
};
|