@dickpy/dsh-imagegen 1.3.0 → 1.4.0

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 (45) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +203 -182
  3. package/cordis.patch.yml +8 -8
  4. package/docs/images/multi-model-comparison.png +0 -0
  5. package/lib/client.js +1103 -837
  6. package/lib/client.js.map +1 -1
  7. package/lib/index.js +265 -135
  8. package/package.json +70 -68
  9. package/src/agent-image-tools.ts +418 -418
  10. package/src/client/ImageGenPanel.tsx +1699 -1508
  11. package/src/client/SettingsCard.tsx +936 -957
  12. package/src/client/TemplateLibrary.tsx +336 -336
  13. package/src/client/api.ts +193 -193
  14. package/src/client/channels-form.ts +263 -263
  15. package/src/client/controller.ts +46 -46
  16. package/src/client/conversation-sync.ts +14 -0
  17. package/src/client/css-modules.d.ts +5 -5
  18. package/src/client/helpers.ts +33 -33
  19. package/src/client/image-toolview.module.css +73 -73
  20. package/src/client/image-toolview.tsx +169 -158
  21. package/src/client/index.ts +32 -22
  22. package/src/client/locales.ts +610 -594
  23. package/src/client/mount.tsx +185 -96
  24. package/src/client/panel.module.css +1713 -1445
  25. package/src/client/settings-card.module.css +1023 -1023
  26. package/src/client/settings-form.ts +336 -336
  27. package/src/client/settings-scope.ts +298 -298
  28. package/src/client/sidebar-entry.ts +148 -102
  29. package/src/client/templates.module.css +453 -453
  30. package/src/engine.ts +520 -478
  31. package/src/gallery-store.ts +286 -286
  32. package/src/generation-runtime.ts +79 -75
  33. package/src/history-store.ts +250 -244
  34. package/src/image-format.ts +11 -11
  35. package/src/image-models.ts +19 -19
  36. package/src/index.ts +318 -318
  37. package/src/model-catalog.ts +115 -98
  38. package/src/presets.ts +71 -63
  39. package/src/prompt-enhancer.ts +137 -79
  40. package/src/protocol.ts +338 -326
  41. package/src/routes.ts +916 -906
  42. package/src/task-queue.ts +113 -103
  43. package/src/templates/cases.json +10196 -10196
  44. package/src/templates-store.ts +278 -278
  45. package/src/updater.ts +117 -117
