cortico-world-imggen 0.3.2 → 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 CHANGED
@@ -18,6 +18,8 @@
18
18
  - **参考库**:一个子文件夹 = 一个条目(`entry.json` + 参考图),散放的图片也算条目,名字取文件名。
19
19
  - **关键词**:词表存在 `<数据目录>/imggen-presets.json`,第一次运行写入一套默认值,可在页面里改。
20
20
  - **自动搭配**:没指定服饰时按「人物情境穿搭 > 情境默认 > 场景默认 > 人物默认」挑。
21
+ - **情境穿搭**:人物条目可写 outfitByContext(情境 → 服饰名,如 {睡前:睡衣}),工作室的「情境穿搭」输入框填 睡前=睡衣, 刚睡醒=睡衣 也行;imggen_library 的 dd / update 同样接受。
22
+ - **和「一桌菜」联动**:日程里的 outfit / scene / props / situation 与 imggen_draw 的参数同名,提示词里让她发图前先查 east_life_now,两边不需要互相调工具。
21
23
  - **提示词纪律**:参考图编号并逐张说明「只取长相 / 只取服装设计」,默认要求「构图、姿势、表情按文字重画」,避免每张都照抄同一个姿势。
22
24
  - **本地工作室页面**:`http://127.0.0.1:8788`(World 页有链接),素材库增删改、上传图、编辑词表、试生成、看生成记录。
23
25
  - 图存到 `<数据目录>/imggen/<日期>/img-<时刻>-<哈希>.png`,目录可在设置页改。
@@ -216,3 +218,35 @@ ONEBOT_TOKEN=<协议端 token> IMGGEN_KEY=<key> IMGGEN_REFS="D:\a.png;D:\b.png"
216
218
  - 65535 的任务超时后不会自动取回,需要重新生成(不会重复扣费那条路没做)。
217
219
  - 工作室页面的「生成」只出图、不发 QQ。
218
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": "调生图模型画一张图,存到本地文件夹,并直接把图发到 QQ。prompt 写画面本身:发生了什么、在哪、什么风格;神态、动作、镜头、光线由下面的关键词控制,别在 prompt 里重复写。有人物出镜时用 characters 指定参考库里的人物(保证长相一致),服饰/场景/道具同理。keywords:situation(情境)、expression(神态)、pose(动作)、shot(镜头)、light(光线)各填一个词表里的名字。to 用当前 QQ 消息 meta 里的 conv(group:<群号> 或 private:<QQ号>),原样复制;不填就发到默认目标。回执里有本地路径、尺寸、用了哪些关键词和参考图、发送结果;开头是「生成失败」时不要当作成功。一张图要几十秒,调用后耐心等回执。",
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": "可选,覆盖配置里的尺寸,例如 1024x1024、1280x720。"
61
+ "description": "覆盖默认尺寸,如 1024x1024。"
62
62
  },
63
63
  "count": {
64
64
  "type": "integer",
65
65
  "minimum": 1,
66
66
  "maximum": 4,
67
- "description": "要几张,默认 1。多张更贵更慢,除非对方明确要几张。"
67
+ "description": "张数,默认 1;多张更慢更贵。"
68
68
  },
69
69
  "to": {
70
70
  "type": "string",
71
- "description": "发送目标:group:<群号> 或 private:<QQ号>。不填用默认目标。"
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": "可选,false 表示只生成不发。"
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": "本地参考库:人物、服饰、场景、道具。action=list 看有什么(可按分类过滤);action=get 看某个条目的设定和参考图;action=add 把一张图存成新条目(file 填本地图片路径或 http 地址);action=update 改条目的名字/描述/别名/标签/人设/默认服饰;action=remove 把条目挪进回收站(不硬删)。对方发来一张图说「记住这个角色」,先拿到图片路径再 add;只是想出图时用 list 确认名字,别猜。",
150
+ "description": "本地参考库(人物/服饰/场景/道具)。list 看清单,get 看某条设定与参考图,add 存新条目(file 填图片路径或 http 地址),update 改字段,remove 挪进回收站。出图前不确定名字就 list,别猜;对方说「记住这个角色」先拿图片路径再 add。",
151
151
  "parameters": {
152
152
  "type": "object",
153
153
  "additionalProperties": false,
@@ -175,41 +175,48 @@
175
175
  },
176
176
  "name": {
177
177
  "type": "string",
178
- "description": "条目名字(get/update/remove 用;add 时是新条目的名字)。"
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:标签,例如 蓝发、猫耳、JK。"
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
+ },
210
+ "outfitByContext": {
211
+ "type": "object",
212
+ "additionalProperties": {
213
+ "type": "string"
214
+ },
215
+ "description": "add/update:情境→服饰名,如 {\"睡前\":\"睡衣\"};也收 \"睡前=睡衣, 刚睡醒=睡衣\"。只对人物有用。"
209
216
  },
210
217
  "file": {
211
218
  "type": "string",
212
- "description": "add:参考图,本地绝对路径或 http(s) 图片地址。"
219
+ "description": "add:参考图,本地路径或 http(s) 地址。"
213
220
  }
214
221
  },
