koishi-plugin-p-draw 1.6.4 → 1.6.6
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/index.js +64 -21
- package/lib/comfy.js +6 -1
- package/lib/i18n.js +2 -0
- package/lib/workflows.js +75 -7
- package/package.json +1 -1
- package/readme.md +20 -3
package/index.js
CHANGED
|
@@ -55,6 +55,7 @@ const CONFIG_GROUPS = {
|
|
|
55
55
|
workflow: [
|
|
56
56
|
'customWorkflowEnabled', 'customWorkflowPath', 'skipQualityPrefixForCustomWorkflow',
|
|
57
57
|
'customWorkflowOverrideParameters', 'customWorkflowReloadOnChange',
|
|
58
|
+
'workflowOverrideModel', 'modelLoaderNodeId',
|
|
58
59
|
'positivePromptNodeId', 'negativePromptNodeId', 'resolutionNodeId', 'seedNodeId', 'stepsNodeId',
|
|
59
60
|
'workflowPresets', 'defaultWorkflowPreset',
|
|
60
61
|
],
|
|
@@ -127,7 +128,7 @@ exports.Config = Schema.object({
|
|
|
127
128
|
width: Schema.number().description('默认宽度'),
|
|
128
129
|
height: Schema.number().description('默认高度'),
|
|
129
130
|
}).description('该模型的参数覆盖')).default({}).description('按模型覆盖参数:key=模型文件名,value 只填要覆盖的字段。显式写了的字段会覆盖工作流内取值'),
|
|
130
|
-
}).description('② 模型与采样参数'),
|
|
131
|
+
}).description('② 模型与采样参数').collapse(),
|
|
131
132
|
|
|
132
133
|
prompt: Schema.object({
|
|
133
134
|
qualityPrefix: Schema.string().default('').description('质量词前缀(Aesthetic 1.1 建议留空;Base 模型可填 masterpiece, best quality, score_7)'),
|
|
@@ -137,13 +138,13 @@ exports.Config = Schema.object({
|
|
|
137
138
|
activeArtistPreset: Schema.string().default('').description('启用的画师组名称'),
|
|
138
139
|
artistPresets: Schema.array(Schema.string()).default([]).description('画师组(格式:名称=tags)'),
|
|
139
140
|
fixedCharacters: Schema.array(Schema.string()).default([]).description('固定角色(格式:角色名=tags;仅兼容旧配置,运行时以数据库为准)'),
|
|
140
|
-
}).description('③ 提示词与画师'),
|
|
141
|
+
}).description('③ 提示词与画师').collapse(),
|
|
141
142
|
|
|
142
143
|
queue: Schema.object({
|
|
143
144
|
queueEnabled: Schema.boolean().default(true).description('启用生成队列(逐张顺序执行)'),
|
|
144
145
|
queueMaxRequests: Schema.number().default(5).description('队列最大任务数(0 表示不限制)'),
|
|
145
146
|
batchMax: Schema.number().default(4).description('单次指令最多生成的张数'),
|
|
146
|
-
}).description('④ 队列与批量'),
|
|
147
|
+
}).description('④ 队列与批量').collapse(),
|
|
147
148
|
|
|
148
149
|
pricing: Schema.object({
|
|
149
150
|
price: Schema.number().default(500).description('一张图消耗的 P 点'),
|
|
@@ -151,7 +152,7 @@ exports.Config = Schema.object({
|
|
|
151
152
|
couponPrice: Schema.number().default(3000).description('提示词优化券单价(可被 data/p-shop.json 覆盖)'),
|
|
152
153
|
couponAskTimeout: Schema.number().default(60).description('优化券确认等待时间(秒)'),
|
|
153
154
|
adminUsers: Schema.array(Schema.string()).default([]).description('免 P 点管理员用户 ID'),
|
|
154
|
-
}).description('⑤ P 点与优化券'),
|
|
155
|
+
}).description('⑤ P 点与优化券').collapse(),
|
|
155
156
|
|
|
156
157
|
access: Schema.object({
|
|
157
158
|
adminOnly: Schema.boolean().default(false).description('仅管理员可用'),
|
|
@@ -160,7 +161,7 @@ exports.Config = Schema.object({
|
|
|
160
161
|
allowedGroupIds: Schema.array(Schema.string()).default([]).description('群白名单(留空不限制)'),
|
|
161
162
|
blockedGroupIds: Schema.array(Schema.string()).default([]).description('群黑名单(优先于白名单)'),
|
|
162
163
|
outputLogs: Schema.boolean().default(true).description('输出详细日志'),
|
|
163
|
-
}).description('⑥ 权限与日志'),
|
|
164
|
+
}).description('⑥ 权限与日志').collapse(),
|
|
164
165
|
|
|
165
166
|
workflow: Schema.object({
|
|
166
167
|
customWorkflowEnabled: Schema.boolean().default(false).description('使用自定义 ComfyUI 工作流 JSON'),
|
|
@@ -168,6 +169,8 @@ exports.Config = Schema.object({
|
|
|
168
169
|
skipQualityPrefixForCustomWorkflow: Schema.boolean().default(true).description('启用自定义工作流时跳过质量前缀注入'),
|
|
169
170
|
customWorkflowOverrideParameters: Schema.boolean().default(false).description('用插件参数覆盖工作流内的采样参数'),
|
|
170
171
|
customWorkflowReloadOnChange: Schema.boolean().default(true).description('工作流文件变化时自动重载(无需重启)'),
|
|
172
|
+
workflowOverrideModel: Schema.boolean().default(true).description('用 unetName 覆盖自定义工作流里的模型文件名(让 `p-draw 模型` 切换对预设也生效)'),
|
|
173
|
+
modelLoaderNodeId: Schema.string().default('').description('指定覆盖哪个模型加载节点 ID(留空:工作流里只有一个模型加载节点时自动覆盖;有多个时跳过不猜)'),
|
|
171
174
|
positivePromptNodeId: Schema.string().default('').description('正面提示词节点 ID(留空自动识别;示例 6,以实际 JSON 为准)'),
|
|
172
175
|
negativePromptNodeId: Schema.string().default('').description('负面提示词节点 ID(留空自动识别;示例 7)'),
|
|
173
176
|
resolutionNodeId: Schema.string().default('').description('尺寸节点 ID(留空自动识别)'),
|
|
@@ -186,9 +189,12 @@ exports.Config = Schema.object({
|
|
|
186
189
|
samplerName: Schema.string().description('该预设固定采样器'),
|
|
187
190
|
scheduler: Schema.string().description('该预设固定调度器'),
|
|
188
191
|
overrideParameters: Schema.boolean().description('用上面的参数覆盖工作流内取值'),
|
|
192
|
+
price: Schema.number().description('该预设每张消耗的 P 点(留空沿用全局 price / multiPrice)'),
|
|
193
|
+
overrideModel: Schema.boolean().description('是否把 unetName 写进这个工作流的模型节点(留空沿用全局)'),
|
|
194
|
+
modelLoaderNodeId: Schema.string().description('该预设的模型加载节点 ID(留空沿用全局)'),
|
|
189
195
|
}).description('预设')).default({}).description('工作流预设:key=预设名。指令里用 `--工作流 <名称>` 或名称/别名开头选择(如 `画图 极速:1girl`)'),
|
|
190
196
|
defaultWorkflowPreset: Schema.string().default('').description('默认预设名(留空则用上面的 customWorkflow* 那套)'),
|
|
191
|
-
}).description('⑦ 自定义工作流'),
|
|
197
|
+
}).description('⑦ 自定义工作流').collapse(),
|
|
192
198
|
|
|
193
199
|
llm: Schema.object({
|
|
194
200
|
promptOptimizeEnabled: Schema.boolean().default(false).description('启用自然语言优化(需配置下面的 LLM 接口)'),
|
|
@@ -212,7 +218,7 @@ exports.Config = Schema.object({
|
|
|
212
218
|
llmExtraBody: Schema.string().role('textarea').default('{}').description('附加请求体 JSON(最后覆盖),用于中转站私有参数,如 {"enable_thinking":false}'),
|
|
213
219
|
llmMaxTokens: Schema.number().default(1000).description('LLM 输出上限'),
|
|
214
220
|
promptOptimizeTemplate: Schema.string().description('优化模板(支持 {theme} {search_block} {character_rule} 占位符)').default('你是为 Anima 图像生成模型编写正面提示词的 AI 画师。\n\n请根据用户的原始要求设计一幅完整、协调、具有视觉吸引力的画面,并将结果输出为英文 Danbooru-style tags。\n\n输出要求:\n- 只输出一行英文 tags,使用英文逗号分隔。\n- 不要输出解释、分析、标题、编号、Markdown、代码块或中文。\n- 不要输出 masterpiece、best quality、score 等质量前缀。\n- 不要输出画师 tags;质量词和画师组会由程序另行拼接。\n- 尽量使用模型容易理解的可见画面描述。\n- 保持用户明确指定的角色、主体、人数、关键服装、动作、表情和道具。\n- 除上述明确要求外,可以自由决定服装细节、姿态、构图、镜头、背景、环境、光影、色彩、氛围、前景和特效。\n- 以最终图像协调、精致、有表现力和好看为优先,不需要机械追求固定 Tag 数量。\n- 不要为了数量重复同义词;画面已经完整时即可停止。\n- 请自行解决明显冲突,直接输出你认为最适合生成最终画面的版本。\n\n角色和动态上下文:\n{character_rule}\n{search_block}\n\n用户原始要求:\n{theme}'),
|
|
215
|
-
}).description('⑧ 提示词优化 / LLM'),
|
|
221
|
+
}).description('⑧ 提示词优化 / LLM').collapse(),
|
|
216
222
|
|
|
217
223
|
search: Schema.object({
|
|
218
224
|
webSearchEnabled: Schema.boolean().default(false).description('启用联网搜索(指令里写「联网/搜索/查一下」触发)'),
|
|
@@ -221,7 +227,7 @@ exports.Config = Schema.object({
|
|
|
221
227
|
webSearchMaxResults: Schema.number().default(5).description('搜索结果数量'),
|
|
222
228
|
webSearchDepth: Schema.string().default('basic').description('搜索深度(basic / advanced)'),
|
|
223
229
|
webSearchQueryTemplate: Schema.string().default('{prompt} 角色 外观 立绘 服装 配色 武器 官方图 official art character design outfit appearance wiki fandom').description('搜索词模板({prompt} 代表用户需求)'),
|
|
224
|
-
}).description('⑨ 联网搜索'),
|
|
230
|
+
}).description('⑨ 联网搜索').collapse(),
|
|
225
231
|
|
|
226
232
|
vision: Schema.object({
|
|
227
233
|
multiVerifyEnabled: Schema.boolean().default(true).description('多人图生成后启用视觉校验'),
|
|
@@ -240,11 +246,11 @@ exports.Config = Schema.object({
|
|
|
240
246
|
proxy: Schema.string().description('该通道专用代理(留空则用上面的 verifyLlmProxy)'),
|
|
241
247
|
}).description('通道')).default({}).description('视觉校验的附加通道:主通道全部失败后按顺序继续尝试'),
|
|
242
248
|
verifyLlmChannelOrder: Schema.array(Schema.string()).default([]).description('视觉附加通道的尝试顺序(填通道名;留空则按配置先后顺序)'),
|
|
243
|
-
}).description('⑩ 多人视觉校验'),
|
|
249
|
+
}).description('⑩ 多人视觉校验').collapse(),
|
|
244
250
|
|
|
245
251
|
legacy: Schema.object({
|
|
246
252
|
workflow: Schema.string().default('anima_t2i').description('旧版工作流标识,仅用于状态/诊断显示,内置工作流固定 anima_t2i'),
|
|
247
|
-
}).description('⑪ 兼容项(旧版,可忽略)'),
|
|
253
|
+
}).description('⑪ 兼容项(旧版,可忽略)').collapse(),
|
|
248
254
|
})
|
|
249
255
|
|
|
250
256
|
// ------------------------------------------------------------------
|
|
@@ -355,7 +361,11 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
355
361
|
}
|
|
356
362
|
|
|
357
363
|
// 自定义工作流路径一律相对 Koishi 运行目录解析(见 lib/workflows.js)
|
|
358
|
-
const workflowOpts = () => ({
|
|
364
|
+
const workflowOpts = () => ({
|
|
365
|
+
baseDir: ctx.baseDir || process.cwd(),
|
|
366
|
+
overrideModel: cfg.workflowOverrideModel !== false,
|
|
367
|
+
modelLoaderNodeId: cfg.modelLoaderNodeId || '',
|
|
368
|
+
})
|
|
359
369
|
|
|
360
370
|
// ---------------- 工作流预设 ----------------
|
|
361
371
|
// 预设 = 一个 JSON 路径 + 可选的节点 ID / 采样参数覆盖,指令里按名字选用。
|
|
@@ -387,6 +397,10 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
387
397
|
? Boolean(preset.overrideParameters)
|
|
388
398
|
: Boolean(cfg.customWorkflowOverrideParameters),
|
|
389
399
|
}
|
|
400
|
+
if (preset.overrideModel !== undefined && preset.overrideModel !== null) {
|
|
401
|
+
patch.workflowOverrideModel = Boolean(preset.overrideModel)
|
|
402
|
+
}
|
|
403
|
+
if (preset.modelLoaderNodeId) patch.modelLoaderNodeId = String(preset.modelLoaderNodeId)
|
|
390
404
|
return patch
|
|
391
405
|
}
|
|
392
406
|
|
|
@@ -401,6 +415,13 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
401
415
|
return out
|
|
402
416
|
}
|
|
403
417
|
|
|
418
|
+
// 预设可以单独定价;没配就回落到全局 price / multiPrice
|
|
419
|
+
function presetPrice(preset) {
|
|
420
|
+
if (!preset || preset.price === undefined || preset.price === null || preset.price === '') return null
|
|
421
|
+
const value = Number(preset.price)
|
|
422
|
+
return Number.isFinite(value) && value >= 0 ? value : null
|
|
423
|
+
}
|
|
424
|
+
|
|
404
425
|
// 体检:这个预设现在能不能真的跑(能否从纯文本启动)
|
|
405
426
|
function inspectPreset(preset) {
|
|
406
427
|
return inspectWorkflowFile(preset.path, {
|
|
@@ -605,6 +626,18 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
605
626
|
lines.push(`步数节点:${fmt(t.stepsIds)}(${how(cfg.stepsNodeId, t.stepsIds.length)})`)
|
|
606
627
|
lines.push(`种子节点:${fmt(t.seedIds)}(${how(cfg.seedNodeId, t.seedIds.length)})`)
|
|
607
628
|
lines.push(`识别的文本编码节点:${fmt(t.textNodes)}`)
|
|
629
|
+
const loaders = report.modelLoaders || []
|
|
630
|
+
if (loaders.length) {
|
|
631
|
+
const list = loaders.map(l => `#${l.id} ${l.classType}`).join('、')
|
|
632
|
+
const how = cfg.workflowOverrideModel === false
|
|
633
|
+
? '不注入(workflowOverrideModel=false,模型由 JSON 决定)'
|
|
634
|
+
: loaders.length > 1
|
|
635
|
+
? (String(cfg.modelLoaderNodeId || '').trim() ? `只注入 #${cfg.modelLoaderNodeId}` : '跳过(有多个模型加载节点,可用 modelLoaderNodeId 指定)')
|
|
636
|
+
: `注入 ${cfg.unetName}`
|
|
637
|
+
lines.push(`模型加载节点:${list}(${how})`)
|
|
638
|
+
} else {
|
|
639
|
+
lines.push('模型加载节点:(未找到可注入的 UNETLoader / CheckpointLoaderSimple)')
|
|
640
|
+
}
|
|
608
641
|
return lines
|
|
609
642
|
}
|
|
610
643
|
|
|
@@ -618,7 +651,9 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
618
651
|
for (const preset of presets) {
|
|
619
652
|
const report = inspectPreset(preset)
|
|
620
653
|
const aliases = (preset.aliases || []).length ? `(别名:${preset.aliases.join('、')})` : ''
|
|
621
|
-
|
|
654
|
+
const unit = presetPrice(preset)
|
|
655
|
+
const priceTag = unit != null ? ` ${unit} P/张` : ' 默认价'
|
|
656
|
+
lines.push(`${report.ok ? '✅' : '❌'} ${preset.name}${aliases}${priceTag}`)
|
|
622
657
|
if (report.ok) {
|
|
623
658
|
const analysis = report.analysis
|
|
624
659
|
const pos = report.targets.positive.map(id => `#${id}`).join('、')
|
|
@@ -966,7 +1001,11 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
966
1001
|
const cfgVal = Number(overrides.cfg) || workCfg.cfg
|
|
967
1002
|
const seed = Number(overrides.seed) || crypto.randomInt(1, 2 ** 32 - 1)
|
|
968
1003
|
const negativePrompt = joinPromptParts([overrides.negativePrompt || cfg.negativePrompt || ''])
|
|
969
|
-
const promptBody = buildWorkflow(workCfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, Boolean(size), Object.assign({}, workflowOpts(), {
|
|
1004
|
+
const promptBody = buildWorkflow(workCfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, Boolean(size), Object.assign({}, workflowOpts(), {
|
|
1005
|
+
modelParams: overrideKeys,
|
|
1006
|
+
overrideModel: baseCfg.workflowOverrideModel !== false,
|
|
1007
|
+
modelLoaderNodeId: baseCfg.modelLoaderNodeId || '',
|
|
1008
|
+
}))
|
|
970
1009
|
|
|
971
1010
|
const clientId = crypto.randomUUID()
|
|
972
1011
|
const submit = await comfyPost('/prompt', { prompt: promptBody, client_id: clientId }, 20000)
|
|
@@ -1696,7 +1735,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
1696
1735
|
const USERID = session.userId
|
|
1697
1736
|
const isAdmin = isAdminUser(session)
|
|
1698
1737
|
const unet = await resolveUnet(USERID)
|
|
1699
|
-
|
|
1738
|
+
let price = Math.max(0, parseInt(cfg.multiPrice) || cfg.price)
|
|
1700
1739
|
if (cfg.outputLogs) {
|
|
1701
1740
|
logger.info(`[p-draw] 多人请求 userId=${USERID} isAdmin=${isAdmin}`)
|
|
1702
1741
|
}
|
|
@@ -1722,6 +1761,8 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
1722
1761
|
if (usable.ok) activePreset = usable.preset
|
|
1723
1762
|
else if (cfg.outputLogs) logger.warn(`[p-draw] 默认预设不可用,已回落:${usable.message}`)
|
|
1724
1763
|
}
|
|
1764
|
+
const presetUnitPrice = presetPrice(activePreset)
|
|
1765
|
+
if (presetUnitPrice != null) price = presetUnitPrice
|
|
1725
1766
|
const text = parsedPreset.prompt
|
|
1726
1767
|
if (!text) return session.text('.multi-usage')
|
|
1727
1768
|
const count = parsedBatch.count
|
|
@@ -2202,6 +2243,8 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2202
2243
|
const text = parsedPreset.prompt
|
|
2203
2244
|
const seed = parsedSeed.seed
|
|
2204
2245
|
const count = parsedBatch.count
|
|
2246
|
+
// 预设可单独定价,未配置则用全局 price
|
|
2247
|
+
const unitPrice = presetPrice(activePreset) ?? Math.max(0, Number(cfg.price) || 0)
|
|
2205
2248
|
// 命令级参数优先于预设 / modelParams / 全局配置(见 runComfyGenerate)
|
|
2206
2249
|
const tuningOverrides = Object.assign(
|
|
2207
2250
|
activePreset ? { preset: activePreset } : {},
|
|
@@ -2214,7 +2257,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2214
2257
|
|
|
2215
2258
|
// P 点校验(按总价 = 张数 × 单价)
|
|
2216
2259
|
// P 点校验(按总价 = 张数 × 单价)
|
|
2217
|
-
const pcheck = await precheckPoints(session, USERID, isAdmin, count *
|
|
2260
|
+
const pcheck = await precheckPoints(session, USERID, isAdmin, count * unitPrice)
|
|
2218
2261
|
if (!pcheck.ok) return pcheck.message
|
|
2219
2262
|
|
|
2220
2263
|
// 原样模式
|
|
@@ -2304,8 +2347,8 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2304
2347
|
|
|
2305
2348
|
// 扣 P 点(一次性扣除总价)
|
|
2306
2349
|
if (!isAdmin) {
|
|
2307
|
-
const saving = await deductP(USERID, count *
|
|
2308
|
-
if (cfg.outputLogs) logger.info(`[p-draw] ${USERID} 已扣除 ${count *
|
|
2350
|
+
const saving = await deductP(USERID, count * unitPrice)
|
|
2351
|
+
if (cfg.outputLogs) logger.info(`[p-draw] ${USERID} 已扣除 ${count * unitPrice} P 点(${count} 张 × ${unitPrice}),余额 ${saving - count * unitPrice}`)
|
|
2309
2352
|
}
|
|
2310
2353
|
|
|
2311
2354
|
// 用户手写了 negative: 区块时,默认负面词仍保留;用户 tag 只补充未出现的部分。
|
|
@@ -2327,7 +2370,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2327
2370
|
}
|
|
2328
2371
|
const generated = await runComfyGenerate(p, parsedSize.size, generationOverrides)
|
|
2329
2372
|
return { ...generated, prompt: p }
|
|
2330
|
-
}, { USERID, isAdmin, totalPrice: count *
|
|
2373
|
+
}, { USERID, isAdmin, totalPrice: count * unitPrice })
|
|
2331
2374
|
if (!queued.ok) return queued.message
|
|
2332
2375
|
const queuedTasks = queued.tasks
|
|
2333
2376
|
const firstPosition = queued.firstPosition
|
|
@@ -2370,7 +2413,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2370
2413
|
return result
|
|
2371
2414
|
}
|
|
2372
2415
|
|
|
2373
|
-
const { results, successCount } = await executeBatch(USERID, isAdmin, count,
|
|
2416
|
+
const { results, successCount } = await executeBatch(USERID, isAdmin, count, unitPrice, runOne)
|
|
2374
2417
|
|
|
2375
2418
|
// 汇总
|
|
2376
2419
|
const allOutputs = []
|
|
@@ -2389,7 +2432,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2389
2432
|
|
|
2390
2433
|
const chargeNotice = buildChargeNotice({
|
|
2391
2434
|
isAdmin,
|
|
2392
|
-
totalPrice: successCount *
|
|
2435
|
+
totalPrice: successCount * unitPrice,
|
|
2393
2436
|
unetName: unet,
|
|
2394
2437
|
seeds,
|
|
2395
2438
|
})
|
|
@@ -2551,5 +2594,5 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2551
2594
|
})
|
|
2552
2595
|
|
|
2553
2596
|
// 暴露内部接口供自动化测试调用(Koishi 忽略 apply 返回值,不影响生产行为)
|
|
2554
|
-
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch, composePrompt, shouldSkipQualityPrefix, qualityPrefixWarning, customWorkflowDiagLines, diagnoseText, workflowDir, normalizeConfig, presetList, presetOverviewText }
|
|
2597
|
+
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch, composePrompt, shouldSkipQualityPrefix, qualityPrefixWarning, customWorkflowDiagLines, diagnoseText, workflowDir, normalizeConfig, presetList, presetOverviewText, presetPrice }
|
|
2555
2598
|
}
|
package/lib/comfy.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// ComfyUI 结果等待与输出提取。
|
|
2
2
|
// waitComfyResult 依赖一个注入的 comfyGet(由 http 客户端提供),可独立单测。
|
|
3
3
|
|
|
4
|
+
// 从 /history 结果里取出图片。
|
|
5
|
+
// PreviewImage 之类的节点会产出 type='temp' 的临时预览图(修脸修手工作流一次能有十几张),
|
|
6
|
+
// 这些不该发给用户;优先只取 SaveImage 的 type='output'。
|
|
7
|
+
// 若整条工作流只有预览节点、没有 SaveImage,则退回取全部,避免什么都取不到。
|
|
4
8
|
function outputImages(history) {
|
|
5
9
|
const images = []
|
|
6
10
|
const outputs = history.outputs || {}
|
|
@@ -12,7 +16,8 @@ function outputImages(history) {
|
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
|
-
|
|
19
|
+
const finals = images.filter(image => image.type !== 'temp')
|
|
20
|
+
return finals.length ? finals : images
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
// ------------------------------------------------------------------
|
package/lib/i18n.js
CHANGED
|
@@ -10,6 +10,8 @@ const zhCN = {
|
|
|
10
10
|
customWorkflowPath: { $description: '自定义工作流 JSON 路径(相对 Koishi 运行目录,例如 data/p-draw/workflows/anima-aesthetic-v1.1.json;插件目录作为回退)' },
|
|
11
11
|
customWorkflowOverrideParameters: { $description: '用插件参数覆盖自定义工作流参数' },
|
|
12
12
|
customWorkflowReloadOnChange: { $description: '工作流 JSON 变化时自动重载(无需重启插件)' },
|
|
13
|
+
workflowOverrideModel: { $description: '用 unetName 覆盖自定义工作流里的模型文件名(让 p-draw 模型 切换对预设也生效)' },
|
|
14
|
+
modelLoaderNodeId: { $description: '指定覆盖哪个模型加载节点 ID(留空则只有一个模型节点时自动覆盖)' },
|
|
13
15
|
positivePromptNodeId: { $description: '自定义工作流中正面提示词节点 ID(留空自动识别;示例 6,以实际 JSON 为准)' },
|
|
14
16
|
negativePromptNodeId: { $description: '自定义工作流中负面提示词节点 ID(留空自动识别;示例 7,以实际 JSON 为准)' },
|
|
15
17
|
resolutionNodeId: { $description: '自定义工作流中尺寸节点 ID(EmptyLatentImage,可留空;示例 5)' },
|
package/lib/workflows.js
CHANGED
|
@@ -182,6 +182,19 @@ function findNodesByClass(workflow, classTypes) {
|
|
|
182
182
|
return ids
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
// 采样节点:类名含 sampler 且带 steps 输入(KSampler / KSamplerAdvanced / ClownsharKSampler_Beta …)
|
|
186
|
+
function findSamplerNodeIds(workflow) {
|
|
187
|
+
const ids = []
|
|
188
|
+
for (const [nodeId, node] of Object.entries(workflow)) {
|
|
189
|
+
if (!node || typeof node !== 'object') continue
|
|
190
|
+
if (!/sampler/i.test(String(node.class_type || ''))) continue
|
|
191
|
+
const inputs = node.inputs
|
|
192
|
+
if (!inputs || typeof inputs !== 'object') continue
|
|
193
|
+
if (!('steps' in inputs)) continue
|
|
194
|
+
ids.push(String(nodeId))
|
|
195
|
+
}
|
|
196
|
+
return ids
|
|
197
|
+
}
|
|
185
198
|
// 尺寸节点:凡是「类名带 Latent 且同时有 width/height 输入」的都算。
|
|
186
199
|
// 这样 EmptyLatentImage、EmptySD3LatentImage、EmptyHunyuanLatentVideo 等新老节点都能认。
|
|
187
200
|
function findResolutionNodeIds(workflow) {
|
|
@@ -198,12 +211,13 @@ function findResolutionNodeIds(workflow) {
|
|
|
198
211
|
return ids
|
|
199
212
|
}
|
|
200
213
|
|
|
201
|
-
//
|
|
214
|
+
// 从任意带 positive/negative 输入的节点(KSampler、KSamplerAdvanced、ClownsharKSampler_Beta
|
|
215
|
+
// 等所有采样器)沿连线反查,找到真正的文本编码节点。
|
|
216
|
+
// 不写死采样器类名,否则 RES4LYF / 自定义采样器都会识别不到。
|
|
202
217
|
function conditioningTextNodeIds(workflow, inputName, textNodes) {
|
|
203
218
|
const pending = []
|
|
204
219
|
for (const node of Object.values(workflow)) {
|
|
205
220
|
if (!node || typeof node !== 'object') continue
|
|
206
|
-
if (!['KSampler', 'KSamplerAdvanced'].includes(String(node.class_type || ''))) continue
|
|
207
221
|
const link = node.inputs && node.inputs[inputName]
|
|
208
222
|
if (Array.isArray(link) && link.length) pending.push(String(link[0]))
|
|
209
223
|
}
|
|
@@ -279,17 +293,17 @@ function resolveCustomNodeTargets(workflow, cfg = {}) {
|
|
|
279
293
|
}
|
|
280
294
|
|
|
281
295
|
// 采样节点:显式指定则只改该节点,否则改所有 KSampler
|
|
282
|
-
const samplerClasses =
|
|
296
|
+
const samplerClasses = findSamplerNodeIds(workflow)
|
|
283
297
|
const explicitSteps = cleanNodeId(cfg.stepsNodeId)
|
|
284
298
|
let stepsIds = []
|
|
285
299
|
if (explicitSteps) {
|
|
286
300
|
if (!workflow[explicitSteps]) {
|
|
287
|
-
errors.push(`配置的步数节点 ID「${explicitSteps}」不存在于工作流中。可能是:\n ${
|
|
301
|
+
errors.push(`配置的步数节点 ID「${explicitSteps}」不存在于工作流中。可能是:\n ${samplerClasses.map(id => nodeLabel(workflow, id)).join('\n ') || '(无)'}`)
|
|
288
302
|
} else {
|
|
289
303
|
stepsIds = [explicitSteps]
|
|
290
304
|
}
|
|
291
305
|
} else {
|
|
292
|
-
stepsIds =
|
|
306
|
+
stepsIds = samplerClasses
|
|
293
307
|
}
|
|
294
308
|
|
|
295
309
|
// seed 节点:显式指定则只改该节点,否则改所有带 seed / noise_seed 输入的节点
|
|
@@ -297,7 +311,7 @@ function resolveCustomNodeTargets(workflow, cfg = {}) {
|
|
|
297
311
|
let seedIds = []
|
|
298
312
|
if (explicitSeed) {
|
|
299
313
|
if (!workflow[explicitSeed]) {
|
|
300
|
-
errors.push(`配置的种子节点 ID「${explicitSeed}」不存在于工作流中。可能是:\n ${
|
|
314
|
+
errors.push(`配置的种子节点 ID「${explicitSeed}」不存在于工作流中。可能是:\n ${samplerClasses.map(id => nodeLabel(workflow, id)).join('\n ') || '(无)'}`)
|
|
301
315
|
} else {
|
|
302
316
|
seedIds = [explicitSeed]
|
|
303
317
|
}
|
|
@@ -326,6 +340,9 @@ function customWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVa
|
|
|
326
340
|
const targets = resolveCustomNodeTargets(workflow, cfg)
|
|
327
341
|
if (targets.errors.length) throw new Error(targets.errors.join('\n'))
|
|
328
342
|
|
|
343
|
+
// 模型名注入:让 unetName / p-draw 模型 对自定义工作流也生效
|
|
344
|
+
const modelResult = applyModelOverride(workflow, cfg, opts)
|
|
345
|
+
|
|
329
346
|
for (const nodeId of targets.positive) {
|
|
330
347
|
if (workflow[nodeId] && workflow[nodeId].inputs) workflow[nodeId].inputs.text = prompt
|
|
331
348
|
}
|
|
@@ -373,7 +390,7 @@ function customWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVa
|
|
|
373
390
|
|
|
374
391
|
// 只读检查:供「p-draw 诊断」报告工作流来源与实际解析到的节点,不生成图片
|
|
375
392
|
function inspectCustomWorkflow(cfg, opts = {}) {
|
|
376
|
-
const report = { ok: false, path: '', mtimeMs: null, targets: null, textNodes: [], error: '' }
|
|
393
|
+
const report = { ok: false, path: '', mtimeMs: null, targets: null, textNodes: [], modelLoaders: [], error: '' }
|
|
377
394
|
try {
|
|
378
395
|
const absPath = resolveCustomWorkflowPath(cfg, opts)
|
|
379
396
|
report.path = absPath
|
|
@@ -383,6 +400,7 @@ function inspectCustomWorkflow(cfg, opts = {}) {
|
|
|
383
400
|
const targets = resolveCustomNodeTargets(workflow, cfg)
|
|
384
401
|
report.targets = targets
|
|
385
402
|
report.textNodes = targets.textNodes
|
|
403
|
+
report.modelLoaders = findModelLoaders(workflow)
|
|
386
404
|
if (targets.errors.length) {
|
|
387
405
|
report.error = targets.errors.join(';')
|
|
388
406
|
return report
|
|
@@ -399,6 +417,52 @@ function inspectCustomWorkflow(cfg, opts = {}) {
|
|
|
399
417
|
const IMAGE_INPUT_RE = /^(LoadImage|LoadImageMask|LoadImageOutput|ImageInput|LoadImageFromUrl)$/i
|
|
400
418
|
const CONTROLNET_RE = /controlnet/i
|
|
401
419
|
|
|
420
|
+
// 主模型加载节点 → 模型文件名所在的输入名
|
|
421
|
+
const MODEL_LOADER_INPUTS = {
|
|
422
|
+
UNETLoader: 'unet_name',
|
|
423
|
+
UnetLoaderGGUF: 'unet_name',
|
|
424
|
+
EnhancedLoadDiffusionModel: 'unet_name',
|
|
425
|
+
CheckpointLoaderSimple: 'ckpt_name',
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// 找出工作流里的模型加载节点
|
|
429
|
+
function findModelLoaders(workflow) {
|
|
430
|
+
const found = []
|
|
431
|
+
for (const [nodeId, node] of Object.entries(workflow)) {
|
|
432
|
+
if (!node || typeof node !== 'object') continue
|
|
433
|
+
const inputName = MODEL_LOADER_INPUTS[String(node.class_type || '')]
|
|
434
|
+
if (!inputName) continue
|
|
435
|
+
const inputs = node.inputs
|
|
436
|
+
if (!inputs || !(inputName in inputs)) continue
|
|
437
|
+
found.push({ id: String(nodeId), inputName, classType: String(node.class_type) })
|
|
438
|
+
}
|
|
439
|
+
return found
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// 把 cfg.unetName 写进工作流的模型加载节点。
|
|
443
|
+
// 多个加载器时不猜(除非用 modelLoaderNodeId 指定),避免把双模型工作流写坏。
|
|
444
|
+
function applyModelOverride(workflow, cfg, opts = {}) {
|
|
445
|
+
if (opts.overrideModel === false) return { applied: false, loaders: findModelLoaders(workflow), reason: 'disabled' }
|
|
446
|
+
const loaders = findModelLoaders(workflow)
|
|
447
|
+
const model = String((cfg && cfg.unetName) || '').trim()
|
|
448
|
+
if (!loaders.length) return { applied: false, loaders, reason: 'no-loader' }
|
|
449
|
+
if (!model) return { applied: false, loaders, reason: 'no-model' }
|
|
450
|
+
|
|
451
|
+
const pinned = cleanNodeId(opts.modelLoaderNodeId)
|
|
452
|
+
let targets = loaders
|
|
453
|
+
if (pinned) {
|
|
454
|
+
targets = loaders.filter(loader => loader.id === pinned)
|
|
455
|
+
if (!targets.length) return { applied: false, loaders, reason: `node-not-found:${pinned}` }
|
|
456
|
+
} else if (loaders.length > 1) {
|
|
457
|
+
return { applied: false, loaders, reason: 'ambiguous' }
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
for (const target of targets) {
|
|
461
|
+
workflow[target.id].inputs[target.inputName] = model
|
|
462
|
+
}
|
|
463
|
+
return { applied: true, loaders, targets, model, reason: '' }
|
|
464
|
+
}
|
|
465
|
+
|
|
402
466
|
// 体检:这个工作流能不能在「纯文本」模式下跑,需要什么额外输入
|
|
403
467
|
function analyzeWorkflow(workflow) {
|
|
404
468
|
const classes = Object.values(workflow).map(node => String((node && node.class_type) || ''))
|
|
@@ -482,6 +546,7 @@ module.exports = {
|
|
|
482
546
|
nodeLabel,
|
|
483
547
|
collectTextNodeIds,
|
|
484
548
|
findNodesByClass,
|
|
549
|
+
findSamplerNodeIds,
|
|
485
550
|
findResolutionNodeIds,
|
|
486
551
|
buildWorkflow,
|
|
487
552
|
customWorkflow,
|
|
@@ -490,6 +555,9 @@ module.exports = {
|
|
|
490
555
|
inspectCustomWorkflow,
|
|
491
556
|
IMAGE_INPUT_RE,
|
|
492
557
|
CONTROLNET_RE,
|
|
558
|
+
MODEL_LOADER_INPUTS,
|
|
559
|
+
findModelLoaders,
|
|
560
|
+
applyModelOverride,
|
|
493
561
|
analyzeWorkflow,
|
|
494
562
|
inspectWorkflowFile,
|
|
495
563
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -125,6 +125,8 @@ plugins:
|
|
|
125
125
|
| `skipQualityPrefixForCustomWorkflow` | 启用自定义工作流时跳过质量前缀注入(默认 `true`) |
|
|
126
126
|
| `customWorkflowOverrideParameters` | 用插件参数覆盖工作流内的采样参数(总开关)。注意:`modelParams` 里显式写了的字段不受这个开关限制,永远覆盖 |
|
|
127
127
|
| `customWorkflowReloadOnChange` | 工作流文件变化时自动重载,无需重启(默认 `true`) |
|
|
128
|
+
| `workflowOverrideModel` | 用 `unetName` 覆盖自定义工作流里的模型文件名(默认 `true`)。开着之后 `p-draw 模型 <名称>` 对预设也生效,不用改 JSON |
|
|
129
|
+
| `modelLoaderNodeId` | 指定覆盖哪个模型加载节点。留空时:工作流里只有一个模型加载节点就自动覆盖,有多个则不猜、跳过 |
|
|
128
130
|
| `positivePromptNodeId` / `negativePromptNodeId` | 正/负面提示词节点 ID;留空自动识别 |
|
|
129
131
|
| `resolutionNodeId` / `seedNodeId` / `stepsNodeId` | 尺寸 / 种子 / 步数节点 ID;可留空(留空则按节点类型覆盖) |
|
|
130
132
|
| `workflowPresets` | 工作流预设字典:`预设名 → { path, aliases, 节点 ID, steps, cfg, ... }`,供指令按名切换(见下方「工作流预设」) |
|
|
@@ -432,15 +434,30 @@ defaultWorkflowPreset: 基础文生图
|
|
|
432
434
|
| 09 | Text-to-Image Baseline | 17 | 文本 | ✅ 可用 |
|
|
433
435
|
| 03 | DMDX 4-Step Speed Run | 19 | 文本 | ✅ 可用(设 `steps: 4`、低 CFG) |
|
|
434
436
|
| 04 | Three-Stage High-Quality | 26 | 文本 | ✅ 可用(多段采样+放大) |
|
|
435
|
-
| 01 | 1.5x Upscale | 20 |
|
|
437
|
+
| 01 | 1.5x Upscale | 20 | 文本 | ✅ 可用(见下方依赖) |
|
|
436
438
|
| 05 | Tiled Upscale | 45 | 视导出而定 | ⚠️ 同上 |
|
|
437
|
-
| 08 | T2I + ControlNet + Face/Hand Repair | 60 | 文本 + 控制图 |
|
|
439
|
+
| 08 | T2I + ControlNet + Face/Hand Repair | 60 | 文本 + 控制图 | ✅ 可用(已裁成单输出;ControlNet 分支默认旁路,需检测器 + SAM 模型) |
|
|
438
440
|
| 02 | ControlNet Precision Control | 32 | 图片 | ❌ 需图生图 |
|
|
439
441
|
| 06 | i2i + ControlNet + Face/Hand Repair | 52 | 图片 | ❌ 需图生图 |
|
|
440
442
|
| 07 | Image-to-Image | 19 | 图片 | ❌ 需图生图 |
|
|
441
443
|
| 10 | Anima-Edit LoRA / IC | 52 | 图片 | ❌ 需图生图 |
|
|
442
444
|
|
|
443
|
-
判断依据是自动体检的结果:**只要 JSON 里出现 `LoadImage` 一类节点,就判定为需要图片输入**。所以
|
|
445
|
+
判断依据是自动体检的结果:**只要 JSON 里出现 `LoadImage` 一类节点,就判定为需要图片输入**。所以 05/08 到底能不能用,取决于你导出时是「从空 latent 开始」还是「从图开始」——`画图 工作流` 会直接告诉你。
|
|
446
|
+
|
|
447
|
+
### 官方工作流需要先装的自定义节点
|
|
448
|
+
|
|
449
|
+
官方这套工作流依赖几个 ComfyUI 自定义节点包,**不装的话图里会显示红色缺失节点**:
|
|
450
|
+
|
|
451
|
+
| 节点包 | 提供 | 用于 |
|
|
452
|
+
|---|---|---|
|
|
453
|
+
| [RES4LYF](https://github.com/ClownsharkBatwing/RES4LYF) | `ClownsharKSampler_Beta` | 几乎所有官方工作流的主力采样器(`beta57` 等调度器) |
|
|
454
|
+
| [Comfy-WaveSpeed](https://github.com/chengzeyi/Comfy-WaveSpeed) | `EnhancedLoadDiffusionModel` | 官方图的模型加载节点 |
|
|
455
|
+
| [ControlAltAI-Nodes](https://github.com/gseth/ControlAltAI-Nodes) | `FluxResolutionNode` | 按兆像素/比例计算尺寸 |
|
|
456
|
+
| [rgthree-comfy](https://github.com/rgthree/rgthree-comfy) | `Seed (rgthree)` | 08 等图的种子节点 |
|
|
457
|
+
|
|
458
|
+
> `XB_UNetNameBroadcaster`(在 XB_ToolBox 里)依赖极重(easyocr / whisper / diffusers…),**不建议装**。它只是给模型加载节点传一个字符串,删掉该节点、直接在加载节点的下拉框里选模型即可。
|
|
459
|
+
|
|
460
|
+
01 实测流程:装上 RES4LYF + Comfy-WaveSpeed + ControlAltAI-Nodes,删掉 `XB_UNetNameBroadcaster`,把模型选成自己的,导出 API 即可。**插件会自动把 `unetName` 注入模型节点**(见 `workflowOverrideModel`),所以后续换模型不用再改 JSON。
|
|
444
461
|
|
|
445
462
|
图生图能力(图片上传 + `LoadImage` 注入 + 重绘幅度)尚未实现,所以 ❌ 的四个目前只能等后续版本。
|
|
446
463
|
|