dsh-mineru 0.1.11 → 0.1.13
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/CHANGELOG.md +35 -2
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/RELEASE.md +5 -0
- package/lib/client.js +311 -68
- package/lib/config.js +92 -45
- package/lib/http.js +26 -9
- package/lib/index.js +68 -14
- package/package.json +15 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,38 @@ All notable changes to **dsh-mineru** are documented here. The format follows [K
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
-
- No changes yet (latest release is 0.1.
|
|
7
|
+
- No changes yet (latest release is 0.1.13).
|
|
8
|
+
|
|
9
|
+
## [0.1.13] - 2026-09-25
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Fix total plugin failure on DSH 2.x: `ctx.settings.register` was removed from the settings service, so `apply()` threw `TypeError: ctx.settings.register is not a function` on its first statement and the entry never activated. Nothing was registered — no `mineru_*` tools, no `mineru-tools` skill, no `/plugin/mineru` routes — while the client half still mounted, so the settings card failed with `Failed to execute 'json' on 'Response': Unexpected end of JSON input` (the host answers an unmounted route with `404` and an empty body). The card is now derived from the exported `CONFIG_SCHEMA` the way DSH 2.x expects it.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Every `CONFIG_SCHEMA` field is marked live through the new `live()` helper, which prefers `.volatile()` and falls back to `.extra('volatile', true)`. DSH only offers the fields carrying `meta.volatile`, and an unguarded `.volatile()` would itself fail activation on schemastery < 3.18.4 — a version a profile can hoist above the installation's copy.
|
|
18
|
+
- `state.getCfg()` and `collectFacts()` re-project the entry config on every read (`plainConfig`), because live fields arrive as cosmokit volatile references rather than plain values. A settings write therefore still reaches the next call without a restart, and `exposeMode` stays a load-time switch.
|
|
19
|
+
- `lib/http.js` looks the card up under the profile entry id (`settingsNamespace(ctx)`, falling back to `'mineru'`) instead of the hard-coded `'mineru'` string, and `GET /plugin/mineru/config` now answers `503` with a `hint` when the card does not exist, instead of a `200` carrying an empty config.
|
|
20
|
+
- DSH 0.1.5 compatibility is retained through feature detection: when `ctx.settings.register` exists, the legacy scope seam is still used (register `'mineru'` + scope read/write), so settings cards and persistence keep working for users who have not upgraded.
|
|
21
|
+
- Docs: AGENTS.md settings convention and known traps, plus a migration note under `docs/plans/`.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- `tests/settings.spec.js`: the schema must flag every field volatile, a settings service **without** `register` must still activate the plugin and register its tools and skill, `settingsNamespace` must follow the entry id, `/config` must explain a missing card, and a settings service **with** `register` (DSH 0.1.5) must register the `'mineru'` namespace and serve `/config` through the legacy scope. The stub settings service throws if `register` is called, so the 2.x regression cannot return silently.
|
|
26
|
+
|
|
27
|
+
## [0.1.12] - 2026-09-13
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- Client UI i18n: every user-facing string (settings tab, tool cards, toasts, drag-drop bridge) now comes from zh/en dictionaries registered with the host `ctx.locale` service; the zh dict remains the fallback when the locale service is absent.
|
|
32
|
+
- Vitest suite (`npm test`): rate limiter, daily counter, option resolution, HTML model forcing, and tool-registry shape (15 tests).
|
|
33
|
+
- AGENTS.md contributor guide and DSH upgrade-tracking notes under docs/plans/.
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- RELEASE.md: packaging validation steps — the shipped client bundle must register with `window.__ModuleLoader__.load`, and bare `--dsw-alias-brand-primary` must not appear in `lib/client.js`.
|
|
38
|
+
- package.json: `@deepseek-ai/schemastery` moved to direct dependencies; added `vitest` devDependency, `npm test` script and `engines.node >= 18`; client inject list now includes `locale`.
|
|
8
39
|
|
|
9
40
|
## [0.1.11] - 2026-09-13
|
|
10
41
|
|
|
@@ -77,7 +108,9 @@ All notable changes to **dsh-mineru** are documented here. The format follows [K
|
|
|
77
108
|
- 限流感知(令牌桶 + 429 退避 + 每日限额);
|
|
78
109
|
- Artifact 落地与 Web 界面(设置卡片、工具结果卡片、HMAC 签名预览)。
|
|
79
110
|
|
|
80
|
-
[0.1.
|
|
111
|
+
[0.1.13]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.13
|
|
112
|
+
[0.1.12]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.12
|
|
113
|
+
[0.1.11]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.11
|
|
81
114
|
[0.1.10]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.10
|
|
82
115
|
[0.1.9]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.9
|
|
83
116
|
[0.1.8]: https://github.com/Lee-Hilex/dsh-mineru/releases/tag/v0.1.8
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# dsh-mineru
|
|
2
2
|
|
|
3
3
|
[](LICENSE)
|
|
4
|
-
[](https://github.com/Lee-Hilex/dsh-mineru/releases)
|
|
5
5
|
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
6
6
|
[](https://mineru.net/apiManage/docs)
|
|
7
7
|
|
package/README.zh.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# dsh-mineru
|
|
2
2
|
|
|
3
3
|
[](LICENSE)
|
|
4
|
-
[](https://github.com/Lee-Hilex/dsh-mineru/releases)
|
|
5
5
|
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
6
6
|
[](https://mineru.net/apiManage/docs)
|
|
7
7
|
|
package/RELEASE.md
CHANGED
|
@@ -34,6 +34,11 @@ npm pack --pack-destination D:\Users\Lee\Desktop\dsh
|
|
|
34
34
|
|
|
35
35
|
- [ ] 生成 `dsh-mineru-<version>.tgz` 到 `D:\Users\Lee\Desktop\dsh\`
|
|
36
36
|
- [ ] tgz 内容核对:`lib/`、`cordis.patch.yml`、`README.md`、`README.zh.md`、`CHANGELOG.md`、`CONTRIBUTING.md`、`LICENSE`、`package.json`(`npm pack --dry-run` 可预览清单)
|
|
37
|
+
- [ ] **打包产物校验(防回归,必做)**:
|
|
38
|
+
- [ ] `lib/client.js` 必须以 `window.__ModuleLoader__.load` 开头注册(宿主会拒绝"加载但未注册"的 client bundle):
|
|
39
|
+
`tar -xOf dsh-mineru-<version>.tgz package/lib/client.js | head -c 32` 应含 `__ModuleLoader__`
|
|
40
|
+
- [ ] `lib/client.js` 中不得出现裸的 `--dsw-alias-brand-primary`(深色模式白底白字事故,见 Issue #3);只允许 `--dsw-alias-brand-primary-new-colorprimary-new-color`
|
|
41
|
+
- [ ] tgz 内 `package.json` 的 `version` 与发布版本一致;6 个 `@deepseek-ai/dsh-*` peer 为 `^0.1.5-rc.1`
|
|
37
42
|
- [ ] 本地安装验证(可选但推荐):
|
|
38
43
|
|
|
39
44
|
```powershell
|
package/lib/client.js
CHANGED
|
@@ -8,6 +8,222 @@ window.__ModuleLoader__.load({
|
|
|
8
8
|
var { jsx, jsxs, Fragment } = require("react/jsx-runtime");
|
|
9
9
|
var { useState, useEffect, useCallback, useRef } = React;
|
|
10
10
|
|
|
11
|
+
// ------------------------------------------------------------------
|
|
12
|
+
// i18n: zh/en dictionaries registered with ctx.locale. When the locale
|
|
13
|
+
// service is unavailable (older host), the zh dict is the fallback.
|
|
14
|
+
// ------------------------------------------------------------------
|
|
15
|
+
var NS = "dsh-mineru";
|
|
16
|
+
var DICTS = {
|
|
17
|
+
zh: {
|
|
18
|
+
"toast.noSession": "请先打开一个会话, 再拖入文档.",
|
|
19
|
+
"toast.emptyFile": "跳过空文件: {name}",
|
|
20
|
+
"toast.tooLarge": "文件超过 200MB 上限, 已跳过: {name}",
|
|
21
|
+
"toast.uploadFail": "上传失败: {name} — {err}",
|
|
22
|
+
"toast.uploadedN": "已上传 {n} 个文件并填入输入框: 请补充需求后点击发送.",
|
|
23
|
+
"toast.draftFail": "文件已上传, 但写入输入框失败: {err} 文件路径: {paths}",
|
|
24
|
+
"drop.draftText": "我拖入了以下文件 (已保存到工作区):\n",
|
|
25
|
+
"settings.loading": "正在加载 MinerU 配置…",
|
|
26
|
+
"settings.retry": "重试",
|
|
27
|
+
"settings.loadFail": "加载配置失败: {err}",
|
|
28
|
+
"settings.title": "MinerU 文档解析",
|
|
29
|
+
"badge.tokenOk": "Token 已配置",
|
|
30
|
+
"badge.tokenMissing": "未配置 Token",
|
|
31
|
+
"badge.current": "当前: {api}",
|
|
32
|
+
"settings.intro": "为 DeepSeek Harness 提供基于 MinerU 的多模态全格式文档解析 (PDF/Word/PPT/Excel/HTML/图片 → 结构化 Markdown). 填写 Token 走精准解析 API; Token 留空走 Agent 轻量解析 API. 也可以直接把文档/图片拖入聊天窗口, 插件会自动保存到工作区并发起解析.",
|
|
33
|
+
"field.token.label": "MinerU Token (精准解析 API)",
|
|
34
|
+
"field.token.badgeConfigured": "已配置 ({src})",
|
|
35
|
+
"field.token.badgeMissing": "未配置",
|
|
36
|
+
"field.token.hint": "在 mineru.net 的 API 管理页面创建. 留空则自动使用 Agent 轻量解析 API (免登录, IP 限频). 值只写不读, 不落设置文件, 保存在 DSH 凭据中.",
|
|
37
|
+
"field.token.placeholder": "留空 = 保留现有 Token",
|
|
38
|
+
"action.saveToken": "保存密钥",
|
|
39
|
+
"action.saving": "保存中…",
|
|
40
|
+
"action.clear": "清除",
|
|
41
|
+
"field.mode.label": "API 模式",
|
|
42
|
+
"field.mode.hint": "auto: 有 Token 用精准解析, 否则用 Agent 轻量解析.",
|
|
43
|
+
"mode.auto": "自动 (有 Token 用精准解析, 否则用 Agent 轻量解析)",
|
|
44
|
+
"mode.precision": "精准解析 API (需 Token)",
|
|
45
|
+
"mode.agent": "Agent 轻量解析 API (免 Token)",
|
|
46
|
+
"field.model.label": "精准解析模型版本",
|
|
47
|
+
"field.model.hint": "vlm 推荐; HTML 文件自动强制 MinerU-HTML.",
|
|
48
|
+
"model.pipeline": "pipeline (基础)",
|
|
49
|
+
"model.vlm": "vlm (推荐)",
|
|
50
|
+
"model.mineruHtml": "MinerU-HTML (HTML 专用)",
|
|
51
|
+
"field.lang.label": "文档语言",
|
|
52
|
+
"field.lang.hint": "影响 OCR 识别效果, 默认 ch (中英).",
|
|
53
|
+
"field.table.label": "表格识别 (enableTable)",
|
|
54
|
+
"field.formula.label": "公式识别 (enableFormula)",
|
|
55
|
+
"field.ocr.label": "强制 OCR (isOcr, 扫描件)",
|
|
56
|
+
"field.extra.label": "额外导出格式 (精准解析)",
|
|
57
|
+
"field.extra.hint": "Markdown + JSON 为默认输出; 可追加 docx/html/latex 到结果 Zip.",
|
|
58
|
+
"disclosure.advanced": "高级设置",
|
|
59
|
+
"disclosure.dirty": " (有未保存的更改)",
|
|
60
|
+
"adv.timeout.label": "整体超时 (ms)",
|
|
61
|
+
"adv.timeout.hint": "含提交、上传、轮询等待与下载. 默认 600000 (10 分钟).",
|
|
62
|
+
"adv.pollInterval.label": "轮询间隔 (ms)",
|
|
63
|
+
"adv.pollInterval.hint": "查询任务结果的间隔, 官方查询限频 1000 次/分钟.",
|
|
64
|
+
"adv.maxFileBytes.label": "本地文件大小上限 (字节)",
|
|
65
|
+
"adv.maxFileBytes.hint": "0 = 按 API 限制 (精准 200MB / Agent 10MB).",
|
|
66
|
+
"adv.inlineMarkdownBytes.label": "结果内联预览上限 (字节)",
|
|
67
|
+
"adv.inlineMarkdownBytes.hint": "工具结果内附的 Markdown 预览长度; 全文始终写入 Artifact.",
|
|
68
|
+
"adv.submitRate.label": "提交限速 (个/分钟)",
|
|
69
|
+
"adv.submitRate.hint": "官方 50 个/分钟, 默认留 40 保有裕量.",
|
|
70
|
+
"adv.pollRate.label": "查询限速 (次/分钟)",
|
|
71
|
+
"adv.pollRate.hint": "官方 1000 次/分钟, 默认 900.",
|
|
72
|
+
"adv.dailyLimit.label": "每日提交上限 (个)",
|
|
73
|
+
"adv.dailyLimit.hint": "官方 5000 个/天 (html 100 个), 达到后在本地提前报错.",
|
|
74
|
+
"adv.urlTtl.label": "预览链接有效期 (秒)",
|
|
75
|
+
"adv.urlTtl.hint": "Artifact 签名预览 URL 的过期时间.",
|
|
76
|
+
"adv.apiBase.label": "API 地址",
|
|
77
|
+
"adv.apiBase.hint": "默认 https://mineru.net.",
|
|
78
|
+
"adv.tokenCredential.label": "凭据引用名",
|
|
79
|
+
"adv.tokenCredential.hint": "DSH Credential 引用名 (POSIX 标识符), 默认 MINERU_API_TOKEN.",
|
|
80
|
+
"adv.artifactRoot.label": "Artifact 根目录名",
|
|
81
|
+
"adv.artifactRoot.hint": "每个工作区下的解析结果目录, 默认 .dsh-mineru.",
|
|
82
|
+
"action.save": "保存并应用",
|
|
83
|
+
"action.saveNoop": "保存并应用 (无更改)",
|
|
84
|
+
"action.reload": "重新加载",
|
|
85
|
+
"action.loading": "加载中…",
|
|
86
|
+
"action.testAgent": "测试 Agent API",
|
|
87
|
+
"action.testToken": "测试 Token",
|
|
88
|
+
"action.testingLong": "测试中…(最多约3分钟)",
|
|
89
|
+
"msg.saved": "已保存并生效.",
|
|
90
|
+
"msg.noop": "没有需要保存的更改.",
|
|
91
|
+
"msg.reloaded": "已重新加载.",
|
|
92
|
+
"msg.conflict": "保存冲突: 设置已被其他会话修改, 请点击重新加载后再保存.",
|
|
93
|
+
"msg.saveFail": "保存失败: {err}",
|
|
94
|
+
"msg.saveNetFail": "保存失败 (网络错误): {err}",
|
|
95
|
+
"msg.tokenSaved": "Token 已保存 (当前解析通道: {api}).",
|
|
96
|
+
"msg.tokenCleared": "Token 已清除 (将使用 Agent 轻量解析 API).",
|
|
97
|
+
"msg.tokenSaveFail": "保存 Token 失败: {err}",
|
|
98
|
+
"msg.tokenSaveNetFail": "保存 Token 失败 (网络错误): {err}",
|
|
99
|
+
"msg.tokenClearFail": "清除 Token 失败: {err}",
|
|
100
|
+
"msg.tokenClearNetFail": "清除 Token 失败 (网络错误): {err}",
|
|
101
|
+
"msg.testNetFail": "测试请求失败 (网络错误): {err}",
|
|
102
|
+
"err.composer": "输入框服务不可用",
|
|
103
|
+
"msg.testOk": "测试通过.",
|
|
104
|
+
"api.precision": "精准解析 API",
|
|
105
|
+
"api.agent": "Agent 轻量解析 API",
|
|
106
|
+
"api.precisionMissingToken": "精准解析 (缺 Token)",
|
|
107
|
+
"view.failed": "解析失败",
|
|
108
|
+
"view.taskFailed": "MinerU 任务失败",
|
|
109
|
+
"view.parsing": "MinerU 解析中…",
|
|
110
|
+
"view.source": "来源: {src}",
|
|
111
|
+
"chip.preview": "预览",
|
|
112
|
+
},
|
|
113
|
+
en: {
|
|
114
|
+
"toast.noSession": "Open a session first, then drop documents.",
|
|
115
|
+
"toast.emptyFile": "Skipped empty file: {name}",
|
|
116
|
+
"toast.tooLarge": "File exceeds the 200MB limit, skipped: {name}",
|
|
117
|
+
"toast.uploadFail": "Upload failed: {name} — {err}",
|
|
118
|
+
"toast.uploadedN": "Uploaded {n} file(s) and filled the input box: add your request, then send.",
|
|
119
|
+
"toast.draftFail": "Files uploaded, but filling the input box failed: {err}. Paths: {paths}",
|
|
120
|
+
"drop.draftText": "I dropped the following files (saved to the workspace):\n",
|
|
121
|
+
"settings.loading": "Loading MinerU settings…",
|
|
122
|
+
"settings.retry": "Retry",
|
|
123
|
+
"settings.loadFail": "Failed to load settings: {err}",
|
|
124
|
+
"settings.title": "MinerU Document Parsing",
|
|
125
|
+
"badge.tokenOk": "Token configured",
|
|
126
|
+
"badge.tokenMissing": "No token",
|
|
127
|
+
"badge.current": "Current: {api}",
|
|
128
|
+
"settings.intro": "Provides DeepSeek Harness with MinerU-based multimodal document parsing (PDF/Word/PPT/Excel/HTML/images → structured Markdown). Configure a token to use the precision API, or leave it empty for the token-free Agent lightweight API. You can also drop documents/images into the chat: the plugin saves them to the workspace and starts parsing.",
|
|
129
|
+
"field.token.label": "MinerU Token (precision API)",
|
|
130
|
+
"field.token.badgeConfigured": "Configured ({src})",
|
|
131
|
+
"field.token.badgeMissing": "Not configured",
|
|
132
|
+
"field.token.hint": "Create one in the API management page on mineru.net. Leave empty to use the Agent lightweight API (no login, IP rate-limited). Write-only: the value is stored in DSH Credentials, never in settings files.",
|
|
133
|
+
"field.token.placeholder": "Leave empty = keep the current token",
|
|
134
|
+
"action.saveToken": "Save token",
|
|
135
|
+
"action.saving": "Saving…",
|
|
136
|
+
"action.clear": "Clear",
|
|
137
|
+
"field.mode.label": "API mode",
|
|
138
|
+
"field.mode.hint": "auto: precision API when a token is configured, otherwise the Agent lightweight API.",
|
|
139
|
+
"mode.auto": "Auto (precision API when a token is set, otherwise Agent lightweight API)",
|
|
140
|
+
"mode.precision": "Precision API (requires token)",
|
|
141
|
+
"mode.agent": "Agent lightweight API (no token)",
|
|
142
|
+
"field.model.label": "Precision model version",
|
|
143
|
+
"field.model.hint": "vlm is recommended; HTML files are force-pinned to MinerU-HTML.",
|
|
144
|
+
"model.pipeline": "pipeline (basic)",
|
|
145
|
+
"model.vlm": "vlm (recommended)",
|
|
146
|
+
"model.mineruHtml": "MinerU-HTML (HTML only)",
|
|
147
|
+
"field.lang.label": "Document language",
|
|
148
|
+
"field.lang.hint": "Affects OCR quality; default ch (Chinese + English).",
|
|
149
|
+
"field.table.label": "Table recognition (enableTable)",
|
|
150
|
+
"field.formula.label": "Formula recognition (enableFormula)",
|
|
151
|
+
"field.ocr.label": "Force OCR (isOcr, scanned documents)",
|
|
152
|
+
"field.extra.label": "Extra export formats (precision)",
|
|
153
|
+
"field.extra.hint": "Markdown + JSON are always exported; add docx/html/latex to the result Zip.",
|
|
154
|
+
"disclosure.advanced": "Advanced settings",
|
|
155
|
+
"disclosure.dirty": " (unsaved changes)",
|
|
156
|
+
"adv.timeout.label": "Overall timeout (ms)",
|
|
157
|
+
"adv.timeout.hint": "Covers submission, upload, polling and download. Default 600000 (10 min).",
|
|
158
|
+
"adv.pollInterval.label": "Poll interval (ms)",
|
|
159
|
+
"adv.pollInterval.hint": "Interval between task-status queries; the official query limit is 1000/min.",
|
|
160
|
+
"adv.maxFileBytes.label": "Local file size limit (bytes)",
|
|
161
|
+
"adv.maxFileBytes.hint": "0 = follow API limits (precision 200MB / Agent 10MB).",
|
|
162
|
+
"adv.inlineMarkdownBytes.label": "Inline preview limit (bytes)",
|
|
163
|
+
"adv.inlineMarkdownBytes.hint": "Length of the Markdown preview attached to tool results; the full text always goes to the Artifact.",
|
|
164
|
+
"adv.submitRate.label": "Submission rate (per minute)",
|
|
165
|
+
"adv.submitRate.hint": "Official limit is 50/min; the default of 40 leaves headroom.",
|
|
166
|
+
"adv.pollRate.label": "Query rate (per minute)",
|
|
167
|
+
"adv.pollRate.hint": "Official limit is 1000/min; default 900.",
|
|
168
|
+
"adv.dailyLimit.label": "Daily submission limit",
|
|
169
|
+
"adv.dailyLimit.hint": "Official limit is 5000/day (100 HTML); the plugin fails fast locally once reached.",
|
|
170
|
+
"adv.urlTtl.label": "Preview link TTL (seconds)",
|
|
171
|
+
"adv.urlTtl.hint": "Expiry of signed artifact preview URLs.",
|
|
172
|
+
"adv.apiBase.label": "API base URL",
|
|
173
|
+
"adv.apiBase.hint": "Default https://mineru.net.",
|
|
174
|
+
"adv.tokenCredential.label": "Credential reference name",
|
|
175
|
+
"adv.tokenCredential.hint": "DSH Credential reference (POSIX identifier), default MINERU_API_TOKEN.",
|
|
176
|
+
"adv.artifactRoot.label": "Artifact root name",
|
|
177
|
+
"adv.artifactRoot.hint": "Parsing-results directory under each workspace, default .dsh-mineru.",
|
|
178
|
+
"action.save": "Save & apply",
|
|
179
|
+
"action.saveNoop": "Save & apply (no changes)",
|
|
180
|
+
"action.reload": "Reload",
|
|
181
|
+
"action.loading": "Loading…",
|
|
182
|
+
"action.testAgent": "Test Agent API",
|
|
183
|
+
"action.testToken": "Test token",
|
|
184
|
+
"action.testingLong": "Testing… (up to ~3 min)",
|
|
185
|
+
"msg.saved": "Saved and applied.",
|
|
186
|
+
"msg.noop": "No changes to save.",
|
|
187
|
+
"msg.reloaded": "Reloaded.",
|
|
188
|
+
"msg.conflict": "Save conflict: settings were changed elsewhere; click Reload before saving again.",
|
|
189
|
+
"msg.saveFail": "Save failed: {err}",
|
|
190
|
+
"msg.saveNetFail": "Save failed (network error): {err}",
|
|
191
|
+
"msg.tokenSaved": "Token saved (current channel: {api}).",
|
|
192
|
+
"msg.tokenCleared": "Token cleared (the Agent lightweight API will be used).",
|
|
193
|
+
"msg.tokenSaveFail": "Failed to save token: {err}",
|
|
194
|
+
"msg.tokenSaveNetFail": "Failed to save token (network error): {err}",
|
|
195
|
+
"msg.tokenClearFail": "Failed to clear token: {err}",
|
|
196
|
+
"msg.tokenClearNetFail": "Failed to clear token (network error): {err}",
|
|
197
|
+
"msg.testNetFail": "Test request failed (network error): {err}",
|
|
198
|
+
"err.composer": "Composer input service unavailable",
|
|
199
|
+
"msg.testOk": "Test passed.",
|
|
200
|
+
"api.precision": "precision API",
|
|
201
|
+
"api.agent": "Agent lightweight API",
|
|
202
|
+
"api.precisionMissingToken": "precision (missing token)",
|
|
203
|
+
"view.failed": "Parsing failed",
|
|
204
|
+
"view.taskFailed": "MinerU task failed",
|
|
205
|
+
"view.parsing": "MinerU parsing…",
|
|
206
|
+
"view.source": "Source: {src}",
|
|
207
|
+
"chip.preview": "Preview",
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
var currentT = function (key) { return DICTS.zh[key] !== undefined ? DICTS.zh[key] : key; };
|
|
211
|
+
function fmtT(str, vars) {
|
|
212
|
+
return String(str).replace(/\{(\w+)\}/g, function (_, k) { return vars && vars[k] !== undefined ? vars[k] : "{" + k + "}"; });
|
|
213
|
+
}
|
|
214
|
+
function T(key, vars) { return fmtT(currentT(key), vars); }
|
|
215
|
+
var localeVersion = 0;
|
|
216
|
+
var localeSubs = [];
|
|
217
|
+
function useLocaleVersion() {
|
|
218
|
+
var [v, setV] = useState(localeVersion);
|
|
219
|
+
useEffect(function () {
|
|
220
|
+
var fn = function () { setV(localeVersion); };
|
|
221
|
+
localeSubs.push(fn);
|
|
222
|
+
return function () { localeSubs = localeSubs.filter(function (f) { return f !== fn; }); };
|
|
223
|
+
}, []);
|
|
224
|
+
return v;
|
|
225
|
+
}
|
|
226
|
+
|
|
11
227
|
// ------------------------------------------------------------------
|
|
12
228
|
// Shared helpers
|
|
13
229
|
// ------------------------------------------------------------------
|
|
@@ -38,13 +254,13 @@ window.__ModuleLoader__.load({
|
|
|
38
254
|
var LANGUAGES = ["ch", "ch_server", "en", "japan", "korean", "chinese_cht", "ta", "te", "ka", "el", "th", "latin", "arabic", "cyrillic", "east_slavic", "devanagari"];
|
|
39
255
|
var EXTRA_FORMATS = ["docx", "html", "latex"];
|
|
40
256
|
|
|
41
|
-
|
|
42
|
-
|
|
257
|
+
function modeLabel(m) { return T("mode." + m); }
|
|
258
|
+
function modelLabel(m) { return m === "MinerU-HTML" ? T("model.mineruHtml") : T("model." + m); }
|
|
43
259
|
|
|
44
260
|
function apiLabel(api) {
|
|
45
|
-
if (api === "precision") return "
|
|
46
|
-
if (api === "agent") return "
|
|
47
|
-
if (api === "precision-missing-token") return "
|
|
261
|
+
if (api === "precision") return T("api.precision");
|
|
262
|
+
if (api === "agent") return T("api.agent");
|
|
263
|
+
if (api === "precision-missing-token") return T("api.precisionMissingToken");
|
|
48
264
|
return String(api ?? "");
|
|
49
265
|
}
|
|
50
266
|
|
|
@@ -130,6 +346,7 @@ window.__ModuleLoader__.load({
|
|
|
130
346
|
// Settings tab: MinerU 解析
|
|
131
347
|
// ------------------------------------------------------------------
|
|
132
348
|
function MineruSettingsTab() {
|
|
349
|
+
useLocaleVersion();
|
|
133
350
|
var [state, setState] = useState({ phase: "loading", revision: 0, value: {}, facts: null, defaults: {}, saveMsg: null, saveErr: null, testMsg: null, testErr: null });
|
|
134
351
|
var [busy, setBusy] = useState({ save: false, reload: false, token: false, testToken: false, testAgent: false });
|
|
135
352
|
var [showAdvanced, setShowAdvanced] = useState(false);
|
|
@@ -142,10 +359,10 @@ window.__ModuleLoader__.load({
|
|
|
142
359
|
var payload = await res.json();
|
|
143
360
|
if (!res.ok || !payload.ok) throw new Error(payload.error ?? ("HTTP " + res.status));
|
|
144
361
|
var value = payload.value ?? {};
|
|
145
|
-
setState(function (prev) { return { ...prev, phase: "ready", revision: payload.revision ?? 0, value: value, facts: payload.facts ?? prev.facts, defaults: payload.schemaHints?.defaults ?? {}, saveMsg: announce === true ? "
|
|
362
|
+
setState(function (prev) { return { ...prev, phase: "ready", revision: payload.revision ?? 0, value: value, facts: payload.facts ?? prev.facts, defaults: payload.schemaHints?.defaults ?? {}, saveMsg: announce === true ? T("msg.reloaded") : null, saveErr: null }; });
|
|
146
363
|
setDirty(false);
|
|
147
364
|
} catch (err) {
|
|
148
|
-
setState(function (prev) { return { ...prev, phase: "error", saveErr: "
|
|
365
|
+
setState(function (prev) { return { ...prev, phase: "error", saveErr: T("settings.loadFail", { err: err?.message ?? String(err) }) }; });
|
|
149
366
|
}
|
|
150
367
|
}, []);
|
|
151
368
|
|
|
@@ -159,7 +376,7 @@ window.__ModuleLoader__.load({
|
|
|
159
376
|
var save = async function () {
|
|
160
377
|
if (busy.save) return;
|
|
161
378
|
if (!dirty) {
|
|
162
|
-
setState(function (prev) { return { ...prev, saveMsg: "
|
|
379
|
+
setState(function (prev) { return { ...prev, saveMsg: T("msg.noop"), saveErr: null }; });
|
|
163
380
|
return;
|
|
164
381
|
}
|
|
165
382
|
setBusy(function (b) { return { ...b, save: true }; });
|
|
@@ -167,16 +384,16 @@ window.__ModuleLoader__.load({
|
|
|
167
384
|
try {
|
|
168
385
|
var res = await apiPost("/config", { patch: state.value, expectedRevision: state.revision });
|
|
169
386
|
if (res.status === 200 && res.payload?.ok) {
|
|
170
|
-
setState(function (prev) { return { ...prev, revision: res.payload.revision ?? prev.revision, saveMsg: "
|
|
387
|
+
setState(function (prev) { return { ...prev, revision: res.payload.revision ?? prev.revision, saveMsg: T("msg.saved") }; });
|
|
171
388
|
setDirty(false);
|
|
172
389
|
await reload();
|
|
173
390
|
} else if (res.status === 409) {
|
|
174
|
-
setState(function (prev) { return { ...prev, saveErr: "
|
|
391
|
+
setState(function (prev) { return { ...prev, saveErr: T("msg.conflict") }; });
|
|
175
392
|
} else {
|
|
176
|
-
setState(function (prev) { return { ...prev, saveErr: "
|
|
393
|
+
setState(function (prev) { return { ...prev, saveErr: T("msg.saveFail", { err: res.payload?.error ?? ("HTTP " + res.status) }) }; });
|
|
177
394
|
}
|
|
178
395
|
} catch (err) {
|
|
179
|
-
setState(function (prev) { return { ...prev, saveErr:
|
|
396
|
+
setState(function (prev) { return { ...prev, saveErr: T("msg.saveNetFail", { err: err?.message ?? String(err) }) }; });
|
|
180
397
|
} finally {
|
|
181
398
|
setBusy(function (b) { return { ...b, save: false }; });
|
|
182
399
|
}
|
|
@@ -191,12 +408,12 @@ window.__ModuleLoader__.load({
|
|
|
191
408
|
if (res.status === 200 && res.payload?.ok) {
|
|
192
409
|
setTokenDraft("");
|
|
193
410
|
await reload();
|
|
194
|
-
setState(function (prev) { return { ...prev, saveMsg: "
|
|
411
|
+
setState(function (prev) { return { ...prev, saveMsg: T("msg.tokenSaved", { api: apiLabel(prev.facts?.api) }) }; });
|
|
195
412
|
} else {
|
|
196
|
-
setState(function (prev) { return { ...prev, saveErr: "
|
|
413
|
+
setState(function (prev) { return { ...prev, saveErr: T("msg.tokenSaveFail", { err: res.payload?.error ?? ("HTTP " + res.status) }) }; });
|
|
197
414
|
}
|
|
198
415
|
} catch (err) {
|
|
199
|
-
setState(function (prev) { return { ...prev, saveErr: "
|
|
416
|
+
setState(function (prev) { return { ...prev, saveErr: T("msg.tokenSaveNetFail", { err: err?.message ?? String(err) }) }; });
|
|
200
417
|
} finally {
|
|
201
418
|
setBusy(function (b) { return { ...b, token: false }; });
|
|
202
419
|
}
|
|
@@ -209,13 +426,13 @@ window.__ModuleLoader__.load({
|
|
|
209
426
|
try {
|
|
210
427
|
var res = await apiPost("/credential", { clear: true });
|
|
211
428
|
if (res.status === 200 && res.payload?.ok) {
|
|
212
|
-
setState(function (prev) { return { ...prev, saveMsg: "
|
|
429
|
+
setState(function (prev) { return { ...prev, saveMsg: T("msg.tokenCleared") }; });
|
|
213
430
|
await reload();
|
|
214
431
|
} else {
|
|
215
|
-
setState(function (prev) { return { ...prev, saveErr: "
|
|
432
|
+
setState(function (prev) { return { ...prev, saveErr: T("msg.tokenClearFail", { err: res.payload?.error ?? ("HTTP " + res.status) }) }; });
|
|
216
433
|
}
|
|
217
434
|
} catch (err) {
|
|
218
|
-
setState(function (prev) { return { ...prev, saveErr: "
|
|
435
|
+
setState(function (prev) { return { ...prev, saveErr: T("msg.tokenClearNetFail", { err: err?.message ?? String(err) }) }; });
|
|
219
436
|
} finally {
|
|
220
437
|
setBusy(function (b) { return { ...b, token: false }; });
|
|
221
438
|
}
|
|
@@ -229,22 +446,22 @@ window.__ModuleLoader__.load({
|
|
|
229
446
|
try {
|
|
230
447
|
var res = await apiPost(which === "token" ? "/test-token" : "/test-agent", {});
|
|
231
448
|
if (res.status === 200 && res.payload?.ok) {
|
|
232
|
-
setState(function (prev) { return { ...prev, testMsg: res.payload.message ?? "
|
|
449
|
+
setState(function (prev) { return { ...prev, testMsg: res.payload.message ?? T("msg.testOk") }; });
|
|
233
450
|
} else {
|
|
234
451
|
setState(function (prev) { return { ...prev, testErr: res.payload?.error ?? ("HTTP " + res.status) }; });
|
|
235
452
|
}
|
|
236
453
|
} catch (err) {
|
|
237
|
-
setState(function (prev) { return { ...prev, testErr:
|
|
454
|
+
setState(function (prev) { return { ...prev, testErr: T("msg.testNetFail", { err: err?.message ?? String(err) }) }; });
|
|
238
455
|
} finally {
|
|
239
456
|
setBusy(function (b) { return { ...b, [key]: false }; });
|
|
240
457
|
}
|
|
241
458
|
};
|
|
242
459
|
|
|
243
460
|
if (state.phase === "loading") {
|
|
244
|
-
return jsx("p", { style: S.hint, children: "
|
|
461
|
+
return jsx("p", { style: S.hint, children: T("settings.loading") });
|
|
245
462
|
}
|
|
246
463
|
if (state.phase === "error") {
|
|
247
|
-
return jsxs("div", { children: [jsx("p", { style: S.error, children: state.saveErr }), jsx("button", { style: S.button, onClick: function () { setBusy(function (b) { return { ...b, reload: true }; }); reload(true).finally(function () { setBusy(function (b) { return { ...b, reload: false }; }); }); }, children: "
|
|
464
|
+
return jsxs("div", { children: [jsx("p", { style: S.error, children: state.saveErr }), jsx("button", { style: S.button, onClick: function () { setBusy(function (b) { return { ...b, reload: true }; }); reload(true).finally(function () { setBusy(function (b) { return { ...b, reload: false }; }); }); }, children: T("settings.retry") })] });
|
|
248
465
|
}
|
|
249
466
|
|
|
250
467
|
var facts = state.facts ?? {};
|
|
@@ -252,28 +469,28 @@ window.__ModuleLoader__.load({
|
|
|
252
469
|
var anyBusy = busy.save || busy.reload || busy.token || busy.testToken || busy.testAgent;
|
|
253
470
|
return jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 4 }, children: [
|
|
254
471
|
jsxs("div", { style: S.row, children: [
|
|
255
|
-
jsx("span", { style: { fontSize: 13, fontWeight: 600, color: "var(--dsw-alias-label-primary, #e8e8e8)" }, children: "
|
|
256
|
-
facts.tokenConfigured ? jsx("span", { style: S.badgeOk, children: "
|
|
257
|
-
jsx("span", { style: S.badge, children: "
|
|
472
|
+
jsx("span", { style: { fontSize: 13, fontWeight: 600, color: "var(--dsw-alias-label-primary, #e8e8e8)" }, children: T("settings.title") }),
|
|
473
|
+
facts.tokenConfigured ? jsx("span", { style: S.badgeOk, children: T("badge.tokenOk") }) : jsx("span", { style: S.badgeWarn, children: T("badge.tokenMissing") }),
|
|
474
|
+
jsx("span", { style: S.badge, children: T("badge.current", { api: apiLabel(facts.api) }) }),
|
|
258
475
|
] }),
|
|
259
|
-
jsx("p", { style: S.hint, children: "
|
|
476
|
+
jsx("p", { style: S.hint, children: T("settings.intro") }),
|
|
260
477
|
|
|
261
478
|
// ---- Token ----
|
|
262
|
-
jsx(Field, { label: "
|
|
263
|
-
jsx("input", { type: "password", style: { ...S.input, flex: 1 }, value: tokenDraft, placeholder: "
|
|
264
|
-
jsx("button", { style: S.buttonPrimary, disabled: busy.token || tokenDraft.length === 0, onClick: saveToken, children: busy.token ? "
|
|
265
|
-
jsx("button", { style: S.button, disabled: busy.token, onClick: clearToken, children: "
|
|
479
|
+
jsx(Field, { label: T("field.token.label"), badge: facts.tokenConfigured ? T("field.token.badgeConfigured", { src: facts.tokenSource ?? "?" }) : T("field.token.badgeMissing"), hint: T("field.token.hint"), children: jsxs("div", { style: S.row, children: [
|
|
480
|
+
jsx("input", { type: "password", style: { ...S.input, flex: 1 }, value: tokenDraft, placeholder: T("field.token.placeholder"), onChange: (e) => setTokenDraft(e.target.value) }),
|
|
481
|
+
jsx("button", { style: S.buttonPrimary, disabled: busy.token || tokenDraft.length === 0, onClick: saveToken, children: busy.token ? T("action.saving") : T("action.saveToken") }),
|
|
482
|
+
jsx("button", { style: S.button, disabled: busy.token, onClick: clearToken, children: T("action.clear") }),
|
|
266
483
|
] }) }),
|
|
267
484
|
|
|
268
485
|
// ---- Basic ----
|
|
269
|
-
jsx(SelectField, { label: "
|
|
270
|
-
jsx(SelectField, { label: "
|
|
271
|
-
jsx(SelectField, { label: "
|
|
272
|
-
jsx(CheckField, { label: "
|
|
273
|
-
jsx(CheckField, { label: "
|
|
274
|
-
jsx(CheckField, { label: "
|
|
275
|
-
|
|
276
|
-
jsx(Field, { label: "
|
|
486
|
+
jsx(SelectField, { label: T("field.mode.label"), hint: T("field.mode.hint"), badge: "mode", value: v.mode ?? "auto", options: MODES.map(function (m) { return { value: m, label: m + " — " + modeLabel(m) }; }), onChange: (val) => setValue("mode", val) }),
|
|
487
|
+
jsx(SelectField, { label: T("field.model.label"), hint: T("field.model.hint"), value: v.modelVersion ?? "vlm", options: MODELS.map(function (m) { return { value: m, label: modelLabel(m) }; }), onChange: (val) => setValue("modelVersion", val) }),
|
|
488
|
+
jsx(SelectField, { label: T("field.lang.label"), hint: T("field.lang.hint"), value: v.language ?? "ch", options: LANGUAGES.map(function (l) { return { value: l, label: l }; }), onChange: (val) => setValue("language", val) }),
|
|
489
|
+
jsx(CheckField, { label: T("field.table.label"), value: v.enableTable !== false, onChange: (val) => setValue("enableTable", val) }),
|
|
490
|
+
jsx(CheckField, { label: T("field.formula.label"), value: v.enableFormula !== false, onChange: (val) => setValue("enableFormula", val) }),
|
|
491
|
+
jsx(CheckField, { label: T("field.ocr.label"), value: v.isOcr === true, onChange: (val) => setValue("isOcr", val) }),
|
|
492
|
+
|
|
493
|
+
jsx(Field, { label: T("field.extra.label"), hint: T("field.extra.hint"), children: jsx("div", { style: S.row, children: EXTRA_FORMATS.map(function (f) {
|
|
277
494
|
var on = Array.isArray(v.extraFormats) && v.extraFormats.indexOf(f) >= 0;
|
|
278
495
|
return jsx("label", { style: { ...S.row, cursor: "pointer" }, children: [jsx("input", { type: "checkbox", checked: on, onChange: function (e) {
|
|
279
496
|
var list = Array.isArray(v.extraFormats) ? v.extraFormats.slice() : [];
|
|
@@ -283,30 +500,30 @@ window.__ModuleLoader__.load({
|
|
|
283
500
|
}) }) }),
|
|
284
501
|
|
|
285
502
|
// ---- Advanced (collapsed) ----
|
|
286
|
-
jsx("button", { type: "button", style: S.disclosure, onClick: function () { setShowAdvanced(!showAdvanced); }, children: (showAdvanced ? "▾ " : "▸ ") + "
|
|
503
|
+
jsx("button", { type: "button", style: S.disclosure, onClick: function () { setShowAdvanced(!showAdvanced); }, children: (showAdvanced ? "▾ " : "▸ ") + T("disclosure.advanced") + (dirty && !showAdvanced ? T("disclosure.dirty") : "") }),
|
|
287
504
|
showAdvanced ? jsxs(Fragment, { children: [
|
|
288
|
-
jsx(NumberField, { label: "
|
|
289
|
-
jsx(NumberField, { label: "
|
|
290
|
-
jsx(NumberField, { label: "
|
|
291
|
-
jsx(NumberField, { label: "
|
|
292
|
-
jsx(NumberField, { label: "
|
|
293
|
-
jsx(NumberField, { label: "
|
|
294
|
-
jsx(NumberField, { label: "
|
|
295
|
-
jsx(NumberField, { label: "
|
|
296
|
-
jsx(TextField, { label: "
|
|
297
|
-
jsx(TextField, { label: "
|
|
298
|
-
jsx(TextField, { label: "
|
|
505
|
+
jsx(NumberField, { label: T("adv.timeout.label"), hint: T("adv.timeout.hint"), value: v.timeoutMs, onChange: (val) => setValue("timeoutMs", parseInt(val, 10)) }),
|
|
506
|
+
jsx(NumberField, { label: T("adv.pollInterval.label"), hint: T("adv.pollInterval.hint"), value: v.pollIntervalMs, onChange: (val) => setValue("pollIntervalMs", parseInt(val, 10)) }),
|
|
507
|
+
jsx(NumberField, { label: T("adv.maxFileBytes.label"), hint: T("adv.maxFileBytes.hint"), value: v.maxFileBytes, onChange: (val) => setValue("maxFileBytes", parseInt(val, 10)) }),
|
|
508
|
+
jsx(NumberField, { label: T("adv.inlineMarkdownBytes.label"), hint: T("adv.inlineMarkdownBytes.hint"), value: v.inlineMarkdownBytes, onChange: (val) => setValue("inlineMarkdownBytes", parseInt(val, 10)) }),
|
|
509
|
+
jsx(NumberField, { label: T("adv.submitRate.label"), hint: T("adv.submitRate.hint"), value: v.submitRatePerMin, onChange: (val) => setValue("submitRatePerMin", parseInt(val, 10)) }),
|
|
510
|
+
jsx(NumberField, { label: T("adv.pollRate.label"), hint: T("adv.pollRate.hint"), value: v.pollRatePerMin, onChange: (val) => setValue("pollRatePerMin", parseInt(val, 10)) }),
|
|
511
|
+
jsx(NumberField, { label: T("adv.dailyLimit.label"), hint: T("adv.dailyLimit.hint"), value: v.dailySubmitLimit, onChange: (val) => setValue("dailySubmitLimit", parseInt(val, 10)) }),
|
|
512
|
+
jsx(NumberField, { label: T("adv.urlTtl.label"), hint: T("adv.urlTtl.hint"), value: v.artifactUrlTtlSec, onChange: (val) => setValue("artifactUrlTtlSec", parseInt(val, 10)) }),
|
|
513
|
+
jsx(TextField, { label: T("adv.apiBase.label"), hint: T("adv.apiBase.hint"), value: v.apiBaseUrl, onChange: (val) => setValue("apiBaseUrl", val) }),
|
|
514
|
+
jsx(TextField, { label: T("adv.tokenCredential.label"), hint: T("adv.tokenCredential.hint"), value: v.tokenCredential, onChange: (val) => setValue("tokenCredential", val) }),
|
|
515
|
+
jsx(TextField, { label: T("adv.artifactRoot.label"), hint: T("adv.artifactRoot.hint"), value: v.artifactRootName, onChange: (val) => setValue("artifactRootName", val) }),
|
|
299
516
|
] }) : null,
|
|
300
517
|
|
|
301
518
|
// ---- Actions ----
|
|
302
519
|
state.saveMsg ? jsx("p", { style: S.okText, children: state.saveMsg }) : null,
|
|
303
520
|
state.saveErr ? jsx("p", { style: S.error, children: state.saveErr }) : null,
|
|
304
521
|
jsxs("div", { style: { ...S.row, paddingTop: 12, flexWrap: "wrap" }, children: [
|
|
305
|
-
jsx("button", { style: S.buttonPrimary, onClick: save, disabled: anyBusy, children: busy.save ? "
|
|
306
|
-
jsx("button", { style: S.button, disabled: anyBusy, onClick: function () { setBusy(function (b) { return { ...b, reload: true }; }); reload(true).finally(function () { setBusy(function (b) { return { ...b, reload: false }; }); }); }, children: busy.reload ? "
|
|
522
|
+
jsx("button", { style: S.buttonPrimary, onClick: save, disabled: anyBusy, children: busy.save ? T("action.saving") : (dirty ? T("action.save") : T("action.saveNoop")) }),
|
|
523
|
+
jsx("button", { style: S.button, disabled: anyBusy, onClick: function () { setBusy(function (b) { return { ...b, reload: true }; }); reload(true).finally(function () { setBusy(function (b) { return { ...b, reload: false }; }); }); }, children: busy.reload ? T("action.loading") : T("action.reload") }),
|
|
307
524
|
jsx("span", { style: { flex: 1 } }),
|
|
308
|
-
jsx("button", { style: S.button, disabled: anyBusy, onClick: function () { return runTest("agent"); }, children: busy.testAgent ? "
|
|
309
|
-
jsx("button", { style: S.button, disabled: anyBusy, onClick: function () { return runTest("token"); }, children: busy.testToken ? "
|
|
525
|
+
jsx("button", { style: S.button, disabled: anyBusy, onClick: function () { return runTest("agent"); }, children: busy.testAgent ? T("action.testingLong") : T("action.testAgent") }),
|
|
526
|
+
jsx("button", { style: S.button, disabled: anyBusy, onClick: function () { return runTest("token"); }, children: busy.testToken ? T("action.testingLong") : T("action.testToken") }),
|
|
310
527
|
] }),
|
|
311
528
|
state.testMsg ? jsx("p", { style: S.okText, children: state.testMsg }) : null,
|
|
312
529
|
state.testErr ? jsx("p", { style: S.error, children: state.testErr }) : null,
|
|
@@ -329,11 +546,12 @@ window.__ModuleLoader__.load({
|
|
|
329
546
|
return jsxs("span", { style: { display: "inline-flex", alignItems: "center", gap: 6, background: "var(--dsw-alias-bg-module-platform, #20242c)", border: "1px solid var(--dsw-alias-border-l2, #2a2d34)", borderRadius: 8, padding: "3px 10px", fontSize: 12 }, children: [
|
|
330
547
|
jsx("button", { type: "button", title: a.path, style: { ...S.button, padding: "0", border: "none", background: "transparent", fontSize: 12 }, onClick: function () { props.openFile(a.path); }, children: a.name }),
|
|
331
548
|
jsx("span", { style: S.hint, children: a.kind + " · " + fmtBytes(a.bytes) }),
|
|
332
|
-
a.url ? jsx("a", { href: a.url, target: "_blank", rel: "noopener noreferrer", style: { fontSize: 12, color: "var(--dsw-alias-brand-primary-new-colorprimary-new-color, #4d6bfe)" }, children: "
|
|
549
|
+
a.url ? jsx("a", { href: a.url, target: "_blank", rel: "noopener noreferrer", style: { fontSize: 12, color: "var(--dsw-alias-brand-primary-new-colorprimary-new-color, #4d6bfe)" }, children: T("chip.preview") }) : null,
|
|
333
550
|
] }, a.path);
|
|
334
551
|
}
|
|
335
552
|
|
|
336
553
|
function MetaCard(props) {
|
|
554
|
+
useLocaleVersion();
|
|
337
555
|
var meta = props.meta;
|
|
338
556
|
if (!meta || typeof meta !== "object") return null;
|
|
339
557
|
var artifacts = Array.isArray(meta.artifacts) ? meta.artifacts : [];
|
|
@@ -364,6 +582,7 @@ window.__ModuleLoader__.load({
|
|
|
364
582
|
}
|
|
365
583
|
|
|
366
584
|
function MineruToolView(props) {
|
|
585
|
+
useLocaleVersion();
|
|
367
586
|
var block = props.block;
|
|
368
587
|
if (!block) return null;
|
|
369
588
|
var args = null;
|
|
@@ -383,8 +602,8 @@ window.__ModuleLoader__.load({
|
|
|
383
602
|
}
|
|
384
603
|
}
|
|
385
604
|
return jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 6, padding: "8px 0" }, children: [
|
|
386
|
-
jsx("span", { style: S.badgeWarn, children: "
|
|
387
|
-
jsx("p", { style: S.error, children: String(text || "
|
|
605
|
+
jsx("span", { style: S.badgeWarn, children: T("view.failed") }),
|
|
606
|
+
jsx("p", { style: S.error, children: String(text || T("view.taskFailed")).slice(0, 600) }),
|
|
388
607
|
] });
|
|
389
608
|
}
|
|
390
609
|
return jsx(MetaCard, { meta: meta, openFile: props.openFile });
|
|
@@ -393,8 +612,8 @@ window.__ModuleLoader__.load({
|
|
|
393
612
|
// running
|
|
394
613
|
var source = args?.source ?? args?.taskId ?? "";
|
|
395
614
|
return jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 6, padding: "8px 0" }, children: [
|
|
396
|
-
jsx("span", { style: S.badge, children: "
|
|
397
|
-
jsx("p", { style: S.hint, children: "
|
|
615
|
+
jsx("span", { style: S.badge, children: T("view.parsing") }),
|
|
616
|
+
jsx("p", { style: S.hint, children: T("view.source", { src: String(source).slice(0, 200) }) }),
|
|
398
617
|
] });
|
|
399
618
|
}
|
|
400
619
|
|
|
@@ -430,7 +649,7 @@ window.__ModuleLoader__.load({
|
|
|
430
649
|
var conversation = ctx.get("conversation");
|
|
431
650
|
var actx = ctx.sessions.scope(sessionId);
|
|
432
651
|
if (!conversation || !actx || typeof conversation.input?.for !== "function") {
|
|
433
|
-
throw new Error("
|
|
652
|
+
throw new Error(T("err.composer"));
|
|
434
653
|
}
|
|
435
654
|
conversation.input.for(actx).setDraft(text);
|
|
436
655
|
};
|
|
@@ -438,14 +657,14 @@ window.__ModuleLoader__.load({
|
|
|
438
657
|
async function intake(files) {
|
|
439
658
|
var sessionId = currentSession();
|
|
440
659
|
if (!sessionId) {
|
|
441
|
-
toast("
|
|
660
|
+
toast(T("toast.noSession"), "error");
|
|
442
661
|
return;
|
|
443
662
|
}
|
|
444
663
|
var uploaded = [];
|
|
445
664
|
for (var i = 0; i < files.length; i++) {
|
|
446
665
|
var file = files[i];
|
|
447
|
-
if (file.size === 0) { toast("
|
|
448
|
-
if (file.size > DROP_MAX_BYTES) { toast("
|
|
666
|
+
if (file.size === 0) { toast(T("toast.emptyFile", { name: file.name }), "error"); continue; }
|
|
667
|
+
if (file.size > DROP_MAX_BYTES) { toast(T("toast.tooLarge", { name: file.name }), "error"); continue; }
|
|
449
668
|
try {
|
|
450
669
|
var url = "/plugin/mineru/upload?sessionId=" + encodeURIComponent(sessionId) + "&name=" + encodeURIComponent(file.name);
|
|
451
670
|
var res = await fetch(url, { method: "POST", headers: { "Content-Type": "application/octet-stream" }, body: file });
|
|
@@ -454,18 +673,18 @@ window.__ModuleLoader__.load({
|
|
|
454
673
|
if (!res.ok || !payload?.ok) throw new Error(payload?.error ?? ("HTTP " + res.status));
|
|
455
674
|
uploaded.push(payload.path);
|
|
456
675
|
} catch (err) {
|
|
457
|
-
toast("
|
|
676
|
+
toast(T("toast.uploadFail", { name: file.name, err: err?.message ?? String(err) }), "error");
|
|
458
677
|
}
|
|
459
678
|
}
|
|
460
679
|
if (uploaded.length === 0) return;
|
|
461
680
|
// Only the file-list statement goes into the composer draft. The user
|
|
462
681
|
// appends their own requirements and sends; nothing is auto-submitted.
|
|
463
|
-
var text = "
|
|
682
|
+
var text = T("drop.draftText") + uploaded.map(function (p) { return "- " + p; }).join("\n") + "\n\n";
|
|
464
683
|
try {
|
|
465
684
|
fillDraft(sessionId, text);
|
|
466
|
-
toast("
|
|
685
|
+
toast(T("toast.uploadedN", { n: uploaded.length }));
|
|
467
686
|
} catch (err) {
|
|
468
|
-
toast("
|
|
687
|
+
toast(T("toast.draftFail", { err: err?.message ?? String(err), paths: uploaded.join("; ") }), "error");
|
|
469
688
|
}
|
|
470
689
|
}
|
|
471
690
|
|
|
@@ -529,9 +748,33 @@ window.__ModuleLoader__.load({
|
|
|
529
748
|
// ------------------------------------------------------------------
|
|
530
749
|
// Plugin entry
|
|
531
750
|
// ------------------------------------------------------------------
|
|
532
|
-
var inject = ["slots", "connection", "sessions", "conversation"];
|
|
751
|
+
var inject = ["slots", "connection", "sessions", "conversation", "locale"];
|
|
533
752
|
|
|
534
753
|
function apply(ctx) {
|
|
754
|
+
// Register zh/en dictionaries with the host locale service. If the
|
|
755
|
+
// service is absent (older host), the zh dict remains the fallback.
|
|
756
|
+
if (ctx.locale) {
|
|
757
|
+
try {
|
|
758
|
+
ctx.effect(function () { return ctx.locale.register(NS, { zh: DICTS.zh, en: DICTS.en }); }, "dsh-mineru: dictionaries");
|
|
759
|
+
ctx.effect(function () {
|
|
760
|
+
var dis = [];
|
|
761
|
+
for (var loc in DICTS) dis.push(ctx.locale.register(NS, loc, DICTS[loc]));
|
|
762
|
+
return function () { for (var i = 0; i < dis.length; i++) dis[i](); };
|
|
763
|
+
}, "dsh-mineru: language-pack dictionaries");
|
|
764
|
+
ctx.effect(function () {
|
|
765
|
+
var rebind = function () {
|
|
766
|
+
currentT = ctx.locale.bind(NS) || currentT;
|
|
767
|
+
localeVersion += 1;
|
|
768
|
+
for (var i = 0; i < localeSubs.length; i++) localeSubs[i]();
|
|
769
|
+
};
|
|
770
|
+
rebind();
|
|
771
|
+
var obs = new MutationObserver(rebind);
|
|
772
|
+
obs.observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] });
|
|
773
|
+
return function () { obs.disconnect(); };
|
|
774
|
+
}, "dsh-mineru: locale watcher");
|
|
775
|
+
} catch (e) { /* locale service unavailable: zh fallback stays */ }
|
|
776
|
+
}
|
|
777
|
+
|
|
535
778
|
ctx.slots.inject("settings.plugins.tab", () => ctx.slots.register({
|
|
536
779
|
name: "settings.plugins.tab",
|
|
537
780
|
id: "mineru",
|
package/lib/config.js
CHANGED
|
@@ -5,13 +5,60 @@
|
|
|
5
5
|
* DSH Credentials under the `tokenCredential` reference name (default
|
|
6
6
|
* MINERU_API_TOKEN), never in settings or composition files.
|
|
7
7
|
*
|
|
8
|
-
* Resolution layers
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Resolution layers: schema defaults < composition base (the bundle row's
|
|
9
|
+
* config) < the profile entry patch written by the Web Settings card. DSH 2.x
|
|
10
|
+
* derives that card from this schema, so every field is marked live (see
|
|
11
|
+
* {@link live}) and arrives in `apply(ctx, config)` as a volatile reference
|
|
12
|
+
* rather than a plain value — read it through {@link plainConfig}.
|
|
11
13
|
* @module dsh-mineru/config
|
|
12
14
|
*/
|
|
13
15
|
import z from '@deepseek-ai/schemastery';
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Mark one field live-editable.
|
|
19
|
+
*
|
|
20
|
+
* DSH 2.x derives a plugin's settings card from its exported `Config` and only
|
|
21
|
+
* offers the fields carrying `meta.volatile`; a schema without them has no card
|
|
22
|
+
* at all. `.volatile()` exists in schemastery >= 3.18.4 only, and a profile can
|
|
23
|
+
* hoist an older copy (3.18.2 still satisfies `^3.18.0`) above the
|
|
24
|
+
* installation's one, so an unguarded call fails activation with
|
|
25
|
+
* `TypeError: ...volatile is not a function`. `.extra('volatile', true)` writes
|
|
26
|
+
* the same flag on every version, so the card appears either way; only hot-edit
|
|
27
|
+
* needs the newer copy.
|
|
28
|
+
* @template T
|
|
29
|
+
* @param {T} field one schemastery field
|
|
30
|
+
* @returns {T} the field, flagged volatile when the copy supports it
|
|
31
|
+
*/
|
|
32
|
+
export function live(field) {
|
|
33
|
+
if (typeof field?.volatile === 'function') return field.volatile();
|
|
34
|
+
if (typeof field?.extra === 'function') return field.extra('volatile', true);
|
|
35
|
+
return field;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Unwrap one live configuration reference.
|
|
40
|
+
*
|
|
41
|
+
* A `meta.volatile` field resolves to a cosmokit volatile reference; reading it
|
|
42
|
+
* through `get()` is what makes a settings write visible to the next call.
|
|
43
|
+
* Plain values pass through unchanged.
|
|
44
|
+
* @param {unknown} value a reference or a plain value
|
|
45
|
+
* @returns {unknown} the current value
|
|
46
|
+
*/
|
|
47
|
+
export function unwrapField(value) {
|
|
48
|
+
return value !== null && typeof value === 'object' && typeof value.get === 'function' ? value.get() : value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Project the entry config into plain values.
|
|
53
|
+
* @param {object} [config] entry config handed to `apply` (volatile fields are references)
|
|
54
|
+
* @returns {object} a plain, detached configuration object
|
|
55
|
+
*/
|
|
56
|
+
export function plainConfig(config) {
|
|
57
|
+
const out = {};
|
|
58
|
+
for (const [key, value] of Object.entries(config ?? {})) out[key] = unwrapField(value);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
15
62
|
/** Supported MinerU document languages (language packs from the API docs). */
|
|
16
63
|
export const LANGUAGE_VALUES = Object.freeze([
|
|
17
64
|
'ch', 'ch_server', 'en', 'japan', 'korean', 'chinese_cht',
|
|
@@ -80,56 +127,56 @@ export const DEFAULTS = Object.freeze({
|
|
|
80
127
|
});
|
|
81
128
|
|
|
82
129
|
export const CONFIG_SCHEMA = z.object({
|
|
83
|
-
apiBaseUrl: z.string().role('text')
|
|
130
|
+
apiBaseUrl: live(z.string().role('text')
|
|
84
131
|
.default(DEFAULTS.apiBaseUrl)
|
|
85
|
-
.description('MinerU API base URL (https://mineru.net).'),
|
|
86
|
-
tokenCredential: z.string().role('text')
|
|
132
|
+
.description('MinerU API base URL (https://mineru.net).')),
|
|
133
|
+
tokenCredential: live(z.string().role('text')
|
|
87
134
|
.default(DEFAULTS.tokenCredential)
|
|
88
|
-
.description('DSH Credential reference name holding the MinerU token.'),
|
|
89
|
-
mode: z.union([z.const('auto'), z.const('precision'), z.const('agent')])
|
|
135
|
+
.description('DSH Credential reference name holding the MinerU token.')),
|
|
136
|
+
mode: live(z.union([z.const('auto'), z.const('precision'), z.const('agent')])
|
|
90
137
|
.default(DEFAULTS.mode)
|
|
91
|
-
.description('API mode: auto (token present -> precision, else agent), precision, or agent.'),
|
|
92
|
-
modelVersion: z.union([z.const('pipeline'), z.const('vlm'), z.const('MinerU-HTML')])
|
|
138
|
+
.description('API mode: auto (token present -> precision, else agent), precision, or agent.')),
|
|
139
|
+
modelVersion: live(z.union([z.const('pipeline'), z.const('vlm'), z.const('MinerU-HTML')])
|
|
93
140
|
.default(DEFAULTS.modelVersion)
|
|
94
|
-
.description('Precision-API model version (pipeline | vlm | MinerU-HTML).'),
|
|
95
|
-
language: z.string().role('text')
|
|
141
|
+
.description('Precision-API model version (pipeline | vlm | MinerU-HTML).')),
|
|
142
|
+
language: live(z.string().role('text')
|
|
96
143
|
.default(DEFAULTS.language)
|
|
97
|
-
.description('Document language pack, e.g. ch, en, latin (see README table).'),
|
|
98
|
-
enableTable: z.boolean().default(DEFAULTS.enableTable)
|
|
99
|
-
.description('Enable table recognition.'),
|
|
100
|
-
enableFormula: z.boolean().default(DEFAULTS.enableFormula)
|
|
101
|
-
.description('Enable formula recognition.'),
|
|
102
|
-
isOcr: z.boolean().default(DEFAULTS.isOcr)
|
|
103
|
-
.description('Force OCR for scanned content.'),
|
|
104
|
-
extraFormats: z.array(z.union([z.const('docx'), z.const('html'), z.const('latex')]))
|
|
144
|
+
.description('Document language pack, e.g. ch, en, latin (see README table).')),
|
|
145
|
+
enableTable: live(z.boolean().default(DEFAULTS.enableTable)
|
|
146
|
+
.description('Enable table recognition.')),
|
|
147
|
+
enableFormula: live(z.boolean().default(DEFAULTS.enableFormula)
|
|
148
|
+
.description('Enable formula recognition.')),
|
|
149
|
+
isOcr: live(z.boolean().default(DEFAULTS.isOcr)
|
|
150
|
+
.description('Force OCR for scanned content.')),
|
|
151
|
+
extraFormats: live(z.array(z.union([z.const('docx'), z.const('html'), z.const('latex')]))
|
|
105
152
|
.default(DEFAULTS.extraFormats)
|
|
106
|
-
.description('Precision-only extra export formats added to the result zip.'),
|
|
107
|
-
exposeMode: z.union([z.const('progressive'), z.const('always')])
|
|
153
|
+
.description('Precision-only extra export formats added to the result zip.')),
|
|
154
|
+
exposeMode: live(z.union([z.const('progressive'), z.const('always')])
|
|
108
155
|
.default(DEFAULTS.exposeMode)
|
|
109
|
-
.description('progressive: mineru_activate bootstrap + skill-based activation; always: register all tools globally.'),
|
|
110
|
-
artifactRootName: z.string().role('text')
|
|
156
|
+
.description('progressive: mineru_activate bootstrap + skill-based activation; always: register all tools globally.')),
|
|
157
|
+
artifactRootName: live(z.string().role('text')
|
|
111
158
|
.default(DEFAULTS.artifactRootName)
|
|
112
|
-
.description('Artifact root directory name inside each session workspace.'),
|
|
113
|
-
pollIntervalMs: z.number().default(DEFAULTS.pollIntervalMs)
|
|
114
|
-
.description('Task-result poll interval (ms).'),
|
|
115
|
-
pollJitterMs: z.number().default(DEFAULTS.pollJitterMs)
|
|
116
|
-
.description('Per-query poll jitter (ms).'),
|
|
117
|
-
timeoutMs: z.number().default(DEFAULTS.timeoutMs)
|
|
118
|
-
.description('Whole-operation deadline (ms).'),
|
|
119
|
-
maxFileBytes: z.number().default(DEFAULTS.maxFileBytes)
|
|
120
|
-
.description('Local file byte cap; 0 = per-mode API limits (200 MB / 10 MB).'),
|
|
121
|
-
inlineMarkdownBytes: z.number().default(DEFAULTS.inlineMarkdownBytes)
|
|
122
|
-
.description('Markdown preview bytes returned inline with the tool result.'),
|
|
123
|
-
artifactUrlTtlSec: z.number().default(DEFAULTS.artifactUrlTtlSec)
|
|
124
|
-
.description('Signed artifact preview URL lifetime (seconds).'),
|
|
125
|
-
submitRatePerMin: z.number().default(DEFAULTS.submitRatePerMin)
|
|
126
|
-
.description('Submission rate cap per minute (official limit: 50/min).'),
|
|
127
|
-
pollRatePerMin: z.number().default(DEFAULTS.pollRatePerMin)
|
|
128
|
-
.description('Result-query rate cap per minute (official limit: 1000/min).'),
|
|
129
|
-
dailySubmitLimit: z.number().default(DEFAULTS.dailySubmitLimit)
|
|
130
|
-
.description('Daily submission cap reported before the API rejects (official: 5000/day).'),
|
|
131
|
-
userAgent: z.string().role('text').default(DEFAULTS.userAgent)
|
|
132
|
-
.description('User-Agent header sent to MinerU.'),
|
|
159
|
+
.description('Artifact root directory name inside each session workspace.')),
|
|
160
|
+
pollIntervalMs: live(z.number().default(DEFAULTS.pollIntervalMs)
|
|
161
|
+
.description('Task-result poll interval (ms).')),
|
|
162
|
+
pollJitterMs: live(z.number().default(DEFAULTS.pollJitterMs)
|
|
163
|
+
.description('Per-query poll jitter (ms).')),
|
|
164
|
+
timeoutMs: live(z.number().default(DEFAULTS.timeoutMs)
|
|
165
|
+
.description('Whole-operation deadline (ms).')),
|
|
166
|
+
maxFileBytes: live(z.number().default(DEFAULTS.maxFileBytes)
|
|
167
|
+
.description('Local file byte cap; 0 = per-mode API limits (200 MB / 10 MB).')),
|
|
168
|
+
inlineMarkdownBytes: live(z.number().default(DEFAULTS.inlineMarkdownBytes)
|
|
169
|
+
.description('Markdown preview bytes returned inline with the tool result.')),
|
|
170
|
+
artifactUrlTtlSec: live(z.number().default(DEFAULTS.artifactUrlTtlSec)
|
|
171
|
+
.description('Signed artifact preview URL lifetime (seconds).')),
|
|
172
|
+
submitRatePerMin: live(z.number().default(DEFAULTS.submitRatePerMin)
|
|
173
|
+
.description('Submission rate cap per minute (official limit: 50/min).')),
|
|
174
|
+
pollRatePerMin: live(z.number().default(DEFAULTS.pollRatePerMin)
|
|
175
|
+
.description('Result-query rate cap per minute (official limit: 1000/min).')),
|
|
176
|
+
dailySubmitLimit: live(z.number().default(DEFAULTS.dailySubmitLimit)
|
|
177
|
+
.description('Daily submission cap reported before the API rejects (official: 5000/day).')),
|
|
178
|
+
userAgent: live(z.string().role('text').default(DEFAULTS.userAgent)
|
|
179
|
+
.description('User-Agent header sent to MinerU.')),
|
|
133
180
|
});
|
|
134
181
|
|
|
135
182
|
/**
|
package/lib/http.js
CHANGED
|
@@ -71,8 +71,9 @@ function stripToken(value) {
|
|
|
71
71
|
* Mount the /plugin/mineru route tree.
|
|
72
72
|
* @param {object} ctx injected web context (webServer service available)
|
|
73
73
|
* @param {object} deps
|
|
74
|
-
* @param {object} deps.settings the settings service (describe)
|
|
75
|
-
* @param {object} deps.
|
|
74
|
+
* @param {object} deps.settings the settings service (describe/update)
|
|
75
|
+
* @param {() => object} deps.config reads the live entry config (volatile fields unwrapped)
|
|
76
|
+
* @param {string} deps.settingsNs the profile entry id the settings card is keyed by
|
|
76
77
|
* @param {object} deps.credentials the credentials service
|
|
77
78
|
* @param {object} deps.schema the registered schemastery schema
|
|
78
79
|
* @param {object} deps.state plugin state (clientFor, collectFacts, artifacts)
|
|
@@ -123,14 +124,30 @@ async function handle(req, res, deps) {
|
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
// DSH keys a plugin's settings card by its profile entry id, which the host
|
|
128
|
+
// half resolves and passes down; 'mineru' is only the fallback.
|
|
129
|
+
const settingsNs = typeof deps.settingsNs === 'string' && deps.settingsNs.length > 0 ? deps.settingsNs : 'mineru';
|
|
130
|
+
const descriptorOf = () => (deps.settings.describe({ redactSecrets: true }) ?? []).find((d) => d.ns === settingsNs);
|
|
131
|
+
|
|
126
132
|
if (route === '/' && method === 'GET') {
|
|
127
133
|
const facts = await deps.state.collectFacts();
|
|
128
134
|
sendJson(res, 200, { ok: true, health: facts, plugin: 'dsh-mineru' });
|
|
129
135
|
return;
|
|
130
136
|
}
|
|
131
137
|
if (route === '/config' && method === 'GET') {
|
|
132
|
-
const descriptor = (
|
|
133
|
-
|
|
138
|
+
const descriptor = descriptorOf();
|
|
139
|
+
if (descriptor === undefined) {
|
|
140
|
+
// The card is derived from CONFIG_SCHEMA: it is missing when the entry is
|
|
141
|
+
// not active, or when no field carries `meta.volatile`.
|
|
142
|
+
sendJson(res, 503, {
|
|
143
|
+
ok: false,
|
|
144
|
+
namespace: settingsNs,
|
|
145
|
+
error: 'settings namespace "' + settingsNs + '" is not registered',
|
|
146
|
+
hint: 'The host derives this card from the plugin\'s exported Config schema: the entry must be active and declare at least one `meta.volatile` field. '
|
|
147
|
+
+ 'Restart DSH after upgrading the plugin, and check that the profile entry id matches the namespace the card asks for.',
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
134
151
|
const facts = await deps.state.collectFacts();
|
|
135
152
|
sendJson(res, 200, {
|
|
136
153
|
ok: true,
|
|
@@ -162,8 +179,8 @@ async function handle(req, res, deps) {
|
|
|
162
179
|
const patch = body && typeof body.patch === 'object' && body.patch !== null ? body.patch : null;
|
|
163
180
|
if (!patch) { sendJson(res, 400, { ok: false, error: 'missing patch object' }); return; }
|
|
164
181
|
try {
|
|
165
|
-
await deps.settings.update(
|
|
166
|
-
const descriptor = (
|
|
182
|
+
await deps.settings.update(settingsNs, patch, Number.isInteger(body.expectedRevision) ? body.expectedRevision : undefined);
|
|
183
|
+
const descriptor = descriptorOf();
|
|
167
184
|
sendJson(res, 200, { ok: true, revision: descriptor?.revision ?? 0 });
|
|
168
185
|
} catch (err) {
|
|
169
186
|
if (err instanceof SettingsConflictError) {
|
|
@@ -178,7 +195,7 @@ async function handle(req, res, deps) {
|
|
|
178
195
|
const raw = await readBody(req);
|
|
179
196
|
let body;
|
|
180
197
|
try { body = JSON.parse(raw || '{}'); } catch { sendJson(res, 400, { ok: false, error: 'invalid JSON body' }); return; }
|
|
181
|
-
const cfg = deps.
|
|
198
|
+
const cfg = deps.config();
|
|
182
199
|
const refName = typeof body.ref === 'string' && /^[A-Za-z_][A-Za-z0-9_]*$/.test(body.ref) ? body.ref : cfg.tokenCredential;
|
|
183
200
|
let ref;
|
|
184
201
|
try {
|
|
@@ -229,7 +246,7 @@ async function handle(req, res, deps) {
|
|
|
229
246
|
* priority quota.
|
|
230
247
|
*/
|
|
231
248
|
async function testToken(deps) {
|
|
232
|
-
const cfg = deps.
|
|
249
|
+
const cfg = deps.config();
|
|
233
250
|
const client = await deps.state.clientFor(cfg);
|
|
234
251
|
if (!client.precisionEnabled()) {
|
|
235
252
|
return { status: 400, body: { ok: false, error: '未配置 MinerU Token: 请先在上方填写并保存 Token.' } };
|
|
@@ -279,7 +296,7 @@ async function testToken(deps) {
|
|
|
279
296
|
* Agent lightweight API. Reports success or the current IP rate-limit state.
|
|
280
297
|
*/
|
|
281
298
|
async function testAgent(deps) {
|
|
282
|
-
const cfg = deps.
|
|
299
|
+
const cfg = deps.config();
|
|
283
300
|
const client = await deps.state.clientFor(cfg);
|
|
284
301
|
const opts = {
|
|
285
302
|
language: cfg.language,
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* dsh-mineru host plugin: MinerU multimodal document parsing for DeepSeek
|
|
3
3
|
* Harness. Registers the mineru_activate bootstrap (or all tools under
|
|
4
|
-
* exposeMode: always), the mineru-tools skill, the "mineru" settings
|
|
5
|
-
*
|
|
6
|
-
* HTTP surface.
|
|
4
|
+
* exposeMode: always), the mineru-tools skill, the "mineru" settings card,
|
|
5
|
+
* credential resolution, and (Web profile) the /plugin/mineru HTTP surface.
|
|
7
6
|
* @module dsh-mineru
|
|
8
7
|
*/
|
|
9
8
|
import { createRequire } from 'node:module';
|
|
@@ -13,7 +12,7 @@ import { WorkspaceArtifactStore } from './artifacts.js';
|
|
|
13
12
|
import { mountHttp } from './http.js';
|
|
14
13
|
import { buildActivateTool, buildAgentTools } from './tools.js';
|
|
15
14
|
import { SKILL_CONTENT, SKILL_DESCRIPTION, SKILL_NAME } from './skill.js';
|
|
16
|
-
import { CONFIG_SCHEMA, DEFAULTS, resolveLoadConfig, validateConfig } from './config.js';
|
|
15
|
+
import { CONFIG_SCHEMA, DEFAULTS, plainConfig, resolveLoadConfig, validateConfig } from './config.js';
|
|
17
16
|
|
|
18
17
|
const require = createRequire(import.meta.url);
|
|
19
18
|
/** Plugin version read from the package manifest (single source of truth). */
|
|
@@ -26,17 +25,71 @@ export const inject = ['tools', 'skills', 'settings', 'credentials', 'agents'];
|
|
|
26
25
|
/** Entry config schema (validated by the Loader). */
|
|
27
26
|
export const Config = CONFIG_SCHEMA;
|
|
28
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the settings namespace the host keys this plugin's card by.
|
|
30
|
+
*
|
|
31
|
+
* DSH 2.x derives the card from the exported `Config` and reports it under the
|
|
32
|
+
* owning profile entry id, which is also the id `settings.update` writes to.
|
|
33
|
+
* The `/plugin/mineru` routes must therefore look the card up under that id
|
|
34
|
+
* rather than under the constant the installer happened to write.
|
|
35
|
+
* @param {object} ctx plugin context
|
|
36
|
+
* @returns {string} the profile entry id, or 'mineru' when it cannot be read
|
|
37
|
+
*/
|
|
38
|
+
export function settingsNamespace(ctx) {
|
|
39
|
+
try {
|
|
40
|
+
const id = ctx?.fiber?.entry?.options?.id;
|
|
41
|
+
if (typeof id === 'string' && id.length > 0) return id;
|
|
42
|
+
} catch {
|
|
43
|
+
// A fiber with no owning entry (or an unreadable computed id) falls back.
|
|
44
|
+
}
|
|
45
|
+
return 'mineru';
|
|
46
|
+
}
|
|
47
|
+
|
|
29
48
|
/**
|
|
30
49
|
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
31
|
-
* @param {object} [config] entry config (composition layer)
|
|
50
|
+
* @param {object} [config] entry config (composition layer); `meta.volatile`
|
|
51
|
+
* fields arrive as live references rather than plain values
|
|
32
52
|
*/
|
|
33
53
|
export function apply(ctx, config) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
54
|
+
// exposeMode is composition-scoped, so it is resolved once at load time from
|
|
55
|
+
// the values the entry actually carries right now.
|
|
56
|
+
const loadCfg = resolveLoadConfig(plainConfig(config));
|
|
57
|
+
|
|
58
|
+
// DSH 2.x removed `ctx.settings.register` (it throws `TypeError:
|
|
59
|
+
// ctx.settings.register is not a function` and aborts the whole activation);
|
|
60
|
+
// the card is derived from CONFIG_SCHEMA instead. What it needs is a volatile
|
|
61
|
+
// field in that schema plus a namespace equal to this entry's id.
|
|
62
|
+
//
|
|
63
|
+
// DSH 0.1.5 still ships `register`; keep using the legacy scope seam there so
|
|
64
|
+
// the settings card and persistence keep working for users who have not
|
|
65
|
+
// upgraded yet. Detect it behaviorally: DSH 2.x removed the method, and its
|
|
66
|
+
// regression stubs throw `TypeError` on call.
|
|
67
|
+
let configNow;
|
|
68
|
+
let settingsNs;
|
|
69
|
+
let scope = null;
|
|
70
|
+
if (typeof ctx.settings?.register === 'function') {
|
|
71
|
+
try {
|
|
72
|
+
scope = ctx.settings.register('mineru', CONFIG_SCHEMA, {
|
|
73
|
+
base: config,
|
|
74
|
+
applies: 'live',
|
|
75
|
+
validate: validateConfig,
|
|
76
|
+
});
|
|
77
|
+
} catch (err) {
|
|
78
|
+
if (!(err instanceof TypeError)) throw err;
|
|
79
|
+
scope = null; // 2.x-shaped service: fall through to the derived card.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (scope) {
|
|
83
|
+
// Legacy seam (DSH 0.1.5): the scope re-resolves schema defaults, the
|
|
84
|
+
// composition base and the stored user section.
|
|
85
|
+
configNow = () => scope.get();
|
|
86
|
+
settingsNs = 'mineru';
|
|
87
|
+
} else {
|
|
88
|
+
// DSH 2.x seam: every read re-projects the entry config, so a settings
|
|
89
|
+
// write reaches the next call without a restart.
|
|
90
|
+
configNow = () => ({ ...DEFAULTS, ...plainConfig(config) });
|
|
91
|
+
settingsNs = settingsNamespace(ctx);
|
|
92
|
+
}
|
|
40
93
|
|
|
41
94
|
/** @type {object} */
|
|
42
95
|
const state = {
|
|
@@ -55,7 +108,7 @@ export function apply(ctx, config) {
|
|
|
55
108
|
urlBuilder: null,
|
|
56
109
|
agentToolDefs: [],
|
|
57
110
|
getCfg() {
|
|
58
|
-
return
|
|
111
|
+
return configNow();
|
|
59
112
|
},
|
|
60
113
|
/**
|
|
61
114
|
* Build a MinerU client for one call: resolves the token per operation
|
|
@@ -79,7 +132,7 @@ export function apply(ctx, config) {
|
|
|
79
132
|
},
|
|
80
133
|
/** Non-secret facts for health surfaces (Web settings + activate). */
|
|
81
134
|
async collectFacts() {
|
|
82
|
-
const cfg =
|
|
135
|
+
const cfg = configNow();
|
|
83
136
|
const ref = credentialRef(cfg.tokenCredential);
|
|
84
137
|
const info = await ctx.credentials.describe(ref);
|
|
85
138
|
const tokenConfigured = Boolean(info?.configured);
|
|
@@ -124,7 +177,8 @@ export function apply(ctx, config) {
|
|
|
124
177
|
state.urlBuilder = (cwd, rel) => state.artifacts.capabilityUrl(cwd, rel);
|
|
125
178
|
mountHttp(webCtx, {
|
|
126
179
|
settings: ctx.settings,
|
|
127
|
-
|
|
180
|
+
config: configNow,
|
|
181
|
+
settingsNs,
|
|
128
182
|
credentials: ctx.credentials,
|
|
129
183
|
schema: CONFIG_SCHEMA,
|
|
130
184
|
state,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mineru",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "dsh-mineru: MinerU 文档解析插件 for DeepSeek Harness — 多模态全格式 (PDF/Word/PPT/Excel/HTML/图片) → 结构化 Markdown. 填 Token 走精准解析 API, 留空走 Agent 轻量解析 API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -35,11 +35,24 @@
|
|
|
35
35
|
"slots",
|
|
36
36
|
"connection",
|
|
37
37
|
"sessions",
|
|
38
|
-
"conversation"
|
|
38
|
+
"conversation",
|
|
39
|
+
"locale"
|
|
39
40
|
],
|
|
40
41
|
"platform": "web"
|
|
41
42
|
}
|
|
42
43
|
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"test": "vitest run"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@deepseek-ai/schemastery": "^3.18.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"vitest": "^3.2.0"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18.0.0"
|
|
55
|
+
},
|
|
43
56
|
"peerDependencies": {
|
|
44
57
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
45
58
|
"@deepseek-ai/schemastery": "^3.18.0",
|