dsh-pdf-mineru 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yurzi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # dsh-pdf-mineru
2
+
3
+ DSH MinerU 文档解析插件。模型通过统一工具接口使用自托管 MinerU v2 或 MinerU 官方云 v4;Provider 差异、上游任务 ID、预签名地址和 ZIP 结果不会暴露给模型。
4
+
5
+ ## 能力
6
+
7
+ - 自托管 v2:`GET /health`、multipart `POST /tasks`、任务轮询和 JSON 结果收集。
8
+ - 官方 v4:`POST /file-urls/batch`、裸 PUT 上传、`GET /extract-results/batch/{batch_id}`、安全 ZIP 收集。
9
+ - 会话 Job:每次提交创建独立 `job_id`,只能由创建它的 DSH Session 查询。
10
+ - 全局结果缓存:按源 SHA-256、规范解析语义、产物集合、Provider compatibility key 和 schema 版本寻址。
11
+ - 单进程请求合并:相同 CacheKey 只提交一次上游解析,每个会话仍保留独立 Job;单个等待者取消不取消 producer。
12
+ - 持久恢复:上游接受任务后立即持久化不含秘密的 ProviderJobRef,重启后可继续轮询和收集。
13
+ - staging、完整校验、原子 rename 发布、损坏缓存隔离和 storageRoot 进程锁。
14
+
15
+ 当前模型工具每次只接受一个文件。领域请求和 Provider 接口保留文件数组,以支持后续按文件缓存的批量 fan-out/fan-in。
16
+
17
+ ## 安装
18
+
19
+ ```sh
20
+ dsh plugin --profile web add dsh-pdf-mineru
21
+
22
+ # 本地 checkout
23
+ dsh plugin --profile web add link:/absolute/path/to/dsh-pdf-mineru
24
+ ```
25
+
26
+ 从 git 安装且使用 pnpm 10+ 时,在 profile 的 `pnpm-workspace.yaml` 允许该包的构建脚本。
27
+
28
+ ## 配置
29
+
30
+ 配置通过 DSH Settings 的 `dsh-pdf-mineru` namespace 持久化。`cordis.patch.yml` 只提供首次启动默认值。API Token 只保存于 DSH credentials 或环境变量中,配置仅保存 credential reference。
31
+
32
+ ### 自托管 v2
33
+
34
+ ```yaml
35
+ schemaVersion: 1
36
+ activeProvider: mp_self_hosted
37
+ providers:
38
+ - id: mp_self_hosted
39
+ type: self-hosted-v2
40
+ baseURL: http://localhost:18000
41
+ apiKeyEnv: MINERU_API_KEY
42
+ allowInsecureHttp: true
43
+ modelMap:
44
+ pipeline: pipeline
45
+ vlm: vlm-engine
46
+ defaults:
47
+ model: pipeline
48
+ ocr: false
49
+ parseMethod: auto
50
+ language: ch
51
+ formula: true
52
+ table: true
53
+ artifacts: [markdown]
54
+ ```
55
+
56
+ `modelMap` 是显式映射。`hybrid-engine` 等值可以配置为统一 `vlm` 的后端,但 Service 不会猜测或静默降级。HTTP 只允许在自托管配置显式启用 `allowInsecureHttp` 时使用。
57
+
58
+ ### 官方 v4
59
+
60
+ ```yaml
61
+ schemaVersion: 1
62
+ activeProvider: mp_official
63
+ providers:
64
+ - id: mp_official
65
+ type: official-v4
66
+ baseURL: https://mineru.net/api/v4
67
+ apiKeyEnv: MINERU_API_KEY
68
+ models: [pipeline, vlm]
69
+ configuredVersion: v4
70
+ defaults:
71
+ model: vlm
72
+ ocr: false
73
+ parseMethod: auto
74
+ language: ch
75
+ formula: true
76
+ table: true
77
+ artifacts: [markdown]
78
+ ```
79
+
80
+ 官方 v4 当前限制为单文件不超过 200 MB、200 页。官方 Provider 不支持自托管专用的 `parseMethod: txt`,配置或请求会明确失败。
81
+
82
+ ### 存储与限制
83
+
84
+ 默认 storageRoot 为 `$DSH_HOME/dsh-pdf-mineru/v1`,布局如下:
85
+
86
+ ```text
87
+ jobs/<session-id>/<job-id>.json
88
+ results/sha256/<prefix>/<cache-key>/manifest.json
89
+ staging/<operation-id>/
90
+ quarantine/<timestamp_reason_id>/
91
+ .process.lock
92
+ ```
93
+
94
+ 首次版本明确限制一个 storageRoot 只能由一个 DSH 进程使用。修改 `storageRoot` 后需重启;Provider、默认参数、轮询和输出限制对新任务热生效。
95
+
96
+ 可配置限制包括源文件大小、API 响应大小、ZIP 下载大小、entry 数、单 entry 解压字节、总解压字节和压缩比。
97
+
98
+ ## 模型工具
99
+
100
+ 所有工具都要求 `exec.agent.session`。模型只看到插件 `job_id`,不会看到上游 `task_id`、`batch_id`、上传 URL、CDN URL 或状态 URL。
101
+
102
+ - `mineru_health`:探测当前 Provider 的连通性、鉴权和协议版本。
103
+ - `mineru_submit_parse_job`:创建会话 Job,返回 `source: cache | shared-operation | provider`。
104
+ - `mineru_get_parse_status`:返回统一 Job 状态和逐文件状态。
105
+ - `mineru_get_parse_result`:返回受限 Markdown preview、manifest 路径和产物路径。
106
+ - `mineru_parse_document`:submit、等待、result 的组合工具;等待超时保留 Job,可稍后继续查询。
107
+
108
+ 新参数为 `file_paths/model/ocr/language/formula/table/pages/artifacts`。旧 `file_path/backend/parse_method/lang_list/formula_enable/table_enable/return_*/start_page_id/end_page_id` 在当前 major 版本保留为 deprecated alias,进入 Service 前立即规范化。`task_id` 仅作为 `job_id` 的过渡别名,不接受真实上游 ID。
109
+
110
+ ## 官方 v4 安全边界
111
+
112
+ - MinerU API 请求使用 Bearer Token、JSON 和 `redirect: error`。
113
+ - 预签名 PUT 使用独立请求构造器,headers 严格为空:无 Authorization、Content-Type 或默认头。
114
+ - CDN ZIP 下载不携带 API Token,并禁止重定向。
115
+ - HTTP 200 但 `code != 0` 仍失败,保留脱敏 `providerCode` 和 `traceId`。
116
+ - 状态和结果只按插件生成的 `data_id` 关联,不信任 `file_name`。
117
+ - 重复 `full_zip_url` 只下载一次。
118
+ - ZIP 拒绝绝对路径、`..`、NUL、反斜杠/驱动器路径、符号链接、非普通条目和加密条目。
119
+ - ZIP 中央目录先扫描限制,随后逐 entry 流式进入 staging;不会把整个归档解压到内存。
120
+
121
+ ## 开发与验证
122
+
123
+ ```sh
124
+ pnpm install
125
+ pnpm run typecheck
126
+ pnpm test
127
+ pnpm run build
128
+ git diff --check
129
+
130
+ # 在已运行的 DSH Web shell 中隔离加载当前 client bundle
131
+ node scripts/verify-current-gui.mjs
132
+ ```
133
+
134
+ 测试默认使用 mock HTTP 和本地 ZIP fixture,不需要真实 Token。真实官方/自托管 e2e 应显式 opt-in,不能作为本地完成条件。
135
+
136
+ ## 许可证
137
+
138
+ 本项目使用 [MIT License](./LICENSE) 开源。
139
+
140
+ ## 致谢
141
+
142
+ 感谢 [Huanlin/dsh-plugin-mineru](https://github.com/HuanLinOTO/dsh-plugin-mineru) 提供灵感。
@@ -0,0 +1,26 @@
1
+ # dsh-pdf-mineru bundle layer. Values below are first-boot composition defaults;
2
+ # later edits persist through the DSH settings service.
3
+ - insert:
4
+ - id: dsh-pdf-mineru
5
+ name: 'dsh-pdf-mineru'
6
+ config:
7
+ schemaVersion: 1
8
+ activeProvider: mp_self_hosted
9
+ providers:
10
+ - id: mp_self_hosted
11
+ type: self-hosted-v2
12
+ baseURL: 'http://localhost:18000'
13
+ apiKeyEnv: MINERU_API_KEY
14
+ allowInsecureHttp: true
15
+ modelMap:
16
+ pipeline: pipeline
17
+ vlm: vlm-engine
18
+ defaults:
19
+ model: pipeline
20
+ ocr: false
21
+ parseMethod: auto
22
+ language: ch
23
+ formula: true
24
+ table: true
25
+ artifacts:
26
+ - markdown