dsh-selection-annotations 0.0.0-stage → 2.1.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/LICENSE +21 -0
  3. package/README.md +161 -3
  4. package/README.zh-CN.md +161 -0
  5. package/client.js +11136 -0
  6. package/cordis.patch.yml +3 -0
  7. package/icon.svg +7 -0
  8. package/lib/annotations-db.js +1157 -0
  9. package/lib/index.js +1304 -0
  10. package/locale/en.json +6 -0
  11. package/locale/zh.json +6 -0
  12. package/package.json +76 -6
  13. package/scripts/build.mjs +37 -0
  14. package/scripts/check-build.mjs +10 -0
  15. package/src/core/annotation-clipboard.js +93 -0
  16. package/src/core/annotation-utils.js +27 -0
  17. package/src/core/cards.js +502 -0
  18. package/src/core/config.js +91 -0
  19. package/src/core/constants.js +34 -0
  20. package/src/core/draft-codec.js +77 -0
  21. package/src/core/draft-store.js +85 -0
  22. package/src/core/hidden-payload.js +73 -0
  23. package/src/core/image-codec.js +111 -0
  24. package/src/core/jump-icon.js +25 -0
  25. package/src/core/locale.js +59 -0
  26. package/src/core/log.js +19 -0
  27. package/src/core/markdown.js +80 -0
  28. package/src/core/messages.js +311 -0
  29. package/src/core/note-tone.js +77 -0
  30. package/src/core/panel-render.js +315 -0
  31. package/src/core/payload.js +191 -0
  32. package/src/core/preview-bridge.js +216 -0
  33. package/src/core/remote-sync.js +206 -0
  34. package/src/core/scroll-trace.js +177 -0
  35. package/src/core/sent-store.js +148 -0
  36. package/src/core/session.js +60 -0
  37. package/src/core/settings.js +168 -0
  38. package/src/core/side-tab-state.js +30 -0
  39. package/src/core/source-capture.js +530 -0
  40. package/src/core/source-locate.js +220 -0
  41. package/src/core/source-resolve.js +89 -0
  42. package/src/core/styles.js +590 -0
  43. package/src/core/turn-anchor.js +54 -0
  44. package/src/core/util.js +55 -0
  45. package/src/core/uuid.js +23 -0
  46. package/src/core/web-picker.js +426 -0
  47. package/src/entry.js +22 -0
  48. package/src/plugin.js +8706 -0
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Selection annotations",
4
+ "description": "Select text in the Web UI to annotate it, then send the whole set with your message. Annotations travel as a separate JSON block, never mixed into your message text; the Agent answers each note in place, and a send is held back until the annotations are stored."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "划选批注",
4
+ "description": "在 Web 界面里选中文字就能加批注,随消息一起发给模型。批注是独立的 JSON 数据块,不会混进消息正文;模型会逐条在批注旁给出答复,批注没存进库时这条消息不会发出去。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
- {
2
- "name": "dsh-selection-annotations",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "dsh-selection-annotations",
3
+ "version": "2.1.1",
4
+ "description": "DeepSeek Harness 批注插件:在 Web 界面里选中文字加批注,随消息一起发送;批注是独立的 JSON 数据块,不会混进消息正文。DSH plugin: select text in the Web UI to annotate it, and send the whole set with your message as a separate JSON content block — never mixed into your message text.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "U2A5F <U2A5F@outlook.com>",
8
+ "keywords": [
9
+ "dsh",
10
+ "dsh-plugin",
11
+ "deepseek-harness",
12
+ "cordis",
13
+ "annotation",
14
+ "selection",
15
+ "quote",
16
+ "web"
17
+ ],
18
+ "engines": {
19
+ "node": ">=22.13"
20
+ },
21
+ "main": "lib/index.js",
22
+ "exports": {
23
+ ".": "./lib/index.js",
24
+ "./client": "./client.js",
25
+ "./icon": "./icon.svg",
26
+ "./locale/*.json": "./locale/*.json",
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "lib",
31
+ "client.js",
32
+ "src",
33
+ "scripts",
34
+ "icon.svg",
35
+ "locale/*.json",
36
+ "cordis.patch.yml",
37
+ "README.md",
38
+ "README.zh-CN.md",
39
+ "CHANGELOG.md"
40
+ ],
41
+ "scripts": {
42
+ "build": "node scripts/build.mjs",
43
+ "check:build": "node scripts/check-build.mjs",
44
+ "test": "node scripts/check-build.mjs && node --import ./test/loader.mjs --test test/*.test.mjs"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/BlazeNebula/dsh-selection-annotations.git"
49
+ },
50
+ "homepage": "https://github.com/BlazeNebula/dsh-selection-annotations#readme",
51
+ "bugs": {
52
+ "url": "https://github.com/BlazeNebula/dsh-selection-annotations/issues"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
57
+ "dsh": {
58
+ "category": "extension",
59
+ "displayName": "划选批注",
60
+ "bundle": {
61
+ "patch": "./cordis.patch.yml"
62
+ },
63
+ "client": {
64
+ "platform": "web",
65
+ "immediately": true,
66
+ "inject": [
67
+ "@deepseek-ai/dsh-client-ui-conversation",
68
+ "@deepseek-ai/dsh-client-ui-session",
69
+ "@deepseek-ai/dsh-client-ui-sidebar-right"
70
+ ]
71
+ }
72
+ },
73
+ "devDependencies": {
74
+ "esbuild": "^0.25.12"
75
+ }
76
+ }
@@ -0,0 +1,37 @@
1
+ import { build } from 'esbuild'
2
+ import { readFileSync } from 'node:fs'
3
+ import { dirname, join } from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
5
+
6
+ const root = join(dirname(fileURLToPath(import.meta.url)), '..')
7
+
8
+ /** DSH 的客户端加载器只取一个文件,所以源码用 ES 模块写、构建时打成 IIFE。 */
9
+ const options = {
10
+ entryPoints: [join(root, 'src/entry.js')],
11
+ bundle: true,
12
+ format: 'iife',
13
+ platform: 'browser',
14
+ target: 'chrome120',
15
+ // React 由宿主注入(__ModuleLoader__ 的 factory(require)),不打进产物。
16
+ external: ['react', 'react-dom/client', '@deepseek-ai/dsh-client-ui-primitives'],
17
+ charset: 'utf8',
18
+ legalComments: 'none',
19
+ logLevel: 'silent',
20
+ }
21
+
22
+ export async function buildClientSource() {
23
+ const result = await build({ ...options, write: false })
24
+ return result.outputFiles[0].text
25
+ }
26
+
27
+ if (process.argv[1] === fileURLToPath(import.meta.url)) {
28
+ const text = await buildClientSource()
29
+ const { writeFileSync } = await import('node:fs')
30
+ writeFileSync(join(root, 'client.js'), text)
31
+ console.log(`client.js <- src/(${text.split('\n').length} 行)`)
32
+ }
33
+
34
+ // 让 check-build 能直接比较源码与产物。
35
+ export function readBuiltClient() {
36
+ return readFileSync(join(root, 'client.js'), 'utf8')
37
+ }
@@ -0,0 +1,10 @@
1
+ // 校验 client.js 与 src/ 一致:直接改产物会被下一次 build 覆盖。
2
+ import { buildClientSource, readBuiltClient } from './build.mjs'
3
+
4
+ const expected = await buildClientSource()
5
+ const actual = readBuiltClient()
6
+
7
+ if (expected !== actual) {
8
+ console.error('client.js 与 src/ 不一致:请运行 `npm run build` 后重新提交。')
9
+ process.exit(1)
10
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * 批注的剪贴板格式:总览右上角「拷贝」把全部批注序列化成一段 JSON,单条「拷贝」
3
+ * 用同一结构只放一条;「粘贴」与输入区的大段粘贴都按这个结构识别。
4
+ * 只保留可迁移的内容(原文、批注、图片、出处),不带本地 id/编号/时间戳。
5
+ */
6
+
7
+ export const ANNOTATION_CLIPBOARD_KIND = 'dsh-selection-annotations/clipboard'
8
+ const PAYLOAD_KIND = 'dsh-selection-annotations'
9
+
10
+ function clipboardImage(image) {
11
+ if (image === null || typeof image !== 'object') return undefined
12
+ const dataUrl = typeof image.dataUrl === 'string' && image.dataUrl !== '' ? image.dataUrl : undefined
13
+ if (dataUrl === undefined) return undefined
14
+ const entry = { name: typeof image.name === 'string' ? image.name : 'image', dataUrl }
15
+ if (typeof image.thumb === 'string' && image.thumb !== '') entry.thumb = image.thumb
16
+ if (typeof image.preview === 'string' && image.preview !== '') entry.preview = image.preview
17
+ return entry
18
+ }
19
+
20
+ function clipboardItem(item) {
21
+ const images = (Array.isArray(item?.images) ? item.images : []).map(clipboardImage).filter(Boolean)
22
+ return {
23
+ quote: typeof item?.quote === 'string' ? item.quote : '',
24
+ note: typeof item?.note === 'string' ? item.note : '',
25
+ ...(images.length > 0 ? { images } : {}),
26
+ ...(item?.source !== null && typeof item?.source === 'object' ? { source: item.source } : {}),
27
+ }
28
+ }
29
+
30
+ /** 把一批批注序列化成可放进剪贴板的字符串。 */
31
+ export function serializeAnnotations(items) {
32
+ const list = Array.isArray(items) ? items : []
33
+ return JSON.stringify({
34
+ kind: ANNOTATION_CLIPBOARD_KIND,
35
+ version: 1,
36
+ count: list.length,
37
+ annotations: list.map(clipboardItem),
38
+ })
39
+ }
40
+
41
+ function normalizeItem(value) {
42
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined
43
+ const quote = typeof value.quote === 'string' ? value.quote : ''
44
+ const note = typeof value.note === 'string' ? value.note : ''
45
+ if (quote.trim() === '' && note.trim() === '') return undefined
46
+ const images = (Array.isArray(value.images) ? value.images : [])
47
+ .map((image) => {
48
+ const dataUrl = typeof image?.dataUrl === 'string' ? image.dataUrl : ''
49
+ if (dataUrl === '') return undefined
50
+ return {
51
+ id: `img-paste-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
52
+ name: typeof image.name === 'string' ? image.name : 'image',
53
+ dataUrl,
54
+ thumb: typeof image.thumb === 'string' && image.thumb !== '' ? image.thumb : dataUrl,
55
+ preview: typeof image.preview === 'string' && image.preview !== '' ? image.preview : dataUrl,
56
+ bytes: Math.round((dataUrl.length * 3) / 4),
57
+ }
58
+ })
59
+ .filter(Boolean)
60
+ return {
61
+ quote,
62
+ note,
63
+ images,
64
+ source: value.source !== null && typeof value.source === 'object' ? value.source : undefined,
65
+ }
66
+ }
67
+
68
+ /**
69
+ * 解析剪贴板文本。只认我们导出的结构(或发送负载同构的结构),其它文本返回
70
+ * undefined,让调用方照常把文字贴进输入框。
71
+ */
72
+ export function parseAnnotations(text) {
73
+ if (typeof text !== 'string' || text.trim() === '') return undefined
74
+ let parsed
75
+ try {
76
+ parsed = JSON.parse(text)
77
+ } catch {
78
+ return undefined
79
+ }
80
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return undefined
81
+ if (parsed.kind !== ANNOTATION_CLIPBOARD_KIND && parsed.kind !== PAYLOAD_KIND) return undefined
82
+ if (!Array.isArray(parsed.annotations)) return undefined
83
+ const items = parsed.annotations.map(normalizeItem).filter(Boolean)
84
+ return items.length > 0 ? items : undefined
85
+ }
86
+
87
+ /** 去重用的内容指纹:原文 + 批注 + 图片名,顺序一致才算同一条。 */
88
+ export function annotationSignature(item) {
89
+ const names = (Array.isArray(item?.images) ? item.images : [])
90
+ .map((image) => (typeof image?.name === 'string' ? image.name : ''))
91
+ .join(',')
92
+ return `${typeof item?.quote === 'string' ? item.quote : ''}\u0000${typeof item?.note === 'string' ? item.note : ''}\u0000${names}`
93
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 一批答复里的每条答复按 uuid 去重:同一条以最后一批为准。
3
+ * 老数据没有 uuid 时才退回按 index 去重,避免同轮不同批同序号互相覆盖。
4
+ */
5
+ export function mergeReplyBatches(batches) {
6
+ const byKey = new Map()
7
+ for (const batch of batches) {
8
+ for (const reply of batch.replies) {
9
+ if (reply === null || typeof reply !== 'object') continue
10
+ const index = Number(reply.index)
11
+ if (!Number.isFinite(index)) continue
12
+ const uuid = typeof reply.uuid === 'string' && reply.uuid !== '' ? reply.uuid : undefined
13
+ const key = uuid !== undefined ? `uuid:${uuid}` : `index:${index}`
14
+ byKey.set(key, { ...reply, index, ...(uuid !== undefined ? { uuid } : {}), at: Number(batch.at) || 0 })
15
+ }
16
+ }
17
+ return [...byKey.values()].sort(
18
+ (a, b) => a.index - b.index || a.at - b.at || String(a.uuid ?? '').localeCompare(String(b.uuid ?? '')),
19
+ )
20
+ }
21
+
22
+ /** 新划出来但既没写文字也没加图:被动确认(点框外、悬停收起)时应当丢弃。 */
23
+ export function shouldDiscardEmpty(mode, note, images) {
24
+ if (mode === 'edit') return false
25
+ if (typeof note === 'string' && note.trim() !== '') return false
26
+ return !Array.isArray(images) || images.length === 0
27
+ }