@dickpy/dsh-imagegen 1.4.0 → 1.5.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 (53) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +270 -124
  3. package/cordis.patch.yml +8 -8
  4. package/docs/images/ecommerce-mode.png +0 -0
  5. package/docs/images/image-generation-studio-three-column.png +0 -0
  6. package/docs/images/imagegen-overview.png +0 -0
  7. package/docs/videos/agent-chat-edit.gif +0 -0
  8. package/docs/videos/agent-chat-edit.mp4 +0 -0
  9. package/lib/client.js +1859 -420
  10. package/lib/client.js.map +1 -1
  11. package/lib/index.js +327 -112
  12. package/package.json +69 -68
  13. package/src/agent-image-tools.ts +447 -418
  14. package/src/client/ImageGenPanel.tsx +1242 -348
  15. package/src/client/SettingsCard.tsx +936 -936
  16. package/src/client/TemplateLibrary.tsx +336 -336
  17. package/src/client/api.ts +203 -193
  18. package/src/client/channels-form.ts +263 -263
  19. package/src/client/controller.ts +46 -46
  20. package/src/client/conversation-sync.ts +14 -14
  21. package/src/client/css-modules.d.ts +5 -5
  22. package/src/client/helpers.ts +33 -33
  23. package/src/client/image-toolview.module.css +73 -73
  24. package/src/client/image-toolview.tsx +18 -18
  25. package/src/client/index.ts +22 -22
  26. package/src/client/locales.ts +156 -28
  27. package/src/client/mount.tsx +117 -117
  28. package/src/client/panel.module.css +1243 -455
  29. package/src/client/settings-card.module.css +1023 -1023
  30. package/src/client/settings-form.ts +336 -336
  31. package/src/client/settings-scope.ts +298 -298
  32. package/src/client/sidebar-entry.ts +190 -190
  33. package/src/client/templates.module.css +453 -453
  34. package/src/edit-image-command.ts +110 -0
  35. package/src/engine.ts +520 -520
  36. package/src/gallery-store.ts +306 -286
  37. package/src/generation-runtime.ts +84 -79
  38. package/src/history-store.ts +270 -250
  39. package/src/image-format.ts +11 -11
  40. package/src/image-models.ts +19 -19
  41. package/src/index.ts +337 -318
  42. package/src/model-catalog.ts +115 -115
  43. package/src/presets.ts +71 -71
  44. package/src/prompt-enhancer.ts +137 -137
  45. package/src/protocol.ts +380 -338
  46. package/src/routes.ts +964 -916
  47. package/src/task-queue.ts +113 -113
  48. package/src/templates/cases.json +10196 -10196
  49. package/src/templates-store.ts +278 -278
  50. package/src/updater.ts +117 -117
  51. package/docs/images/agent-chat-edit.png +0 -0
  52. package/docs/images/agent-chat-generate.png +0 -0
  53. package/docs/images/agent-chat-poster-workflow.png +0 -0