@@ -1,244 +1,250 @@
1
- /**
2
- * Host-persisted generation history: images are stored as individual files
3
- * under ~/.dsh/dsh-imagegen/images/ and an index.json keeps the metadata +
4
- * file names. This makes the history survive across browsers/devices that
5
- * connect to the same DSH host, and keeps list responses small (the browser
6
- * loads image bytes lazily through the history image route).
7
- *
8
- * Framework-free (node:fs only) so the route layer can drive it directly.
9
- */
10
-
11
- import { promises as fs } from 'node:fs'
12
- import { homedir } from 'node:os'
13
- import path from 'node:path'
14
- import { HISTORY_MAX, type GenerateMode, type HistoryEntry, type HistoryEntryInput } from './protocol.ts'
15
-
16
- const HISTORY_DIR = path.join(homedir(), '.dsh', 'dsh-imagegen')
17
- const INDEX_PATH = path.join(HISTORY_DIR, 'index.json')
18
- const IMAGES_DIR = path.join(HISTORY_DIR, 'images')
19
-
20
- // History mutations read and replace one shared index. Serialize them so
21
- // overlapping requests cannot each read an old index and lose the other's row.
22
- let pendingMutation: Promise<void> = Promise.resolve()
23
-
24
- function mutateHistory<T>(operation: () => Promise<T>): Promise<T> {
25
- const next = pendingMutation.then(operation, operation)
26
- pendingMutation = next.then(() => undefined, () => undefined)
27
- return next
28
- }
29
-
30
- /** One image's on-disk record (file name + mime, never base64). */
31
- interface StoredImage {
32
- file: string
33
- mime: string
34
- revisedPrompt?: string
35
- }
36
-
37
- /** One entry's on-disk record. */
38
- interface StoredEntry {
39
- id: string
40
- createdAt: number
41
- mode: GenerateMode
42
- model: string
43
- prompt: string
44
- size: string
45
- quality: string
46
- detail: string
47
- n: number
48
- images: StoredImage[]
49
- refName?: string
50
- channelId?: string
51
- channel?: string
52
- }
53
-
54
- /** The index.json shape. */
55
- interface IndexFile {
56
- entries: StoredEntry[]
57
- }
58
-
59
- /** File extension for a MIME type (image file names). */
60
- function extensionOf(mime: string): string {
61
- switch (mime.split(';')[0]!.trim()) {
62
- case 'image/jpeg': return 'jpg'
63
- case 'image/webp': return 'webp'
64
- case 'image/gif': return 'gif'
65
- default: return 'png'
66
- }
67
- }
68
-
69
- /** MIME type for a stored image file name (image route responses). */
70
- function mimeOfFile(file: string): string {
71
- const ext = path.extname(file).toLowerCase()
72
- switch (ext) {
73
- case '.jpg':
74
- case '.jpeg': return 'image/jpeg'
75
- case '.webp': return 'image/webp'
76
- case '.gif': return 'image/gif'
77
- default: return 'image/png'
78
- }
79
- }
80
-
81
- /** Sanitize an entry id for use as a file-name prefix. */
82
- function safeId(id: string): string {
83
- const cleaned = id.replace(/[^a-zA-Z0-9-]/g, '-')
84
- return cleaned === '' ? 'entry' : cleaned
85
- }
86
-
87
- /** Ensure the storage directories exist. */
88
- async function ensureDirs(): Promise<void> {
89
- await fs.mkdir(IMAGES_DIR, { recursive: true })
90
- }
91
-
92
- /** Read the index, tolerating a missing/corrupt file. */
93
- async function readIndex(): Promise<StoredEntry[]> {
94
- try {
95
- const raw = await fs.readFile(INDEX_PATH, 'utf8')
96
- const parsed: unknown = JSON.parse(raw)
97
- if (parsed === null || typeof parsed !== 'object') return []
98
- const entries = (parsed as { entries?: unknown }).entries
99
- if (!Array.isArray(entries)) return []
100
- return entries.filter(isStoredEntry)
101
- } catch {
102
- return []
103
- }
104
- }
105
-
106
- /** Persist the index. */
107
- async function writeIndex(entries: StoredEntry[]): Promise<void> {
108
- await ensureDirs()
109
- const payload: IndexFile = { entries }
110
- const tmp = `${INDEX_PATH}.tmp-${process.pid}`
111
- await fs.writeFile(tmp, JSON.stringify(payload), 'utf8')
112
- await fs.rename(tmp, INDEX_PATH)
113
- }
114
-
115
- /** Structural guard for a stored entry. */
116
- function isStoredEntry(value: unknown): value is StoredEntry {
117
- if (value === null || typeof value !== 'object') return false
118
- const entry = value as Record<string, unknown>
119
- return typeof entry.id === 'string'
120
- && typeof entry.createdAt === 'number'
121
- && (entry.mode === 'text' || entry.mode === 'edit')
122
- && typeof entry.prompt === 'string'
123
- && Array.isArray(entry.images)
124
- && entry.images.every(image => {
125
- if (image === null || typeof image !== 'object') return false
126
- const record = image as Record<string, unknown>
127
- return typeof record.file === 'string' && typeof record.mime === 'string'
128
- })
129
- }
130
-
131
- /** Remove one entry's image files (best effort). */
132
- async function removeEntryFiles(entry: StoredEntry): Promise<void> {
133
- for (const image of entry.images) {
134
- try { await fs.rm(path.join(IMAGES_DIR, image.file), { force: true }) } catch { /* ignore */ }
135
- }
136
- }
137
-
138
- /** Project a stored entry onto the wire shape (image URLs). */
139
- function toWire(entry: StoredEntry): HistoryEntry {
140
- return {
141
- id: entry.id,
142
- createdAt: entry.createdAt,
143
- mode: entry.mode,
144
- model: entry.model,
145
- prompt: entry.prompt,
146
- size: entry.size,
147
- quality: entry.quality,
148
- detail: entry.detail,
149
- n: entry.n,
150
- images: entry.images.map(image => ({
151
- url: `/api/dsh-imagegen/history/image/${image.file}`,
152
- mime: image.mime,
153
- ...image.revisedPrompt === undefined ? {} : { revisedPrompt: image.revisedPrompt },
154
- })),
155
- ...entry.refName === undefined ? {} : { refName: entry.refName },
156
- ...entry.channel === undefined ? {} : { channel: entry.channel },
157
- ...entry.channelId === undefined ? {} : { channelId: entry.channelId },
158
- }
159
- }
160
-
161
- /** List the persisted history, newest first, as wire entries. */
162
- export async function listHistory(): Promise<HistoryEntry[]> {
163
- const entries = await readIndex()
164
- return entries.map(toWire)
165
- }
166
-
167
- /** Append one generation, evicting the oldest beyond HISTORY_MAX. */
168
- export async function appendHistory(input: HistoryEntryInput): Promise<HistoryEntry[]> {
169
- return mutateHistory(async () => {
170
- await ensureDirs()
171
- const prefix = safeId(input.id)
172
- const storedImages: StoredImage[] = []
173
- try {
174
- for (let index = 0; index < input.images.length; index++) {
175
- const image = input.images[index]!
176
- const file = `${prefix}-${index}.${extensionOf(image.mime)}`
177
- await fs.writeFile(path.join(IMAGES_DIR, file), Buffer.from(image.b64, 'base64'))
178
- storedImages.push({
179
- file,
180
- mime: image.mime,
181
- ...image.revisedPrompt === undefined ? {} : { revisedPrompt: image.revisedPrompt },
182
- })
183
- }
184
- } catch (error) {
185
- await removeEntryFiles({ images: storedImages } as StoredEntry)
186
- throw error
187
- }
188
- const entry: StoredEntry = {
189
- id: input.id,
190
- createdAt: input.createdAt,
191
- mode: input.mode,
192
- model: input.model,
193
- prompt: input.prompt,
194
- size: input.size,
195
- quality: input.quality,
196
- detail: input.detail,
197
- n: input.n,
198
- images: storedImages,
199
- ...input.refName === undefined ? {} : { refName: input.refName },
200
- ...input.channelId === undefined ? {} : { channelId: input.channelId },
201
- ...input.channel === undefined ? {} : { channel: input.channel },
202
- }
203
- const merged = [entry, ...await readIndex()]
204
- const kept = merged.slice(0, HISTORY_MAX)
205
- for (const dropped of merged.slice(HISTORY_MAX)) await removeEntryFiles(dropped)
206
- await writeIndex(kept)
207
- return kept.map(toWire)
208
- })
209
- }
210
-
211
- /** Remove one entry (and its image files). */
212
- export async function removeHistory(id: string): Promise<HistoryEntry[]> {
213
- return mutateHistory(async () => {
214
- const previous = await readIndex()
215
- const target = previous.find(entry => entry.id === id)
216
- if (target !== undefined) await removeEntryFiles(target)
217
- const kept = previous.filter(entry => entry.id !== id)
218
- await writeIndex(kept)
219
- return kept.map(toWire)
220
- })
221
- }
222
-
223
- /** Remove every entry (and all image files). */
224
- export async function clearHistory(): Promise<HistoryEntry[]> {
225
- return mutateHistory(async () => {
226
- const previous = await readIndex()
227
- for (const entry of previous) await removeEntryFiles(entry)
228
- await writeIndex([])
229
- return []
230
- })
231
- }
232
-
233
- /** Read one stored image file by its (validated) file name. */
234
- export async function readHistoryImage(file: string): Promise<{ data: Buffer; mime: string } | undefined> {
235
- // Only accept <id>-<index>.<png|jpg|jpeg|webp|gif> — the exact names this
236
- // store writes — so the route can never escape the images directory.
237
- if (!/^[a-zA-Z0-9][a-zA-Z0-9-]*-[0-9]+\.(png|jpg|jpeg|webp|gif)$/.test(file)) return undefined
238
- try {
239
- const data = await fs.readFile(path.join(IMAGES_DIR, file))
240
- return { data, mime: mimeOfFile(file) }
241
- } catch {
242
- return undefined
243
- }
244
- }
1
+ /**
2
+ * Host-persisted generation history: images are stored as individual files
3
+ * under ~/.dsh/dsh-imagegen/images/ and an index.json keeps the metadata +
4
+ * file names. This makes the history survive across browsers/devices that
5
+ * connect to the same DSH host, and keeps list responses small (the browser
6
+ * loads image bytes lazily through the history image route).
7
+ *
8
+ * Framework-free (node:fs only) so the route layer can drive it directly.
9
+ */
10
+
11
+ import { promises as fs } from 'node:fs'
12
+ import { homedir } from 'node:os'
13
+ import path from 'node:path'
14
+ import { HISTORY_MAX, type GenerateMode, type HistoryEntry, type HistoryEntryInput } from './protocol.ts'
15
+
16
+ const HISTORY_DIR = path.join(homedir(), '.dsh', 'dsh-imagegen')
17
+ const INDEX_PATH = path.join(HISTORY_DIR, 'index.json')
18
+ const IMAGES_DIR = path.join(HISTORY_DIR, 'images')
19
+
20
+ // History mutations read and replace one shared index. Serialize them so
21
+ // overlapping requests cannot each read an old index and lose the other's row.
22
+ let pendingMutation: Promise<void> = Promise.resolve()
23
+
24
+ function mutateHistory<T>(operation: () => Promise<T>): Promise<T> {
25
+ const next = pendingMutation.then(operation, operation)
26
+ pendingMutation = next.then(() => undefined, () => undefined)
27
+ return next
28
+ }
29
+
30
+ /** One image's on-disk record (file name + mime, never base64). */
31
+ interface StoredImage {
32
+ file: string
33
+ mime: string
34
+ revisedPrompt?: string
35
+ }
36
+
37
+ /** One entry's on-disk record. */
38
+ interface StoredEntry {
39
+ id: string
40
+ createdAt: number
41
+ mode: GenerateMode
42
+ model: string
43
+ prompt: string
44
+ size: string
45
+ quality: string
46
+ detail: string
47
+ n: number
48
+ images: StoredImage[]
49
+ refName?: string
50
+ channelId?: string
51
+ channel?: string
52
+ comparisonId?: string
53
+ comparisonModels?: string[]
54
+ }
55
+
56
+ /** The index.json shape. */
57
+ interface IndexFile {
58
+ entries: StoredEntry[]
59
+ }
60
+
61
+ /** File extension for a MIME type (image file names). */
62
+ function extensionOf(mime: string): string {
63
+ switch (mime.split(';')[0]!.trim()) {
64
+ case 'image/jpeg': return 'jpg'
65
+ case 'image/webp': return 'webp'
66
+ case 'image/gif': return 'gif'
67
+ default: return 'png'
68
+ }
69
+ }
70
+
71
+ /** MIME type for a stored image file name (image route responses). */
72
+ function mimeOfFile(file: string): string {
73
+ const ext = path.extname(file).toLowerCase()
74
+ switch (ext) {
75
+ case '.jpg':
76
+ case '.jpeg': return 'image/jpeg'
77
+ case '.webp': return 'image/webp'
78
+ case '.gif': return 'image/gif'
79
+ default: return 'image/png'
80
+ }
81
+ }
82
+
83
+ /** Sanitize an entry id for use as a file-name prefix. */
84
+ function safeId(id: string): string {
85
+ const cleaned = id.replace(/[^a-zA-Z0-9-]/g, '-')
86
+ return cleaned === '' ? 'entry' : cleaned
87
+ }
88
+
89
+ /** Ensure the storage directories exist. */
90
+ async function ensureDirs(): Promise<void> {
91
+ await fs.mkdir(IMAGES_DIR, { recursive: true })
92
+ }
93
+
94
+ /** Read the index, tolerating a missing/corrupt file. */
95
+ async function readIndex(): Promise<StoredEntry[]> {
96
+ try {
97
+ const raw = await fs.readFile(INDEX_PATH, 'utf8')
98
+ const parsed: unknown = JSON.parse(raw)
99
+ if (parsed === null || typeof parsed !== 'object') return []
100
+ const entries = (parsed as { entries?: unknown }).entries
101
+ if (!Array.isArray(entries)) return []
102
+ return entries.filter(isStoredEntry)
103
+ } catch {
104
+ return []
105
+ }
106
+ }
107
+
108
+ /** Persist the index. */
109
+ async function writeIndex(entries: StoredEntry[]): Promise<void> {
110
+ await ensureDirs()
111
+ const payload: IndexFile = { entries }
112
+ const tmp = `${INDEX_PATH}.tmp-${process.pid}`
113
+ await fs.writeFile(tmp, JSON.stringify(payload), 'utf8')
114
+ await fs.rename(tmp, INDEX_PATH)
115
+ }
116
+
117
+ /** Structural guard for a stored entry. */
118
+ function isStoredEntry(value: unknown): value is StoredEntry {
119
+ if (value === null || typeof value !== 'object') return false
120
+ const entry = value as Record<string, unknown>
121
+ return typeof entry.id === 'string'
122
+ && typeof entry.createdAt === 'number'
123
+ && (entry.mode === 'text' || entry.mode === 'edit')
124
+ && typeof entry.prompt === 'string'
125
+ && Array.isArray(entry.images)
126
+ && entry.images.every(image => {
127
+ if (image === null || typeof image !== 'object') return false
128
+ const record = image as Record<string, unknown>
129
+ return typeof record.file === 'string' && typeof record.mime === 'string'
130
+ })
131
+ }
132
+
133
+ /** Remove one entry's image files (best effort). */
134
+ async function removeEntryFiles(entry: StoredEntry): Promise<void> {
135
+ for (const image of entry.images) {
136
+ try { await fs.rm(path.join(IMAGES_DIR, image.file), { force: true }) } catch { /* ignore */ }
137
+ }
138
+ }
139
+
140
+ /** Project a stored entry onto the wire shape (image URLs). */
141
+ function toWire(entry: StoredEntry): HistoryEntry {
142
+ return {
143
+ id: entry.id,
144
+ createdAt: entry.createdAt,
145
+ mode: entry.mode,
146
+ model: entry.model,
147
+ prompt: entry.prompt,
148
+ size: entry.size,
149
+ quality: entry.quality,
150
+ detail: entry.detail,
151
+ n: entry.n,
152
+ images: entry.images.map(image => ({
153
+ url: `/api/dsh-imagegen/history/image/${image.file}`,
154
+ mime: image.mime,
155
+ ...image.revisedPrompt === undefined ? {} : { revisedPrompt: image.revisedPrompt },
156
+ })),
157
+ ...entry.refName === undefined ? {} : { refName: entry.refName },
158
+ ...entry.channel === undefined ? {} : { channel: entry.channel },
159
+ ...entry.channelId === undefined ? {} : { channelId: entry.channelId },
160
+ ...entry.comparisonId === undefined ? {} : { comparisonId: entry.comparisonId },
161
+ ...entry.comparisonModels === undefined ? {} : { comparisonModels: entry.comparisonModels },
162
+ }
163
+ }
164
+
165
+ /** List the persisted history, newest first, as wire entries. */
166
+ export async function listHistory(): Promise<HistoryEntry[]> {
167
+ const entries = await readIndex()
168
+ return entries.map(toWire)
169
+ }
170
+
171
+ /** Append one generation, evicting the oldest beyond HISTORY_MAX. */
172
+ export async function appendHistory(input: HistoryEntryInput): Promise<HistoryEntry[]> {
173
+ return mutateHistory(async () => {
174
+ await ensureDirs()
175
+ const prefix = safeId(input.id)
176
+ const storedImages: StoredImage[] = []
177
+ try {
178
+ for (let index = 0; index < input.images.length; index++) {
179
+ const image = input.images[index]!
180
+ const file = `${prefix}-${index}.${extensionOf(image.mime)}`
181
+ await fs.writeFile(path.join(IMAGES_DIR, file), Buffer.from(image.b64, 'base64'))
182
+ storedImages.push({
183
+ file,
184
+ mime: image.mime,
185
+ ...image.revisedPrompt === undefined ? {} : { revisedPrompt: image.revisedPrompt },
186
+ })
187
+ }
188
+ } catch (error) {
189
+ await removeEntryFiles({ images: storedImages } as StoredEntry)
190
+ throw error
191
+ }
192
+ const entry: StoredEntry = {
193
+ id: input.id,
194
+ createdAt: input.createdAt,
195
+ mode: input.mode,
196
+ model: input.model,
197
+ prompt: input.prompt,
198
+ size: input.size,
199
+ quality: input.quality,
200
+ detail: input.detail,
201
+ n: input.n,
202
+ images: storedImages,
203
+ ...input.refName === undefined ? {} : { refName: input.refName },
204
+ ...input.channelId === undefined ? {} : { channelId: input.channelId },
205
+ ...input.channel === undefined ? {} : { channel: input.channel },
206
+ ...input.comparisonId === undefined ? {} : { comparisonId: input.comparisonId },
207
+ ...input.comparisonModels === undefined ? {} : { comparisonModels: input.comparisonModels },
208
+ }
209
+ const merged = [entry, ...await readIndex()]
210
+ const kept = merged.slice(0, HISTORY_MAX)
211
+ for (const dropped of merged.slice(HISTORY_MAX)) await removeEntryFiles(dropped)
212
+ await writeIndex(kept)
213
+ return kept.map(toWire)
214
+ })
215
+ }
216
+
217
+ /** Remove one entry (and its image files). */
218
+ export async function removeHistory(id: string): Promise<HistoryEntry[]> {
219
+ return mutateHistory(async () => {
220
+ const previous = await readIndex()
221
+ const target = previous.find(entry => entry.id === id)
222
+ if (target !== undefined) await removeEntryFiles(target)
223
+ const kept = previous.filter(entry => entry.id !== id)
224
+ await writeIndex(kept)
225
+ return kept.map(toWire)
226
+ })
227
+ }
228
+
229
+ /** Remove every entry (and all image files). */
230
+ export async function clearHistory(): Promise<HistoryEntry[]> {
231
+ return mutateHistory(async () => {
232
+ const previous = await readIndex()
233
+ for (const entry of previous) await removeEntryFiles(entry)
234
+ await writeIndex([])
235
+ return []
236
+ })
237
+ }
238
+
239
+ /** Read one stored image file by its (validated) file name. */
240
+ export async function readHistoryImage(file: string): Promise<{ data: Buffer; mime: string } | undefined> {
241
+ // Only accept <id>-<index>.<png|jpg|jpeg|webp|gif> — the exact names this
242
+ // store writes — so the route can never escape the images directory.
243
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9-]*-[0-9]+\.(png|jpg|jpeg|webp|gif)$/.test(file)) return undefined
244
+ try {
245
+ const data = await fs.readFile(path.join(IMAGES_DIR, file))
246
+ return { data, mime: mimeOfFile(file) }
247
+ } catch {
248
+ return undefined
249
+ }
250
+ }
@@ -1,11 +1,11 @@
1
- /** Detect the supported raster format from its encoded bytes. */
2
- export type SupportedImageMime = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif'
3
-
4
- export function detectImageMime(data: Uint8Array): SupportedImageMime | undefined {
5
- const startsWith = (...bytes: number[]): boolean => bytes.every((value, index) => data[index] === value)
6
- if (startsWith(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a)) return 'image/png'
7
- if (startsWith(0xff, 0xd8, 0xff)) return 'image/jpeg'
8
- if (startsWith(0x47, 0x49, 0x46, 0x38, 0x37, 0x61) || startsWith(0x47, 0x49, 0x46, 0x38, 0x39, 0x61)) return 'image/gif'
9
- if (startsWith(0x52, 0x49, 0x46, 0x46) && data[8] === 0x57 && data[9] === 0x45 && data[10] === 0x42 && data[11] === 0x50) return 'image/webp'
10
- return undefined
11
- }
1
+ /** Detect the supported raster format from its encoded bytes. */
2
+ export type SupportedImageMime = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif'
3
+
4
+ export function detectImageMime(data: Uint8Array): SupportedImageMime | undefined {
5
+ const startsWith = (...bytes: number[]): boolean => bytes.every((value, index) => data[index] === value)
6
+ if (startsWith(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a)) return 'image/png'
7
+ if (startsWith(0xff, 0xd8, 0xff)) return 'image/jpeg'
8
+ if (startsWith(0x47, 0x49, 0x46, 0x38, 0x37, 0x61) || startsWith(0x47, 0x49, 0x46, 0x38, 0x39, 0x61)) return 'image/gif'
9
+ if (startsWith(0x52, 0x49, 0x46, 0x46) && data[8] === 0x57 && data[9] === 0x45 && data[10] === 0x42 && data[11] === 0x50) return 'image/webp'
10
+ return undefined
11
+ }
@@ -1,19 +1,19 @@
1
- /**
2
- * Image-model configuration shared by the host, panel, and Agent tools.
3
- * `/models` exposes candidates only: the configured list is the explicit
4
- * allow-list because OpenAI-compatible gateways rarely advertise modalities.
5
- */
6
-
7
- export const DEFAULT_IMAGE_MODELS = ['gpt-image-2', 'grok-imagine-image', 'nanobanana2', 'nanobanana2-lite', 'nanobanana-pro', 'seedream-5.0-pro'] as const
8
-
9
- /** Normalize user-entered model identifiers and retain a usable legacy default. */
10
- export function normalizeImageModels(value: unknown): string[] {
11
- const candidates = Array.isArray(value) ? value : []
12
- const unique = new Set<string>()
13
- for (const candidate of candidates) {
14
- if (typeof candidate !== 'string') continue
15
- const model = candidate.trim()
16
- if (model !== '') unique.add(model)
17
- }
18
- return unique.size > 0 ? [...unique] : [...DEFAULT_IMAGE_MODELS]
19
- }
1
+ /**
2
+ * Image-model configuration shared by the host, panel, and Agent tools.
3
+ * `/models` exposes candidates only: the configured list is the explicit
4
+ * allow-list because OpenAI-compatible gateways rarely advertise modalities.
5
+ */
6
+
7
+ export const DEFAULT_IMAGE_MODELS = ['gpt-image-2', 'grok-imagine-image', 'nanobanana2', 'nanobanana2-lite', 'nanobanana-pro', 'seedream-5.0-pro', 'glm-image'] as const
8
+
9
+ /** Normalize user-entered model identifiers and retain a usable legacy default. */
10
+ export function normalizeImageModels(value: unknown): string[] {
11
+ const candidates = Array.isArray(value) ? value : []
12
+ const unique = new Set<string>()
13
+ for (const candidate of candidates) {
14
+ if (typeof candidate !== 'string') continue
15
+ const model = candidate.trim()
16
+ if (model !== '') unique.add(model)
17
+ }
18
+ return unique.size > 0 ? [...unique] : [...DEFAULT_IMAGE_MODELS]
19
+ }