koishi-plugin-p-draw 1.5.7 → 1.6.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/index.js +176 -74
- package/lib/i18n.js +12 -4
- package/lib/workflows.js +404 -169
- package/package.json +1 -1
- package/readme.md +100 -6
package/index.js
CHANGED
|
@@ -37,13 +37,24 @@ exports.Config = Schema.object({
|
|
|
37
37
|
comfyuiBaseUrl: Schema.string().default('http://127.0.0.1:8188').description('ComfyUI 地址'),
|
|
38
38
|
workflow: Schema.string().default('anima_t2i').description('工作流类型(内置 anima_t2i)'),
|
|
39
39
|
customWorkflowEnabled: Schema.boolean().default(false).description('使用自定义 ComfyUI 工作流 JSON'),
|
|
40
|
-
customWorkflowPath: Schema.string().default('').description('自定义工作流 JSON
|
|
40
|
+
customWorkflowPath: Schema.string().default('').description('自定义工作流 JSON 路径(相对 Koishi 运行目录,例如 data/p-draw/workflows/anima-aesthetic-v1.1.json;插件目录作为回退)'),
|
|
41
41
|
customWorkflowOverrideParameters: Schema.boolean().default(false).description('用插件参数覆盖自定义工作流参数'),
|
|
42
|
+
customWorkflowReloadOnChange: Schema.boolean().default(true).description('工作流 JSON 变化时自动重载(无需重启插件)'),
|
|
43
|
+
positivePromptNodeId: Schema.string().default('').description('自定义工作流中正面提示词节点 ID(留空自动识别;示例 6,以实际 JSON 为准)'),
|
|
44
|
+
negativePromptNodeId: Schema.string().default('').description('自定义工作流中负面提示词节点 ID(留空自动识别;示例 7,以实际 JSON 为准)'),
|
|
45
|
+
resolutionNodeId: Schema.string().default('').description('自定义工作流中尺寸节点 ID(EmptyLatentImage,可留空;示例 5)'),
|
|
46
|
+
seedNodeId: Schema.string().default('').description('自定义工作流中种子节点 ID(KSampler,可留空;示例 3)'),
|
|
47
|
+
stepsNodeId: Schema.string().default('').description('自定义工作流中步数节点 ID(KSampler,可留空;示例 3)'),
|
|
42
48
|
timeout: Schema.number().default(300).description('单次生成超时(秒)'),
|
|
43
49
|
pollInterval: Schema.number().default(2).description('生成状态查询间隔(秒)'),
|
|
44
50
|
|
|
45
51
|
// 模型文件
|
|
46
|
-
unetName: Schema.string().default('anima-
|
|
52
|
+
unetName: Schema.string().default('anima-aesthetic-v1.1.safetensors').description('主模型文件名(需与 ComfyUI models/diffusion_models 下的文件名完全一致,含连字符)。8G 显存推荐改为 GGUF Q8_0 版(如 anima-aesthetic-v1.1-Q8_0.gguf),插件会自动改用 UnetLoaderGGUF 加载'),
|
|
53
|
+
useGgufUnet: Schema.union([
|
|
54
|
+
Schema.const('auto').description('按模型文件名自动判断(.gguf 用 UnetLoaderGGUF)'),
|
|
55
|
+
Schema.const('true').description('强制使用 UnetLoaderGGUF(需安装 ComfyUI-GGUF)'),
|
|
56
|
+
Schema.const('false').description('强制使用原生 UNETLoader'),
|
|
57
|
+
]).default('auto').description('主模型加载方式(auto / true / false)'),
|
|
47
58
|
modelParams: Schema.dict(Schema.object({
|
|
48
59
|
samplerName: Schema.string().description('采样器(如 er_sde / res_2s / dpmpp_2m)'),
|
|
49
60
|
scheduler: Schema.string().description('调度器(如 simple / beta57 / normal)'),
|
|
@@ -60,13 +71,14 @@ exports.Config = Schema.object({
|
|
|
60
71
|
height: Schema.number().default(1216).description('默认高度'),
|
|
61
72
|
allowedSizes: Schema.array(Schema.string()).default(['832x1216', '896x1152', '1024x1024', '1152x896', '1216x832', '768x1344', '1344x768', '1024x1536']).description('可用尺寸列表(宽x高)'),
|
|
62
73
|
steps: Schema.number().default(30).description('采样步数'),
|
|
63
|
-
cfg: Schema.number().default(4.
|
|
74
|
+
cfg: Schema.number().default(4.0).description('CFG 强度(Aesthetic 1.1 推荐 4,用 3 也常能出更好效果)'),
|
|
64
75
|
samplerName: Schema.string().default('er_sde').description('采样器'),
|
|
65
76
|
scheduler: Schema.string().default('simple').description('调度器'),
|
|
66
77
|
|
|
67
|
-
//
|
|
68
|
-
qualityPrefix: Schema.string().default('masterpiece, best quality, score_7
|
|
69
|
-
|
|
78
|
+
// 提示词(默认值按 Design.md A4:Aesthetic 1.1 训练时已剥离质量标签,不需要质量前缀)
|
|
79
|
+
qualityPrefix: Schema.string().default('').description('质量词前缀(使用 Aesthetic 1.1 时建议留空;Base 模型可填 masterpiece, best quality, score_7)'),
|
|
80
|
+
skipQualityPrefixForCustomWorkflow: Schema.boolean().default(true).description('启用自定义工作流时自动跳过质量前缀注入(Aesthetic 模型不需要质量标签)'),
|
|
81
|
+
negativePrompt: Schema.string().default('worst quality, low quality, score_1, score_2, score_3, artist name, blurry, jpeg artifacts').description('负面提示词(Aesthetic 1.1 推荐值)'),
|
|
70
82
|
promptOptimizeEnabled: Schema.boolean().default(false).description('启用自然语言优化(需要配置下方 LLM 接口)'),
|
|
71
83
|
llmBaseUrl: Schema.string().default('').description('LLM 接口地址(OpenAI 兼容,例如 https://api.deepseek.com/v1)'),
|
|
72
84
|
llmApiKey: Schema.string().role('secret').default('').description('LLM API Key'),
|
|
@@ -128,7 +140,7 @@ const {
|
|
|
128
140
|
NO_ARTIST_RE, NO_STYLE_RE,
|
|
129
141
|
} = require('./lib/tags')
|
|
130
142
|
const {
|
|
131
|
-
buildWorkflow,
|
|
143
|
+
buildWorkflow, inspectCustomWorkflow, isGgufUnet,
|
|
132
144
|
} = require('./lib/workflows')
|
|
133
145
|
const { outputImages, waitComfyResult } = require('./lib/comfy')
|
|
134
146
|
const { materializeImageSource } = require('./lib/media')
|
|
@@ -174,18 +186,59 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
174
186
|
// 用户自选模型偏好(userid -> unet 文件名),持久化在 p_draw_config.user_models
|
|
175
187
|
if (!cfg.userModels || typeof cfg.userModels !== 'object') cfg.userModels = {}
|
|
176
188
|
|
|
177
|
-
|
|
178
|
-
//
|
|
189
|
+
// 启动时清理上次运行遗留的临时目录(先清理,再创建本次目录)。
|
|
190
|
+
// 目录名带 PID:只清理「进程已退出」的目录,避免并行实例把自己的活跃临时目录删掉
|
|
191
|
+
// (旧版无 PID 后缀的 pdraw-* 视为历史遗留,直接清理)。
|
|
192
|
+
function cleanupStaleTempDirs() {
|
|
193
|
+
try {
|
|
194
|
+
for (const name of fs.readdirSync(os.tmpdir())) {
|
|
195
|
+
if (!name.startsWith('pdraw-')) continue
|
|
196
|
+
const owned = name.match(/^pdraw-(\d+)-/)
|
|
197
|
+
if (owned) {
|
|
198
|
+
const pid = parseInt(owned[1], 10)
|
|
199
|
+
if (pid === process.pid) continue
|
|
200
|
+
try {
|
|
201
|
+
process.kill(pid, 0)
|
|
202
|
+
continue // 进程仍存活,跳过
|
|
203
|
+
} catch (e) { /* 进程已退出,可清理 */ }
|
|
204
|
+
}
|
|
205
|
+
const dir = path.join(os.tmpdir(), name)
|
|
206
|
+
try {
|
|
207
|
+
for (const file of fs.readdirSync(dir)) fs.unlinkSync(path.join(dir, file))
|
|
208
|
+
fs.rmdirSync(dir)
|
|
209
|
+
} catch (e) { /* ignore */ }
|
|
210
|
+
}
|
|
211
|
+
} catch (e) { /* ignore */ }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
cleanupStaleTempDirs()
|
|
215
|
+
|
|
216
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), `pdraw-${process.pid}-`))
|
|
217
|
+
|
|
218
|
+
// 自定义工作流目录(Design.md A7:工作流文件由用户从 ComfyUI 导出后放入 data/p-draw/workflows/)
|
|
219
|
+
const workflowDir = path.join(ctx.baseDir || process.cwd(), 'data', 'p-draw', 'workflows')
|
|
179
220
|
try {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
221
|
+
fs.mkdirSync(workflowDir, { recursive: true })
|
|
222
|
+
} catch (e) {
|
|
223
|
+
logger.warn(`创建自定义工作流目录失败(${workflowDir}):${e.message}`)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 自定义工作流路径一律相对 Koishi 运行目录解析(见 lib/workflows.js)
|
|
227
|
+
const workflowOpts = () => ({ baseDir: ctx.baseDir || process.cwd() })
|
|
228
|
+
|
|
229
|
+
// A4:自定义工作流(Aesthetic 1.1)默认跳过质量前缀注入
|
|
230
|
+
function shouldSkipQualityPrefix() {
|
|
231
|
+
return Boolean(cfg.customWorkflowEnabled && cfg.skipQualityPrefixForCustomWorkflow)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// A7:自定义工作流启用且质量前缀非空时,提示用户质量标签可能不适用于 Aesthetic 模型
|
|
235
|
+
function qualityPrefixWarning() {
|
|
236
|
+
if (!cfg.customWorkflowEnabled) return ''
|
|
237
|
+
if (!String(cfg.qualityPrefix || '').trim()) return ''
|
|
238
|
+
return shouldSkipQualityPrefix()
|
|
239
|
+
? '检测到自定义工作流已启用,已自动跳过质量前缀注入;qualityPrefix 对 Aesthetic 模型不生效,建议手动置空。'
|
|
240
|
+
: '检测到自定义工作流已启用,qualityPrefix 可能不适用于 Aesthetic 模型,建议手动置空(或开启 skipQualityPrefixForCustomWorkflow)。'
|
|
241
|
+
}
|
|
189
242
|
|
|
190
243
|
const baseUrl = () => normalizeBaseUrl(cfg.comfyuiBaseUrl)
|
|
191
244
|
|
|
@@ -258,14 +311,21 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
258
311
|
payload.vram_total_mb = Math.round((device.vram_total || 0) / 1024 / 1024)
|
|
259
312
|
payload.vram_free_mb = Math.round((device.vram_free || 0) / 1024 / 1024)
|
|
260
313
|
if (objectInfo) {
|
|
261
|
-
|
|
314
|
+
// 主模型列表按实际使用的 loader 读取:GGUF 走 UnetLoaderGGUF,其余走 UNETLoader
|
|
315
|
+
const gguf = isGgufUnet(cfg)
|
|
316
|
+
const unetNode = gguf ? 'UnetLoaderGGUF' : 'UNETLoader'
|
|
317
|
+
const unetList = availableModels(objectInfo, unetNode, 'unet_name')
|
|
262
318
|
const clipList = availableModels(objectInfo, 'CLIPLoader', 'clip_name')
|
|
263
319
|
const vaeList = availableModels(objectInfo, 'VAELoader', 'vae_name')
|
|
320
|
+
payload.unet_loader = unetNode
|
|
321
|
+
payload.unet_loader_available = Boolean(objectInfo[unetNode])
|
|
264
322
|
payload.unet_available = unetList.includes(cfg.unetName)
|
|
265
323
|
payload.unet_models = unetList
|
|
266
324
|
payload.clip_available = clipList.includes(cfg.clipName)
|
|
267
325
|
payload.vae_available = vaeList.includes(cfg.vaeName)
|
|
268
326
|
} else {
|
|
327
|
+
payload.unet_loader = isGgufUnet(cfg) ? 'UnetLoaderGGUF' : 'UNETLoader'
|
|
328
|
+
payload.unet_loader_available = undefined
|
|
269
329
|
payload.unet_available = undefined
|
|
270
330
|
payload.clip_available = undefined
|
|
271
331
|
payload.vae_available = undefined
|
|
@@ -311,7 +371,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
311
371
|
`ComfyUI 状态:在线`,
|
|
312
372
|
`版本:${payload.comfyui_version || '未知'}`,
|
|
313
373
|
`GPU:${payload.gpu || '未知'}(显存 ${payload.vram_total_mb}MB / 空闲 ${payload.vram_free_mb}MB)`,
|
|
314
|
-
`主模型:${cfg.unetName} ${modelStatus(cfg.unetName, payload.unet_available)}
|
|
374
|
+
`主模型:${cfg.unetName} ${modelStatus(cfg.unetName, payload.unet_available)}(加载器 ${payload.unet_loader || (isGgufUnet(cfg) ? 'UnetLoaderGGUF' : 'UNETLoader')})`,
|
|
315
375
|
`文本编码器:${cfg.clipName} ${modelStatus(cfg.clipName, payload.clip_available)}`,
|
|
316
376
|
`VAE:${cfg.vaeName} ${modelStatus(cfg.vaeName, payload.vae_available)}`,
|
|
317
377
|
`可用尺寸:${payload.allowed_sizes.join('、')}`,
|
|
@@ -322,14 +382,48 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
322
382
|
return lines.join('\n')
|
|
323
383
|
}
|
|
324
384
|
|
|
385
|
+
// 自定义工作流的诊断明细:来源路径 / mtime / 实际解析到的节点 ID / 定位方式
|
|
386
|
+
function customWorkflowDiagLines() {
|
|
387
|
+
const lines = []
|
|
388
|
+
const report = inspectCustomWorkflow(cfg, workflowOpts())
|
|
389
|
+
if (!report.ok && !report.path) {
|
|
390
|
+
lines.push(`自定义工作流:读取失败 — ${report.error}`)
|
|
391
|
+
return lines
|
|
392
|
+
}
|
|
393
|
+
lines.push(`自定义工作流:${report.path}`)
|
|
394
|
+
if (report.mtimeMs) {
|
|
395
|
+
const stamp = new Date(report.mtimeMs)
|
|
396
|
+
lines.push(`工作流更新时间:${stamp.toLocaleString('zh-CN')}(${cfg.customWorkflowReloadOnChange === false ? '变更不自动重载' : '变更自动重载'})`)
|
|
397
|
+
}
|
|
398
|
+
if (!report.ok) {
|
|
399
|
+
lines.push(`自定义工作流:解析失败 — ${report.error}`)
|
|
400
|
+
return lines
|
|
401
|
+
}
|
|
402
|
+
const t = report.targets
|
|
403
|
+
const how = (configured, found) => (configured ? '配置指定' : (found ? '自动识别' : '自动识别(未找到)'))
|
|
404
|
+
const fmt = (ids) => (ids && ids.length ? ids.map(id => `#${id}`).join('、') : '(无)')
|
|
405
|
+
lines.push(`正面提示词节点:${fmt(t.positive)}(${how(cfg.positivePromptNodeId, t.positive.length)})`)
|
|
406
|
+
lines.push(`负面提示词节点:${fmt(t.negative)}(${how(cfg.negativePromptNodeId, t.negative.length)})`)
|
|
407
|
+
lines.push(`尺寸节点:${fmt(t.resolutionIds)}(${how(cfg.resolutionNodeId, t.resolutionIds.length)})`)
|
|
408
|
+
lines.push(`步数节点:${fmt(t.stepsIds)}(${how(cfg.stepsNodeId, t.stepsIds.length)})`)
|
|
409
|
+
lines.push(`种子节点:${fmt(t.seedIds)}(${how(cfg.seedNodeId, t.seedIds.length)})`)
|
|
410
|
+
lines.push(`识别的文本编码节点:${fmt(t.textNodes)}`)
|
|
411
|
+
return lines
|
|
412
|
+
}
|
|
413
|
+
|
|
325
414
|
async function diagnoseText(session) {
|
|
326
415
|
const payload = await statusPayload()
|
|
327
416
|
const lines = ['【p-draw 诊断】']
|
|
328
417
|
lines.push(`插件版本:${require('./package.json').version || '未知'}`)
|
|
329
418
|
lines.push(`ComfyUI 地址:${payload.base_url}`)
|
|
330
419
|
lines.push(`工作流:${cfg.customWorkflowEnabled ? '自定义 ' + (cfg.customWorkflowPath || '(未填写路径)') : (cfg.workflow || 'anima_t2i')}`)
|
|
420
|
+
if (cfg.customWorkflowEnabled) {
|
|
421
|
+
lines.push(...customWorkflowDiagLines())
|
|
422
|
+
}
|
|
331
423
|
lines.push(`模型:${cfg.unetName} / ${cfg.clipName} / ${cfg.vaeName}`)
|
|
424
|
+
lines.push(`主模型加载器:${payload.unet_loader || (isGgufUnet(cfg) ? 'UnetLoaderGGUF' : 'UNETLoader')}`)
|
|
332
425
|
lines.push(`默认尺寸:${cfg.width}x${cfg.height},步数 ${cfg.steps},CFG ${cfg.cfg},采样器 ${cfg.samplerName}/${cfg.scheduler}`)
|
|
426
|
+
lines.push(`质量前缀:${String(cfg.qualityPrefix || '').trim() ? '已配置' + (shouldSkipQualityPrefix() ? '(自定义工作流下已跳过)' : '') : '未配置(空)'}`)
|
|
333
427
|
lines.push(`队列:${cfg.queueEnabled ? '启用(上限 ' + (cfg.queueMaxRequests || '∞') + ')' : '关闭'}`)
|
|
334
428
|
lines.push(`P 点价格:${cfg.price}`)
|
|
335
429
|
lines.push(`权限:${cfg.adminOnly ? '仅管理员' : '开放'}`)
|
|
@@ -341,6 +435,9 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
341
435
|
lines.push(`版本:${payload.comfyui_version || '未知'}`)
|
|
342
436
|
lines.push(`GPU:${payload.gpu || '未知'}(显存 ${payload.vram_total_mb}MB / 空闲 ${payload.vram_free_mb}MB)`)
|
|
343
437
|
lines.push(`模型可用性:主模型${payload.unet_available === undefined ? '(未获取)' : payload.unet_available ? '✓' : '✗'} / 编码器${payload.clip_available === undefined ? '(未获取)' : payload.clip_available ? '✓' : '✗'} / VAE${payload.vae_available === undefined ? '(未获取)' : payload.vae_available ? '✓' : '✗'}`)
|
|
438
|
+
if (payload.unet_loader_available === false) {
|
|
439
|
+
lines.push(`加载器提示:ComfyUI 中没有 ${payload.unet_loader} 节点,请安装 ComfyUI-GGUF 插件,或把 useGgufUnet 设为 false 使用 safetensors 模型。`)
|
|
440
|
+
}
|
|
344
441
|
if (payload.unet_models && payload.unet_models.length) {
|
|
345
442
|
lines.push(`可选模型:\n${payload.unet_models.join('\n')}`)
|
|
346
443
|
}
|
|
@@ -351,6 +448,9 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
351
448
|
if (payload.object_info_warning) {
|
|
352
449
|
lines.push(`模型列表接口:${payload.object_info_warning}(不影响生图)`)
|
|
353
450
|
}
|
|
451
|
+
// A7:自定义工作流 + 非空 qualityPrefix 的迁移提示
|
|
452
|
+
const warning = qualityPrefixWarning()
|
|
453
|
+
if (warning) lines.push(`⚠ ${warning}`)
|
|
354
454
|
return lines.join('\n')
|
|
355
455
|
}
|
|
356
456
|
|
|
@@ -476,35 +576,35 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
476
576
|
const modelSeed = `当前模型:${unetName},--seed=${seeds.join(',')}`
|
|
477
577
|
if (isAdmin) return modelSeed
|
|
478
578
|
return `已扣除 ${totalPrice} P 点,${modelSeed}`
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function buildGenerationReply(session, { successCount, count, failures, notes = [] }) {
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function buildGenerationReply(session, { successCount, count, failures, notes = [] }) {
|
|
482
582
|
const reply = []
|
|
483
583
|
if (notes.length) reply.push(notes.join('\n'))
|
|
484
584
|
if (failures.length) reply.push(session.text('.batch-partial', [successCount, count, failures.length, failures.join(';')]))
|
|
485
|
-
return reply.filter(Boolean).join('\n')
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
function shouldOptimizePerImage({ count, enabled, admin }) {
|
|
489
|
-
return count > 1 && (enabled || admin)
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
async function sendNotices(session, notices, opts = {}) {
|
|
493
|
-
const content = notices.filter(Boolean).join('\n')
|
|
494
|
-
if (!content) return
|
|
495
|
-
try {
|
|
496
|
-
const quoteId = session.event?.message?.id || session.messageId
|
|
497
|
-
let message = content
|
|
498
|
-
if (opts.quote && quoteId) {
|
|
499
|
-
const quote = session.platform === 'onebot'
|
|
500
|
-
? h('reply', { id: quoteId })
|
|
501
|
-
: h.quote(quoteId)
|
|
502
|
-
message = quote + content
|
|
503
|
-
}
|
|
504
|
-
if (cfg.outputLogs && opts.quote) logger.info(`[p-draw] 发送扣费引用通知 platform=${session.platform || 'unknown'} messageId=${quoteId || 'missing'}`)
|
|
505
|
-
await session.send(message)
|
|
506
|
-
} catch (e) {
|
|
507
|
-
logger.warn(`发送反馈消息失败:${e.message}`)
|
|
585
|
+
return reply.filter(Boolean).join('\n')
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function shouldOptimizePerImage({ count, enabled, admin }) {
|
|
589
|
+
return count > 1 && (enabled || admin)
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
async function sendNotices(session, notices, opts = {}) {
|
|
593
|
+
const content = notices.filter(Boolean).join('\n')
|
|
594
|
+
if (!content) return
|
|
595
|
+
try {
|
|
596
|
+
const quoteId = session.event?.message?.id || session.messageId
|
|
597
|
+
let message = content
|
|
598
|
+
if (opts.quote && quoteId) {
|
|
599
|
+
const quote = session.platform === 'onebot'
|
|
600
|
+
? h('reply', { id: quoteId })
|
|
601
|
+
: h.quote(quoteId)
|
|
602
|
+
message = quote + content
|
|
603
|
+
}
|
|
604
|
+
if (cfg.outputLogs && opts.quote) logger.info(`[p-draw] 发送扣费引用通知 platform=${session.platform || 'unknown'} messageId=${quoteId || 'missing'}`)
|
|
605
|
+
await session.send(message)
|
|
606
|
+
} catch (e) {
|
|
607
|
+
logger.warn(`发送反馈消息失败:${e.message}`)
|
|
508
608
|
}
|
|
509
609
|
}
|
|
510
610
|
|
|
@@ -548,6 +648,8 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
548
648
|
const objectInfo = await getObjectInfoCached()
|
|
549
649
|
const list = [
|
|
550
650
|
...availableModels(objectInfo, 'UNETLoader', 'unet_name'),
|
|
651
|
+
// GGUF 模型(ComfyUI-GGUF)同样可供用户选择
|
|
652
|
+
...availableModels(objectInfo, 'UnetLoaderGGUF', 'unet_name'),
|
|
551
653
|
...availableModels(objectInfo, 'CheckpointLoaderSimple', 'ckpt_name')
|
|
552
654
|
.filter(name => String(name).trim().toLowerCase().replace(/[-_]/g, '~') === 'animagine~xl~3.1.safetensors'),
|
|
553
655
|
]
|
|
@@ -622,7 +724,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
622
724
|
const cfgVal = Number(overrides.cfg) || workCfg.cfg
|
|
623
725
|
const seed = Number(overrides.seed) || crypto.randomInt(1, 2 ** 32 - 1)
|
|
624
726
|
const negativePrompt = joinPromptParts([overrides.negativePrompt || cfg.negativePrompt || ''])
|
|
625
|
-
const promptBody = buildWorkflow(workCfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, Boolean(size))
|
|
727
|
+
const promptBody = buildWorkflow(workCfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, Boolean(size), workflowOpts())
|
|
626
728
|
|
|
627
729
|
const clientId = crypto.randomUUID()
|
|
628
730
|
const submit = await comfyPost('/prompt', { prompt: promptBody, client_id: clientId }, 20000)
|
|
@@ -873,7 +975,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
873
975
|
async function composePrompt(userPrompt, raw, fixedOverride) {
|
|
874
976
|
if (raw) return { prompt: userPrompt, degraded: false }
|
|
875
977
|
const parts = []
|
|
876
|
-
if (cfg.qualityPrefix) parts.push(String(cfg.qualityPrefix).trim())
|
|
978
|
+
if (cfg.qualityPrefix && !shouldSkipQualityPrefix()) parts.push(String(cfg.qualityPrefix).trim())
|
|
877
979
|
if (fixedOverride === 'skip') {
|
|
878
980
|
// 不注入固定角色 tags
|
|
879
981
|
} else if (typeof fixedOverride === 'string') {
|
|
@@ -1155,7 +1257,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1155
1257
|
// 组装最终提示词:质量词 + 画师组 + 主 tag 流(含角色外观)+ narrative 块(仅互动/站位)
|
|
1156
1258
|
const contentClean = cleanContentTags(commonContent, 65, false, [], true)
|
|
1157
1259
|
const parts = []
|
|
1158
|
-
if (cfg.qualityPrefix) parts.push(String(cfg.qualityPrefix).trim())
|
|
1260
|
+
if (cfg.qualityPrefix && !shouldSkipQualityPrefix()) parts.push(String(cfg.qualityPrefix).trim())
|
|
1159
1261
|
// 多人同样遵守 no artist 守卫(与单图一致):用户说「不要画师」时跳过画师 tags
|
|
1160
1262
|
const artistTags = resolveArtistTags(prompt)
|
|
1161
1263
|
if (artistTags) parts.push(artistTags)
|
|
@@ -1485,7 +1587,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1485
1587
|
unetName: unet,
|
|
1486
1588
|
seeds,
|
|
1487
1589
|
})
|
|
1488
|
-
if (!allOutputs.length) {
|
|
1590
|
+
if (!allOutputs.length) {
|
|
1489
1591
|
if (cfg.outputLogs) logger.warn(`多人生成全部失败(${USERID}),已按张退款`)
|
|
1490
1592
|
return session.text('.generate-failed', ['全部失败(已按张退款)'])
|
|
1491
1593
|
}
|
|
@@ -1500,7 +1602,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1500
1602
|
return buildGenerationReply(session, { successCount, count, failures, notes })
|
|
1501
1603
|
}
|
|
1502
1604
|
|
|
1503
|
-
// ---------------- 权限 ----------------
|
|
1605
|
+
// ---------------- 权限 ----------------
|
|
1504
1606
|
function readableOptimizeReason(reason) {
|
|
1505
1607
|
if (!reason) return ''
|
|
1506
1608
|
if (reason === 'llm_not_configured') return '(未配置 LLM 模型名或接口地址)'
|
|
@@ -1870,25 +1972,25 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1870
1972
|
if (!raw) {
|
|
1871
1973
|
const globalOpt = cfg.promptOptimizeEnabled
|
|
1872
1974
|
const adminOpt = !globalOpt && isAdmin && cfg.llmModel && cfg.llmBaseUrl
|
|
1873
|
-
const tokenOpt = !globalOpt && !isAdmin && cfg.llmModel && cfg.llmBaseUrl
|
|
1874
|
-
if (globalOpt) {
|
|
1875
|
-
if (shouldOptimizePerImage({ count, enabled: true, admin: false })) {
|
|
1876
|
-
perImageOptimize = true
|
|
1877
|
-
} else {
|
|
1878
|
-
const optimized = await optimizePrompt(session, userPrompt, false)
|
|
1879
|
-
finalPrompt = optimized.prompt
|
|
1880
|
-
degraded = !optimized.ok
|
|
1881
|
-
optimizedReason = optimized.reason || ''
|
|
1882
|
-
}
|
|
1883
|
-
} else if (adminOpt) {
|
|
1884
|
-
if (shouldOptimizePerImage({ count, enabled: false, admin: true })) {
|
|
1885
|
-
perImageOptimize = true
|
|
1886
|
-
} else {
|
|
1887
|
-
const optimized = await optimizePrompt(session, userPrompt, true)
|
|
1888
|
-
finalPrompt = optimized.prompt
|
|
1889
|
-
degraded = !optimized.ok
|
|
1890
|
-
optimizedReason = optimized.reason || ''
|
|
1891
|
-
}
|
|
1975
|
+
const tokenOpt = !globalOpt && !isAdmin && cfg.llmModel && cfg.llmBaseUrl
|
|
1976
|
+
if (globalOpt) {
|
|
1977
|
+
if (shouldOptimizePerImage({ count, enabled: true, admin: false })) {
|
|
1978
|
+
perImageOptimize = true
|
|
1979
|
+
} else {
|
|
1980
|
+
const optimized = await optimizePrompt(session, userPrompt, false)
|
|
1981
|
+
finalPrompt = optimized.prompt
|
|
1982
|
+
degraded = !optimized.ok
|
|
1983
|
+
optimizedReason = optimized.reason || ''
|
|
1984
|
+
}
|
|
1985
|
+
} else if (adminOpt) {
|
|
1986
|
+
if (shouldOptimizePerImage({ count, enabled: false, admin: true })) {
|
|
1987
|
+
perImageOptimize = true
|
|
1988
|
+
} else {
|
|
1989
|
+
const optimized = await optimizePrompt(session, userPrompt, true)
|
|
1990
|
+
finalPrompt = optimized.prompt
|
|
1991
|
+
degraded = !optimized.ok
|
|
1992
|
+
optimizedReason = optimized.reason || ''
|
|
1993
|
+
}
|
|
1892
1994
|
} else if (tokenOpt) {
|
|
1893
1995
|
// 全局优化关闭:使用 p-shop 的「提示词优化券」(p_system.llmToken)。
|
|
1894
1996
|
// 券一次性,按张数扣:x3 扣 3 张,每张图独立做一次 LLM 优化。
|
|
@@ -2021,7 +2123,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
2021
2123
|
unetName: unet,
|
|
2022
2124
|
seeds,
|
|
2023
2125
|
})
|
|
2024
|
-
if (!allOutputs.length) {
|
|
2126
|
+
if (!allOutputs.length) {
|
|
2025
2127
|
if (cfg.outputLogs) logger.warn(`生成全部失败(${USERID}),已按张退款`)
|
|
2026
2128
|
return session.text('.generate-failed', ['全部失败(已按张退款)'])
|
|
2027
2129
|
}
|
|
@@ -2034,7 +2136,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
2034
2136
|
await sendNotices(session, [chargeNotice])
|
|
2035
2137
|
|
|
2036
2138
|
return buildGenerationReply(session, { successCount, count, failures })
|
|
2037
|
-
}
|
|
2139
|
+
}
|
|
2038
2140
|
// ---------------- 提示词优化券交互式确认 ----------------
|
|
2039
2141
|
// 仅全局优化关闭 + 非管理员 + 已配置 LLM(tokenOpt 分支)时进入。
|
|
2040
2142
|
// 返回:{ cancelled, tokenUsedCount, perImageOptimize, noOptimizeReason }
|
|
@@ -2179,5 +2281,5 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
2179
2281
|
})
|
|
2180
2282
|
|
|
2181
2283
|
// 暴露内部接口供自动化测试调用(Koishi 忽略 apply 返回值,不影响生产行为)
|
|
2182
|
-
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch }
|
|
2183
|
-
}
|
|
2284
|
+
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch, composePrompt, shouldSkipQualityPrefix, qualityPrefixWarning, customWorkflowDiagLines, diagnoseText, workflowDir }
|
|
2285
|
+
}
|
package/lib/i18n.js
CHANGED
|
@@ -4,11 +4,18 @@ const zhCN = {
|
|
|
4
4
|
comfyuiBaseUrl: { $description: 'ComfyUI 地址' },
|
|
5
5
|
workflow: { $description: '工作流类型(内置 anima_t2i)' },
|
|
6
6
|
customWorkflowEnabled: { $description: '使用自定义 ComfyUI 工作流 JSON' },
|
|
7
|
-
customWorkflowPath: { $description: '自定义工作流 JSON
|
|
7
|
+
customWorkflowPath: { $description: '自定义工作流 JSON 路径(相对 Koishi 运行目录,例如 data/p-draw/workflows/anima-aesthetic-v1.1.json;插件目录作为回退)' },
|
|
8
8
|
customWorkflowOverrideParameters: { $description: '用插件参数覆盖自定义工作流参数' },
|
|
9
|
+
customWorkflowReloadOnChange: { $description: '工作流 JSON 变化时自动重载(无需重启插件)' },
|
|
10
|
+
positivePromptNodeId: { $description: '自定义工作流中正面提示词节点 ID(留空自动识别;示例 6,以实际 JSON 为准)' },
|
|
11
|
+
negativePromptNodeId: { $description: '自定义工作流中负面提示词节点 ID(留空自动识别;示例 7,以实际 JSON 为准)' },
|
|
12
|
+
resolutionNodeId: { $description: '自定义工作流中尺寸节点 ID(EmptyLatentImage,可留空;示例 5)' },
|
|
13
|
+
seedNodeId: { $description: '自定义工作流中种子节点 ID(KSampler,可留空;示例 3)' },
|
|
14
|
+
stepsNodeId: { $description: '自定义工作流中步数节点 ID(KSampler,可留空;示例 3)' },
|
|
9
15
|
timeout: { $description: '单次生成超时(秒)' },
|
|
10
16
|
pollInterval: { $description: '生成状态查询间隔(秒)' },
|
|
11
|
-
unetName: { $description: '
|
|
17
|
+
unetName: { $description: '主模型文件名(8G 显存推荐 GGUF Q8_0 版,插件会自动改用 UnetLoaderGGUF 加载)' },
|
|
18
|
+
useGgufUnet: { $description: '主模型加载方式(auto 按文件名判断 / true 强制 GGUF / false 强制 safetensors)' },
|
|
12
19
|
clipName: { $description: '文本编码器文件名' },
|
|
13
20
|
vaeName: { $description: 'VAE 文件名' },
|
|
14
21
|
width: { $description: '默认宽度' },
|
|
@@ -18,8 +25,9 @@ const zhCN = {
|
|
|
18
25
|
cfg: { $description: 'CFG 强度' },
|
|
19
26
|
samplerName: { $description: '采样器' },
|
|
20
27
|
scheduler: { $description: '调度器' },
|
|
21
|
-
qualityPrefix: { $description: '
|
|
22
|
-
|
|
28
|
+
qualityPrefix: { $description: '质量词前缀(使用 Aesthetic 1.1 时建议留空;Base 模型可填 masterpiece, best quality, score_7)' },
|
|
29
|
+
skipQualityPrefixForCustomWorkflow: { $description: '启用自定义工作流时自动跳过质量前缀注入(Aesthetic 模型不需要质量标签)' },
|
|
30
|
+
negativePrompt: { $description: '负面提示词(Aesthetic 1.1 推荐值)' },
|
|
23
31
|
promptOptimizeEnabled: { $description: '启用自然语言优化(需要配置下方 LLM 接口)' },
|
|
24
32
|
llmBaseUrl: { $description: 'LLM 接口地址(OpenAI 兼容,例如 https://api.deepseek.com/v1)' },
|
|
25
33
|
llmApiKey: { $description: 'LLM API Key' },
|
package/lib/workflows.js
CHANGED
|
@@ -1,169 +1,404 @@
|
|
|
1
|
-
// ComfyUI 工作流构建(移植自 anima comfyui_workflows)。
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
1
|
+
// ComfyUI 工作流构建(移植自 anima comfyui_workflows)。
|
|
2
|
+
// 纯函数 + fs:内置 Anima / Animagine 图,以及用户导出的自定义工作流 JSON 注入。
|
|
3
|
+
//
|
|
4
|
+
// 自定义工作流的「工作流准备」分层(Design.md A1/A3/A7):
|
|
5
|
+
// 1) resolveCustomWorkflowPath 路径解析(Koishi baseDir 优先,插件目录回退)
|
|
6
|
+
// 2) readCustomWorkflowBody 读取 + 按 mtime/size 缓存(支持 customWorkflowReloadOnChange 热重载)
|
|
7
|
+
// 3) resolveCustomNodeTargets 节点定位(显式配置 ID 优先,结构反查回退)
|
|
8
|
+
// 4) customWorkflow 注入提示词 / 尺寸 / 采样参数 / seed
|
|
9
|
+
//
|
|
10
|
+
// 约束:代码中不硬编码任何节点 ID。节点 ID 始终来自配置或工作流结构本身(A7)。
|
|
11
|
+
|
|
12
|
+
const fs = require('fs')
|
|
13
|
+
const path = require('path')
|
|
14
|
+
|
|
15
|
+
// ------------------------------------------------------------------
|
|
16
|
+
// 主模型 loader 选择(Design.md A2:8G 显存推荐 GGUF Q8_0)
|
|
17
|
+
// ------------------------------------------------------------------
|
|
18
|
+
// useGgufUnet: 'auto'(按文件名后缀)/ 'true' / 'false'
|
|
19
|
+
function isGgufUnet(cfg) {
|
|
20
|
+
const mode = String((cfg && cfg.useGgufUnet) || 'auto').trim().toLowerCase()
|
|
21
|
+
if (['true', 'yes', 'on', '1', 'gguf'].includes(mode)) return true
|
|
22
|
+
if (['false', 'no', 'off', '0', 'safetensors'].includes(mode)) return false
|
|
23
|
+
return /\.gguf$/i.test(String((cfg && cfg.unetName) || '').trim())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// GGUF 走 ComfyUI-GGUF 的 UnetLoaderGGUF,其余走原生 UNETLoader。
|
|
27
|
+
function unetLoaderNode(cfg) {
|
|
28
|
+
if (isGgufUnet(cfg)) {
|
|
29
|
+
return { class_type: 'UnetLoaderGGUF', inputs: { unet_name: cfg.unetName } }
|
|
30
|
+
}
|
|
31
|
+
return { class_type: 'UNETLoader', inputs: { unet_name: cfg.unetName, weight_dtype: 'fp8_e4m3fn' } }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ------------------------------------------------------------------
|
|
35
|
+
// 内置工作流
|
|
36
|
+
// ------------------------------------------------------------------
|
|
37
|
+
function animaT2IWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVal, seed) {
|
|
38
|
+
return {
|
|
39
|
+
'44': unetLoaderNode(cfg),
|
|
40
|
+
'45': { class_type: 'CLIPLoader', inputs: { clip_name: cfg.clipName, type: 'stable_diffusion', device: 'default' } },
|
|
41
|
+
'15': { class_type: 'VAELoader', inputs: { vae_name: cfg.vaeName } },
|
|
42
|
+
'28': { class_type: 'EmptyLatentImage', inputs: { width, height, batch_size: 1 } },
|
|
43
|
+
'11': { class_type: 'CLIPTextEncode', inputs: { text: prompt, clip: ['45', 0] } },
|
|
44
|
+
'12': { class_type: 'CLIPTextEncode', inputs: { text: negativePrompt, clip: ['45', 0] } },
|
|
45
|
+
'19': {
|
|
46
|
+
class_type: 'KSampler',
|
|
47
|
+
inputs: {
|
|
48
|
+
model: ['44', 0],
|
|
49
|
+
positive: ['11', 0],
|
|
50
|
+
negative: ['12', 0],
|
|
51
|
+
latent_image: ['28', 0],
|
|
52
|
+
seed,
|
|
53
|
+
steps,
|
|
54
|
+
cfg: cfgVal,
|
|
55
|
+
sampler_name: cfg.samplerName,
|
|
56
|
+
scheduler: cfg.scheduler,
|
|
57
|
+
denoise: 1,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
'8': { class_type: 'VAEDecodeTiled', inputs: { samples: ['19', 0], vae: ['15', 0], tile_size: 512, overlap: 64, temporal_size: 64, temporal_overlap: 8 } },
|
|
61
|
+
'9': { class_type: 'SaveImage', inputs: { images: ['8', 0], filename_prefix: 'pdraw/anm' } },
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function animagineT2IWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVal, seed) {
|
|
66
|
+
return {
|
|
67
|
+
'4': { class_type: 'CheckpointLoaderSimple', inputs: { ckpt_name: cfg.unetName } },
|
|
68
|
+
'5': { class_type: 'EmptyLatentImage', inputs: { width, height, batch_size: 1 } },
|
|
69
|
+
'6': { class_type: 'CLIPTextEncode', inputs: { text: prompt, clip: ['4', 1] } },
|
|
70
|
+
'7': { class_type: 'CLIPTextEncode', inputs: { text: negativePrompt, clip: ['4', 1] } },
|
|
71
|
+
'3': {
|
|
72
|
+
class_type: 'KSampler',
|
|
73
|
+
inputs: {
|
|
74
|
+
model: ['4', 0],
|
|
75
|
+
positive: ['6', 0],
|
|
76
|
+
negative: ['7', 0],
|
|
77
|
+
latent_image: ['5', 0],
|
|
78
|
+
seed,
|
|
79
|
+
steps,
|
|
80
|
+
cfg: cfgVal,
|
|
81
|
+
sampler_name: cfg.samplerName,
|
|
82
|
+
scheduler: cfg.scheduler,
|
|
83
|
+
denoise: 1,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
'8': { class_type: 'VAEDecode', inputs: { samples: ['3', 0], vae: ['4', 2] } },
|
|
87
|
+
'9': { class_type: 'SaveImage', inputs: { images: ['8', 0], filename_prefix: 'pdraw/animagine' } },
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ------------------------------------------------------------------
|
|
92
|
+
// 1) 路径解析
|
|
93
|
+
// ------------------------------------------------------------------
|
|
94
|
+
// A5 的 customWorkflowPath 形如 "data/p-draw/workflows/anima-aesthetic-v1.1.json",
|
|
95
|
+
// 相对 Koishi 的 baseDir(即运行目录)而不是插件目录,因此 baseDir 优先、插件目录回退。
|
|
96
|
+
function resolveCustomWorkflowPath(cfg, opts = {}) {
|
|
97
|
+
const raw = String((cfg && cfg.customWorkflowPath) || '').trim()
|
|
98
|
+
if (!raw) throw new Error('自定义工作流路径为空,请填写 customWorkflowPath')
|
|
99
|
+
if (path.isAbsolute(raw)) {
|
|
100
|
+
if (!fs.existsSync(raw)) throw new Error(`自定义工作流文件不存在:${raw}`)
|
|
101
|
+
return raw
|
|
102
|
+
}
|
|
103
|
+
const candidates = []
|
|
104
|
+
if (opts.baseDir) candidates.push(path.resolve(opts.baseDir, raw))
|
|
105
|
+
candidates.push(path.resolve(__dirname, '..', raw))
|
|
106
|
+
for (const candidate of candidates) {
|
|
107
|
+
if (fs.existsSync(candidate)) return candidate
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`自定义工作流文件不存在。已查找:\n${candidates.map(c => ' ' + c).join('\n')}`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ------------------------------------------------------------------
|
|
113
|
+
// 2) 读取 + 缓存(customWorkflowReloadOnChange 热重载)
|
|
114
|
+
// ------------------------------------------------------------------
|
|
115
|
+
const workflowFileCache = new Map() // absPath -> { mtimeMs, size, body }
|
|
116
|
+
|
|
117
|
+
function readCustomWorkflowBody(absPath, reloadOnChange) {
|
|
118
|
+
let stat
|
|
119
|
+
try {
|
|
120
|
+
stat = fs.statSync(absPath)
|
|
121
|
+
} catch (e) {
|
|
122
|
+
throw new Error(`自定义工作流读取失败:${e.message}`)
|
|
123
|
+
}
|
|
124
|
+
const cached = workflowFileCache.get(absPath)
|
|
125
|
+
const fresh = cached && (!reloadOnChange || (cached.mtimeMs === stat.mtimeMs && cached.size === stat.size))
|
|
126
|
+
if (fresh) return cached.body
|
|
127
|
+
|
|
128
|
+
let body
|
|
129
|
+
try {
|
|
130
|
+
body = JSON.parse(fs.readFileSync(absPath, 'utf-8'))
|
|
131
|
+
} catch (e) {
|
|
132
|
+
throw new Error(`自定义工作流加载失败:${e.message}`)
|
|
133
|
+
}
|
|
134
|
+
// 兼容「导出为 API 格式」的文件:内容包在 { prompt: {...} } 里
|
|
135
|
+
const graph = body && typeof body === 'object' && body.prompt && typeof body.prompt === 'object' ? body.prompt : body
|
|
136
|
+
if (!graph || typeof graph !== 'object' || Array.isArray(graph)) {
|
|
137
|
+
throw new Error('自定义工作流 JSON 无效:顶层不是节点表')
|
|
138
|
+
}
|
|
139
|
+
workflowFileCache.set(absPath, { mtimeMs: stat.mtimeMs, size: stat.size, body: graph })
|
|
140
|
+
return graph
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function clearWorkflowCache() {
|
|
144
|
+
workflowFileCache.clear()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ------------------------------------------------------------------
|
|
148
|
+
// 3) 节点定位
|
|
149
|
+
// ------------------------------------------------------------------
|
|
150
|
+
function cleanNodeId(value) {
|
|
151
|
+
const text = String(value == null ? '' : value).trim().replace(/^#/, '')
|
|
152
|
+
return text
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function nodeLabel(workflow, id) {
|
|
156
|
+
const node = workflow[id]
|
|
157
|
+
if (!node || typeof node !== 'object') return `#${id}(不存在)`
|
|
158
|
+
const title = node._meta && node._meta.title
|
|
159
|
+
return `#${id} [${node.class_type || '未知'}${title ? ' / ' + title : ''}]`
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 所有「带 text 输入的文本编码节点」,用于提示词注入与报错提示
|
|
163
|
+
function collectTextNodeIds(workflow) {
|
|
164
|
+
const ids = []
|
|
165
|
+
for (const [nodeId, node] of Object.entries(workflow)) {
|
|
166
|
+
if (!node || typeof node !== 'object') continue
|
|
167
|
+
const classType = String(node.class_type || '')
|
|
168
|
+
const inputs = node.inputs
|
|
169
|
+
if (classType.includes('TextEncode') && inputs && typeof inputs.text === 'string') {
|
|
170
|
+
ids.push(String(nodeId))
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return ids
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function findNodesByClass(workflow, classTypes) {
|
|
177
|
+
const wanted = new Set(classTypes)
|
|
178
|
+
const ids = []
|
|
179
|
+
for (const [nodeId, node] of Object.entries(workflow)) {
|
|
180
|
+
if (node && typeof node === 'object' && wanted.has(String(node.class_type || ''))) ids.push(String(nodeId))
|
|
181
|
+
}
|
|
182
|
+
return ids
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 从 KSampler 的 positive/negative 入口沿连线反查,找到真正的文本编码节点
|
|
186
|
+
function conditioningTextNodeIds(workflow, inputName, textNodes) {
|
|
187
|
+
const pending = []
|
|
188
|
+
for (const node of Object.values(workflow)) {
|
|
189
|
+
if (!node || typeof node !== 'object') continue
|
|
190
|
+
if (!['KSampler', 'KSamplerAdvanced'].includes(String(node.class_type || ''))) continue
|
|
191
|
+
const link = node.inputs && node.inputs[inputName]
|
|
192
|
+
if (Array.isArray(link) && link.length) pending.push(String(link[0]))
|
|
193
|
+
}
|
|
194
|
+
const found = []
|
|
195
|
+
const visited = new Set()
|
|
196
|
+
while (pending.length) {
|
|
197
|
+
const nodeId = pending.pop()
|
|
198
|
+
if (visited.has(nodeId)) continue
|
|
199
|
+
visited.add(nodeId)
|
|
200
|
+
if (textNodes.includes(nodeId)) {
|
|
201
|
+
found.push(nodeId)
|
|
202
|
+
continue
|
|
203
|
+
}
|
|
204
|
+
const node = workflow[nodeId]
|
|
205
|
+
const inputs = node && node.inputs
|
|
206
|
+
if (!inputs || typeof inputs !== 'object') continue
|
|
207
|
+
for (const value of Object.values(inputs)) {
|
|
208
|
+
if (Array.isArray(value) && value.length) {
|
|
209
|
+
const sourceId = String(value[0])
|
|
210
|
+
if (workflow[sourceId]) pending.push(sourceId)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return found
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// 解析自定义工作流中真正要写入的节点集合。
|
|
218
|
+
// 显式配置(positivePromptNodeId 等)优先;留空则按结构反查。ID 不存在时给出可用节点提示。
|
|
219
|
+
function resolveCustomNodeTargets(workflow, cfg = {}) {
|
|
220
|
+
const textNodes = collectTextNodeIds(workflow)
|
|
221
|
+
const errors = []
|
|
222
|
+
const explicitPositive = cleanNodeId(cfg.positivePromptNodeId)
|
|
223
|
+
const explicitNegative = cleanNodeId(cfg.negativePromptNodeId)
|
|
224
|
+
|
|
225
|
+
function resolveTextNode(explicit, inputName, label) {
|
|
226
|
+
if (!explicit) return conditioningTextNodeIds(workflow, inputName, textNodes)
|
|
227
|
+
const available = textNodes.map(id => nodeLabel(workflow, id)).join('\n ') || '(无)'
|
|
228
|
+
if (!workflow[explicit]) {
|
|
229
|
+
errors.push(`配置的${label}节点 ID「${explicit}」不存在于工作流中。可用文本编码节点:\n ${available}`)
|
|
230
|
+
return []
|
|
231
|
+
}
|
|
232
|
+
if (!textNodes.includes(explicit)) {
|
|
233
|
+
errors.push(`配置的${label}节点 ID「${explicit}」不是文本编码节点(${nodeLabel(workflow, explicit)})。可用文本编码节点:\n ${available}`)
|
|
234
|
+
return []
|
|
235
|
+
}
|
|
236
|
+
return [explicit]
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let positive = resolveTextNode(explicitPositive, 'positive', '正面提示词')
|
|
240
|
+
let negative = resolveTextNode(explicitNegative, 'negative', '负面提示词')
|
|
241
|
+
|
|
242
|
+
// 显式配置优先:自动反查结果不得抢占已被显式指定的节点
|
|
243
|
+
if (explicitPositive) negative = negative.filter(id => id !== explicitPositive)
|
|
244
|
+
if (explicitNegative) positive = positive.filter(id => id !== explicitNegative)
|
|
245
|
+
|
|
246
|
+
if (!positive.length && !errors.length) errors.push('自定义工作流中找不到正面提示词节点')
|
|
247
|
+
if (!negative.length && !errors.length) errors.push('自定义工作流中找不到负面提示词节点')
|
|
248
|
+
if (positive.length && negative.length && positive.some(id => negative.includes(id))) {
|
|
249
|
+
errors.push('自定义工作流正负面节点有歧义,请在配置中显式填写 positivePromptNodeId / negativePromptNodeId')
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// 尺寸节点:显式指定则只改该节点,否则改所有 EmptyLatentImage
|
|
253
|
+
const explicitResolution = cleanNodeId(cfg.resolutionNodeId)
|
|
254
|
+
let resolutionIds = []
|
|
255
|
+
if (explicitResolution) {
|
|
256
|
+
if (!workflow[explicitResolution]) {
|
|
257
|
+
errors.push(`配置的尺寸节点 ID「${explicitResolution}」不存在于工作流中。可能是:\n ${findNodesByClass(workflow, ['EmptyLatentImage']).map(id => nodeLabel(workflow, id)).join('\n ') || '(无)'}`)
|
|
258
|
+
} else {
|
|
259
|
+
resolutionIds = [explicitResolution]
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
resolutionIds = findNodesByClass(workflow, ['EmptyLatentImage'])
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// 采样节点:显式指定则只改该节点,否则改所有 KSampler
|
|
266
|
+
const samplerClasses = ['KSampler', 'KSamplerAdvanced']
|
|
267
|
+
const explicitSteps = cleanNodeId(cfg.stepsNodeId)
|
|
268
|
+
let stepsIds = []
|
|
269
|
+
if (explicitSteps) {
|
|
270
|
+
if (!workflow[explicitSteps]) {
|
|
271
|
+
errors.push(`配置的步数节点 ID「${explicitSteps}」不存在于工作流中。可能是:\n ${findNodesByClass(workflow, samplerClasses).map(id => nodeLabel(workflow, id)).join('\n ') || '(无)'}`)
|
|
272
|
+
} else {
|
|
273
|
+
stepsIds = [explicitSteps]
|
|
274
|
+
}
|
|
275
|
+
} else {
|
|
276
|
+
stepsIds = findNodesByClass(workflow, samplerClasses)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// seed 节点:显式指定则只改该节点,否则改所有带 seed / noise_seed 输入的节点
|
|
280
|
+
const explicitSeed = cleanNodeId(cfg.seedNodeId)
|
|
281
|
+
let seedIds = []
|
|
282
|
+
if (explicitSeed) {
|
|
283
|
+
if (!workflow[explicitSeed]) {
|
|
284
|
+
errors.push(`配置的种子节点 ID「${explicitSeed}」不存在于工作流中。可能是:\n ${findNodesByClass(workflow, samplerClasses).map(id => nodeLabel(workflow, id)).join('\n ') || '(无)'}`)
|
|
285
|
+
} else {
|
|
286
|
+
seedIds = [explicitSeed]
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
seedIds = Object.entries(workflow)
|
|
290
|
+
.filter(([, node]) => node && typeof node === 'object' && node.inputs && typeof node.inputs === 'object'
|
|
291
|
+
&& ('seed' in node.inputs || 'noise_seed' in node.inputs))
|
|
292
|
+
.map(([id]) => String(id))
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return { positive, negative, resolutionIds, stepsIds, seedIds, textNodes, errors }
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ------------------------------------------------------------------
|
|
299
|
+
// 4) 注入
|
|
300
|
+
// ------------------------------------------------------------------
|
|
301
|
+
function customWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, explicitSize, opts = {}) {
|
|
302
|
+
const absPath = resolveCustomWorkflowPath(cfg, opts)
|
|
303
|
+
// 默认热重载(A6:换 JSON 无需重启插件)
|
|
304
|
+
const reloadOnChange = cfg.customWorkflowReloadOnChange !== false
|
|
305
|
+
const body = readCustomWorkflowBody(absPath, reloadOnChange)
|
|
306
|
+
|
|
307
|
+
// 深拷贝后再改,缓存里的原始节点表不被污染
|
|
308
|
+
const workflow = JSON.parse(JSON.stringify(body))
|
|
309
|
+
|
|
310
|
+
const targets = resolveCustomNodeTargets(workflow, cfg)
|
|
311
|
+
if (targets.errors.length) throw new Error(targets.errors.join('\n'))
|
|
312
|
+
|
|
313
|
+
for (const nodeId of targets.positive) {
|
|
314
|
+
if (workflow[nodeId] && workflow[nodeId].inputs) workflow[nodeId].inputs.text = prompt
|
|
315
|
+
}
|
|
316
|
+
for (const nodeId of targets.negative) {
|
|
317
|
+
if (workflow[nodeId] && workflow[nodeId].inputs) workflow[nodeId].inputs.text = negativePrompt
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const override = Boolean(cfg.customWorkflowOverrideParameters)
|
|
321
|
+
const resolutionSet = new Set(targets.resolutionIds)
|
|
322
|
+
const stepsSet = new Set(targets.stepsIds)
|
|
323
|
+
const seedSet = new Set(targets.seedIds)
|
|
324
|
+
|
|
325
|
+
for (const [nodeId, node] of Object.entries(workflow)) {
|
|
326
|
+
if (!node || typeof node !== 'object') continue
|
|
327
|
+
const classType = String(node.class_type || '')
|
|
328
|
+
const inputs = node.inputs
|
|
329
|
+
if (!inputs || typeof inputs !== 'object') continue
|
|
330
|
+
if (classType === 'SaveImage' && 'filename_prefix' in inputs) {
|
|
331
|
+
inputs.filename_prefix = 'pdraw/anm'
|
|
332
|
+
}
|
|
333
|
+
// 尺寸:配置了 customWorkflowOverrideParameters,或用户显式指定了尺寸时覆盖
|
|
334
|
+
if ((override || explicitSize) && resolutionSet.has(nodeId)) {
|
|
335
|
+
if ('width' in inputs) inputs.width = width
|
|
336
|
+
if ('height' in inputs) inputs.height = height
|
|
337
|
+
}
|
|
338
|
+
if (override && stepsSet.has(nodeId)) {
|
|
339
|
+
if ('steps' in inputs) inputs.steps = steps
|
|
340
|
+
if ('cfg' in inputs) inputs.cfg = cfgVal
|
|
341
|
+
if (cfg.samplerName && 'sampler_name' in inputs) inputs.sampler_name = cfg.samplerName
|
|
342
|
+
if (cfg.scheduler && 'scheduler' in inputs) inputs.scheduler = cfg.scheduler
|
|
343
|
+
}
|
|
344
|
+
if (seedSet.has(nodeId)) {
|
|
345
|
+
if ('seed' in inputs) inputs.seed = seed
|
|
346
|
+
if ('noise_seed' in inputs) inputs.noise_seed = seed
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return workflow
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// 只读检查:供「p-draw 诊断」报告工作流来源与实际解析到的节点,不生成图片
|
|
353
|
+
function inspectCustomWorkflow(cfg, opts = {}) {
|
|
354
|
+
const report = { ok: false, path: '', mtimeMs: null, targets: null, textNodes: [], error: '' }
|
|
355
|
+
try {
|
|
356
|
+
const absPath = resolveCustomWorkflowPath(cfg, opts)
|
|
357
|
+
report.path = absPath
|
|
358
|
+
try { report.mtimeMs = fs.statSync(absPath).mtimeMs } catch (e) { /* ignore */ }
|
|
359
|
+
const body = readCustomWorkflowBody(absPath, cfg.customWorkflowReloadOnChange !== false)
|
|
360
|
+
const workflow = JSON.parse(JSON.stringify(body))
|
|
361
|
+
const targets = resolveCustomNodeTargets(workflow, cfg)
|
|
362
|
+
report.targets = targets
|
|
363
|
+
report.textNodes = targets.textNodes
|
|
364
|
+
if (targets.errors.length) {
|
|
365
|
+
report.error = targets.errors.join(';')
|
|
366
|
+
return report
|
|
367
|
+
}
|
|
368
|
+
report.ok = true
|
|
369
|
+
return report
|
|
370
|
+
} catch (e) {
|
|
371
|
+
report.error = String(e && e.message || e)
|
|
372
|
+
return report
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function buildWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, explicitSize, opts = {}) {
|
|
377
|
+
if (cfg.customWorkflowEnabled && cfg.customWorkflowPath) {
|
|
378
|
+
return customWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, explicitSize, opts)
|
|
379
|
+
}
|
|
380
|
+
const normalizedModel = String(cfg.unetName || '').trim().toLowerCase().replace(/[-_]/g, '~')
|
|
381
|
+
if (normalizedModel === 'animagine~xl~3.1.safetensors') {
|
|
382
|
+
return animagineT2IWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVal, seed)
|
|
383
|
+
}
|
|
384
|
+
return animaT2IWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVal, seed)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
module.exports = {
|
|
388
|
+
isGgufUnet,
|
|
389
|
+
unetLoaderNode,
|
|
390
|
+
animaT2IWorkflow,
|
|
391
|
+
animagineT2IWorkflow,
|
|
392
|
+
resolveCustomWorkflowPath,
|
|
393
|
+
readCustomWorkflowBody,
|
|
394
|
+
clearWorkflowCache,
|
|
395
|
+
cleanNodeId,
|
|
396
|
+
nodeLabel,
|
|
397
|
+
collectTextNodeIds,
|
|
398
|
+
findNodesByClass,
|
|
399
|
+
buildWorkflow,
|
|
400
|
+
customWorkflow,
|
|
401
|
+
conditioningTextNodeIds,
|
|
402
|
+
resolveCustomNodeTargets,
|
|
403
|
+
inspectCustomWorkflow,
|
|
404
|
+
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -16,12 +16,12 @@ p点-绘图插件,连接本地 ComfyUI 生图,参考 AstrBot 的 [anima 绘
|
|
|
16
16
|
- **用户自选模型**:`p-draw 模型` 查看当前与可用模型(自动读取 ComfyUI 的 UNET 和 Animagine checkpoint),`p-draw 模型 <名称>` 切换(支持模糊匹配,如 `anima-aesthetic`),`p-draw 模型 默认` 恢复默认。偏好按用户保存(`p_draw_config.user_models`),单人和多人生成都会生效;未自选时用 `unetName` 默认模型。自定义工作流(`customWorkflowEnabled`)不参与模型切换。
|
|
17
17
|
- **Animagine XL 3.1**:将模型文件放入 ComfyUI 的 checkpoints 目录后,用 `p-draw 模型 animagine` 选择。该模型使用 SDXL Danbooru/tag 文生图工作流,并复用 `promptOptimizeTemplate`。
|
|
18
18
|
- 画师组保存在数据库 `p_draw_config` 表中;固定角色保存在 `p_draw_fixed_characters` 表中,每个角色一行。管理指令不触发插件重载(不会打断正在生成的图,也不会把配置恢复成默认)。旧版 `fixedCharacters` 配置会在启动时迁入角色表。
|
|
19
|
-
- 自定义 ComfyUI 工作流 JSON
|
|
19
|
+
- 自定义 ComfyUI 工作流 JSON(对接 Anima Aesthetic 1.1 Text-to-Image Baseline,见下方「工作流对接」)。
|
|
20
20
|
- 生成队列(逐张顺序执行,防止争抢 GPU)。
|
|
21
21
|
- `p-draw 状态` 查看 ComfyUI 连接状态与模型可用性。
|
|
22
22
|
- `p-draw help`(或 `帮助`)查看全部指令帮助,包含生成 / 多人 / 批量张数 / 尺寸 / 画师组 / 状态等。
|
|
23
|
-
- 发图时会以合并转发发送,每张图片后附对应的 Positive / Negative 提示词;生成完成消息会显示实际模型和 seed(如 `已扣除 750 P 点,当前模型:animagine-xl-3.1.safetensors,--seed=123456`)。管理员/免扣费用户不显示扣费金额,但仍显示模型和 seed。
|
|
24
|
-
- 批量生成(如 `x5` / `x10`)开启 LLM 优化时,每张图会在生成前单独重新优化一次提示词;因此 `random color hair`、`random color eyes` 等动态要求可以在不同图片中产生不同结果。
|
|
23
|
+
- 发图时会以合并转发发送,每张图片后附对应的 Positive / Negative 提示词;生成完成消息会显示实际模型和 seed(如 `已扣除 750 P 点,当前模型:animagine-xl-3.1.safetensors,--seed=123456`)。管理员/免扣费用户不显示扣费金额,但仍显示模型和 seed。
|
|
24
|
+
- 批量生成(如 `x5` / `x10`)开启 LLM 优化时,每张图会在生成前单独重新优化一次提示词;因此 `random color hair`、`random color eyes` 等动态要求可以在不同图片中产生不同结果。
|
|
25
25
|
|
|
26
26
|
## 安装
|
|
27
27
|
|
|
@@ -31,7 +31,7 @@ p点-绘图插件,连接本地 ComfyUI 生图,参考 AstrBot 的 [anima 绘
|
|
|
31
31
|
plugins:
|
|
32
32
|
p-draw:
|
|
33
33
|
comfyuiBaseUrl: http://127.0.0.1:8188
|
|
34
|
-
unetName:
|
|
34
|
+
unetName: anima-aesthetic-v1.1.safetensors
|
|
35
35
|
clipName: qwen_3_06b_base.safetensors
|
|
36
36
|
vaeName: qwen_image_vae.safetensors
|
|
37
37
|
price: 500
|
|
@@ -66,11 +66,16 @@ plugins:
|
|
|
66
66
|
|----|------|
|
|
67
67
|
| `comfyuiBaseUrl` | ComfyUI API 地址(默认 `http://127.0.0.1:8188`) |
|
|
68
68
|
| `unetName` / `clipName` / `vaeName` | 模型文件名,需与 ComfyUI 下拉框中的文件名一致 |
|
|
69
|
+
| `useGgufUnet` | 主模型加载方式:`auto`(按文件名后缀判断,默认)/ `true`(强制 `UnetLoaderGGUF`,需装 ComfyUI-GGUF)/ `false`(强制 `UNETLoader`) |
|
|
69
70
|
| `modelParams` | 每个模型独立参数覆盖(字典):`key`=模型文件名,`value`=要覆盖的 `samplerName` / `scheduler` / `steps` / `cfg` / `width` / `height`。让不同模型用各自最佳采样参数,只填需要覆盖的字段,命令级 `--steps`/`--cfg` 仍优先 |
|
|
70
|
-
| `customWorkflowEnabled` / `customWorkflowPath` | 使用自定义工作流 JSON
|
|
71
|
+
| `customWorkflowEnabled` / `customWorkflowPath` | 使用自定义工作流 JSON;路径相对 Koishi 运行目录解析(插件目录作为回退) |
|
|
72
|
+
| `customWorkflowReloadOnChange` | 工作流 JSON 变化时自动重载,无需重启插件(默认 `true`) |
|
|
73
|
+
| `positivePromptNodeId` / `negativePromptNodeId` | 自定义工作流中正/负面提示词节点 ID;留空自动识别 |
|
|
74
|
+
| `resolutionNodeId` / `seedNodeId` / `stepsNodeId` | 自定义工作流中尺寸 / 种子 / 步数节点 ID;可留空(留空则按节点类型批量覆盖) |
|
|
75
|
+
| `skipQualityPrefixForCustomWorkflow` | 启用自定义工作流时自动跳过质量前缀注入(默认 `true`) |
|
|
71
76
|
| `width` / `height` / `allowedSizes` | 默认尺寸与可用尺寸列表 |
|
|
72
77
|
| `steps` / `cfg` / `samplerName` / `scheduler` | 采样参数 |
|
|
73
|
-
| `qualityPrefix` / `negativePrompt` |
|
|
78
|
+
| `qualityPrefix` / `negativePrompt` | 质量词前缀与负面提示词。默认 `qualityPrefix` 为空(Aesthetic 1.1 不需要质量标签),`negativePrompt` 为 Aesthetic 推荐值;从 Base 模型迁移时再把 `qualityPrefix` 填回 `masterpiece, best quality, score_7` |
|
|
74
79
|
| `promptOptimizeEnabled` / `llmBaseUrl` / `llmApiKey` / `llmModel` | 自然语言优化(OpenAI 兼容接口) |
|
|
75
80
|
| `promptOptimizeTemplate` | 自然语言优化模板(支持 `{theme}` `{search_block}` `{character_rule}` 占位符) |
|
|
76
81
|
| `webSearchEnabled` / `tavilyApiKey` / `webSearchMaxResults` / `webSearchDepth` / `webSearchQueryTemplate` | 联网搜索(指令带 `联网`/`搜索` 触发,需 Tavily Key) |
|
|
@@ -86,6 +91,95 @@ plugins:
|
|
|
86
91
|
| `allowedGroupIds` / `blockedGroupIds` | QQ 群白名单 / 黑名单(群号,黑名单优先) |
|
|
87
92
|
| `outputLogs` | 是否输出详细日志 |
|
|
88
93
|
|
|
94
|
+
## 工作流对接:Anima Aesthetic 1.1
|
|
95
|
+
|
|
96
|
+
### 1. 模型文件放置
|
|
97
|
+
|
|
98
|
+
| 文件 | 目标目录 | 说明 |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| `anima-aesthetic-v1.1.safetensors` | `ComfyUI/models/diffusion_models/` | 约 4.18GB,BF16 |
|
|
101
|
+
| `anima-aesthetic-v1.1-Q8_0.gguf` | `ComfyUI/models/diffusion_models/` | 约 2.1GB,GGUF 量化版(**8G 显存推荐**) |
|
|
102
|
+
| `qwen_3_06b_base.safetensors` | `ComfyUI/models/text_encoders/` | 文本编码器,与 Base 模型共用 |
|
|
103
|
+
| `qwen_image_vae.safetensors` | `ComfyUI/models/vae/` | VAE,与 Base 模型共用 |
|
|
104
|
+
|
|
105
|
+
**8G 显存(如 4060)推荐 GGUF Q8_0**:需要先安装 [ComfyUI-GGUF](https://github.com/city96/ComfyUI-GGUF) 插件。插件按 `unetName` 后缀自动选择加载器——`.gguf` 用 `UnetLoaderGGUF`,其余用 `UNETLoader`;也可用 `useGgufUnet` 强制指定。
|
|
106
|
+
|
|
107
|
+
推荐参数:
|
|
108
|
+
|
|
109
|
+
| 精度 | 采样器 | 调度器 | 步数 | CFG |
|
|
110
|
+
|---|---|---|---|---|
|
|
111
|
+
| safetensors(BF16) | `er_sde` | `simple` | 30 | 4(用 3 也常更好) |
|
|
112
|
+
| GGUF Q8_0 | `euler` / `euler a` | `normal` | 30–50 | 4–5 |
|
|
113
|
+
|
|
114
|
+
分辨率范围 512–1536px。
|
|
115
|
+
|
|
116
|
+
### 2. 节点 ID 识别
|
|
117
|
+
|
|
118
|
+
节点 ID 取决于你实际导出的 JSON。**插件不内置任何节点 ID,也不假设任何固定值。**
|
|
119
|
+
|
|
120
|
+
1. 在 ComfyUI 中加载 `text2image anima-aesthetic-v1.1.json`;
|
|
121
|
+
2. 选中正面 CLIPTextEncode(标题通常是 `CLIP Text Encode (Positive Prompt)`),记下 ID(示例 `6`);
|
|
122
|
+
3. 选中负面 CLIPTextEncode,记下 ID(示例 `7`);
|
|
123
|
+
4. 选中 EmptyLatentImage,记下 ID(示例 `5`)→ 填 `resolutionNodeId`(可选);
|
|
124
|
+
5. 选中 KSampler,记下 ID(示例 `3`)→ 填 `seedNodeId` 与 `stepsNodeId`(可选)。
|
|
125
|
+
|
|
126
|
+
配置的节点 ID 优先;**留空时插件会从 KSampler 的 positive/negative 连线自动反查**,因此不填也能用。填错时 `p-draw 诊断` 会列出工作流里实际可用的文本编码节点。
|
|
127
|
+
|
|
128
|
+
### 3. 提示词差异
|
|
129
|
+
|
|
130
|
+
Aesthetic 1.1 在 80 万张高质量图像上微调,**训练时已剥离质量标签**,正面提示词不需要 `masterpiece, best quality, score_7` 之类前缀。
|
|
131
|
+
|
|
132
|
+
- `qualityPrefix` 建议留空;
|
|
133
|
+
- `skipQualityPrefixForCustomWorkflow`(默认 `true`):启用自定义工作流时自动跳过质量前缀注入;
|
|
134
|
+
- 负面词推荐 `worst quality, low quality, score_1, score_2, score_3, artist name, blurry, jpeg artifacts`(已是默认值)。
|
|
135
|
+
|
|
136
|
+
从 Base 模型迁移过来时,`p-draw 诊断` 会额外提示 qualityPrefix 可能不适用于 Aesthetic 模型。
|
|
137
|
+
|
|
138
|
+
### 4. 配置模板
|
|
139
|
+
|
|
140
|
+
工作流 JSON 由你从 ComfyUI 导出后放入 Koishi 运行目录的 `data/p-draw/workflows/`(插件启动时自动创建该目录)。
|
|
141
|
+
|
|
142
|
+
```yaml
|
|
143
|
+
p-draw:
|
|
144
|
+
comfyuiBaseUrl: "http://127.0.0.1:8188"
|
|
145
|
+
|
|
146
|
+
# 自定义工作流
|
|
147
|
+
customWorkflowEnabled: true
|
|
148
|
+
customWorkflowPath: "data/p-draw/workflows/anima-aesthetic-v1.1.json"
|
|
149
|
+
positivePromptNodeId: "6" # 以你导出的 JSON 为准
|
|
150
|
+
negativePromptNodeId: "7"
|
|
151
|
+
resolutionNodeId: "5" # 可留空
|
|
152
|
+
seedNodeId: "3" # 可留空
|
|
153
|
+
stepsNodeId: "3" # 可留空
|
|
154
|
+
customWorkflowOverrideParameters: true
|
|
155
|
+
customWorkflowReloadOnChange: true
|
|
156
|
+
|
|
157
|
+
# 8G 显存友好参数
|
|
158
|
+
width: 1024
|
|
159
|
+
height: 1024
|
|
160
|
+
steps: 30
|
|
161
|
+
cfg: 4.0
|
|
162
|
+
samplerName: "er_sde"
|
|
163
|
+
scheduler: "simple"
|
|
164
|
+
|
|
165
|
+
# Aesthetic 1.1 提示词
|
|
166
|
+
qualityPrefix: ""
|
|
167
|
+
negativePrompt: "worst quality, low quality, score_1, score_2, score_3, artist name, blurry, jpeg artifacts"
|
|
168
|
+
|
|
169
|
+
# 若使用 GGUF:unetName 填 .gguf 文件,插件自动改用 UnetLoaderGGUF
|
|
170
|
+
# unetName: "anima-aesthetic-v1.1-Q8_0.gguf"
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`customWorkflowPath` 相对 **Koishi 运行目录**解析(插件目录作为回退,兼容旧配置)。
|
|
174
|
+
|
|
175
|
+
### 5. 验收清单
|
|
176
|
+
|
|
177
|
+
- [ ] 使用 `text2image anima-aesthetic-v1.1.json`,发送 `画图 1girl, solo, 白色裙子`,正面提示词写入正确的 CLIPTextEncode 节点,成图无过度锐化或风格偏移。
|
|
178
|
+
- [ ] `qualityPrefix` 置空后,画风保持 Aesthetic 1.1 的默认美学水平。
|
|
179
|
+
- [ ] 使用 GGUF Q8_0 时,显存峰值不超过 7.5GB,1024×1024 / 30 步在 30 秒量级。
|
|
180
|
+
- [ ] 替换工作流 JSON 后,在 `customWorkflowReloadOnChange: true` 下无需重启插件即生效。
|
|
181
|
+
- [ ] `p-draw 诊断` 能显示实际工作流路径、更新时间与实际解析到的节点 ID。
|
|
182
|
+
|
|
89
183
|
## 注意
|
|
90
184
|
|
|
91
185
|
- `p-draw` 指令消耗 `price` P 点,`p-draw 多人` 消耗 `multiPrice` P 点,需要先通过 `p-qiandao` 签到。
|