dsh-pdf-mineru 0.0.7 → 0.0.8

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 CHANGED
@@ -1,10 +1,28 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.0.8
4
4
 
5
- ### Fixed
5
+ ### Changed
6
6
 
7
- - Recover stale Windows `.process.lock` files safely after abnormal DSH exits using named pipe serialization and fail-closed PID liveness verification.
7
+ - Refactored model tool surface to decoupled, specialized single-document tools: `read_pdf` (synchronous reading with page slicing via `pages`, content focus filtering via `focus`, and reading-order multimodal figure inlining) and `async_parse_pdf` (native background parsing with document structure summary).
8
+ - Enforced single `file_path` across tools, pipeline, Zod schema, and SettingsPage, removing multi-file parameters (`file_paths`) and `maxFilesPerRequest` limit while preserving underlying provider batch primitives.
9
+ - Completely decoupled proprietary MinerU parameters (`model`, `ocr`, `formula`, `table`, `language`, `artifacts`, `max_inline_images`) from tool arguments; always request all artifacts from providers for permanent local caching.
10
+ - Replaced markdown preview fields with full `markdown_content` and authoritative `content_status` (`complete`, `partial`, `not_requested`), featuring fair character budget allocation, clean paragraph-boundary truncation, and resume line offsets for partial deliveries.
11
+ - Enhanced `pages` parsing to flexibly accept single numbers, number arrays, and range strings (e.g. `"1-3, 5"`); added `focus` filtering based on cached `content_list.json` with graceful fallback to Markdown.
12
+ - Strictly ordered inline images by natural document reading order, linked to page selection, bound markdown captions, and eliminated rigid image quotas.
13
+ - Re-architected model output and tool descriptions to strict Plain Text English with zero emoji, eliminating hallucinated guidance references to deprecated fields.
14
+ - Decoupled document presentation, outline (TOC) extraction, character budget allocation, and prose formatting from `MinerUService` into dedicated `src/service/result-presenter.ts`.
15
+ - Consolidated shared HTTP request pipelines, timeout management, error body diagnostics, and retry policies into `src/providers/http-client.ts`, eliminating duplicate logic across official and self-hosted providers.
16
+ - Upgraded `self-hosted-v2` multipart streaming to Node 22 native `FormData` and `openAsBlob`, removing third-party `form-data` package dependency.
17
+ - Replaced hand-rolled streaming JSON parser in `safe-zip` with standard V8 `JSON.parse`, and standardized delay timers across all modules using `node:timers/promises`.
18
+ - Adopted scoped locking (`withLock`) across mutating storage operations (`clearCache`, `commitTransaction`, `quarantine`) with contention backoff, eliminating startup lifetime lock holding to allow concurrent multi-process initialization.
19
+ - Eliminated self-inflicted read-only (`0o400`/`0o500`) permission cycles in `result-repository`, streamlining cache cleanup and quarantine deletions.
20
+ - Modernized single-process storage lock (`ProcessLock`) to use atomic file creation (`flag: 'wx'`) with cross-platform dead PID reclamation, retiring abstract Unix sockets and Windows named pipes.
21
+
22
+ ### Removed
23
+
24
+ - Removed `mineru_health` from the model-facing tool surface, keeping it strictly as an internal loopback RPC probe for the Web GUI.
25
+ - Removed obsolete batch coordination (`batch-coordinator.ts`, `batchViewSchema`) in favor of unified `ResultView`.
8
26
 
9
27
  ## 0.0.7
10
28
 
package/README.md CHANGED
@@ -85,44 +85,45 @@ Agent 会自动根据文档长度和指令意图,智能选择同步返回或
85
85
 
86
86
  ### 场景 1:常规论文 / 报告解析
87
87
  > **你**:“帮我解析 `/workspace/paper.pdf`,提取正文、数学公式和表格,整理成 Markdown 格式。”
