dsh-image-lite 0.1.1 → 0.2.1
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/assets/icon.svg +19 -0
- package/client.js +228 -58
- package/index.js +33 -67
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +6 -2
package/assets/icon.svg
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<!-- Subject: one framed picture with a landscape inside — the studio's own
|
|
3
|
+
output at its simplest. Drafted to references/artwork.md: 36x36 canvas,
|
|
4
|
+
no tile or background (Plugin Manager draws the tile), ink box 22x17
|
|
5
|
+
centred on (18,18), flat two-stop gradient borrowed from the installed
|
|
6
|
+
icons it sits beside (#69B9FF -> #324DE2), no text, no effects. -->
|
|
7
|
+
<rect x="7" y="9.5" width="22" height="17" rx="3.2" stroke="url(#igl-frame)" stroke-width="2.2"/>
|
|
8
|
+
<path d="M9.6 23.4l4.5-4.4a2.1 2.1 0 0 1 2.9 0l2.1 2.1" stroke="url(#igl-frame)" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
9
|
+
<circle cx="13.4" cy="15.3" r="1.85" fill="url(#igl-frame)"/>
|
|
10
|
+
<defs>
|
|
11
|
+
<linearGradient id="igl-frame" x1="18" y1="9.5" x2="18" y2="26.5" gradientUnits="userSpaceOnUse">
|
|
12
|
+
<stop stop-color="#69B9FF"/>
|
|
13
|
+
<stop offset="1" stop-color="#324DE2"/>
|
|
14
|
+
</linearGradient>
|
|
15
|
+
</defs>
|
|
16
|
+
</svg>
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
package/client.js
CHANGED
|
@@ -28,14 +28,71 @@ window.__ModuleLoader__.load({
|
|
|
28
28
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
29
29
|
|
|
30
30
|
const React = require('react')
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
// Glyphs are drawn here instead of imported. `@deepseek-ai/dsh-client-ui-primitives`
|
|
32
|
+
// exports no generic icon set (only its own `GuideArtwork*` illustrations), and a
|
|
33
|
+
// third-party client's module table need not resolve it at all — so every glyph
|
|
34
|
+
// used to fall through to a text label. Local SVGs render on any release, keep the
|
|
35
|
+
// product's stroke weight, and inherit `currentColor` from the button around them.
|
|
36
|
+
const glyph = (props, ...children) => React.createElement('svg', {
|
|
37
|
+
width: props.size ?? 16,
|
|
38
|
+
height: props.size ?? 16,
|
|
39
|
+
viewBox: '0 0 16 16',
|
|
40
|
+
fill: 'none',
|
|
41
|
+
stroke: 'currentColor',
|
|
42
|
+
strokeWidth: 1.4,
|
|
43
|
+
strokeLinecap: 'round',
|
|
44
|
+
strokeLinejoin: 'round',
|
|
45
|
+
className: props.className,
|
|
46
|
+
'aria-hidden': 'true',
|
|
47
|
+
focusable: 'false',
|
|
48
|
+
}, ...children)
|
|
49
|
+
const glyphPath = (d, extra) => React.createElement('path', { d, ...extra })
|
|
50
|
+
|
|
51
|
+
function IconClose(props) {
|
|
52
|
+
return glyph(props, glyphPath('M4.6 4.6l6.8 6.8'), glyphPath('M11.4 4.6l-6.8 6.8'))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function IconTrash(props) {
|
|
56
|
+
return glyph(props,
|
|
57
|
+
glyphPath('M3 4.4h10'),
|
|
58
|
+
glyphPath('M6.4 4.4V3.1h3.2v1.3'),
|
|
59
|
+
glyphPath('M4.7 4.4l.6 8.1a.9.9 0 0 0 .9.8h3.6a.9.9 0 0 0 .9-.8l.6-8.1'),
|
|
60
|
+
glyphPath('M6.8 6.8v4.2'),
|
|
61
|
+
glyphPath('M9.2 6.8v4.2'))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function IconPlus(props) {
|
|
65
|
+
return glyph(props, glyphPath('M8 3.6v8.8'), glyphPath('M3.6 8h8.8'))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function IconSparkle(props) {
|
|
69
|
+
return glyph(props, glyphPath('M8 2.6c.55 2.5 1.9 3.85 4.4 4.4-2.5.55-3.85 1.9-4.4 4.4-.55-2.5-1.9-3.85-4.4-4.4 2.5-.55 3.85-1.9 4.4-4.4Z'))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// The 开始 guide capsule draws a fixed-palette 36px illustration (the same
|
|
73
|
+
// contract the shipped `GuideArtwork*` components follow): one framed
|
|
74
|
+
// picture, the studio's own output at its simplest, so the card stops
|
|
75
|
+
// showing the guide's cube placeholder. Flat #539CFA keeps it legible on the
|
|
76
|
+
// guide's dark card; the plugin row's icon in `assets/icon.svg` carries the
|
|
77
|
+
// same drawing as a gradient, where it sits beside other gradient icons.
|
|
78
|
+
function StudioArtwork({ size = 36, className } = {}) {
|
|
79
|
+
return React.createElement('svg', {
|
|
80
|
+
width: size,
|
|
81
|
+
height: size,
|
|
82
|
+
className,
|
|
83
|
+
viewBox: '0 0 36 36',
|
|
84
|
+
fill: 'none',
|
|
85
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
86
|
+
'aria-hidden': 'true',
|
|
87
|
+
focusable: 'false',
|
|
88
|
+
},
|
|
89
|
+
React.createElement('rect', { x: 7, y: 9.5, width: 22, height: 17, rx: 3.2, stroke: '#539CFA', strokeWidth: 2.2 }),
|
|
90
|
+
React.createElement('path', {
|
|
91
|
+
d: 'M9.6 23.4l4.5-4.4a2.1 2.1 0 0 1 2.9 0l2.1 2.1',
|
|
92
|
+
stroke: '#539CFA', strokeWidth: 2.2, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
93
|
+
}),
|
|
94
|
+
React.createElement('circle', { cx: 13.4, cy: 15.3, r: 1.85, fill: '#539CFA' }),
|
|
95
|
+
)
|
|
39
96
|
}
|
|
40
97
|
// A `position: fixed` overlay is still clipped when an ancestor creates a
|
|
41
98
|
// containing block (`transform` / `filter` / `contain`) — the right sidebar
|
|
@@ -48,12 +105,6 @@ window.__ModuleLoader__.load({
|
|
|
48
105
|
} catch {
|
|
49
106
|
portalFactory = null
|
|
50
107
|
}
|
|
51
|
-
const pickIcon = (...names) => names.map((n) => primitives[n]).find((v) => typeof v === 'function')
|
|
52
|
-
const IconClose = pickIcon('IconCloseOutline16', 'IconCloseOutlineRegular', 'IconCloseOutlineMedium')
|
|
53
|
-
const IconTrash = pickIcon('IconTrashOutline16', 'IconTrashOutlineRegular', 'IconTrashOutlineMedium')
|
|
54
|
-
const IconPlus = pickIcon('IconPlusOutline16', 'IconPlusOutlineRegular', 'IconPlusOutlineMedium')
|
|
55
|
-
const IconSparkle = pickIcon('IconSparkle16', 'IconSparkleRegular', 'IconSparkleMedium')
|
|
56
|
-
|
|
57
108
|
const ENTRY_NS = 'image-gen-lite'
|
|
58
109
|
const LOCALE_NS = 'image-gen-lite'
|
|
59
110
|
const RPC_CHANNEL = '/image-gen-lite'
|
|
@@ -83,6 +134,8 @@ window.__ModuleLoader__.load({
|
|
|
83
134
|
refs: 'Reference images',
|
|
84
135
|
refsEmpty: 'No references yet. Upload, paste, or click "keep editing" on a result below.',
|
|
85
136
|
refsFull: 'Up to 5 reference images.',
|
|
137
|
+
refsPartial: 'Only part of the selection was added — up to 5 references fit.',
|
|
138
|
+
cancelled: 'Generation cancelled.',
|
|
86
139
|
upload: 'Upload',
|
|
87
140
|
clear: 'Clear',
|
|
88
141
|
clearHint: 'Clear references, prompt and results to start a new picture.',
|
|
@@ -128,6 +181,7 @@ window.__ModuleLoader__.load({
|
|
|
128
181
|
keyPlaceholder: 'sk-… paste the API key',
|
|
129
182
|
keyHint: 'Stored in the DSH credentials service — the config keeps only a masked preview.',
|
|
130
183
|
keyStoredHint: 'Already stored: {hint}. Leave empty to keep it.',
|
|
184
|
+
keySaved: 'Saved: {hint}',
|
|
131
185
|
keyEnvHint: 'Read from the environment (or an existing credential) under this name.',
|
|
132
186
|
keyReplaceHint: 'The old value here is not a credential name — paste the API key to replace it.',
|
|
133
187
|
keyWriteFailed: 'Could not store the API key: {reason}',
|
|
@@ -172,6 +226,8 @@ window.__ModuleLoader__.load({
|
|
|
172
226
|
refs: '参考图',
|
|
173
227
|
refsEmpty: '暂无参考图。可上传、粘贴,或在下方结果里点「用这张继续」。',
|
|
174
228
|
refsFull: '最多 5 张参考图。',
|
|
229
|
+
refsPartial: '只加入了其中一部分:参考图最多 5 张。',
|
|
230
|
+
cancelled: '已取消生成。',
|
|
175
231
|
upload: '上传',
|
|
176
232
|
clear: '清空',
|
|
177
233
|
clearHint: '清空参考图、描述和结果,开始新的生成。',
|
|
@@ -216,6 +272,7 @@ window.__ModuleLoader__.load({
|
|
|
216
272
|
keyPlaceholder: 'sk-… 粘贴 API 密钥',
|
|
217
273
|
keyHint: '保存到 DSH 凭据服务,配置里只留加密预览。',
|
|
218
274
|
keyStoredHint: '已保存:{hint}。留空则保持不变。',
|
|
275
|
+
keySaved: '已保存:{hint}',
|
|
219
276
|
keyEnvHint: '从这个名字的环境变量(或已有凭据)读取。',
|
|
220
277
|
keyReplaceHint: '原来那串不是凭据名,粘贴 API 密钥即可替换。',
|
|
221
278
|
keyWriteFailed: '密钥保存失败:{reason}',
|
|
@@ -498,8 +555,11 @@ window.__ModuleLoader__.load({
|
|
|
498
555
|
|
|
499
556
|
// ---------------------------------------------------------------- RPC
|
|
500
557
|
|
|
501
|
-
async function rpcCall(rpc, endpoint, payload) {
|
|
502
|
-
|
|
558
|
+
async function rpcCall(rpc, endpoint, payload, signal) {
|
|
559
|
+
// `signal` rides along to Connection's `rpc.call(channel, endpoint,
|
|
560
|
+
// payload, signal)`, which aborts the request and, through the host
|
|
561
|
+
// bridge, cancels the generation instead of letting it burn tokens.
|
|
562
|
+
const result = await rpc.call(RPC_CHANNEL, endpoint, payload, signal)
|
|
503
563
|
if (!result.ok) throw new Error(result.error?.message ?? String(result.error))
|
|
504
564
|
return result.value
|
|
505
565
|
}
|
|
@@ -648,7 +708,10 @@ window.__ModuleLoader__.load({
|
|
|
648
708
|
.then((url) => { if (!cancelled) setSrc(url) })
|
|
649
709
|
.catch(() => { if (!cancelled) setFailed(true) })
|
|
650
710
|
return () => { cancelled = true }
|
|
651
|
-
|
|
711
|
+
// `load` is rebuilt whenever cwd/sessionId arrive, and the `file`
|
|
712
|
+
// endpoint resolves relative paths against that cwd: without it here a
|
|
713
|
+
// tile that loaded before cwd was known never retries.
|
|
714
|
+
}, [key, tick, load])
|
|
652
715
|
|
|
653
716
|
if (failed) {
|
|
654
717
|
return React.createElement('button', {
|
|
@@ -710,7 +773,7 @@ window.__ModuleLoader__.load({
|
|
|
710
773
|
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
711
774
|
},
|
|
712
775
|
onClick: onClose,
|
|
713
|
-
},
|
|
776
|
+
}, React.createElement(IconClose, { size: 16 })),
|
|
714
777
|
)
|
|
715
778
|
|
|
716
779
|
// No portal runtime (older bundle): still better than a clipped overlay.
|
|
@@ -774,7 +837,7 @@ window.__ModuleLoader__.load({
|
|
|
774
837
|
const text = textParts.join('\n')
|
|
775
838
|
return React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, padding: '4px 0' } },
|
|
776
839
|
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 6 } },
|
|
777
|
-
|
|
840
|
+
React.createElement(IconSparkle, { size: 14 }),
|
|
778
841
|
React.createElement('span', {
|
|
779
842
|
style: { fontSize: 13, lineHeight: '20px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
780
843
|
}, `${TOOL_NAME}: ${derivePrompt(argsRaw)}`)),
|
|
@@ -903,11 +966,20 @@ window.__ModuleLoader__.load({
|
|
|
903
966
|
...buildActiveFromOption({ ...option, baseUrl: provider?.baseUrl, apiKeyEnv: provider?.apiKeyEnv }),
|
|
904
967
|
}
|
|
905
968
|
: emptyActiveValue()
|
|
906
|
-
|
|
969
|
+
// `mutate` resolves false when the form rejected the write (stale
|
|
970
|
+
// revision, read-only); swallowing that leaves the picker bouncing back
|
|
971
|
+
// with no explanation.
|
|
972
|
+
setProviderError('')
|
|
973
|
+
void liteForm.mutate([{ op: 'set', path: ['active'], value: nextActive }])
|
|
974
|
+
.then((result) => { if (result === false) setProviderError(t('saveFailed')) })
|
|
975
|
+
.catch((error) => setProviderError(`${t('saveFailed')} ${error?.message ?? String(error)}`))
|
|
907
976
|
}
|
|
908
977
|
|
|
909
978
|
function pickAspect(value) {
|
|
910
|
-
|
|
979
|
+
setProviderError('')
|
|
980
|
+
void liteForm.mutate([{ op: 'set', path: ['activeAspect'], value }])
|
|
981
|
+
.then((result) => { if (result === false) setProviderError(t('saveFailed')) })
|
|
982
|
+
.catch((error) => setProviderError(`${t('saveFailed')} ${error?.message ?? String(error)}`))
|
|
911
983
|
}
|
|
912
984
|
|
|
913
985
|
function saveSidebarEnabled(next) {
|
|
@@ -955,7 +1027,7 @@ window.__ModuleLoader__.load({
|
|
|
955
1027
|
? React.createElement('button', {
|
|
956
1028
|
type: 'button', className: 'dsh-igl-btn',
|
|
957
1029
|
onClick: () => setEditing(draftFromProvider(null, providers)),
|
|
958
|
-
},
|
|
1030
|
+
}, React.createElement(IconPlus, { size: 12 }), t('addProvider'))
|
|
959
1031
|
: null,
|
|
960
1032
|
),
|
|
961
1033
|
editing !== null
|
|
@@ -1072,7 +1144,12 @@ window.__ModuleLoader__.load({
|
|
|
1072
1144
|
async function pickFolderPath(ctx) {
|
|
1073
1145
|
const bridge = globalThis.__DSH_DIRECTORY_PICKER__
|
|
1074
1146
|
if (bridge !== undefined && typeof bridge.pick === 'function') return await bridge.pick()
|
|
1075
|
-
|
|
1147
|
+
// Read the service through ctx.get, never as `ctx.uiWorkspace`: on cordis
|
|
1148
|
+
// 4.x a service that is not in `inject` throws "cannot get property ...
|
|
1149
|
+
// without inject" on access, which would skip this fallback entirely
|
|
1150
|
+
// instead of reaching it (same trap as the host-side webServer mount).
|
|
1151
|
+
let ui
|
|
1152
|
+
try { ui = typeof ctx?.get === 'function' ? ctx.get('uiWorkspace') : undefined } catch { ui = undefined }
|
|
1076
1153
|
if (ui !== undefined && typeof ui.pickDirectory === 'function') return await ui.pickDirectory()
|
|
1077
1154
|
throw new Error('image_generate_lite: this runtime exposes no directory picker')
|
|
1078
1155
|
}
|
|
@@ -1258,7 +1335,7 @@ window.__ModuleLoader__.load({
|
|
|
1258
1335
|
React.createElement('div', { style: { display: 'flex', gap: 6, flex: 'none' } },
|
|
1259
1336
|
React.createElement('button', { type: 'button', className: 'dsh-igl-btn', onClick: onEdit }, t('editProvider')),
|
|
1260
1337
|
React.createElement('button', { type: 'button', className: 'dsh-igl-btn', onClick: onDelete, 'aria-label': t('deleteProvider') },
|
|
1261
|
-
|
|
1338
|
+
React.createElement(IconTrash, { size: 12 })),
|
|
1262
1339
|
),
|
|
1263
1340
|
)
|
|
1264
1341
|
}
|
|
@@ -1343,6 +1420,12 @@ window.__ModuleLoader__.load({
|
|
|
1343
1420
|
|
|
1344
1421
|
// ---------------------------------------------------------------- studio panel
|
|
1345
1422
|
|
|
1423
|
+
/** True when a drag carries real files (not just text or a link). */
|
|
1424
|
+
function carriesFiles(event) {
|
|
1425
|
+
const types = event?.dataTransfer?.types
|
|
1426
|
+
return types !== undefined && types !== null && Array.from(types).includes('Files')
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1346
1429
|
function StudioBody(props) {
|
|
1347
1430
|
const t = props.t ?? translateFactory(en)
|
|
1348
1431
|
const { ctx, rpc, sessionId, liteForm, useSessions } = props
|
|
@@ -1351,6 +1434,17 @@ window.__ModuleLoader__.load({
|
|
|
1351
1434
|
const [error, setError] = React.useState('')
|
|
1352
1435
|
const [prompt, setPrompt] = React.useState(store.prompt)
|
|
1353
1436
|
const [refsFocus, setRefsFocus] = React.useState(false)
|
|
1437
|
+
const [dragging, setDragging] = React.useState(false)
|
|
1438
|
+
// The refs the uploader reads at *execution* time (a render-time count
|
|
1439
|
+
// goes stale between two quick pastes), the queue that keeps uploads
|
|
1440
|
+
// serialized, and the controller of the run in flight for cancellation.
|
|
1441
|
+
const refsRef = React.useRef(store.refs)
|
|
1442
|
+
const uploadChain = React.useRef(Promise.resolve())
|
|
1443
|
+
const abortRef = React.useRef(null)
|
|
1444
|
+
React.useEffect(() => { refsRef.current = store.refs }, [store.refs])
|
|
1445
|
+
// Leaving the panel aborts the run: it used to keep generating (and
|
|
1446
|
+
// billing) after the tab was closed.
|
|
1447
|
+
React.useEffect(() => () => { abortRef.current?.abort() }, [])
|
|
1354
1448
|
|
|
1355
1449
|
const liteSnap = useSnapshot(liteForm)
|
|
1356
1450
|
|
|
@@ -1379,42 +1473,66 @@ window.__ModuleLoader__.load({
|
|
|
1379
1473
|
if (!option) return
|
|
1380
1474
|
const provider = providers.find((p) => p.id === option.providerId)
|
|
1381
1475
|
try {
|
|
1382
|
-
await liteForm.mutate([{
|
|
1476
|
+
const applied = await liteForm.mutate([{
|
|
1383
1477
|
op: 'set',
|
|
1384
1478
|
path: ['active'],
|
|
1385
1479
|
value: {
|
|
1386
1480
|
...buildActiveFromOption({ ...option, baseUrl: provider?.baseUrl, apiKeyEnv: provider?.apiKeyEnv }),
|
|
1387
1481
|
},
|
|
1388
1482
|
}])
|
|
1389
|
-
|
|
1483
|
+
if (applied === false) setError(t('saveFailed'))
|
|
1484
|
+
} catch (error) { setError(`${t('saveFailed')} ${error?.message ?? String(error)}`) }
|
|
1390
1485
|
}
|
|
1391
1486
|
|
|
1392
1487
|
async function pickAspect(value) {
|
|
1393
1488
|
try {
|
|
1394
|
-
await liteForm.mutate([{ op: 'set', path: ['activeAspect'], value }])
|
|
1395
|
-
|
|
1489
|
+
const applied = await liteForm.mutate([{ op: 'set', path: ['activeAspect'], value }])
|
|
1490
|
+
if (applied === false) setError(t('saveFailed'))
|
|
1491
|
+
} catch (error) { setError(`${t('saveFailed')} ${error?.message ?? String(error)}`) }
|
|
1396
1492
|
}
|
|
1397
1493
|
|
|
1398
|
-
|
|
1494
|
+
function addFiles(fileList) {
|
|
1399
1495
|
const files = Array.from(fileList ?? []).filter((f) => /^image\/(png|jpe?g|webp|gif)$/i.test(f.type))
|
|
1400
|
-
if (files.length === 0) return
|
|
1401
|
-
|
|
1496
|
+
if (files.length === 0) return Promise.resolve()
|
|
1497
|
+
// Serialize every upload. Two quick pastes used to read the same
|
|
1498
|
+
// render-time ref count, both pass the room check and upload twice —
|
|
1499
|
+
// the second batch then losing to a silent `.slice(0, MAX_REFS)`.
|
|
1500
|
+
const next = uploadChain.current.then(() => uploadFiles(files), () => uploadFiles(files))
|
|
1501
|
+
uploadChain.current = next.catch(() => {})
|
|
1502
|
+
return next
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
async function uploadFiles(files) {
|
|
1506
|
+
const base = refsRef.current
|
|
1507
|
+
const room = MAX_REFS - base.length
|
|
1402
1508
|
if (room <= 0) { setError(t('refsFull')); return }
|
|
1403
|
-
const
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
reader.onerror = () => rejectData(reader.error)
|
|
1409
|
-
reader.readAsDataURL(file)
|
|
1410
|
-
})
|
|
1411
|
-
items.push({ data, mediaType: file.type === 'image/jpg' ? 'image/jpeg' : file.type, name: file.name })
|
|
1412
|
-
}
|
|
1509
|
+
const accepted = files.slice(0, room)
|
|
1510
|
+
const skipped = files.length - accepted.length
|
|
1511
|
+
// Everything that can fail sits inside one try: the FileReader awaits
|
|
1512
|
+
// used to sit outside it, so an unreadable file rejected the whole call
|
|
1513
|
+
// and every caller (paste, drop, file input) dropped it unhandled.
|
|
1413
1514
|
try {
|
|
1515
|
+
const items = []
|
|
1516
|
+
for (const file of accepted) {
|
|
1517
|
+
const data = await new Promise((resolveData, rejectData) => {
|
|
1518
|
+
const reader = new FileReader()
|
|
1519
|
+
reader.onload = () => resolveData(String(reader.result).split(',', 2)[1] ?? '')
|
|
1520
|
+
reader.onerror = () => rejectData(new Error(reader.error?.message ?? `cannot read ${file.name}`))
|
|
1521
|
+
reader.readAsDataURL(file)
|
|
1522
|
+
})
|
|
1523
|
+
items.push({ data, mediaType: file.type === 'image/jpg' ? 'image/jpeg' : file.type, name: file.name })
|
|
1524
|
+
}
|
|
1414
1525
|
const value = await rpcCall(rpc, 'admitImages', { items })
|
|
1415
|
-
const fresh = value.refs.filter((ref) => !
|
|
1416
|
-
|
|
1417
|
-
|
|
1526
|
+
const fresh = value.refs.filter((ref) => !base.some((r) => r.attachmentId === ref.attachmentId))
|
|
1527
|
+
const merged = [...base, ...fresh].slice(0, MAX_REFS)
|
|
1528
|
+
refsRef.current = merged
|
|
1529
|
+
if (fresh.length > 0) updateStore((prev) => ({
|
|
1530
|
+
...prev,
|
|
1531
|
+
refs: [...prev.refs, ...fresh.filter((ref) => !prev.refs.some((r) => r.attachmentId === ref.attachmentId))].slice(0, MAX_REFS),
|
|
1532
|
+
}))
|
|
1533
|
+
// Never drop the overflow on the floor: say what actually landed.
|
|
1534
|
+
if (skipped > 0 || base.length + fresh.length > MAX_REFS) setError(t('refsPartial'))
|
|
1535
|
+
else setError('')
|
|
1418
1536
|
} catch (err) {
|
|
1419
1537
|
setError(`${t('uploadFailed')} ${err?.message ?? ''}`)
|
|
1420
1538
|
}
|
|
@@ -1435,6 +1553,8 @@ window.__ModuleLoader__.load({
|
|
|
1435
1553
|
async function generate() {
|
|
1436
1554
|
const text = prompt.trim()
|
|
1437
1555
|
if (!text || busy) return
|
|
1556
|
+
const controller = new AbortController()
|
|
1557
|
+
abortRef.current = controller
|
|
1438
1558
|
setBusy(true)
|
|
1439
1559
|
setError('')
|
|
1440
1560
|
try {
|
|
@@ -1443,7 +1563,8 @@ window.__ModuleLoader__.load({
|
|
|
1443
1563
|
aspect: activeAspect,
|
|
1444
1564
|
prompt: text,
|
|
1445
1565
|
...store.refs.length > 0 ? { refs: store.refs } : {},
|
|
1446
|
-
})
|
|
1566
|
+
}, controller.signal)
|
|
1567
|
+
if (controller.signal.aborted) return
|
|
1447
1568
|
updateStore((prev) => ({
|
|
1448
1569
|
...prev,
|
|
1449
1570
|
prompt: text,
|
|
@@ -1457,12 +1578,18 @@ window.__ModuleLoader__.load({
|
|
|
1457
1578
|
}, ...prev.recent].slice(0, 12),
|
|
1458
1579
|
}))
|
|
1459
1580
|
} catch (err) {
|
|
1460
|
-
setError(
|
|
1581
|
+
if (controller.signal.aborted || err?.name === 'AbortError') setError(t('cancelled'))
|
|
1582
|
+
else setError(`${t('errorPrefix')}: ${err?.message ?? err}`)
|
|
1461
1583
|
} finally {
|
|
1584
|
+
if (abortRef.current === controller) abortRef.current = null
|
|
1462
1585
|
setBusy(false)
|
|
1463
1586
|
}
|
|
1464
1587
|
}
|
|
1465
1588
|
|
|
1589
|
+
function cancelGenerate() {
|
|
1590
|
+
abortRef.current?.abort()
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1466
1593
|
const canGenerate = hasActive && !!cwd && prompt.trim().length > 0 && !busy
|
|
1467
1594
|
const nothingToClear = store.refs.length === 0 && prompt.trim().length === 0 && store.recent.length === 0
|
|
1468
1595
|
// Start over: references, prompt, results — the model and aspect stay.
|
|
@@ -1472,11 +1599,34 @@ window.__ModuleLoader__.load({
|
|
|
1472
1599
|
setError('')
|
|
1473
1600
|
}
|
|
1474
1601
|
|
|
1475
|
-
|
|
1602
|
+
// A dropped file must never reach the browser's default handler: that
|
|
1603
|
+
// navigates the whole GUI to file:// and takes the live session with it.
|
|
1604
|
+
// Root-level, so every child (refs box, prompt, results) is covered.
|
|
1605
|
+
const dragHandlers = {
|
|
1606
|
+
onDragOver: (event) => {
|
|
1607
|
+
if (!carriesFiles(event)) return
|
|
1608
|
+
event.preventDefault()
|
|
1609
|
+
try { event.dataTransfer.dropEffect = 'copy' } catch {}
|
|
1610
|
+
if (!dragging) setDragging(true)
|
|
1611
|
+
},
|
|
1612
|
+
onDragLeave: (event) => {
|
|
1613
|
+
const next = event.relatedTarget
|
|
1614
|
+
if (typeof next === 'object' && next !== null && event.currentTarget.contains(next)) return
|
|
1615
|
+
setDragging(false)
|
|
1616
|
+
},
|
|
1617
|
+
onDrop: (event) => {
|
|
1618
|
+
setDragging(false)
|
|
1619
|
+
if (!carriesFiles(event)) return
|
|
1620
|
+
event.preventDefault()
|
|
1621
|
+
void addFiles(event.dataTransfer.files)
|
|
1622
|
+
},
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
return React.createElement('div', { style: css.panel, ...dragHandlers, onPaste: (event) => {
|
|
1476
1626
|
const files = Array.from(event.clipboardData?.items ?? [])
|
|
1477
1627
|
.map((item) => item.getAsFile())
|
|
1478
1628
|
.filter((f) => f !== null)
|
|
1479
|
-
if (files.length > 0) { event.preventDefault(); addFiles(files) }
|
|
1629
|
+
if (files.length > 0) { event.preventDefault(); void addFiles(files) }
|
|
1480
1630
|
} },
|
|
1481
1631
|
// Clear — top-right, red, disabled while a generation runs or when idle.
|
|
1482
1632
|
React.createElement('div', { style: css.topbar },
|
|
@@ -1528,7 +1678,7 @@ window.__ModuleLoader__.load({
|
|
|
1528
1678
|
role: 'group',
|
|
1529
1679
|
'aria-label': t('refs'),
|
|
1530
1680
|
'aria-describedby': 'dsh-igl-refs-hint',
|
|
1531
|
-
style: { ...css.drop, ...(refsFocus ? css.dropActive : null) },
|
|
1681
|
+
style: { ...css.drop, ...((refsFocus || dragging) ? css.dropActive : null) },
|
|
1532
1682
|
onFocus: () => setRefsFocus(true),
|
|
1533
1683
|
onBlur: () => setRefsFocus(false),
|
|
1534
1684
|
onClick: () => setRefsFocus(true),
|
|
@@ -1536,7 +1686,9 @@ window.__ModuleLoader__.load({
|
|
|
1536
1686
|
const files = Array.from(event.clipboardData?.items ?? [])
|
|
1537
1687
|
.map((item) => item.getAsFile())
|
|
1538
1688
|
.filter((f) => f !== null)
|
|
1539
|
-
|
|
1689
|
+
// The panel root listens for the same paste; without this the box
|
|
1690
|
+
// uploads every image twice (two attachments, two ref slots).
|
|
1691
|
+
if (files.length > 0) { event.preventDefault(); event.stopPropagation(); void addFiles(files) }
|
|
1540
1692
|
},
|
|
1541
1693
|
},
|
|
1542
1694
|
store.refs.length === 0
|
|
@@ -1552,7 +1704,7 @@ window.__ModuleLoader__.load({
|
|
|
1552
1704
|
},
|
|
1553
1705
|
'aria-label': t('removeRef'),
|
|
1554
1706
|
onClick: () => removeRef(ref),
|
|
1555
|
-
},
|
|
1707
|
+
}, React.createElement(IconTrash, { size: 12 })),
|
|
1556
1708
|
))),
|
|
1557
1709
|
),
|
|
1558
1710
|
React.createElement('div', { style: css.row },
|
|
@@ -1577,9 +1729,14 @@ window.__ModuleLoader__.load({
|
|
|
1577
1729
|
}),
|
|
1578
1730
|
error ? React.createElement('p', { style: css.error, role: 'alert' }, error) : null,
|
|
1579
1731
|
!cwd ? React.createElement('p', { style: css.hint }, t('noCwd')) : null,
|
|
1580
|
-
React.createElement('
|
|
1581
|
-
|
|
1582
|
-
|
|
1732
|
+
React.createElement('div', { style: { ...css.row, gap: 8 } },
|
|
1733
|
+
React.createElement('button', {
|
|
1734
|
+
type: 'button', className: 'dsh-igl-primary', disabled: !canGenerate, onClick: generate,
|
|
1735
|
+
}, busy ? t('generating') : t('generate')),
|
|
1736
|
+
busy ? React.createElement('button', {
|
|
1737
|
+
type: 'button', className: 'dsh-igl-btn', onClick: cancelGenerate,
|
|
1738
|
+
}, t('cancel')) : null,
|
|
1739
|
+
),
|
|
1583
1740
|
),
|
|
1584
1741
|
// Results
|
|
1585
1742
|
React.createElement('div', { style: css.section },
|
|
@@ -1607,7 +1764,7 @@ window.__ModuleLoader__.load({
|
|
|
1607
1764
|
function StudioTitle(props) {
|
|
1608
1765
|
const t = props.t ?? translateFactory(en)
|
|
1609
1766
|
return React.createElement(React.Fragment, null,
|
|
1610
|
-
|
|
1767
|
+
React.createElement(IconSparkle, { size: 16 }),
|
|
1611
1768
|
React.createElement('span', { style: { fontSize: 13, lineHeight: '20px' } }, t('title')),
|
|
1612
1769
|
)
|
|
1613
1770
|
}
|
|
@@ -1620,7 +1777,7 @@ window.__ModuleLoader__.load({
|
|
|
1620
1777
|
title: t('cornerTooltip'),
|
|
1621
1778
|
'aria-label': t('cornerTooltip'),
|
|
1622
1779
|
onClick: props.openStudio,
|
|
1623
|
-
},
|
|
1780
|
+
}, React.createElement(IconSparkle, { size: 16 }))
|
|
1624
1781
|
}
|
|
1625
1782
|
|
|
1626
1783
|
// ---------------------------------------------------------------- configForms
|
|
@@ -1709,6 +1866,7 @@ window.__ModuleLoader__.load({
|
|
|
1709
1866
|
order: 30,
|
|
1710
1867
|
title: () => t('guideTitle'),
|
|
1711
1868
|
description: () => t('guideDescription'),
|
|
1869
|
+
icon: StudioArtwork,
|
|
1712
1870
|
}],
|
|
1713
1871
|
keepMounted: true,
|
|
1714
1872
|
}))
|
|
@@ -1746,8 +1904,20 @@ window.__ModuleLoader__.load({
|
|
|
1746
1904
|
}),
|
|
1747
1905
|
}, CornerButton)))
|
|
1748
1906
|
}
|
|
1749
|
-
|
|
1750
|
-
|
|
1907
|
+
// Re-mount only when the gate actually flips. `lite.subscribe` fires on
|
|
1908
|
+
// every config write — including the panel's own model and aspect
|
|
1909
|
+
// pickers (1382/1394) — and releasing the pane registration on those
|
|
1910
|
+
// unmounts StudioBody, throwing away a half-typed prompt and resetting
|
|
1911
|
+
// `busy`, which lets a second generate fire while the first still runs.
|
|
1912
|
+
let mountedEnabled = sidebarStudioEnabled(lite)
|
|
1913
|
+
const sync = () => {
|
|
1914
|
+
const enabled = sidebarStudioEnabled(lite)
|
|
1915
|
+
if (enabled === mountedEnabled) return
|
|
1916
|
+
mountedEnabled = enabled
|
|
1917
|
+
release()
|
|
1918
|
+
mount()
|
|
1919
|
+
}
|
|
1920
|
+
if (mountedEnabled) mount()
|
|
1751
1921
|
const stop = typeof lite.subscribe === 'function' ? lite.subscribe(sync) : undefined
|
|
1752
1922
|
return () => { try { stop?.() } catch {} release() }
|
|
1753
1923
|
}, 'dsh-image-lite: sidebar studio'))
|
package/index.js
CHANGED
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
* write takes effect on the next tool call without a restart.
|
|
14
14
|
*
|
|
15
15
|
* P1 scope: the `openai-images` API format only (gpt-image-1 and
|
|
16
|
-
* compatible gateways). The 出图 fetch layer, the
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* compatible gateways). The 出图 fetch layer, the tool, and the
|
|
17
|
+
* system-prompt section are written against the DSH services (attachments /
|
|
18
|
+
* credentials / tools / system-prompt); the panel's RPC channel rides on
|
|
19
|
+
* Connection's generic channel registry rather than a private route, so the
|
|
20
|
+
* transport stays owned by the platform. This plugin is self-contained — no
|
|
21
|
+
* other image plugin is required.
|
|
20
22
|
*/
|
|
21
23
|
import z from '@deepseek-ai/schemastery'
|
|
22
24
|
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
|
@@ -59,7 +61,7 @@ export const ENTRY_NS = 'image-gen-lite'
|
|
|
59
61
|
/** Loopback RPC channel for the client half. */
|
|
60
62
|
export const RPC_CHANNEL = '/image-gen-lite'
|
|
61
63
|
|
|
62
|
-
const USER_AGENT = 'dsh-image-lite/0.
|
|
64
|
+
const USER_AGENT = 'dsh-image-lite/0.2.0'
|
|
63
65
|
const SUPPORTED_FORMAT = 'openai-images'
|
|
64
66
|
|
|
65
67
|
/**
|
|
@@ -640,72 +642,35 @@ function failure(error) {
|
|
|
640
642
|
}
|
|
641
643
|
|
|
642
644
|
/**
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
645
|
+
* Mount the panel's RPC channel on Connection's generic channel registry.
|
|
646
|
+
*
|
|
647
|
+
* The registry owns the transport end to end: envelope framing, the
|
|
648
|
+
* content-type check, the Host/Origin fence, 401/403 admission, request
|
|
649
|
+
* cancellation and the buffered-body cap. Its handler receives the bridge's
|
|
650
|
+
* abort signal as the third argument, so a client disconnect now actually
|
|
651
|
+
* cancels in-flight work instead of being dropped on the floor.
|
|
652
|
+
*
|
|
653
|
+
* Enter through `connection.register(owner, …)`, never its `rpc.handle` sugar:
|
|
654
|
+
* that getter takes the owner from Connection's own context, where
|
|
655
|
+
* `owner.webServer` throws "cannot get property webServer without inject" and
|
|
656
|
+
* the route silently never mounts (reproduced against cordis 4.1.0 — plain
|
|
657
|
+
* `rpc.handle`, `ctx.connection.rpc.handle` and destructured `rpc.handle` all
|
|
658
|
+
* fail the same way). Passing this inject scope explicitly is what makes
|
|
659
|
+
* `owner.webServer` resolvable, so `webServer` also has to stay in the inject
|
|
660
|
+
* list.
|
|
661
|
+
*
|
|
662
|
+
* The previous implementation mounted a prefix route of its own and
|
|
663
|
+
* re-implemented the envelope; that copy drifted from the platform (no
|
|
664
|
+
* cancellation, no body cap) and has been removed.
|
|
647
665
|
*/
|
|
648
|
-
async function serveRpc(req, res, admit, handle) {
|
|
649
|
-
let rejection
|
|
650
|
-
try {
|
|
651
|
-
rejection = admit(req)
|
|
652
|
-
} catch {
|
|
653
|
-
rejection = 500
|
|
654
|
-
}
|
|
655
|
-
if (rejection !== undefined) {
|
|
656
|
-
res.writeHead(rejection)
|
|
657
|
-
res.end(rejection === 401 ? 'unauthorized' : 'forbidden')
|
|
658
|
-
return
|
|
659
|
-
}
|
|
660
|
-
const url = new URL(req.url ?? '/', 'http://x')
|
|
661
|
-
const endpoint = url.pathname.startsWith(`${RPC_CHANNEL}/`) ? url.pathname.slice(RPC_CHANNEL.length + 1) : ''
|
|
662
|
-
if (req.method !== 'POST' || endpoint === '') {
|
|
663
|
-
res.writeHead(req.method === 'POST' ? 404 : 405)
|
|
664
|
-
res.end()
|
|
665
|
-
return
|
|
666
|
-
}
|
|
667
|
-
if ((req.headers['content-type'] ?? '').split(';')[0].trim().toLowerCase() !== 'application/json') {
|
|
668
|
-
res.writeHead(415)
|
|
669
|
-
res.end('content type must be application/json')
|
|
670
|
-
return
|
|
671
|
-
}
|
|
672
|
-
let raw = ''
|
|
673
|
-
for await (const chunk of req) raw += chunk
|
|
674
|
-
let message
|
|
675
|
-
try {
|
|
676
|
-
message = JSON.parse(raw)
|
|
677
|
-
} catch {
|
|
678
|
-
res.writeHead(400)
|
|
679
|
-
res.end('body is not JSON')
|
|
680
|
-
return
|
|
681
|
-
}
|
|
682
|
-
const rpcId = typeof message?.rpcId === 'string' ? message.rpcId : 'invalid-request'
|
|
683
|
-
const reply = (result) => {
|
|
684
|
-
res.writeHead(200, { 'content-type': 'application/json' })
|
|
685
|
-
res.end(JSON.stringify({ type: 'server-response', rpcId, result }))
|
|
686
|
-
}
|
|
687
|
-
if (message?.type !== 'client-request' || message.method !== endpoint) {
|
|
688
|
-
reply({ ok: false, error: { code: 'gateway/bad-request', message: 'method does not match endpoint', details: {} } })
|
|
689
|
-
return
|
|
690
|
-
}
|
|
691
|
-
try {
|
|
692
|
-
reply(await handle(endpoint, message.payload))
|
|
693
|
-
} catch (error) {
|
|
694
|
-
reply({ ok: false, error: { code: 'gateway/internal', message: error instanceof Error ? error.message : String(error), details: {} } })
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
|
|
698
666
|
function registerRpc(ctx, readActive, readAspect, readOutputDir) {
|
|
699
667
|
ctx.inject(['connection', 'webServer'], (scoped) => {
|
|
700
668
|
const connection = scoped.get('connection')
|
|
701
|
-
|
|
702
|
-
if (connection
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
path: RPC_CHANNEL,
|
|
707
|
-
handler: (req, res) => serveRpc(req, res, admit, handleRpc),
|
|
708
|
-
}), 'dsh-image-lite: rpc route')
|
|
669
|
+
if (connection === undefined) return
|
|
670
|
+
if (typeof connection.register !== 'function') {
|
|
671
|
+
scoped.logger?.warn?.('dsh-image-lite: this host has no connection.register; the 生图工作台 panel has no RPC channel')
|
|
672
|
+
return
|
|
673
|
+
}
|
|
709
674
|
async function handleRpc(endpoint, payload, signal) {
|
|
710
675
|
try {
|
|
711
676
|
if (typeof payload !== 'object' || payload === null) throw new BadRequest('payload must be an object')
|
|
@@ -804,6 +769,7 @@ function registerRpc(ctx, readActive, readAspect, readOutputDir) {
|
|
|
804
769
|
return failure(error)
|
|
805
770
|
}
|
|
806
771
|
}
|
|
772
|
+
connection.register(scoped, RPC_CHANNEL, handleRpc)
|
|
807
773
|
})
|
|
808
774
|
}
|
|
809
775
|
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Image studio lite",
|
|
4
|
+
"description": "Generate images from the conversation with the image_generate_lite tool, or work in the 生图工作台 sidebar tab. The model library, default model and default image spec live in this plugin's own settings card."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-image-lite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "DSH 生图插件支持双模式生图:直接对话大模型,通过 image_generate_lite 工具生图;或在侧边栏「生图工作台」处理生图任务。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "index.js",
|
|
16
|
+
"icon": "./assets/icon.svg",
|
|
16
17
|
"scripts": {
|
|
17
18
|
"test": "node --test test/*.test.js"
|
|
18
19
|
},
|
|
@@ -20,6 +21,8 @@
|
|
|
20
21
|
".": "./index.js",
|
|
21
22
|
"./client": "./client.js",
|
|
22
23
|
"./wire": "./wire.js",
|
|
24
|
+
"./icon": "./assets/icon.svg",
|
|
25
|
+
"./locale/*.json": "./locale/*.json",
|
|
23
26
|
"./package.json": "./package.json"
|
|
24
27
|
},
|
|
25
28
|
"files": [
|
|
@@ -30,6 +33,8 @@
|
|
|
30
33
|
"README.md",
|
|
31
34
|
"docs/how-it-works.svg",
|
|
32
35
|
"docs/how-it-works.en.svg",
|
|
36
|
+
"assets/icon.svg",
|
|
37
|
+
"locale/*.json",
|
|
33
38
|
"LICENSE"
|
|
34
39
|
],
|
|
35
40
|
"repository": {
|
|
@@ -53,7 +58,6 @@
|
|
|
53
58
|
"platform": "web",
|
|
54
59
|
"inject": [
|
|
55
60
|
"@deepseek-ai/dsh-client-ui-renderer",
|
|
56
|
-
"@deepseek-ai/dsh-client-ui-primitives",
|
|
57
61
|
"@deepseek-ai/dsh-client-locale"
|
|
58
62
|
]
|
|
59
63
|
}
|