@dickpy/dsh-imagegen 1.0.7 → 1.0.9
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 +9 -5
- package/lib/client.js +752 -108
- package/lib/client.js.map +1 -1
- package/lib/index.js +359 -5
- package/package.json +3 -2
- package/src/client/ImageGenPanel.tsx +25 -0
- package/src/client/TemplateLibrary.tsx +336 -0
- package/src/client/api.ts +21 -1
- package/src/client/locales.ts +56 -0
- package/src/client/panel.module.css +36 -1
- package/src/client/templates.module.css +453 -0
- package/src/index.ts +2 -1
- package/src/protocol.ts +59 -1
- package/src/routes.ts +73 -1
- package/src/templates/cases.json +10196 -0
- package/src/templates-store.ts +278 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt-template library styles. Same conventions as panel.module.css:
|
|
3
|
+
* scoped box-sizing, dsh --dsw-* tokens, no leakage outside the overlay
|
|
4
|
+
* subtree.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
.overlay,
|
|
8
|
+
.overlay *,
|
|
9
|
+
.overlay *::before,
|
|
10
|
+
.overlay *::after {
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.overlay {
|
|
15
|
+
position: fixed;
|
|
16
|
+
inset: 0;
|
|
17
|
+
z-index: 130;
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
padding: 28px;
|
|
22
|
+
background: var(--dsw-alias-bg-mask-1);
|
|
23
|
+
color: var(--dsw-alias-label-primary);
|
|
24
|
+
font-family: var(--dsw-font-family);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.shell {
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
width: min(1180px, 100%);
|
|
31
|
+
height: 100%;
|
|
32
|
+
max-height: 100%;
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
border: 1px solid var(--dsw-alias-border-l1);
|
|
35
|
+
border-radius: 14px;
|
|
36
|
+
background: var(--dsw-alias-bg-base);
|
|
37
|
+
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* --- header ------------------------------------------------------------ */
|
|
41
|
+
|
|
42
|
+
.header {
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
justify-content: space-between;
|
|
46
|
+
gap: 12px;
|
|
47
|
+
padding: 14px 18px 10px;
|
|
48
|
+
flex: none;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.heading {
|
|
52
|
+
display: flex;
|
|
53
|
+
align-items: baseline;
|
|
54
|
+
gap: 10px;
|
|
55
|
+
min-width: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.title {
|
|
59
|
+
margin: 0;
|
|
60
|
+
font-size: 15px;
|
|
61
|
+
font-weight: 650;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.meta {
|
|
65
|
+
font-size: 12px;
|
|
66
|
+
color: var(--dsw-alias-label-tertiary);
|
|
67
|
+
white-space: nowrap;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.headerActions {
|
|
71
|
+
display: inline-flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
gap: 8px;
|
|
74
|
+
flex: none;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.close {
|
|
78
|
+
display: inline-flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
justify-content: center;
|
|
81
|
+
width: 28px;
|
|
82
|
+
height: 28px;
|
|
83
|
+
border: none;
|
|
84
|
+
border-radius: 8px;
|
|
85
|
+
background: transparent;
|
|
86
|
+
color: var(--dsw-alias-label-secondary);
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.close:hover {
|
|
91
|
+
background: var(--dsw-alias-interactive-bg-hover);
|
|
92
|
+
color: var(--dsw-alias-label-primary);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* --- toolbar ----------------------------------------------------------- */
|
|
96
|
+
|
|
97
|
+
.toolbar {
|
|
98
|
+
display: flex;
|
|
99
|
+
flex-direction: column;
|
|
100
|
+
gap: 10px;
|
|
101
|
+
padding: 0 18px 12px;
|
|
102
|
+
flex: none;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.search {
|
|
106
|
+
width: 100%;
|
|
107
|
+
height: 34px;
|
|
108
|
+
padding: 0 12px;
|
|
109
|
+
border: 1px solid var(--dsw-alias-border-l1);
|
|
110
|
+
border-radius: 9px;
|
|
111
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
112
|
+
color: var(--dsw-alias-label-primary);
|
|
113
|
+
font-size: 13px;
|
|
114
|
+
font-family: inherit;
|
|
115
|
+
outline: none;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.search:focus {
|
|
119
|
+
border-color: var(--dsw-alias-brand-primary);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.search::placeholder {
|
|
123
|
+
color: var(--dsw-alias-label-dimmed);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.categoryRow {
|
|
127
|
+
display: flex;
|
|
128
|
+
flex-wrap: wrap;
|
|
129
|
+
gap: 6px;
|
|
130
|
+
max-height: 64px;
|
|
131
|
+
overflow-y: auto;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.categoryPill {
|
|
135
|
+
height: 26px;
|
|
136
|
+
padding: 0 11px;
|
|
137
|
+
border: 1px solid var(--dsw-alias-border-l1);
|
|
138
|
+
border-radius: 999px;
|
|
139
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
140
|
+
color: var(--dsw-alias-label-secondary);
|
|
141
|
+
font-size: 12px;
|
|
142
|
+
font-family: inherit;
|
|
143
|
+
cursor: pointer;
|
|
144
|
+
white-space: nowrap;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.categoryPill:hover {
|
|
148
|
+
color: var(--dsw-alias-label-primary);
|
|
149
|
+
background: var(--dsw-alias-interactive-bg-hover);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.categoryPill[data-active] {
|
|
153
|
+
border-color: var(--dsw-alias-brand-primary);
|
|
154
|
+
background: var(--dsw-alias-brand-primary);
|
|
155
|
+
color: var(--dsw-alias-bg-base);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.notice {
|
|
159
|
+
margin: 0 18px 10px;
|
|
160
|
+
padding: 8px 12px;
|
|
161
|
+
border: 1px solid var(--dsw-alias-border-l1);
|
|
162
|
+
border-radius: 9px;
|
|
163
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
164
|
+
color: var(--dsw-alias-label-secondary);
|
|
165
|
+
font-size: 12px;
|
|
166
|
+
flex: none;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* --- body / grid -------------------------------------------------------- */
|
|
170
|
+
|
|
171
|
+
.body {
|
|
172
|
+
flex: 1;
|
|
173
|
+
min-height: 0;
|
|
174
|
+
overflow-y: auto;
|
|
175
|
+
padding: 2px 18px 14px;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.state {
|
|
179
|
+
display: flex;
|
|
180
|
+
flex-direction: column;
|
|
181
|
+
align-items: center;
|
|
182
|
+
justify-content: center;
|
|
183
|
+
gap: 12px;
|
|
184
|
+
height: 100%;
|
|
185
|
+
min-height: 220px;
|
|
186
|
+
color: var(--dsw-alias-label-tertiary);
|
|
187
|
+
font-size: 13px;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.spinner {
|
|
191
|
+
width: 26px;
|
|
192
|
+
height: 26px;
|
|
193
|
+
border: 2px solid var(--dsw-alias-border-l2);
|
|
194
|
+
border-top-color: var(--dsw-alias-brand-primary);
|
|
195
|
+
border-radius: 50%;
|
|
196
|
+
animation: dsh-imagegen-templates-spin 0.9s linear infinite;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@keyframes dsh-imagegen-templates-spin {
|
|
200
|
+
to { transform: rotate(360deg); }
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.grid {
|
|
204
|
+
display: grid;
|
|
205
|
+
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
|
206
|
+
gap: 12px;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.card {
|
|
210
|
+
display: flex;
|
|
211
|
+
flex-direction: column;
|
|
212
|
+
gap: 0;
|
|
213
|
+
padding: 0;
|
|
214
|
+
overflow: hidden;
|
|
215
|
+
border: 1px solid var(--dsw-alias-border-l1);
|
|
216
|
+
border-radius: 11px;
|
|
217
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
218
|
+
cursor: pointer;
|
|
219
|
+
text-align: left;
|
|
220
|
+
font-family: inherit;
|
|
221
|
+
color: var(--dsw-alias-label-primary);
|
|
222
|
+
transition: border-color 0.15s ease, transform 0.15s ease;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.card:hover {
|
|
226
|
+
border-color: var(--dsw-alias-brand-primary);
|
|
227
|
+
transform: translateY(-1px);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.thumbWrap {
|
|
231
|
+
position: relative;
|
|
232
|
+
display: block;
|
|
233
|
+
width: 100%;
|
|
234
|
+
aspect-ratio: 1 / 1;
|
|
235
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.thumb {
|
|
239
|
+
display: block;
|
|
240
|
+
width: 100%;
|
|
241
|
+
height: 100%;
|
|
242
|
+
object-fit: cover;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.thumbPlaceholder {
|
|
246
|
+
display: flex;
|
|
247
|
+
align-items: center;
|
|
248
|
+
justify-content: center;
|
|
249
|
+
width: 100%;
|
|
250
|
+
height: 100%;
|
|
251
|
+
color: var(--dsw-alias-label-dimmed);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.featuredBadge {
|
|
255
|
+
position: absolute;
|
|
256
|
+
top: 8px;
|
|
257
|
+
left: 8px;
|
|
258
|
+
padding: 2px 8px;
|
|
259
|
+
border-radius: 999px;
|
|
260
|
+
background: var(--dsw-alias-brand-primary);
|
|
261
|
+
color: var(--dsw-alias-bg-base);
|
|
262
|
+
font-size: 11px;
|
|
263
|
+
font-weight: 600;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.cardBody {
|
|
267
|
+
display: flex;
|
|
268
|
+
flex-direction: column;
|
|
269
|
+
gap: 4px;
|
|
270
|
+
padding: 9px 11px 10px;
|
|
271
|
+
min-width: 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.cardTitle {
|
|
275
|
+
font-size: 12.5px;
|
|
276
|
+
font-weight: 600;
|
|
277
|
+
line-height: 1.35;
|
|
278
|
+
display: -webkit-box;
|
|
279
|
+
-webkit-line-clamp: 2;
|
|
280
|
+
-webkit-box-orient: vertical;
|
|
281
|
+
overflow: hidden;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.cardMeta {
|
|
285
|
+
display: flex;
|
|
286
|
+
align-items: center;
|
|
287
|
+
gap: 6px;
|
|
288
|
+
min-width: 0;
|
|
289
|
+
font-size: 11px;
|
|
290
|
+
color: var(--dsw-alias-label-tertiary);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.cardCategory {
|
|
294
|
+
flex: none;
|
|
295
|
+
padding: 1px 7px;
|
|
296
|
+
border-radius: 999px;
|
|
297
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
298
|
+
color: var(--dsw-alias-label-secondary);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.cardSource {
|
|
302
|
+
overflow: hidden;
|
|
303
|
+
text-overflow: ellipsis;
|
|
304
|
+
white-space: nowrap;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/* --- footer ------------------------------------------------------------- */
|
|
308
|
+
|
|
309
|
+
.footer {
|
|
310
|
+
flex: none;
|
|
311
|
+
display: flex;
|
|
312
|
+
align-items: center;
|
|
313
|
+
justify-content: space-between;
|
|
314
|
+
gap: 10px;
|
|
315
|
+
padding: 9px 18px;
|
|
316
|
+
border-top: 1px solid var(--dsw-alias-border-l1);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.attribution {
|
|
320
|
+
font-size: 11.5px;
|
|
321
|
+
color: var(--dsw-alias-label-dimmed);
|
|
322
|
+
min-width: 0;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.sourceLink {
|
|
326
|
+
flex: none;
|
|
327
|
+
font-size: 11.5px;
|
|
328
|
+
font-weight: 600;
|
|
329
|
+
color: var(--dsw-alias-brand-primary);
|
|
330
|
+
text-decoration: none;
|
|
331
|
+
white-space: nowrap;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.sourceLink:hover {
|
|
335
|
+
text-decoration: underline;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/* --- detail overlay ----------------------------------------------------- */
|
|
339
|
+
|
|
340
|
+
.detailOverlay {
|
|
341
|
+
position: absolute;
|
|
342
|
+
inset: 0;
|
|
343
|
+
display: flex;
|
|
344
|
+
align-items: center;
|
|
345
|
+
justify-content: center;
|
|
346
|
+
padding: 34px;
|
|
347
|
+
background: var(--dsw-alias-bg-mask-1);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
.detail {
|
|
351
|
+
display: grid;
|
|
352
|
+
grid-template-columns: minmax(0, 5fr) minmax(0, 4fr);
|
|
353
|
+
grid-template-rows: minmax(0, 1fr);
|
|
354
|
+
gap: 0;
|
|
355
|
+
width: min(980px, 100%);
|
|
356
|
+
max-height: 100%;
|
|
357
|
+
overflow: hidden;
|
|
358
|
+
border: 1px solid var(--dsw-alias-border-l1);
|
|
359
|
+
border-radius: 14px;
|
|
360
|
+
background: var(--dsw-alias-bg-base);
|
|
361
|
+
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.detailMedia {
|
|
365
|
+
display: flex;
|
|
366
|
+
align-items: center;
|
|
367
|
+
justify-content: center;
|
|
368
|
+
min-height: 0;
|
|
369
|
+
overflow: hidden;
|
|
370
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.detailImage {
|
|
374
|
+
display: block;
|
|
375
|
+
width: 100%;
|
|
376
|
+
height: 100%;
|
|
377
|
+
object-fit: contain;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.detailInfo {
|
|
381
|
+
display: flex;
|
|
382
|
+
flex-direction: column;
|
|
383
|
+
gap: 10px;
|
|
384
|
+
min-height: 0;
|
|
385
|
+
overflow-y: auto;
|
|
386
|
+
padding: 18px;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.detailTitle {
|
|
390
|
+
margin: 0;
|
|
391
|
+
font-size: 15px;
|
|
392
|
+
font-weight: 650;
|
|
393
|
+
line-height: 1.4;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.detailMeta {
|
|
397
|
+
display: flex;
|
|
398
|
+
align-items: center;
|
|
399
|
+
flex-wrap: wrap;
|
|
400
|
+
gap: 8px;
|
|
401
|
+
font-size: 12px;
|
|
402
|
+
color: var(--dsw-alias-label-tertiary);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
.detailLink {
|
|
406
|
+
color: var(--dsw-alias-brand-primary);
|
|
407
|
+
text-decoration: none;
|
|
408
|
+
overflow: hidden;
|
|
409
|
+
text-overflow: ellipsis;
|
|
410
|
+
white-space: nowrap;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.detailLink:hover {
|
|
414
|
+
text-decoration: underline;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.detailPrompt {
|
|
418
|
+
flex: 1;
|
|
419
|
+
min-height: 0;
|
|
420
|
+
margin: 0;
|
|
421
|
+
padding: 12px;
|
|
422
|
+
overflow-y: auto;
|
|
423
|
+
border: 1px solid var(--dsw-alias-border-l1);
|
|
424
|
+
border-radius: 10px;
|
|
425
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
426
|
+
color: var(--dsw-alias-label-primary);
|
|
427
|
+
font-size: 12.5px;
|
|
428
|
+
line-height: 1.6;
|
|
429
|
+
font-family: inherit;
|
|
430
|
+
white-space: pre-wrap;
|
|
431
|
+
word-break: break-word;
|
|
432
|
+
user-select: text;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
.detailActions {
|
|
436
|
+
display: flex;
|
|
437
|
+
gap: 8px;
|
|
438
|
+
flex: none;
|
|
439
|
+
position: sticky;
|
|
440
|
+
bottom: 0;
|
|
441
|
+
margin: 0 -18px -18px;
|
|
442
|
+
padding: 12px 18px;
|
|
443
|
+
background: var(--dsw-alias-bg-base);
|
|
444
|
+
border-top: 1px solid var(--dsw-alias-border-l1);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/* Narrow shells: stack the detail pane. */
|
|
448
|
+
@media (max-width: 760px) {
|
|
449
|
+
.detail {
|
|
450
|
+
grid-template-columns: 1fr;
|
|
451
|
+
grid-template-rows: minmax(0, 3fr) minmax(0, 4fr);
|
|
452
|
+
}
|
|
453
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ export const inject = ['webServer', 'systemPrompt']
|
|
|
26
26
|
// contract only requires name / inject / Config / apply.
|
|
27
27
|
export { makeRoutes } from './routes.ts'
|
|
28
28
|
export { generateImage, ImageGenError } from './engine.ts'
|
|
29
|
+
export { listTemplates, readTemplateImage, refreshTemplates, clearTemplateMemo } from './templates-store.ts'
|
|
29
30
|
export { checkForUpdate, clearUpdateCache, compareVersions, CURRENT_VERSION, installUpdate, profileFromProcess } from './updater.ts'
|
|
30
31
|
|
|
31
32
|
/** The branded settings namespace of this plugin (the card edits it). */
|
|
@@ -58,7 +59,7 @@ const DEFAULT_ANNOUNCE = true
|
|
|
58
59
|
const SECTION_ORDER = 150
|
|
59
60
|
|
|
60
61
|
/** Model-facing announcement: plugin presence, capabilities, and limits. */
|
|
61
|
-
export const IMAGEGEN_GUIDANCE = '本机已安装 dsh-imagegen 插件(DSH AI 生图):侧边栏「AI 生图」入口。能力:对接 OpenAI 兼容图像生成 API(模型 gpt-image-2),支持文生图(/images/generations)与图生图(/images/edits,上传参考图);API 地址与密钥在 GUI「设置 → 插件 → 可配置」中配置,密钥仅存于本机设置文档;生成请求由本地宿主代理转发,结果以 base64
|
|
62
|
+
export const IMAGEGEN_GUIDANCE = '本机已安装 dsh-imagegen 插件(DSH AI 生图):侧边栏「AI 生图」入口。能力:对接 OpenAI 兼容图像生成 API(模型 gpt-image-2),支持文生图(/images/generations)与图生图(/images/edits,上传参考图);API 地址与密钥在 GUI「设置 → 插件 → 可配置」中配置,密钥仅存于本机设置文档;生成请求由本地宿主代理转发,结果以 base64 返回面板,可预览与下载。内置「提示词模板库」(面板提示词框左下角「模板库」按钮):打包 awesome-gpt-image-2 的数百条 gpt-image-2 提示词案例(含中文标题、分类、参考图,可搜索/按分类筛选),参考图经宿主代理按需缓存到本地;用户可一键把模板提示词填入提示词框再生成。限制:生成消耗上游 API 额度;图片内容由上游模型生成,可能不符合预期或包含不适宜内容;api_key 以明文存储在设置文档中;参考图会发送至所配置的 API 服务;模板库在线刷新与参考图首次加载需要访问 vibeui.top。用户提到「生图 / 绘画 / 生成图片 / gpt-image-2 / 文生图 / 图生图 / 提示词模板」时即指本插件,请据此协作。'
|
|
62
63
|
|
|
63
64
|
/** Effective config (schema defaults applied). */
|
|
64
65
|
interface EffectiveConfig {
|
package/src/protocol.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
export const IMAGEGEN_SETTINGS_NAMESPACE = 'dsh-imagegen'
|
|
9
9
|
|
|
10
10
|
/** Published package version shared by the host updater and the client UI. */
|
|
11
|
-
export const PLUGIN_VERSION = '1.0.
|
|
11
|
+
export const PLUGIN_VERSION = '1.0.9'
|
|
12
12
|
|
|
13
13
|
/** Same-origin route family (loopback-only, mirroring the dsh-ssh fence). */
|
|
14
14
|
export const SETTINGS_API = {
|
|
@@ -42,6 +42,64 @@ export const HISTORY_API = {
|
|
|
42
42
|
/** Maximum number of history entries retained host-side (oldest evicted). */
|
|
43
43
|
export const HISTORY_MAX = 50
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Same-origin route family for the bundled prompt-template library
|
|
47
|
+
* (awesome-gpt-image-2 mirror). The case list ships inside the package and is
|
|
48
|
+
* served by the host; reference images are proxied through the `image` prefix
|
|
49
|
+
* route and cached on disk so repeated views never hit the network again.
|
|
50
|
+
*/
|
|
51
|
+
export const TEMPLATES_API = {
|
|
52
|
+
list: '/api/dsh-imagegen/templates/list',
|
|
53
|
+
refresh: '/api/dsh-imagegen/templates/refresh',
|
|
54
|
+
image: '/api/dsh-imagegen/templates/image',
|
|
55
|
+
} as const
|
|
56
|
+
|
|
57
|
+
/** One prompt-library case as the browser consumes it. */
|
|
58
|
+
export interface TemplateCase {
|
|
59
|
+
/** Upstream case number (stable across refreshes). */
|
|
60
|
+
id: number
|
|
61
|
+
/** Short case title. */
|
|
62
|
+
title: string
|
|
63
|
+
/** Full reusable prompt text. */
|
|
64
|
+
prompt: string
|
|
65
|
+
/** English category name (grouping key). */
|
|
66
|
+
category: string
|
|
67
|
+
/** Chinese category display name. */
|
|
68
|
+
categoryZh: string
|
|
69
|
+
/** Style tags. */
|
|
70
|
+
styles: string[]
|
|
71
|
+
/** Scene tags. */
|
|
72
|
+
scenes: string[]
|
|
73
|
+
/** Original author handle, e.g. @vista8. */
|
|
74
|
+
sourceLabel: string
|
|
75
|
+
/** Original author link. */
|
|
76
|
+
sourceUrl: string
|
|
77
|
+
/** awesome-gpt-image-2 repo anchor link. */
|
|
78
|
+
githubUrl: string
|
|
79
|
+
/** Reference-image file name served through the image route ('' when none). */
|
|
80
|
+
image: string
|
|
81
|
+
/** Whether the source gallery featured the case. */
|
|
82
|
+
featured: boolean
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Template-library list payload. */
|
|
86
|
+
export interface TemplateListResult {
|
|
87
|
+
cases: TemplateCase[]
|
|
88
|
+
total: number
|
|
89
|
+
/** Where the served list came from. */
|
|
90
|
+
origin: 'bundled' | 'refreshed'
|
|
91
|
+
/** Upstream repository the library mirrors. */
|
|
92
|
+
repository: string
|
|
93
|
+
/** ISO time of the last successful refresh / bundle snapshot. */
|
|
94
|
+
fetchedAt: string
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Template-library refresh outcome. */
|
|
98
|
+
export interface TemplateRefreshResult {
|
|
99
|
+
total: number
|
|
100
|
+
fetchedAt: string
|
|
101
|
+
}
|
|
102
|
+
|
|
45
103
|
/** Generation modes. */
|
|
46
104
|
export type GenerateMode = 'text' | 'edit'
|
|
47
105
|
|
package/src/routes.ts
CHANGED
|
@@ -11,8 +11,9 @@ import type { WebRoute } from '@deepseek-ai/dsh-host-webserver'
|
|
|
11
11
|
import { SettingsConflictError, settingsNamespace, type SettingsDescriptor } from '@deepseek-ai/dsh-settings'
|
|
12
12
|
import { generateImage, type UpstreamConfig } from './engine.ts'
|
|
13
13
|
import { appendHistory, clearHistory, listHistory, readHistoryImage, removeHistory } from './history-store.ts'
|
|
14
|
+
import { listTemplates, readTemplateImage, refreshTemplates } from './templates-store.ts'
|
|
14
15
|
import { checkForUpdate, CURRENT_VERSION, installUpdate } from './updater.ts'
|
|
15
|
-
import { GENERATE_API, HISTORY_API, IMAGEGEN_SETTINGS_NAMESPACE, SETTINGS_API, UPDATE_API, type GeneratedImage, type GenerateRequest, type HistoryEntry, type HistoryEntryInput } from './protocol.ts'
|
|
16
|
+
import { GENERATE_API, HISTORY_API, IMAGEGEN_SETTINGS_NAMESPACE, SETTINGS_API, TEMPLATES_API, UPDATE_API, type GeneratedImage, type GenerateRequest, type HistoryEntry, type HistoryEntryInput, type TemplateListResult, type TemplateRefreshResult } from './protocol.ts'
|
|
16
17
|
|
|
17
18
|
/** Cap on JSON request bodies (settings ops and generate payloads are small). */
|
|
18
19
|
const MAX_JSON_BODY_BYTES = 24 * 1024 * 1024
|
|
@@ -41,6 +42,12 @@ export interface ImageGenRoutesDeps {
|
|
|
41
42
|
clear: () => Promise<HistoryEntry[]>
|
|
42
43
|
readImage: (file: string) => Promise<{ data: Buffer; mime: string } | undefined>
|
|
43
44
|
}
|
|
45
|
+
/** Overrideable template-library backend, primarily for host integration tests. */
|
|
46
|
+
templates?: {
|
|
47
|
+
list: () => Promise<TemplateListResult>
|
|
48
|
+
refresh: () => Promise<TemplateRefreshResult>
|
|
49
|
+
readImage: (file: string) => Promise<{ data: Buffer; mime: string } | undefined>
|
|
50
|
+
}
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
/** Loopback literal check plus browser same-origin markers (mirrors dsh-ssh). */
|
|
@@ -183,6 +190,11 @@ export function makeRoutes(deps: ImageGenRoutesDeps): WebRoute[] {
|
|
|
183
190
|
clear: clearHistory,
|
|
184
191
|
readImage: readHistoryImage,
|
|
185
192
|
}
|
|
193
|
+
const templates = deps.templates ?? {
|
|
194
|
+
list: listTemplates,
|
|
195
|
+
refresh: refreshTemplates,
|
|
196
|
+
readImage: readTemplateImage,
|
|
197
|
+
}
|
|
186
198
|
const guard = (req: IncomingMessage, res: ServerResponse, method: string): boolean => {
|
|
187
199
|
if (!isLoopbackRequest(req)) {
|
|
188
200
|
writeJson(res, 403, { error: 'forbidden: loopback-only' })
|
|
@@ -442,5 +454,65 @@ export function makeRoutes(deps: ImageGenRoutesDeps): WebRoute[] {
|
|
|
442
454
|
res.end(found.data)
|
|
443
455
|
},
|
|
444
456
|
},
|
|
457
|
+
// --------------------------------------------------- templates list
|
|
458
|
+
{
|
|
459
|
+
kind: 'exact',
|
|
460
|
+
path: TEMPLATES_API.list,
|
|
461
|
+
handler: async (req, res) => {
|
|
462
|
+
if (!guard(req, res, 'POST')) return
|
|
463
|
+
try {
|
|
464
|
+
const result = await templates.list()
|
|
465
|
+
writeJson(res, 200, { ok: true, ...result })
|
|
466
|
+
} catch (error) {
|
|
467
|
+
writeJson(res, 200, { ok: false, code: 'templates-failed', message: messageOf(error) })
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
// ------------------------------------------------- templates refresh
|
|
472
|
+
{
|
|
473
|
+
kind: 'exact',
|
|
474
|
+
path: TEMPLATES_API.refresh,
|
|
475
|
+
handler: async (req, res) => {
|
|
476
|
+
if (!guard(req, res, 'POST')) return
|
|
477
|
+
try {
|
|
478
|
+
const result = await templates.refresh()
|
|
479
|
+
writeJson(res, 200, { ok: true, ...result })
|
|
480
|
+
} catch (error) {
|
|
481
|
+
writeJson(res, 200, { ok: false, code: 'templates-refresh-failed', message: messageOf(error) })
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
// -------------------------------------- templates image (prefix, proxied)
|
|
486
|
+
{
|
|
487
|
+
kind: 'prefix',
|
|
488
|
+
path: TEMPLATES_API.image,
|
|
489
|
+
handler: async (req, res) => {
|
|
490
|
+
if (!isLoopbackRequest(req)) {
|
|
491
|
+
writeJson(res, 403, { error: 'forbidden: loopback-only' })
|
|
492
|
+
return
|
|
493
|
+
}
|
|
494
|
+
if (req.method !== 'GET') {
|
|
495
|
+
writeJson(res, 405, { error: `method not allowed: ${req.method}` })
|
|
496
|
+
return
|
|
497
|
+
}
|
|
498
|
+
const file = imageFileFrom(req.url, TEMPLATES_API.image)
|
|
499
|
+
if (file === undefined) {
|
|
500
|
+
writeJson(res, 404, { error: 'not found' })
|
|
501
|
+
return
|
|
502
|
+
}
|
|
503
|
+
const found = await templates.readImage(file)
|
|
504
|
+
if (found === undefined) {
|
|
505
|
+
writeJson(res, 404, { error: 'not found' })
|
|
506
|
+
return
|
|
507
|
+
}
|
|
508
|
+
res.writeHead(200, {
|
|
509
|
+
'content-type': found.mime,
|
|
510
|
+
'content-length': found.data.length,
|
|
511
|
+
// Cached on disk by the host; reference images are immutable per name.
|
|
512
|
+
'cache-control': 'private, max-age=86400',
|
|
513
|
+
})
|
|
514
|
+
res.end(found.data)
|
|
515
|
+
},
|
|
516
|
+
},
|
|
445
517
|
]
|
|
446
518
|
}
|