88
- > **Agent**:调用 `mineru_parse_document`,直接返回排版好的 Markdown 文本与产物清单。
88
+ > **Agent**:调用 `read_pdf`,直接返回排版好的 Markdown 文本与关键内联图表。
89
89
 
90
- ### 场景 2:超长文档后台异步解析(推荐)
90
+ ### 场景 2:超长文档后台全量解析(推荐)
91
91
  > **你**:“请在后台解析这本 120 页的技术研报 `/data/annual-report.pdf`,解析完成后告诉我。”
92
- > **Agent**:提交 `mineru_submit_parse_job` 并返回任务 ID(如 `mineru-1`),随后可在后台静默运行,完成后自动读取结果并向您汇报。
92
+ > **Agent**:提交 `async_parse_pdf` 并返回任务 ID(如 `mineru-1`),全量解析到本地缓存,完成后返回文档结构化摘要(页数、大纲、表格数、图片数等),并提示使用 `read_pdf` 按需读取。
93
93
 
94
- ### 场景 3:指定页码与扫描件 OCR
95
- > **你**:“解析 `/data/scanned_doc.pdf` 的第 1 到 5 页,这个是扫描件,请开启强制 OCR 模式。”
96
- > **Agent**:传入 `pages: "1-5"` 与 `ocr: true` 进行精准定向识别。
97
-
98
- ### 场景 4:检查服务状态
99
- > **你**:“检查一下当前 MinerU 服务的连接状态和剩余队列。”
100
- > **Agent**:调用 `mineru_health`,回报服务连通性、鉴权状态与排队情况。
101
-
102
- ---
94
+ ### 场景 3:按需切片读取(指定页码与关注内容)
95
+ > **你**:“读取 `/data/report.pdf` 的第 1 到 5 页中的表格。”
96
+ > **Agent**:调用 `read_pdf` 并传入 `pages: "1-5"` 与 `focus: "table"` 进行精准定向提取。
103
97
 
104
98
  ## ⚙️ 模型工具与参数参考
105
99
 
106
- 插件为 Agent 注册了三项核心工具:
100
+ 插件为 Agent 注册了两项核心文档解析工具:
107
101
 
108
102
  | 工具名称 | 适用场景 | 说明 |
109
103
  | --- | --- | --- |
110
- | `mineru_parse_document` | 短篇文档 / 同步等待 | 同步解析文档,直接返回 Markdown 预览、产物清单与存储路径 |
111
- | `mineru_submit_parse_job` | 长篇文档 / 批量解析 | 注册为 DSH 原生后台任务(`mineru-N`),不阻塞当前对话 |
112
- | `mineru_health` | 状态诊断 | 检查 MinerU 服务连通性、鉴权有效性及协议版本 |
104
+ | `read_pdf` | 同步读取 / 按需切片 | 同步读取 PDF,支持指定页码(`pages`)与内容类型(`focus`)切片提取,返回 Markdown 文本与按自然顺序排列的内联多模态图表 |
105
+ | `async_parse_pdf` | 长篇文档 / 后台解析 | 注册为 DSH 原生后台任务(`mineru-N`),全量解析 PDF 至本地缓存,完成后交付文档结构化摘要与后续阅读指引,不阻塞当前对话 |
106
+
107
+ ### 核心交付字段与正文状态说明
108
+
109
+ 调用 `read_pdf` 或后台任务 `async_parse_pdf` 完成后,交付结果包含可靠的正文与完整性判定:
110
+
111
+ - `markdown_content`:提取的正文 Markdown 文本。
112
+ - `content_status`:正文交付状态:
113
+ - `complete`:本次请求所选页面的提取 Markdown 已完整提供,可直接用于回答,无需重复读取正文文件。
114
+ - `partial`:提取正文存在但因输出预算截断,提供可读取的完整正文文件路径 (`markdown_path`) 及续读起始行号 (`read_offset_line`),明确区分正文文件与结果清单 (`manifest_path`)。
115
+ - `not_requested`:本次请求未包含 `markdown` 产物。
116
+ - `output.maxInlineChars`:单次响应的整次字符预算(默认 200,000 字符),优先保障元信息与正文展示。
113
117
 
