cortico-world-imggen 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/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`,目录可在设置页改。
@@ -210,6 +212,7 @@ ONEBOT_TOKEN=<协议端 token> IMGGEN_KEY=<key> IMGGEN_REFS="D:\a.png;D:\b.png"
210
212
 
211
213
  ## 已知边界
212
214
 
215
+ - **默认不带服务商水印**:请求里固定发 `watermark: false`。火山的 Seedream 默认会盖「AI生成」,实测 1920×1080 一定出现、1024×1024 不一定;想要水印就在「额外请求参数」里写 `{"watermark": true}` 覆盖。
213
216
  - 参考图只取每个条目的封面一张,`maxRefs` 控制总数;条目里多放的图暂不参与组合。
214
217
  - 生成的图不进 Coo 的上下文(省 token),所以她看不见自己画成什么样。
215
218
  - 65535 的任务超时后不会自动取回,需要重新生成(不会重复扣费那条路没做)。
package/describe.json CHANGED
@@ -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": "本地参考库:人物、服饰、场景、道具。action=list 看有什么(可按分类过滤);action=get 看某个条目的设定和参考图;action=add 把一张图存成新条目(file 填本地图片路径或 http 地址);action=update 改条目的名字/描述/别名/标签/人设/默认服饰/情境穿搭;action=remove 把条目挪进回收站(不硬删)。对方发来一张图说「记住这个角色」,先拿到图片路径再 add;只是想出图时用 list 确认名字,别猜。",
151
151
  "parameters": {
152
152
  "type": "object",
153
153
  "additionalProperties": false,
@@ -207,6 +207,13 @@
207
207
  "type": "string",
208
208
  "description": "add/update:默认服饰(服饰条目的名字)。"
209
209
  },
210
+ "outfitByContext": {
211
+ "type": "object",
212
+ "additionalProperties": {
213
+ "type": "string"
214
+ },
215
+ "description": "add/update:情境 → 服饰名,例如 {\"睡前\":\"睡衣\",\"刚睡醒\":\"睡衣\"};也接受 \"睡前=睡衣, 刚睡醒=睡衣\" 这种写法。只对人物有意义。"
216
+ },
210
217
  "file": {
211
218
  "type": "string",
212
219
  "description": "add:参考图,本地绝对路径或 http(s) 图片地址。"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-imggen",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
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/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);
@@ -405,6 +434,9 @@ export function catalogText(lib: Library, maxPerCategory = 30): string {
405
434
  if (e.tags.length) bits.push('标签 ' + e.tags.join('、'));
406
435
  if (e.category === 'characters' && e.expressions) bits.push('神态 ' + e.expressions);
407
436
  if (e.category === 'characters' && e.defaultOutfit) bits.push('默认服饰 ' + e.defaultOutfit);
437
+ if (e.category === 'characters' && Object.keys(e.outfitByContext).length) {
438
+ bits.push('情境穿搭 ' + formatOutfitByContext(e.outfitByContext));
439
+ }
408
440
  if (!e.images.length) bits.push('无参考图');
409
441
  return bits.length ? e.name + '(' + bits.join(';') + ')' : e.name;
410
442
  });
package/src/providers.ts CHANGED
@@ -337,6 +337,8 @@ function buildBody(cfg: ImggenConfig, style: Exclude<RequestStyle, 'auto'>, prom
337
337
  n: count,
338
338
  size: normalizeSize(size, caps),
339
339
  response_format: 'b64_json',
340
+ // 火山 Seedream 默认会在右下角盖「AI生成」水印;显式关掉,用户仍可用 extraBody 覆盖。
341
+ watermark: false,
340
342
  };
341
343
  }
342
344
  if (extra) {
@@ -382,6 +384,7 @@ async function generateByTask(input: GenInput, base: string, refs: RefFile[]): P
382
384
  n: count,
383
385
  // 让图片数据随查询结果一起回来;默认的 result_urls 在海外节点,国内常连不上。
384
386
  response_format: 'b64_json',
387
+ watermark: false,
385
388
  };
386
389
  if (size) job.size = size;
387
390
  if (refs.length) job.image_urls = refs.map((r) => r.uri);
@@ -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
  }));
@@ -184,7 +184,7 @@
184
184
  const CATS = [['characters','人物'],['outfits','服饰'],['scenes','场景'],['props','道具']];
185
185
  const GROUPS = [['situations','情境'],['expressions','神态'],['poses','动作'],['shots','镜头'],['lights','光线']];
186
186
  const FIELDS = {
187
- characters: [['desc','外观描述'],['persona','人设(不外发)'],['expressions','神态特点'],['defaultOutfit','默认服饰']],
187
+ characters: [['desc','外观描述'],['persona','人设(不外发)'],['expressions','神态特点'],['defaultOutfit','默认服饰'],['outfitByContext','情境穿搭(睡前=睡衣, 刚睡醒=睡衣)']],
188
188
  outfits: [['desc','设计描述']],
189
189
  scenes: [['desc','空间描述'],['defaultOutfit','默认服饰']],
190
190
  props: [['desc','造型描述']],
@@ -268,13 +268,21 @@ function renderLibrary() {
268
268
  });
269
269
  }
270
270
 
271
+ function fieldValue(key, raw) {
272
+ // outfitByContext 存的是对象,表单里显示成「睡前=睡衣, 刚睡醒=睡衣」
273
+ if (key === 'outfitByContext' && raw && typeof raw === 'object') {
274
+ return Object.entries(raw).map(([k, v]) => k + '=' + v).join(', ');
275
+ }
276
+ return raw || '';
277
+ }
278
+
271
279
  function fieldRows(category, entry) {
272
280
  const fields = FIELDS[category] || [['desc', '描述']];
273
281
  return fields.map(([key, label]) =>
274
282
  '<div class="row"><label>' + label + '</label>' +
275
283
  (key === 'desc' || key === 'persona' || key === 'expressions'
276
- ? '<textarea data-f="' + key + '">' + esc(entry[key] || '') + '</textarea>'
277
- : '<input type="text" data-f="' + key + '" value="' + esc(entry[key] || '') + '">') +
284
+ ? '<textarea data-f="' + key + '">' + esc(fieldValue(key, entry[key])) + '</textarea>'
285
+ : '<input type="text" data-f="' + key + '" placeholder="' + (key === 'outfitByContext' ? '睡前=睡衣, 刚睡醒=睡衣' : '') + '" value="' + esc(fieldValue(key, entry[key])) + '">') +
278
286
  '</div>').join('');
279
287
  }
280
288
 
@@ -341,7 +349,8 @@ function openEditor() {
341
349
  try {
342
350
  if (isNew) {
343
351
  await api('/api/library/add', { category: cat, name: patch.name, desc: patch.desc, persona: patch.persona,
344
- expressions: patch.expressions, defaultOutfit: patch.defaultOutfit, aliases: patch.aliases, tags: patch.tags,
352
+ expressions: patch.expressions, defaultOutfit: patch.defaultOutfit, outfitByContext: patch.outfitByContext,
353
+ aliases: patch.aliases, tags: patch.tags,
345
354
  files: picked });
346
355
  } else {
347
356
  await api('/api/library/update', { category: cat, id: e.id, patch });
package/src/tools.ts CHANGED
@@ -93,7 +93,7 @@ export const TOOL_DECLS: ReadonlyArray<ToolSpec> = [
93
93
  tags: ['read', 'act'],
94
94
  description:
95
95
  '本地参考库:人物、服饰、场景、道具。action=list 看有什么(可按分类过滤);action=get 看某个条目的设定和参考图;'
96
- + 'action=add 把一张图存成新条目(file 填本地图片路径或 http 地址);action=update 改条目的名字/描述/别名/标签/人设/默认服饰;'
96
+ + 'action=add 把一张图存成新条目(file 填本地图片路径或 http 地址);action=update 改条目的名字/描述/别名/标签/人设/默认服饰/情境穿搭;'
97
97
  + 'action=remove 把条目挪进回收站(不硬删)。'
98
98
  + '对方发来一张图说「记住这个角色」,先拿到图片路径再 add;只是想出图时用 list 确认名字,别猜。',
99
99
  parameters: {
@@ -109,6 +109,11 @@ export const TOOL_DECLS: ReadonlyArray<ToolSpec> = [
109
109
  persona: { type: 'string', description: 'add/update:人设,只给你自己看,不会发给生图接口。' },
110
110
  expressions: { type: 'string', description: 'add/update:神态特点,例如「开心时尾巴会摇」,会写进提示词。' },
111
111
  defaultOutfit: { type: 'string', description: 'add/update:默认服饰(服饰条目的名字)。' },
112
+ outfitByContext: {
113
+ type: 'object',
114
+ additionalProperties: { type: 'string' },
115
+ description: 'add/update:情境 → 服饰名,例如 {"睡前":"睡衣","刚睡醒":"睡衣"};也接受 "睡前=睡衣, 刚睡醒=睡衣" 这种写法。只对人物有意义。',
116
+ },
112
117
  file: { type: 'string', description: 'add:参考图,本地绝对路径或 http(s) 图片地址。' },
113
118
  },
114
119
  required: ['action'],
package/src/world.ts CHANGED
@@ -25,6 +25,8 @@ import {
25
25
  scanLibrary,
26
26
  updateEntry,
27
27
  type Category,
28
+ formatOutfitByContext,
29
+ parseOutfitByContext,
28
30
  } from './library.ts';
29
31
  import { describeTarget, loginInfo, parseTarget, sendImages } from './onebot.ts';
30
32
  import { configGroupFor } from './panel.ts';
@@ -357,7 +359,13 @@ export class ImggenWorld implements World {
357
359
  e.tags.length ? '标签 ' + e.tags.join('、') : '',
358
360
  e.images.length ? e.images.length + ' 张图' : '无图',
359
361
  ].filter(Boolean);
360
- return ' ' + e.name + '(' + bits.join(';') + ')' + (e.desc ? ':' + e.desc.slice(0, 40) : '');
362
+ const ctx = formatOutfitByContext(e.outfitByContext);
363
+ const extra = [
364
+ e.defaultOutfit ? '默认服饰:' + e.defaultOutfit : '',
365
+ ctx ? '情境穿搭:' + ctx : '',
366
+ ].filter(Boolean);
367
+ return ' ' + e.name + '(' + bits.join(';') + ')' + (e.desc ? ':' + e.desc.slice(0, 40) : '')
368
+ + (extra.length ? '\n ' + extra.join('\n ') : '');
361
369
  }).join('\n');
362
370
  });
363
371
  return '参考库 ' + root + '\n' + blocks.join('\n');
@@ -375,6 +383,7 @@ export class ImggenWorld implements World {
375
383
  e.persona ? '人设:' + e.persona : '',
376
384
  e.expressions ? '神态特点:' + e.expressions : '',
377
385
  e.defaultOutfit ? '默认服饰:' + e.defaultOutfit : '',
386
+ formatOutfitByContext(e.outfitByContext) ? '情境穿搭:' + formatOutfitByContext(e.outfitByContext) : '',
378
387
  '参考图:' + (e.images.length ? e.images.join('、') : '(没有)'),
379
388
  '路径:' + e.dir,
380
389
  ].filter(Boolean).join('\n');
@@ -403,6 +412,7 @@ export class ImggenWorld implements World {
403
412
  persona: String(args.persona ?? ''),
404
413
  expressions: String(args.expressions ?? ''),
405
414
  defaultOutfit: String(args.defaultOutfit ?? ''),
415
+ outfitByContext: parseOutfitByContext(args.outfitByContext),
406
416
  aliases: Array.isArray(args.aliases) ? args.aliases.map(String) : [],
407
417
  tags: Array.isArray(args.tags) ? args.tags.map(String) : [],
408
418
  images,
@@ -421,6 +431,7 @@ export class ImggenWorld implements World {
421
431
  if (args.persona !== undefined) patch.persona = String(args.persona);
422
432
  if (args.expressions !== undefined) patch.expressions = String(args.expressions);
423
433
  if (args.defaultOutfit !== undefined) patch.defaultOutfit = String(args.defaultOutfit);
434
+ if (args.outfitByContext !== undefined) patch.outfitByContext = parseOutfitByContext(args.outfitByContext);
424
435
  if (Array.isArray(args.aliases)) patch.aliases = args.aliases.map(String);
425
436
  if (Array.isArray(args.tags)) patch.tags = args.tags.map(String);
426
437
  if (!Object.keys(patch).length) return { text: '没给要改的字段。', failed: true };