@xilonglab/oc-docx 1.0.0

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 ADDED
@@ -0,0 +1,34 @@
1
+ # oc-docx
2
+
3
+ OpenClaw 的 DOCX **插件**:逻辑在 **`@xilonglab/js-docx`**(`libs/js-docx`);本仓库提供根目录 **`package.json`(唯一)**、**`openclaw.plugin.json`**、**`extensions/index.js`**(工具实现)、**`skills/docx/SKILL.md`**(技能说明)。
4
+
5
+ ## 布局
6
+
7
+ ```
8
+ oc-docx/
9
+ ├── package.json
10
+ ├── openclaw.plugin.json
11
+ ├── extensions/
12
+ │ └── index.js
13
+ ├── skills/
14
+ │ └── docx/
15
+ │ └── SKILL.md
16
+ └── README.md
17
+ ```
18
+
19
+ ## 安装
20
+
21
+ ```bash
22
+ cd /path/to/oc-docx
23
+ npm install
24
+ ```
25
+
26
+ 根目录 `dependencies` 里默认 `file:../js-docx` 指向同级 `js-docx` 仓库;发布或 CI 可改为 npm 上的 `@xilonglab/js-docx` 版本号。
27
+
28
+ ## OpenClaw
29
+
30
+ 通过 `openclaw plugins install ./path/to/oc-docx`(或链接安装)加载插件;`openclaw.plugin.json` 中的 `skills` 会指向 `skills/docx`。具体启用方式以你所用 OpenClaw 版本文档为准。
31
+
32
+ ## 与 js-docx-mcp
33
+
34
+ MCP 与本插件共用 **`@xilonglab/js-docx`** 导出的 `createDocx`、`editDocx`、`renderXml`、`getXmlReference`、`readDocx`。
@@ -0,0 +1,89 @@
1
+ /**
2
+ * OpenClaw 插件扩展 — 对 @xilonglab/js-docx 的薄封装(与 js-docx-mcp 同源 API)。
3
+ */
4
+
5
+ import jsDocx from '@xilonglab/js-docx';
6
+
7
+ const {
8
+ createDocx,
9
+ editDocx,
10
+ renderXml,
11
+ getXmlReference,
12
+ readDocx,
13
+ } = jsDocx;
14
+
15
+ function ok(payload) {
16
+ return {
17
+ result: typeof payload === 'string' ? payload : JSON.stringify(payload, null, 2),
18
+ };
19
+ }
20
+
21
+ function err(e) {
22
+ return {
23
+ result: JSON.stringify({ success: false, error: e.message }, null, 2),
24
+ error: true,
25
+ };
26
+ }
27
+
28
+ export default {
29
+ async create_docx(args) {
30
+ try {
31
+ const { templatePath, xmlContent, outputPath, data } = args;
32
+ return ok(
33
+ await createDocx({
34
+ templatePath: templatePath ?? null,
35
+ xmlContent,
36
+ outputPath,
37
+ data: data ?? {},
38
+ })
39
+ );
40
+ } catch (e) {
41
+ return err(e);
42
+ }
43
+ },
44
+
45
+ async edit_docx(args) {
46
+ try {
47
+ const { docxPath, xmlContent, outputPath, data } = args;
48
+ return ok(
49
+ await editDocx({
50
+ docxPath,
51
+ xmlContent,
52
+ outputPath,
53
+ data: data ?? {},
54
+ })
55
+ );
56
+ } catch (e) {
57
+ return err(e);
58
+ }
59
+ },
60
+
61
+ async render_xml(args) {
62
+ try {
63
+ const { xmlContent } = args;
64
+ return ok(renderXml({ xmlContent }));
65
+ } catch (e) {
66
+ return err(e);
67
+ }
68
+ },
69
+
70
+ async get_xml_reference() {
71
+ const text = getXmlReference() || 'XML 语法参考文件未找到';
72
+ return ok(text);
73
+ },
74
+
75
+ async read_docx(args) {
76
+ try {
77
+ const { docxPath, includeHeaders = false, includeFooters = false } = args;
78
+ return ok(
79
+ await readDocx({
80
+ docxPath,
81
+ includeHeaders,
82
+ includeFooters,
83
+ })
84
+ );
85
+ } catch (e) {
86
+ return err(e);
87
+ }
88
+ },
89
+ };
@@ -0,0 +1,14 @@
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "../js-docx-mcp"
5
+ },
6
+ {
7
+ "path": "."
8
+ },
9
+ {
10
+ "path": "../js-docx"
11
+ }
12
+ ],
13
+ "settings": {}
14
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": "oc-docx",
3
+ "name": "oc-docx",
4
+ "version": "1.0.0",
5
+ "description": "创建、编辑与读取 DOCX(xl-p / xl-table 等语法)。与 js-docx-mcp 共用 @xilonglab/js-docx。",
6
+ "configSchema": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "properties": {}
10
+ },
11
+ "skills": ["skills/docx"]
12
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@xilonglab/oc-docx",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "OpenClaw DOCX 插件:extensions + skills/docx(依赖 @xilonglab/js-docx)",
6
+ "main": "./extensions/index.js",
7
+ "openclaw": {
8
+ "extensions": ["./extensions/index.js"]
9
+ },
10
+ "scripts": {
11
+ "install:all": "npm install"
12
+ },
13
+ "dependencies": {
14
+ "@xilonglab/js-docx": "file:../js-docx"
15
+ },
16
+ "license": "ISC"
17
+ }
@@ -0,0 +1,62 @@
1
+ ---
2
+ name: docx
3
+ description: 使用 xl 语法创建、编辑、读取 DOCX;工具由本插件 extensions 注册。
4
+ ---
5
+
6
+ # DOCX(xl 语法)
7
+
8
+ 实现位于 **`@xilonglab/js-docx`**;本技能说明何时、如何调用插件暴露的工具。
9
+
10
+ ## 工具一览
11
+
12
+ ### `create_docx`
13
+
14
+ 根据模板与 XML 内容创建新的 DOCX。
15
+
16
+ | 参数 | 类型 | 必填 | 说明 |
17
+ |------|------|------|------|
18
+ | `templatePath` | string | 否 | 模板路径,或内置 `"v"`(竖版)/ `"h"`(横版);省略默认 `v` |
19
+ | `xmlContent` | string | 是 | xl-p、xl-table 等标签的 XML |
20
+ | `outputPath` | string | 是 | 输出 `.docx` 绝对路径或工作区相对路径 |
21
+ | `data` | object | 否 | 模板变量 |
22
+
23
+ ### `edit_docx`
24
+
25
+ 编辑现有 DOCX,替换正文 body。
26
+
27
+ | 参数 | 类型 | 必填 | 说明 |
28
+ |------|------|------|------|
29
+ | `docxPath` | string | 是 | 要编辑的 `.docx` 路径 |
30
+ | `xmlContent` | string | 是 | 新的 xl 语法 XML |
31
+ | `outputPath` | string | 否 | 输出路径;省略则覆盖原文件 |
32
+ | `data` | object | 否 | 模板变量 |
33
+
34
+ ### `render_xml`
35
+
36
+ 将 xl 语法 XML 编译为 WordprocessingML 片段。
37
+
38
+ | 参数 | 类型 | 必填 | 说明 |
39
+ |------|------|------|------|
40
+ | `xmlContent` | string | 是 | xl-p、xl-table 等 |
41
+
42
+ ### `get_xml_reference`
43
+
44
+ 返回 xl 语法参考全文(无参数)。
45
+
46
+ ### `read_docx`
47
+
48
+ 读取 DOCX 正文(及可选页眉页脚),反编译为 xl 风格 XML。
49
+
50
+ | 参数 | 类型 | 必填 | 说明 |
51
+ |------|------|------|------|
52
+ | `docxPath` | string | 是 | `.docx` 路径 |
53
+ | `includeHeaders` | boolean | 否 | 是否包含页眉 |
54
+ | `includeFooters` | boolean | 否 | 是否包含页脚 |
55
+
56
+ ## 权限
57
+
58
+ 插件需要读写工作区文件(`files:read` / `files:write`),与宿主 OpenClaw 配置一致即可。
59
+
60
+ ## 与 js-docx-mcp
61
+
62
+ MCP 与本插件共用 **`@xilonglab/js-docx`** 的 `createDocx`、`editDocx`、`renderXml`、`getXmlReference`、`readDocx`。