@gongfpp/dsh-novel-fish 0.1.4 → 1.0.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.
- package/README.md +67 -55
- package/assets/icon.png +0 -0
- package/docs/community-markets.md +48 -29
- package/docs/compatibility-017.md +70 -0
- package/docs/continuous-reading-020.md +46 -0
- package/docs/evidence/banner-100.png +0 -0
- package/docs/evidence/compatibility-017-result.json +65 -0
- package/docs/evidence/continuous-reading-020-result.json +72 -0
- package/docs/evidence/native-settings-sample.md +11 -0
- package/docs/evidence/native-settings-types-015.png +0 -0
- package/docs/evidence/npm-market-014-result.json +132 -0
- package/docs/evidence/plugin-settings-details.png +0 -0
- package/docs/evidence/public-release-015-result.json +36 -0
- package/docs/evidence/reading-demo-100.png +0 -0
- package/docs/evidence/settings-100.png +0 -0
- package/docs/host-adapter.md +3 -3
- package/docs/icon-metadata-021.md +40 -0
- package/docs/interaction-paths-020.md +39 -0
- package/docs/marketplace.md +3 -3
- package/docs/native-settings-update.md +48 -0
- package/docs/plugin-settings-update.md +61 -0
- package/docs/release.md +70 -1
- package/index.json +70 -6
- package/lib/client.js +306 -185
- package/locale/en.json +15 -6
- package/locale/zh.json +15 -6
- package/package.json +15 -13
- package/scripts/check-host-contracts.mjs +246 -0
- package/src/chat-adapter.js +22 -2
- package/src/client.js +5 -5
- package/src/settings.js +155 -95
- package/src/store.js +22 -3
- package/test/chat-adapter.test.js +61 -3
- package/test/client.test.js +82 -0
- package/test/helpers/host-primitives.js +28 -0
- package/test/host-contracts.test.js +32 -0
- package/test/release.test.js +19 -5
- package/test/settings.test.js +214 -65
- package/test/store.test.js +40 -0
- package/assets/icon.svg +0 -1
package/locale/en.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"stopped": "Stopped",
|
|
11
11
|
"unknownBlock": "Unknown content block",
|
|
12
12
|
"jsonTruncated": "… truncated, {total} characters",
|
|
13
|
-
"noBook": "Select a book under
|
|
13
|
+
"noBook": "Select a book under Plugins → Novel Fish first.",
|
|
14
14
|
"switchHint": "Collapse and actively expand this region to read from the current progress.",
|
|
15
15
|
"loading": "Loading…",
|
|
16
16
|
"readError": "The passage could not be loaded; progress did not change.",
|
|
@@ -30,16 +30,25 @@
|
|
|
30
30
|
"typeReadFile": "Open files (read / read_image)",
|
|
31
31
|
"typeCommand": "Run commands (bash / pwsh)",
|
|
32
32
|
"typeFileSearch": "File search (grep / glob)",
|
|
33
|
-
"selectedTypes": "{count} / {total} types selected
|
|
34
|
-
"allTypes": "Select
|
|
35
|
-
"
|
|
33
|
+
"selectedTypes": "{count} / {total} types selected",
|
|
34
|
+
"allTypes": "Select all",
|
|
35
|
+
"clearTypes": "Deselect all",
|
|
36
|
+
"typeHint": "A different region’s first active expansion continues reading. Select none to stop reading.",
|
|
37
|
+
"continueOnReopen": "Continue in the same region",
|
|
38
|
+
"continueOnReopenHint": "When on, collapsing and actively reopening the same region reads the next passage; when off, reopening only shows the passage already there.",
|
|
39
|
+
"books": "Books",
|
|
40
|
+
"importBook": "Import book",
|
|
41
|
+
"reading": "Reading in chat",
|
|
42
|
+
"appearance": "Titles",
|
|
43
|
+
"cancel": "Cancel",
|
|
44
|
+
"confirmDelete": "Delete",
|
|
36
45
|
"bookSource": "Import a book (EPUB / TXT / MD)",
|
|
37
46
|
"selectBook": "Current book",
|
|
38
47
|
"noBook": "Select a book",
|
|
39
48
|
"deleteBook": "Delete current book",
|
|
40
|
-
"progressValue": "Read {progress} / {total} passages
|
|
49
|
+
"progressValue": "Read {progress} / {total} passages · {percent}%",
|
|
41
50
|
"emptyLibrary": "Import an EPUB, TXT, or MD file to begin.",
|
|
42
|
-
"nativeControls": "Icons
|
|
51
|
+
"nativeControls": "Icons and disclosure interactions follow DSH.",
|
|
43
52
|
"titleMain": "Main title",
|
|
44
53
|
"titleExtra": "Additional text",
|
|
45
54
|
"nativeTitle": "Follow the native DSH region title",
|
package/locale/zh.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"stopped": "已停止",
|
|
11
11
|
"unknownBlock": "未知内容块",
|
|
12
12
|
"jsonTruncated": "… 已截断,共 {total} 字符",
|
|
13
|
-
"noBook": "
|
|
13
|
+
"noBook": "请先在插件 → 小说摸鱼中选择一本书。",
|
|
14
14
|
"switchHint": "请收起后再主动展开此区域,从当前进度读取。",
|
|
15
15
|
"loading": "正在读取…",
|
|
16
16
|
"readError": "小说未能加载,阅读进度未改变。",
|
|
@@ -30,16 +30,25 @@
|
|
|
30
30
|
"typeReadFile": "打开文件(read / read_image)",
|
|
31
31
|
"typeCommand": "运行命令(bash / pwsh)",
|
|
32
32
|
"typeFileSearch": "文件搜索(grep / glob)",
|
|
33
|
-
"selectedTypes": "已选择 {count} / {total} 类
|
|
34
|
-
"allTypes": "全选
|
|
35
|
-
"
|
|
33
|
+
"selectedTypes": "已选择 {count} / {total} 类",
|
|
34
|
+
"allTypes": "全选",
|
|
35
|
+
"clearTypes": "取消全选",
|
|
36
|
+
"typeHint": "首次主动展开另一个区域才续读;空选时不读取。",
|
|
37
|
+
"continueOnReopen": "同一区域再次展开续读",
|
|
38
|
+
"continueOnReopenHint": "开启后,收起再主动展开同一区域会接着读下一段;关闭时重复展开只显示这一段。",
|
|
39
|
+
"books": "书籍",
|
|
40
|
+
"importBook": "导入书籍",
|
|
41
|
+
"reading": "聊天内阅读",
|
|
42
|
+
"appearance": "标题显示",
|
|
43
|
+
"cancel": "取消",
|
|
44
|
+
"confirmDelete": "删除",
|
|
36
45
|
"bookSource": "导入书籍(EPUB / TXT / MD)",
|
|
37
46
|
"selectBook": "当前书籍",
|
|
38
47
|
"noBook": "请选择书籍",
|
|
39
48
|
"deleteBook": "删除当前书籍",
|
|
40
|
-
"progressValue": "已读 {progress} / {total}
|
|
49
|
+
"progressValue": "已读 {progress} / {total} 段 · {percent}%",
|
|
41
50
|
"emptyLibrary": "请导入 EPUB、TXT 或 MD 文件开始阅读。",
|
|
42
|
-
"nativeControls": "
|
|
51
|
+
"nativeControls": "图标与折叠交互跟随 DSH。",
|
|
43
52
|
"titleMain": "主标题",
|
|
44
53
|
"titleExtra": "补充文字",
|
|
45
54
|
"nativeTitle": "跟随 DSH 的原生区域标题",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gongfpp/dsh-novel-fish",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/gongfpp/dsh-novel-fish.git"
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
],
|
|
19
19
|
"author": "gongfpp",
|
|
20
20
|
"description": "多选原生思考与工具区域,主动展开时保留原文并以分隔线追加本地小说;不改会话、不发送给模型。",
|
|
21
|
+
"icon": "./assets/icon.png",
|
|
21
22
|
"type": "module",
|
|
22
23
|
"exports": {
|
|
23
24
|
".": "./index.js",
|
|
24
25
|
"./client": "./lib/client.js",
|
|
25
|
-
"./icon": "./assets/icon.
|
|
26
|
+
"./icon": "./assets/icon.png",
|
|
26
27
|
"./locale/*.json": "./locale/*.json",
|
|
27
28
|
"./package.json": "./package.json"
|
|
28
29
|
},
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"src/**",
|
|
35
36
|
"scripts/**",
|
|
36
37
|
"test/**",
|
|
37
|
-
"assets/icon.
|
|
38
|
+
"assets/icon.png",
|
|
38
39
|
"locale/*.json",
|
|
39
40
|
"docs/**",
|
|
40
41
|
"pnpm-lock.yaml",
|
|
@@ -43,12 +44,6 @@
|
|
|
43
44
|
"THIRD-PARTY-NOTICES.txt",
|
|
44
45
|
"LICENSE"
|
|
45
46
|
],
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "node scripts/build.mjs",
|
|
48
|
-
"test": "node --test test/*.test.js",
|
|
49
|
-
"verify": "pnpm run build && pnpm test",
|
|
50
|
-
"pack": "pnpm pack"
|
|
51
|
-
},
|
|
52
47
|
"devDependencies": {
|
|
53
48
|
"@xmldom/xmldom": "^0.9.12",
|
|
54
49
|
"crc-32": "1.2.2",
|
|
@@ -58,11 +53,12 @@
|
|
|
58
53
|
"jsdom": "^30.1.3",
|
|
59
54
|
"jszip": "^3.10.1",
|
|
60
55
|
"react": "18.3.1",
|
|
61
|
-
"react-test-renderer": "18.3.1"
|
|
56
|
+
"react-test-renderer": "18.3.1",
|
|
57
|
+
"semver": "7.7.2"
|
|
62
58
|
},
|
|
63
59
|
"engines": {
|
|
64
60
|
"node": ">=22",
|
|
65
|
-
"dsh": "0.2.1-rc.2"
|
|
61
|
+
"dsh": ">=0.2.1-rc.2 <=0.2.2-alpha.2"
|
|
66
62
|
},
|
|
67
63
|
"license": "MIT",
|
|
68
64
|
"dsh": {
|
|
@@ -73,9 +69,15 @@
|
|
|
73
69
|
"platform": "web",
|
|
74
70
|
"inject": [
|
|
75
71
|
"@deepseek-ai/dsh-client-ui-chat",
|
|
76
|
-
"@deepseek-ai/dsh-client-ui-
|
|
72
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager",
|
|
77
73
|
"@deepseek-ai/dsh-client-locale"
|
|
78
74
|
]
|
|
79
75
|
}
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "node scripts/build.mjs",
|
|
79
|
+
"test": "node --test test/*.test.js",
|
|
80
|
+
"verify": "pnpm run build && pnpm test",
|
|
81
|
+
"pack": "pnpm pack"
|
|
80
82
|
}
|
|
81
|
-
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Read-only, offline probe of an installed DSH build. No server or user profile.
|
|
3
|
+
// Usage: node scripts/check-host-contracts.mjs /absolute/path/to/@deepseek-ai/dsh
|
|
4
|
+
import assert from 'node:assert/strict'
|
|
5
|
+
import { existsSync } from 'node:fs'
|
|
6
|
+
import { readFile, readdir } from 'node:fs/promises'
|
|
7
|
+
import { isAbsolute, join, dirname } from 'node:path'
|
|
8
|
+
import { fileURLToPath } from 'node:url'
|
|
9
|
+
import vm from 'node:vm'
|
|
10
|
+
import { build } from 'esbuild'
|
|
11
|
+
import { JSDOM, VirtualConsole } from 'jsdom'
|
|
12
|
+
import { IDBFactory, IDBKeyRange } from 'fake-indexeddb'
|
|
13
|
+
|
|
14
|
+
const project = fileURLToPath(new URL('../', import.meta.url))
|
|
15
|
+
const host = process.argv[2] ?? process.env.HOST_ROOT
|
|
16
|
+
const report = { hostVersion: null, checks: [], claims: null,
|
|
17
|
+
claimsMeaning: 'Observed book progress after an untrusted click, not claimPassage invocation count.', limitations: [
|
|
18
|
+
'JSDOM, not a browser: no layout, animation, focus or trusted-user-event proof.',
|
|
19
|
+
'Private host exports are exposed only in memory; host boot/apply and full UI renderer are not started.',
|
|
20
|
+
'Identity ancestors and plugin-manager slot declaration are checked statically; small mounting/context facades are supplied by this probe.',
|
|
21
|
+
'Tool/Bash rows and the plugin-manager page are statically checked, not rendered; settings menus/modal are closed.',
|
|
22
|
+
'Plugin is built in memory from current src/client.js; lib/client.js freshness is not checked.',
|
|
23
|
+
'Only the supplied installation is tested; this is not proof for other or future versions.',
|
|
24
|
+
] }
|
|
25
|
+
const check = (name, detail) => report.checks.push({ name, detail })
|
|
26
|
+
const read = path => readFile(path, 'utf8')
|
|
27
|
+
let dom
|
|
28
|
+
try {
|
|
29
|
+
assert.ok(host && isAbsolute(host), 'Pass an absolute DSH installation path (or HOST_ROOT).')
|
|
30
|
+
report.hostVersion = JSON.parse(await read(join(host, 'package.json'))).version
|
|
31
|
+
// Global installs nest the client packages under the dsh package, while a plain
|
|
32
|
+
// `npm install @deepseek-ai/dsh` hoists them next to it. Accept both layouts.
|
|
33
|
+
const siblingScope = dirname(host)
|
|
34
|
+
const packageDir = name => {
|
|
35
|
+
const nested = join(host, 'node_modules/@deepseek-ai', `dsh-${name}`)
|
|
36
|
+
return existsSync(nested) ? nested : join(siblingScope, `dsh-${name}`)
|
|
37
|
+
}
|
|
38
|
+
const client = name => read(join(packageDir(name), 'lib/client.js'))
|
|
39
|
+
const [chat, tool, conversation, manager] = await Promise.all([
|
|
40
|
+
client('client-ui-chat'), client('client-ui-tool'), client('client-ui-conversation'), client('client-ui-plugin-manager'),
|
|
41
|
+
])
|
|
42
|
+
for (const [source, markers] of [[chat, ['data-chat-node-key', 'data-chat-flow-kind']],
|
|
43
|
+
[tool, ['data-chat-call-id', 'data-tool', 'data-variant', 'data-sample']], [conversation, ['data-conversation-session']]]) {
|
|
44
|
+
for (const marker of markers) assert.ok(source.includes(`"${marker}"`), `Missing host DOM marker: ${marker}`)
|
|
45
|
+
}
|
|
46
|
+
const config = manager.match(/"plugins\.bundle\.config":\s*\{\s*kind:\s*"(\w+)",\s*scope:\s*"(\w+)"/)
|
|
47
|
+
assert.ok(config, 'Missing plugins.bundle.config declaration')
|
|
48
|
+
assert.equal(config[1], 'keyed')
|
|
49
|
+
assert.match(manager, /renderSlot\("plugins\.bundle\.config",\s*\{\s*view:\s*"page"\s*\},\s*\{\s*entryKey:\s*pkg\.name/)
|
|
50
|
+
check('static host markers and bundle-config seat', 'chat/tool/conversation markers; keyed config rendered by package name with view=page')
|
|
51
|
+
|
|
52
|
+
// Built-in modules live in the shipped web shell, not separate npm packages.
|
|
53
|
+
const assets = join(packageDir('web-frontend'), 'dist/assets')
|
|
54
|
+
const candidates = (await readdir(assets)).filter(name => /^index-.*\.js$/.test(name))
|
|
55
|
+
let entry, frontend, registry
|
|
56
|
+
for (const candidate of candidates) {
|
|
57
|
+
const source = await read(join(assets, candidate))
|
|
58
|
+
const match = source.match(/function\s+([\w$]+)\(\)\s*\{\s*return\s*\{\s*react:/)
|
|
59
|
+
if (match && source.includes('"@deepseek-ai/dsh-client-ui-primitives"')) {
|
|
60
|
+
entry = join(assets, candidate); frontend = source; registry = match[1]; break
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
assert.ok(registry, 'Cannot locate the shipped web static-module registry; probe needs an update')
|
|
64
|
+
// Disable only the final application boot block, never component/module code.
|
|
65
|
+
const boot = /try\s*\{\s*const\s+[\w$]+\s*=\s*document\.getElementById\("root"\)/
|
|
66
|
+
assert.ok(boot.test(frontend), 'Cannot isolate web application boot; refusing to execute shell')
|
|
67
|
+
frontend = frontend.replace(boot, match => `if (false) ${match}`)
|
|
68
|
+
const errors = []
|
|
69
|
+
const virtualConsole = new VirtualConsole()
|
|
70
|
+
virtualConsole.on('jsdomError', error => errors.push(error.message))
|
|
71
|
+
dom = new JSDOM('<!doctype html><html><head></head><body></body></html>', {
|
|
72
|
+
url: 'http://host-contract.invalid/', runScripts: 'outside-only', pretendToBeVisual: true, virtualConsole,
|
|
73
|
+
})
|
|
74
|
+
Object.assign(dom.window, {
|
|
75
|
+
TextEncoder, TextDecoder, indexedDB: new IDBFactory(), IDBKeyRange,
|
|
76
|
+
fetch: () => { throw new Error('Network is forbidden in host-contract probe') },
|
|
77
|
+
console: { ...console, error: error => { if (error?.message !== 'web app: missing #root') errors.push(String(error)) } },
|
|
78
|
+
})
|
|
79
|
+
const bundled = await build({ stdin: {
|
|
80
|
+
contents: `${frontend}\nglobalThis.__hostContracts = ${registry}();`, resolveDir: dirname(entry), sourcefile: entry,
|
|
81
|
+
}, bundle: true, write: false, format: 'iife', logLevel: 'silent' })
|
|
82
|
+
vm.runInContext(bundled.outputFiles[0].text, dom.getInternalVMContext(), { filename: entry, timeout: 15000 })
|
|
83
|
+
const modules = dom.window.__hostContracts
|
|
84
|
+
const React = modules.react, h = React.createElement
|
|
85
|
+
const primitives = modules['@deepseek-ai/dsh-client-ui-primitives']
|
|
86
|
+
for (const name of ['DisclosureRow', 'TextShimmer', 'Switch', 'Button', 'Input', 'Menu', 'Modal', 'IconChevronDownOutlineRegular']) {
|
|
87
|
+
assert.ok(primitives[name], `Missing real primitive ${name}`)
|
|
88
|
+
}
|
|
89
|
+
const core = new modules['@deepseek-ai/dsh-client-ui-slots'].SlotCore()
|
|
90
|
+
const disposers = [], waiting = new Map()
|
|
91
|
+
const register = (options, component) => {
|
|
92
|
+
const off = core.register(options, component)
|
|
93
|
+
disposers.push(off)
|
|
94
|
+
for (const [name, callback] of waiting) if (core.spec(name)) { waiting.delete(name); callback() }
|
|
95
|
+
return off
|
|
96
|
+
}
|
|
97
|
+
const ctx = {
|
|
98
|
+
slots: { register, registerFactory: (...args) => { const off = core.registerFactory(...args); disposers.push(off); return off },
|
|
99
|
+
inject: (name, callback) => core.spec(name) ? callback() : waiting.set(name, callback) },
|
|
100
|
+
effect: callback => { const off = callback(); if (typeof off === 'function') disposers.push(off) },
|
|
101
|
+
locale: { register: () => () => {}, bind: () => key => key },
|
|
102
|
+
}
|
|
103
|
+
// These two outer seats belong to much larger application trees. Their declarations
|
|
104
|
+
// are checked in the original builds; all subsequent registrations use real SlotCore.
|
|
105
|
+
assert.match(chat, /"conversation\.chat\.node":\s*\{\s*kind:\s*"keyed",\s*scope:\s*"session"/)
|
|
106
|
+
register({ name: 'root', children: {
|
|
107
|
+
'conversation.chat.node': { kind: 'keyed', scope: 'session' },
|
|
108
|
+
'plugins.bundle.config': { kind: config[1], scope: config[2] },
|
|
109
|
+
} }, () => null)
|
|
110
|
+
const capture = (source, filename, expose = '') => {
|
|
111
|
+
let definition
|
|
112
|
+
dom.window.__ModuleLoader__ = { load: value => { definition = value } }
|
|
113
|
+
if (expose) {
|
|
114
|
+
assert.equal(source.split('return module.exports;').length, 2, 'Unknown host factory return shape')
|
|
115
|
+
source = source.replace('return module.exports;', `module.exports.__probe = { ${expose} }; return module.exports;`)
|
|
116
|
+
}
|
|
117
|
+
vm.runInContext(source, dom.getInternalVMContext(), { filename, timeout: 10000 })
|
|
118
|
+
assert.ok(definition?.factory, `No module factory captured from ${filename}`)
|
|
119
|
+
const require = name => {
|
|
120
|
+
assert.ok(modules[name], `Unexpected host import: ${name}`)
|
|
121
|
+
return modules[name]
|
|
122
|
+
}
|
|
123
|
+
require.asset = path => `http://host-contract.invalid/assets/${path}` // CSS only; never fetched
|
|
124
|
+
return definition.factory(require)
|
|
125
|
+
}
|
|
126
|
+
const hostChat = capture(chat, 'host-chat-client.js', 'registerChatNodeRenderers, ReasoningRow')
|
|
127
|
+
hostChat.__probe.registerChatNodeRenderers(ctx, {}, {})
|
|
128
|
+
assert.equal(core.spec('conversation.chat.reasoning.body')?.kind, 'single')
|
|
129
|
+
assert.ok(core.factory('conversation.chat.reasoning.content'))
|
|
130
|
+
const originalBody = core.entriesOfSlot('conversation.chat.reasoning.body')[0]
|
|
131
|
+
const plugin = await build({ entryPoints: [join(project, 'src/client.js')], bundle: true, write: false,
|
|
132
|
+
format: 'iife', logLevel: 'silent' })
|
|
133
|
+
capture(plugin.outputFiles[0].text, 'novel-client-source.js').apply(ctx)
|
|
134
|
+
const body = core.entriesOfSlot('conversation.chat.reasoning.body')[0]
|
|
135
|
+
assert.notEqual(body, originalBody, 'Plugin body must shadow, not replace/delete, host body')
|
|
136
|
+
assert.ok(core.entries('conversation.chat.reasoning.body').includes(originalBody))
|
|
137
|
+
const settings = core.entriesOfSlot('plugins.bundle.config').find(entry => entry.options.key === '@gongfpp/dsh-novel-fish')
|
|
138
|
+
assert.ok(settings)
|
|
139
|
+
check('real SlotCore registrations', 'host registerChatNodeRenderers + plugin apply; body priority shadowing, content Factory and package-keyed settings')
|
|
140
|
+
|
|
141
|
+
const injected = settings.inject()
|
|
142
|
+
const state = injected.hooks.novelState
|
|
143
|
+
await new Promise((resolve, reject) => {
|
|
144
|
+
const timer = setTimeout(() => { off(); reject(new Error('IndexedDB hydration timed out')) }, 3000)
|
|
145
|
+
const ready = () => { if (state.getSnapshot().hydrated) { clearTimeout(timer); off(); resolve() } }
|
|
146
|
+
const off = state.subscribe(ready); ready()
|
|
147
|
+
})
|
|
148
|
+
assert.equal(state.getSnapshot().error, null)
|
|
149
|
+
await injected.onSetOption('mainTitle', 'Contract title')
|
|
150
|
+
await injected.onSetOption('extraTitle', 'Contract summary')
|
|
151
|
+
await injected.onSetOption('enabled', false)
|
|
152
|
+
const book = await injected.onImportFile({ name: 'contract.txt', arrayBuffer: async () => new TextEncoder().encode('Contract novel passage.').buffer })
|
|
153
|
+
await injected.onSelectBook(book.id)
|
|
154
|
+
const hooks = sources => Object.fromEntries(Object.entries(sources).map(([key, source]) => [
|
|
155
|
+
modules['@deepseek-ai/dsh-client-ui-slots'].standardHookPropName(key),
|
|
156
|
+
select => select(React.useSyncExternalStore(source.subscribe, source.getSnapshot)),
|
|
157
|
+
]))
|
|
158
|
+
const t = key => key
|
|
159
|
+
const slotCalls = []
|
|
160
|
+
const renderFactorySlot = (name, props) => {
|
|
161
|
+
slotCalls.push({ name, ...props })
|
|
162
|
+
const factory = core.factory(name)
|
|
163
|
+
assert.ok(factory, `Unknown Factory ${name}`)
|
|
164
|
+
return h(factory.component, { ...props, t })
|
|
165
|
+
}
|
|
166
|
+
function ReasoningProbe() {
|
|
167
|
+
const [expanded, setExpanded] = React.useState(false)
|
|
168
|
+
return h(hostChat.__probe.ReasoningRow, {
|
|
169
|
+
text: 'Native summary\n\nNative reasoning', running: true, t,
|
|
170
|
+
usePresentation: select => select({ settledReasoningPreview: true }),
|
|
171
|
+
useDisclosure: () => ({ expanded, toggle: () => setExpanded(value => !value) }),
|
|
172
|
+
renderSlot: (name, props) => {
|
|
173
|
+
assert.equal(name, 'conversation.chat.reasoning.body')
|
|
174
|
+
const values = body.inject()
|
|
175
|
+
return h(body.component, { ...props, sessionId: 'probe-session', ...hooks(values.hooks), renderFactorySlot, t })
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
const mount = dom.window.document.createElement('main')
|
|
180
|
+
dom.window.document.body.append(mount)
|
|
181
|
+
const root = modules['react-dom/client'].createRoot(mount)
|
|
182
|
+
const flush = callback => modules['react-dom'].flushSync(callback)
|
|
183
|
+
const render = () => flush(() => root.render(h(React.Fragment, null,
|
|
184
|
+
h('div', { 'data-conversation-session': 'probe-session' },
|
|
185
|
+
h('div', { 'data-chat-flow-kind': 'assistant-step', 'data-chat-node-key': 'probe-node' }, h(ReasoningProbe))),
|
|
186
|
+
h(settings.component, { ...injected, ...hooks(injected.hooks), t, view: 'page' }),
|
|
187
|
+
)))
|
|
188
|
+
render()
|
|
189
|
+
await new Promise(resolve => setTimeout(resolve, 25))
|
|
190
|
+
const header = mount.querySelector('[data-disclosure-row]')
|
|
191
|
+
assert.ok(header)
|
|
192
|
+
assert.equal(header.getAttribute('role'), 'button')
|
|
193
|
+
assert.equal(header.getAttribute('aria-expanded'), 'false')
|
|
194
|
+
const nativeNodes = [...header.querySelectorAll('*')]
|
|
195
|
+
const glyphs = [...header.querySelectorAll('svg')]
|
|
196
|
+
const nativeGlyphs = glyphs.map(node => node.outerHTML)
|
|
197
|
+
assert.ok(glyphs.length > 0)
|
|
198
|
+
await injected.onSetOption('enabled', true)
|
|
199
|
+
await new Promise(resolve => setTimeout(resolve, 25))
|
|
200
|
+
assert.deepEqual([...header.querySelectorAll('*')], nativeNodes, 'Adapter must preserve native elements')
|
|
201
|
+
assert.deepEqual(glyphs.map(node => node.outerHTML), nativeGlyphs, 'Adapter must not change native SVGs')
|
|
202
|
+
assert.ok(header.textContent.includes('Contract title'))
|
|
203
|
+
assert.ok(header.textContent.includes('Contract summary'))
|
|
204
|
+
assert.deepEqual([...header.querySelectorAll('[data-shimmer-text]')].map(el => el.getAttribute('data-shimmer-text')), ['Contract title', 'Contract summary'])
|
|
205
|
+
assert.equal(mount.querySelectorAll('[data-novel-append]').length, 0)
|
|
206
|
+
check('real ReasoningRow / DisclosureRow / TextShimmer', 'plugin changes both native text and shimmer layers on actual shipped components; native SVGs remain')
|
|
207
|
+
// This event is intentionally untrusted: it opens React's host row but must never claim a passage.
|
|
208
|
+
flush(() => header.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true })))
|
|
209
|
+
await new Promise(resolve => setTimeout(resolve, 25))
|
|
210
|
+
assert.equal(header.getAttribute('aria-expanded'), 'true')
|
|
211
|
+
assert.ok(slotCalls.some(call => call.name === 'conversation.chat.reasoning.content' && call.text === 'Native summary\n\nNative reasoning' && call.running === true))
|
|
212
|
+
assert.ok(mount.querySelector('[data-novel-original]').textContent.includes('Native reasoning'))
|
|
213
|
+
report.claims = state.getSnapshot().books.find(item => item.id === book.id).progress
|
|
214
|
+
assert.equal(report.claims, 0, 'Untrusted DOM click must not advance book progress')
|
|
215
|
+
check('untrusted-event guard', 'actual host click expands the row but imported in-memory book progress stays at zero; no trusted input is simulated')
|
|
216
|
+
assert.ok(mount.querySelector('[data-novel-settings] button'))
|
|
217
|
+
assert.ok(mount.querySelector('[data-novel-settings] input[type="file"]'))
|
|
218
|
+
check('real body Factory props and settings primitives', 'host row passes text/running; plugin calls actual MarkdownText Factory; settings mounts with real controls and memory IndexedDB')
|
|
219
|
+
await injected.onSetOption('enabled', false)
|
|
220
|
+
await new Promise(resolve => setTimeout(resolve, 25))
|
|
221
|
+
assert.ok(header.textContent.includes('message.think'), 'Disabling must restore native title')
|
|
222
|
+
assert.equal(mount.querySelector('[data-novel-target]'), null)
|
|
223
|
+
check('restore on disable', 'native title restored and adapter target marker removed')
|
|
224
|
+
// The adapter keeps the native row and only rewrites its text, so it depends on the
|
|
225
|
+
// shipped title layers, disclosure row and folding anchors staying put.
|
|
226
|
+
const anchors = {
|
|
227
|
+
chat: { source: chat, markers: ['data-chat-flow-key', 'data-turn-process-member', 'data-turn-process-hidden', 'data-shimmer-decoration'] },
|
|
228
|
+
conversation: { source: conversation, markers: ['data-conversation-session'] },
|
|
229
|
+
shell: { source: frontend, markers: ['data-shimmer-text', 'data-disclosure-row'] },
|
|
230
|
+
}
|
|
231
|
+
for (const [name, { source, markers }] of Object.entries(anchors)) {
|
|
232
|
+
for (const marker of markers) assert.ok(source.includes(`"${marker}"`), `Missing ${name} adapter anchor: ${marker}`)
|
|
233
|
+
}
|
|
234
|
+
check('adapter anchors for title layers and fold state', 'shimmer text/decoration, disclosure row, session identity and turn-process fold markers still ship; ambient DOM rescan has a contract to rescan')
|
|
235
|
+
flush(() => root.unmount())
|
|
236
|
+
for (const dispose of disposers.reverse()) dispose()
|
|
237
|
+
assert.deepEqual(errors, [], 'Unexpected host/JSDOM runtime errors')
|
|
238
|
+
report.ok = true
|
|
239
|
+
} catch (error) {
|
|
240
|
+
report.ok = false
|
|
241
|
+
report.error = error.stack ?? String(error)
|
|
242
|
+
process.exitCode = 1
|
|
243
|
+
} finally {
|
|
244
|
+
dom?.window.close()
|
|
245
|
+
console.log(JSON.stringify(report, null, 2))
|
|
246
|
+
}
|
package/src/chat-adapter.js
CHANGED
|
@@ -98,6 +98,23 @@ export function registerChatAdapter(ctx, store, React, locale) {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
// Streaming text mutates the DOM far more often than a frame; merge observer
|
|
102
|
+
// bursts into one scan so a long session cannot turn every token into a full
|
|
103
|
+
// rescan. Settings/passage updates still refresh immediately.
|
|
104
|
+
let queued = null
|
|
105
|
+
const coalescedRefresh = () => {
|
|
106
|
+
if (!queued) return
|
|
107
|
+
queued = null
|
|
108
|
+
if (!disposed) refresh()
|
|
109
|
+
}
|
|
110
|
+
const scheduleRefresh = () => {
|
|
111
|
+
if (queued) return
|
|
112
|
+
const entry = { frame: null }
|
|
113
|
+
queued = entry
|
|
114
|
+
if (view?.requestAnimationFrame) entry.frame = view.requestAnimationFrame(coalescedRefresh)
|
|
115
|
+
else queueMicrotask(coalescedRefresh)
|
|
116
|
+
}
|
|
117
|
+
|
|
101
118
|
const activate = event => {
|
|
102
119
|
if (!event.isTrusted || event.defaultPrevented) return
|
|
103
120
|
if (event.type === 'keydown' && (event.repeat || !['Enter', ' '].includes(event.key))) return
|
|
@@ -125,13 +142,14 @@ export function registerChatAdapter(ctx, store, React, locale) {
|
|
|
125
142
|
if (!disposed && toggle.isConnected && toggle.getAttribute('aria-expanded') === 'true'
|
|
126
143
|
&& current.enabled && current.currentBookId === bookId && isTarget(current, currentId)
|
|
127
144
|
&& store.cacheGeneration === intent.generation && readingKey(currentId) === intent.key) {
|
|
128
|
-
void store.
|
|
145
|
+
if (current.continueOnReopen === true) void store.continuePassage(readingKey(id), id.type)
|
|
146
|
+
else void store.claimPassage(readingKey(id), id.type)
|
|
129
147
|
}
|
|
130
148
|
}
|
|
131
149
|
if (view?.requestAnimationFrame) intent.frame = view.requestAnimationFrame(verify)
|
|
132
150
|
else queueMicrotask(verify)
|
|
133
151
|
}
|
|
134
|
-
const observer = new MutationObserver(
|
|
152
|
+
const observer = new MutationObserver(scheduleRefresh)
|
|
135
153
|
observer.observe(document.body, { childList: true, subtree: true, characterData: true, attributes: true,
|
|
136
154
|
attributeFilter: ['data-shimmer-text', 'aria-expanded', 'data-tool', 'data-state'] })
|
|
137
155
|
document.addEventListener('click', activate, true)
|
|
@@ -144,6 +162,8 @@ export function registerChatAdapter(ctx, store, React, locale) {
|
|
|
144
162
|
observer.disconnect(); stopSettings(); stopPassages()
|
|
145
163
|
document.removeEventListener('click', activate, true)
|
|
146
164
|
document.removeEventListener('keydown', activate, true)
|
|
165
|
+
if (queued && queued.frame !== null && view?.cancelAnimationFrame) view.cancelAnimationFrame(queued.frame)
|
|
166
|
+
queued = null
|
|
147
167
|
for (const intent of pending.values()) if (intent.frame !== null) view.cancelAnimationFrame(intent.frame)
|
|
148
168
|
pending.clear()
|
|
149
169
|
for (const root of decorated.keys()) restore(root)
|
package/src/client.js
CHANGED
|
@@ -19,12 +19,13 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
id: MODULE_ID,
|
|
20
20
|
factory(require) {
|
|
21
21
|
const React = require('react')
|
|
22
|
+
const primitives = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
22
23
|
return {
|
|
23
24
|
inject: ['slots', 'locale'],
|
|
24
25
|
apply(ctx) {
|
|
25
26
|
const storage = new IndexedDbStorage()
|
|
26
27
|
const store = new NovelStore(storage)
|
|
27
|
-
const SettingsRow = createSettingsRow(React)
|
|
28
|
+
const SettingsRow = createSettingsRow(React, primitives)
|
|
28
29
|
const settingsActions = {
|
|
29
30
|
onSetOption: (key, value) => store.setOption(key, value),
|
|
30
31
|
onSetNotice: notice => store.setNotice(notice),
|
|
@@ -35,10 +36,9 @@ window.__ModuleLoader__.load({
|
|
|
35
36
|
|
|
36
37
|
ctx.effect(() => ctx.locale.register(LOCALE, { zh: flatten(zh), en: flatten(en) }), 'novel-fish: locale')
|
|
37
38
|
ctx.effect(() => () => store.dispose(), 'novel-fish: store')
|
|
38
|
-
ctx.slots.inject('
|
|
39
|
-
name: '
|
|
40
|
-
|
|
41
|
-
order: 24,
|
|
39
|
+
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
|
40
|
+
name: 'plugins.bundle.config',
|
|
41
|
+
key: MODULE_ID,
|
|
42
42
|
locale: LOCALE,
|
|
43
43
|
inject: () => ({
|
|
44
44
|
hooks: {
|