114
118
  ### 常用解析参数(均可通过自然语言告知 Agent)
115
119
 
116
- | 参数 | 类型 | 默认值 | 作用说明 |
120
+ | 参数 | 类型 | 适用工具 | 作用说明 |
117
121
  | --- | --- | --- | --- |
118
- | `file_paths` | `string[]` | 必填 | 待解析的本地文件绝对路径(支持单个或批量) |
119
- | `model` | `pipeline` / `vlm` | `pipeline` | 解析引擎类型:`pipeline`(快速高效)或 `vlm`(视觉大模型,复杂图文理解更强) |
120
- | `ocr` | `boolean` | `false` | 是否对所有页面强制开启 OCR(适合纯图片型或扫描版 PDF) |
121
- | `formula` | `boolean` | `true` | 是否提取数学公式并转换为 LaTeX 代码 |
122
- | `table` | `boolean` | `true` | 是否提取表格结构 |
123
- | `pages` | `string` | 全部 | 1-based 页码范围,例如 `"1-10,15"` |
124
- | `language` | `string` | `"ch"` | 语言提示代码(如 `ch` 中文、`en` 英文等) |
125
- | `artifacts` | `string[]` | `["markdown"]` | 需要提取保留的产物类型:`markdown`、`images`、`layout`、`content-list` |
122
+ | `file_path` | `string` | 全部 | 待解析/读取的本地文件路径(必填) |
123
+ | `pages` | `number` / `string` / `number[]` | `read_pdf` | 1-based 页码选择,支持单页(如 `3`)、数组(如 `[1, 2, 5]`)或范围字符串(如 `"1-3, 5"`) |
124
+ | `focus` | `string` / `string[]` | `read_pdf` | 关注内容类型:`all`(默认全部)、`text`(正文代码公式)、`table`(表格与表题)、`image`(图表与图题) |
125
+ | `inline_images` | `boolean` | `read_pdf` | 是否直接内联多模态图表(模型路由支持图片时默认开启) |
126
+ | `poll_timeout_ms` | `number` | `read_pdf` | 最大同步等待超时毫秒数 |
126
127
 
127
128
  ---
128
129
 
@@ -130,14 +131,12 @@ Agent 会自动根据文档长度和指令意图,智能选择同步返回或
130
131
 
131
132
  ```mermaid
132
133
  flowchart LR
133
- Agent[DSH Agent] --> Health[mineru_health]
134
- Agent --> Sync[mineru_parse_document]
135
- Agent --> Async[mineru_submit_parse_job]
134
+ Agent[DSH Agent] --> Sync[read_pdf]
135
+ Agent --> Async[async_parse_pdf]
136
136
 
137
137
  Async --> Jobs[DSH JobRegistry]
138
138
  Jobs --> Service[MinerUService]
139
139
  Sync --> Service
140
- Health --> Providers[ProviderRegistry]
141
140
 
142
141
  Service --> Cache{Result cache}
143
142
  Cache -->|hit| Result[Immutable result]
@@ -151,7 +150,7 @@ flowchart LR
151
150
  Publish --> Result
152
151
  ```
153
152
 
154
- - **统一工具分发**:Agent 发起的同步请求(`mineru_parse_document`)直接返回结果,异步长任务(`mineru_submit_parse_job`)交由 DSH 原生 JobRegistry 调度。
153
+ - **统一工具分发**:Agent 发起的同步请求(`read_pdf`)直接返回结果,异步长任务(`async_parse_pdf`)交由 DSH 原生 JobRegistry 调度。
155
154
  - **智能缓存命中**:每次解析计算文件 SHA-256 与参数指纹,若命中缓存则秒级返回不可变产物。
