@lyra_wang/dsh-pending-queue 0.3.0 → 0.3.3
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 +4 -1
- package/client.js +170 -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,9 @@ node --test test/routes.test.mjs
|
|
|
63
63
|
## 版本
|
|
64
64
|
|
|
65
65
|
- 0.1.0 — 首个版本:新增、编辑、删除、排序、发送、填入、已发送留痕。
|
|
66
|
+
- 0.3.3 — 编辑态补上「引用选中」:编辑某条时也能把聊天里选中的文字加进去,和草稿区一致。
|
|
67
|
+
- 0.3.2 — 编辑态也能加图:点「编辑」后,在编辑框里粘贴/拖入图片同样生效,编辑项里也有「+ 图片」。
|
|
68
|
+
- 0.3.1 — 粘贴更稳:剪贴板只给 `items` 不给 `files` 的截图也能接住;补「+ 图片」选文件入口;未存下的草稿按会话暂存到 localStorage。
|
|
66
69
|
- 0.3.0 — 图片:面板可粘贴/拖入图片,存本机、条目带缩略图,推送时按“路径 + read_image 提示”进对话;删除行时清理不再被引用的图片文件。
|
|
67
70
|
- 0.2.0 — 引用:一条记录改成分段结构(文字 / 引用),面板可「引用选中」聊天里的文字,推送时还原成真引用块。
|
|
68
71
|
- 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,79 @@ 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
|
+
/** Edit-mode quote: the selection joins the row being edited. */
|
|
650
|
+
const addEditingQuote = useCallback(() => {
|
|
651
|
+
let live = ''
|
|
652
|
+
try {
|
|
653
|
+
live = String(window.getSelection() || '')
|
|
654
|
+
} catch {
|
|
655
|
+
live = ''
|
|
656
|
+
}
|
|
657
|
+
const text = (live.trim() !== '' ? live : lastChatSelection).trim()
|
|
658
|
+
if (text === '') {
|
|
659
|
+
setError(t('quote.empty'))
|
|
660
|
+
return
|
|
661
|
+
}
|
|
662
|
+
setEditing((current) => current === null ? current : ({
|
|
663
|
+
id: current.id,
|
|
664
|
+
segments: [...current.segments, { type: 'quote', text }],
|
|
665
|
+
}))
|
|
666
|
+
setError('')
|
|
667
|
+
}, [t])
|
|
668
|
+
|
|
669
|
+
const openPicker = useCallback((target) => {
|
|
670
|
+
pickerTarget.current = target
|
|
671
|
+
if (fileInput.current) fileInput.current.click()
|
|
672
|
+
}, [])
|
|
673
|
+
|
|
574
674
|
const onPaste = useCallback((event) => {
|
|
575
|
-
const
|
|
576
|
-
? Array.from(event.clipboardData.files)
|
|
577
|
-
: []
|
|
578
|
-
const image = files.find((file) => String(file.type || '').startsWith('image/'))
|
|
675
|
+
const image = imageFrom(event.clipboardData)
|
|
579
676
|
if (image === undefined) return
|
|
580
677
|
event.preventDefault()
|
|
678
|
+
event.stopPropagation()
|
|
581
679
|
void uploadImage(image)
|
|
582
|
-
}, [uploadImage])
|
|
680
|
+
}, [imageFrom, uploadImage])
|
|
681
|
+
|
|
682
|
+
const onEditPaste = useCallback((event) => {
|
|
683
|
+
const image = imageFrom(event.clipboardData)
|
|
684
|
+
if (image === undefined) return
|
|
685
|
+
event.preventDefault()
|
|
686
|
+
event.stopPropagation()
|
|
687
|
+
void appendEditingImage(image)
|
|
688
|
+
}, [imageFrom, appendEditingImage])
|
|
689
|
+
|
|
690
|
+
const onEditDrop = useCallback((event) => {
|
|
691
|
+
const image = imageFrom(event.dataTransfer)
|
|
692
|
+
if (image === undefined) return
|
|
693
|
+
event.preventDefault()
|
|
694
|
+
void appendEditingImage(image)
|
|
695
|
+
}, [imageFrom, appendEditingImage])
|
|
583
696
|
|
|
584
697
|
const onDrop = useCallback((event) => {
|
|
585
698
|
const files = event.dataTransfer && event.dataTransfer.files
|
|
@@ -650,7 +763,7 @@ window.__ModuleLoader__.load({
|
|
|
650
763
|
}
|
|
651
764
|
|
|
652
765
|
const body = isEditing
|
|
653
|
-
? h('div', { key: 'editing' }, [
|
|
766
|
+
? h('div', { key: 'editing', onDrop: onEditDrop }, [
|
|
654
767
|
...editing.segments.map((segment, segmentIndex) => {
|
|
655
768
|
if (segment.type === 'quote' || segment.type === 'file') {
|
|
656
769
|
return h('div', { key: 'es' + segmentIndex, className: ROOT + '-chip' }, [
|
|
@@ -679,6 +792,7 @@ window.__ModuleLoader__.load({
|
|
|
679
792
|
className: ROOT + '-edit',
|
|
680
793
|
value: segment.text,
|
|
681
794
|
rows: 2,
|
|
795
|
+
onPaste: onEditPaste,
|
|
682
796
|
onChange: (event) => {
|
|
683
797
|
const value = event.target.value
|
|
684
798
|
setEditing((current) => current === null ? current : ({
|
|
@@ -699,6 +813,14 @@ window.__ModuleLoader__.load({
|
|
|
699
813
|
})
|
|
700
814
|
}),
|
|
701
815
|
h('div', { key: 'acts', className: ROOT + '-acts' }, [
|
|
816
|
+
h('button', {
|
|
817
|
+
key: 'quote', type: 'button', className: ROOT + '-act',
|
|
818
|
+
onClick: addEditingQuote,
|
|
819
|
+
}, t('action.quote')),
|
|
820
|
+
h('button', {
|
|
821
|
+
key: 'image', type: 'button', className: ROOT + '-act',
|
|
822
|
+
onClick: () => openPicker('edit'),
|
|
823
|
+
}, t('action.image')),
|
|
702
824
|
h('button', {
|
|
703
825
|
key: 'save', type: 'button', className: ROOT + '-act', 'data-tone': 'send', disabled: isBusy,
|
|
704
826
|
onClick: () => { void saveEdit() },
|
|
@@ -739,6 +861,7 @@ window.__ModuleLoader__.load({
|
|
|
739
861
|
key: 'compose',
|
|
740
862
|
className: ROOT + '-compose',
|
|
741
863
|
onDrop,
|
|
864
|
+
onPaste,
|
|
742
865
|
onDragOver: (event) => {
|
|
743
866
|
if (event.dataTransfer && Array.from(event.dataTransfer.types || []).includes('Files')) event.preventDefault()
|
|
744
867
|
},
|
|
@@ -749,7 +872,11 @@ window.__ModuleLoader__.load({
|
|
|
749
872
|
value: draft,
|
|
750
873
|
placeholder: t('input.placeholder'),
|
|
751
874
|
rows: 2,
|
|
752
|
-
onChange: (event) =>
|
|
875
|
+
onChange: (event) => {
|
|
876
|
+
const value = event.target.value
|
|
877
|
+
setDraft(value)
|
|
878
|
+
persist({ draft: value, quotes, images })
|
|
879
|
+
},
|
|
753
880
|
onKeyDown: onComposeKey,
|
|
754
881
|
onPaste,
|
|
755
882
|
}),
|
|
@@ -761,7 +888,11 @@ window.__ModuleLoader__.load({
|
|
|
761
888
|
h('span', { key: 'txt', className: ROOT + '-chipText' }, text),
|
|
762
889
|
h('button', {
|
|
763
890
|
key: 'x', type: 'button', className: ROOT + '-x', 'aria-label': t('action.removeAttachment'),
|
|
764
|
-
onClick: () =>
|
|
891
|
+
onClick: () => {
|
|
892
|
+
const nextQuotes = quotes.filter((_, i) => i !== index)
|
|
893
|
+
setQuotes(nextQuotes)
|
|
894
|
+
persist({ draft, quotes: nextQuotes, images })
|
|
895
|
+
},
|
|
765
896
|
}, '×'),
|
|
766
897
|
])))
|
|
767
898
|
: null,
|
|
@@ -774,7 +905,11 @@ window.__ModuleLoader__.load({
|
|
|
774
905
|
h('img', { key: 'img', src: assetUrl(sessionId, image.path), alt: image.name || '' }),
|
|
775
906
|
h('button', {
|
|
776
907
|
key: 'x', type: 'button', className: ROOT + '-thumbX', 'aria-label': t('action.removeAttachment'),
|
|
777
|
-
onClick: () =>
|
|
908
|
+
onClick: () => {
|
|
909
|
+
const nextImages = images.filter((_, i) => i !== index)
|
|
910
|
+
setImages(nextImages)
|
|
911
|
+
persist({ draft, quotes, images: nextImages })
|
|
912
|
+
},
|
|
778
913
|
}, '×'),
|
|
779
914
|
])))
|
|
780
915
|
: null,
|
|
@@ -782,6 +917,21 @@ window.__ModuleLoader__.load({
|
|
|
782
917
|
h('span', { key: 'hint', className: ROOT + '-hint' }, images.length > 0
|
|
783
918
|
? t('image.hint')
|
|
784
919
|
: quotes.length > 0 ? t('quote.hint') : t('input.hint')),
|
|
920
|
+
h('input', {
|
|
921
|
+
key: 'file',
|
|
922
|
+
ref: fileInput,
|
|
923
|
+
type: 'file',
|
|
924
|
+
accept: 'image/*',
|
|
925
|
+
style: { display: 'none' },
|
|
926
|
+
onChange: (event) => {
|
|
927
|
+
const picked = event.target.files && event.target.files[0]
|
|
928
|
+
event.target.value = ''
|
|
929
|
+
if (!picked) return
|
|
930
|
+
if (pickerTarget.current === 'edit' && editing !== null) void appendEditingImage(picked)
|
|
931
|
+
else void uploadImage(picked)
|
|
932
|
+
},
|
|
933
|
+
}),
|
|
934
|
+
h('button', { key: 'image', type: 'button', className: ROOT + '-ghost', onClick: () => { if (fileInput.current) fileInput.current.click() } }, t('action.image')),
|
|
785
935
|
h('button', { key: 'quote', type: 'button', className: ROOT + '-ghost', onClick: addQuote }, t('action.quote')),
|
|
786
936
|
h('button', {
|
|
787
937
|
key: 'save', type: 'button', className: ROOT + '-primary',
|
|
@@ -879,4 +1029,4 @@ window.__ModuleLoader__.load({
|
|
|
879
1029
|
},
|
|
880
1030
|
}
|
|
881
1031
|
},
|
|
882
|
-
})
|
|
1032
|
+
})
|
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.3",
|
|
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",
|