package/src/updater.ts CHANGED
@@ -1,117 +1,117 @@
1
- /** GitHub Release discovery and explicit, user-triggered plugin updates. */
2
-
3
- import { spawn, type ChildProcess } from 'node:child_process'
4
- import { PLUGIN_VERSION } from './protocol.ts'
5
-
6
- /** Keep this in sync with package.json for each published release. */
7
- export const CURRENT_VERSION = PLUGIN_VERSION
8
- export const PACKAGE_NAME = '@dickpy/dsh-imagegen'
9
- export const RELEASES_URL = 'https://api.github.com/repos/dickpy/dsh-imagegen/releases/latest'
10
-
11
- const CHECK_TIMEOUT_MS = 10_000
12
- const CACHE_TTL_MS = 15 * 60_000
13
-
14
- export interface UpdateInfo {
15
- currentVersion: string
16
- latestVersion: string
17
- updateAvailable: boolean
18
- releaseUrl: string
19
- publishedAt?: string
20
- }
21
-
22
- interface GitHubRelease {
23
- tag_name?: unknown
24
- html_url?: unknown
25
- published_at?: unknown
26
- draft?: unknown
27
- prerelease?: unknown
28
- }
29
-
30
- let cached: { expiresAt: number; value: UpdateInfo } | undefined
31
-
32
- /** Compare stable semver triples; returns positive when `left` is newer. */
33
- export function compareVersions(left: string, right: string): number {
34
- const parse = (value: string): [number, number, number] => {
35
- const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(value.trim())
36
- if (match === null) return [0, 0, 0]
37
- return [Number(match[1]), Number(match[2]), Number(match[3])]
38
- }
39
- const a = parse(left)
40
- const b = parse(right)
41
- return a[0] - b[0] || a[1] - b[1] || a[2] - b[2]
42
- }
43
-
44
- function normalizedReleaseVersion(tag: unknown): string | undefined {
45
- if (typeof tag !== 'string' || !/^v?\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(tag.trim())) return undefined
46
- return tag.trim().replace(/^v/, '')
47
- }
48
-
49
- /** Read the latest stable GitHub Release, with a short host-side cache. */
50
- export async function checkForUpdate(fetchFn: typeof fetch = fetch, now = Date.now()): Promise<UpdateInfo> {
51
- if (cached !== undefined && cached.expiresAt > now) return cached.value
52
- const response = await fetchFn(RELEASES_URL, {
53
- headers: {
54
- accept: 'application/vnd.github+json',
55
- 'user-agent': 'dsh-imagegen-update-check',
56
- },
57
- signal: AbortSignal.timeout(CHECK_TIMEOUT_MS),
58
- })
59
- if (!response.ok) throw new Error(`GitHub Releases returned HTTP ${response.status}`)
60
- const payload: unknown = await response.json()
61
- if (payload === null || typeof payload !== 'object') throw new Error('GitHub Releases returned malformed JSON')
62
- const release = payload as GitHubRelease
63
- if (release.draft === true || release.prerelease === true) throw new Error('latest GitHub Release is not stable')
64
- const latestVersion = normalizedReleaseVersion(release.tag_name)
65
- if (latestVersion === undefined) throw new Error('latest GitHub Release has an invalid version tag')
66
- const releaseUrl = typeof release.html_url === 'string' ? release.html_url : 'https://github.com/dickpy/dsh-imagegen/releases'
67
- const value: UpdateInfo = {
68
- currentVersion: CURRENT_VERSION,
69
- latestVersion,
70
- updateAvailable: compareVersions(latestVersion, CURRENT_VERSION) > 0,
71
- releaseUrl,
72
- ...typeof release.published_at === 'string' ? { publishedAt: release.published_at } : {},
73
- }
74
- cached = { expiresAt: now + CACHE_TTL_MS, value }
75
- return value
76
- }
77
-
78
- /** Resolve the profile that launched the current DSH process. */
79
- export function profileFromProcess(argv: readonly string[] = process.argv, env: NodeJS.ProcessEnv = process.env): string {
80
- const envProfile = env.DSH_PROFILE?.trim()
81
- if (envProfile !== undefined && /^[a-zA-Z0-9_-]+$/.test(envProfile)) return envProfile
82
- const profileIndex = argv.indexOf('--profile')
83
- const explicit = profileIndex >= 0 ? argv[profileIndex + 1]?.trim() : undefined
84
- if (explicit !== undefined && /^[a-zA-Z0-9_-]+$/.test(explicit)) return explicit
85
- if (argv.includes('web')) return 'web'
86
- return 'web'
87
- }
88
-
89
- /** Run the same official command documented for plugin installation. */
90
- export function installUpdate(
91
- version: string,
92
- spawnFn: typeof spawn = spawn,
93
- argv: readonly string[] = process.argv,
94
- env: NodeJS.ProcessEnv = process.env,
95
- ): Promise<void> {
96
- if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) {
97
- return Promise.reject(new Error('invalid update version'))
98
- }
99
- const profile = profileFromProcess(argv, env)
100
- const command = process.platform === 'win32' ? 'dsh.cmd' : 'dsh'
101
- const child = spawnFn(command, ['plugin', '--profile', profile, 'add', `${PACKAGE_NAME}@${version}`], {
102
- shell: process.platform === 'win32',
103
- stdio: 'ignore',
104
- }) as ChildProcess
105
- return new Promise((resolve, reject) => {
106
- child.once('error', reject)
107
- child.once('exit', (code, signal) => {
108
- if (code === 0) resolve()
109
- else reject(new Error(signal === null ? `plugin update exited with code ${code ?? 'unknown'}` : `plugin update terminated by ${signal}`))
110
- })
111
- })
112
- }
113
-
114
- /** Test helper: clear the host-side Release cache. */
115
- export function clearUpdateCache(): void {
116
- cached = undefined
117
- }
1
+ /** GitHub Release discovery and explicit, user-triggered plugin updates. */
2
+
3
+ import { spawn, type ChildProcess } from 'node:child_process'
4
+ import { PLUGIN_VERSION } from './protocol.ts'
5
+
6
+ /** Keep this in sync with package.json for each published release. */
7
+ export const CURRENT_VERSION = PLUGIN_VERSION
8
+ export const PACKAGE_NAME = '@dickpy/dsh-imagegen'
9
+ export const RELEASES_URL = 'https://api.github.com/repos/dickpy/dsh-imagegen/releases/latest'
10
+
11
+ const CHECK_TIMEOUT_MS = 10_000
12
+ const CACHE_TTL_MS = 15 * 60_000
13
+
14
+ export interface UpdateInfo {
15
+ currentVersion: string
16
+ latestVersion: string
17
+ updateAvailable: boolean
18
+ releaseUrl: string
19
+ publishedAt?: string
20
+ }
21
+
22
+ interface GitHubRelease {
23
+ tag_name?: unknown
24
+ html_url?: unknown
25
+ published_at?: unknown
26
+ draft?: unknown
27
+ prerelease?: unknown
28
+ }
29
+
30
+ let cached: { expiresAt: number; value: UpdateInfo } | undefined
31
+
32
+ /** Compare stable semver triples; returns positive when `left` is newer. */
33
+ export function compareVersions(left: string, right: string): number {
34
+ const parse = (value: string): [number, number, number] => {
35
+ const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(value.trim())
36
+ if (match === null) return [0, 0, 0]
37
+ return [Number(match[1]), Number(match[2]), Number(match[3])]
38
+ }
39
+ const a = parse(left)
40
+ const b = parse(right)
41
+ return a[0] - b[0] || a[1] - b[1] || a[2] - b[2]
42
+ }
43
+
44
+ function normalizedReleaseVersion(tag: unknown): string | undefined {
45
+ if (typeof tag !== 'string' || !/^v?\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(tag.trim())) return undefined
46
+ return tag.trim().replace(/^v/, '')
47
+ }
48
+
49
+ /** Read the latest stable GitHub Release, with a short host-side cache. */
50
+ export async function checkForUpdate(fetchFn: typeof fetch = fetch, now = Date.now()): Promise<UpdateInfo> {
51
+ if (cached !== undefined && cached.expiresAt > now) return cached.value
52
+ const response = await fetchFn(RELEASES_URL, {
53
+ headers: {
54
+ accept: 'application/vnd.github+json',
55
+ 'user-agent': 'dsh-imagegen-update-check',
56
+ },
57
+ signal: AbortSignal.timeout(CHECK_TIMEOUT_MS),
58
+ })
59
+ if (!response.ok) throw new Error(`GitHub Releases returned HTTP ${response.status}`)
60
+ const payload: unknown = await response.json()
61
+ if (payload === null || typeof payload !== 'object') throw new Error('GitHub Releases returned malformed JSON')
62
+ const release = payload as GitHubRelease
63
+ if (release.draft === true || release.prerelease === true) throw new Error('latest GitHub Release is not stable')
64
+ const latestVersion = normalizedReleaseVersion(release.tag_name)
65
+ if (latestVersion === undefined) throw new Error('latest GitHub Release has an invalid version tag')
66
+ const releaseUrl = typeof release.html_url === 'string' ? release.html_url : 'https://github.com/dickpy/dsh-imagegen/releases'
67
+ const value: UpdateInfo = {
68
+ currentVersion: CURRENT_VERSION,
69
+ latestVersion,
70
+ updateAvailable: compareVersions(latestVersion, CURRENT_VERSION) > 0,
71
+ releaseUrl,
72
+ ...typeof release.published_at === 'string' ? { publishedAt: release.published_at } : {},
73
+ }
74
+ cached = { expiresAt: now + CACHE_TTL_MS, value }
75
+ return value
76
+ }
77
+
78
+ /** Resolve the profile that launched the current DSH process. */
79
+ export function profileFromProcess(argv: readonly string[] = process.argv, env: NodeJS.ProcessEnv = process.env): string {
80
+ const envProfile = env.DSH_PROFILE?.trim()
81
+ if (envProfile !== undefined && /^[a-zA-Z0-9_-]+$/.test(envProfile)) return envProfile
82
+ const profileIndex = argv.indexOf('--profile')
83
+ const explicit = profileIndex >= 0 ? argv[profileIndex + 1]?.trim() : undefined
84
+ if (explicit !== undefined && /^[a-zA-Z0-9_-]+$/.test(explicit)) return explicit
85
+ if (argv.includes('web')) return 'web'
86
+ return 'web'
87
+ }
88
+
89
+ /** Run the same official command documented for plugin installation. */
90
+ export function installUpdate(
91
+ version: string,
92
+ spawnFn: typeof spawn = spawn,
93
+ argv: readonly string[] = process.argv,
94
+ env: NodeJS.ProcessEnv = process.env,
95
+ ): Promise<void> {
96
+ if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) {
97
+ return Promise.reject(new Error('invalid update version'))
98
+ }
99
+ const profile = profileFromProcess(argv, env)
100
+ const command = process.platform === 'win32' ? 'dsh.cmd' : 'dsh'
101
+ const child = spawnFn(command, ['plugin', '--profile', profile, 'add', `${PACKAGE_NAME}@${version}`], {
102
+ shell: process.platform === 'win32',
103
+ stdio: 'ignore',
104
+ }) as ChildProcess
105
+ return new Promise((resolve, reject) => {
106
+ child.once('error', reject)
107
+ child.once('exit', (code, signal) => {
108
+ if (code === 0) resolve()
109
+ else reject(new Error(signal === null ? `plugin update exited with code ${code ?? 'unknown'}` : `plugin update terminated by ${signal}`))
110
+ })
111
+ })
112
+ }
113
+
114
+ /** Test helper: clear the host-side Release cache. */
115
+ export function clearUpdateCache(): void {
116
+ cached = undefined
117
+ }
Binary file
Binary file