koishi-plugin-p-draw 1.5.6 → 1.5.8
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 +29 -18
- package/package.json +1 -1
- package/readme.md +1 -0
package/index.js
CHANGED
|
@@ -174,8 +174,7 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
174
174
|
// 用户自选模型偏好(userid -> unet 文件名),持久化在 p_draw_config.user_models
|
|
175
175
|
if (!cfg.userModels || typeof cfg.userModels !== 'object') cfg.userModels = {}
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
// 启动时清理上次运行遗留的临时文件
|
|
177
|
+
// 启动时清理上次运行遗留的临时目录(先清理,再创建本次目录)
|
|
179
178
|
try {
|
|
180
179
|
const leftovers = fs.readdirSync(os.tmpdir()).filter((n) => n.startsWith('pdraw-'))
|
|
181
180
|
for (const name of leftovers) {
|
|
@@ -187,6 +186,8 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
187
186
|
}
|
|
188
187
|
} catch (e) { /* ignore */ }
|
|
189
188
|
|
|
189
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pdraw-'))
|
|
190
|
+
|
|
190
191
|
const baseUrl = () => normalizeBaseUrl(cfg.comfyuiBaseUrl)
|
|
191
192
|
|
|
192
193
|
function parseAllowedSizes() {
|
|
@@ -478,11 +479,15 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
478
479
|
return `已扣除 ${totalPrice} P 点,${modelSeed}`
|
|
479
480
|
}
|
|
480
481
|
|
|
481
|
-
function buildGenerationReply(session, { successCount, count, failures, notes = [] }) {
|
|
482
|
+
function buildGenerationReply(session, { successCount, count, failures, notes = [] }) {
|
|
482
483
|
const reply = []
|
|
483
484
|
if (notes.length) reply.push(notes.join('\n'))
|
|
484
485
|
if (failures.length) reply.push(session.text('.batch-partial', [successCount, count, failures.length, failures.join(';')]))
|
|
485
|
-
return reply.filter(Boolean).join('\n')
|
|
486
|
+
return reply.filter(Boolean).join('\n')
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function shouldOptimizePerImage({ count, enabled, admin }) {
|
|
490
|
+
return count > 1 && (enabled || admin)
|
|
486
491
|
}
|
|
487
492
|
|
|
488
493
|
async function sendNotices(session, notices, opts = {}) {
|
|
@@ -1866,19 +1871,25 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
1866
1871
|
if (!raw) {
|
|
1867
1872
|
const globalOpt = cfg.promptOptimizeEnabled
|
|
1868
1873
|
const adminOpt = !globalOpt && isAdmin && cfg.llmModel && cfg.llmBaseUrl
|
|
1869
|
-
const tokenOpt = !globalOpt && !isAdmin && cfg.llmModel && cfg.llmBaseUrl
|
|
1870
|
-
if (globalOpt) {
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1874
|
+
const tokenOpt = !globalOpt && !isAdmin && cfg.llmModel && cfg.llmBaseUrl
|
|
1875
|
+
if (globalOpt) {
|
|
1876
|
+
if (shouldOptimizePerImage({ count, enabled: true, admin: false })) {
|
|
1877
|
+
perImageOptimize = true
|
|
1878
|
+
} else {
|
|
1879
|
+
const optimized = await optimizePrompt(session, userPrompt, false)
|
|
1880
|
+
finalPrompt = optimized.prompt
|
|
1881
|
+
degraded = !optimized.ok
|
|
1882
|
+
optimizedReason = optimized.reason || ''
|
|
1883
|
+
}
|
|
1884
|
+
} else if (adminOpt) {
|
|
1885
|
+
if (shouldOptimizePerImage({ count, enabled: false, admin: true })) {
|
|
1886
|
+
perImageOptimize = true
|
|
1887
|
+
} else {
|
|
1888
|
+
const optimized = await optimizePrompt(session, userPrompt, true)
|
|
1889
|
+
finalPrompt = optimized.prompt
|
|
1890
|
+
degraded = !optimized.ok
|
|
1891
|
+
optimizedReason = optimized.reason || ''
|
|
1892
|
+
}
|
|
1882
1893
|
} else if (tokenOpt) {
|
|
1883
1894
|
// 全局优化关闭:使用 p-shop 的「提示词优化券」(p_system.llmToken)。
|
|
1884
1895
|
// 券一次性,按张数扣:x3 扣 3 张,每张图独立做一次 LLM 优化。
|
|
@@ -2169,5 +2180,5 @@ exports.apply = async function apply(ctx, cfg) {
|
|
|
2169
2180
|
})
|
|
2170
2181
|
|
|
2171
2182
|
// 暴露内部接口供自动化测试调用(Koishi 忽略 apply 返回值,不影响生产行为)
|
|
2172
|
-
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, sendNotices, sendImagesAsForward, executeBatch }
|
|
2183
|
+
return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch }
|
|
2173
2184
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -21,6 +21,7 @@ p点-绘图插件,连接本地 ComfyUI 生图,参考 AstrBot 的 [anima 绘
|
|
|
21
21
|
- `p-draw 状态` 查看 ComfyUI 连接状态与模型可用性。
|
|
22
22
|
- `p-draw help`(或 `帮助`)查看全部指令帮助,包含生成 / 多人 / 批量张数 / 尺寸 / 画师组 / 状态等。
|
|
23
23
|
- 发图时会以合并转发发送,每张图片后附对应的 Positive / Negative 提示词;生成完成消息会显示实际模型和 seed(如 `已扣除 750 P 点,当前模型:animagine-xl-3.1.safetensors,--seed=123456`)。管理员/免扣费用户不显示扣费金额,但仍显示模型和 seed。
|
|
24
|
+
- 批量生成(如 `x5` / `x10`)开启 LLM 优化时,每张图会在生成前单独重新优化一次提示词;因此 `random color hair`、`random color eyes` 等动态要求可以在不同图片中产生不同结果。
|
|
24
25
|
|
|
25
26
|
## 安装
|
|
26
27
|
|