@dickpy/dsh-imagegen 1.5.1 → 1.5.2

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.
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Inspiration-wall styles for the studio's empty canvas. Same conventions as
3
+ * panel.module.css: dsh --dsw-* tokens, scoped to this component's subtree.
4
+ */
5
+
6
+ .wrap {
7
+ display: flex;
8
+ flex-direction: column;
9
+ align-items: center;
10
+ gap: 16px;
11
+ width: min(880px, 100%);
12
+ margin: auto;
13
+ padding: 24px;
14
+ font-family: var(--dsw-font-family);
15
+ }
16
+
17
+ .title {
18
+ font-size: 15px;
19
+ font-weight: 650;
20
+ color: var(--dsw-alias-label-primary);
21
+ }
22
+
23
+ /* Fallback (sample failed / libraries empty): mirrors the panel's plain
24
+ canvas empty state so the swap is invisible. */
25
+ .emptyIcon {
26
+ display: inline-flex;
27
+ color: var(--dsw-alias-label-dimmed);
28
+ }
29
+
30
+ .emptyTitle {
31
+ margin-top: -6px;
32
+ font-size: 15px;
33
+ font-weight: 650;
34
+ color: var(--dsw-alias-label-primary);
35
+ }
36
+
37
+ .emptyHint {
38
+ font-size: 12.5px;
39
+ color: var(--dsw-alias-label-tertiary);
40
+ }
41
+
42
+ .grid {
43
+ display: grid;
44
+ grid-template-columns: repeat(4, 1fr);
45
+ gap: 12px;
46
+ width: 100%;
47
+ }
48
+
49
+ /* Narrow canvases: fold the wall down instead of shrinking tiles into slivers. */
50
+ @media (max-width: 900px) {
51
+ .grid {
52
+ grid-template-columns: repeat(3, 1fr);
53
+ }
54
+ }
55
+
56
+ @media (max-width: 560px) {
57
+ .grid {
58
+ grid-template-columns: repeat(2, 1fr);
59
+ }
60
+ }
61
+
62
+ .tile {
63
+ position: relative;
64
+ display: block;
65
+ width: 100%;
66
+ aspect-ratio: 1 / 1;
67
+ padding: 0;
68
+ overflow: hidden;
69
+ border: 1px solid var(--dsw-alias-border-l1);
70
+ border-radius: 12px;
71
+ background: var(--dsw-alias-bg-layer-1);
72
+ cursor: pointer;
73
+ transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
74
+ }
75
+
76
+ .tile:hover {
77
+ border-color: var(--dsw-alias-brand-primary);
78
+ transform: translateY(-2px);
79
+ box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
80
+ }
81
+
82
+ .thumbWrap {
83
+ position: absolute;
84
+ inset: 0;
85
+ display: block;
86
+ }
87
+
88
+ .thumb {
89
+ display: block;
90
+ width: 100%;
91
+ height: 100%;
92
+ object-fit: cover;
93
+ }
94
+
95
+ .thumbFallback {
96
+ display: flex;
97
+ align-items: center;
98
+ justify-content: center;
99
+ width: 100%;
100
+ height: 100%;
101
+ padding: 6px;
102
+ overflow: hidden;
103
+ background: var(--dsw-alias-bg-layer-2);
104
+ color: var(--dsw-alias-label-tertiary);
105
+ font-size: 11px;
106
+ line-height: 1.4;
107
+ text-align: center;
108
+ }
109
+
110
+ .thumbTitle {
111
+ position: absolute;
112
+ inset: auto 0 0 0;
113
+ padding: 14px 8px 6px;
114
+ overflow: hidden;
115
+ text-overflow: ellipsis;
116
+ white-space: nowrap;
117
+ background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
118
+ color: #ffffff;
119
+ font-size: 10.5px;
120
+ text-align: center;
121
+ opacity: 0;
122
+ transition: opacity 0.15s ease;
123
+ pointer-events: none;
124
+ }
125
+
126
+ .tile:hover .thumbTitle {
127
+ opacity: 1;
128
+ }
129
+
130
+ .spinner {
131
+ width: 20px;
132
+ height: 20px;
133
+ border: 2px solid var(--dsw-alias-border-l2);
134
+ border-top-color: var(--dsw-alias-brand-primary);
135
+ border-radius: 50%;
136
+ animation: dsh-imagegen-inspiration-spin 0.9s linear infinite;
137
+ }
138
+
139
+ @keyframes dsh-imagegen-inspiration-spin {
140
+ to { transform: rotate(360deg); }
141
+ }
142
+
143
+ /* Touch shells have no hover: keep titles visible. */
144
+ @media (hover: none) {
145
+ .thumbTitle {
146
+ opacity: 1;
147
+ }
148
+ }
@@ -301,6 +301,7 @@ export const zh = {
301
301
  // template library
302
302
  'templates.open': '模板库',
303
303
  'templates.title': '提示词模板库',
304
+ 'templates.sources': '模板库来源',
304
305
  'templates.meta': '共 {count} 个模板 · {origin}',
305
306
  'templates.origin.bundled': '内置快照',
306
307
  'templates.origin.refreshed': '在线刷新',
@@ -311,21 +312,33 @@ export const zh = {
311
312
  'templates.use': '使用此提示词',
312
313
  'templates.copy': '复制提示词',
313
314
  'templates.copied': '已复制',
314
- 'templates.refresh': '刷新模板库',
315
+ 'templates.refresh': '刷新本库',
315
316
  'templates.refreshing': '刷新中…',
316
317
  'templates.refreshed': '已刷新,共 {count} 个模板',
317
318
  'templates.refreshFailed': '刷新失败:{error}',
319
+ 'templates.favorites': '收藏',
320
+ 'templates.favoritesHint': '只看已收藏的模板',
321
+ 'templates.favoritesEmpty': '还没有收藏,点击模板卡片右上角的星标即可收藏',
322
+ 'templates.favoriteAdd': '收藏此模板',
323
+ 'templates.favoriteRemove': '取消收藏',
324
+ 'templates.favorite': '收藏',
325
+ 'templates.unfavorite': '已收藏',
318
326
  'templates.cacheAll': '缓存全部图片',
319
- 'templates.cacheAllHint': '通过本机代理把全部参考图缓存到本地磁盘,之后离线也能浏览',
327
+ 'templates.cacheAllHint': '通过本机代理把当前模板库的全部参考图缓存到本地磁盘,之后离线也能浏览',
320
328
  'templates.caching': '缓存中 {done}/{total}…',
321
329
  'templates.cached': '图片已全部缓存',
322
330
  'templates.empty': '没有匹配的模板',
323
331
  'templates.loading': '正在加载模板库…',
324
332
  'templates.loadFailed': '模板库加载失败:{error}',
325
333
  'templates.retry': '重试',
326
- 'templates.attribution': '模板与图片来自 awesome-gpt-image-2 项目,作者链接见各模板详情',
327
- 'templates.source': '来源:vibeui.top',
334
+ 'templates.attribution': '模板与图片来自各来源站点,作者链接见模板详情',
335
+ 'templates.source': '来源:{label}',
328
336
  'templates.featured': '精选',
337
+ // inspiration wall (studio empty state)
338
+ 'inspiration.title': '灵感案例',
339
+ 'inspiration.shuffle': '随机',
340
+ 'inspiration.shuffling': '换一批…',
341
+ 'inspiration.useHint': '点击使用该提示词',
329
342
  // channel management
330
343
  'channels.title': '渠道',
331
344
  'channels.hint': '填写各渠道的 API 地址与密钥即可使用对应模型',
@@ -665,6 +678,7 @@ export const en: Record<keyof typeof zh, string> = {
665
678
  // template library
666
679
  'templates.open': 'Templates',
667
680
  'templates.title': 'Prompt Template Library',
681
+ 'templates.sources': 'Template sources',
668
682
  'templates.meta': '{count} templates · {origin}',
669
683
  'templates.origin.bundled': 'bundled snapshot',
670
684
  'templates.origin.refreshed': 'refreshed online',
@@ -675,21 +689,33 @@ export const en: Record<keyof typeof zh, string> = {
675
689
  'templates.use': 'Use this prompt',
676
690
  'templates.copy': 'Copy prompt',
677
691
  'templates.copied': 'Copied',
678
- 'templates.refresh': 'Refresh library',
692
+ 'templates.refresh': 'Refresh this library',
679
693
  'templates.refreshing': 'Refreshing…',
680
694
  'templates.refreshed': 'Refreshed — {count} templates',
681
695
  'templates.refreshFailed': 'Refresh failed: {error}',
696
+ 'templates.favorites': 'Favorites',
697
+ 'templates.favoritesHint': 'Show favorited templates only',
698
+ 'templates.favoritesEmpty': 'No favorites yet — tap the star in a card\'s top-right corner to save one',
699
+ 'templates.favoriteAdd': 'Favorite this template',
700
+ 'templates.favoriteRemove': 'Remove from favorites',
701
+ 'templates.favorite': 'Favorite',
702
+ 'templates.unfavorite': 'Favorited',
682
703
  'templates.cacheAll': 'Cache all images',
683
- 'templates.cacheAllHint': 'Mirror every reference image to local disk through the host proxy, for offline browsing',
704
+ 'templates.cacheAllHint': 'Mirror every reference image of the current library to local disk through the host proxy, for offline browsing',
684
705
  'templates.caching': 'Caching {done}/{total}…',
685
706
  'templates.cached': 'All images cached',
686
707
  'templates.empty': 'No matching templates',
687
708
  'templates.loading': 'Loading the template library…',
688
709
  'templates.loadFailed': 'Failed to load the library: {error}',
689
710
  'templates.retry': 'Retry',
690
- 'templates.attribution': 'Templates and images come from the awesome-gpt-image-2 project; author links are on each template',
691
- 'templates.source': 'Source: vibeui.top',
711
+ 'templates.attribution': 'Templates and images come from each source site; author links are on each template',
712
+ 'templates.source': 'Source: {label}',
692
713
  'templates.featured': 'Featured',
714
+ // inspiration wall (studio empty state)
715
+ 'inspiration.title': 'Inspiration',
716
+ 'inspiration.shuffle': 'Shuffle',
717
+ 'inspiration.shuffling': 'Shuffling…',
718
+ 'inspiration.useHint': 'Click to use this prompt',
693
719
  // channel management
694
720
  'channels.title': 'Channels',
695
721
  'channels.hint': 'Fill in each channel\'s API URL and key to use its models',
@@ -92,6 +92,60 @@
92
92
  color: var(--dsw-alias-label-primary);
93
93
  }
94
94
 
95
+ /* --- source tabs --------------------------------------------------------- */
96
+
97
+ .sourceTabs {
98
+ display: flex;
99
+ align-items: center;
100
+ gap: 6px;
101
+ padding: 0 18px 10px;
102
+ border-bottom: 1px solid var(--dsw-alias-border-l1);
103
+ flex: none;
104
+ }
105
+
106
+ .sourceTab {
107
+ display: inline-flex;
108
+ align-items: center;
109
+ gap: 6px;
110
+ height: 30px;
111
+ padding: 0 14px;
112
+ border: 1px solid transparent;
113
+ border-radius: 9px 9px 0 0;
114
+ border-bottom: none;
115
+ background: transparent;
116
+ color: var(--dsw-alias-label-secondary);
117
+ font-size: 13px;
118
+ font-weight: 600;
119
+ font-family: inherit;
120
+ cursor: pointer;
121
+ white-space: nowrap;
122
+ }
123
+
124
+ .sourceTab:hover {
125
+ color: var(--dsw-alias-label-primary);
126
+ background: var(--dsw-alias-interactive-bg-hover);
127
+ }
128
+
129
+ .sourceTab[data-active] {
130
+ border-color: var(--dsw-alias-border-l1);
131
+ border-radius: 9px;
132
+ background: var(--dsw-alias-bg-layer-1);
133
+ color: var(--dsw-alias-brand-primary);
134
+ }
135
+
136
+ .sourceTabCount {
137
+ padding: 0 6px;
138
+ border-radius: 999px;
139
+ background: var(--dsw-alias-bg-layer-2);
140
+ color: var(--dsw-alias-label-tertiary);
141
+ font-size: 11px;
142
+ font-weight: 500;
143
+ }
144
+
145
+ .sourceTab[data-active] .sourceTabCount {
146
+ color: var(--dsw-alias-label-secondary);
147
+ }
148
+
95
149
  /* --- toolbar ----------------------------------------------------------- */
96
150
 
97
151
  .toolbar {
@@ -263,6 +317,47 @@
263
317
  font-weight: 600;
264
318
  }
265
319
 
320
+ .favStar {
321
+ position: absolute;
322
+ top: 6px;
323
+ right: 6px;
324
+ display: inline-flex;
325
+ align-items: center;
326
+ justify-content: center;
327
+ width: 26px;
328
+ height: 26px;
329
+ padding: 0;
330
+ border: none;
331
+ border-radius: 8px;
332
+ background: rgba(0, 0, 0, 0.35);
333
+ color: rgba(255, 255, 255, 0.85);
334
+ cursor: pointer;
335
+ opacity: 0;
336
+ transition: opacity 0.15s ease;
337
+ }
338
+
339
+ .card:hover .favStar,
340
+ .favStar:focus-visible,
341
+ .favStar[data-active] {
342
+ opacity: 1;
343
+ }
344
+
345
+ .favStar:hover {
346
+ background: rgba(0, 0, 0, 0.55);
347
+ color: #ffffff;
348
+ }
349
+
350
+ .favStar[data-active] {
351
+ color: #ffb020;
352
+ }
353
+
354
+ /* Touch shells have no hover: keep the star reachable. */
355
+ @media (hover: none) {
356
+ .favStar {
357
+ opacity: 1;
358
+ }
359
+ }
360
+
266
361
  .cardBody {
267
362
  display: flex;
268
363
  flex-direction: column;
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ import type {} from '@deepseek-ai/dsh-tools'
20
20
  import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'
21
21
  import { IMAGEGEN_SETTINGS_NAMESPACE, type ChannelConfig, type ModelMapping } from './protocol.ts'
22
22
  import { makeRoutes, type SettingsSeam } from './routes.ts'
23
+ import { syncAllTemplates } from './templates-store.ts'
23
24
  import { ImageGenerationRuntime, type ChannelsView, type RuntimeChannel } from './generation-runtime.ts'
24
25
  import { registerAgentImageTools } from './agent-image-tools.ts'
25
26
  import { registerEditImageCommand } from './edit-image-command.ts'
@@ -39,7 +40,8 @@ export { ImageGenerationRuntime } from './generation-runtime.ts'
39
40
  export { registerAgentImageTools } from './agent-image-tools.ts'
40
41
  export { latestSessionImage, registerEditImageCommand } from './edit-image-command.ts'
41
42
  export { appendGallery, clearGallery, listGallery, readGalleryImage, removeGallery, updateGalleryTags } from './gallery-store.ts'
42
- export { listTemplates, readTemplateImage, refreshTemplates, clearTemplateMemo } from './templates-store.ts'
43
+ export { listTemplates, readTemplateImage, refreshTemplates, sampleTemplates, syncAllTemplates, clearTemplateMemo } from './templates-store.ts'
44
+ export { addTemplateFavorite, clearTemplateFavoritesMemo, listTemplateFavorites, removeTemplateFavorite } from './template-favorites.ts'
43
45
  export { checkForUpdate, clearUpdateCache, compareVersions, CURRENT_VERSION, installUpdate, profileFromProcess } from './updater.ts'
44
46
 
45
47
  /** The branded settings namespace of this plugin (the card edits it). */
@@ -115,7 +117,7 @@ const DEFAULT_ALLOW_AGENT_IMAGE_GENERATION = true
115
117
  const SECTION_ORDER = 150
116
118
 
117
119
  /** Model-facing announcement: plugin presence, capabilities, and limits. */
118
- export const IMAGEGEN_GUIDANCE = '本机已安装 dsh-imagegen 插件(DSH AI 生图):侧边栏「AI 生图」入口。能力:通过「渠道」对接 OpenAI 兼容图像生成 API(每个渠道 = 一个 API 端点 + 各自的模型目录),支持文生图(/images/generations)与图生图(/images/edits,上传参考图,grok-imagine 模型按官方 JSON image_url 协议发送,nanobanana 系列按 aspect_ratio / image_size 参数协议发送;seedream 系列统一走 /images/generations,参考图以 JSON image 数组发送;智谱 `glm-image` 使用官方 `/api/paas/v4/images/generations`,当前仅支持文生图)。API 地址与密钥在 GUI 设置中按渠道配置,密钥仅存于本机设置文档;生成请求由本地宿主代理转发,结果以 base64 返回面板,可预览与下载。模型只能使用用户在各渠道配置目录中的模型;检测模型时会过滤聊天、Embedding 等非图片模型,但模型出现在 /models 中仍不等于其网关原生支持生图协议,遇到 Qwen、Gemini 等非 OpenAI 生图协议时应如实说明上游兼容性。可一键把满意的图片加入「画廊」。内置「提示词模板库」(面板提示词框左下角「模板库」按钮):打包 awesome-gpt-image-2 的数百条提示词案例,可搜索、筛选与复用。Agent 可直接调用 `generate_image` 提交文生图,也可用 `edit_image` 图生图;默认保持工具调用等待直到任务完成,完成图片显示在工具调用对应的左侧结果区域,模型收到状态和附件引用,不会额外伪造用户消息。用户也可以使用 `/edit_image <修改描述>`,命令会直接读取当前对话最近图片并调用插件图片模型,不经过对话模型的图片能力检查。若明确需要后台执行,可传 `wait_for_completion: false`,之后再用 `get_image_generation_task` 查询;不要反复轮询。限制:生成消耗上游 API 额度;图片内容由上游模型生成,可能不符合预期或包含不适宜内容;api_key 以明文存储在设置文档中;参考图会发送至所配置的 API 服务;模板库在线刷新与参考图首次加载需要访问 vibeui.top。用户提到「生图 / 绘画 / 生成图片 / 文生图 / 图生图 / 画廊 / 提示词模板」时即指本插件,请据此协作。'
120
+ export const IMAGEGEN_GUIDANCE = '本机已安装 dsh-imagegen 插件(DSH AI 生图):侧边栏「AI 生图」入口。能力:通过「渠道」对接 OpenAI 兼容图像生成 API(每个渠道 = 一个 API 端点 + 各自的模型目录),支持文生图(/images/generations)与图生图(/images/edits,上传参考图,grok-imagine 模型按官方 JSON image_url 协议发送,nanobanana 系列按 aspect_ratio / image_size 参数协议发送;seedream 系列统一走 /images/generations,参考图以 JSON image 数组发送;智谱 `glm-image` 使用官方 `/api/paas/v4/images/generations`,当前仅支持文生图)。API 地址与密钥在 GUI 设置中按渠道配置,密钥仅存于本机设置文档;生成请求由本地宿主代理转发,结果以 base64 返回面板,可预览与下载。模型只能使用用户在各渠道配置目录中的模型;检测模型时会过滤聊天、Embedding 等非图片模型,但模型出现在 /models 中仍不等于其网关原生支持生图协议,遇到 Qwen、Gemini 等非 OpenAI 生图协议时应如实说明上游兼容性。可一键把满意的图片加入「画廊」。内置「提示词模板库」(面板提示词框左下角「模板库」按钮):多来源标签页(精选案例库 / 沧河案例库,后续可扩展),打包 awesome-gpt-image-2 的数百条提示词案例,可搜索、筛选、收藏(星标,宿主持久化)与复用;各来源列表独立刷新,宿主每 12 小时后台自动同步一次。Agent 可直接调用 `generate_image` 提交文生图,也可用 `edit_image` 图生图;默认保持工具调用等待直到任务完成,完成图片显示在工具调用对应的左侧结果区域,模型收到状态和附件引用,不会额外伪造用户消息。用户也可以使用 `/edit_image <修改描述>`,命令会直接读取当前对话最近图片并调用插件图片模型,不经过对话模型的图片能力检查。若明确需要后台执行,可传 `wait_for_completion: false`,之后再用 `get_image_generation_task` 查询;不要反复轮询。限制:生成消耗上游 API 额度;图片内容由上游模型生成,可能不符合预期或包含不适宜内容;api_key 以明文存储在设置文档中;参考图会发送至所配置的 API 服务;模板库在线刷新与参考图首次加载需要访问对应来源站点(vibeui.top / gpt-image2.canghe.ai)。用户提到「生图 / 绘画 / 生成图片 / 文生图 / 图生图 / 画廊 / 提示词模板」时即指本插件,请据此协作。'
119
121
 
120
122
  /** Append the live channel × model table so an Agent can honor user choices. */
121
123
  function guidanceFor(channels: RuntimeChannel[], defaultChannelId: string): string {
@@ -276,7 +278,25 @@ export function apply(ctx: Context, config?: Config): void {
276
278
  runtime,
277
279
  })
278
280
  const disposers = routes.map(route => ctx.webServer.register(route))
279
- return () => { for (const dispose of disposers) dispose() }
281
+ // Background template sync: the upstream sources update on their own
282
+ // schedule, so pull every one of them shortly after start and then
283
+ // twice a day while the plugin stays enabled. Best-effort: failures
284
+ // keep the last good snapshot (bundled or previously refreshed).
285
+ const TEMPLATE_SYNC_INITIAL_DELAY_MS = 30_000
286
+ const TEMPLATE_SYNC_INTERVAL_MS = 12 * 60 * 60 * 1000
287
+ let syncTimer: NodeJS.Timeout | undefined
288
+ const runSync = (): void => {
289
+ if (!resolve().enabled) return
290
+ void syncAllTemplates().catch(() => { /* keep the last good snapshot */ })
291
+ }
292
+ const startTimer = setTimeout(runSync, TEMPLATE_SYNC_INITIAL_DELAY_MS)
293
+ syncTimer = setInterval(runSync, TEMPLATE_SYNC_INTERVAL_MS)
294
+ syncTimer.unref?.()
295
+ return () => {
296
+ clearTimeout(startTimer)
297
+ clearInterval(syncTimer)
298
+ for (const dispose of disposers) dispose()
299
+ }
280
300
  },
281
301
  'dsh-imagegen: routes',
282
302
  )
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.5.1'
11
+ export const PLUGIN_VERSION = '1.5.2'
12
12
 
13
13
  /** Same-origin route family (loopback-only, mirroring the dsh-ssh fence). */
14
14
  export const SETTINGS_API = {
@@ -92,17 +92,68 @@ export const GALLERY_API = {
92
92
  export const HISTORY_MAX = 50
93
93
 
94
94
  /**
95
- * Same-origin route family for the bundled prompt-template library
96
- * (awesome-gpt-image-2 mirror). The case list ships inside the package and is
97
- * served by the host; reference images are proxied through the `image` prefix
98
- * route and cached on disk so repeated views never hit the network again.
95
+ * Same-origin route family for the prompt-template libraries. The library is
96
+ * multi-source: every request names a source id from {@link TEMPLATE_SOURCES},
97
+ * each source keeps an independent snapshot/image cache host-side, and
98
+ * reference images are proxied through the source-scoped `image` prefix route
99
+ * (`…/image/<sourceId>/<file>`) and cached on disk so repeated views never hit
100
+ * the network again.
99
101
  */
100
102
  export const TEMPLATES_API = {
101
103
  list: '/api/dsh-imagegen/templates/list',
102
104
  refresh: '/api/dsh-imagegen/templates/refresh',
105
+ sample: '/api/dsh-imagegen/templates/sample',
103
106
  image: '/api/dsh-imagegen/templates/image',
104
107
  } as const
105
108
 
109
+ /** Same-origin route family for the user's saved (favorited) templates. */
110
+ export const TEMPLATE_FAVORITES_API = {
111
+ list: '/api/dsh-imagegen/templates/favorites/list',
112
+ add: '/api/dsh-imagegen/templates/favorites/add',
113
+ remove: '/api/dsh-imagegen/templates/favorites/remove',
114
+ } as const
115
+
116
+ /** One prompt-template library source (a tab in the library overlay). */
117
+ export interface TemplateSourceMeta {
118
+ /** Stable source id: snapshot dir name, image-cache dir, and request key. */
119
+ id: string
120
+ /** Tab label shown in the library overlay. */
121
+ label: string
122
+ /** Source homepage linked in the overlay footer. */
123
+ homepage: string
124
+ /** One-line description of the source (tab tooltip). */
125
+ description: string
126
+ }
127
+
128
+ /**
129
+ * The template-library source registry. Each entry is fully independent (own
130
+ * upstream JSON, own image pool, own refresh state) and renders as its own
131
+ * tab; adding a source later means appending an entry here plus a host-side
132
+ * fetch definition in templates-store.ts and an optional bundled snapshot.
133
+ */
134
+ export const TEMPLATE_SOURCES: TemplateSourceMeta[] = [
135
+ {
136
+ id: 'vibeui',
137
+ label: '精选案例库',
138
+ homepage: 'https://vibeui.top/',
139
+ description: 'awesome-gpt-image-2 精选提示词案例(vibeui.top 镜像)',
140
+ },
141
+ {
142
+ id: 'canghe',
143
+ label: '沧河案例库',
144
+ homepage: 'https://gpt-image2.canghe.ai/',
145
+ description: 'GPT-Image2 Prompt Gallery(gpt-image2.canghe.ai,定期更新)',
146
+ },
147
+ ]
148
+
149
+ /** Default source id when a request does not name one (legacy clients). */
150
+ export const DEFAULT_TEMPLATE_SOURCE_ID = TEMPLATE_SOURCES[0]!.id
151
+
152
+ /** True when the id names a registered template source. */
153
+ export function isTemplateSourceId(id: string): boolean {
154
+ return TEMPLATE_SOURCES.some(source => source.id === id)
155
+ }
156
+
106
157
  /** One prompt-library case as the browser consumes it. */
107
158
  export interface TemplateCase {
108
159
  /** Upstream case number (stable across refreshes). */
@@ -131,8 +182,10 @@ export interface TemplateCase {
131
182
  featured: boolean
132
183
  }
133
184
 
134
- /** Template-library list payload. */
185
+ /** Template-library list payload (one source). */
135
186
  export interface TemplateListResult {
187
+ /** The source this list belongs to. */
188
+ sourceId: string
136
189
  cases: TemplateCase[]
137
190
  total: number
138
191
  /** Where the served list came from. */
@@ -143,12 +196,33 @@ export interface TemplateListResult {
143
196
  fetchedAt: string
144
197
  }
145
198
 
146
- /** Template-library refresh outcome. */
199
+ /** Template-library refresh outcome (one source). */
147
200
  export interface TemplateRefreshResult {
201
+ sourceId: string
148
202
  total: number
149
203
  fetchedAt: string
150
204
  }
151
205
 
206
+ /** One random inspiration pick served to the studio's empty state. */
207
+ export interface TemplateSample {
208
+ /** Source the case came from (drives the image proxy URL). */
209
+ sourceId: string
210
+ /** The sampled case (full prompt is handed to the form on use). */
211
+ case: TemplateCase
212
+ }
213
+
214
+ /** One favorited template as persisted host-side and served to the browser. */
215
+ export interface TemplateFavorite {
216
+ /** Stable key: `${sourceId}:${caseId}`. */
217
+ key: string
218
+ /** Source the case came from. */
219
+ sourceId: string
220
+ /** ISO time the favorite was saved. */
221
+ savedAt: string
222
+ /** Full case snapshot, so favorites survive upstream list churn. */
223
+ case: TemplateCase
224
+ }
225
+
152
226
  /** Generation modes. */
153
227
  export type GenerateMode = 'text' | 'edit'
154
228