koishi-plugin-p-draw 1.6.3 → 1.6.5
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 +301 -57
- package/lib/i18n.js +4 -0
- package/lib/parse.js +50 -0
- package/lib/workflows.js +162 -9
- package/package.json +1 -1
- package/readme.md +121 -10
package/index.js
CHANGED
|
@@ -26,6 +26,7 @@ exports.usage = `
|
|
|
26
26
|
输出更详细的配置与连通性诊断。
|
|
27
27
|
- **尺寸:** 支持 \`竖图\` \`横图\` \`方图\` \`长竖图\` \`宽屏\` 或在描述中写 \`1024x1536:描述\` / \`--尺寸 1216x832\`。
|
|
28
28
|
- **采样参数:** 描述里可写 \`--steps 40\` / \`--cfg 3.5\`(也可写 \`--步数\` / \`--强度\`)临时覆盖步数与 CFG,优先于 \`modelParams\` 与全局配置。
|
|
29
|
+
- **工作流预设:** 配置里可登记多套工作流 JSON,用 \`--工作流 名称:描述\` 或直接以名称/别名开头(如 \`极速:描述\`)切换;\`画图 工作流\` 可列出所有预设及是否可用。
|
|
29
30
|
- **原样模式:** 描述前加 \`无优化\` 直接提交写好的 tags。
|
|
30
31
|
- **联网搜索:** 描述中带 \`联网\` / \`搜索\` / \`查一下\` 等词时,会先联网搜索补充角色设定(需配置 Tavily Key)。
|
|
31
32
|
- **画师组:** \`创建画师组 名称=tags\` \`切换画师组 名称\` \`查看画师组\` \`删除画师组 名称\`
|
|
@@ -33,17 +34,77 @@ exports.usage = `
|
|
|
33
34
|
`;
|
|
34
35
|
|
|
35
36
|
const { zhCN } = require('./lib/i18n')
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
// 配置分组定义:组名 → 组内扁平键。
|
|
38
|
+
//
|
|
39
|
+
// 控制台里只有「嵌套 object 字段」才会渲染出折叠箭头(intersect 分支是平铺的),
|
|
40
|
+
// 所以这里用嵌套结构换折叠能力;运行时统一摊平成扁平 cfg,
|
|
41
|
+
// 并兼容老版本写在 koishi.yml 里的扁平键。
|
|
42
|
+
const CONFIG_GROUPS = {
|
|
43
|
+
connection: ['comfyuiBaseUrl', 'timeout', 'pollInterval'],
|
|
44
|
+
model: [
|
|
45
|
+
'unetName', 'useGgufUnet', 'clipName', 'vaeName', 'width', 'height',
|
|
46
|
+
'allowedSizes', 'steps', 'cfg', 'samplerName', 'scheduler', 'modelParams',
|
|
47
|
+
],
|
|
48
|
+
prompt: [
|
|
49
|
+
'qualityPrefix', 'negativePrompt', 'styleTags', 'defaultArtistTags',
|
|
50
|
+
'activeArtistPreset', 'artistPresets', 'fixedCharacters',
|
|
51
|
+
],
|
|
52
|
+
queue: ['queueEnabled', 'queueMaxRequests', 'batchMax'],
|
|
53
|
+
pricing: ['price', 'multiPrice', 'couponPrice', 'couponAskTimeout', 'adminUsers'],
|
|
54
|
+
access: ['adminOnly', 'allowedUserIds', 'blockedUserIds', 'allowedGroupIds', 'blockedGroupIds', 'outputLogs'],
|
|
55
|
+
workflow: [
|
|
56
|
+
'customWorkflowEnabled', 'customWorkflowPath', 'skipQualityPrefixForCustomWorkflow',
|
|
57
|
+
'customWorkflowOverrideParameters', 'customWorkflowReloadOnChange',
|
|
58
|
+
'workflowOverrideModel', 'modelLoaderNodeId',
|
|
59
|
+
'positivePromptNodeId', 'negativePromptNodeId', 'resolutionNodeId', 'seedNodeId', 'stepsNodeId',
|
|
60
|
+
'workflowPresets', 'defaultWorkflowPreset',
|
|
61
|
+
],
|
|
62
|
+
llm: [
|
|
63
|
+
'promptOptimizeEnabled', 'llmBaseUrl', 'llmApiKey', 'llmProxy', 'llmModel', 'llmModels',
|
|
64
|
+
'llmChannels', 'llmChannelOrder', 'llmThinking', 'llmExtraBody', 'llmMaxTokens',
|
|
65
|
+
'promptOptimizeTemplate',
|
|
66
|
+
],
|
|
67
|
+
search: [
|
|
68
|
+
'webSearchEnabled', 'tavilyApiKey', 'tavilyProxy',
|
|
69
|
+
'webSearchMaxResults', 'webSearchDepth', 'webSearchQueryTemplate',
|
|
70
|
+
],
|
|
71
|
+
vision: [
|
|
72
|
+
'multiVerifyEnabled', 'multiVerifyPassScore', 'multiCandidateCount', 'multiSendDegradedCandidate',
|
|
73
|
+
'verifyLlmBaseUrl', 'verifyLlmApiKey', 'verifyLlmProxy', 'verifyLlmModel', 'verifyLlmModels',
|
|
74
|
+
'verifyLlmChannels', 'verifyLlmChannelOrder',
|
|
75
|
+
],
|
|
76
|
+
legacy: ['workflow'],
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 把嵌套配置摊平成扁平 cfg(就地写入,保持对象引用不变)。
|
|
80
|
+
// 优先级:顶层的旧扁平键 > 分组内的值。这样老 koishi.yml 直接可用,
|
|
81
|
+
// 而迁移到新结构后(顶层不再有同名键)就以分组值为准。
|
|
82
|
+
function normalizeConfig(raw) {
|
|
83
|
+
const src = raw && typeof raw === 'object' ? raw : {}
|
|
84
|
+
const known = Object.values(CONFIG_GROUPS).flat()
|
|
85
|
+
const legacy = known.filter(key => Object.prototype.hasOwnProperty.call(src, key))
|
|
86
|
+
|
|
87
|
+
for (const [group, keys] of Object.entries(CONFIG_GROUPS)) {
|
|
88
|
+
const node = src[group]
|
|
89
|
+
if (!node || typeof node !== 'object') continue
|
|
90
|
+
for (const key of keys) {
|
|
91
|
+
// 顶层扁平旧键优先,不被分组值覆盖
|
|
92
|
+
if (legacy.includes(key)) continue
|
|
93
|
+
if (key in node) src[key] = node[key]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { config: src, legacy }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 控制台里每个分组是一个「可折叠小节」:嵌套 object 字段天生带折叠箭头,默认展开。
|
|
100
|
+
exports.Config = Schema.object({
|
|
101
|
+
connection: Schema.object({
|
|
41
102
|
comfyuiBaseUrl: Schema.string().default('http://127.0.0.1:8188').description('ComfyUI 地址'),
|
|
42
103
|
timeout: Schema.number().default(300).description('单次生成超时(秒)'),
|
|
43
104
|
pollInterval: Schema.number().default(2).description('生成状态查询间隔(秒)'),
|
|
44
105
|
}).description('① ComfyUI 连接'),
|
|
45
106
|
|
|
46
|
-
Schema.object({
|
|
107
|
+
model: Schema.object({
|
|
47
108
|
unetName: Schema.string().default('anima-aesthetic-v1.1.safetensors').description('主模型文件名,需与 ComfyUI models/diffusion_models 下的文件名完全一致;8G 显存可填 .gguf 版(插件自动改用 UnetLoaderGGUF)'),
|
|
48
109
|
useGgufUnet: Schema.union([
|
|
49
110
|
Schema.const('auto').description('按文件名自动判断(.gguf → UnetLoaderGGUF)'),
|
|
@@ -59,11 +120,19 @@ exports.Config = Schema.intersect([
|
|
|
59
120
|
cfg: Schema.number().default(4.0).description('CFG 强度(Aesthetic 1.1 推荐 4,用 3 也常更好)'),
|
|
60
121
|
samplerName: Schema.string().default('er_sde').description('采样器'),
|
|
61
122
|
scheduler: Schema.string().default('simple').description('调度器'),
|
|
123
|
+
modelParams: Schema.dict(Schema.object({
|
|
124
|
+
samplerName: Schema.string().description('采样器'),
|
|
125
|
+
scheduler: Schema.string().description('调度器'),
|
|
126
|
+
steps: Schema.number().description('采样步数'),
|
|
127
|
+
cfg: Schema.number().description('CFG 强度'),
|
|
128
|
+
width: Schema.number().description('默认宽度'),
|
|
129
|
+
height: Schema.number().description('默认高度'),
|
|
130
|
+
}).description('该模型的参数覆盖')).default({}).description('按模型覆盖参数:key=模型文件名,value 只填要覆盖的字段。显式写了的字段会覆盖工作流内取值'),
|
|
62
131
|
}).description('② 模型与采样参数'),
|
|
63
132
|
|
|
64
|
-
Schema.object({
|
|
133
|
+
prompt: Schema.object({
|
|
65
134
|
qualityPrefix: Schema.string().default('').description('质量词前缀(Aesthetic 1.1 建议留空;Base 模型可填 masterpiece, best quality, score_7)'),
|
|
66
|
-
negativePrompt: Schema.string().default('worst quality, low quality, score_1, score_2, score_3, artist name, blurry, jpeg artifacts').description('负面提示词。推荐值就是当前默认值:worst quality, low quality, score_1, score_2, score_3, artist name, blurry, jpeg artifacts(Aesthetic 1.1 适用)。若用 Base 模型,可再加 score_4, score_5, score_6
|
|
135
|
+
negativePrompt: Schema.string().default('worst quality, low quality, score_1, score_2, score_3, artist name, blurry, jpeg artifacts').description('负面提示词。推荐值就是当前默认值:worst quality, low quality, score_1, score_2, score_3, artist name, blurry, jpeg artifacts(Aesthetic 1.1 适用)。若用 Base 模型,可再加 score_4, score_5, score_6'),
|
|
67
136
|
styleTags: Schema.string().default('').description('画风 tags'),
|
|
68
137
|
defaultArtistTags: Schema.string().default('').description('备用画师 tags'),
|
|
69
138
|
activeArtistPreset: Schema.string().default('').description('启用的画师组名称'),
|
|
@@ -71,13 +140,13 @@ exports.Config = Schema.intersect([
|
|
|
71
140
|
fixedCharacters: Schema.array(Schema.string()).default([]).description('固定角色(格式:角色名=tags;仅兼容旧配置,运行时以数据库为准)'),
|
|
72
141
|
}).description('③ 提示词与画师'),
|
|
73
142
|
|
|
74
|
-
Schema.object({
|
|
143
|
+
queue: Schema.object({
|
|
75
144
|
queueEnabled: Schema.boolean().default(true).description('启用生成队列(逐张顺序执行)'),
|
|
76
145
|
queueMaxRequests: Schema.number().default(5).description('队列最大任务数(0 表示不限制)'),
|
|
77
146
|
batchMax: Schema.number().default(4).description('单次指令最多生成的张数'),
|
|
78
147
|
}).description('④ 队列与批量'),
|
|
79
148
|
|
|
80
|
-
Schema.object({
|
|
149
|
+
pricing: Schema.object({
|
|
81
150
|
price: Schema.number().default(500).description('一张图消耗的 P 点'),
|
|
82
151
|
multiPrice: Schema.number().default(900).description('多人指令单张消耗的 P 点'),
|
|
83
152
|
couponPrice: Schema.number().default(3000).description('提示词优化券单价(可被 data/p-shop.json 覆盖)'),
|
|
@@ -85,7 +154,7 @@ exports.Config = Schema.intersect([
|
|
|
85
154
|
adminUsers: Schema.array(Schema.string()).default([]).description('免 P 点管理员用户 ID'),
|
|
86
155
|
}).description('⑤ P 点与优化券'),
|
|
87
156
|
|
|
88
|
-
Schema.object({
|
|
157
|
+
access: Schema.object({
|
|
89
158
|
adminOnly: Schema.boolean().default(false).description('仅管理员可用'),
|
|
90
159
|
allowedUserIds: Schema.array(Schema.string()).default([]).description('用户白名单(留空不限制)'),
|
|
91
160
|
blockedUserIds: Schema.array(Schema.string()).default([]).description('用户黑名单(优先于白名单)'),
|
|
@@ -94,36 +163,43 @@ exports.Config = Schema.intersect([
|
|
|
94
163
|
outputLogs: Schema.boolean().default(true).description('输出详细日志'),
|
|
95
164
|
}).description('⑥ 权限与日志'),
|
|
96
165
|
|
|
97
|
-
|
|
98
|
-
Schema.object({
|
|
166
|
+
workflow: Schema.object({
|
|
99
167
|
customWorkflowEnabled: Schema.boolean().default(false).description('使用自定义 ComfyUI 工作流 JSON'),
|
|
100
168
|
customWorkflowPath: Schema.string().default('').description('工作流 JSON 路径(相对 Koishi 运行目录,如 data/p-draw/workflows/anima-aesthetic-v1.1.json)'),
|
|
101
169
|
skipQualityPrefixForCustomWorkflow: Schema.boolean().default(true).description('启用自定义工作流时跳过质量前缀注入'),
|
|
102
170
|
customWorkflowOverrideParameters: Schema.boolean().default(false).description('用插件参数覆盖工作流内的采样参数'),
|
|
103
171
|
customWorkflowReloadOnChange: Schema.boolean().default(true).description('工作流文件变化时自动重载(无需重启)'),
|
|
172
|
+
workflowOverrideModel: Schema.boolean().default(true).description('用 unetName 覆盖自定义工作流里的模型文件名(让 `p-draw 模型` 切换对预设也生效)'),
|
|
173
|
+
modelLoaderNodeId: Schema.string().default('').description('指定覆盖哪个模型加载节点 ID(留空:工作流里只有一个模型加载节点时自动覆盖;有多个时跳过不猜)'),
|
|
104
174
|
positivePromptNodeId: Schema.string().default('').description('正面提示词节点 ID(留空自动识别;示例 6,以实际 JSON 为准)'),
|
|
105
175
|
negativePromptNodeId: Schema.string().default('').description('负面提示词节点 ID(留空自动识别;示例 7)'),
|
|
106
|
-
resolutionNodeId: Schema.string().default('').description('尺寸节点 ID
|
|
176
|
+
resolutionNodeId: Schema.string().default('').description('尺寸节点 ID(留空自动识别)'),
|
|
107
177
|
seedNodeId: Schema.string().default('').description('种子节点 ID(KSampler,可留空;示例 3)'),
|
|
108
178
|
stepsNodeId: Schema.string().default('').description('步数节点 ID(KSampler,可留空;示例 3)'),
|
|
179
|
+
workflowPresets: Schema.dict(Schema.object({
|
|
180
|
+
path: Schema.string().description('工作流 JSON 路径(相对 Koishi 运行目录)'),
|
|
181
|
+
aliases: Schema.array(Schema.string()).description('指令别名,例如 ["极速","fast"]'),
|
|
182
|
+
positivePromptNodeId: Schema.string().description('正面提示词节点 ID(留空自动识别)'),
|
|
183
|
+
negativePromptNodeId: Schema.string().description('负面提示词节点 ID(留空自动识别)'),
|
|
184
|
+
resolutionNodeId: Schema.string().description('尺寸节点 ID(留空自动识别)'),
|
|
185
|
+
seedNodeId: Schema.string().description('种子节点 ID(留空自动识别)'),
|
|
186
|
+
stepsNodeId: Schema.string().description('步数节点 ID(留空自动识别)'),
|
|
187
|
+
steps: Schema.number().description('该预设固定步数(如极速流 4)'),
|
|
188
|
+
cfg: Schema.number().description('该预设固定 CFG'),
|
|
189
|
+
samplerName: Schema.string().description('该预设固定采样器'),
|
|
190
|
+
scheduler: Schema.string().description('该预设固定调度器'),
|
|
191
|
+
overrideParameters: Schema.boolean().description('用上面的参数覆盖工作流内取值'),
|
|
192
|
+
overrideModel: Schema.boolean().description('是否把 unetName 写进这个工作流的模型节点(留空沿用全局)'),
|
|
193
|
+
modelLoaderNodeId: Schema.string().description('该预设的模型加载节点 ID(留空沿用全局)'),
|
|
194
|
+
}).description('预设')).default({}).description('工作流预设:key=预设名。指令里用 `--工作流 <名称>` 或名称/别名开头选择(如 `画图 极速:1girl`)'),
|
|
195
|
+
defaultWorkflowPreset: Schema.string().default('').description('默认预设名(留空则用上面的 customWorkflow* 那套)'),
|
|
109
196
|
}).description('⑦ 自定义工作流').collapse(),
|
|
110
197
|
|
|
111
|
-
Schema.object({
|
|
112
|
-
modelParams: Schema.dict(Schema.object({
|
|
113
|
-
samplerName: Schema.string().description('采样器'),
|
|
114
|
-
scheduler: Schema.string().description('调度器'),
|
|
115
|
-
steps: Schema.number().description('采样步数'),
|
|
116
|
-
cfg: Schema.number().description('CFG 强度'),
|
|
117
|
-
width: Schema.number().description('默认宽度'),
|
|
118
|
-
height: Schema.number().description('默认高度'),
|
|
119
|
-
}).description('该模型的参数覆盖')).default({}).description('按模型覆盖参数:key=模型文件名,value 只填要覆盖的字段。优先级:命令级 --steps/--cfg > 本节 > 全局配置'),
|
|
120
|
-
}).description('⑧ 模型独立参数覆盖').collapse(),
|
|
121
|
-
|
|
122
|
-
Schema.object({
|
|
198
|
+
llm: Schema.object({
|
|
123
199
|
promptOptimizeEnabled: Schema.boolean().default(false).description('启用自然语言优化(需配置下面的 LLM 接口)'),
|
|
124
200
|
llmBaseUrl: Schema.string().default('').description('LLM 接口地址(OpenAI 兼容,如 https://api.deepseek.com/v1)'),
|
|
125
201
|
llmApiKey: Schema.string().role('secret').default('').description('LLM API Key'),
|
|
126
|
-
llmProxy: Schema.string().default('').description('仅 LLM 使用代理(留空直连)。格式 http://127.0.0.1:7890 / socks5://127.0.0.1:7891,可省略 http
|
|
202
|
+
llmProxy: Schema.string().default('').description('仅 LLM 使用代理(留空直连)。格式 http://127.0.0.1:7890 / socks5://127.0.0.1:7891,可省略 http://;通道内单独填了 proxy 则优先用通道的'),
|
|
127
203
|
llmModel: Schema.string().default('').description('LLM 模型名(旧版单模型;请在 llmModels 里配置,这里留空即可)'),
|
|
128
204
|
llmModels: Schema.array(Schema.string()).default([]).description('主通道的模型名列表,按顺序逐个尝试(如 ["deepseek-chat","gpt-4o-mini"])'),
|
|
129
205
|
llmChannels: Schema.dict(Schema.object({
|
|
@@ -141,18 +217,18 @@ exports.Config = Schema.intersect([
|
|
|
141
217
|
llmExtraBody: Schema.string().role('textarea').default('{}').description('附加请求体 JSON(最后覆盖),用于中转站私有参数,如 {"enable_thinking":false}'),
|
|
142
218
|
llmMaxTokens: Schema.number().default(1000).description('LLM 输出上限'),
|
|
143
219
|
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}'),
|
|
144
|
-
}).description('
|
|
220
|
+
}).description('⑧ 提示词优化 / LLM').collapse(),
|
|
145
221
|
|
|
146
|
-
Schema.object({
|
|
222
|
+
search: Schema.object({
|
|
147
223
|
webSearchEnabled: Schema.boolean().default(false).description('启用联网搜索(指令里写「联网/搜索/查一下」触发)'),
|
|
148
224
|
tavilyApiKey: Schema.string().role('secret').default('').description('Tavily API Key(https://tavily.com)'),
|
|
149
|
-
tavilyProxy: Schema.string().default('').description('仅联网搜索(Tavily
|
|
225
|
+
tavilyProxy: Schema.string().default('').description('仅联网搜索(Tavily)使用代理(留空直连)。与 LLM / 视觉校验的代理互相独立'),
|
|
150
226
|
webSearchMaxResults: Schema.number().default(5).description('搜索结果数量'),
|
|
151
227
|
webSearchDepth: Schema.string().default('basic').description('搜索深度(basic / advanced)'),
|
|
152
228
|
webSearchQueryTemplate: Schema.string().default('{prompt} 角色 外观 立绘 服装 配色 武器 官方图 official art character design outfit appearance wiki fandom').description('搜索词模板({prompt} 代表用户需求)'),
|
|
153
|
-
}).description('
|
|
229
|
+
}).description('⑨ 联网搜索').collapse(),
|
|
154
230
|
|
|
155
|
-
Schema.object({
|
|
231
|
+
vision: Schema.object({
|
|
156
232
|
multiVerifyEnabled: Schema.boolean().default(true).description('多人图生成后启用视觉校验'),
|
|
157
233
|
multiVerifyPassScore: Schema.number().default(6).description('校验合格分数(0-10)'),
|
|
158
234
|
multiCandidateCount: Schema.number().default(2).description('候选采样数量(最多重试 候选数-1 次)'),
|
|
@@ -169,20 +245,18 @@ exports.Config = Schema.intersect([
|
|
|
169
245
|
proxy: Schema.string().description('该通道专用代理(留空则用上面的 verifyLlmProxy)'),
|
|
170
246
|
}).description('通道')).default({}).description('视觉校验的附加通道:主通道全部失败后按顺序继续尝试'),
|
|
171
247
|
verifyLlmChannelOrder: Schema.array(Schema.string()).default([]).description('视觉附加通道的尝试顺序(填通道名;留空则按配置先后顺序)'),
|
|
172
|
-
}).description('
|
|
248
|
+
}).description('⑩ 多人视觉校验').collapse(),
|
|
173
249
|
|
|
174
|
-
Schema.object({
|
|
250
|
+
legacy: Schema.object({
|
|
175
251
|
workflow: Schema.string().default('anima_t2i').description('旧版工作流标识,仅用于状态/诊断显示,内置工作流固定 anima_t2i'),
|
|
176
|
-
}).description('
|
|
177
|
-
]).i18n({
|
|
178
|
-
'zh-CN': zhCN,
|
|
252
|
+
}).description('⑪ 兼容项(旧版,可忽略)').collapse(),
|
|
179
253
|
})
|
|
180
254
|
|
|
181
255
|
// ------------------------------------------------------------------
|
|
182
256
|
// 纯函数库已拆分到 lib/(解析 / tag 清洗 / 工作流 / Comfy 等待 / 多人规划 / HTTP 客户端)
|
|
183
257
|
// ------------------------------------------------------------------
|
|
184
258
|
const {
|
|
185
|
-
normalizeBaseUrl, escapeRe, parseGenerationSize, parseBatchCount, parseSeed, parseStepsCfg,
|
|
259
|
+
normalizeBaseUrl, escapeRe, parseGenerationSize, parseBatchCount, parseSeed, parseStepsCfg, parseWorkflowPreset,
|
|
186
260
|
stripRawPrefix, splitPositiveNegativePrompt, parseNameTags, parsePresetList, mergeTagText,
|
|
187
261
|
} = require('./lib/parse')
|
|
188
262
|
const {
|
|
@@ -190,7 +264,7 @@ const {
|
|
|
190
264
|
NO_ARTIST_RE, NO_STYLE_RE,
|
|
191
265
|
} = require('./lib/tags')
|
|
192
266
|
const {
|
|
193
|
-
buildWorkflow, inspectCustomWorkflow, isGgufUnet,
|
|
267
|
+
buildWorkflow, inspectCustomWorkflow, isGgufUnet, inspectWorkflowFile,
|
|
194
268
|
} = require('./lib/workflows')
|
|
195
269
|
const { outputImages, waitComfyResult } = require('./lib/comfy')
|
|
196
270
|
const { materializeImageSource } = require('./lib/media')
|
|
@@ -201,20 +275,25 @@ const {
|
|
|
201
275
|
const { buildComfyClient } = require('./lib/http')
|
|
202
276
|
const { createOutboundFetch, normalizeProxyUrl, proxySupportAvailable } = require('./lib/net')
|
|
203
277
|
const { buildLlmChain, hasLlm, buildChatBody, runLlmChain } = require('./lib/llm')
|
|
204
|
-
exports.apply = async function apply(ctx,
|
|
205
|
-
//
|
|
206
|
-
|
|
278
|
+
exports.apply = async function apply(ctx, rawConfig) {
|
|
279
|
+
// 配置统一摊平成扁平 cfg:同时接受新的分组写法和老版本的扁平写法
|
|
280
|
+
const { config: cfg, legacy } = normalizeConfig(rawConfig)
|
|
207
281
|
|
|
208
282
|
const logger = ctx.logger('p-draw')
|
|
209
283
|
ctx.i18n.define('zh-CN', zhCN)
|
|
284
|
+
if (legacy.length) {
|
|
285
|
+
logger.warn(`[p-draw] koishi.yml 里仍有扁平旧配置键(${legacy.slice(0, 6).join('、')}${legacy.length > 6 ? ' 等' : ''}),本次已按它们生效;建议迁移到分组结构后删掉旧键,否则控制台里改同名项不会生效。`)
|
|
286
|
+
}
|
|
210
287
|
|
|
211
288
|
// 出站请求:代理按用途各自传入(联网搜索 / 文本 LLM / 视觉校验互不影响)
|
|
212
289
|
const outboundFetch = createOutboundFetch({
|
|
213
290
|
onWarn: (message) => logger.warn(message),
|
|
214
291
|
})
|
|
215
292
|
|
|
216
|
-
//
|
|
217
|
-
//
|
|
293
|
+
// 注意:不在此处 extend p_system 表 —— 该表由 p-qiandao 等 p 系插件创建。
|
|
294
|
+
// 重复声明同一张表可能导致 Koishi 的 schema 迁移冲突,拖垮签到插件。
|
|
295
|
+
|
|
296
|
+
// 运行时数据持久化到数据库,而不是调用 scope.update // 写 koishi.yml:scope.update 会触发插件重载,导致正在生成的图被 dispose(Context has
|
|
218
297
|
// been disposed),且重复写入时配置文件会被冲掉(曾出现配置整体恢复成默认)。
|
|
219
298
|
try {
|
|
220
299
|
ctx.model.extend('p_draw_config', {
|
|
@@ -281,7 +360,81 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
281
360
|
}
|
|
282
361
|
|
|
283
362
|
// 自定义工作流路径一律相对 Koishi 运行目录解析(见 lib/workflows.js)
|
|
284
|
-
const workflowOpts = () => ({
|
|
363
|
+
const workflowOpts = () => ({
|
|
364
|
+
baseDir: ctx.baseDir || process.cwd(),
|
|
365
|
+
overrideModel: cfg.workflowOverrideModel !== false,
|
|
366
|
+
modelLoaderNodeId: cfg.modelLoaderNodeId || '',
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
// ---------------- 工作流预设 ----------------
|
|
370
|
+
// 预设 = 一个 JSON 路径 + 可选的节点 ID / 采样参数覆盖,指令里按名字选用。
|
|
371
|
+
function presetList() {
|
|
372
|
+
const dict = cfg.workflowPresets
|
|
373
|
+
if (!dict || typeof dict !== 'object') return []
|
|
374
|
+
return Object.entries(dict)
|
|
375
|
+
.filter(([, value]) => value && typeof value === 'object')
|
|
376
|
+
.map(([name, value]) => ({ name, aliases: value.aliases || [], ...value }))
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function findPreset(name) {
|
|
380
|
+
if (!name) return null
|
|
381
|
+
return presetList().find(preset => preset.name === name) || null
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// 预设 → 生成用的配置补丁(工作流路径 + 节点 ID + 参数)
|
|
385
|
+
function presetCfgPatch(preset) {
|
|
386
|
+
if (!preset) return {}
|
|
387
|
+
const patch = {
|
|
388
|
+
customWorkflowEnabled: true,
|
|
389
|
+
customWorkflowPath: preset.path || '',
|
|
390
|
+
positivePromptNodeId: preset.positivePromptNodeId || '',
|
|
391
|
+
negativePromptNodeId: preset.negativePromptNodeId || '',
|
|
392
|
+
resolutionNodeId: preset.resolutionNodeId || '',
|
|
393
|
+
seedNodeId: preset.seedNodeId || '',
|
|
394
|
+
stepsNodeId: preset.stepsNodeId || '',
|
|
395
|
+
customWorkflowOverrideParameters: preset.overrideParameters != null
|
|
396
|
+
? Boolean(preset.overrideParameters)
|
|
397
|
+
: Boolean(cfg.customWorkflowOverrideParameters),
|
|
398
|
+
}
|
|
399
|
+
if (preset.overrideModel !== undefined && preset.overrideModel !== null) {
|
|
400
|
+
patch.workflowOverrideModel = Boolean(preset.overrideModel)
|
|
401
|
+
}
|
|
402
|
+
if (preset.modelLoaderNodeId) patch.modelLoaderNodeId = String(preset.modelLoaderNodeId)
|
|
403
|
+
return patch
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// 预设里显式写死的参数,优先级高于 modelParams
|
|
407
|
+
function presetParams(preset) {
|
|
408
|
+
if (!preset) return {}
|
|
409
|
+
const out = {}
|
|
410
|
+
for (const key of ['steps', 'cfg', 'samplerName', 'scheduler', 'width', 'height']) {
|
|
411
|
+
if (preset[key] === undefined || preset[key] === null || preset[key] === '') continue
|
|
412
|
+
out[key] = key === 'samplerName' || key === 'scheduler' ? String(preset[key]).trim() : Number(preset[key])
|
|
413
|
+
}
|
|
414
|
+
return out
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// 体检:这个预设现在能不能真的跑(能否从纯文本启动)
|
|
418
|
+
function inspectPreset(preset) {
|
|
419
|
+
return inspectWorkflowFile(preset.path, {
|
|
420
|
+
positivePromptNodeId: preset.positivePromptNodeId || '',
|
|
421
|
+
negativePromptNodeId: preset.negativePromptNodeId || '',
|
|
422
|
+
resolutionNodeId: preset.resolutionNodeId || '',
|
|
423
|
+
seedNodeId: preset.seedNodeId || '',
|
|
424
|
+
stepsNodeId: preset.stepsNodeId || '',
|
|
425
|
+
customWorkflowReloadOnChange: cfg.customWorkflowReloadOnChange,
|
|
426
|
+
}, workflowOpts())
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// 指令里选了预设时先体检,不可用就给出人话原因
|
|
430
|
+
function checkPresetUsable(name) {
|
|
431
|
+
const preset = findPreset(name)
|
|
432
|
+
if (!preset) return { ok: false, message: `没有名为「${name}」的工作流预设。可用:${presetList().map(p => p.name).join('、') || '(未配置)'}` }
|
|
433
|
+
if (!String(preset.path || '').trim()) return { ok: false, message: `预设「${name}」没有填写 path。` }
|
|
434
|
+
const report = inspectPreset(preset)
|
|
435
|
+
if (!report.ok) return { ok: false, message: `预设「${name}」当前不可用:${report.error}` }
|
|
436
|
+
return { ok: true, preset }
|
|
437
|
+
}
|
|
285
438
|
|
|
286
439
|
// A4:自定义工作流(Aesthetic 1.1)默认跳过质量前缀注入
|
|
287
440
|
function shouldSkipQualityPrefix() {
|
|
@@ -465,6 +618,56 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
465
618
|
lines.push(`步数节点:${fmt(t.stepsIds)}(${how(cfg.stepsNodeId, t.stepsIds.length)})`)
|
|
466
619
|
lines.push(`种子节点:${fmt(t.seedIds)}(${how(cfg.seedNodeId, t.seedIds.length)})`)
|
|
467
620
|
lines.push(`识别的文本编码节点:${fmt(t.textNodes)}`)
|
|
621
|
+
const loaders = report.modelLoaders || []
|
|
622
|
+
if (loaders.length) {
|
|
623
|
+
const list = loaders.map(l => `#${l.id} ${l.classType}`).join('、')
|
|
624
|
+
const how = cfg.workflowOverrideModel === false
|
|
625
|
+
? '不注入(workflowOverrideModel=false,模型由 JSON 决定)'
|
|
626
|
+
: loaders.length > 1
|
|
627
|
+
? (String(cfg.modelLoaderNodeId || '').trim() ? `只注入 #${cfg.modelLoaderNodeId}` : '跳过(有多个模型加载节点,可用 modelLoaderNodeId 指定)')
|
|
628
|
+
: `注入 ${cfg.unetName}`
|
|
629
|
+
lines.push(`模型加载节点:${list}(${how})`)
|
|
630
|
+
} else {
|
|
631
|
+
lines.push('模型加载节点:(未找到可注入的 UNETLoader / CheckpointLoaderSimple)')
|
|
632
|
+
}
|
|
633
|
+
return lines
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// 预设总览:每个预设能不能跑、需要什么(不实际生图)
|
|
637
|
+
function presetOverviewText() {
|
|
638
|
+
const presets = presetList()
|
|
639
|
+
if (!presets.length) {
|
|
640
|
+
return '还没有配置工作流预设。\n在「⑦ 自定义工作流 → workflowPresets」里添加,key 用预设名,例如:\n workflowPresets:\n 极速4步:\n path: data/p-draw/workflows/03-dmdx.json\n aliases: [极速]'
|
|
641
|
+
}
|
|
642
|
+
const lines = ['工作流预设:']
|
|
643
|
+
for (const preset of presets) {
|
|
644
|
+
const report = inspectPreset(preset)
|
|
645
|
+
const aliases = (preset.aliases || []).length ? `(别名:${preset.aliases.join('、')})` : ''
|
|
646
|
+
lines.push(`${report.ok ? '✅' : '❌'} ${preset.name}${aliases}`)
|
|
647
|
+
if (report.ok) {
|
|
648
|
+
const analysis = report.analysis
|
|
649
|
+
const pos = report.targets.positive.map(id => `#${id}`).join('、')
|
|
650
|
+
const neg = report.targets.negative.map(id => `#${id}`).join('、')
|
|
651
|
+
lines.push(` 节点 ${analysis.nodeCount} 个 · 正面 ${pos} · 负面 ${neg} · 尺寸 ${report.targets.resolutionIds.map(id => `#${id}`).join('、') || '(无)'}`)
|
|
652
|
+
} else {
|
|
653
|
+
lines.push(` 不可用:${report.error}`)
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const def = String(cfg.defaultWorkflowPreset || '').trim()
|
|
657
|
+
lines.push(`默认预设:${def ? `${def}${findPreset(def) ? '' : '(未找到此预设,已回落)'}` : '(未设置,使用内置/自定义工作流)'}`)
|
|
658
|
+
lines.push('用法:画图 --工作流 <名称>:描述 或 画图 <别名>:描述')
|
|
659
|
+
return lines.join('\n')
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// 诊断里附一段预设摘要
|
|
663
|
+
function presetDiagLines() {
|
|
664
|
+
const presets = presetList()
|
|
665
|
+
if (!presets.length) return []
|
|
666
|
+
const lines = [`工作流预设(${presets.length} 个):`]
|
|
667
|
+
for (const preset of presets) {
|
|
668
|
+
const report = inspectPreset(preset)
|
|
669
|
+
lines.push(` ${report.ok ? '✅' : '❌'} ${preset.name}${report.ok ? '' : ` — ${report.error}`}`)
|
|
670
|
+
}
|
|
468
671
|
return lines
|
|
469
672
|
}
|
|
470
673
|
|
|
@@ -508,6 +711,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
508
711
|
// A7:自定义工作流 + 非空 qualityPrefix 的迁移提示
|
|
509
712
|
const warning = qualityPrefixWarning()
|
|
510
713
|
if (warning) lines.push(`⚠ ${warning}`)
|
|
714
|
+
lines.push(...presetDiagLines())
|
|
511
715
|
return lines.join('\n')
|
|
512
716
|
}
|
|
513
717
|
|
|
@@ -767,9 +971,15 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
767
971
|
async function runComfyGenerate(prompt, size, overrides) {
|
|
768
972
|
const sizes = parseAllowedSizes()
|
|
769
973
|
const unetName = overrides.unet || cfg.unetName
|
|
770
|
-
//
|
|
974
|
+
// 工作流预设:把路径 / 节点 ID 替换进配置,并取出预设写死的采样参数
|
|
975
|
+
const preset = overrides.preset || null
|
|
976
|
+
const presetExtra = presetParams(preset)
|
|
977
|
+
const baseCfg = preset ? Object.assign({}, cfg, presetCfgPatch(preset)) : cfg
|
|
978
|
+
// 应用该模型的独立参数覆盖(modelParams),再叠加预设参数与命令级 overrides
|
|
771
979
|
const modelSpecific = resolveModelParams(unetName)
|
|
772
|
-
const workCfg = Object.assign({},
|
|
980
|
+
const workCfg = Object.assign({}, baseCfg, modelSpecific, presetExtra, { unetName })
|
|
981
|
+
// 预设/modelParams 里显式配置的字段要覆盖自定义工作流内的取值
|
|
982
|
+
const overrideKeys = Object.assign({}, modelSpecific, presetExtra)
|
|
773
983
|
const requestedWidth = (size && size[0]) || overrides.width || workCfg.width
|
|
774
984
|
const requestedHeight = (size && size[1]) || overrides.height || workCfg.height
|
|
775
985
|
// 防御:sampler/scheduler 配置若带尾随空格会导致 ComfyUI 报 "Value not in list",统一 trim
|
|
@@ -781,7 +991,11 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
781
991
|
const cfgVal = Number(overrides.cfg) || workCfg.cfg
|
|
782
992
|
const seed = Number(overrides.seed) || crypto.randomInt(1, 2 ** 32 - 1)
|
|
783
993
|
const negativePrompt = joinPromptParts([overrides.negativePrompt || cfg.negativePrompt || ''])
|
|
784
|
-
const promptBody = buildWorkflow(workCfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, Boolean(size), Object.assign({}, workflowOpts(), {
|
|
994
|
+
const promptBody = buildWorkflow(workCfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, Boolean(size), Object.assign({}, workflowOpts(), {
|
|
995
|
+
modelParams: overrideKeys,
|
|
996
|
+
overrideModel: baseCfg.workflowOverrideModel !== false,
|
|
997
|
+
modelLoaderNodeId: baseCfg.modelLoaderNodeId || '',
|
|
998
|
+
}))
|
|
785
999
|
|
|
786
1000
|
const clientId = crypto.randomUUID()
|
|
787
1001
|
const submit = await comfyPost('/prompt', { prompt: promptBody, client_id: clientId }, 20000)
|
|
@@ -1331,7 +1545,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1331
1545
|
|
|
1332
1546
|
// 视觉校验(anima_verify + generation_verifier 移植):对生成的图片跑视觉 LLM,
|
|
1333
1547
|
// 不合格则用相同提示词重试(最多 multiCandidateCount 张),按多候选规则挑选并返回结果。
|
|
1334
|
-
async function verifyGeneratedImages(session, images, userRequest, prompt, size, planCount, unet, negativePrompt) {
|
|
1548
|
+
async function verifyGeneratedImages(session, images, userRequest, prompt, size, planCount, unet, negativePrompt, preset = null) {
|
|
1335
1549
|
if (!hasLlm(cfg, 'vision')) {
|
|
1336
1550
|
return { ok: true, degraded: true, message: '', verdict: null, outputs: images, prompt, negativePrompt }
|
|
1337
1551
|
}
|
|
@@ -1443,7 +1657,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1443
1657
|
if (hint) {
|
|
1444
1658
|
currentPrompt = `${userRequest}\n【上次问题,请修正】${hint}`
|
|
1445
1659
|
}
|
|
1446
|
-
const regen = await runComfyGenerate(currentPrompt, size, { unet, negativePrompt: currentNegativePrompt })
|
|
1660
|
+
const regen = await runComfyGenerate(currentPrompt, size, Object.assign({ unet, negativePrompt: currentNegativePrompt }, preset ? { preset } : {}))
|
|
1447
1661
|
if (!regen.ok) {
|
|
1448
1662
|
logger.warn(`多人校验重试生成失败:${regen.message}`)
|
|
1449
1663
|
break
|
|
@@ -1524,11 +1738,24 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1524
1738
|
const parsedBatch = parseBatchCount(parsedSize.prompt, cfg.batchMax)
|
|
1525
1739
|
// 采样参数覆盖(--steps 40 / --cfg 3.5),并从描述中剥离,避免进入 LLM 规划
|
|
1526
1740
|
const parsedTuning = parseStepsCfg(parsedBatch.prompt)
|
|
1527
|
-
|
|
1741
|
+
// 工作流预设(多人生图同样支持)
|
|
1742
|
+
const parsedPreset = parseWorkflowPreset(parsedTuning.prompt, presetList())
|
|
1743
|
+
if (parsedPreset.error) return parsedPreset.error
|
|
1744
|
+
let activePreset = null
|
|
1745
|
+
if (parsedPreset.preset) {
|
|
1746
|
+
const usable = checkPresetUsable(parsedPreset.preset)
|
|
1747
|
+
if (!usable.ok) return usable.message
|
|
1748
|
+
activePreset = usable.preset
|
|
1749
|
+
} else if (String(cfg.defaultWorkflowPreset || '').trim()) {
|
|
1750
|
+
const usable = checkPresetUsable(String(cfg.defaultWorkflowPreset).trim())
|
|
1751
|
+
if (usable.ok) activePreset = usable.preset
|
|
1752
|
+
else if (cfg.outputLogs) logger.warn(`[p-draw] 默认预设不可用,已回落:${usable.message}`)
|
|
1753
|
+
}
|
|
1754
|
+
const text = parsedPreset.prompt
|
|
1528
1755
|
if (!text) return session.text('.multi-usage')
|
|
1529
1756
|
const count = parsedBatch.count
|
|
1530
1757
|
const tuningOverrides = Object.assign(
|
|
1531
|
-
{},
|
|
1758
|
+
activePreset ? { preset: activePreset } : {},
|
|
1532
1759
|
parsedTuning.steps != null ? { steps: parsedTuning.steps } : {},
|
|
1533
1760
|
parsedTuning.cfg != null ? { cfg: parsedTuning.cfg } : {},
|
|
1534
1761
|
)
|
|
@@ -1600,7 +1827,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1600
1827
|
if (!cfg.multiVerifyEnabled) {
|
|
1601
1828
|
return { ok: true, outputs: result.outputs, seed: result.seed, prompt: finalPrompt, negativePrompt: result.negativePrompt, note: session.text('.multi-degraded', ['(未启用校验或未配置视觉模型)']) }
|
|
1602
1829
|
}
|
|
1603
|
-
const verified = await verifyGeneratedImages(session, result.outputs, text, finalPrompt, size, plan.characters.length, unet, result.negativePrompt || multiNegative)
|
|
1830
|
+
const verified = await verifyGeneratedImages(session, result.outputs, text, finalPrompt, size, plan.characters.length, unet, result.negativePrompt || multiNegative, activePreset)
|
|
1604
1831
|
if (!verified.ok) return { ok: false, message: verified.message }
|
|
1605
1832
|
return { ok: true, outputs: verified.outputs, seed: result.seed, prompt: verified.prompt || finalPrompt, negativePrompt: verified.negativePrompt || result.negativePrompt || multiNegative, note: verified.message || '' }
|
|
1606
1833
|
}
|
|
@@ -1824,6 +2051,9 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1824
2051
|
if (lower === '诊断' || lower === 'diagnose' || lower === '部署诊断' || lower === 'debug' || lower === '调试' || lower === '调试状态') {
|
|
1825
2052
|
return await diagnoseText(session)
|
|
1826
2053
|
}
|
|
2054
|
+
if (lower === '工作流' || lower === '预设' || lower === 'workflow' || lower === 'workflows') {
|
|
2055
|
+
return presetOverviewText()
|
|
2056
|
+
}
|
|
1827
2057
|
|
|
1828
2058
|
// 多人指令:p-draw 多人 <描述>
|
|
1829
2059
|
const multiMatch = text.match(/^(?:多人|多人生图|双人|三人|群像)\s*(.*)$/)
|
|
@@ -1984,12 +2214,26 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1984
2214
|
const parsedSeed = parseSeed(parsedBatch.prompt)
|
|
1985
2215
|
// 采样参数覆盖(--steps 40 / --cfg 3.5),并从提示词中剥离
|
|
1986
2216
|
const parsedTuning = parseStepsCfg(parsedSeed.prompt)
|
|
1987
|
-
|
|
2217
|
+
// 工作流预设:--工作流 xxx 或开头裸写名称/别名
|
|
2218
|
+
const parsedPreset = parseWorkflowPreset(parsedTuning.prompt, presetList())
|
|
2219
|
+
if (parsedPreset.error) return parsedPreset.error
|
|
2220
|
+
let activePreset = null
|
|
2221
|
+
if (parsedPreset.preset) {
|
|
2222
|
+
const usable = checkPresetUsable(parsedPreset.preset)
|
|
2223
|
+
if (!usable.ok) return usable.message
|
|
2224
|
+
activePreset = usable.preset
|
|
2225
|
+
} else if (String(cfg.defaultWorkflowPreset || '').trim()) {
|
|
2226
|
+
// 默认预设不可用时不阻断生成,回落到 customWorkflow* / 内置工作流
|
|
2227
|
+
const usable = checkPresetUsable(String(cfg.defaultWorkflowPreset).trim())
|
|
2228
|
+
if (usable.ok) activePreset = usable.preset
|
|
2229
|
+
else if (cfg.outputLogs) logger.warn(`[p-draw] 默认预设不可用,已回落:${usable.message}`)
|
|
2230
|
+
}
|
|
2231
|
+
const text = parsedPreset.prompt
|
|
1988
2232
|
const seed = parsedSeed.seed
|
|
1989
2233
|
const count = parsedBatch.count
|
|
1990
|
-
//
|
|
2234
|
+
// 命令级参数优先于预设 / modelParams / 全局配置(见 runComfyGenerate)
|
|
1991
2235
|
const tuningOverrides = Object.assign(
|
|
1992
|
-
{},
|
|
2236
|
+
activePreset ? { preset: activePreset } : {},
|
|
1993
2237
|
parsedTuning.steps != null ? { steps: parsedTuning.steps } : {},
|
|
1994
2238
|
parsedTuning.cfg != null ? { cfg: parsedTuning.cfg } : {},
|
|
1995
2239
|
)
|
|
@@ -2336,5 +2580,5 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
2336
2580
|
})
|
|
2337
2581
|
|
|
2338
2582
|
// 暴露内部接口供自动化测试调用(Koishi 忽略 apply 返回值,不影响生产行为)
|
|
2339
|
-
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch, composePrompt, shouldSkipQualityPrefix, qualityPrefixWarning, customWorkflowDiagLines, diagnoseText, workflowDir }
|
|
2583
|
+
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch, composePrompt, shouldSkipQualityPrefix, qualityPrefixWarning, customWorkflowDiagLines, diagnoseText, workflowDir, normalizeConfig, presetList, presetOverviewText }
|
|
2340
2584
|
}
|
package/lib/i18n.js
CHANGED
|
@@ -10,11 +10,15 @@ 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)' },
|
|
16
18
|
seedNodeId: { $description: '自定义工作流中种子节点 ID(KSampler,可留空;示例 3)' },
|
|
17
19
|
stepsNodeId: { $description: '自定义工作流中步数节点 ID(KSampler,可留空;示例 3)' },
|
|
20
|
+
workflowPresets: { $description: '工作流预设:key=预设名。指令里用 --工作流 <名称> 或名称/别名开头选择' },
|
|
21
|
+
defaultWorkflowPreset: { $description: '默认预设名(留空则用 customWorkflow* 那套)' },
|
|
18
22
|
timeout: { $description: '单次生成超时(秒)' },
|
|
19
23
|
pollInterval: { $description: '生成状态查询间隔(秒)' },
|
|
20
24
|
unetName: { $description: '主模型文件名(8G 显存推荐 GGUF Q8_0 版,插件会自动改用 UnetLoaderGGUF 加载)' },
|
package/lib/parse.js
CHANGED
|
@@ -191,6 +191,54 @@ function parseStepsCfg(text) {
|
|
|
191
191
|
return { steps, cfg, prompt }
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
// 工作流预设选择:--工作流 名称 / --workflow 名称,或开头裸写名称/别名(如「极速:描述」)
|
|
195
|
+
// presets: [{ name, aliases: [] }]
|
|
196
|
+
function matchPreset(wanted, presets) {
|
|
197
|
+
const key = String(wanted || '').trim().toLowerCase()
|
|
198
|
+
if (!key) return null
|
|
199
|
+
for (const preset of presets) {
|
|
200
|
+
if (String(preset.name || '').toLowerCase() === key) return preset.name
|
|
201
|
+
if ((preset.aliases || []).some(alias => String(alias || '').toLowerCase() === key)) return preset.name
|
|
202
|
+
}
|
|
203
|
+
return null
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function parseWorkflowPreset(text, presets = []) {
|
|
207
|
+
const original = String(text || '').trim()
|
|
208
|
+
const list = Array.isArray(presets) ? presets : []
|
|
209
|
+
if (!list.length) return { preset: null, prompt: original, error: null }
|
|
210
|
+
|
|
211
|
+
// 1) 显式开关:--工作流 xxx
|
|
212
|
+
const flag = original.match(/(?<!\S)--(?:工作流|预设|workflow|preset)\s*(?:=|=|:|:)?\s*([^\s,,::]+)/i)
|
|
213
|
+
if (flag) {
|
|
214
|
+
const hit = matchPreset(flag[1], list)
|
|
215
|
+
if (!hit) {
|
|
216
|
+
return {
|
|
217
|
+
preset: null,
|
|
218
|
+
prompt: original,
|
|
219
|
+
error: `没有名为「${flag[1]}」的工作流预设。可用:${list.map(p => p.name).join('、')}`,
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return { preset: hit, prompt: stripMatchedToken(original, flag), error: null }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// 2) 开头裸写名称或别名(长的优先,避免「高清」抢了「高清重绘」)
|
|
226
|
+
const candidates = []
|
|
227
|
+
for (const preset of list) {
|
|
228
|
+
if (preset.name) candidates.push([String(preset.name), preset.name])
|
|
229
|
+
for (const alias of preset.aliases || []) if (alias) candidates.push([String(alias), preset.name])
|
|
230
|
+
}
|
|
231
|
+
candidates.sort((a, b) => b[0].length - a[0].length)
|
|
232
|
+
for (const [token, name] of candidates) {
|
|
233
|
+
const pattern = new RegExp(`^\\s*${escapeRe(token)}\\s*(?:[::,,]|\\s|$)`, 'i')
|
|
234
|
+
const matched = original.match(pattern)
|
|
235
|
+
if (matched) {
|
|
236
|
+
return { preset: name, prompt: original.slice(matched[0].length).trim(), error: null }
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return { preset: null, prompt: original, error: null }
|
|
240
|
+
}
|
|
241
|
+
|
|
194
242
|
// ------------------------------------------------------------------
|
|
195
243
|
// 提示词辅助(移植自 anima prompt_presets)
|
|
196
244
|
// ------------------------------------------------------------------
|
|
@@ -302,6 +350,8 @@ module.exports = {
|
|
|
302
350
|
CFG_PATTERN,
|
|
303
351
|
stripMatchedToken,
|
|
304
352
|
parseStepsCfg,
|
|
353
|
+
matchPreset,
|
|
354
|
+
parseWorkflowPreset,
|
|
305
355
|
RAW_PREFIXES,
|
|
306
356
|
stripRawPrefix,
|
|
307
357
|
splitPositiveNegativePrompt,
|
package/lib/workflows.js
CHANGED
|
@@ -182,12 +182,42 @@ function findNodesByClass(workflow, classTypes) {
|
|
|
182
182
|
return ids
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
//
|
|
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
|
+
}
|
|
198
|
+
// 尺寸节点:凡是「类名带 Latent 且同时有 width/height 输入」的都算。
|
|
199
|
+
// 这样 EmptyLatentImage、EmptySD3LatentImage、EmptyHunyuanLatentVideo 等新老节点都能认。
|
|
200
|
+
function findResolutionNodeIds(workflow) {
|
|
201
|
+
const ids = []
|
|
202
|
+
for (const [nodeId, node] of Object.entries(workflow)) {
|
|
203
|
+
if (!node || typeof node !== 'object') continue
|
|
204
|
+
const classType = String(node.class_type || '')
|
|
205
|
+
const inputs = node.inputs
|
|
206
|
+
if (!inputs || typeof inputs !== 'object') continue
|
|
207
|
+
if (!/latent/i.test(classType)) continue
|
|
208
|
+
if (!('width' in inputs) || !('height' in inputs)) continue
|
|
209
|
+
ids.push(String(nodeId))
|
|
210
|
+
}
|
|
211
|
+
return ids
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 从任意带 positive/negative 输入的节点(KSampler、KSamplerAdvanced、ClownsharKSampler_Beta
|
|
215
|
+
// 等所有采样器)沿连线反查,找到真正的文本编码节点。
|
|
216
|
+
// 不写死采样器类名,否则 RES4LYF / 自定义采样器都会识别不到。
|
|
186
217
|
function conditioningTextNodeIds(workflow, inputName, textNodes) {
|
|
187
218
|
const pending = []
|
|
188
219
|
for (const node of Object.values(workflow)) {
|
|
189
220
|
if (!node || typeof node !== 'object') continue
|
|
190
|
-
if (!['KSampler', 'KSamplerAdvanced'].includes(String(node.class_type || ''))) continue
|
|
191
221
|
const link = node.inputs && node.inputs[inputName]
|
|
192
222
|
if (Array.isArray(link) && link.length) pending.push(String(link[0]))
|
|
193
223
|
}
|
|
@@ -254,26 +284,26 @@ function resolveCustomNodeTargets(workflow, cfg = {}) {
|
|
|
254
284
|
let resolutionIds = []
|
|
255
285
|
if (explicitResolution) {
|
|
256
286
|
if (!workflow[explicitResolution]) {
|
|
257
|
-
errors.push(`配置的尺寸节点 ID「${explicitResolution}」不存在于工作流中。可能是:\n ${
|
|
287
|
+
errors.push(`配置的尺寸节点 ID「${explicitResolution}」不存在于工作流中。可能是:\n ${findResolutionNodeIds(workflow).map(id => nodeLabel(workflow, id)).join('\n ') || '(无)'}`)
|
|
258
288
|
} else {
|
|
259
289
|
resolutionIds = [explicitResolution]
|
|
260
290
|
}
|
|
261
291
|
} else {
|
|
262
|
-
resolutionIds =
|
|
292
|
+
resolutionIds = findResolutionNodeIds(workflow)
|
|
263
293
|
}
|
|
264
294
|
|
|
265
295
|
// 采样节点:显式指定则只改该节点,否则改所有 KSampler
|
|
266
|
-
const samplerClasses =
|
|
296
|
+
const samplerClasses = findSamplerNodeIds(workflow)
|
|
267
297
|
const explicitSteps = cleanNodeId(cfg.stepsNodeId)
|
|
268
298
|
let stepsIds = []
|
|
269
299
|
if (explicitSteps) {
|
|
270
300
|
if (!workflow[explicitSteps]) {
|
|
271
|
-
errors.push(`配置的步数节点 ID「${explicitSteps}」不存在于工作流中。可能是:\n ${
|
|
301
|
+
errors.push(`配置的步数节点 ID「${explicitSteps}」不存在于工作流中。可能是:\n ${samplerClasses.map(id => nodeLabel(workflow, id)).join('\n ') || '(无)'}`)
|
|
272
302
|
} else {
|
|
273
303
|
stepsIds = [explicitSteps]
|
|
274
304
|
}
|
|
275
305
|
} else {
|
|
276
|
-
stepsIds =
|
|
306
|
+
stepsIds = samplerClasses
|
|
277
307
|
}
|
|
278
308
|
|
|
279
309
|
// seed 节点:显式指定则只改该节点,否则改所有带 seed / noise_seed 输入的节点
|
|
@@ -281,7 +311,7 @@ function resolveCustomNodeTargets(workflow, cfg = {}) {
|
|
|
281
311
|
let seedIds = []
|
|
282
312
|
if (explicitSeed) {
|
|
283
313
|
if (!workflow[explicitSeed]) {
|
|
284
|
-
errors.push(`配置的种子节点 ID「${explicitSeed}」不存在于工作流中。可能是:\n ${
|
|
314
|
+
errors.push(`配置的种子节点 ID「${explicitSeed}」不存在于工作流中。可能是:\n ${samplerClasses.map(id => nodeLabel(workflow, id)).join('\n ') || '(无)'}`)
|
|
285
315
|
} else {
|
|
286
316
|
seedIds = [explicitSeed]
|
|
287
317
|
}
|
|
@@ -310,6 +340,9 @@ function customWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVa
|
|
|
310
340
|
const targets = resolveCustomNodeTargets(workflow, cfg)
|
|
311
341
|
if (targets.errors.length) throw new Error(targets.errors.join('\n'))
|
|
312
342
|
|
|
343
|
+
// 模型名注入:让 unetName / p-draw 模型 对自定义工作流也生效
|
|
344
|
+
const modelResult = applyModelOverride(workflow, cfg, opts)
|
|
345
|
+
|
|
313
346
|
for (const nodeId of targets.positive) {
|
|
314
347
|
if (workflow[nodeId] && workflow[nodeId].inputs) workflow[nodeId].inputs.text = prompt
|
|
315
348
|
}
|
|
@@ -357,7 +390,7 @@ function customWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVa
|
|
|
357
390
|
|
|
358
391
|
// 只读检查:供「p-draw 诊断」报告工作流来源与实际解析到的节点,不生成图片
|
|
359
392
|
function inspectCustomWorkflow(cfg, opts = {}) {
|
|
360
|
-
const report = { ok: false, path: '', mtimeMs: null, targets: null, textNodes: [], error: '' }
|
|
393
|
+
const report = { ok: false, path: '', mtimeMs: null, targets: null, textNodes: [], modelLoaders: [], error: '' }
|
|
361
394
|
try {
|
|
362
395
|
const absPath = resolveCustomWorkflowPath(cfg, opts)
|
|
363
396
|
report.path = absPath
|
|
@@ -367,6 +400,7 @@ function inspectCustomWorkflow(cfg, opts = {}) {
|
|
|
367
400
|
const targets = resolveCustomNodeTargets(workflow, cfg)
|
|
368
401
|
report.targets = targets
|
|
369
402
|
report.textNodes = targets.textNodes
|
|
403
|
+
report.modelLoaders = findModelLoaders(workflow)
|
|
370
404
|
if (targets.errors.length) {
|
|
371
405
|
report.error = targets.errors.join(';')
|
|
372
406
|
return report
|
|
@@ -379,6 +413,116 @@ function inspectCustomWorkflow(cfg, opts = {}) {
|
|
|
379
413
|
}
|
|
380
414
|
}
|
|
381
415
|
|
|
416
|
+
// 只有图像输入类节点才需要用户「喂图」;这些工作流在纯文生图模式下无法使用
|
|
417
|
+
const IMAGE_INPUT_RE = /^(LoadImage|LoadImageMask|LoadImageOutput|ImageInput|LoadImageFromUrl)$/i
|
|
418
|
+
const CONTROLNET_RE = /controlnet/i
|
|
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
|
+
|
|
466
|
+
// 体检:这个工作流能不能在「纯文本」模式下跑,需要什么额外输入
|
|
467
|
+
function analyzeWorkflow(workflow) {
|
|
468
|
+
const classes = Object.values(workflow).map(node => String((node && node.class_type) || ''))
|
|
469
|
+
const unique = (list) => [...new Set(list)]
|
|
470
|
+
const imageInputClasses = unique(classes.filter(type => IMAGE_INPUT_RE.test(type)))
|
|
471
|
+
const controlNetClasses = unique(classes.filter(type => CONTROLNET_RE.test(type)))
|
|
472
|
+
const resolutionIds = findResolutionNodeIds(workflow)
|
|
473
|
+
const textNodes = collectTextNodeIds(workflow)
|
|
474
|
+
|
|
475
|
+
const requires = []
|
|
476
|
+
if (imageInputClasses.length) requires.push(`图片输入(${imageInputClasses.join(' / ')})`)
|
|
477
|
+
if (controlNetClasses.length && !imageInputClasses.length) {
|
|
478
|
+
requires.push(`ControlNet 控制图(${controlNetClasses.join(' / ')})`)
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
return {
|
|
482
|
+
nodeCount: classes.length,
|
|
483
|
+
textNodes,
|
|
484
|
+
resolutionIds,
|
|
485
|
+
imageInputClasses,
|
|
486
|
+
controlNetClasses,
|
|
487
|
+
hasLatentStart: resolutionIds.length > 0,
|
|
488
|
+
requires,
|
|
489
|
+
// 纯文本可跑:有文生图起点,且没有任何需要外部图片的节点
|
|
490
|
+
canRunTextOnly: resolutionIds.length > 0 && imageInputClasses.length === 0,
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// 体检任意一个工作流文件(预设用)。返回结构不抛错,便于诊断里逐条展示。
|
|
495
|
+
function inspectWorkflowFile(workflowPath, cfg = {}, opts = {}) {
|
|
496
|
+
const report = {
|
|
497
|
+
ok: false, path: '', mtimeMs: null, analysis: null, targets: null, error: '',
|
|
498
|
+
}
|
|
499
|
+
try {
|
|
500
|
+
const absPath = resolveCustomWorkflowPath({ customWorkflowPath: workflowPath }, opts)
|
|
501
|
+
report.path = absPath
|
|
502
|
+
try { report.mtimeMs = fs.statSync(absPath).mtimeMs } catch (e) { /* ignore */ }
|
|
503
|
+
const body = readCustomWorkflowBody(absPath, cfg.customWorkflowReloadOnChange !== false)
|
|
504
|
+
const workflow = JSON.parse(JSON.stringify(body))
|
|
505
|
+
report.analysis = analyzeWorkflow(workflow)
|
|
506
|
+
const targets = resolveCustomNodeTargets(workflow, cfg)
|
|
507
|
+
report.targets = targets
|
|
508
|
+
if (targets.errors.length) {
|
|
509
|
+
report.error = targets.errors.join(';')
|
|
510
|
+
return report
|
|
511
|
+
}
|
|
512
|
+
if (!report.analysis.canRunTextOnly) {
|
|
513
|
+
report.error = report.analysis.requires.length
|
|
514
|
+
? `需要${report.analysis.requires.join('、')},当前版本不支持图生图`
|
|
515
|
+
: '工作流里找不到可写入尺寸的 latent 节点(缺少文生图起点)'
|
|
516
|
+
return report
|
|
517
|
+
}
|
|
518
|
+
report.ok = true
|
|
519
|
+
return report
|
|
520
|
+
} catch (e) {
|
|
521
|
+
report.error = String((e && e.message) || e)
|
|
522
|
+
return report
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
382
526
|
function buildWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, explicitSize, opts = {}) {
|
|
383
527
|
if (cfg.customWorkflowEnabled && cfg.customWorkflowPath) {
|
|
384
528
|
return customWorkflow(cfg, prompt, negativePrompt, width, height, steps, cfgVal, seed, explicitSize, opts)
|
|
@@ -402,9 +546,18 @@ module.exports = {
|
|
|
402
546
|
nodeLabel,
|
|
403
547
|
collectTextNodeIds,
|
|
404
548
|
findNodesByClass,
|
|
549
|
+
findSamplerNodeIds,
|
|
550
|
+
findResolutionNodeIds,
|
|
405
551
|
buildWorkflow,
|
|
406
552
|
customWorkflow,
|
|
407
553
|
conditioningTextNodeIds,
|
|
408
554
|
resolveCustomNodeTargets,
|
|
409
555
|
inspectCustomWorkflow,
|
|
556
|
+
IMAGE_INPUT_RE,
|
|
557
|
+
CONTROLNET_RE,
|
|
558
|
+
MODEL_LOADER_INPUTS,
|
|
559
|
+
findModelLoaders,
|
|
560
|
+
applyModelOverride,
|
|
561
|
+
analyzeWorkflow,
|
|
562
|
+
inspectWorkflowFile,
|
|
410
563
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -66,7 +66,7 @@ plugins:
|
|
|
66
66
|
|
|
67
67
|
## 配置说明
|
|
68
68
|
|
|
69
|
-
控制台里配置分成 **
|
|
69
|
+
控制台里配置分成 **11 个可折叠分组**,点标题即可折叠/展开,默认展开。分组是嵌套结构,`koishi.yml` 里写成 `组名: { 字段名: 值 }`,详见文末的分组对照与示例。
|
|
70
70
|
|
|
71
71
|
### ① ComfyUI 连接
|
|
72
72
|
|
|
@@ -125,8 +125,12 @@ 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;可留空(留空则按节点类型覆盖) |
|
|
132
|
+
| `workflowPresets` | 工作流预设字典:`预设名 → { path, aliases, 节点 ID, steps, cfg, ... }`,供指令按名切换(见下方「工作流预设」) |
|
|
133
|
+
| `defaultWorkflowPreset` | 默认预设名;留空则使用 `customWorkflow*` 那套或内置工作流 |
|
|
130
134
|
|
|
131
135
|
### ⑧ 模型独立参数覆盖(折叠)
|
|
132
136
|
|
|
@@ -173,22 +177,52 @@ plugins:
|
|
|
173
177
|
|----|------|
|
|
174
178
|
| `workflow` | 旧版工作流标识,仅用于状态/诊断显示,内置工作流固定 `anima_t2i` |
|
|
175
179
|
|
|
176
|
-
|
|
180
|
+
控制台里配置分成 **11 个可折叠分组**(每个分组都能折叠/展开,默认展开)。分组是**嵌套结构**:`koishi.yml` 里对应写成 `组名: { 字段名: 值 }`。
|
|
181
|
+
|
|
182
|
+
已有的**扁平旧配置仍然生效**(插件会就地摊平并打一条日志提醒),但建议迁移成下面的分组写法——否则你在控制台里改同名项不会生效,因为旧扁平键优先级更高。
|
|
183
|
+
|
|
184
|
+
| 分组 | 内容 |
|
|
185
|
+
|---|---|
|
|
186
|
+
| `connection` | ComfyUI 地址、超时、轮询间隔 |
|
|
187
|
+
| `model` | 模型文件、采样参数、尺寸、`modelParams` |
|
|
188
|
+
| `prompt` | 质量前缀、负面词、画师组、固定角色 |
|
|
189
|
+
| `queue` | 队列与批量张数 |
|
|
190
|
+
| `pricing` | P 点价格、优化券、管理员 |
|
|
191
|
+
| `access` | 白名单/黑名单、日志 |
|
|
192
|
+
| `workflow` | 自定义工作流、节点 ID、工作流预设 |
|
|
193
|
+
| `llm` | 提示词优化、多通道/多模型、LLM 代理 |
|
|
194
|
+
| `search` | 联网搜索(Tavily)与其代理 |
|
|
195
|
+
| `vision` | 多人视觉校验及其通道/代理 |
|
|
196
|
+
| `legacy` | 旧版 `workflow` 标识,可忽略 |
|
|
177
197
|
|
|
178
198
|
```yaml
|
|
179
199
|
p-draw:0z81el:
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
200
|
+
connection:
|
|
201
|
+
comfyuiBaseUrl: http://127.0.0.1:8188
|
|
202
|
+
model:
|
|
203
|
+
unetName: anima-aesthetic-v1.1.safetensors
|
|
204
|
+
cfg: 4.0
|
|
205
|
+
steps: 30
|
|
206
|
+
prompt:
|
|
207
|
+
qualityPrefix: ''
|
|
208
|
+
workflow:
|
|
209
|
+
customWorkflowEnabled: true
|
|
210
|
+
customWorkflowPath: data/p-draw/workflows/anima-aesthetic-v1.1.json
|
|
211
|
+
workflowPresets:
|
|
212
|
+
极速4步:
|
|
213
|
+
path: data/p-draw/workflows/03-dmdx.json
|
|
214
|
+
aliases: [极速]
|
|
215
|
+
steps: 4
|
|
216
|
+
cfg: 1.0
|
|
217
|
+
llm:
|
|
218
|
+
llmBaseUrl: https://api.deepseek.com
|
|
219
|
+
llmModels: [deepseek-chat]
|
|
188
220
|
```
|
|
189
221
|
|
|
190
222
|
## 中转站、多模型与代理
|
|
191
223
|
|
|
224
|
+
> 下面片段为便于阅读只按**字段名**展示,实际请写在对应分组下:`llm*` → `llm:`,`tavilyProxy` / `webSearch*` → `search:`,`verifyLlm*` → `vision:`。
|
|
225
|
+
|
|
192
226
|
### 多模型逐个回退
|
|
193
227
|
|
|
194
228
|
同一个 `baseUrl` + `apiKey` 下可以填**多个模型名**,按顺序逐个尝试;前一个失败(网络错误 / 非 2xx / 返回空文本)自动换下一个:
|
|
@@ -350,6 +384,83 @@ p-draw:
|
|
|
350
384
|
- [ ] 替换工作流 JSON 后,在 `customWorkflowReloadOnChange: true` 下无需重启插件即生效。
|
|
351
385
|
- [ ] `p-draw 诊断` 能显示实际工作流路径、更新时间与实际解析到的节点 ID。
|
|
352
386
|
|
|
387
|
+
## 工作流预设
|
|
388
|
+
|
|
389
|
+
> 下面片段按字段名展示,实际写在 `workflow:` 分组下(见「配置说明」的分组示例)。
|
|
390
|
+
|
|
391
|
+
Anima Aesthetic 1.1 官方/社区共 10 个工作流。插件**不内置任何 JSON**,你导出后登记成预设,指令里按名字切换。
|
|
392
|
+
|
|
393
|
+
### 登记预设
|
|
394
|
+
|
|
395
|
+
```yaml
|
|
396
|
+
workflowPresets:
|
|
397
|
+
基础文生图: # 预设名 = 指令里用的名字
|
|
398
|
+
path: data/p-draw/workflows/09-baseline.json
|
|
399
|
+
aliases: [基础, base] # 指令别名(可选)
|
|
400
|
+
positivePromptNodeId: '6' # 节点 ID 可留空,插件会自动识别
|
|
401
|
+
negativePromptNodeId: '7'
|
|
402
|
+
极速4步:
|
|
403
|
+
path: data/p-draw/workflows/03-dmdx.json
|
|
404
|
+
aliases: [极速, fast]
|
|
405
|
+
steps: 4 # 该预设固定步数,覆盖全局与 modelParams
|
|
406
|
+
cfg: 1.0
|
|
407
|
+
overrideParameters: true
|
|
408
|
+
defaultWorkflowPreset: 基础文生图
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### 指令用法
|
|
412
|
+
|
|
413
|
+
```
|
|
414
|
+
画图 --工作流 极速4步:1girl, solo
|
|
415
|
+
画图 极速:1girl, solo # 用别名开头,等效
|
|
416
|
+
画图 工作流 # 列出所有预设及其可用性
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
`画图 工作流` 会逐个体检并给出结论,例如:
|
|
420
|
+
|
|
421
|
+
```
|
|
422
|
+
✅ 基础文生图(别名:基础、base)
|
|
423
|
+
节点 9 个 · 正面 #6 · 负面 #7 · 尺寸 #5
|
|
424
|
+
❌ 图生图(别名:i2i)
|
|
425
|
+
不可用:需要图片输入(LoadImage),当前版本不支持图生图
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
选了不可用的预设会**直接拒绝并说明原因**,不会静默失败或跑错工作流。
|
|
429
|
+
|
|
430
|
+
### 10 个工作流的可用性对照
|
|
431
|
+
|
|
432
|
+
| # | 工作流 | 节点 | 起点 | 当前版本 |
|
|
433
|
+
|---|---|---|---|---|
|
|
434
|
+
| 09 | Text-to-Image Baseline | 17 | 文本 | ✅ 可用 |
|
|
435
|
+
| 03 | DMDX 4-Step Speed Run | 19 | 文本 | ✅ 可用(设 `steps: 4`、低 CFG) |
|
|
436
|
+
| 04 | Three-Stage High-Quality | 26 | 文本 | ✅ 可用(多段采样+放大) |
|
|
437
|
+
| 01 | 1.5x Upscale | 20 | 文本 | ✅ 可用(见下方依赖) |
|
|
438
|
+
| 05 | Tiled Upscale | 45 | 视导出而定 | ⚠️ 同上 |
|
|
439
|
+
| 08 | T2I + ControlNet + Face/Hand Repair | 60 | 文本 + 控制图 | ⚠️ ControlNet 分支需参考图,禁用后方可用 |
|
|
440
|
+
| 02 | ControlNet Precision Control | 32 | 图片 | ❌ 需图生图 |
|
|
441
|
+
| 06 | i2i + ControlNet + Face/Hand Repair | 52 | 图片 | ❌ 需图生图 |
|
|
442
|
+
| 07 | Image-to-Image | 19 | 图片 | ❌ 需图生图 |
|
|
443
|
+
| 10 | Anima-Edit LoRA / IC | 52 | 图片 | ❌ 需图生图 |
|
|
444
|
+
|
|
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。
|
|
461
|
+
|
|
462
|
+
图生图能力(图片上传 + `LoadImage` 注入 + 重绘幅度)尚未实现,所以 ❌ 的四个目前只能等后续版本。
|
|
463
|
+
|
|
353
464
|
## 注意
|
|
354
465
|
|
|
355
466
|
- `p-draw` 指令消耗 `price` P 点,`p-draw 多人` 消耗 `multiPrice` P 点,需要先通过 `p-qiandao` 签到。
|