dsh-office-tools 1.0.3 → 1.0.5
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/README.md +31 -71
- package/README.zh.md +31 -70
- package/dsh.plugin.json +2 -2
- package/lib/index.js +119 -58
- package/package.json +13 -9
package/README.md
CHANGED
|
@@ -1,108 +1,68 @@
|
|
|
1
1
|
# dsh-office-tools
|
|
2
2
|
|
|
3
|
-
Eight model-facing Office file tools for DeepSeek Harness, running entirely in the plugin host half.
|
|
4
|
-
|
|
5
3
|
[](https://www.npmjs.com/package/dsh-office-tools) [](https://github.com/kw78/dsh-office-tools/actions/workflows/ci.yml) [](LICENSE) [](https://awesome-dsh-plugin.com)
|
|
6
4
|
|
|
7
|
-
>
|
|
5
|
+
> **If you find this project useful, please give it a ⭐ Star — it helps others find it.**
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
Eight model-facing Office file tools for DeepSeek Harness: create, read, and update Word (`.docx`), Excel (`.xlsx`), and PowerPoint (`.pptx`) files inside the session workspace. Zero runtime dependencies — every package is generated and parsed by the plugin's own OOXML engine, and every byte crosses the official `ctx.fs` service.
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
## Tools
|
|
12
10
|
|
|
13
11
|
| Tool | Purpose |
|
|
14
12
|
|---|---|
|
|
15
13
|
| `word_create` | Create `.docx` (title, paragraphs, bullets, one table) |
|
|
16
|
-
| `word_read` | Extract text
|
|
17
|
-
| `word_update` | Append paragraphs, bullets, and/or a table
|
|
18
|
-
| `excel_create` | Create
|
|
19
|
-
| `excel_read` | Read
|
|
20
|
-
| `excel_update` | Replace/create
|
|
21
|
-
| `ppt_create` | Create
|
|
22
|
-
| `ppt_read` | Extract
|
|
14
|
+
| `word_read` | Extract text; `format: "markdown"` renders structure |
|
|
15
|
+
| `word_update` | Append paragraphs, bullets, and/or a table |
|
|
16
|
+
| `excel_create` | Create multi-sheet `.xlsx` from cell grids |
|
|
17
|
+
| `excel_read` | Read sheets as rows; formulas return cached values or `'=…'` |
|
|
18
|
+
| `excel_update` | Replace/create sheets, or write cells by A1 address |
|
|
19
|
+
| `ppt_create` | Create 16:9 `.pptx` (slides, bullets, notes, linked images) |
|
|
20
|
+
| `ppt_read` | Extract text, notes, tables, and per-shape geometry |
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
Strings starting with `=` become real Excel formulas.
|
|
25
23
|
|
|
26
24
|
## Demo
|
|
27
25
|
|
|
28
|
-
One prompt, a quarterly-report trio
|
|
26
|
+
One prompt, a quarterly-report trio:
|
|
29
27
|
|
|
30
28
|
<img src="docs/demo/session.svg" alt="One prompt generating report.docx, budget.xlsx, and deck.pptx" width="780">
|
|
31
29
|
|
|
32
|
-
The prompt behind that session:
|
|
33
|
-
|
|
34
|
-
> Generate the Q3 quarterly-report trio: `report.docx` (title, two summary paragraphs, three highlights, a metrics table), `budget.xlsx` (a Budget sheet with `=SUM` totals and plan-vs-actual variance formulas, plus a Summary sheet), and `deck.pptx` (title slide + three content slides with speaker notes).
|
|
35
|
-
|
|
36
|
-
The model turns it into `word_create` → `excel_create` → `ppt_create` (reads come back through `word_read` / `excel_read` / `ppt_read`; freshly written formulas read back as `'=…'` strings until Excel caches values). The whole flow is pinned by `tests/demo-trio.spec.ts`, so the demo cannot drift from the tools. The file sizes in the image come from a real run of that test scenario.
|
|
37
|
-
|
|
38
|
-
## Harness integration
|
|
39
|
-
|
|
40
|
-
The plugin follows the standard DSH host-plugin contract:
|
|
41
|
-
|
|
42
|
-
- It exports `name` / `inject` / `apply` / `Config`; `inject = ['tools', 'fs']` — the official tool registry and the official filesystem service (`@deepseek-ai/dsh-tools`, `@deepseek-ai/dsh-fs`) are its only runtime service dependencies.
|
|
43
|
-
- `apply(ctx)` wraps every `ctx.tools.register(defineTool({...}))` in `ctx.effect(...)` so Cordis disposes the registrations with the plugin fiber.
|
|
44
|
-
- `defineTool` declares model-visible `parameters`, a validated canonical `output.schema`, and a pure `output.render` text projection.
|
|
45
|
-
- `execute(args, exec)` resolves every path against `exec.agent.session.header.cwd`; relative paths stay in the session workspace and absolute paths are accepted only when still inside it. Containment and symlink resolution are enforced by the `ctx.fs` backend (plus a lexical pre-check here).
|
|
46
|
-
- All reads arrive as raw bytes via `ctx.fs.readBytes`; all writes leave as UTF-8 text via `ctx.fs.writeText` — published atomically by the backend; `overwrite` defaults to `false`.
|
|
47
|
-
- Generated packages are pure ASCII by construction (an ASCII-safe STORE zip planner pads each XML part and aligns offsets so every CRC/size/offset field stays byte-safe), which is exactly what lets real `.docx`/`.xlsx`/`.pptx` files travel through the text channel byte-identically. Non-ASCII text encodes as XML character references; every Office suite opens the result.
|
|
48
|
-
- Reads accept any real-world package (STORE and DEFLATE entries, bounded by the zip-bomb guard).
|
|
49
|
-
- `word_update` / `excel_update` re-publish through the text channel, so they work on packages whose every part is text (always true for files these tools write, and for OOXML packages without binary media); packages carrying binary media are refused with a clear error instead of being corrupted.
|
|
50
|
-
- Images are LINKED, not embedded: the model controls placement fully (`x/y/w/h` inches, `contain`/`cover` cropping, alt text; PNG/JPG/GIF headers are sniffed so omitted dimensions default to natural size), and the deck references the workspace image file. Keep the image files next to the deck when moving it — that is the trade-off of a dependency-free, binary-free package.
|
|
51
|
-
- `ppt_create` echoes the full layout (every element's box in inches + the canvas size + a text wireframe sketch per slide); `ppt_read` returns the same geometry for any deck, so the model can see and re-author compositions.
|
|
52
|
-
|
|
53
|
-
## Build
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
pnpm install
|
|
57
|
-
pnpm run check # typecheck + tests + build
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Artifacts: `lib/index.js` (ESM host bundle of this plugin's own code only — ~116 kB, zero runtime dependencies) and `lib/types/**/*.d.ts`. Every `@deepseek-ai/*` package (cordis, the dsh services, schemastery) stays external and is provided by the profile's node_modules.
|
|
61
|
-
|
|
62
30
|
## Install
|
|
63
31
|
|
|
64
32
|
```bash
|
|
65
|
-
# npm (recommended)
|
|
66
|
-
dsh plugin --profile web add dsh-office-tools
|
|
67
|
-
|
|
68
|
-
# GitHub source
|
|
69
|
-
dsh plugin --profile web add github:kw78/dsh-office-tools
|
|
70
|
-
|
|
71
|
-
# local checkout
|
|
72
|
-
dsh plugin --profile web add /path/to/dsh-office-tools
|
|
33
|
+
dsh plugin --profile web add dsh-office-tools # npm (recommended)
|
|
34
|
+
dsh plugin --profile web add github:kw78/dsh-office-tools # from source
|
|
73
35
|
```
|
|
74
36
|
|
|
75
|
-
Restart
|
|
37
|
+
Restart DSH after installing. Requires a profile that provides the `fs` service (every profile with built-in read/write tools does).
|
|
76
38
|
|
|
77
|
-
##
|
|
39
|
+
## Notes
|
|
78
40
|
|
|
79
|
-
|
|
41
|
+
- All paths are confined to the session workspace; `overwrite` defaults to `false`.
|
|
42
|
+
- Reads accept any real package (STORE/DEFLATE) with zip-bomb guards; updates refuse packages with binary parts instead of corrupting them.
|
|
43
|
+
- PPT images are **linked, not embedded**: the sanctioned `ctx.fs` write channel is UTF-8 text only, so a package cannot carry binary image parts. Keep image files next to the deck when moving it, and note that PowerPoint blocks external content by default — a linked picture renders as a "blocked automatic download" placeholder until you enable external content (File → Info → Enable Content, or add the folder under Trust Center → Trusted Locations). This is a PowerPoint security policy, not a package defect.
|
|
44
|
+
- `ppt_create` echoes every element's landing position; `ppt_read` returns the same geometry for any deck.
|
|
80
45
|
|
|
81
|
-
|
|
82
|
-
|---|---|---|---|
|
|
83
|
-
| `enablePptTools` | boolean | `true` | Register `ppt_create` / `ppt_read`. Set to `false` to load this plugin for Word/Excel only. |
|
|
46
|
+
## Configuration
|
|
84
47
|
|
|
85
|
-
|
|
48
|
+
One option: `enablePptTools` (default `true`) — set it to `false` to coexist with a dedicated presentation plugin such as dsh-ppt:
|
|
86
49
|
|
|
87
50
|
```yaml
|
|
88
|
-
# profile cordis.patch.yml
|
|
89
51
|
- insert:
|
|
90
52
|
- id: dsh-office-tools
|
|
91
53
|
config:
|
|
92
54
|
enablePptTools: false
|
|
93
55
|
```
|
|
94
56
|
|
|
95
|
-
##
|
|
57
|
+
## Development
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pnpm install && pnpm run check # typecheck + tests + build
|
|
61
|
+
pnpm run test:e2e # real-composition E2E (sandbox-policy + fs-sandbox + tools)
|
|
62
|
+
```
|
|
96
63
|
|
|
97
|
-
|
|
98
|
-
- Recommended repository topics: `dsh`, `dsh-plugin`, `deepseek-harness`, `office`.
|
|
64
|
+
Compatibility: the declared DSH 0.1.x ranges and `>=0.2.0-rc.1 <0.3.0-0`; exact tested releases live in `package.json` (`dsh.compatibility.dshReleases`). CI exercises both 0.1.2-rc.1 and 0.2.0-rc.1. DSH 0.3.x is not declared supported.
|
|
99
65
|
|
|
100
|
-
|
|
66
|
+
Generated packages are limited to 50 MiB. Up to 200 PPT slides (including an optional title slide) are accepted; linked images remain external. See [architecture and migration plan](docs/ARCHITECTURE.zh.md) for the binary-write seam needed for true embedding.
|
|
101
67
|
|
|
102
|
-
|
|
103
|
-
- Reads are capped at 50 MiB compressed; before anything is inflated, the archive's own declared sizes are checked against budgets (256 MiB per entry, 512 MiB per archive, 100 000 entries), so zip bombs are refused rather than decompressed. XML parts carrying DOCTYPE/ENTITY declarations are refused outright.
|
|
104
|
-
- Text/cell results are bounded and mark `truncated`.
|
|
105
|
-
- Creates/updates are bounded by row and cell limits and refuse overwrites by default.
|
|
106
|
-
- No LibreOffice/PowerPoint/Word subprocess is spawned and no third-party library is shipped: formats are generated and parsed by this plugin's own ASCII-safe OOXML engine over `node:zlib`.
|
|
107
|
-
- The plugin's own code never touches the file system directly — there is no `node:fs` import anywhere in `src/`; every byte flows through the official, user-visible `ctx.fs` service. This is what lets third-party store automation verify the whole runtime source deterministically (DSH Store issue #334: 1.0.0 passes the complete automatic low-risk policy — zero runtime dependencies, zero file/network/commands/credentials signals, bounded source, exact per-release compatibility declarations).
|
|
108
|
-
- Roadmap: [docs/ROADMAP.md](docs/ROADMAP.md).
|
|
68
|
+
Further reading: [DEVELOPMENT.md](docs/DEVELOPMENT.md) · [ROADMAP.md](docs/ROADMAP.md) · [hub-registration.md](docs/hub-registration.md) · MIT [License](LICENSE)
|
package/README.zh.md
CHANGED
|
@@ -2,106 +2,67 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/dsh-office-tools) [](https://github.com/kw78/dsh-office-tools/actions/workflows/ci.yml) [](LICENSE) [](https://awesome-dsh-plugin.com)
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> **如果你觉得本项目好用的话,请给个 ⭐ Star —— 谢谢!**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
为 DeepSeek Harness 提供 8 个模型可调用的 Office 文件工具:在会话工作区内创建、读取、更新 Word(`.docx`)、Excel(`.xlsx`)、PowerPoint(`.pptx`)。零运行时依赖 —— 文件由插件自带的 OOXML 引擎生成与解析,所有字节都经官方 `ctx.fs` 服务传输。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## 工具
|
|
10
10
|
|
|
11
11
|
| 工具 | 作用 |
|
|
12
12
|
|---|---|
|
|
13
13
|
| `word_create` | 创建 `.docx`(标题、段落、项目符号、一个表格) |
|
|
14
|
-
| `word_read` |
|
|
15
|
-
| `word_update` |
|
|
16
|
-
| `excel_create` | 创建多 sheet 的 `.xlsx
|
|
17
|
-
| `excel_read` |
|
|
18
|
-
| `excel_update` |
|
|
19
|
-
| `ppt_create` | 创建 16:9 `.pptx
|
|
20
|
-
| `ppt_read` |
|
|
14
|
+
| `word_read` | 提取文本;`format: "markdown"` 结构化渲染 |
|
|
15
|
+
| `word_update` | 向现有文档追加段落、项目符号和/或表格 |
|
|
16
|
+
| `excel_create` | 创建多 sheet 的 `.xlsx` |
|
|
17
|
+
| `excel_read` | 读取 sheet 为行;公式返回缓存值或 `'=…'` 串 |
|
|
18
|
+
| `excel_update` | 替换/新建整张 sheet,或按 A1 地址写单元格 |
|
|
19
|
+
| `ppt_create` | 创建 16:9 `.pptx`(幻灯片、要点、备注、链接式图片) |
|
|
20
|
+
| `ppt_read` | 提取文本、备注、表格与每个形状的几何信息 |
|
|
21
21
|
|
|
22
|
-
以 `=` 开头的字符串单元格会写成真正的 Excel
|
|
22
|
+
以 `=` 开头的字符串单元格会写成真正的 Excel 公式。
|
|
23
23
|
|
|
24
24
|
## 演示
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
一句话,季度报告三件套:
|
|
27
27
|
|
|
28
28
|
<img src="docs/demo/session.svg" alt="一句话生成 report.docx、budget.xlsx、deck.pptx" width="780">
|
|
29
29
|
|
|
30
|
-
上图会话用的提示词:
|
|
31
|
-
|
|
32
|
-
> 生成 Q3 季度报告三件套:`report.docx`(标题、两段摘要、三个要点、一张指标表)、`budget.xlsx`(Budget sheet 含 `=SUM` 合计与计划/实际差异公式,再加一个 Summary sheet)、`deck.pptx`(标题页 + 3 页正文,含演讲者备注)。
|
|
33
|
-
|
|
34
|
-
模型会把它拆成 `word_create` → `excel_create` → `ppt_create`(回读走 `word_read` / `excel_read` / `ppt_read`;新写入的公式在被 Excel 计算缓存前以 `'=…'` 串回读)。整个流程由 `tests/demo-trio.spec.ts` 钉死,演示不会与工具行为漂移;图中的体积数字来自该测试场景的一次真实运行。
|
|
35
|
-
|
|
36
|
-
## 框架接入方式
|
|
37
|
-
|
|
38
|
-
插件遵循 DSH 标准 host 插件契约:
|
|
39
|
-
|
|
40
|
-
- 模块导出 `name` / `inject` / `apply` / `Config`;本插件 `inject = ['tools', 'fs']`——官方工具注册表与官方文件服务(`@deepseek-ai/dsh-tools`、`@deepseek-ai/dsh-fs`)是仅有的运行时服务依赖。
|
|
41
|
-
- `apply(ctx)` 中用 `ctx.effect(() => ...)` 包裹 `ctx.tools.register(defineTool({...}))`,Cordis fiber 卸载时自动 dispose。
|
|
42
|
-
- `defineTool` 统一声明 `parameters`(模型可见 JSON Schema)、`output.schema`(强制校验的规范 JSON 值)与 `output.render`(模型看到的文本投影)。
|
|
43
|
-
- 每个 `execute(args, exec)` 从 `exec.agent.session.header.cwd` 取会话工作目录;相对路径按该目录解析,绝对路径只接受仍位于工作目录内的路径。containment 与符号链接解析由 `ctx.fs` 后端权威执行(本插件再做一道词法预检)。
|
|
44
|
-
- 读经 `ctx.fs.readBytes` 以原始字节到达;写经 `ctx.fs.writeText` 以 UTF-8 文本离开(后端原子落盘);`overwrite` 默认 `false`,防止误覆盖。
|
|
45
|
-
- 生成的包是纯 ASCII 的 STORE 型 zip:规划器为每个 XML 部件做尾部换行填充并做 1 KiB 槽位对齐(跳过每 64 KiB 页的不安全偏移带),使 CRC/大小/偏移字段全部字节安全——这正是真实 Office 文件能以字节一致方式通过官方文本通道的原因。非 ASCII 文本编码为 XML 字符引用。
|
|
46
|
-
- 读取接受任意真实包(STORE/DEFLATE,含 zip 炸弹防御);`word_update`/`excel_update` 适用于全文本部件的包,携带二进制媒体的包会被明确拒绝。
|
|
47
|
-
- 图片为链接式:模型完全掌控摆放(x/y/w/h 英寸、contain/cover、alt;PNG/JPG/GIF 头部嗅探出原图尺寸),deck 引用 workspace 图片文件;`ppt_create` 结果回显全部元素落点(英寸坐标 + 画布尺寸 + 每页文本线框图),`ppt_read` 对任意 deck 返回同样的几何信息。
|
|
48
|
-
|
|
49
|
-
## 构建
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
pnpm install
|
|
53
|
-
pnpm run check # typecheck + tests + build
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
构建产物:`lib/index.js`(ESM host bundle,仅打包本插件自有代码——约 116 kB,零运行时依赖)与 `lib/types/**/*.d.ts`;所有 `@deepseek-ai/*`(cordis、dsh 服务、schemastery)保持 external,由 profile 的 node_modules 提供。
|
|
57
|
-
|
|
58
30
|
## 安装
|
|
59
31
|
|
|
60
32
|
```bash
|
|
61
|
-
# npm(推荐)
|
|
62
|
-
dsh plugin --profile web add dsh-office-tools
|
|
63
|
-
|
|
64
|
-
# GitHub 源码
|
|
65
|
-
dsh plugin --profile web add github:kw78/dsh-office-tools
|
|
66
|
-
|
|
67
|
-
# 本地目录
|
|
68
|
-
dsh plugin --profile web add /path/to/dsh-office-tools
|
|
33
|
+
dsh plugin --profile web add dsh-office-tools # npm(推荐)
|
|
34
|
+
dsh plugin --profile web add github:kw78/dsh-office-tools # 源码
|
|
69
35
|
```
|
|
70
36
|
|
|
71
|
-
安装后重启 DSH
|
|
37
|
+
安装后重启 DSH。宿主需提供 `fs` 服务(凡带内置 read/write 工具的 profile 都有)。
|
|
72
38
|
|
|
73
|
-
##
|
|
39
|
+
## 注意事项
|
|
74
40
|
|
|
75
|
-
|
|
41
|
+
- 所有路径限制在会话工作目录内;`overwrite` 默认 `false`。
|
|
42
|
+
- 读取接受任意真实包(STORE/DEFLATE),带 zip 炸弹防御;更新遇到含二进制部件的包会明确拒绝而非损坏它。
|
|
43
|
+
- PPT 图片为**链接式**(非内嵌):官方 `ctx.fs` 写入通道只支持 UTF-8 文本,包内无法携带二进制图片部件。移动 deck 时请连同图片文件;另注意 PowerPoint 默认阻止外部内容——链接图片会显示为"已阻止自动下载此图片"占位符,需手动启用外部内容(文件 → 信息 → 启用内容,或把目录加入信任中心的可信位置)后才会显示。这是 PowerPoint 的安全策略,不是包结构缺陷。
|
|
44
|
+
- `ppt_create` 回显每个元素的落点坐标;`ppt_read` 对任意 deck 返回同样的几何信息。
|
|
76
45
|
|
|
77
|
-
|
|
78
|
-
|---|---|---|---|
|
|
79
|
-
| `enablePptTools` | boolean | `true` | 注册 `ppt_create` / `ppt_read`。设为 `false` 时本插件只提供 Word/Excel 工具。 |
|
|
46
|
+
## 配置
|
|
80
47
|
|
|
81
|
-
|
|
48
|
+
只有一个选项:`enablePptTools`(默认 `true`)——与 dsh-ppt 等专用演示插件共存时设为 `false`:
|
|
82
49
|
|
|
83
50
|
```yaml
|
|
84
|
-
# profile 的 cordis.patch.yml
|
|
85
51
|
- insert:
|
|
86
52
|
- id: dsh-office-tools
|
|
87
53
|
config:
|
|
88
54
|
enablePptTools: false
|
|
89
55
|
```
|
|
90
56
|
|
|
91
|
-
##
|
|
57
|
+
## 开发
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pnpm install && pnpm run check # typecheck + tests + build
|
|
61
|
+
pnpm run test:e2e # 真实组合 E2E(sandbox-policy + fs-sandbox + tools)
|
|
62
|
+
```
|
|
92
63
|
|
|
93
|
-
-
|
|
94
|
-
- 仓库 topics 建议:`dsh`、`dsh-plugin`、`deepseek-harness`、`office`。
|
|
64
|
+
兼容性:声明的 DSH 0.1.x 区间,以及 `>=0.2.0-rc.1 <0.3.0-0`;逐版本的实测记录见 `package.json`(`dsh.compatibility.dshReleases`)。CI 验证 0.1.2-rc.1 和 0.2.0-rc.1,尚未声明支持 DSH 0.3.x。
|
|
95
65
|
|
|
96
|
-
|
|
66
|
+
生成文件最多 50 MiB;PPT 最多 200 页(包含可选封面)。图片仍为外部链接。分层架构与真实图片嵌入的迁移方案见 [架构分析](docs/ARCHITECTURE.zh.md)。
|
|
97
67
|
|
|
98
|
-
-
|
|
99
|
-
- 读取文件上限 50 MiB(压缩后体积);解压前先校验压缩包自身声明的大小预算(单条目 ≤256 MiB、整包 ≤512 MiB、条目数 ≤100 000),zip 炸弹会被直接拒绝而不是解压;携带 DOCTYPE/ENTITY 声明的 XML 部件一律拒绝。
|
|
100
|
-
- 文本/单元格结果有上限并标记 `truncated`。
|
|
101
|
-
- 创建/更新有行数、单元格数上限,且默认不覆盖已有文件。
|
|
102
|
-
- 不调用 LibreOffice / PowerPoint / Word 等外部进程,所有格式均通过纯 JS 库生成/解析。
|
|
103
|
-
- 插件自身代码零文件系统直接访问——`src/` 中没有任何 `node:fs` 导入,所有字节经官方、用户可见的 `ctx.fs` 服务流动。这让第三方商店自动化可以确定性核验全部运行时源码(DSH Store #334:1.0.0 通过完整的自动低风险策略——零运行时依赖、零文件/网络/命令/凭据信号、有界源码、逐版本精确兼容声明)。
|
|
104
|
-
- 生成的包是纯 ASCII 的 STORE 型 zip(规划器为每个 XML 部件做尾部填充并做槽位对齐,让 CRC/大小/偏移字段全部字节安全),因此能以字节一致的方式通过官方 UTF-8 文本通道落盘;非 ASCII 文本编码为 XML 字符引用,各 Office 套件均可正常打开。
|
|
105
|
-
- `word_update`/`excel_update` 经文本通道重发布:适用于全部部件均为文本的包(本插件生成的文件必然满足;不含二进制媒体的 OOXML 包也满足),携带二进制媒体(内嵌图片/字体)的包会被明确拒绝而非损坏。
|
|
106
|
-
- 图片为链接式(非内嵌):模型完全掌控摆放(英寸坐标 x/y/w/h、contain/cover 裁剪、alt 文本;PNG/JPG/GIF 文件头会被嗅探,省略尺寸时按原图大小),deck 引用 workspace 中的图片文件——移动 deck 时请连同图片文件,这是零二进制包的取舍。
|
|
107
|
-
- 版本路线见 [docs/ROADMAP.md](docs/ROADMAP.md)。
|
|
68
|
+
更多文档:[DEVELOPMENT.md](docs/DEVELOPMENT.md) · [ROADMAP.md](docs/ROADMAP.md) · [hub-registration.md](docs/hub-registration.md) · MIT [License](LICENSE)
|
package/dsh.plugin.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-office-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"description": "Office tools for the model: create, read, and update Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) files inside the session workspace through the official DSH filesystem service.",
|
|
6
6
|
"engines": {
|
|
7
|
-
"dsh": "
|
|
7
|
+
"dsh": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0 || >=0.2.0-rc.1 <0.3.0-0"
|
|
8
8
|
},
|
|
9
9
|
"contributes": {
|
|
10
10
|
"tools": [
|
package/lib/index.js
CHANGED
|
@@ -52,68 +52,100 @@ var DOS_DATE = 2026 - 1980 << 9 | 1 << 5 | 1;
|
|
|
52
52
|
var LOCAL_HEADER_BYTES = 30;
|
|
53
53
|
var CENTRAL_HEADER_BYTES = 46;
|
|
54
54
|
var EOCD_BYTES = 22;
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
var MAX_SAFE_U16 = 32639;
|
|
56
|
+
var CRC_SUFFIX_BYTES = 8;
|
|
57
|
+
function nextSafeField(value) {
|
|
58
|
+
let candidate = value;
|
|
59
|
+
for (let byte = 0; byte < 4; byte += 1) {
|
|
60
|
+
const unit = 2 ** (8 * byte);
|
|
61
|
+
if (Math.floor(candidate / unit) % 256 > 127) {
|
|
62
|
+
const band = unit * 256;
|
|
63
|
+
candidate = (Math.floor(candidate / band) + 1) * band;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!safeField(candidate)) throw new Error("ASCII-safe ZIP field exceeds its representable range");
|
|
67
|
+
return candidate;
|
|
68
|
+
}
|
|
69
|
+
function safeCrcSuffix(state) {
|
|
70
|
+
for (let variant = 0; variant < 256; variant += 1) {
|
|
71
|
+
let folded = state;
|
|
72
|
+
let suffix = "";
|
|
73
|
+
for (let bit = 0; bit < CRC_SUFFIX_BYTES; bit += 1) {
|
|
74
|
+
const byte = variant & 1 << bit ? 9 : 32;
|
|
75
|
+
suffix += String.fromCharCode(byte);
|
|
76
|
+
folded = crcFold(folded, byte);
|
|
77
|
+
}
|
|
78
|
+
const crc = (folded ^ 4294967295) >>> 0;
|
|
79
|
+
if (safeField(crc)) return { suffix, crc };
|
|
80
|
+
}
|
|
81
|
+
throw new Error("internal error: trailing XML whitespace cannot produce a byte-safe CRC");
|
|
82
|
+
}
|
|
83
|
+
function extraField(total) {
|
|
84
|
+
if (total === 0) return "";
|
|
85
|
+
return u16(0) + u16(total - 4) + "\0".repeat(total - 4);
|
|
86
|
+
}
|
|
87
|
+
function feasibleExtraLength(end) {
|
|
88
|
+
if (safeField(end)) return 0;
|
|
89
|
+
let total = nextSafeField(Math.max(4, nextSafeField(end) - end));
|
|
90
|
+
while (total <= MAX_SAFE_U16) {
|
|
91
|
+
if (!safeField(total - 4)) {
|
|
92
|
+
total = nextSafeField(total + 4);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const next = nextSafeField(end + total);
|
|
96
|
+
if (next === end + total) return total;
|
|
97
|
+
total = nextSafeField(total + next - (end + total));
|
|
98
|
+
}
|
|
99
|
+
return void 0;
|
|
60
100
|
}
|
|
61
101
|
function planEntries(parts) {
|
|
62
102
|
const planned = [];
|
|
63
103
|
let offset = 0;
|
|
64
104
|
for (const part of parts) {
|
|
65
105
|
assertAscii(part.name, "zip entry name");
|
|
106
|
+
assertAscii(part.content, "zip entry content");
|
|
66
107
|
const nameLength = part.name.length;
|
|
67
108
|
const headerSize = LOCAL_HEADER_BYTES + nameLength;
|
|
68
109
|
const baseLength = part.content.length;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
let entryNext = 0;
|
|
72
|
-
for (let growth = 0; growth < 512 && chosen === void 0; growth += 1) {
|
|
73
|
-
const budget = slots * SLOT_BYTES - headerSize - baseLength;
|
|
74
|
-
if (budget < 0) {
|
|
75
|
-
slots += 1;
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
let state = contentCrcState(part.content);
|
|
79
|
-
for (let pad = 0; pad <= budget; pad += 1) {
|
|
80
|
-
if (pad > 0) state = crcFold(state, 10);
|
|
81
|
-
const length = baseLength + pad;
|
|
82
|
-
if (!safeField(length)) continue;
|
|
83
|
-
if (!safeField((state ^ 4294967295) >>> 0)) continue;
|
|
84
|
-
const content = pad === 0 ? part.content : part.content + "\n".repeat(pad);
|
|
85
|
-
chosen = { content, crc: (state ^ 4294967295) >>> 0 };
|
|
86
|
-
entryNext = skipUnsafeBand(offset + slots * SLOT_BYTES);
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
if (chosen === void 0) slots += 1;
|
|
110
|
+
if (!safeField(nameLength) || nameLength > MAX_SAFE_U16) {
|
|
111
|
+
throw new Error(`zip entry name is too long or has a non-byte-safe length: "${part.name}"`);
|
|
90
112
|
}
|
|
91
|
-
|
|
92
|
-
|
|
113
|
+
let length = nextSafeField(baseLength + CRC_SUFFIX_BYTES);
|
|
114
|
+
let extraLength;
|
|
115
|
+
for (; ; ) {
|
|
116
|
+
const end = offset + headerSize + length;
|
|
117
|
+
if (end > MAX_OFFICE_FILE_BYTES) throw new Error("generated Office package exceeds the 50 MiB write budget");
|
|
118
|
+
extraLength = feasibleExtraLength(end);
|
|
119
|
+
if (extraLength !== void 0) break;
|
|
120
|
+
length = nextSafeField(length + Math.max(1, nextSafeField(end) - end - MAX_SAFE_U16));
|
|
93
121
|
}
|
|
122
|
+
const pad = length - baseLength - CRC_SUFFIX_BYTES;
|
|
123
|
+
let state = contentCrcState(part.content);
|
|
124
|
+
for (let index = 0; index < pad; index += 1) state = crcFold(state, 10);
|
|
125
|
+
const { suffix, crc } = safeCrcSuffix(state);
|
|
94
126
|
planned.push({
|
|
95
127
|
name: part.name,
|
|
96
|
-
content:
|
|
97
|
-
crc
|
|
128
|
+
content: part.content + "\n".repeat(pad) + suffix,
|
|
129
|
+
crc,
|
|
98
130
|
offset,
|
|
99
|
-
localExtraLength:
|
|
131
|
+
localExtraLength: extraLength,
|
|
100
132
|
commentLength: 0,
|
|
101
133
|
centralExtraLength: 0
|
|
102
134
|
});
|
|
103
|
-
offset
|
|
135
|
+
offset += headerSize + extraLength + length;
|
|
104
136
|
}
|
|
105
137
|
const baseDirectorySize = planned.reduce((sum, entry) => sum + CENTRAL_HEADER_BYTES + entry.name.length, 0);
|
|
106
138
|
let commentLength = -1;
|
|
107
|
-
let centralExtraLength =
|
|
108
|
-
for (;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
commentLength
|
|
139
|
+
let centralExtraLength = -1;
|
|
140
|
+
for (let comment = 0; comment <= MAX_SAFE_U16; comment = nextSafeField(comment + 1)) {
|
|
141
|
+
const extra = feasibleExtraLength(baseDirectorySize + comment);
|
|
142
|
+
if (extra !== void 0) {
|
|
143
|
+
centralExtraLength = extra;
|
|
144
|
+
commentLength = comment;
|
|
145
|
+
break;
|
|
113
146
|
}
|
|
114
|
-
if (commentLength <= 127) break;
|
|
115
147
|
}
|
|
116
|
-
if (
|
|
148
|
+
if (commentLength < 0 || centralExtraLength < 0) {
|
|
117
149
|
throw new Error("cannot lay out an ASCII-safe central directory size");
|
|
118
150
|
}
|
|
119
151
|
if (planned.length > 0) {
|
|
@@ -124,10 +156,29 @@ function planEntries(parts) {
|
|
|
124
156
|
return { entries: planned, directoryOffset: offset };
|
|
125
157
|
}
|
|
126
158
|
function buildAsciiZip(parts) {
|
|
127
|
-
if (parts.length === 0 || parts.length >
|
|
128
|
-
throw new Error(`an ASCII-safe package holds 1
|
|
129
|
-
}
|
|
130
|
-
const
|
|
159
|
+
if (parts.length === 0 || parts.length > MAX_SAFE_U16) {
|
|
160
|
+
throw new Error(`an ASCII-safe package holds 1..${MAX_SAFE_U16} entries, got ${parts.length}`);
|
|
161
|
+
}
|
|
162
|
+
const count = nextSafeField(parts.length);
|
|
163
|
+
const names = new Set(parts.map((part) => part.name));
|
|
164
|
+
if (names.size !== parts.length) throw new Error("cannot write a zip archive with duplicate entry names");
|
|
165
|
+
const expanded = [...parts];
|
|
166
|
+
const paddingNames = [];
|
|
167
|
+
for (let index = 1; expanded.length < count; index += 1) {
|
|
168
|
+
const name2 = `dshPadding/pad${index}.xml`;
|
|
169
|
+
if (names.has(name2)) continue;
|
|
170
|
+
names.add(name2);
|
|
171
|
+
paddingNames.push(name2);
|
|
172
|
+
expanded.push({ name: name2, content: '<padding xmlns="urn:dsh-office-tools:padding"/>' });
|
|
173
|
+
}
|
|
174
|
+
const typesIndex = expanded.findIndex((part) => part.name === "[Content_Types].xml");
|
|
175
|
+
if (paddingNames.length > 0 && typesIndex >= 0 && !/<Default\b[^>]*\bExtension=["']xml["']/i.test(expanded[typesIndex].content)) {
|
|
176
|
+
const original = expanded[typesIndex];
|
|
177
|
+
const overrides = paddingNames.map((name2) => `<Override PartName="/${name2}" ContentType="application/xml"/>`).join("");
|
|
178
|
+
if (!/<\/(?:\w+:)?Types\s*>/.test(original.content)) throw new Error("cannot add padding parts to malformed content types");
|
|
179
|
+
expanded[typesIndex] = { ...original, content: original.content.replace(/<\/(?:\w+:)?Types\s*>/, `${overrides}$&`) };
|
|
180
|
+
}
|
|
181
|
+
const plan = planEntries(expanded);
|
|
131
182
|
const planned = plan.entries;
|
|
132
183
|
const local = [];
|
|
133
184
|
const central = [];
|
|
@@ -135,7 +186,9 @@ function buildAsciiZip(parts) {
|
|
|
135
186
|
for (const entry of planned) {
|
|
136
187
|
const nameLength = entry.name.length;
|
|
137
188
|
const length = entry.content.length;
|
|
138
|
-
if (entry.offset
|
|
189
|
+
if (entry.offset !== cursor) {
|
|
190
|
+
throw new Error(`internal error: zip entry "${entry.name}" is not contiguous (planned ${entry.offset}, actual ${cursor})`);
|
|
191
|
+
}
|
|
139
192
|
local.push(
|
|
140
193
|
"PK",
|
|
141
194
|
u16(20),
|
|
@@ -149,7 +202,7 @@ function buildAsciiZip(parts) {
|
|
|
149
202
|
u16(nameLength),
|
|
150
203
|
u16(entry.localExtraLength),
|
|
151
204
|
entry.name,
|
|
152
|
-
|
|
205
|
+
extraField(entry.localExtraLength),
|
|
153
206
|
entry.content
|
|
154
207
|
);
|
|
155
208
|
central.push(
|
|
@@ -171,17 +224,22 @@ function buildAsciiZip(parts) {
|
|
|
171
224
|
u32(0),
|
|
172
225
|
u32(entry.offset),
|
|
173
226
|
entry.name,
|
|
174
|
-
|
|
227
|
+
extraField(entry.centralExtraLength),
|
|
175
228
|
"d".repeat(entry.commentLength)
|
|
176
229
|
);
|
|
177
230
|
cursor = entry.offset + LOCAL_HEADER_BYTES + nameLength + entry.localExtraLength + length;
|
|
178
231
|
}
|
|
179
232
|
const directorySize = central.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
180
233
|
const directoryOffset = plan.directoryOffset;
|
|
234
|
+
if (directoryOffset !== cursor) {
|
|
235
|
+
throw new Error(`internal error: the central directory does not follow the last entry (planned ${directoryOffset}, actual ${cursor})`);
|
|
236
|
+
}
|
|
181
237
|
if (!safeField(directorySize) || !safeField(directoryOffset)) {
|
|
182
238
|
throw new Error("internal error: the planned central directory fields are not ASCII-safe");
|
|
183
239
|
}
|
|
184
|
-
|
|
240
|
+
if (directoryOffset + directorySize + EOCD_BYTES > MAX_OFFICE_FILE_BYTES) {
|
|
241
|
+
throw new Error("generated Office package exceeds the 50 MiB write budget");
|
|
242
|
+
}
|
|
185
243
|
const eocd = [
|
|
186
244
|
"PK",
|
|
187
245
|
u16(0),
|
|
@@ -192,7 +250,7 @@ function buildAsciiZip(parts) {
|
|
|
192
250
|
u32(directoryOffset),
|
|
193
251
|
u16(0)
|
|
194
252
|
].join("");
|
|
195
|
-
const output = [...local,
|
|
253
|
+
const output = [...local, central.join(""), eocd].join("");
|
|
196
254
|
assertAscii(output, "zip output");
|
|
197
255
|
return output;
|
|
198
256
|
}
|
|
@@ -1179,13 +1237,13 @@ function slideXml(shapes) {
|
|
|
1179
1237
|
function notesSlideXml(notes) {
|
|
1180
1238
|
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><p:notes ${A_NS} ${R_NS} ${P_NS}><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr><p:sp><p:nvSpPr><p:cNvPr id="2" name="Notes Placeholder 1"/><p:cNvSpPr><a:spLocks noGrp="1"/></p:cNvSpPr><p:nvPr><p:ph type="body" idx="1"/></p:nvPr></p:nvSpPr><p:spPr><a:xfrm><a:off x="685800" y="1143000"/><a:ext cx="5486400" cy="5029200"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr><p:txBody><a:bodyPr/><a:lstStyle/><a:p><a:r><a:rPr lang="en-US" dirty="0"/><a:t xml:space="preserve">${encodeXmlText(notes)}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:notes>`;
|
|
1181
1239
|
}
|
|
1182
|
-
var THEME_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><a:theme ${A_NS} name="Office"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="44546A"/></a:dk2><a:lt2><a:srgbClr val="E7E6E6"/></a:lt2><a:accent1><a:srgbClr val="4472C4"/></a:accent1><a:accent2><a:srgbClr val="ED7D31"/></a:accent2><a:accent3><a:srgbClr val="A5A5A5"/></a:accent3><a:accent4><a:srgbClr val="FFC000"/></a:accent4><a:accent5><a:srgbClr val="5B9BD5"/></a:accent5><a:accent6><a:srgbClr val="70AD47"/></a:accent6><a:hlink><a:srgbClr val="0563C1"/></a:hlink><a:folHlink><a:srgbClr val="954F72"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Calibri Light"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:lumMod val="110000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:lumMod val="
|
|
1240
|
+
var THEME_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><a:theme ${A_NS} name="Office"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="44546A"/></a:dk2><a:lt2><a:srgbClr val="E7E6E6"/></a:lt2><a:accent1><a:srgbClr val="4472C4"/></a:accent1><a:accent2><a:srgbClr val="ED7D31"/></a:accent2><a:accent3><a:srgbClr val="A5A5A5"/></a:accent3><a:accent4><a:srgbClr val="FFC000"/></a:accent4><a:accent5><a:srgbClr val="5B9BD5"/></a:accent5><a:accent6><a:srgbClr val="70AD47"/></a:accent6><a:hlink><a:srgbClr val="0563C1"/></a:hlink><a:folHlink><a:srgbClr val="954F72"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Calibri Light"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:lumMod val="110000"/><a:satMod val="105000"/><a:tint val="67000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:lumMod val="105000"/><a:satMod val="109000"/><a:tint val="81000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:satMod val="103000"/><a:lumMod val="102000"/><a:tint val="94000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:lumMod val="99000"/><a:satMod val="120000"/><a:shade val="78000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="6350"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="12700"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="19050"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>`;
|
|
1183
1241
|
var SLIDE_MASTER_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><p:sldMaster ${A_NS} ${R_NS} ${P_NS}><p:cSld name="Office">${shapeTree("")}</p:cSld><p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/><p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst><p:txStyles><p:titleStyle><a:lvl1pPr><a:defRPr sz="4400"/></a:lvl1pPr></p:titleStyle><p:bodyStyle><a:lvl1pPr><a:defRPr sz="2400"/></a:lvl1pPr></p:bodyStyle><p:otherStyle><a:lvl1pPr><a:defRPr sz="1800"/></a:lvl1pPr></p:otherStyle></p:txStyles></p:sldMaster>`;
|
|
1184
1242
|
var SLIDE_LAYOUT_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><p:sldLayout ${A_NS} ${R_NS} ${P_NS} type="blank" preserve="1"><p:cSld name="Blank">${shapeTree("")}</p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sldLayout>`;
|
|
1185
1243
|
var NOTES_MASTER_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><p:notesMaster ${A_NS} ${R_NS} ${P_NS}><p:cSld name="Notes">${shapeTree("")}</p:cSld><p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/></p:notesMaster>`;
|
|
1186
|
-
function contentTypesXml(slideCount,
|
|
1244
|
+
function contentTypesXml(slideCount, notesNumbers) {
|
|
1187
1245
|
const slides = Array.from({ length: slideCount }, (_, index) => `<Override PartName="/ppt/slides/slide${index + 1}.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>`).join("");
|
|
1188
|
-
const notes =
|
|
1246
|
+
const notes = notesNumbers.map((number) => `<Override PartName="/ppt/notesSlides/notesSlide${number}.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml"/>`).join("");
|
|
1189
1247
|
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types ${CT_NS}><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/><Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/><Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/><Override PartName="/ppt/notesMasters/notesMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml"/><Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/><Override PartName="/ppt/theme/theme2.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>` + slides + notes + '<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/><Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/></Types>';
|
|
1190
1248
|
}
|
|
1191
1249
|
function presentationXml(slideCount) {
|
|
@@ -1240,13 +1298,15 @@ function validateSlideSpecs(slides) {
|
|
|
1240
1298
|
}
|
|
1241
1299
|
}
|
|
1242
1300
|
function imageLinkTarget(deck, image) {
|
|
1243
|
-
const
|
|
1244
|
-
const
|
|
1301
|
+
const deckPath = deck.absolute.replace(/\\/g, "/");
|
|
1302
|
+
const imagePath = image.absolute.replace(/\\/g, "/");
|
|
1303
|
+
const deckParts = deckPath.split("/").filter(Boolean).slice(0, -1);
|
|
1304
|
+
const imageParts = imagePath.split("/").filter(Boolean);
|
|
1245
1305
|
let common = 0;
|
|
1246
1306
|
while (common < deckParts.length && common < imageParts.length - 1 && deckParts[common] === imageParts[common]) common += 1;
|
|
1247
1307
|
const up = deckParts.length - common;
|
|
1248
1308
|
const relative2 = [...Array.from({ length: up }, () => ".."), ...imageParts.slice(common)].join("/");
|
|
1249
|
-
return relative2.startsWith("../") || relative2 === "" ?
|
|
1309
|
+
return relative2.startsWith("../") || relative2 === "" ? imagePath : relative2;
|
|
1250
1310
|
}
|
|
1251
1311
|
async function placeImage(exec, ctx, deck, image, slideIndex, imageIndex) {
|
|
1252
1312
|
const resolved = await resolveOfficePath(exec, ctx, image.path, IMAGE_EXTENSIONS, true);
|
|
@@ -1254,7 +1314,7 @@ async function placeImage(exec, ctx, deck, image, slideIndex, imageIndex) {
|
|
|
1254
1314
|
if (info !== void 0 && (info.size ?? 0) > MAX_IMAGE_BYTES) {
|
|
1255
1315
|
throw new Error(`slide ${slideIndex + 1} image ${imageIndex + 1} "${image.path}" is ${info.size} bytes; maximum linked image size is ${MAX_IMAGE_BYTES} bytes`);
|
|
1256
1316
|
}
|
|
1257
|
-
const head = await ctx.fs.readBytes(resolved.target, exec.signal,
|
|
1317
|
+
const head = await ctx.fs.readBytes(resolved.target, exec.signal, Math.max(1024, info?.size ?? 0));
|
|
1258
1318
|
const intrinsic = sniffImageSize(head.subarray(0, Math.min(head.byteLength, 1024)));
|
|
1259
1319
|
const target = imageLinkTarget(deck, resolved);
|
|
1260
1320
|
const naturalW = intrinsic === void 0 ? void 0 : intrinsic.width * EMU_PER_PIXEL / EMU_PER_INCH;
|
|
@@ -1384,6 +1444,7 @@ async function buildPptxText(args, exec, ctx, deck) {
|
|
|
1384
1444
|
}
|
|
1385
1445
|
const slideCount = builds.length;
|
|
1386
1446
|
if (slideCount === 0) throw new Error("ppt_create needs a title or at least one slide");
|
|
1447
|
+
if (slideCount > 200) throw new Error("too many slides including the title slide (maximum 200)");
|
|
1387
1448
|
for (const [slideIndex, build] of builds.entries()) {
|
|
1388
1449
|
const images = build.spec.images ?? [];
|
|
1389
1450
|
build.images = [];
|
|
@@ -1391,10 +1452,10 @@ async function buildPptxText(args, exec, ctx, deck) {
|
|
|
1391
1452
|
build.images.push(await placeImage(exec, ctx, deck, image, slideIndex, imageIndex));
|
|
1392
1453
|
}
|
|
1393
1454
|
}
|
|
1394
|
-
const
|
|
1455
|
+
const notesNumbers = builds.map((build, index) => build.spec.notes !== void 0 && build.spec.notes.trim() !== "" ? index + 1 : 0).filter((number) => number > 0);
|
|
1395
1456
|
const layout = [];
|
|
1396
1457
|
const parts = [
|
|
1397
|
-
{ name: "[Content_Types].xml", content: contentTypesXml(slideCount,
|
|
1458
|
+
{ name: "[Content_Types].xml", content: contentTypesXml(slideCount, notesNumbers) },
|
|
1398
1459
|
{ name: "_rels/.rels", content: ROOT_RELS_XML },
|
|
1399
1460
|
{ name: "ppt/presentation.xml", content: presentationXml(slideCount) },
|
|
1400
1461
|
{ name: "ppt/_rels/presentation.xml.rels", content: presentationRelsXml(slideCount) },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-office-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "DSH model-facing Office tools: create, read, and update Word (.docx), Excel (.xlsx), and PowerPoint (.pptx) files inside the session workspace, entirely through the official DSH filesystem service.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -18,14 +18,15 @@
|
|
|
18
18
|
"patch": "./cordis.patch.yml"
|
|
19
19
|
},
|
|
20
20
|
"compatibility": {
|
|
21
|
-
"dsh": "
|
|
21
|
+
"dsh": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0 || >=0.2.0-rc.1 <0.3.0-0",
|
|
22
22
|
"dshReleases": {
|
|
23
23
|
"0.1.1-rc.2": "compatible",
|
|
24
24
|
"0.1.2-alpha.4": "compatible",
|
|
25
25
|
"0.1.2-alpha.5": "compatible",
|
|
26
26
|
"0.1.2-rc.1": "compatible",
|
|
27
27
|
"0.1.5-rc.1": "compatible",
|
|
28
|
-
"0.1.5-rc.2": "compatible"
|
|
28
|
+
"0.1.5-rc.2": "compatible",
|
|
29
|
+
"0.2.0-rc.1": "compatible"
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
},
|
|
@@ -48,11 +49,11 @@
|
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
51
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
51
|
-
"@deepseek-ai/dsh-agent": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0",
|
|
52
|
-
"@deepseek-ai/dsh-fs": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0",
|
|
53
|
-
"@deepseek-ai/dsh-llm": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0",
|
|
54
|
-
"@deepseek-ai/dsh-session": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0",
|
|
55
|
-
"@deepseek-ai/dsh-tools": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0"
|
|
52
|
+
"@deepseek-ai/dsh-agent": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0 || >=0.2.0-rc.1 <0.3.0-0",
|
|
53
|
+
"@deepseek-ai/dsh-fs": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0 || >=0.2.0-rc.1 <0.3.0-0",
|
|
54
|
+
"@deepseek-ai/dsh-llm": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0 || >=0.2.0-rc.1 <0.3.0-0",
|
|
55
|
+
"@deepseek-ai/dsh-session": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0 || >=0.2.0-rc.1 <0.3.0-0",
|
|
56
|
+
"@deepseek-ai/dsh-tools": "^0.1.0-rc.6 || ^0.1.1-rc.0 || ^0.1.2-alpha.0 || ^0.1.5-alpha.0 || >=0.2.0-rc.1 <0.3.0-0"
|
|
56
57
|
},
|
|
57
58
|
"peerDependenciesMeta": {
|
|
58
59
|
"@deepseek-ai/cordis": {
|
|
@@ -87,8 +88,10 @@
|
|
|
87
88
|
"@deepseek-ai/dsh-tools": "0.1.2-rc.1",
|
|
88
89
|
"@deepseek-ai/schemastery": "^3.18.2",
|
|
89
90
|
"@types/node": "^24.0.0",
|
|
91
|
+
"@types/semver": "7.7.1",
|
|
90
92
|
"esbuild": "^0.25.0",
|
|
91
93
|
"jszip": "^3.10.1",
|
|
94
|
+
"semver": "7.8.5",
|
|
92
95
|
"typescript": "^5.6.0",
|
|
93
96
|
"vitest": "^4.1.8",
|
|
94
97
|
"xlsx": "^0.18.5"
|
|
@@ -150,7 +153,8 @@
|
|
|
150
153
|
"0.1.2-alpha.5",
|
|
151
154
|
"0.1.2-rc.1",
|
|
152
155
|
"0.1.5-rc.1",
|
|
153
|
-
"0.1.5-rc.2"
|
|
156
|
+
"0.1.5-rc.2",
|
|
157
|
+
"0.2.0-rc.1"
|
|
154
158
|
]
|
|
155
159
|
},
|
|
156
160
|
"capability": {
|