215
222
  "required": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-imggen",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "description": "Coopanion World:本地参考库 + 关键词的生图工作室,桌宠自己画图并把图直接发到 QQ。",
6
6
  "license": "MIT",
package/src/ENV_PROMPT.md CHANGED
@@ -14,6 +14,8 @@
14
14
 
15
15
  不要自己主动画图刷屏,也不要为了解释一个概念随手画。一次对话里连着画三张以上基本是错的,先问一句。
16
16
 
17
+ **穿着和地点跟日程对齐**:要画「她自己」在某个场景里时(比如对方问「你现在在干嘛」「给我看看你」),先看一桌菜的日程——用 `feast_life_now` 查此刻的安排,把那里的 `outfit` / `scene` / `props` / `situation` 原样填进 `imggen_draw` 对应的参数。日程里写什么就画什么,别自己编衣服和地方。
18
+
17
19
  ## 参考库里有什么
18
20
 
19
21
  {{imggen.library}}
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
@@ -271,6 +271,8 @@ export interface AddInput {
271
271
  /** 要复制进条目的本地图片路径。 */
272
272
  images?: string[];
273
273
  defaultOutfit?: string;
274
+ /** 情境 → 服饰名,例如 { 睡前: '睡衣' }。 */
275
+ outfitByContext?: Record<string, string>;
274
276
  }
275
277
 
276
278
  /** 新建条目:建目录、复制图片、写 entry.json。返回条目 id。 */
@@ -313,7 +315,7 @@ export function addEntry(root: string, input: AddInput, problems: string[] = [])
313
315
  persona: input.persona ?? '',
314
316
  expressions: input.expressions ?? '',
315
317
  defaultOutfit: input.defaultOutfit ?? '',
316
- outfitByContext: {},
318
+ outfitByContext: input.outfitByContext ?? {},
317
319
  cover: images[0] ?? '',
318
320
  });
319
321
  return id;
@@ -323,6 +325,31 @@ export function writeEntryFile(dir: string, meta: Record<string, unknown>): void
323
325
  writeFileSync(join(dir, 'entry.json'), JSON.stringify(meta, null, 2) + '\n', 'utf8');
324
326
  }
325
327
 
328
+ /** 把 entry.json 里的 outfitByContext 归一成 { 情境: 服饰名 };脏数据丢弃。 */
329
+ export function parseOutfitByContext(raw: unknown): Record<string, string> {
330
+ if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
331
+ return Object.fromEntries(
332
+ Object.entries(raw as Record<string, unknown>)
333
+ .map(([k, v]) => [String(k).trim(), String(v ?? '').trim()] as const)
334
+ .filter(([k, v]) => k && v),
335
+ );
336
+ }
337
+ // 也接受 "睡前=睡衣, 刚睡醒=睡衣" 这种文本写法。
338
+ const text = String(raw ?? '').trim();
339
+ if (!text) return {};
340
+ const out: Record<string, string> = {};
341
+ for (const part of text.split(/[,,;;\n]/)) {
342
+ const m = /^(.+?)\s*(?:=|→|:|:|->)\s*(.+)$/.exec(part.trim());
343
+ if (m) out[m[1]!.trim()] = m[2]!.trim();
344
+ }
345
+ return out;
346
+ }
347
+
348
+ /** outfitByContext → 一行文本,给工具输出和面板回显用。 */
349
+ export function formatOutfitByContext(map: Record<string, string>): string {
350
+ return Object.entries(map ?? {}).map(([k, v]) => k + '→' + v).join(';');
351
+ }
352
+
326
353
  export type EntryPatch = Partial<Omit<AddInput, 'category' | 'images'>> & { cover?: string };