156
155
  - **并发请求合并**:同进程内的并发重复请求由 `SharedOperationRegistry` 合并,避免重复向上游提交。
157
156
  - **双 Provider 适配**:上游适配自建 FastAPI v2 或官方云 v4,解析产物经校验后原子发布。
@@ -191,7 +190,6 @@ defaults:
191
190
  ocr: false
192
191
  formula: true
193
192
  table: true
194
- artifacts: [markdown]
195
193
  ```
196
194
 
197
195
  ### 2. 本地私有化 (Self-hosted v2) 推荐配置
@@ -211,7 +209,6 @@ defaults:
211
209
  ocr: false
212
210
  formula: true
213
211
  table: true
214
- artifacts: [markdown]
215
212
  ```
216
213
 
217
214
  ### 3. 存储与限制自定义(可选)
@@ -219,8 +216,9 @@ defaults:
219
216
  storage:
220
217
  storageRoot: /absolute/path/to/dsh/cache/pdf-mineru # 默认在 $DSH_HOME/cache/pdf-mineru
221
218
  cacheEnabled: true
219
+ output:
220
+ maxInlineChars: 200000 # 单次响应最大内联字符预算(UTF-16 字符)
222
221
  limits:
223
- maxFilesPerRequest: 1
224
222
  maxFileBytes: 209715200 # 200 MB
