cortico-world-imggen 0.4.2 → 0.5.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 CHANGED
@@ -8,6 +8,13 @@
8
8
  > 思路移植自 [dsh-image-studio](https://github.com/aa1355721445-lgtm/dsh-image-studio)(本地参考库 + 关键词 + 发图策略),
9
9
  > 但按 Cortico 的 World 契约重写:没有 DSH 的宿主 API,所以调度、发图、管理页面都是自己实现的。
10
10
 
11
+ ## 0.5.0 新手上路(下载完怎么用)
12
+
13
+ 1. **打开工作室界面**:启用扩展后,在宿主 **World 面板 / 设置页**点击 **「打开生图工作室」**(或双击数据目录下的 `打开生图工作室.url` 快捷方式)即可进入网页界面:
14
+ - **☁️ 云端模式**:极简 3 页签(API 设置 + 测试连接、人设卡上传、简单试画与画廊)。
15
+ - **🖥️ 本地 ComfyUI 模式**:完整工作台(Anima / Krea2 / MOSS 三架构、多 LoRA 叠加、UI 工作流拖入自动转 API、显存/队列实时监控与重绘)。
16
+ 2. **懒得自己配?直接交给 DSH(桌宠)!**:可以直接把云端接口地址、API Key 或角色人设图发给桌宠,跟她说「帮我配好生图接口 / 把这张图存成人设卡」,她会自动调用工具帮你搞定。
17
+
11
18
  ## 0.4.1 更新
12
19
 
13
20
  - **后端档案(profiles)**:把「后端 + 接口 + 模型 + key」存成一组,切换时整组生效。
package/describe.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "tools": [
3
3
  {
4
4
  "name": "imggen_draw",
5
- "description": "画一张图,存本地并发 QQ。prompt 只写画面;神态/动作/镜头/光线用关键词;人物/服饰/场景/道具填库里的名字。to 抄消息 meta 里的 conv。回执含路径、尺寸和发送结果;「生成失败」不算成功。本地约 30 秒~2 分钟。",
5
+ "description": "画图存本地并发 QQ。prompt 写画面;神态/动作/镜头/光线用关键词;人物/服饰/场景/道具填库名;to 抄 meta 的 conv。",
6
6
  "parameters": {
7
7
  "type": "object",
8
8
  "additionalProperties": false,
@@ -66,6 +66,30 @@
66
66
  "maximum": 4,
67
67
  "description": "张数,默认 1"
68
68
  },
69
+ "lora": {
70
+ "type": "string",
71
+ "description": "单次指定角色 LoRA 文件名(不改默认设置)"
72
+ },
73
+ "loras": {
74
+ "type": "array",
75
+ "items": {
76
+ "type": "string"
77
+ },
78
+ "description": "单次指定多个 LoRA 文件名(多角色同框时按顺序串联)"
79
+ },
80
+ "workflow": {
81
+ "type": "string",
82
+ "description": "单次指定工作流模板文件名或路径"
83
+ },
84
+ "arch": {
85
+ "type": "string",
86
+ "enum": [
87
+ "krea2",
88
+ "anima",
89
+ "moss"
90
+ ],
91
+ "description": "单次或临时指定本地架构"
92
+ },
69
93
  "to": {
70
94
  "type": "string",
71
95
  "description": "group:<群号> / private:<QQ号>"
@@ -93,7 +117,7 @@
93
117
  },
94
118
  {
95
119
  "name": "imggen_redraw",
96
- "description": "以图改图:拿一张已有的图当底图,按 prompt 重绘。file 填 imggen_list 的文件名或绝对路径,不填用最新一张。denoise 越小越贴近原图(0.3 只是微调细节,0.7 改动很大),默认 0.55。底图的构图和人物位置会保留,只有画面内容按 prompt 变。只有本地 ComfyUI 支持,云端会拒绝。",
120
+ "description": "以图改图(仅本地 ComfyUI):用已有图当底图按 prompt 重绘,保留构图位置。file 不填用最新图,denoise 默认 0.55(0.3 微调/0.7 大改)。",
97
121
  "parameters": {
98
122
  "type": "object",
99
123
  "additionalProperties": false,
@@ -112,6 +136,17 @@
112
136
  "maximum": 0.95,
113
137
  "description": "重绘幅度,默认 0.55"
114
138
  },
139
+ "lora": {
140
+ "type": "string",
141
+ "description": "单次指定 LoRA 文件名"
142
+ },
143
+ "loras": {
144
+ "type": "array",
145
+ "items": {
146
+ "type": "string"
147
+ },
148
+ "description": "单次指定多个 LoRA 文件名"
149
+ },
115
150
  "to": {
116
151
  "type": "string",
117
152
  "description": "group:<群号> / private:<QQ号>"
@@ -304,7 +339,7 @@
304
339
  },
305
340
  {
306
341
  "name": "imggen_comfy",
307
- "description": "本地设置:status 看状态,list 列可用 LoRA / 工作流(按架构分组),set 改(backend=local|cloud;model=本地模型架构名;lora=文件名,空串不挂;workflow=路径或文件名,空串用内置)。profiles / useProfile / saveProfile 管后端档案。换画风、换 LoRA、快速试几张用它。",
342
+ "description": "本地 ComfyUI 设置:status 看状态,list 列可用 LoRA/模板,set 改 backend/model/lora/loras/workflow,profiles/useProfile/saveProfile 管档案。",
308
343
  "parameters": {
309
344
  "type": "object",
310
345
  "additionalProperties": false,
@@ -322,9 +357,12 @@
322
357
  "profiles",
323
358
  "useProfile",
324
359
  "saveProfile",
325
- "restart"
360
+ "restart",
361
+ "workflow",
362
+ "freeMemory",
363
+ "interrupt"
326
364
  ],
327
- "description": "status 看状态;list 列 LoRA/工作流;set 改后端/模型/LoRA/工作流;profiles 列档案;useProfile 切档案;saveProfile 存档案"
365
+ "description": "status 看状态;list 列 LoRA/工作流;set 改后端/模型/LoRA/工作流;profiles 列档案;useProfile 切档案;saveProfile 存档案;workflow 看当前模板LoRA与触发词;freeMemory 释放显存;interrupt 中断当前任务"
328
366
  },
329
367
  "backend": {
330
368
  "type": "string",
@@ -338,14 +376,22 @@
338
376
  "type": "string",
339
377
  "enum": [
340
378
  "krea2",
341
- "anima"
379
+ "anima",
380
+ "moss"
342
381
  ],
343
- "description": "set:本地模型架构(本机装的那几个;不确定先 status)"
382
+ "description": "set:本地模型架构(krea2 / anima / moss)"
344
383
  },
345
384
  "lora": {
346
385
  "type": "string",
347
386
  "description": "set:角色 LoRA 文件名,空=不挂"
348
387
  },
388
+ "loras": {
389
+ "type": "array",
390
+ "items": {
391
+ "type": "string"
392
+ },
393
+ "description": "set:多个角色/画风 LoRA 文件名列表"
394
+ },
349
395
  "workflow": {
350
396
  "type": "string",
351
397
  "description": "set:工作流文件名,空=内置"
package/package.json CHANGED
@@ -1,81 +1,85 @@
1
- {
2
- "name": "cortico-world-imggen",
3
- "version": "0.4.2",
4
- "type": "module",
5
- "description": "生图工具包:给桌宠画她现在的样子(做饭、出门买菜、按描述换造型),支持云端口与本机 ComfyUI,可与其他插件联动。",
6
- "license": "MIT",
7
- "main": "./src/definition.ts",
8
- "exports": {
9
- ".": "./src/definition.ts",
10
- "./package.json": "./package.json"
11
- },
12
- "files": [
13
- "src",
14
- "scripts",
15
- "icon.png",
16
- "describe.json",
17
- "README.md",
18
- "发布说明-0.4.0.md",
19
- "发布说明-0.4.1.md",
20
- "发布说明-0.4.2.md",
21
- "更新公告-0.4.2.md"
22
- ],
23
- "engines": {
24
- "node": ">=22"
25
- },
26
- "publishConfig": {
27
- "access": "public"
28
- },
29
- "keywords": [
30
- "cortico-world",
31
- "cortico",
32
- "coopanion",
33
- "image-generation",
34
- "text-to-image",
35
- "reference-library",
36
- "qq"
37
- ],
38
- "cortico": {
39
- "kind": "world",
40
- "api": 6,
41
- "displayName": "鱼的生图包",
42
- "describe": "describe.json",
43
- "tags": [
44
- "im",
45
- "qq",
46
- "internet",
47
- "creative",
48
- "requires-key",
49
- "external-setup",
50
- "experimental",
51
- "unofficial-api"
52
- ],
53
- "locales": {
54
- "zh": {
55
- "displayName": "鱼的生图包",
56
- "description": "给你的大肥鱼加上生图工具包,随时随地展示她现在的样子,例如正在做饭,或者依你描述造型,出门买菜,可与其他插件联动。支持本地参考库(人物/服饰/场景/道具)与关键词词表,云端接口与本机 ComfyUI 双后端,人物 LoRA 与画风/姿势工作流自由搭配,出图直接发到 QQ,后台出图不卡对话。"
57
- },
58
- "en": {
59
- "displayName": "Fish's Image Pack",
60
- "description": "Image generation with a local reference library and keyword presets, sending results straight to QQ. Dual backend (cloud API or local ComfyUI) with backend profiles: backend + endpoint + model + key switch as one group. Character LoRA pairs with any style/pose workflow; background drawing keeps chat responsive."
61
- }
62
- },
63
- "icon": "icon.png"
64
- },
65
- "dependencies": {},
66
- "repository": {
67
- "type": "git",
68
- "url": "https://github.com/cormini/cortico-world-imggen.git"
69
- },
70
- "homepage": "https://github.com/cormini/cortico-world-imggen#readme",
71
- "scripts": {
72
- "describe": "node --experimental-transform-types --no-warnings scripts/gen-describe.mjs",
73
- "test": "node --experimental-transform-types --no-warnings scripts/test-providers.mjs",
74
- "test:library": "node --experimental-transform-types --no-warnings scripts/test-library.mjs",
75
- "test:studio": "node --experimental-transform-types --no-warnings scripts/test-studio.mjs",
76
- "smoke": "node --experimental-transform-types --no-warnings --import ./scripts/smoke-loader.mjs scripts/smoke.mjs",
77
- "verify": "node --experimental-transform-types --no-warnings --import ./scripts/smoke-loader.mjs scripts/verify-framework.mjs",
78
- "selftest": "node --experimental-transform-types --no-warnings scripts/selftest.mjs",
79
- "release:check": "node --experimental-transform-types --no-warnings scripts/test-providers.mjs && node --experimental-transform-types --no-warnings scripts/test-library.mjs && node --experimental-transform-types --no-warnings scripts/test-studio.mjs"
80
- }
81
- }
1
+ {
2
+ "name": "cortico-world-imggen",
3
+ "version": "0.5.0",
4
+ "type": "module",
5
+ "description": "生图工具包:给桌宠画她现在的样子(做饭、出门买菜、按描述换造型),支持云端口与本机 ComfyUI,可与其他插件联动。",
6
+ "license": "MIT",
7
+ "main": "./src/definition.ts",
8
+ "exports": {
9
+ ".": "./src/definition.ts",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "src",
14
+ "scripts",
15
+ "icon.png",
16
+ "describe.json",
17
+ "README.md",
18
+ "发布说明-0.4.0.md",
19
+ "发布说明-0.4.1.md",
20
+ "发布说明-0.4.2.md",
21
+ "更新公告-0.4.2.md",
22
+ "发布说明-0.4.3.md",
23
+ "更新公告-0.4.3.md",
24
+ "发布说明-0.5.0.md"
25
+ ],
26
+ "engines": {
27
+ "node": ">=22"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "describe": "node --no-warnings scripts/gen-describe.mjs",
34
+ "test": "node --no-warnings scripts/test-providers.mjs",
35
+ "test:library": "node --no-warnings scripts/test-library.mjs",
36
+ "test:studio": "node --no-warnings scripts/test-studio.mjs",
37
+ "test:v050": "node --no-warnings scripts/test-v050.mjs",
38
+ "smoke": "node --no-warnings --import ./scripts/smoke-loader.mjs scripts/smoke.mjs",
39
+ "verify": "node --no-warnings --import ./scripts/smoke-loader.mjs scripts/verify-framework.mjs",
40
+ "selftest": "node --no-warnings scripts/selftest.mjs",
41
+ "release:check": "node --no-warnings scripts/test-providers.mjs && node --no-warnings scripts/test-library.mjs && node --no-warnings scripts/test-studio.mjs && node --no-warnings scripts/test-v050.mjs"
42
+ },
43
+ "keywords": [
44
+ "cortico-world",
45
+ "cortico",
46
+ "coopanion",
47
+ "image-generation",
48
+ "text-to-image",
49
+ "reference-library",
50
+ "qq"
51
+ ],
52
+ "cortico": {
53
+ "kind": "world",
54
+ "api": 6,
55
+ "displayName": "鱼的生图包",
56
+ "describe": "describe.json",
57
+ "tags": [
58
+ "im",
59
+ "qq",
60
+ "internet",
61
+ "creative",
62
+ "requires-key",
63
+ "external-setup",
64
+ "experimental",
65
+ "unofficial-api"
66
+ ],
67
+ "locales": {
68
+ "zh": {
69
+ "displayName": "鱼的生图包",
70
+ "description": "给你的大肥鱼加上生图工具包,随时随地展示她现在的样子,例如正在做饭,或者依你描述造型,出门买菜,可与其他插件联动。支持本地参考库(人物/服饰/场景/道具)与关键词词表,云端接口与本机 ComfyUI 双后端,人物 LoRA 与画风/姿势工作流自由搭配,出图直接发到 QQ,后台出图不卡对话。"
71
+ },
72
+ "en": {
73
+ "displayName": "Fish's Image Pack",
74
+ "description": "Image generation with a local reference library and keyword presets, sending results straight to QQ. Dual backend (cloud API or local ComfyUI) with backend profiles: backend + endpoint + model + key switch as one group. Character LoRA pairs with any style/pose workflow; background drawing keeps chat responsive."
75
+ }
76
+ },
77
+ "icon": "icon.png"
78
+ },
79
+ "dependencies": {},
80
+ "repository": {
81
+ "type": "git",
82
+ "url": "https://github.com/cormini/cortico-world-imggen.git"
83
+ },
84
+ "homepage": "https://github.com/cormini/cortico-world-imggen#readme"
85
+ }
package/scripts/smoke.mjs CHANGED
@@ -48,7 +48,7 @@ const tools = world.tools();
48
48
  const names = tools.map((t) => t.name).sort().join(',');
49
49
  const declared = def.describe.tools.map((t) => t.name).sort().join(',');
50
50
  check(names === declared, 'tools() 与 describe.tools 不一致:' + names + ' vs ' + declared);
51
- check(tools.length === 6, '应该有 6 个工具,实际 ' + tools.length);
51
+ check(tools.length === 7, '应该有 7 个工具,实际 ' + tools.length);
52
52
 
53
53
  // ── 提示词变量 ──
54
54
  const vars = world.envPromptVars();
@@ -118,7 +118,7 @@ if (studio) {
118
118
  check(state?.config?.libraryRoot?.includes('imggen-library'), '/api/state 应带库目录');
119
119
  const page = await fetch(studio + '/');
120
120
  const html = await page.text();
121
- check(html.includes('生图工作室') && html.includes('/api/state'), '页面 HTML 不对');
121
+ check((html.includes('画师工作室') || html.includes('生图工作室')) && html.includes('/api/state'), '页面 HTML 不对');
122
122
  const bad = await fetch(studio + '/api/image?path=' + encodeURIComponent('C:\\Windows\\win.ini'));
123
123
  check(bad.status === 403, '页面不该能读库目录以外的文件,实际 ' + bad.status);
124
124
  } catch (e) {
@@ -141,4 +141,4 @@ if (problems.length) {
141
141
  for (const p of problems) console.log(' - ' + p);
142
142
  process.exit(1);
143
143
  }
144
- console.log('\n装配冒烟:全部通过(6 个工具 / 8 个提示词变量 / 库增删改查 / 工作室页面)');
144
+ console.log('\n装配冒烟:全部通过(7 个工具 / 8 个提示词变量 / 库增删改查 / 工作室页面)');
@@ -18,8 +18,11 @@ const base = {
18
18
  comfyCfg: 1,
19
19
  };
20
20
 
21
- const ANIMA_TPL = WF_DIR + '/Anima-快速试构图-API.json';
22
- const KREA_TPL = WF_DIR + '/Krea2-BArtstyle-API.json';
21
+ const detailed = listComfyWorkflowsDetailed(WF_DIR);
22
+ const animaItem = detailed.find((w) => w.arch === 'anima');
23
+ const kreaItem = detailed.find((w) => w.arch === 'krea2');
24
+ const ANIMA_TPL = animaItem ? animaItem.path : WF_DIR + '/Anima-快速试构图-API.json';
25
+ const KREA_TPL = kreaItem ? kreaItem.path : WF_DIR + '/Krea2-BArtstyle-API.json';
23
26
  const PROMPT = 'masterpiece, best quality, 1girl, solo, blue hair, white maid dress, sitting on floor, rainy window at night, warm lamp, anime style';
24
27
 
25
28
  console.log('\n=== A. anima + Anima 模板(应该成功)===');
@@ -0,0 +1,222 @@
1
+ /**
2
+ * v0.5.0 专项回归测试:覆盖 MOSS 架构、UI->API 工作流转换、多 LoRA 串联、
3
+ * secret profiles 保留、换行符转义、LoRA 递归扫描与 Studio 新接口。
4
+ */
5
+ import assert from 'node:assert/strict';
6
+ import { mkdtempSync, mkdirSync, writeFileSync, existsSync } from 'node:fs';
7
+ import { tmpdir } from 'node:os';
8
+ import { join } from 'node:path';
9
+ import { templateArchFromGraph, archLabel } from '../src/workflow-arch.ts';
10
+ import { isUiWorkflow, convertUiWorkflowToApi } from '../src/workflow-convert.ts';
11
+ import { saveSecretKey, loadSecretKey, saveProfileKey, listProfileKeyMasks } from '../src/secret.ts';
12
+ import { enhancePrompt } from '../src/prompt-director.ts';
13
+ import { addEntry, updateEntry, scanLibrary, removeImageFromEntry } from '../src/library.ts';
14
+ import { scanLoraCatalog } from '../src/lora-catalog.ts';
15
+ import { comfyGraph, applyCharacterLoras, renderWorkflowTemplate, pruneEmptyLoraNodes } from '../src/providers.ts';
16
+ import { DEFAULTS, normalizeConfig } from '../src/config.ts';
17
+ import { StudioServer } from '../src/studio/server.ts';
18
+
19
+ const PNG_B64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8AAAwAB/AF+p0n4AAAAAElFTkSuQmCC';
20
+
21
+ // 1. workflow-arch: MOSS detection
22
+ {
23
+ const mossGraph = {
24
+ '1': { class_type: 'EmptyFlux2LatentImage', inputs: { width: 1024, height: 1024, batch_size: 1 } },
25
+ '2': { class_type: 'Flux2Scheduler', inputs: { steps: 20, width: 1024, height: 1024 } },
26
+ '3': { class_type: 'CFGGuider', inputs: { cfg: 4 } },
27
+ };
28
+ assert.equal(templateArchFromGraph(mossGraph), 'moss');
29
+ assert.ok(archLabel('moss').includes('MOSS'));
30
+ console.log('PASS workflow-arch MOSS 识别');
31
+ }
32
+
33
+ // 2. workflow-convert: UI JSON -> API JSON (including bypassed node passthrough)
34
+ {
35
+ const ui = {
36
+ nodes: [
37
+ { id: 1, type: 'UNETLoader', mode: 0, widgets_values: ['moss_model.safetensors', 'default'], outputs: [{ name: 'MODEL', links: [10] }] },
38
+ { id: 2, type: 'LoraLoaderModelOnly', mode: 4, widgets_values: ['bypassed.safetensors', 1], inputs: [{ name: 'model', link: 10 }], outputs: [{ name: 'MODEL', links: [11] }] },
39
+ { id: 3, type: 'EmptyFlux2LatentImage', mode: 0, widgets_values: [1024, 1024, 1], outputs: [{ name: 'LATENT', links: [12] }] },
40
+ { id: 4, type: 'CLIPTextEncode', mode: 0, widgets_values: ['test positive'], outputs: [{ name: 'CONDITIONING', links: [13] }] },
41
+ { id: 5, type: 'CFGGuider', mode: 0, widgets_values: [3], inputs: [{ name: 'model', link: 11 }, { name: 'positive', link: 13 }], outputs: [{ name: 'GUIDER', links: [] }] },
42
+ ],
43
+ links: [
44
+ [10, 1, 0, 2, 0, 'MODEL'],
45
+ [11, 2, 0, 5, 0, 'MODEL'],
46
+ [12, 3, 0, 5, 1, 'LATENT'],
47
+ [13, 4, 0, 5, 1, 'CONDITIONING'],
48
+ ],
49
+ };
50
+ assert.equal(isUiWorkflow(ui), true);
51
+ const conv = convertUiWorkflowToApi(ui);
52
+ assert.equal(conv.arch, 'moss');
53
+ assert.ok(!conv.apiGraph['2'], '被 Bypass 的节点应被剥离');
54
+ assert.deepEqual(conv.apiGraph['5'].inputs.model, ['1', 0], 'Bypass 节点应直通上游连接');
55
+ console.log('PASS workflow-convert UI->API 与 Bypass 剥离');
56
+ }
57
+
58
+ // 3. secret.ts: saveSecretKey preserves profiles
59
+ {
60
+ const dir = mkdtempSync(join(tmpdir(), 'imggen-sec-'));
61
+ saveProfileKey(dir, 'work', 'sk-work-9999');
62
+ saveProfileKey(dir, 'personal', 'sk-pers-8888');
63
+ saveSecretKey(dir, 'sk-new-2222');
64
+ assert.equal(loadSecretKey(dir), 'sk-new-2222');
65
+ const masks = listProfileKeyMasks(dir);
66
+ assert.ok(masks.work && masks.personal, '保存主 Key 时必须保留 profiles');
67
+ console.log('PASS secret.ts profiles 保留与脱敏');
68
+ }
69
+
70
+ // 4. providers.ts: MOSS comfyGraph, multi-LoRA, template newline escaping, CLIPLoader guard
71
+ {
72
+ const cfg = normalizeConfig({ ...DEFAULTS, comfyArch: 'moss' });
73
+ const g = comfyGraph(cfg, 'hello', '1024x1024', 1, 123, [
74
+ { file: 'a.safetensors', strength: 0.8 },
75
+ { file: 'b.safetensors', strength: 0.6 },
76
+ ]);
77
+ const types = Object.values(g).map((n) => n.class_type);
78
+ assert.ok(types.includes('EmptyFlux2LatentImage'), 'MOSS 图应包含 EmptyFlux2LatentImage');
79
+ assert.ok(types.includes('SamplerCustomAdvanced'), 'MOSS 图应包含 SamplerCustomAdvanced');
80
+ assert.equal(types.filter((t) => t === 'LoraLoaderModelOnly').length, 2, '应串联 2 个 LoRA 节点');
81
+
82
+ // template newline escaping & empty lora cleanup + applyCharacterLoras
83
+ const tpl = {
84
+ '1': { class_type: 'CLIPTextEncode', inputs: { text: '{{prompt}}' } },
85
+ '2': { class_type: 'LoraLoaderModelOnly', inputs: { model: ['10', 0], lora_name: '{{lora}}', strength_model: 1 } },
86
+ '3': { class_type: 'CFGGuider', inputs: { model: ['2', 0], cfg: 3 } },
87
+ '10': { class_type: 'UNETLoader', inputs: { unet_name: 'x.safetensors' } },
88
+ };
89
+ const rendered = renderWorkflowTemplate(tpl, { prompt: 'line1\nline2', negative: '', width: 1024, height: 1024, seed: 42, lora: '' });
90
+ assert.equal(rendered['1'].inputs.text, 'line1\nline2');
91
+ pruneEmptyLoraNodes(rendered);
92
+ assert.ok(!rendered['2'], '空 {{lora}} 节点应被裁剪');
93
+ assert.deepEqual(rendered['3'].inputs.model, ['10', 0], '下游应直连回上游');
94
+
95
+ applyCharacterLoras(rendered, [{ file: 'c1.safetensors', strength: 0.9 }, { file: 'c2.safetensors', strength: 0.7 }], 'moss', '');
96
+ const addedLoras = Object.values(rendered).filter((n) => n.class_type === 'LoraLoaderModelOnly');
97
+ assert.equal(addedLoras.length, 2, 'applyCharacterLoras 应挂载 2 个角色 LoRA');
98
+
99
+ // MOSS graph uses CLIPLoader (type: flux2), not CLIPLoaderGGUF even if comfyUnet ends with .gguf
100
+ const ggufCfg = normalizeConfig({ ...DEFAULTS, comfyArch: 'moss', comfyUnet: 'foo.gguf' });
101
+ const mossG = comfyGraph(ggufCfg, 'hello', '1024x1024', 1, 123);
102
+ const clipNodes = Object.values(mossG).filter((n) => n.class_type === 'CLIPLoader');
103
+ assert.equal(clipNodes.length, 1, 'MOSS 图应使用原生 CLIPLoader');
104
+ console.log('PASS providers MOSS 图构建、多 LoRA 串联、换行转义与 CLIPLoader 守卫');
105
+ }
106
+
107
+ // 5. prompt-director: MOSS trait firewall
108
+ {
109
+ const res = await enhancePrompt({
110
+ arch: 'moss',
111
+ mode: 'local',
112
+ prompt: '两人在玄关贴春联',
113
+ characters: ['八云汐', '八云沫'],
114
+ characterDetails: [
115
+ { name: '八云汐', desc: '白发蓝瞳' },
116
+ { name: '八云沫', desc: '蓝发黄瞳' },
117
+ ],
118
+ });
119
+ assert.equal(res.modeUsed, 'local');
120
+ assert.ok(res.prompt.includes('On camera left') || res.prompt.includes('without') || res.prompt.includes('画面左侧'), 'MOSS 本地增强应包含空间分栏或特征隔离');
121
+ console.log('PASS prompt-director MOSS 本地增强');
122
+ }
123
+
124
+ // 6. library.ts + lora-catalog.ts
125
+ {
126
+ const root = mkdtempSync(join(tmpdir(), 'imggen-lib-'));
127
+ const tmpA = join(root, 'a.png');
128
+ const tmpB = join(root, 'b.png');
129
+ writeFileSync(tmpA, Buffer.from(PNG_B64, 'base64'));
130
+ writeFileSync(tmpB, Buffer.from(PNG_B64, 'base64'));
131
+ const id = addEntry(root, {
132
+ category: 'characters',
133
+ name: '小汐',
134
+ desc: '白发蓝瞳猫娘',
135
+ loras: { moss: { file: 'MOSS/shio.safetensors', strength: 0.85 } },
136
+ images: [tmpA, tmpB],
137
+ }, []);
138
+ assert.equal(id, '小汐');
139
+ updateEntry(root, '小汐', 'characters', {
140
+ loras: {
141
+ moss: { file: 'MOSS/shio_v2.safetensors', strength: 0.9 },
142
+ anima: { file: 'anima/shio.safetensors', strength: 0.8 },
143
+ },
144
+ });
145
+ const lib = scanLibrary(root);
146
+ assert.equal(lib.byCategory.characters[0].loras?.anima?.file, 'anima/shio.safetensors');
147
+ const rm = removeImageFromEntry(root, 'characters', '小汐', 'b.png');
148
+ assert.equal(rm, true);
149
+ assert.equal(scanLibrary(root).byCategory.characters[0].images.length, 1);
150
+
151
+ const loraDir = join(root, 'loras');
152
+ mkdirSync(join(loraDir, 'MOSS'), { recursive: true });
153
+ writeFileSync(join(loraDir, 'MOSS', 'demo_moss.safetensors'), Buffer.from([8, 0, 0, 0, 0, 0, 0, 0, 0x7b, 0x7d]));
154
+ writeFileSync(join(loraDir, 'MOSS', 'demo_moss.preview.png'), Buffer.from(PNG_B64, 'base64'));
155
+ const cat = scanLoraCatalog(loraDir);
156
+ assert.equal(cat.length, 1);
157
+ assert.equal(cat[0].arch, 'moss');
158
+ assert.ok(!!cat[0].preview);
159
+ console.log('PASS library entry.loras / removeImageFromEntry 与 lora-catalog 递归扫描');
160
+ }
161
+
162
+ // 7. studio/server.ts new endpoints
163
+ {
164
+ const root = mkdtempSync(join(tmpdir(), 'imggen-st2-'));
165
+ const wfDir = join(root, 'workflows');
166
+ const outDir = join(root, 'out');
167
+ mkdirSync(wfDir, { recursive: true });
168
+ mkdirSync(outDir, { recursive: true });
169
+ writeFileSync(join(outDir, 'delme.png'), Buffer.from(PNG_B64, 'base64'));
170
+ const server = new StudioServer({
171
+ getConfig: () => normalizeConfig({ ...DEFAULTS, comfyWorkflowDir: wfDir, saveDir: outDir }),
172
+ libraryRoot: () => join(root, 'lib'),
173
+ saveDir: () => outDir,
174
+ presetsFile: () => join(root, 'presets.json'),
175
+ generate: async () => ({ ok: true, message: 'ok', prompt: 'ok', images: [] }),
176
+ testCloud: async () => ({ ok: true, detail: 'mock ok' }),
177
+ comfyLive: async () => ({ online: true, gpuName: 'RTX 4090', vramTotal: 24e9, vramFree: 16e9, running: 0, pending: 0, residentArch: 'moss' }),
178
+ importWorkflow: (filename, jsonText) => {
179
+ const parsed = JSON.parse(jsonText);
180
+ const conv = convertUiWorkflowToApi(parsed);
181
+ const savedName = filename.replace(/\.json$/i, '') + '-API.json';
182
+ writeFileSync(join(wfDir, savedName), JSON.stringify(conv.apiGraph, null, 2));
183
+ return { savedName, arch: conv.arch, convertedFromUi: true, summary: conv.summary };
184
+ },
185
+ workflowDetail: (name) => '模板:' + name,
186
+ log: () => {},
187
+ });
188
+ const url = await server.start(18990 + Math.floor(Math.random() * 50));
189
+ const cloud = await (await fetch(url + '/api/cloud/test', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' })).json();
190
+ assert.equal(cloud.ok, true);
191
+ const live = await (await fetch(url + '/api/comfy/live')).json();
192
+ assert.equal(live.online, true);
193
+ const imp = await (await fetch(url + '/api/workflows/import', {
194
+ method: 'POST',
195
+ headers: { 'content-type': 'application/json' },
196
+ body: JSON.stringify({
197
+ filename: 'test-moss.json',
198
+ content: JSON.stringify({
199
+ nodes: [{ id: 1, type: 'EmptyFlux2LatentImage', mode: 0, widgets_values: [1024, 1024, 1] }],
200
+ links: [],
201
+ }),
202
+ }),
203
+ })).json();
204
+ assert.equal(imp.ok, true);
205
+ assert.equal(imp.savedName, 'test-moss-API.json');
206
+ assert.equal(imp.arch, 'moss');
207
+ assert.equal(imp.convertedFromUi, true);
208
+ const det = await (await fetch(url + '/api/workflows/detail?name=test-moss-API.json')).json();
209
+ assert.equal(det.ok, true);
210
+ assert.ok(det.detail.includes('test-moss-API.json'));
211
+ const delOut = await (await fetch(url + '/api/outputs/delete', {
212
+ method: 'POST',
213
+ headers: { 'content-type': 'application/json' },
214
+ body: JSON.stringify({ path: join(outDir, 'delme.png') }),
215
+ })).json();
216
+ assert.equal(delOut.ok, true);
217
+ assert.equal(existsSync(join(outDir, 'delme.png')), false);
218
+ await server.stop();
219
+ console.log('PASS studio/server v0.5.0 新接口 (/api/cloud/test, /api/comfy/live, /api/workflows/import, /api/outputs/delete)');
220
+ }
221
+
222
+ console.log('\n🎉 v0.5.0 专项测试全部通过!');