koishi-plugin-p-draw 1.6.5 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +28 -14
- package/lib/comfy.js +6 -1
- package/package.json +1 -1
- package/readme.md +1 -1
package/index.js
CHANGED
|
@@ -128,7 +128,7 @@ exports.Config = Schema.object({
|
|
|
128
128
|
width: Schema.number().description('默认宽度'),
|
|
129
129
|
height: Schema.number().description('默认高度'),
|
|
130
130
|
}).description('该模型的参数覆盖')).default({}).description('按模型覆盖参数:key=模型文件名,value 只填要覆盖的字段。显式写了的字段会覆盖工作流内取值'),
|
|
131
|
-
}).description('② 模型与采样参数'),
|
|
131
|
+
}).description('② 模型与采样参数').collapse(),
|
|
132
132
|
|
|
133
133
|
prompt: Schema.object({
|
|
134
134
|
qualityPrefix: Schema.string().default('').description('质量词前缀(Aesthetic 1.1 建议留空;Base 模型可填 masterpiece, best quality, score_7)'),
|
|
@@ -138,13 +138,13 @@ exports.Config = Schema.object({
|
|
|
138
138
|
activeArtistPreset: Schema.string().default('').description('启用的画师组名称'),
|
|
139
139
|
artistPresets: Schema.array(Schema.string()).default([]).description('画师组(格式:名称=tags)'),
|
|
140
140
|
fixedCharacters: Schema.array(Schema.string()).default([]).description('固定角色(格式:角色名=tags;仅兼容旧配置,运行时以数据库为准)'),
|
|
141
|
-
}).description('③ 提示词与画师'),
|
|
141
|
+
}).description('③ 提示词与画师').collapse(),
|
|
142
142
|
|
|
143
143
|
queue: Schema.object({
|
|
144
144
|
queueEnabled: Schema.boolean().default(true).description('启用生成队列(逐张顺序执行)'),
|
|
145
145
|
queueMaxRequests: Schema.number().default(5).description('队列最大任务数(0 表示不限制)'),
|
|
146
146
|
batchMax: Schema.number().default(4).description('单次指令最多生成的张数'),
|
|
147
|
-
}).description('④ 队列与批量'),
|
|
147
|
+
}).description('④ 队列与批量').collapse(),
|
|
148
148
|
|
|
149
149
|
pricing: Schema.object({
|
|
150
150
|
price: Schema.number().default(500).description('一张图消耗的 P 点'),
|
|
@@ -152,7 +152,7 @@ exports.Config = Schema.object({
|
|
|
152
152
|
couponPrice: Schema.number().default(3000).description('提示词优化券单价(可被 data/p-shop.json 覆盖)'),
|
|
153
153
|
couponAskTimeout: Schema.number().default(60).description('优化券确认等待时间(秒)'),
|
|
154
154
|
adminUsers: Schema.array(Schema.string()).default([]).description('免 P 点管理员用户 ID'),
|
|
155
|
-
}).description('⑤ P 点与优化券'),
|
|
155
|
+
}).description('⑤ P 点与优化券').collapse(),
|
|
156
156
|
|
|
157
157
|
access: Schema.object({
|
|
158
158
|
adminOnly: Schema.boolean().default(false).description('仅管理员可用'),
|
|
@@ -161,7 +161,7 @@ exports.Config = Schema.object({
|
|
|
161
161
|
allowedGroupIds: Schema.array(Schema.string()).default([]).description('群白名单(留空不限制)'),
|
|
162
162
|
blockedGroupIds: Schema.array(Schema.string()).default([]).description('群黑名单(优先于白名单)'),
|
|
163
163
|
outputLogs: Schema.boolean().default(true).description('输出详细日志'),
|
|
164
|
-
}).description('⑥ 权限与日志'),
|
|
164
|
+
}).description('⑥ 权限与日志').collapse(),
|
|
165
165
|
|
|
166
166
|
workflow: Schema.object({
|
|
167
167
|
customWorkflowEnabled: Schema.boolean().default(false).description('使用自定义 ComfyUI 工作流 JSON'),
|
|
@@ -189,6 +189,7 @@ exports.Config = Schema.object({
|
|
|
189
189
|
samplerName: Schema.string().description('该预设固定采样器'),
|
|
190
190
|
scheduler: Schema.string().description('该预设固定调度器'),
|
|
191
191
|
overrideParameters: Schema.boolean().description('用上面的参数覆盖工作流内取值'),
|
|
192
|
+
price: Schema.number().description('该预设每张消耗的 P 点(留空沿用全局 price / multiPrice)'),
|
|
192
193
|
overrideModel: Schema.boolean().description('是否把 unetName 写进这个工作流的模型节点(留空沿用全局)'),
|
|
193
194
|
modelLoaderNodeId: Schema.string().description('该预设的模型加载节点 ID(留空沿用全局)'),
|
|
194
195
|
}).description('预设')).default({}).description('工作流预设:key=预设名。指令里用 `--工作流 <名称>` 或名称/别名开头选择(如 `画图 极速:1girl`)'),
|
|
@@ -414,6 +415,13 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
414
415
|
return out
|
|
415
416
|
}
|
|
416
417
|
|
|
418
|
+
// 预设可以单独定价;没配就回落到全局 price / multiPrice
|
|
419
|
+
function presetPrice(preset) {
|
|
420
|
+
if (!preset || preset.price === undefined || preset.price === null || preset.price === '') return null
|
|
421
|
+
const value = Number(preset.price)
|
|
422
|
+
return Number.isFinite(value) && value >= 0 ? value : null
|
|
423
|
+
}
|
|
424
|
+
|
|
417
425
|
// 体检:这个预设现在能不能真的跑(能否从纯文本启动)
|
|
418
426
|
function inspectPreset(preset) {
|
|
419
427
|
return inspectWorkflowFile(preset.path, {
|
|
@@ -643,7 +651,9 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
643
651
|
for (const preset of presets) {
|
|
644
652
|
const report = inspectPreset(preset)
|
|
645
653
|
const aliases = (preset.aliases || []).length ? `(别名:${preset.aliases.join('、')})` : ''
|
|
646
|
-
|
|
654
|
+
const unit = presetPrice(preset)
|
|
655
|
+
const priceTag = unit != null ? ` ${unit} P/张` : ' 默认价'
|
|
656
|
+
lines.push(`${report.ok ? '✅' : '❌'} ${preset.name}${aliases}${priceTag}`)
|
|
647
657
|
if (report.ok) {
|
|
648
658
|
const analysis = report.analysis
|
|
649
659
|
const pos = report.targets.positive.map(id => `#${id}`).join('、')
|
|
@@ -1725,7 +1735,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
1725
1735
|
const USERID = session.userId
|
|
1726
1736
|
const isAdmin = isAdminUser(session)
|
|
1727
1737
|
const unet = await resolveUnet(USERID)
|
|
1728
|
-
|
|
1738
|
+
let price = Math.max(0, parseInt(cfg.multiPrice) || cfg.price)
|
|
1729
1739
|
if (cfg.outputLogs) {
|
|
1730
1740
|
logger.info(`[p-draw] 多人请求 userId=${USERID} isAdmin=${isAdmin}`)
|
|
1731
1741
|
}
|
|
@@ -1751,6 +1761,8 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
1751
1761
|
if (usable.ok) activePreset = usable.preset
|
|
1752
1762
|
else if (cfg.outputLogs) logger.warn(`[p-draw] 默认预设不可用,已回落:${usable.message}`)
|
|
1753
1763
|
}
|
|
1764
|
+
const presetUnitPrice = presetPrice(activePreset)
|
|
1765
|
+
if (presetUnitPrice != null) price = presetUnitPrice
|
|
1754
1766
|
const text = parsedPreset.prompt
|
|
1755
1767
|
if (!text) return session.text('.multi-usage')
|
|
1756
1768
|
const count = parsedBatch.count
|
|
@@ -2231,6 +2243,8 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2231
2243
|
const text = parsedPreset.prompt
|
|
2232
2244
|
const seed = parsedSeed.seed
|
|
2233
2245
|
const count = parsedBatch.count
|
|
2246
|
+
// 预设可单独定价,未配置则用全局 price
|
|
2247
|
+
const unitPrice = presetPrice(activePreset) ?? Math.max(0, Number(cfg.price) || 0)
|
|
2234
2248
|
// 命令级参数优先于预设 / modelParams / 全局配置(见 runComfyGenerate)
|
|
2235
2249
|
const tuningOverrides = Object.assign(
|
|
2236
2250
|
activePreset ? { preset: activePreset } : {},
|
|
@@ -2243,7 +2257,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2243
2257
|
|
|
2244
2258
|
// P 点校验(按总价 = 张数 × 单价)
|
|
2245
2259
|
// P 点校验(按总价 = 张数 × 单价)
|
|
2246
|
-
const pcheck = await precheckPoints(session, USERID, isAdmin, count *
|
|
2260
|
+
const pcheck = await precheckPoints(session, USERID, isAdmin, count * unitPrice)
|
|
2247
2261
|
if (!pcheck.ok) return pcheck.message
|
|
2248
2262
|
|
|
2249
2263
|
// 原样模式
|
|
@@ -2333,8 +2347,8 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2333
2347
|
|
|
2334
2348
|
// 扣 P 点(一次性扣除总价)
|
|
2335
2349
|
if (!isAdmin) {
|
|
2336
|
-
const saving = await deductP(USERID, count *
|
|
2337
|
-
if (cfg.outputLogs) logger.info(`[p-draw] ${USERID} 已扣除 ${count *
|
|
2350
|
+
const saving = await deductP(USERID, count * unitPrice)
|
|
2351
|
+
if (cfg.outputLogs) logger.info(`[p-draw] ${USERID} 已扣除 ${count * unitPrice} P 点(${count} 张 × ${unitPrice}),余额 ${saving - count * unitPrice}`)
|
|
2338
2352
|
}
|
|
2339
2353
|
|
|
2340
2354
|
// 用户手写了 negative: 区块时,默认负面词仍保留;用户 tag 只补充未出现的部分。
|
|
@@ -2356,7 +2370,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2356
2370
|
}
|
|
2357
2371
|
const generated = await runComfyGenerate(p, parsedSize.size, generationOverrides)
|
|
2358
2372
|
return { ...generated, prompt: p }
|
|
2359
|
-
}, { USERID, isAdmin, totalPrice: count *
|
|
2373
|
+
}, { USERID, isAdmin, totalPrice: count * unitPrice })
|
|
2360
2374
|
if (!queued.ok) return queued.message
|
|
2361
2375
|
const queuedTasks = queued.tasks
|
|
2362
2376
|
const firstPosition = queued.firstPosition
|
|
@@ -2399,7 +2413,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2399
2413
|
return result
|
|
2400
2414
|
}
|
|
2401
2415
|
|
|
2402
|
-
const { results, successCount } = await executeBatch(USERID, isAdmin, count,
|
|
2416
|
+
const { results, successCount } = await executeBatch(USERID, isAdmin, count, unitPrice, runOne)
|
|
2403
2417
|
|
|
2404
2418
|
// 汇总
|
|
2405
2419
|
const allOutputs = []
|
|
@@ -2418,7 +2432,7 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2418
2432
|
|
|
2419
2433
|
const chargeNotice = buildChargeNotice({
|
|
2420
2434
|
isAdmin,
|
|
2421
|
-
totalPrice: successCount *
|
|
2435
|
+
totalPrice: successCount * unitPrice,
|
|
2422
2436
|
unetName: unet,
|
|
2423
2437
|
seeds,
|
|
2424
2438
|
})
|
|
@@ -2580,5 +2594,5 @@ exports.apply = async function apply(ctx, rawConfig) {
|
|
|
2580
2594
|
})
|
|
2581
2595
|
|
|
2582
2596
|
// 暴露内部接口供自动化测试调用(Koishi 忽略 apply 返回值,不影响生产行为)
|
|
2583
|
-
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch, composePrompt, shouldSkipQualityPrefix, qualityPrefixWarning, customWorkflowDiagLines, diagnoseText, workflowDir, normalizeConfig, presetList, presetOverviewText }
|
|
2597
|
+
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch, composePrompt, shouldSkipQualityPrefix, qualityPrefixWarning, customWorkflowDiagLines, diagnoseText, workflowDir, normalizeConfig, presetList, presetOverviewText, presetPrice }
|
|
2584
2598
|
}
|
package/lib/comfy.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// ComfyUI 结果等待与输出提取。
|
|
2
2
|
// waitComfyResult 依赖一个注入的 comfyGet(由 http 客户端提供),可独立单测。
|
|
3
3
|
|
|
4
|
+
// 从 /history 结果里取出图片。
|
|
5
|
+
// PreviewImage 之类的节点会产出 type='temp' 的临时预览图(修脸修手工作流一次能有十几张),
|
|
6
|
+
// 这些不该发给用户;优先只取 SaveImage 的 type='output'。
|
|
7
|
+
// 若整条工作流只有预览节点、没有 SaveImage,则退回取全部,避免什么都取不到。
|
|
4
8
|
function outputImages(history) {
|
|
5
9
|
const images = []
|
|
6
10
|
const outputs = history.outputs || {}
|
|
@@ -12,7 +16,8 @@ function outputImages(history) {
|
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
|
-
|
|
19
|
+
const finals = images.filter(image => image.type !== 'temp')
|
|
20
|
+
return finals.length ? finals : images
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
// ------------------------------------------------------------------
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -436,7 +436,7 @@ defaultWorkflowPreset: 基础文生图
|
|
|
436
436
|
| 04 | Three-Stage High-Quality | 26 | 文本 | ✅ 可用(多段采样+放大) |
|
|
437
437
|
| 01 | 1.5x Upscale | 20 | 文本 | ✅ 可用(见下方依赖) |
|
|
438
438
|
| 05 | Tiled Upscale | 45 | 视导出而定 | ⚠️ 同上 |
|
|
439
|
-
| 08 | T2I + ControlNet + Face/Hand Repair | 60 | 文本 + 控制图 |
|
|
439
|
+
| 08 | T2I + ControlNet + Face/Hand Repair | 60 | 文本 + 控制图 | ✅ 可用(已裁成单输出;ControlNet 分支默认旁路,需检测器 + SAM 模型) |
|
|
440
440
|
| 02 | ControlNet Precision Control | 32 | 图片 | ❌ 需图生图 |
|
|
441
441
|
| 06 | i2i + ControlNet + Face/Hand Repair | 52 | 图片 | ❌ 需图生图 |
|
|
442
442
|
| 07 | Image-to-Image | 19 | 图片 | ❌ 需图生图 |
|