dsh-downloader
把「多连接分块 + 断点续传 + 代理 + SHA-256 校验」的下载器,做成 DeepSeek Harness 里的三个 agent 工具。
纯 Node 内置模块实现(fs / net / tls / http / https / crypto),零 npm 依赖,不需要 Python。
任务跑在 DSH 宿主进程里:回合结束后继续下载,随时用 dl_status 查进度。
English: a resumable, multi-connection HTTP(S) downloader for DeepSeek Harness, exposed as three agent tools.
Zero dependencies, proxy-aware (HTTP CONNECT tunnel for HTTPS), SHA-256 verified, and the job outlives the turn.
工具
| 工具 | 作用 | 关键参数 |
|---|---|---|
dl_start |
开始 / 续传一个下载任务,立即返回 jobId |
url、outFile(必填);totalBytes、sha256、threads(默认 8,上限 32)、chunkMb(默认 16)、proxy、headers |
dl_status |
查进度:传 jobId 查单个,不传则列出全部 |
jobId |
dl_cancel |
停止任务 | jobId;deletePartial(默认 false,保留半成品与续传状态) |
dl_status / dl_cancel 统一返回 { count, jobs: [...] }。每个 job 含 state
(pending / running / done / failed / cancelled)、bytesDone、percent、speedBps、
etaSeconds、doneChunks / totalChunks、error 等字段。
行为要点
- 续传:进度写在
<outFile>.dlstate.json(URL、总长、块大小、已完成块位图)。同一 URL、同一块大小再次dl_start会跳过已完成块继续下;成功后自动删除状态文件。 - 并行:默认 8 条连接、16 MiB 一块,按分块号顺序派发。单块失败最多重试 6 次(指数退避)。
- 代理:
proxy: "http://127.0.0.1:3128",对 HTTPS 走CONNECT隧道,所有请求都经它。 - 校验:给了
sha256就在完成后整文件校验,不一致判failed(不会假装成功)。 - 不支持 Range 的服务器(返回 200):自动退化成单连接顺序下载;这类源没有续传能力。
- 超时:连接 / CONNECT 15s、等响应头 45s、响应体静默 60s,超时判失败并走重试退避,
不会像早期版本那样永远停在
pending。可用环境变量覆盖:DSH_DL_CONNECT_TIMEOUT_MS、DSH_DL_HEADERS_TIMEOUT_MS、DSH_DL_IDLE_TIMEOUT_MS。 - Windows 细节:不预先
truncate到最终大小(NTFS 上会按约 100 MB/s 零填充整段), 而是让分块按各自偏移写入,结束时再校正文件长度。
安装
本包自带 bundle patch(cordis.patch.yml,插入一行 id: downloader / name: dsh-downloader)。
从 GitHub 直接装:
dsh plugin --profile desktop add github:morethaninformation/dsh-downloader
或用 Release 里的预构建 tarball(不必从源码构建,也不需要 pnpm 拉依赖):
dsh plugin --profile desktop add https://github.com/morethaninformation/dsh-downloader/releases/latest/download/dsh-downloader.tgz
装完重启一次 DSH,dl_start / dl_status / dl_cancel 会出现在工具列表里。卸载:
dsh plugin --profile desktop remove dsh-downloader。
用法示例
dl_start({ url: "https://example.com/model.gguf", outFile: "D:\\models\\model.gguf",
totalBytes: 47039860096, sha256: "219e…", threads: 8, chunkMb: 16,
proxy: "http://127.0.0.1:3128" })
→ { jobId: "dl-1", state: "pending", ... }
dl_status({ jobId: "dl-1" })
→ { count: 1, jobs: [{ percent: 3.1, speedBps: 4200000, etaSeconds: 10800, ... }] }
限制
- 只支持 HTTP / HTTPS(含
http://代理的CONNECT隧道);不支持 SOCKS 与 FTP。 - 续传依赖服务器支持 Range;不支持时退化为顺序下载,中断后从头再来。
- 任务表存在内存里:DSH 重启后任务消失,但
.dlstate.json仍在,对同一 URL 与块大小重新dl_start即可接着下。 - 分块的块大小必须一致才能续传;改变
chunkMb会作废旧进度。
自测
node test/smoke.mjs # 本地 Range 服务器:多连接、取消后续传、无 Range 退化、sha256 失败、302 跟随
node test/smoke.mjs --net # 追加真实 HTTPS 下载
node test/apply.mjs # 假 cordis ctx:验证三个工具注册与 execute
License
MIT
No comments yet. Be the first to write one.