@goodandready/dsh-image-gen 0.10.31 → 0.10.33

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/README.md CHANGED
@@ -123,6 +123,11 @@
123
123
  ## 🛠️ Complete Tools Reference
124
124
 
125
125
  * **`generate_image`**: Generate images with pluggable providers, seeds, aspect ratios, and style presets.
126
+ * **`set_style_anchor` (#283)**: Lock session visual identity (subject, outfit, medium, color palette, lighting) for consistent multi-turn generation.
127
+ * **`generate_ui_asset` (#284)**: Layout-aware UI asset generator for icons, stickers, badges, spot graphics, and heroes with negative space constraints (`isolated`, `centered`, `left_empty`, `right_empty`, `top_empty`, `bottom_empty`) and auto-transparency.
128
+ * **`generate_style_matrix` (#286)**: 2x2 visual benchmarking matrix exploring 4 aesthetic presets simultaneously with blind compare mode and 1-click style preset adoption.
129
+ * **`In-Chat Inpainting Canvas` (#285)**: Interactive brush overlay and mask drawer mounted directly over image message cards in chat.
130
+ * **`Smart Provider Fallback Chain` (#282)**: Intelligent cascading failover across providers on 429, 5xx, timeouts, or depleted balance.
126
131
  * **`edit_image`**: Targeted inpainting and modification with automatic session reference resolution (#142, #144, #145).
127
132
  * **`vary_image`**: Controlled variation generation preserving composition (#143, #144).
128
133
  * **`remove_background`**: Extract subject with transparent PNG output (FAL BiRefNet / Rembg).
package/README.ru.md CHANGED
@@ -163,6 +163,9 @@ graph LR
163
163
  | Инструмент | Назначение | Ключевые параметры |
164
164
  |---|---|---|
165
165
  | **`generate_image`** | Генерация изображения по тексту | `prompt`, `image_size`, `seed`, `style`, `negative_prompt`, `count` |
166
+ | **`set_style_anchor`** | Фиксация визуального стиля и персонажа сессии (объект, костюм, палитра, свет) (#283) | `mode` (`character`/`style`), `image`, `description`, `strength`, `clear` |
167
+ | **`generate_ui_asset`** | Генерация интерфейсных ассетов с контролем свободного пространства и авто-прозрачностью (#284) | `prompt`, `asset_type`, `layout_composition`, `transparent`, `output_format` |
168
+ | **`generate_style_matrix`** | Сетка 2x2 для одновременного бенчмаркинга концепта в 4 стилях со слепым сравнением (#286) | `prompt`, `styles`, `blind_mode`, `output_format` |
166
169
  | **`edit_image`** | Направленное редактирование / inpainting с авто-поиском оригинала (#142, #144, #145) | `prompt`, `image` (по умолч. `latest`), `mask`, `strength` |
167
170
  | **`vary_image`** | Генерация вариаций существующей картинки (#143, #144) | `image` (по умолч. `latest`), `prompt`, `variation_strength` (0.1–0.9), `count` |
168
171
  | **`remove_background`** | Удаление фона с сохранением прозрачного PNG | `image`, `model`, `output_name` |
package/README.zh.md CHANGED
@@ -113,4 +113,12 @@ dsh plugin --profile web add @goodandready/dsh-image-gen
113
113
 
114
114
  ## 📄 许可证
115
115
 
116
- MIT © [GooDAnDReaDY](https://github.com/GooDAnDReaDY)
116
+ MIT © [GooDAnDReaDY](https://github.com/GooDAnDReaDY)
117
+
118
+ ## 🛠️ 新增核心功能 (v0.10.32)
119
+
120
+ * **`set_style_anchor` (#283)**: 会话级角色与风格参考锚点,在连续对话中锁定主体、配色、光照与渲染媒介。
121
+ * **`generate_ui_asset` (#284)**: 布局感知与留白控制 UI 资产生成器,支持精准留白(`isolated`、`centered`、`left_empty`、`right_empty`、`top_empty`、`bottom_empty`)与自动透明通道。
122
+ * **`generate_style_matrix` (#286)**: 2x2 风格矩阵探索与双盲对比,并发生成 4 种美学预设切片并支持一键应用。
123
+ * **`对话内局部重绘画布` (#285)**: 在消息卡片上直接唤起交互式笔刷画布,支持选区涂抹与即时 Inpainting 局部重绘。
124
+ * **`智能服务商自动故障转移链` (#282)**: 主服务商 429、5xx、超时或额度耗尽时自动无缝切换备选渠道。
@@ -0,0 +1,103 @@
1
+ // anchor-helpers.js — Character & Style Reference Anchor manager (#283).
2
+ // Maintains active visual identity and style reference across multi-turn sessions.
3
+
4
+ /**
5
+ * In-memory registry of active visual anchors keyed by scopeId (e.g. session id).
6
+ * Structure: Map<string, { image: string, label: string, mode: 'character'|'style', strength: number, updatedAt: string }>
7
+ */
8
+ const sessionAnchors = new Map()
9
+
10
+ /**
11
+ * Normalizes anchor strength between 0.1 and 1.0.
12
+ *
13
+ * @param {number|undefined} val
14
+ * @returns {number}
15
+ */
16
+ export function normalizeAnchorStrength(val) {
17
+ if (typeof val !== 'number' || Number.isNaN(val)) return 0.65
18
+ return Math.min(1.0, Math.max(0.1, Number(val.toFixed(2))))
19
+ }
20
+
21
+ /**
22
+ * Sets or updates the active visual anchor for a given session or scope.
23
+ *
24
+ * @param {string} scopeId Session or workspace identifier
25
+ * @param {object} data
26
+ * @param {string} data.image Image URL, attachment ID (sha256:...), or local path
27
+ * @param {string} [data.label] Human-readable description of character/style
28
+ * @param {'character'|'style'} [data.mode='style']
29
+ * @param {number} [data.strength=0.65]
30
+ * @returns {object} The stored anchor record
31
+ */
32
+ export function setSessionAnchor(scopeId, data = {}) {
33
+ const key = String(scopeId || 'default')
34
+ if (!data.image) {
35
+ throw new Error('An anchor image (URL, path, or attachment ID) is required.')
36
+ }
37
+
38
+ const mode = data.mode === 'character' ? 'character' : 'style'
39
+ const strength = normalizeAnchorStrength(data.strength)
40
+ const label = String(data.label || (mode === 'character' ? 'Character Anchor' : 'Style Anchor')).trim()
41
+
42
+ const anchor = {
43
+ image: String(data.image).trim(),
44
+ label,
45
+ mode,
46
+ strength,
47
+ updatedAt: new Date().toISOString(),
48
+ }
49
+
50
+ sessionAnchors.set(key, anchor)
51
+ return anchor
52
+ }
53
+
54
+ /**
55
+ * Retrieves the currently active visual anchor for a session scope.
56
+ *
57
+ * @param {string} scopeId
58
+ * @returns {object|null}
59
+ */
60
+ export function getSessionAnchor(scopeId) {
61
+ const key = String(scopeId || 'default')
62
+ return sessionAnchors.get(key) || null
63
+ }
64
+
65
+ /**
66
+ * Clears the active visual anchor for a session scope.
67
+ *
68
+ * @param {string} scopeId
69
+ * @returns {boolean} True if an anchor was present and removed
70
+ */
71
+ export function clearSessionAnchor(scopeId) {
72
+ const key = String(scopeId || 'default')
73
+ return sessionAnchors.delete(key)
74
+ }
75
+
76
+ /**
77
+ * Clears all active anchors (for testing/cleanup).
78
+ */
79
+ export function clearAllAnchors() {
80
+ sessionAnchors.clear()
81
+ }
82
+
83
+ /**
84
+ * Injects anchor reference hints into the prompt if an anchor is active and not already included.
85
+ *
86
+ * @param {object|null} anchor
87
+ * @param {string} prompt
88
+ * @returns {string}
89
+ */
90
+ export function applyAnchorPromptHints(anchor, prompt) {
91
+ if (!anchor || !anchor.label) return prompt
92
+ const lower = prompt.toLowerCase()
93
+ const labelLower = anchor.label.toLowerCase()
94
+
95
+ // Avoid duplicate injection if user already mentioned the anchor label
96
+ if (lower.includes(labelLower)) return prompt
97
+
98
+ if (anchor.mode === 'character') {
99
+ return `${prompt}, visual character anchor: ${anchor.label}, maintaining consistent facial features, costume, and physical identity`
100
+ }
101
+
102
+ return `${prompt}, visual style anchor: ${anchor.label}, maintaining consistent aesthetic palette, rendering technique, and lighting`
103
+ }