koishi-plugin-p-draw 1.5.5 → 1.5.7

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.
Files changed (3) hide show
  1. package/index.js +36 -23
  2. package/package.json +1 -1
  3. package/readme.md +1 -0
package/index.js CHANGED
@@ -478,13 +478,16 @@ exports.apply = async function apply(ctx, cfg) {
478
478
  return `已扣除 ${totalPrice} P 点,${modelSeed}`
479
479
  }
480
480
 
481
- function buildGenerationReply(session, { successCount, count, failures, notes = [], chargeNotice = '' }) {
482
- const reply = []
483
- if (chargeNotice) reply.push(chargeNotice)
484
- if (notes.length) reply.push(notes.join('\n'))
485
- if (failures.length) reply.push(session.text('.batch-partial', [successCount, count, failures.length, failures.join(';')]))
481
+ function buildGenerationReply(session, { successCount, count, failures, notes = [] }) {
482
+ const reply = []
483
+ if (notes.length) reply.push(notes.join('\n'))
484
+ if (failures.length) reply.push(session.text('.batch-partial', [successCount, count, failures.length, failures.join(';')]))
486
485
  return reply.filter(Boolean).join('\n')
487
486
  }
487
+
488
+ function shouldOptimizePerImage({ count, enabled, admin }) {
489
+ return count > 1 && (enabled || admin)
490
+ }
488
491
 
489
492
  async function sendNotices(session, notices, opts = {}) {
490
493
  const content = notices.filter(Boolean).join('\n')
@@ -1492,10 +1495,12 @@ exports.apply = async function apply(ctx, cfg) {
1492
1495
  // 发图:合并转发,不引用原指令
1493
1496
  await sendImagesAsForward(session, forwardOutputs)
1494
1497
 
1495
- return buildGenerationReply(session, { successCount, count, failures, notes, chargeNotice })
1498
+ await sendNotices(session, [chargeNotice])
1499
+
1500
+ return buildGenerationReply(session, { successCount, count, failures, notes })
1496
1501
  }
1497
1502
 
1498
- // ---------------- 权限 ----------------
1503
+ // ---------------- 权限 ----------------
1499
1504
  function readableOptimizeReason(reason) {
1500
1505
  if (!reason) return ''
1501
1506
  if (reason === 'llm_not_configured') return '(未配置 LLM 模型名或接口地址)'
@@ -1865,19 +1870,25 @@ exports.apply = async function apply(ctx, cfg) {
1865
1870
  if (!raw) {
1866
1871
  const globalOpt = cfg.promptOptimizeEnabled
1867
1872
  const adminOpt = !globalOpt && isAdmin && cfg.llmModel && cfg.llmBaseUrl
1868
- const tokenOpt = !globalOpt && !isAdmin && cfg.llmModel && cfg.llmBaseUrl
1869
- if (globalOpt) {
1870
- // 全局优化开启:一次优化,整批复用同一提示词
1871
- const optimized = await optimizePrompt(session, userPrompt, false)
1872
- finalPrompt = optimized.prompt
1873
- degraded = !optimized.ok
1874
- optimizedReason = optimized.reason || ''
1875
- } else if (adminOpt) {
1876
- // 管理员在全局关闭时也免费优化(不耗券)
1877
- const optimized = await optimizePrompt(session, userPrompt, true)
1878
- finalPrompt = optimized.prompt
1879
- degraded = !optimized.ok
1880
- optimizedReason = optimized.reason || ''
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
+ }
1881
1892
  } else if (tokenOpt) {
1882
1893
  // 全局优化关闭:使用 p-shop 的「提示词优化券」(p_system.llmToken)。
1883
1894
  // 券一次性,按张数扣:x3 扣 3 张,每张图独立做一次 LLM 优化。
@@ -2020,8 +2031,10 @@ exports.apply = async function apply(ctx, cfg) {
2020
2031
  // 发图:合并转发,不引用原指令
2021
2032
  await sendImagesAsForward(session, forwardOutputs)
2022
2033
 
2023
- return buildGenerationReply(session, { successCount, count, failures, chargeNotice })
2024
- }
2034
+ await sendNotices(session, [chargeNotice])
2035
+
2036
+ return buildGenerationReply(session, { successCount, count, failures })
2037
+ }
2025
2038
  // ---------------- 提示词优化券交互式确认 ----------------
2026
2039
  // 仅全局优化关闭 + 非管理员 + 已配置 LLM(tokenOpt 分支)时进入。
2027
2040
  // 返回:{ cancelled, tokenUsedCount, perImageOptimize, noOptimizeReason }
@@ -2166,5 +2179,5 @@ exports.apply = async function apply(ctx, cfg) {
2166
2179
  })
2167
2180
 
2168
2181
  // 暴露内部接口供自动化测试调用(Koishi 忽略 apply 返回值,不影响生产行为)
2169
- return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, sendNotices, sendImagesAsForward, executeBatch }
2182
+ return { couponConfirmFlow, buyCouponsAndConsume, normalizeConfirm, resolveCouponPrice, buildChargeNotice, buildGenerationReply, shouldOptimizePerImage, sendNotices, sendImagesAsForward, executeBatch }
2170
2183
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-p-draw",
3
3
  "description": "p点-绘图,连接本地 ComfyUI 生图。支持自然语言优化、尺寸选择、画师组、固定角色、生成队列,需要配合 p-qiandao 使用",
4
- "version": "1.5.5",
4
+ "version": "1.5.7",
5
5
  "main": "index.js",
6
6
  "files": [
7
7
  "index.js",
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