@lyra_wang/dsh-pending-queue 0.3.0 → 0.3.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.
- package/README.md +3 -1
- package/client.js +146 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ dsh plugin --profile desktop add ./lyra_wang-dsh-pending-queue-0.1.0.tgz
|
|
|
28
28
|
## 用法
|
|
29
29
|
|
|
30
30
|
1. 在右侧栏打开「待发送」。
|
|
31
|
-
2. 在顶部输入框里记一条,`Cmd/Ctrl + Enter` 或点「存下」。输入框里可以直接**粘贴或拖入图片**(png / jpeg / webp / gif
|
|
31
|
+
2. 在顶部输入框里记一条,`Cmd/Ctrl + Enter` 或点「存下」。输入框里可以直接**粘贴或拖入图片**(png / jpeg / webp / gif),也可以点「+ 图片」选文件。没点「存下」的文字、引用和图片会按会话暂存在浏览器里,切走或重启 App 后回来还在。
|
|
32
32
|
3. 想带上引用:在聊天里选中一段文字,回到面板点「引用选中」,它会挂在这条下面;推送时还原成真正的引用块(和输入框的引用同源)。
|
|
33
33
|
4. 每一条可以:
|
|
34
34
|
- **发送**:内容进输入框并立刻提交(agent 正在跑时会排进队列,不会打断当前任务)
|
|
@@ -63,6 +63,8 @@ node --test test/routes.test.mjs
|
|
|
63
63
|
## 版本
|
|
64
64
|
|
|
65
65
|
- 0.1.0 — 首个版本:新增、编辑、删除、排序、发送、填入、已发送留痕。
|
|
66
|
+
- 0.3.2 — 编辑态也能加图:点「编辑」后,在编辑框里粘贴/拖入图片同样生效,编辑项里也有「+ 图片」。
|
|
67
|
+
- 0.3.1 — 粘贴更稳:剪贴板只给 `items` 不给 `files` 的截图也能接住;补「+ 图片」选文件入口;未存下的草稿按会话暂存到 localStorage。
|
|
66
68
|
- 0.3.0 — 图片:面板可粘贴/拖入图片,存本机、条目带缩略图,推送时按“路径 + read_image 提示”进对话;删除行时清理不再被引用的图片文件。
|
|
67
69
|
- 0.2.0 — 引用:一条记录改成分段结构(文字 / 引用),面板可「引用选中」聊天里的文字,推送时还原成真引用块。
|
|
68
70
|
- 0.1.1 — 补上 `icon.svg`。0.1.0 的 `package.json` 声明了 `icon` 与 `./icon` 导出,但文件没进包,插件管理器读元信息时 `lstat` 失败,列表里会显示「包元信息错误」。
|
package/client.js
CHANGED
|
@@ -36,6 +36,8 @@ window.__ModuleLoader__.load({
|
|
|
36
36
|
const UPLOAD_URL = '/plugins/pending-queue/upload'
|
|
37
37
|
const ASSET_URL = '/plugins/pending-queue/asset'
|
|
38
38
|
const ROOT = 'dsh-pending-queue'
|
|
39
|
+
/** Per-session scratch key: unsaved typing survives a tab switch or restart. */
|
|
40
|
+
const DRAFT_KEY = 'dsh.pending-queue.draft.v1.'
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
43
|
* The last non-empty chat selection, captured from the moment the plugin
|
|
@@ -343,6 +345,41 @@ window.__ModuleLoader__.load({
|
|
|
343
345
|
const [busy, setBusy] = useState('')
|
|
344
346
|
const [notice, setNotice] = useState('')
|
|
345
347
|
const live = useRef(true)
|
|
348
|
+
const fileInput = useRef(null)
|
|
349
|
+
/** 'compose' or 'edit': which list the file picker feeds. */
|
|
350
|
+
const pickerTarget = useRef('compose')
|
|
351
|
+
|
|
352
|
+
/** Restore the unsaved draft once per session. */
|
|
353
|
+
useEffect(() => {
|
|
354
|
+
if (!sessionId) return
|
|
355
|
+
try {
|
|
356
|
+
const raw = window.localStorage.getItem(DRAFT_KEY + sessionId)
|
|
357
|
+
if (raw === null) return
|
|
358
|
+
const parsed = JSON.parse(raw)
|
|
359
|
+
if (typeof parsed.draft === 'string') setDraft(parsed.draft)
|
|
360
|
+
if (Array.isArray(parsed.quotes)) setQuotes(parsed.quotes.filter((entry) => typeof entry === 'string'))
|
|
361
|
+
if (Array.isArray(parsed.images)) setImages(parsed.images.filter((entry) => entry && typeof entry.path === 'string'))
|
|
362
|
+
} catch {
|
|
363
|
+
/* a broken scratch value is not worth an error banner */
|
|
364
|
+
}
|
|
365
|
+
}, [sessionId])
|
|
366
|
+
|
|
367
|
+
/** Write the unsaved draft; called by the edits that change it. */
|
|
368
|
+
const persist = useCallback((next) => {
|
|
369
|
+
if (!sessionId) return
|
|
370
|
+
try {
|
|
371
|
+
const text = typeof next.draft === 'string' ? next.draft : ''
|
|
372
|
+
const quotesNext = Array.isArray(next.quotes) ? next.quotes : []
|
|
373
|
+
const imagesNext = Array.isArray(next.images) ? next.images : []
|
|
374
|
+
if (text.trim() === '' && quotesNext.length === 0 && imagesNext.length === 0) {
|
|
375
|
+
window.localStorage.removeItem(DRAFT_KEY + sessionId)
|
|
376
|
+
} else {
|
|
377
|
+
window.localStorage.setItem(DRAFT_KEY + sessionId, JSON.stringify({ draft: text, quotes: quotesNext, images: imagesNext }))
|
|
378
|
+
}
|
|
379
|
+
} catch {
|
|
380
|
+
/* storage full or unavailable: the draft simply is not remembered */
|
|
381
|
+
}
|
|
382
|
+
}, [sessionId])
|
|
346
383
|
|
|
347
384
|
useEffect(() => {
|
|
348
385
|
live.current = true
|
|
@@ -405,11 +442,12 @@ window.__ModuleLoader__.load({
|
|
|
405
442
|
}, 2200)
|
|
406
443
|
}, [])
|
|
407
444
|
|
|
408
|
-
|
|
409
|
-
|
|
445
|
+
/** Upload one image and return the stored file, without touching any list. */
|
|
446
|
+
const uploadFile = useCallback(async (file) => {
|
|
447
|
+
if (!sessionId) return undefined
|
|
410
448
|
if (!file || !String(file.type || '').startsWith('image/')) {
|
|
411
449
|
setError(t('error.image'))
|
|
412
|
-
return
|
|
450
|
+
return undefined
|
|
413
451
|
}
|
|
414
452
|
setBusy('upload')
|
|
415
453
|
try {
|
|
@@ -421,17 +459,25 @@ window.__ModuleLoader__.load({
|
|
|
421
459
|
})
|
|
422
460
|
const payload = await readJson(response)
|
|
423
461
|
if (!response.ok || payload.ok !== true) throw new Error(payload.message || ('HTTP ' + response.status))
|
|
424
|
-
if (live.current)
|
|
425
|
-
|
|
426
|
-
setError('')
|
|
427
|
-
}
|
|
462
|
+
if (live.current) setError('')
|
|
463
|
+
return payload.file
|
|
428
464
|
} catch (failure) {
|
|
429
465
|
if (live.current) setError(messageOf(failure))
|
|
466
|
+
return undefined
|
|
430
467
|
} finally {
|
|
431
468
|
if (live.current) setBusy('')
|
|
432
469
|
}
|
|
433
470
|
}, [sessionId, t])
|
|
434
471
|
|
|
472
|
+
/** Compose-area upload: adds the image to the pending list. */
|
|
473
|
+
const uploadImage = useCallback(async (file) => {
|
|
474
|
+
const stored = await uploadFile(file)
|
|
475
|
+
if (!stored || !live.current) return
|
|
476
|
+
const nextImages = [...images, stored]
|
|
477
|
+
setImages(nextImages)
|
|
478
|
+
persist({ draft, quotes, images: nextImages })
|
|
479
|
+
}, [uploadFile, images, draft, quotes, persist])
|
|
480
|
+
|
|
435
481
|
const saveDraft = useCallback(async () => {
|
|
436
482
|
const text = draft.trim()
|
|
437
483
|
const segments = []
|
|
@@ -450,9 +496,10 @@ window.__ModuleLoader__.load({
|
|
|
450
496
|
setDraft('')
|
|
451
497
|
setQuotes([])
|
|
452
498
|
setImages([])
|
|
499
|
+
persist({ draft: '', quotes: [], images: [] })
|
|
453
500
|
}
|
|
454
501
|
}
|
|
455
|
-
}, [draft, quotes, images, act, t])
|
|
502
|
+
}, [draft, quotes, images, act, t, persist])
|
|
456
503
|
|
|
457
504
|
const addQuote = useCallback(() => {
|
|
458
505
|
let live = ''
|
|
@@ -466,9 +513,11 @@ window.__ModuleLoader__.load({
|
|
|
466
513
|
setError(t('quote.empty'))
|
|
467
514
|
return
|
|
468
515
|
}
|
|
469
|
-
|
|
516
|
+
const nextQuotes = [...quotes, text]
|
|
517
|
+
setQuotes(nextQuotes)
|
|
518
|
+
persist({ draft, quotes: nextQuotes, images })
|
|
470
519
|
setError('')
|
|
471
|
-
}, [t])
|
|
520
|
+
}, [t, persist, draft, quotes, images])
|
|
472
521
|
|
|
473
522
|
/**
|
|
474
523
|
* Replay one row through the composer: leading text replaces the draft,
|
|
@@ -571,15 +620,59 @@ window.__ModuleLoader__.load({
|
|
|
571
620
|
}
|
|
572
621
|
}, [saveDraft])
|
|
573
622
|
|
|
623
|
+
/** Pull the first image out of a clipboard or drop payload, either shape. */
|
|
624
|
+
const imageFrom = useCallback((payload) => {
|
|
625
|
+
if (!payload) return undefined
|
|
626
|
+
const files = payload.files ? Array.from(payload.files) : []
|
|
627
|
+
const direct = files.find((file) => String(file.type || '').startsWith('image/'))
|
|
628
|
+
if (direct !== undefined) return direct
|
|
629
|
+
if (!payload.items) return undefined
|
|
630
|
+
for (const item of Array.from(payload.items)) {
|
|
631
|
+
if (item.kind === 'file' && String(item.type || '').startsWith('image/')) {
|
|
632
|
+
const file = item.getAsFile()
|
|
633
|
+
if (file) return file
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return undefined
|
|
637
|
+
}, [])
|
|
638
|
+
|
|
639
|
+
/** Edit-mode upload: the image joins the row being edited, not the compose area. */
|
|
640
|
+
const appendEditingImage = useCallback(async (file) => {
|
|
641
|
+
const stored = await uploadFile(file)
|
|
642
|
+
if (!stored || !live.current) return
|
|
643
|
+
setEditing((current) => current === null ? current : ({
|
|
644
|
+
id: current.id,
|
|
645
|
+
segments: [...current.segments, { type: 'file', path: stored.path, name: stored.name }],
|
|
646
|
+
}))
|
|
647
|
+
}, [uploadFile])
|
|
648
|
+
|
|
649
|
+
const openPicker = useCallback((target) => {
|
|
650
|
+
pickerTarget.current = target
|
|
651
|
+
if (fileInput.current) fileInput.current.click()
|
|
652
|
+
}, [])
|
|
653
|
+
|
|
574
654
|
const onPaste = useCallback((event) => {
|
|
575
|
-
const
|
|
576
|
-
? Array.from(event.clipboardData.files)
|
|
577
|
-
: []
|
|
578
|
-
const image = files.find((file) => String(file.type || '').startsWith('image/'))
|
|
655
|
+
const image = imageFrom(event.clipboardData)
|
|
579
656
|
if (image === undefined) return
|
|
580
657
|
event.preventDefault()
|
|
658
|
+
event.stopPropagation()
|
|
581
659
|
void uploadImage(image)
|
|
582
|
-
}, [uploadImage])
|
|
660
|
+
}, [imageFrom, uploadImage])
|
|
661
|
+
|
|
662
|
+
const onEditPaste = useCallback((event) => {
|
|
663
|
+
const image = imageFrom(event.clipboardData)
|
|
664
|
+
if (image === undefined) return
|
|
665
|
+
event.preventDefault()
|
|
666
|
+
event.stopPropagation()
|
|
667
|
+
void appendEditingImage(image)
|
|
668
|
+
}, [imageFrom, appendEditingImage])
|
|
669
|
+
|
|
670
|
+
const onEditDrop = useCallback((event) => {
|
|
671
|
+
const image = imageFrom(event.dataTransfer)
|
|
672
|
+
if (image === undefined) return
|
|
673
|
+
event.preventDefault()
|
|
674
|
+
void appendEditingImage(image)
|
|
675
|
+
}, [imageFrom, appendEditingImage])
|
|
583
676
|
|
|
584
677
|
const onDrop = useCallback((event) => {
|
|
585
678
|
const files = event.dataTransfer && event.dataTransfer.files
|
|
@@ -650,7 +743,7 @@ window.__ModuleLoader__.load({
|
|
|
650
743
|
}
|
|
651
744
|
|
|
652
745
|
const body = isEditing
|
|
653
|
-
? h('div', { key: 'editing' }, [
|
|
746
|
+
? h('div', { key: 'editing', onDrop: onEditDrop }, [
|
|
654
747
|
...editing.segments.map((segment, segmentIndex) => {
|
|
655
748
|
if (segment.type === 'quote' || segment.type === 'file') {
|
|
656
749
|
return h('div', { key: 'es' + segmentIndex, className: ROOT + '-chip' }, [
|
|
@@ -679,6 +772,7 @@ window.__ModuleLoader__.load({
|
|
|
679
772
|
className: ROOT + '-edit',
|
|
680
773
|
value: segment.text,
|
|
681
774
|
rows: 2,
|
|
775
|
+
onPaste: onEditPaste,
|
|
682
776
|
onChange: (event) => {
|
|
683
777
|
const value = event.target.value
|
|
684
778
|
setEditing((current) => current === null ? current : ({
|
|
@@ -699,6 +793,10 @@ window.__ModuleLoader__.load({
|
|
|
699
793
|
})
|
|
700
794
|
}),
|
|
701
795
|
h('div', { key: 'acts', className: ROOT + '-acts' }, [
|
|
796
|
+
h('button', {
|
|
797
|
+
key: 'image', type: 'button', className: ROOT + '-act',
|
|
798
|
+
onClick: () => openPicker('edit'),
|
|
799
|
+
}, t('action.image')),
|
|
702
800
|
h('button', {
|
|
703
801
|
key: 'save', type: 'button', className: ROOT + '-act', 'data-tone': 'send', disabled: isBusy,
|
|
704
802
|
onClick: () => { void saveEdit() },
|
|
@@ -739,6 +837,7 @@ window.__ModuleLoader__.load({
|
|
|
739
837
|
key: 'compose',
|
|
740
838
|
className: ROOT + '-compose',
|
|
741
839
|
onDrop,
|
|
840
|
+
onPaste,
|
|
742
841
|
onDragOver: (event) => {
|
|
743
842
|
if (event.dataTransfer && Array.from(event.dataTransfer.types || []).includes('Files')) event.preventDefault()
|
|
744
843
|
},
|
|
@@ -749,7 +848,11 @@ window.__ModuleLoader__.load({
|
|
|
749
848
|
value: draft,
|
|
750
849
|
placeholder: t('input.placeholder'),
|
|
751
850
|
rows: 2,
|
|
752
|
-
onChange: (event) =>
|
|
851
|
+
onChange: (event) => {
|
|
852
|
+
const value = event.target.value
|
|
853
|
+
setDraft(value)
|
|
854
|
+
persist({ draft: value, quotes, images })
|
|
855
|
+
},
|
|
753
856
|
onKeyDown: onComposeKey,
|
|
754
857
|
onPaste,
|
|
755
858
|
}),
|
|
@@ -761,7 +864,11 @@ window.__ModuleLoader__.load({
|
|
|
761
864
|
h('span', { key: 'txt', className: ROOT + '-chipText' }, text),
|
|
762
865
|
h('button', {
|
|
763
866
|
key: 'x', type: 'button', className: ROOT + '-x', 'aria-label': t('action.removeAttachment'),
|
|
764
|
-
onClick: () =>
|
|
867
|
+
onClick: () => {
|
|
868
|
+
const nextQuotes = quotes.filter((_, i) => i !== index)
|
|
869
|
+
setQuotes(nextQuotes)
|
|
870
|
+
persist({ draft, quotes: nextQuotes, images })
|
|
871
|
+
},
|
|
765
872
|
}, '×'),
|
|
766
873
|
])))
|
|
767
874
|
: null,
|
|
@@ -774,7 +881,11 @@ window.__ModuleLoader__.load({
|
|
|
774
881
|
h('img', { key: 'img', src: assetUrl(sessionId, image.path), alt: image.name || '' }),
|
|
775
882
|
h('button', {
|
|
776
883
|
key: 'x', type: 'button', className: ROOT + '-thumbX', 'aria-label': t('action.removeAttachment'),
|
|
777
|
-
onClick: () =>
|
|
884
|
+
onClick: () => {
|
|
885
|
+
const nextImages = images.filter((_, i) => i !== index)
|
|
886
|
+
setImages(nextImages)
|
|
887
|
+
persist({ draft, quotes, images: nextImages })
|
|
888
|
+
},
|
|
778
889
|
}, '×'),
|
|
779
890
|
])))
|
|
780
891
|
: null,
|
|
@@ -782,6 +893,21 @@ window.__ModuleLoader__.load({
|
|
|
782
893
|
h('span', { key: 'hint', className: ROOT + '-hint' }, images.length > 0
|
|
783
894
|
? t('image.hint')
|
|
784
895
|
: quotes.length > 0 ? t('quote.hint') : t('input.hint')),
|
|
896
|
+
h('input', {
|
|
897
|
+
key: 'file',
|
|
898
|
+
ref: fileInput,
|
|
899
|
+
type: 'file',
|
|
900
|
+
accept: 'image/*',
|
|
901
|
+
style: { display: 'none' },
|
|
902
|
+
onChange: (event) => {
|
|
903
|
+
const picked = event.target.files && event.target.files[0]
|
|
904
|
+
event.target.value = ''
|
|
905
|
+
if (!picked) return
|
|
906
|
+
if (pickerTarget.current === 'edit' && editing !== null) void appendEditingImage(picked)
|
|
907
|
+
else void uploadImage(picked)
|
|
908
|
+
},
|
|
909
|
+
}),
|
|
910
|
+
h('button', { key: 'image', type: 'button', className: ROOT + '-ghost', onClick: () => { if (fileInput.current) fileInput.current.click() } }, t('action.image')),
|
|
785
911
|
h('button', { key: 'quote', type: 'button', className: ROOT + '-ghost', onClick: addQuote }, t('action.quote')),
|
|
786
912
|
h('button', {
|
|
787
913
|
key: 'save', type: 'button', className: ROOT + '-primary',
|
|
@@ -879,4 +1005,4 @@ window.__ModuleLoader__.load({
|
|
|
879
1005
|
},
|
|
880
1006
|
}
|
|
881
1007
|
},
|
|
882
|
-
})
|
|
1008
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lyra_wang/dsh-pending-queue",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Right-sidebar draft queue for DeepSeek Harness: jot ideas down, quote chat text, attach images, then push one into the session when the previous task is finished.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|