327
354
 
328
355
  /** 改条目:只改给到的字段,其余保持。散图条目会先升级成文件夹。 */
@@ -351,7 +378,9 @@ export function updateEntry(root: string, id: string, category: Category, patch:
351
378
  persona: patch.persona ?? str(meta.persona),
352
379
  expressions: patch.expressions ?? str(meta.expressions),
353
380
  defaultOutfit: patch.defaultOutfit ?? str(meta.defaultOutfit),
354
- outfitByContext: meta.outfitByContext ?? {},
381
+ outfitByContext: patch.outfitByContext !== undefined
382
+ ? parseOutfitByContext(patch.outfitByContext)
383
+ : parseOutfitByContext(meta.outfitByContext),
355
384
  cover: patch.cover ?? str(meta.cover) ?? '',
356
385
  };
357
386
  writeEntryFile(dir, next);
@@ -394,17 +423,27 @@ export function addImageToEntry(root: string, category: Category, id: string, sr
394
423
  }
395
424
 
396
425
  /** 库目录文本,进系统提示:让模型知道库里有什么,别去猜名字。 */
397
- export function catalogText(lib: Library, maxPerCategory = 30): string {
426
+ /** 库清单的详细程度;alias 是默认档,名字 + 别名,够她挑条目又不占上下文。 */
427
+ export type CatalogDetail = 'full' | 'alias' | 'name';
428
+
429
+ export function catalogText(lib: Library, maxPerCategory = 30, detail: CatalogDetail = 'alias'): string {
398
430
  const lines: string[] = [];
399
431
  for (const category of CATEGORIES) {
400
432
  const entries = lib.byCategory[category];
401
433
  if (!entries.length) continue;
402
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 + '(无参考图)';
403
437
  const bits: string[] = [];
404
- if (e.aliases.length) bits.push('别名 ' + e.aliases.join('/'));
405
- if (e.tags.length) bits.push('标签 ' + e.tags.join('、'));
406
- if (e.category === 'characters' && e.expressions) bits.push('神态 ' + e.expressions);
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
+ }
407
443
  if (e.category === 'characters' && e.defaultOutfit) bits.push('默认服饰 ' + e.defaultOutfit);
444
+ if (e.category === 'characters' && Object.keys(e.outfitByContext).length) {
445
+ bits.push('情境穿搭 ' + formatOutfitByContext(e.outfitByContext));
446
+ }
408
447
  if (!e.images.length) bits.push('无参考图');
409
448
  return bits.length ? e.name + '(' + bits.join(';') + ')' : e.name;
410
449
  });
@@ -17,6 +17,7 @@ import {
17
17
  removeEntry,
18
18
  scanLibrary,
19
19
  updateEntry,
20
+ parseOutfitByContext,
20
21
  type Category,
21
22
  } from '../library.ts';
22
23
  import { PRESET_GROUPS, defaultPresets, loadPresets, savePresets, type Presets } from '../presets.ts';
@@ -265,6 +266,7 @@ export class StudioServer {
265
266
  persona?: string;
266
267
  expressions?: string;
267
268
  defaultOutfit?: string;
269
+ outfitByContext?: unknown;
268
270
  aliases?: string;
269
271
  tags?: string;
270
272
  files?: Array<{ name: string; dataUrl: string }>;
@@ -284,6 +286,7 @@ export class StudioServer {
284
286
  persona: body.persona ?? '',
285
287
  expressions: body.expressions ?? '',
286
288
  defaultOutfit: body.defaultOutfit ?? '',
289
+ outfitByContext: parseOutfitByContext(body.outfitByContext),
287
290
  aliases: String(body.aliases ?? '').split(/[,,、]/).map((s) => s.trim()).filter(Boolean),
288
291
  tags: String(body.tags ?? '').split(/[,,、]/).map((s) => s.trim()).filter(Boolean),
289
292
  images: files,
@@ -378,6 +381,7 @@ export class StudioServer {
378
381
  persona: e.persona,
379
382
  expressions: e.expressions,
380
383
  defaultOutfit: e.defaultOutfit,
384
+ outfitByContext: e.outfitByContext,
381
385
  loose: e.loose,
382
386
  images: e.images.map((n) => '/api/image?path=' + encodeURIComponent(join(e.dir, n))),
383
387
  }));