225
223
  ```
226
224
 
package/lib/client.js CHANGED
@@ -486,13 +486,6 @@ window.__ModuleLoader__.load({
486
486
  }
487
487
  //#endregion
488
488
  //#region src/client/SettingsPage.tsx
489
- const ALL_ARTIFACT_KINDS = [
490
- "markdown",
491
- "layout",
492
- "model-output",
493
- "content-list",
494
- "images"
495
- ];
496
489
  const PROVIDER_TYPES = ["self-hosted-v2", "official-v4"];
497
490
  function ensureProviderProfiles(config) {
498
491
  const providers = [...config.providers];
@@ -735,15 +728,6 @@ window.__ModuleLoader__.load({
735
728
  const credentialLocked = credentialView?.writable === false;
736
729
  const credentialInputDisabled = saving || credentialBusy || activeCredentialRef === void 0 || !credentialStateReady || credentialLocked;
737
730
  const credentialPlaceholder = credentialView?.configured === true ? t("credential.placeholderStored") : t("credential.placeholderEmpty");
738
- const toggleArtifact = (kind) => {
739
- const current = draft.defaults.artifacts;
740
- let next;
741
- if (current.includes(kind)) {
742
- if (kind === "markdown") return;
743
- next = current.filter((k) => k !== kind);
744
- } else next = [...current, kind];
745
- setDraft((prev) => prev === null ? prev : updateConfigSection(prev, "defaults", { artifacts: next }));
746
- };
747
731
  const toggleOfficialModel = (model) => {
748
732
  if (activeProvider.type !== "official-v4") return;
749
733
  const current = activeProvider.models;
@@ -1162,24 +1146,6 @@ window.__ModuleLoader__.load({
1162
1146
  children: t("field.defaultTable")
1163
1147
  })]
1164
1148
  })]
1165
- }),
1166
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1167
- className: classMap.field,
1168
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1169
- className: classMap.fieldLabel,
1170
- children: t("field.defaultArtifacts")
1171
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1172
- className: classMap.checkboxGroup,
1173
- children: ALL_ARTIFACT_KINDS.map((kind) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1174
- className: classMap.checkboxOption,
1175
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1176
- type: "checkbox",
1177
- checked: draft.defaults.artifacts.includes(kind),
1178
- disabled: kind === "markdown",
1179
- onChange: () => toggleArtifact(kind)
1180
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(`artifact.${kind}`) })]
1181
- }, kind))
1182
- })]
1183
1149
  })
1184
1150
  ]
1185
1151
  }),
@@ -1379,20 +1345,9 @@ window.__ModuleLoader__.load({
1379
1345
  className: classMap.groupTitle,
1380
1346
  children: t("section.limits")
1381
1347
  }),
1382
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1348
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1383
1349
  className: classMap.row,
1384
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1385
- className: classMap.field,
1386
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1387
- className: classMap.fieldLabel,
1388
- children: t("field.maxFilesPerRequest")
1389
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1390
- className: classMap.input,
1391
- type: "number",
1392
- value: draft.limits.maxFilesPerRequest,
1393
- onChange: (e) => setDraft((prev) => prev === null ? prev : updateConfigSection(prev, "limits", { maxFilesPerRequest: Number(e.target.value) }))
1394
- })]
1395
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1350
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1396
1351
  className: classMap.field,
1397
1352
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1398
1353
  className: classMap.fieldLabel,
@@ -1403,7 +1358,7 @@ window.__ModuleLoader__.load({
1403
1358
  value: draft.limits.maxFileBytes,
1404
1359
  onChange: (e) => setDraft((prev) => prev === null ? prev : updateConfigSection(prev, "limits", { maxFileBytes: Number(e.target.value) }))
1405
1360
  })]
1406
- })]
1361
+ })
1407
1362
  }),
1408
1363
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1409
1364
  className: classMap.row,
@@ -1530,7 +1485,6 @@ window.__ModuleLoader__.load({
1530
1485
  "field.defaultLang": "Default Language",
1531
1486
  "field.defaultFormula": "Enable Formula Extraction",
1532
1487
  "field.defaultTable": "Enable Table Extraction",
1533
- "field.defaultArtifacts": "Default Required Artifacts",
1534
1488
  "field.storageRoot": "Storage Root Directory",
1535
1489
  "field.cacheEnabled": "Enable Global Cache",
1536
1490
  "field.stagingTtlMs": "Staging Cleanup TTL (ms)",
@@ -1542,7 +1496,6 @@ window.__ModuleLoader__.load({
1542
1496
  "field.retryBaseDelayMs": "Base Retry Delay (ms)",
1543
1497
  "field.retryMaxDelayMs": "Maximum Retry Delay (ms)",
1544
1498
  "field.maxInlineChars": "Max Inline Markdown Chars",
1545
- "field.maxFilesPerRequest": "Max Files Per Request",
1546
1499
  "field.maxFileBytes": "Max File Bytes",
1547
1500
  "field.maxApiResponseBytes": "Max API Response Bytes",
1548
1501
  "field.maxZipDownloadBytes": "Max ZIP Download Bytes",
@@ -1648,7 +1601,6 @@ window.__ModuleLoader__.load({
1648
1601
  "field.defaultLang": "默认语言",
1649
1602
  "field.defaultFormula": "开启公式解析",
1650
1603
  "field.defaultTable": "开启表格解析",
1651
- "field.defaultArtifacts": "默认必要产物",
1652
1604
  "field.storageRoot": "持久存储根目录",
1653
1605
  "field.cacheEnabled": "启用全局内容寻址缓存",
1654
1606
  "field.stagingTtlMs": "Staging 暂存清理 TTL (ms)",
@@ -1659,8 +1611,7 @@ window.__ModuleLoader__.load({
1659
1611
  "field.retryMaxAttempts": "最大尝试次数",
1660
1612
  "field.retryBaseDelayMs": "基础重试延迟 (ms)",
1661
1613
  "field.retryMaxDelayMs": "最大重试延迟 (ms)",
1662
- "field.maxInlineChars": "Markdown 预览字符上限",
1663
- "field.maxFilesPerRequest": "单次请求最大文件数",
1614
+ "field.maxInlineChars": "Markdown 内联字符上限",
1664
1615
  "field.maxFileBytes": "单个源文件大小上限 (bytes)",
1665
1616
  "field.maxApiResponseBytes": "API 响应体大小上限 (bytes)",
1666
1617
  "field.maxZipDownloadBytes": "ZIP 下载包大小上限 (bytes)",