dsh-mineru 0.1.15 → 0.1.17
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 +17 -0
- package/README.md +5 -1
- package/README.zh.md +5 -1
- package/lib/client.js +33 -0
- package/lib/dns-resolve.js +135 -0
- package/lib/mineru-client.js +125 -4
- package/package.json +101 -101
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to **dsh-mineru** are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/), and versioning follows [Semantic Versioning](https://semver.org/lang/zh-CN/). 版本号唯一来源是 `package.json`。
|
|
4
4
|
|
|
5
|
+
## [0.1.17] - 2026-11-11
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- The MinerU settings panel could be unreachable: the client only registered a `settings.plugins.tab` contribution, and a deployment whose composition ships no Plugins settings section never renders that slot, so the tab was dropped silently and Settings showed no MinerU entry at all. The panel now also registers a standalone `settings.section` (with a `settings.section.icon`), which every settings dialog renders; the tab registration stays for deployments that do have the Plugins section.
|
|
10
|
+
|
|
11
|
+
## [0.1.16] - 2026-11-11
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Result downloads no longer die on a hijacked result CDN. Campus/ISP DNS can answer `cdn-mineru.openxlab.org.cn` with a loopback address (`127.0.0.1` / `::1`), which turned the whole parse into `MinerU 结果下载失败:fetch failed` even though the batch had already run and been billed. `lib/dns-resolve.js` now builds a `lookup` callback that keeps trusting the system resolver whenever it returns a usable address and only falls back to public resolvers (`223.5.5.5`, `119.29.29.29`, UDP 53, 10-minute per-host cache) when every answer is loopback. The download path stays on `fetch` first and only switches to `node:http(s)` with that lookup when the transport itself fails, so injected test doubles and proxies still behave.
|
|
16
|
+
- The fallback resolver speaks the promise API (`node:dns/promises`). Importing the callback `Resolver` from `node:dns` threw `ERR_INVALID_ARG_TYPE` on the first real query — every mocked test passed, and only a live download exposed it.
|
|
17
|
+
|
|
18
|
+
### Tests
|
|
19
|
+
|
|
20
|
+
- `tests/dns-resolve.spec.js` (9 cases): loopback classification, usable system answers short-circuiting the fallback, hijacked answers falling back, per-host caching, `all: true` array shape, `family` filtering, and error passthrough when both resolvers fail.
|
|
21
|
+
|
|
5
22
|
## [0.1.15] - 2026-10-24
|
|
6
23
|
|
|
7
24
|
### Fixed
|
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
|
|
|
@@ -429,6 +429,7 @@ Plugin behavior:
|
|
|
429
429
|
| `MINERU_TOKEN_REQUIRED` | Token-required operation without a token | Configure a token or use Agent mode |
|
|
430
430
|
| `MINERU_UNSUPPORTED_TYPE` | Format unsupported by the current API | Switch format or API mode |
|
|
431
431
|
| `MINERU_BATCH_TOO_LARGE` | Batch exceeds 1000 items | Split into multiple calls |
|
|
432
|
+
| `MINERU_DOWNLOAD_FAILED` | The result zip could not be downloaded (HTTP error or transport failure) | Check that the result CDN resolves to a real address — see the DNS question in the FAQ; 0.1.16+ falls back to public resolvers automatically |
|
|
432
433
|
|
|
433
434
|
Every error is mapped to an **actionable message** instead of a raw code.
|
|
434
435
|
|
|
@@ -461,6 +462,9 @@ Yes. It falls back to the tokenless Agent API (≤ 10 MB, ≤ 20 pages, Markdown
|
|
|
461
462
|
**Q: Why is only `mineru_activate` in my tool list?**
|
|
462
463
|
That is progressive exposure by design. Call `mineru_activate` once and the other three tools unlock; or set `exposeMode: always` to register everything globally.
|
|
463
464
|
|
|
465
|
+
**Q: A parse fails with `MINERU_DOWNLOAD_FAILED` / `fetch failed`, but the batch obviously ran?**
|
|
466
|
+
Look up `cdn-mineru.openxlab.org.cn` on that machine. Some campus and ISP resolvers answer public CDN hosts with a loopback address; the upload and the batch then succeed, and only the result download dies. Since 0.1.16 the download path keeps using the system resolver while it returns a usable address and falls back to public resolvers (`223.5.5.5`, `119.29.29.29`) only when every answer is loopback — no hosts edit, no proxy. Already-submitted batches are reused, so collecting the result again costs no extra quota.
|
|
467
|
+
|
|
464
468
|
**Q: My parse timed out — is the file lost?**
|
|
465
469
|
No. The task keeps running on MinerU's servers; use `mineru_task` (`taskId` + `api`) anytime to query progress and collect the result without resubmitting.
|
|
466
470
|
|
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
|
|
|
@@ -401,6 +401,7 @@ Token 每次操作实时解析——**轮换后下一次调用立即生效,无
|
|
|
401
401
|
| `MINERU_TOKEN_REQUIRED` | 需要 Token 的操作未配 Token | 配置 Token 或改用 Agent 模式 |
|
|
402
402
|
| `MINERU_UNSUPPORTED_TYPE` | 该格式不被当前 API 支持 | 换格式或换 API 模式 |
|
|
403
403
|
| `MINERU_BATCH_TOO_LARGE` | 单次批量超过 1000 个 | 拆分后多次调用 |
|
|
404
|
+
| `MINERU_DOWNLOAD_FAILED` | 结果 zip 下载失败(HTTP 错误或传输层失败) | 先查结果 CDN 是否解析到真实地址(见 FAQ「下载失败」一条);0.1.16 起会自动回退公网解析 |
|
|
404
405
|
|
|
405
406
|
所有错误都会映射为**可操作的中文提示**,而不是原始错误码。
|
|
406
407
|
|
|
@@ -433,6 +434,9 @@ Token 每次操作实时解析——**轮换后下一次调用立即生效,无
|
|
|
433
434
|
**Q:为什么工具列表里只有 `mineru_activate`?**
|
|
434
435
|
这是渐进式曝光设计。调用一次 `mineru_activate`,其余三个工具立即解锁;或者把配置项 `exposeMode` 改为 `always` 全局注册。
|
|
435
436
|
|
|
437
|
+
**Q:解析报 `MINERU_DOWNLOAD_FAILED` / `fetch failed`,但批次明明是成功的?**
|
|
438
|
+
先在这台机器上查一下 `cdn-mineru.openxlab.org.cn` 的解析结果。部分校园网/运营商 DNS 会把结果 CDN 应答成回环地址(`127.0.0.1` / `::1`):上传与建批都正常,只有最后下载结果 zip 必挂。0.1.16 起下载走「系统解析只要给出可用地址就用系统结果,全部是回环才回退公网解析(`223.5.5.5`、`119.29.29.29`)」的兜底,不需要改 hosts、不需要代理。已经提交过的批次会被复用,重新收集结果不额外扣额度。
|
|
439
|
+
|
|
436
440
|
**Q:解析超时了,文件会不会丢?**
|
|
437
441
|
不会。任务在 MinerU 服务端继续执行,用 `mineru_task`(`taskId` + `api`)随时查询进度并收集结果,无需重新提交。
|
|
438
442
|
|
package/lib/client.js
CHANGED
|
@@ -26,6 +26,7 @@ window.__ModuleLoader__.load({
|
|
|
26
26
|
"settings.retry": "重试",
|
|
27
27
|
"settings.loadFail": "加载配置失败: {err}",
|
|
28
28
|
"settings.title": "MinerU 文档解析",
|
|
29
|
+
"settings.nav": "MinerU 解析",
|
|
29
30
|
"badge.tokenOk": "Token 已配置",
|
|
30
31
|
"badge.tokenMissing": "未配置 Token",
|
|
31
32
|
"badge.current": "当前: {api}",
|
|
@@ -122,6 +123,7 @@ window.__ModuleLoader__.load({
|
|
|
122
123
|
"settings.retry": "Retry",
|
|
123
124
|
"settings.loadFail": "Failed to load settings: {err}",
|
|
124
125
|
"settings.title": "MinerU Document Parsing",
|
|
126
|
+
"settings.nav": "MinerU",
|
|
125
127
|
"badge.tokenOk": "Token configured",
|
|
126
128
|
"badge.tokenMissing": "No token",
|
|
127
129
|
"badge.current": "Current: {api}",
|
|
@@ -789,6 +791,37 @@ window.__ModuleLoader__.load({
|
|
|
789
791
|
} catch (e) { /* locale service unavailable: zh fallback stays */ }
|
|
790
792
|
}
|
|
791
793
|
|
|
794
|
+
// A deployment whose composition ships no Plugins settings section
|
|
795
|
+
// never renders `settings.plugins.tab`, so the registration below is
|
|
796
|
+
// silently dropped there. `settings.section` is the surface every
|
|
797
|
+
// settings dialog renders, so the panel gets a standalone entry of its
|
|
798
|
+
// own; the tab registration stays for deployments that do have the
|
|
799
|
+
// Plugins section.
|
|
800
|
+
ctx.slots.inject("settings.section.icon", () => ctx.slots.register({
|
|
801
|
+
name: "settings.section.icon",
|
|
802
|
+
id: "mineru",
|
|
803
|
+
order: 30,
|
|
804
|
+
label: () => T("settings.nav"),
|
|
805
|
+
}, ({ size }) => jsx("svg", {
|
|
806
|
+
width: size || 16,
|
|
807
|
+
height: size || 16,
|
|
808
|
+
viewBox: "0 0 24 24",
|
|
809
|
+
fill: "none",
|
|
810
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
811
|
+
children: [
|
|
812
|
+
jsx("path", { d: "M7 3h7l4 4v14H7z", stroke: "currentColor", strokeWidth: "1.7", strokeLinejoin: "round" }),
|
|
813
|
+
jsx("path", { d: "M14 3v4h4", stroke: "currentColor", strokeWidth: "1.7", strokeLinejoin: "round" }),
|
|
814
|
+
jsx("path", { d: "M9.5 13h5M9.5 17h5", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round" }),
|
|
815
|
+
],
|
|
816
|
+
})));
|
|
817
|
+
|
|
818
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
819
|
+
name: "settings.section",
|
|
820
|
+
id: "mineru",
|
|
821
|
+
order: 30,
|
|
822
|
+
label: () => T("settings.nav"),
|
|
823
|
+
}, MineruSettingsTab));
|
|
824
|
+
|
|
792
825
|
ctx.slots.inject("settings.plugins.tab", () => ctx.slots.register({
|
|
793
826
|
name: "settings.plugins.tab",
|
|
794
827
|
id: "mineru",
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DNS resolution with a public-resolver fallback.
|
|
3
|
+
*
|
|
4
|
+
* Campus and ISP DNS servers sometimes answer public CDN hostnames with a
|
|
5
|
+
* loopback address (captive-DNS / filtering behaviour). When that happens the
|
|
6
|
+
* MinerU API is reachable but the result CDN is not, and the download step
|
|
7
|
+
* fails with a bare `fetch failed`. This module builds a `lookup` callback for
|
|
8
|
+
* `node:http(s)` that keeps trusting the system resolver unless it returns no
|
|
9
|
+
* usable address, and only then asks ordinary public resolvers over UDP 53 —
|
|
10
|
+
* no DNS-over-HTTPS dependency, no proxy, no hosts-file edit.
|
|
11
|
+
*
|
|
12
|
+
* The callback follows the `net.connect` contract: it answers
|
|
13
|
+
* `(err, address, family)` by default and `(err, [{ address, family }])` when
|
|
14
|
+
* `options.all` is set (undici and Node's autoSelectFamily ask that way).
|
|
15
|
+
* @module dsh-mineru/dns-resolve
|
|
16
|
+
*/
|
|
17
|
+
import { lookup as systemLookup } from 'node:dns';
|
|
18
|
+
import { Resolver } from 'node:dns/promises';
|
|
19
|
+
|
|
20
|
+
/** Public resolvers used only when the system resolver yields nothing usable. */
|
|
21
|
+
const DEFAULT_SERVERS = ['223.5.5.5', '119.29.29.29'];
|
|
22
|
+
const DEFAULT_TTL_MS = 10 * 60 * 1000;
|
|
23
|
+
const DEFAULT_TIMEOUT_MS = 5000;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether an address is unusable for reaching a public host.
|
|
27
|
+
* Loopback and unspecified addresses mean a filtered or captive resolver,
|
|
28
|
+
* never a real destination for a remote CDN.
|
|
29
|
+
* @param {unknown} address
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
export function isLoopbackAddress(address) {
|
|
33
|
+
const value = String(address ?? '').toLowerCase();
|
|
34
|
+
if (value === '::1' || value === '::' || value === '0.0.0.0') return true;
|
|
35
|
+
if (value.startsWith('127.')) return true;
|
|
36
|
+
const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(value);
|
|
37
|
+
if (mapped) return isLoopbackAddress(mapped[1]);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Resolve a hostname through explicit public resolvers.
|
|
43
|
+
* @param {string[]} servers
|
|
44
|
+
* @param {number} timeoutMs
|
|
45
|
+
* @returns {(hostname: string) => Promise<{address: string, family: number}[]>}
|
|
46
|
+
*/
|
|
47
|
+
export function createPublicResolve(servers = DEFAULT_SERVERS, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
48
|
+
const resolver = new Resolver({ timeout: timeoutMs, tries: 2 });
|
|
49
|
+
resolver.setServers(servers);
|
|
50
|
+
return async function resolve(hostname) {
|
|
51
|
+
const [v4, v6] = await Promise.all([
|
|
52
|
+
resolver.resolve4(hostname).catch(() => []),
|
|
53
|
+
resolver.resolve6(hostname).catch(() => []),
|
|
54
|
+
]);
|
|
55
|
+
const addresses = [
|
|
56
|
+
...v4.map((address) => ({ address, family: 4 })),
|
|
57
|
+
...v6.map((address) => ({ address, family: 6 })),
|
|
58
|
+
].filter((entry) => !isLoopbackAddress(entry.address));
|
|
59
|
+
if (addresses.length === 0) {
|
|
60
|
+
throw new Error('public resolvers returned no usable address for ' + hostname);
|
|
61
|
+
}
|
|
62
|
+
return addresses;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Build a `lookup` callback that falls back to public resolvers.
|
|
68
|
+
*
|
|
69
|
+
* Results are cached per hostname for `ttlMs`, so a download loop resolves
|
|
70
|
+
* once. Every injectable seam exists for tests: `systemLookup` and `resolve`.
|
|
71
|
+
* @param {object} [options]
|
|
72
|
+
* @param {string[]} [options.servers] public resolvers to ask on fallback
|
|
73
|
+
* @param {number} [options.ttlMs] fallback-answer cache lifetime
|
|
74
|
+
* @param {number} [options.timeoutMs] per-query timeout for the public resolvers
|
|
75
|
+
* @param {Function} [options.systemLookup] `node:dns` lookup replacement
|
|
76
|
+
* @param {(hostname: string) => Promise<{address: string, family: number}[]>} [options.resolve]
|
|
77
|
+
* @returns {(hostname: string, options: object|Function, callback?: Function) => void}
|
|
78
|
+
*/
|
|
79
|
+
export function createFallbackLookup(options = {}) {
|
|
80
|
+
const ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
81
|
+
const system = options.systemLookup ?? systemLookup;
|
|
82
|
+
const resolve = options.resolve ?? createPublicResolve(
|
|
83
|
+
options.servers ?? DEFAULT_SERVERS,
|
|
84
|
+
options.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
85
|
+
);
|
|
86
|
+
/** @type {Map<string, {addresses: {address: string, family: number}[], expires: number}>} */
|
|
87
|
+
const cache = new Map();
|
|
88
|
+
|
|
89
|
+
return function lookup(hostname, opts, callback) {
|
|
90
|
+
const query = typeof opts === 'function' ? {} : (opts ?? {});
|
|
91
|
+
const done = typeof opts === 'function' ? opts : callback;
|
|
92
|
+
|
|
93
|
+
/** @param {{address: string, family: number}[]} addresses @param {Error|null} [fallbackError] */
|
|
94
|
+
const deliver = (addresses, fallbackError) => {
|
|
95
|
+
if (addresses.length === 0) {
|
|
96
|
+
done(fallbackError ?? new Error('no usable address for ' + hostname));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const wanted = query.family === 6 ? 6 : query.family === 4 ? 4 : 0;
|
|
100
|
+
const matching = wanted ? addresses.filter((entry) => entry.family === wanted) : addresses;
|
|
101
|
+
const list = matching.length > 0 ? matching : addresses;
|
|
102
|
+
if (query.all) {
|
|
103
|
+
done(null, list);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
done(null, list[0].address, list[0].family);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const cached = cache.get(hostname);
|
|
110
|
+
if (cached && cached.expires > Date.now()) {
|
|
111
|
+
deliver(cached.addresses);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (cached) cache.delete(hostname);
|
|
115
|
+
|
|
116
|
+
system(hostname, { ...query, all: true }, (error, list) => {
|
|
117
|
+
const usable = (list ?? []).filter((entry) => !isLoopbackAddress(entry.address));
|
|
118
|
+
if (usable.length > 0) {
|
|
119
|
+
deliver(usable);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
resolve(hostname).then(
|
|
123
|
+
(addresses) => {
|
|
124
|
+
if (addresses.length === 0) {
|
|
125
|
+
deliver([], error);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
cache.set(hostname, { addresses, expires: Date.now() + ttlMs });
|
|
129
|
+
deliver(addresses);
|
|
130
|
+
},
|
|
131
|
+
(resolveError) => deliver([], error ?? resolveError),
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
}
|
package/lib/mineru-client.js
CHANGED
|
@@ -12,10 +12,13 @@
|
|
|
12
12
|
* @module dsh-mineru/mineru-client
|
|
13
13
|
*/
|
|
14
14
|
import { extname, join } from 'node:path';
|
|
15
|
+
import http from 'node:http';
|
|
16
|
+
import https from 'node:https';
|
|
15
17
|
import { createReadStream, createWriteStream } from 'node:fs';
|
|
16
18
|
import { mkdir, readFile, rm, stat } from 'node:fs/promises';
|
|
17
19
|
import { pipeline } from 'node:stream/promises';
|
|
18
|
-
import { Readable } from 'node:stream';
|
|
20
|
+
import { Readable, Transform } from 'node:stream';
|
|
21
|
+
import { createFallbackLookup } from './dns-resolve.js';
|
|
19
22
|
import { extractZip, readZipEntryText } from './zip.js';
|
|
20
23
|
import { AGENT_UNSUPPORTED_EXTENSIONS, MODEL_VERSION_VALUES, SUPPORTED_EXTENSIONS } from './config.js';
|
|
21
24
|
|
|
@@ -298,8 +301,56 @@ async function uploadToSignedUrl(filePath, uploadUrl, { signal, timeoutMs, userA
|
|
|
298
301
|
}
|
|
299
302
|
}
|
|
300
303
|
|
|
301
|
-
/**
|
|
302
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Shared fallback resolver for result downloads. Kept at module scope so its
|
|
306
|
+
* per-host cache survives repeated downloads of the same run.
|
|
307
|
+
*/
|
|
308
|
+
const downloadLookup = createFallbackLookup();
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* One GET over node:http(s), following redirects, with the DNS fallback in
|
|
312
|
+
* place. `fetch()` cannot take a custom `lookup`, which is why this exists:
|
|
313
|
+
* a resolver that answers a public CDN with loopback addresses is
|
|
314
|
+
* indistinguishable from a network outage to fetch.
|
|
315
|
+
* @param {string} url
|
|
316
|
+
* @param {{signal?: AbortSignal, timeoutMs: number, userAgent?: string, maxRedirects?: number}} opts
|
|
317
|
+
* @returns {Promise<import('node:http').IncomingMessage>}
|
|
318
|
+
*/
|
|
319
|
+
function openDownload(url, { signal, timeoutMs, userAgent, maxRedirects = 5 }) {
|
|
320
|
+
return new Promise((resolve, reject) => {
|
|
321
|
+
const target = new URL(url);
|
|
322
|
+
const transport = target.protocol === 'http:' ? http : https;
|
|
323
|
+
const req = transport.request(target, {
|
|
324
|
+
method: 'GET',
|
|
325
|
+
headers: { 'User-Agent': userAgent ?? 'dsh-mineru' },
|
|
326
|
+
lookup: downloadLookup,
|
|
327
|
+
signal,
|
|
328
|
+
}, (res) => {
|
|
329
|
+
const status = res.statusCode ?? 0;
|
|
330
|
+
const location = res.headers.location;
|
|
331
|
+
if (status >= 300 && status < 400 && location) {
|
|
332
|
+
res.resume();
|
|
333
|
+
if (maxRedirects <= 0) {
|
|
334
|
+
reject(new MineruError('MinerU 结果下载重定向次数过多', 'MINERU_DOWNLOAD_FAILED'));
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
openDownload(new URL(location, target).href, {
|
|
338
|
+
signal, timeoutMs, userAgent, maxRedirects: maxRedirects - 1,
|
|
339
|
+
}).then(resolve, reject);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
resolve(res);
|
|
343
|
+
});
|
|
344
|
+
req.setTimeout(timeoutMs, () => {
|
|
345
|
+
req.destroy(new MineruError('MinerU 结果下载超时', 'MINERU_TIMEOUT'));
|
|
346
|
+
});
|
|
347
|
+
req.on('error', reject);
|
|
348
|
+
req.end();
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Download through `fetch` (the normal path, and the one tests fake). */
|
|
353
|
+
async function downloadViaFetch(url, destPath, { signal, timeoutMs, userAgent, maxBytes }) {
|
|
303
354
|
const controller = new AbortController();
|
|
304
355
|
const timer = setTimeout(() => controller.abort(), Math.max(timeoutMs, 120000));
|
|
305
356
|
const onAbort = () => controller.abort();
|
|
@@ -329,6 +380,54 @@ async function downloadTo(url, destPath, { signal, timeoutMs, userAgent, maxByte
|
|
|
329
380
|
});
|
|
330
381
|
await pipeline(stream, createWriteStream(destPath));
|
|
331
382
|
return size;
|
|
383
|
+
} catch (err) {
|
|
384
|
+
await rm(destPath, { force: true }).catch(() => {});
|
|
385
|
+
if (err instanceof MineruError) throw err;
|
|
386
|
+
if (err?.name === 'AbortError') {
|
|
387
|
+
if (signal?.aborted) throw abortError();
|
|
388
|
+
throw new MineruError('MinerU 结果下载超时', 'MINERU_TIMEOUT');
|
|
389
|
+
}
|
|
390
|
+
const wrapped = new MineruError('MinerU 结果下载失败:' + (err?.message ?? String(err)), 'MINERU_DOWNLOAD_FAILED');
|
|
391
|
+
// Marks a transport failure (DNS/connect), not an HTTP answer: only that
|
|
392
|
+
// kind is worth retrying through the fallback resolver.
|
|
393
|
+
wrapped.transport = true;
|
|
394
|
+
throw wrapped;
|
|
395
|
+
} finally {
|
|
396
|
+
clearTimeout(timer);
|
|
397
|
+
signal?.removeEventListener('abort', onAbort);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Download over node:http(s), routing the hostname through the fallback lookup. */
|
|
402
|
+
async function downloadViaHttp(url, destPath, { signal, timeoutMs, userAgent, maxBytes }) {
|
|
403
|
+
const controller = new AbortController();
|
|
404
|
+
const timer = setTimeout(() => controller.abort(), Math.max(timeoutMs, 120000));
|
|
405
|
+
const onAbort = () => controller.abort();
|
|
406
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
407
|
+
let size = 0;
|
|
408
|
+
try {
|
|
409
|
+
const res = await openDownload(url, {
|
|
410
|
+
signal: controller.signal,
|
|
411
|
+
timeoutMs: Math.max(timeoutMs, 120000),
|
|
412
|
+
userAgent,
|
|
413
|
+
});
|
|
414
|
+
const status = res.statusCode ?? 0;
|
|
415
|
+
if (status < 200 || status >= 300) {
|
|
416
|
+
res.resume();
|
|
417
|
+
throw new MineruError('MinerU 结果下载失败(HTTP ' + status + ')', 'MINERU_DOWNLOAD_FAILED');
|
|
418
|
+
}
|
|
419
|
+
const counter = new Transform({
|
|
420
|
+
transform(chunk, _encoding, callback) {
|
|
421
|
+
size += chunk.length;
|
|
422
|
+
if (maxBytes && size > maxBytes) {
|
|
423
|
+
callback(new MineruError('MinerU 结果超过下载上限 ' + maxBytes + ' 字节', 'MINERU_TOO_LARGE'));
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
callback(null, chunk);
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
await pipeline(res, counter, createWriteStream(destPath));
|
|
430
|
+
return size;
|
|
332
431
|
} catch (err) {
|
|
333
432
|
await rm(destPath, { force: true }).catch(() => {});
|
|
334
433
|
if (err instanceof MineruError) throw err;
|
|
@@ -341,7 +440,29 @@ async function downloadTo(url, destPath, { signal, timeoutMs, userAgent, maxByte
|
|
|
341
440
|
clearTimeout(timer);
|
|
342
441
|
signal?.removeEventListener('abort', onAbort);
|
|
343
442
|
}
|
|
344
|
-
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Download a URL to a local file (result zips / markdown).
|
|
447
|
+
*
|
|
448
|
+
* The fetch path runs first so an ordinary network behaves exactly as before.
|
|
449
|
+
* When it fails at the transport layer (DNS filtered to loopback, connection
|
|
450
|
+
* refused, TLS reset) the download is retried once over node:http(s), which
|
|
451
|
+
* can resolve the hostname through public resolvers. An HTTP error status is
|
|
452
|
+
* never retried — the server answered, the request is simply wrong.
|
|
453
|
+
*/
|
|
454
|
+
async function downloadTo(url, destPath, opts) {
|
|
455
|
+
try {
|
|
456
|
+
return await downloadViaFetch(url, destPath, opts);
|
|
457
|
+
} catch (err) {
|
|
458
|
+
if (err instanceof MineruError && err.transport === true) {
|
|
459
|
+
return downloadViaHttp(url, destPath, opts);
|
|
460
|
+
}
|
|
461
|
+
throw err;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
345
466
|
* The Mineru client. Create one per API base + token; rate limiters and the
|
|
346
467
|
* daily counter are shared so concurrent tool calls stay under the official
|
|
347
468
|
* frequency caps.
|
package/package.json
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-mineru",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "dsh-mineru: MinerU 文档解析插件 for DeepSeek Harness — 多模态全格式 (PDF/Word/PPT/Excel/HTML/图片) → 结构化 Markdown. 填 Token 走精准解析 API, 留空走 Agent 轻量解析 API. 注意: 解析需把文件上传至 MinerU 远端(内容出网), 无完全离线模式, 涉密/不得出网材料请勿使用.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"types": "lib/types/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./lib/types/index.d.ts",
|
|
11
|
-
"default": "./lib/index.js"
|
|
12
|
-
},
|
|
13
|
-
"./client": {
|
|
14
|
-
"types": "./lib/types/client.d.ts",
|
|
15
|
-
"default": "./lib/client.js"
|
|
16
|
-
},
|
|
17
|
-
"./package.json": "./package.json"
|
|
18
|
-
},
|
|
19
|
-
"files": [
|
|
20
|
-
"lib/",
|
|
21
|
-
"cordis.patch.yml",
|
|
22
|
-
"README.md",
|
|
23
|
-
"README.zh.md",
|
|
24
|
-
"CHANGELOG.md",
|
|
25
|
-
"RELEASE.md",
|
|
26
|
-
"CONTRIBUTING.md",
|
|
27
|
-
"LICENSE"
|
|
28
|
-
],
|
|
29
|
-
"dsh": {
|
|
30
|
-
"bundle": {
|
|
31
|
-
"patch": "./cordis.patch.yml"
|
|
32
|
-
},
|
|
33
|
-
"client": {
|
|
34
|
-
"inject": [
|
|
35
|
-
"slots",
|
|
36
|
-
"connection",
|
|
37
|
-
"sessions",
|
|
38
|
-
"conversation",
|
|
39
|
-
"locale"
|
|
40
|
-
],
|
|
41
|
-
"platform": "web"
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"test": "vitest run",
|
|
46
|
-
"test:compat": "vitest run tests/dsh-compat.spec.js"
|
|
47
|
-
},
|
|
48
|
-
"dependencies": {
|
|
49
|
-
"@deepseek-ai/schemastery": "^3.18.0"
|
|
50
|
-
},
|
|
51
|
-
"devDependencies": {
|
|
52
|
-
"@deepseek-ai/cordis": "4.0.5",
|
|
53
|
-
"@deepseek-ai/dsh-agent": "0.2.0-rc.2",
|
|
54
|
-
"@deepseek-ai/dsh-app-boot": "0.2.0-rc.2",
|
|
55
|
-
"@deepseek-ai/dsh-credentials": "0.2.0-rc.2",
|
|
56
|
-
"@deepseek-ai/dsh-host-webserver": "0.2.0-rc.2",
|
|
57
|
-
"@deepseek-ai/dsh-llm": "0.2.0-rc.2",
|
|
58
|
-
"@deepseek-ai/dsh-scope": "0.2.0-rc.2",
|
|
59
|
-
"@deepseek-ai/dsh-settings": "0.2.0-rc.2",
|
|
60
|
-
"@deepseek-ai/dsh-skill": "0.2.0-rc.2",
|
|
61
|
-
"@deepseek-ai/dsh-tools": "0.2.0-rc.2",
|
|
62
|
-
"vitest": "^4.1.11"
|
|
63
|
-
},
|
|
64
|
-
"engines": {
|
|
65
|
-
"node": ">=18.0.0"
|
|
66
|
-
},
|
|
67
|
-
"peerDependencies": {
|
|
68
|
-
"@deepseek-ai/cordis": "^4.0.1",
|
|
69
|
-
"@deepseek-ai/schemastery": "^3.18.0",
|
|
70
|
-
"@deepseek-ai/dsh-tools": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
71
|
-
"@deepseek-ai/dsh-settings": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
72
|
-
"@deepseek-ai/dsh-credentials": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
73
|
-
"@deepseek-ai/dsh-skill": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
74
|
-
"@deepseek-ai/dsh-host-webserver": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
75
|
-
"@deepseek-ai/dsh-llm": "^0.1.5-rc.1 || ^0.2.0-rc.1"
|
|
76
|
-
},
|
|
77
|
-
"license": "MIT",
|
|
78
|
-
"keywords": [
|
|
79
|
-
"deepseek-harness",
|
|
80
|
-
"dsh",
|
|
81
|
-
"dsh-plugin",
|
|
82
|
-
"mineru",
|
|
83
|
-
"document-parsing",
|
|
84
|
-
"pdf",
|
|
85
|
-
"ocr",
|
|
86
|
-
"markdown",
|
|
87
|
-
"multimodal"
|
|
88
|
-
],
|
|
89
|
-
"repository": {
|
|
90
|
-
"type": "git",
|
|
91
|
-
"url": "git+https://github.com/Lee-Hilex/dsh-mineru.git"
|
|
92
|
-
},
|
|
93
|
-
"homepage": "https://github.com/Lee-Hilex/dsh-mineru#readme",
|
|
94
|
-
"bugs": {
|
|
95
|
-
"url": "https://github.com/Lee-Hilex/dsh-mineru/issues"
|
|
96
|
-
},
|
|
97
|
-
"author": {
|
|
98
|
-
"name": "Lee-Hilex",
|
|
99
|
-
"email": "niuniu910417@163.com"
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-mineru",
|
|
3
|
+
"version": "0.1.17",
|
|
4
|
+
"description": "dsh-mineru: MinerU 文档解析插件 for DeepSeek Harness — 多模态全格式 (PDF/Word/PPT/Excel/HTML/图片) → 结构化 Markdown. 填 Token 走精准解析 API, 留空走 Agent 轻量解析 API. 注意: 解析需把文件上传至 MinerU 远端(内容出网), 无完全离线模式, 涉密/不得出网材料请勿使用.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./lib/types/client.d.ts",
|
|
15
|
+
"default": "./lib/client.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib/",
|
|
21
|
+
"cordis.patch.yml",
|
|
22
|
+
"README.md",
|
|
23
|
+
"README.zh.md",
|
|
24
|
+
"CHANGELOG.md",
|
|
25
|
+
"RELEASE.md",
|
|
26
|
+
"CONTRIBUTING.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"dsh": {
|
|
30
|
+
"bundle": {
|
|
31
|
+
"patch": "./cordis.patch.yml"
|
|
32
|
+
},
|
|
33
|
+
"client": {
|
|
34
|
+
"inject": [
|
|
35
|
+
"slots",
|
|
36
|
+
"connection",
|
|
37
|
+
"sessions",
|
|
38
|
+
"conversation",
|
|
39
|
+
"locale"
|
|
40
|
+
],
|
|
41
|
+
"platform": "web"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"test:compat": "vitest run tests/dsh-compat.spec.js"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@deepseek-ai/schemastery": "^3.18.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@deepseek-ai/cordis": "4.0.5",
|
|
53
|
+
"@deepseek-ai/dsh-agent": "0.2.0-rc.2",
|
|
54
|
+
"@deepseek-ai/dsh-app-boot": "0.2.0-rc.2",
|
|
55
|
+
"@deepseek-ai/dsh-credentials": "0.2.0-rc.2",
|
|
56
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.0-rc.2",
|
|
57
|
+
"@deepseek-ai/dsh-llm": "0.2.0-rc.2",
|
|
58
|
+
"@deepseek-ai/dsh-scope": "0.2.0-rc.2",
|
|
59
|
+
"@deepseek-ai/dsh-settings": "0.2.0-rc.2",
|
|
60
|
+
"@deepseek-ai/dsh-skill": "0.2.0-rc.2",
|
|
61
|
+
"@deepseek-ai/dsh-tools": "0.2.0-rc.2",
|
|
62
|
+
"vitest": "^4.1.11"
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=18.0.0"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
69
|
+
"@deepseek-ai/schemastery": "^3.18.0",
|
|
70
|
+
"@deepseek-ai/dsh-tools": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
71
|
+
"@deepseek-ai/dsh-settings": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
72
|
+
"@deepseek-ai/dsh-credentials": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
73
|
+
"@deepseek-ai/dsh-skill": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
74
|
+
"@deepseek-ai/dsh-host-webserver": "^0.1.5-rc.1 || ^0.2.0-rc.1",
|
|
75
|
+
"@deepseek-ai/dsh-llm": "^0.1.5-rc.1 || ^0.2.0-rc.1"
|
|
76
|
+
},
|
|
77
|
+
"license": "MIT",
|
|
78
|
+
"keywords": [
|
|
79
|
+
"deepseek-harness",
|
|
80
|
+
"dsh",
|
|
81
|
+
"dsh-plugin",
|
|
82
|
+
"mineru",
|
|
83
|
+
"document-parsing",
|
|
84
|
+
"pdf",
|
|
85
|
+
"ocr",
|
|
86
|
+
"markdown",
|
|
87
|
+
"multimodal"
|
|
88
|
+
],
|
|
89
|
+
"repository": {
|
|
90
|
+
"type": "git",
|
|
91
|
+
"url": "git+https://github.com/Lee-Hilex/dsh-mineru.git"
|
|
92
|
+
},
|
|
93
|
+
"homepage": "https://github.com/Lee-Hilex/dsh-mineru#readme",
|
|
94
|
+
"bugs": {
|
|
95
|
+
"url": "https://github.com/Lee-Hilex/dsh-mineru/issues"
|
|
96
|
+
},
|
|
97
|
+
"author": {
|
|
98
|
+
"name": "Lee-Hilex",
|
|
99
|
+
"email": "niuniu910417@163.com"
|
|
100
|
+
}
|
|
101
|
+
}
|