refactor(skills): 本地安装改成「README 式说明」,install.sh/requirements.txt 归服务器
按三条原则收紧: 1) 线上零影响:office/install.sh 回退成原来的 linux-only 版本(本地本来就不该跑它); image-process 的字体候选表撤回(那是在代码里写环境兼容,方向错了)。 2) install.sh / requirements.txt 只做服务器工件:镜像构建与 agent-executor-init 读它们, 行为一字未变。 3) 本机缺东西时由 .md 指路,模型自己去装:四个技能各加 INSTALL.md(具体命令 + 平台 资产/字体表 + 验证方式),并在 SKILL.md 里各加一行指向它(skill get 就能看到)。 报错文案带上 INSTALL.md 的绝对路径,所以「撞到缺依赖」的那一刻就能拿到说明书。 保留的两处代码钩子都不是环境探测,而是「说明书里写的安装方式得真能生效」: - office: start.sh 把 skills/office/scripts 塞进 PATH(本地没 root 写 /usr/local/bin); 封装层 ENOENT 指向 INSTALL.md。 - x2pdf: find_soffice() 探 macOS app bundle(brew cask 装的 soffice 不在 PATH); WeasyPrint 不可用时回落 LibreOffice,让本地只需一个后端而不是 pango+WeasyPrint 两条链。 INSTALL.md 里 officecli 指向 releases/latest(它会自更新,实测 1.0.157 跑一次变 1.0.160), 不要求与服务器 pin 对齐。 实测:office --version / office create / office view outline 正常;x2pdf 缺 markdown 与 image-process 缺字体两条报错都给出 INSTALL.md 绝对路径,按 font 参数即通过。
This commit is contained in:
+23
-13
@@ -277,21 +277,31 @@ health 只作为「端口上有服务但不是本启动器拉起的」兜底提
|
||||
需要系统库的包(`weasyprint` → pango/cairo)pip 装不了,仍需用户 `brew install`;这类不在
|
||||
自动修复范围内,模型只报结论。
|
||||
|
||||
### 4.14 `office` 本地化:平台矩阵 + PATH 直塞,不碰 `app/`
|
||||
### 4.14 本地安装:`install.sh` / `requirements.txt` 归服务器,本机走 `INSTALL.md`
|
||||
|
||||
`office` 技能是 `SKILL.md` + `scripts/office`(Node 封装层)+ `bin/officecli`(.NET 单文件二进制)。
|
||||
本地化只做两件小事:
|
||||
原则:**不为了本地去改安装脚本**。`install.sh`(系统依赖/资产)与 `requirements.txt`(Python 包)
|
||||
是服务器工件:镜像构建与 `agent-executor-init` 读它们,行为保持不变;`install.sh` 里只有 apt 与
|
||||
linux-x64 资产,本来也不该在 mac 上跑。
|
||||
|
||||
- **PATH**:服务器上靠镜像里的 `/usr/local/bin/office` 软链;本地没 root 写不了系统目录,
|
||||
本机「真要用到却缺东西」时,由技能自己的 `INSTALL.md` 告诉模型怎么装(`SKILL.md` 里各加一行
|
||||
指向它)。写法是具体命令 + 平台表(哪些包、什么 URL、字体在哪),**不写兼容代码**:没有平台矩阵、
|
||||
没有自动探测多套运行时。“不要尝试兼容所有环境”就是这个意思。
|
||||
|
||||
只有两处代码级的必要钩子,都不是环境探测:
|
||||
|
||||
- **`office` 的 PATH**:服务器靠镜像里的 `/usr/local/bin/office` 软链;本地没 root 写不了系统目录,
|
||||
`start.sh` 起 core 时把 `skills/office/scripts` 直接塞进 `PATH`(脚本自身可执行,不复制、不装软链)。
|
||||
`terminal` 继承 core 的 env,模型调 `office <cmd>` 即命中。
|
||||
- **二进制**:`install.sh` 改成按 `uname -s/-m` 选资产(linux x64/arm64、mac x64/arm64),
|
||||
校验和 pin 到上游 release 的 `SHA256SUMS`(八个平台都有,不用猜);mac 没有 `sha256sum`,
|
||||
用 `shasum -a 256` 兜底。但已经存在的二进制只要能跑就沿用:officecli 会把自己更新到上游
|
||||
latest(实测 1.0.157 跑一次变 1.0.160,大小与 latest 资产完全一致),拿 pin 去比对只会反复
|
||||
重拉 34MB。pin 因此只约束「本次下载的东西」;服务器上卷是 `:ro`,二进制不会漂,仍走 sha 比对。
|
||||
**启动器不预下载**:首次用到时,封装层报错里带 `install.sh` 的绝对路径,
|
||||
模型跑一次即可(~34MB,GitHub 慢时自动换 gh-proxy)。
|
||||
`terminal` 继承 core 的 env,模型调 `office <cmd>` 即命中。报错文案指向 `INSTALL.md` 绝对路径。
|
||||
- **`x2pdf` 的 `find_soffice()`**:`brew install --cask libreoffice` 后 `soffice` 不在 `PATH`
|
||||
(在 `/Applications/LibreOffice.app/Contents/MacOS/`),不探这几个默认位置,`INSTALL.md`
|
||||
里写的“装 LibreOffice 即可”就是假的。同理保留了 WeasyPrint 不可用时回落 LibreOffice:
|
||||
这让本地只需一个后端,而不是 pango + WeasyPrint 两套链。
|
||||
|
||||
`officecli` 会把自己更新到上游 latest(实测 1.0.157 跑一次变 1.0.160),所以 `INSTALL.md` 直接
|
||||
指向 `releases/latest`,不要求与服务器 pin 的版本对齐。
|
||||
|
||||
没做的是预览:预览卡片要 executor 的 `:3100` 网关,本地没有。要补就相当于把
|
||||
`executor/preview.js` 的槽位管理搬进 core,不值得。
|
||||
|
||||
没做的是预览:预览卡片要 executor 的 `:3100` 网关,本地没有。要补就相当于把
|
||||
`executor/preview.js` 的槽位管理搬进 core,不值得。
|
||||
@@ -367,7 +377,7 @@ tail -f local/.runtime/core.log # 以及 npm-install.log / mcp-*.log
|
||||
| Windows 不支持 | `spawn('/bin/sh')`、`process.kill(-pid)`、模型写的 bash 语法都是 POSIX 语义 |
|
||||
| `mint_public_link` 不可用 | 本地 `public_link.base_url` 为空,工具会回明确的「未配置」错误 |
|
||||
| 技能依赖 | 本地不预装:缺包时模型会把包装进 `skills/deps`(`$AGENT_SKILLS_DEPS`,已在该进程 `PYTHONPATH` 里,装完下次运行即生效);连 `python3` 都没有时也由它自己装。怎么装由模型自己决定。需要系统库的包(`weasyprint`→pango/cairo)pip 装不了,仍需手工 `brew install`。服务器上由 `agent-executor-init` 处理 |
|
||||
| `office` 二进制 | 不入库、镜像阶段不下载:首次用到时由模型按报错提示跑一次 `skills/office/install.sh`(按 `uname` 选 linux/mac 资产,下载时校验和 pin 到上游 `SHA256SUMS`,约 34MB;GitHub 慢时自动换 gh-proxy)。不需要 root,装完不需重启。officecli 会自更新到上游 latest,版本比 pin 新属正常 |
|
||||
| `office` 二进制 | 不入库、也不预装:首次用到时封装层报 `binary missing` 并给出同目录 `INSTALL.md` 的绝对路径,模型按它自己下载(`releases/latest`,mac/linux 资产表,~34MB,GitHub 慢就用 gh-proxy)。不需要 root、不需重启。officecli 会自更新到 latest,版本比服务器 pin 的新属正常 |
|
||||
| `office` 预览 | 预览卡片走 core → executor 的 `:3100` 网关,本地没有这个网关 → 点开打不开。文档创建/编辑/读取不受影响 |
|
||||
| 首个 `npm install` 要联网 | 支持 `NPM_REGISTRY` 覆盖源;`app/package-lock.json` 的 `resolved` 已改指向公共 registry(原来钉在内网镜像,外部机器必失败) |
|
||||
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ cd agent
|
||||
|---|---|---|
|
||||
| 语音输入 | `ffmpeg` + 设置页给 `asr` 填上游(`X-ASR-Base-Url` / `X-ASR-Model`) | 麦克风入口自动隐藏(`/api/asr/status` 返回 `enabled:false`),`mcp_asr` 子进程也不启动 |
|
||||
| 技能 | `python3`(仅 Python 类技能需要) | 技能清单照常显示;调 `run.py` 类技能报「入口启动失败」,`office` 这类非 Python 技能不受影响 |
|
||||
| Office 文档(docx/xlsx/pptx) | 首次用到时下载一次 officecli 二进制(约 34MB) | `office` 命令报「binary missing」并给出 `skills/office/install.sh` 绝对路径,按提示跑一次即可(不需要 root、不需重启) |
|
||||
| Office 文档(docx/xlsx/pptx) | 首次用到时下载一次 officecli 二进制(约 34MB) | `office` 命令报「binary missing」并给出同目录 `INSTALL.md` 的路径,按它下载即可(不需 root、不需重启) |
|
||||
| 网页搜索 | 无 | 装了 Node 就有(内置免费后端) |
|
||||
| 图片 / 视频生成 | 设置页给对应 MCP 填上游 key | 调用时报明确的缺参错误 |
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# 本机安装 Python 依赖(document-photo-to-pdf 技能)
|
||||
|
||||
依赖由同目录 `requirements.txt` 声明(服务器 init 按它装;本机自己装)。纯 wheel,无编译、无系统库。
|
||||
下文「技能目录」= `$(dirname "$AGENT_SKILLS_DEPS")/document-photo-to-pdf`。
|
||||
|
||||
```bash
|
||||
python3 -m pip install --target "$AGENT_SKILLS_DEPS" \
|
||||
-r "$(dirname "$AGENT_SKILLS_DEPS")/document-photo-to-pdf/requirements.txt"
|
||||
```
|
||||
|
||||
## 依赖说明
|
||||
|
||||
| 包 | 用途 |
|
||||
|---|---|
|
||||
| `numpy` | 透视校正、统计与阈值计算 |
|
||||
| `Pillow` | 图片读写、缩放、调色 |
|
||||
| `pymupdf` | 生成 PDF(import 名是 `fitz`)与自检渲染 |
|
||||
|
||||
自检渲染优先用系统 `pdftoppm`(poppler,可选);没有就用 `pymupdf`;再不行才落到 `pypdfium2`。
|
||||
`pypdfium2` **不必装**,只在 `pymupdf` 也缺失时才有意义。
|
||||
|
||||
## 验证
|
||||
|
||||
```bash
|
||||
python3 -c "import numpy, PIL, fitz"
|
||||
```
|
||||
|
||||
缺依赖时技能会抛 `ModuleNotFoundError`(最先撞到的是 `numpy`)。装完不需要重启 agent:
|
||||
每次 `skill run` 都是新进程,`$AGENT_SKILLS_DEPS` 已在 `PYTHONPATH` 里。
|
||||
@@ -59,3 +59,7 @@ input_schema:
|
||||
- 一图一纸;同框多纸只取最大。
|
||||
- 建议 ≤20 页;更多或 300dpi 可能超 120s,可分批。
|
||||
- `out/` 里的原图是自然尺寸(不缩放、不调色),页与页尺寸可能不同;PDF 仍按纸张/批次统一。
|
||||
|
||||
## 环境
|
||||
|
||||
缺 Python 依赖时按同目录 `INSTALL.md` 自己装(服务器由镜像 + `requirements.txt` 提供)。
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# 本机安装依赖与字体(image-process 技能)
|
||||
|
||||
下文「技能目录」= `$(dirname "$AGENT_SKILLS_DEPS")/image-process`。
|
||||
|
||||
## Python 包:Pillow
|
||||
|
||||
```bash
|
||||
python3 -m pip install --target "$AGENT_SKILLS_DEPS" \
|
||||
-r "$(dirname "$AGENT_SKILLS_DEPS")/image-process/requirements.txt"
|
||||
python3 -c "import PIL" # 验证
|
||||
```
|
||||
|
||||
## 中文字体:只在 `watermark` 且文字含中文时需要
|
||||
|
||||
技能不内置字体,也不做跨平台查找,只认两条 Linux 路径(镜像里预装文泉驿)。
|
||||
本机缺字体时报「中文水印缺少字体」,这时**传 `font` 参数**指向任意中文字体即可:
|
||||
|
||||
| 平台 | 常见字体路径 |
|
||||
|---|---|
|
||||
| macOS | `/System/Library/Fonts/Hiragino Sans GB.ttc`(简体,推荐)、`/System/Library/Fonts/PingFang.ttc` |
|
||||
| Linux | `/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc` |
|
||||
| Windows | `C:\Windows\Fonts\msyh.ttc` |
|
||||
|
||||
```json
|
||||
{"action":"watermark","input":"a.jpg","text":"机密",
|
||||
"font":"/System/Library/Fonts/Hiragino Sans GB.ttc"}
|
||||
```
|
||||
|
||||
英文/数字水印不需要字体(走 Pillow 内置默认字体)。其余动作(info / convert / resize / crop /
|
||||
compress / slice / grid)只依赖 Pillow。
|
||||
@@ -106,5 +106,5 @@ output_schema:
|
||||
- 本技能**只做确定性图像处理**(转换/缩放/裁剪/压缩/水印/拼图),不含 AI 生成、抠图、换脸、扩图、修复等生成式/语义编辑能力。
|
||||
- 若用户的需求属于"文生图 / AI 修图"等生成式范畴,不要用本技能硬凑,应说明能力边界并推荐第三方工具(豆包、即梦、可灵、Photoshop 等)。
|
||||
- 任何操作都不会覆盖输入原图;输出目录不存在时自动创建。
|
||||
- 中文水印需要字体:优先用 `font` 参数指定;否则依赖系统字体(镜像预装文泉驿,install.sh 会兑底安装)。
|
||||
- 输入依赖预装的 Pillow,无需额外 Python 依赖;系统级字体依赖见 install.sh。
|
||||
- 中文水印需要字体:优先用 `font` 参数指定;否则依赖系统字体(镜像预装文泉驿)。
|
||||
- 输入依赖 Pillow;本机缺 Pillow 或字体时按同目录 `INSTALL.md` 自己装(服务器由镜像 + `requirements.txt` 提供)。
|
||||
|
||||
@@ -34,16 +34,8 @@ NAMED_COLORS = {
|
||||
'purple': (128, 0, 128), 'cyan': (0, 255, 255),
|
||||
}
|
||||
CJK_FONT_CANDIDATES = [
|
||||
# 服务端镜像:文泉驿优先(Pillow 优先若用 Noto 的 ttc,索引 0 是 JP 字型)
|
||||
'/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc',
|
||||
'/usr/share/fonts/truetype/wqy/wqy-microhei.ttc',
|
||||
# 本地端:macOS/Windows 的中文字体不在上面这些路径里。
|
||||
# 索引 0 的字面不同:Hiragino Sans GB 是简体(W3 常规),PingFang.ttc 是 HK 字形,Songti 是 Black。
|
||||
'/System/Library/Fonts/Hiragino Sans GB.ttc',
|
||||
'/System/Library/Fonts/PingFang.ttc',
|
||||
'/System/Library/Fonts/Supplemental/Songti.ttc',
|
||||
r'C:\Windows\Fonts\msyh.ttc',
|
||||
r'C:\Windows\Fonts\simsun.ttc',
|
||||
]
|
||||
# Noto 只作最后兑底:Pillow(FreeType) 能读它的 CFF 轮廓,但 ttc 默认字型(索引 0)是 JP 字形,
|
||||
# 中文水印会出日式写法;因此系统文泉驿(CJK_FONT_CANDIDATES)排在它前面。
|
||||
@@ -257,7 +249,8 @@ def action_watermark(img, fmt, args):
|
||||
if font_path:
|
||||
font = ImageFont.truetype(font_path, font_size)
|
||||
elif need_cjk:
|
||||
raise ValueError('中文水印缺少字体:传 font 参数指定 TTF/TTC 路径即可(系统字体列表里没找到中文字体)')
|
||||
raise ValueError('中文水印缺少字体:传 font 参数(TTF/TTC 路径);各平台常见字体路径见 %s'
|
||||
% (Path(__file__).resolve().parent / 'INSTALL.md'))
|
||||
else:
|
||||
try:
|
||||
font = ImageFont.load_default(size=font_size)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
# 本机安装 officecli(office 技能)
|
||||
|
||||
技能三件套:本文件同目录的 `SKILL.md`(用法)、`scripts/office`(Node 封装层,已在 `PATH` 里)、
|
||||
`bin/officecli`(.NET 单文件二进制,**不入库**)。
|
||||
|
||||
服务器上由镜像构建 / `agent-executor-init` 跑同目录的 `install.sh`(只处理 linux-x64)。
|
||||
**本机不要跑 `install.sh`**,按下面自己下:先装才用,不需要重启 agent(封装层每次执行时才解析二进制路径)。
|
||||
|
||||
下文「技能目录」= `$(dirname "$AGENT_SKILLS_DEPS")/office`(本地形态 `AGENT_SKILLS_DEPS` 指向 `<仓库>/skills/deps`)。
|
||||
|
||||
## 1. 下载对应平台的资产
|
||||
|
||||
| 平台 | 资产名 |
|
||||
|---|---|
|
||||
| macOS Apple Silicon | `officecli-mac-arm64` |
|
||||
| macOS Intel | `officecli-mac-x64` |
|
||||
| Linux x64 | `officecli-linux-x64` |
|
||||
| Linux arm64 | `officecli-linux-arm64` |
|
||||
|
||||
```bash
|
||||
mkdir -p "$(dirname "$AGENT_SKILLS_DEPS")/office/bin"
|
||||
curl -fL --progress-bar \
|
||||
-o "$(dirname "$AGENT_SKILLS_DEPS")/office/bin/officecli" \
|
||||
https://github.com/iOfficeAI/OfficeCLI/releases/latest/download/officecli-mac-x64
|
||||
```
|
||||
|
||||
- 用 `latest` 就够(officecli 首次运行也会把自己更新到 latest),不用对齐服务器 pin 的版本。
|
||||
- 国内慢就换源:`https://gh-proxy.com/https://github.com/iOfficeAI/OfficeCLI/releases/latest/download/<资产>`。
|
||||
- 约 34MB,超时/断流就重试;`curl -fL` 失败时不会留下半截文件可用。
|
||||
|
||||
## 2. 赋可执行位并验证
|
||||
|
||||
```bash
|
||||
chmod +x "$(dirname "$AGENT_SKILLS_DEPS")/office/bin/officecli"
|
||||
office --version # 或 office help
|
||||
```
|
||||
|
||||
`office` 命令由本地启动器注入 `PATH` 提供(`skills/office/scripts` 目录),不需要建软链、不需要 root。
|
||||
如果 `office` 不在 PATH(例如手工起 core 没带启动器),可以直接跑
|
||||
`node "$(dirname "$AGENT_SKILLS_DEPS")/office/scripts/office" help`。
|
||||
|
||||
## 3. 装不上怎么办
|
||||
|
||||
封装层会报 `office.core binary missing: <路径>`,说明二进制没到位;文档的创建/编辑/读取全部依赖它,
|
||||
没有它就用别的路子(例如要 PDF 用 `x2pdf` 技能)。**不要**为此改系统目录或去装 .NET 运行时——
|
||||
该二进制是自包含的。
|
||||
@@ -34,4 +34,5 @@ create/open 成功后,用户可自行查看该文档的实时预览(预览
|
||||
## 注意
|
||||
|
||||
- 所有操作文档在任务目录里。
|
||||
- 缺 `bin/officecli`(报 `binary missing`)时:按同目录 `INSTALL.md` 自己装;服务器端由镜像构建 / `agent-executor-init` 提供,本机不要跑 `install.sh`。
|
||||
- `view` 的渲染族(html/screenshot/pdf 等)本环境不可用;要 PDF 用 x2pdf 技能。
|
||||
|
||||
+16
-56
@@ -1,82 +1,39 @@
|
||||
#!/bin/bash
|
||||
# office 技能资产与入口(skills/README 5.2 约定:本脚本在「镜像构建(skills 阶段)」与「启动 init」两处都跑,必须幂等):
|
||||
#
|
||||
# 1) 资产 bin/officecli —— officecli 官方 .NET 单文件二进制,按平台取对应 release 资产:
|
||||
# Linux(x64/arm64) / macOS(x64/arm64)。Windows 暂不支持(要用时手工放置二进制并设 OFFICECLI_BIN)。
|
||||
# 校验和 pin 死,取自上游 release 的 SHA256SUMS(与下面 VER 对应)。注意 officecli 会自更新,
|
||||
# 所以 sha 只约束「本次下载的资产」;已在且能跑的直接沿用(详见下方 usable() 的注释)。
|
||||
# 1) 资产 bin/officecli —— officecli 官方 .NET 单文件二进制(v1.0.157 linux-x64)。
|
||||
# 不进 git(.gitignore 已排除 skills/office/bin/)、不进镜像:init 阶段写进宿主 ./skills 卷,
|
||||
# executor 容器以 :ro 挂到 /workspace/skills —— 运行期只读执行,改动版本=改本文件 pin 重启。
|
||||
# 构建阶段($HERE 在 /tmp 下,产物即弃)跳过下载,只烘 PATH 入口。
|
||||
# 主源 GitHub,备源 gh-proxy(国内网络)。
|
||||
# 主源 GitHub,备源 gh-proxy(国内网络);sha256 必须等于 pin,宁缺毋错。
|
||||
# 2) PATH 入口 /usr/local/bin/office -> <运行期技能根>/scripts/office —— 构建阶段写进镜像层持久;
|
||||
# init 阶段根只读,|| true 静默(镜像里已就位)。
|
||||
# 本地端(macOS)没有写 /usr/local/bin 的权限,这里会静默失败——不影响使用:
|
||||
# local/start.sh 直接把 scripts 目录放进 PATH,本地同样能直接调 `office`。
|
||||
# init 阶段根只读,|| true 静默(镜像里已就位)。officecli 二进制刻意不进 PATH:模型只见封装层。
|
||||
#
|
||||
# 两个源都拉不到:exit 1(init 不写 marker,下次启动自动重试);救急可手动放置同名二进制到
|
||||
# skills/office/bin/officecli(sha 对上即认),再 docker compose up -d 重跑 init。
|
||||
#
|
||||
# 本地首次使用(macOS/Linux):bash skills/office/install.sh,装完即可 `office help`,
|
||||
# 无需重启 agent(封装层每次执行时才解析二进制路径)。
|
||||
set -u
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
VER=v1.0.157
|
||||
SHA=f8eefe88dbfa7464bee421e5421efe57fc26bc3180b30e56eef58594c8245c94
|
||||
ASSET="$HERE/bin/officecli"
|
||||
|
||||
ln -sfn "${EXECUTOR_SKILLS_DIR:-/workspace/skills}/office/scripts/office" /usr/local/bin/office 2>/dev/null || true
|
||||
|
||||
# 构建阶段:PATH 入口已烘,资产交给 init(避免每次 skills 层重建白拉 35MB)。
|
||||
# 放在平台探测之前:构建阶段不下载,也就不该因为构建机架构不被识别而中断镜像构建。
|
||||
# 构建阶段:PATH 入口已烘,资产交给 init(避免每次 skills 层重建白拉 35MB)
|
||||
case "$HERE" in
|
||||
/tmp/*) echo "[office] build stage: PATH 入口就位;bin/officecli 资产由 init 阶段落到技能卷"; exit 0 ;;
|
||||
esac
|
||||
|
||||
# 平台 → 资产名 + 官方校验和(SHA256SUMS@$VER)
|
||||
case "$(uname -s)" in
|
||||
Linux)
|
||||
case "$(uname -m)" in
|
||||
x86_64|amd64) NAME=officecli-linux-x64; SHA=f8eefe88dbfa7464bee421e5421efe57fc26bc3180b30e56eef58594c8245c94 ;;
|
||||
aarch64|arm64) NAME=officecli-linux-arm64; SHA=60db926c8a1371984b9e99622a834777befb02b6f73d0f3fff914ffcc2760d2f ;;
|
||||
*) echo "[office] 不支持的 Linux 架构:$(uname -m)" >&2; exit 1 ;;
|
||||
esac ;;
|
||||
Darwin)
|
||||
case "$(uname -m)" in
|
||||
x86_64) NAME=officecli-mac-x64; SHA=178c1e9ebaf44c24d2b4b359064a5dea6eb7b2f539809871a3de1c09599dff9f ;;
|
||||
arm64) NAME=officecli-mac-arm64; SHA=0dae0990a9cc29688a5d54469f984c34e5b15ab6bbd194a0ffdc571bb9040124 ;;
|
||||
*) echo "[office] 不支持的 macOS 架构:$(uname -m)" >&2; exit 1 ;;
|
||||
esac ;;
|
||||
*)
|
||||
echo "[office] 本平台没有预置资产($(uname -s) $(uname -m)):手工放置二进制到 $ASSET 并设 OFFICECLI_BIN 即可" >&2
|
||||
exit 1 ;;
|
||||
esac
|
||||
|
||||
# macOS 默认没有 sha256sum,只有 shasum
|
||||
sha_of() {
|
||||
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1
|
||||
else shasum -a 256 "$1" | cut -d' ' -f1; fi
|
||||
}
|
||||
|
||||
verify() { [ -f "$ASSET" ] && [ "$(sha_of "$ASSET")" = "$SHA" ]; }
|
||||
|
||||
# 已存在且能跑就算就位:officecli 会自更新到上游 latest(实测 1.0.157 跑一次就变成 1.0.160,
|
||||
# 文件大小与 latest 资产完全一致),拿 sha pin 去比对已跑过的二进制只会反复重拉 34MB。
|
||||
# 校验和的意义因此收窄为「管本次下载的东西」;服务器上卷是 :ro,二进制不会漂,正常仍走 verify。
|
||||
usable() { [ -f "$ASSET" ] && "$ASSET" --version >/dev/null 2>&1; }
|
||||
verify() { [ -f "$ASSET" ] && echo "$SHA $ASSET" | sha256sum -c - >/dev/null 2>&1; }
|
||||
|
||||
if verify; then
|
||||
echo "[office] 资产已就位(sha 匹配):$ASSET"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if usable; then
|
||||
echo "[office] 资产已就位(版本 $("$ASSET" --version 2>/dev/null | head -1),与 pin 的 $VER 不同:officecli 自更新所致)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mkdir -p "$HERE/bin"
|
||||
for u in "https://github.com/iOfficeAI/OfficeCLI/releases/download/$VER/$NAME" \
|
||||
"https://gh-proxy.com/https://github.com/iOfficeAI/OfficeCLI/releases/download/$VER/$NAME"; do
|
||||
for u in "https://github.com/iOfficeAI/OfficeCLI/releases/download/$VER/officecli-linux-x64" \
|
||||
"https://gh-proxy.com/https://github.com/iOfficeAI/OfficeCLI/releases/download/$VER/officecli-linux-x64"; do
|
||||
echo "[office] 拉取 $u (connect<=10s, speed>=100KB/s, max 300s)"
|
||||
t0=$(date +%s)
|
||||
if curl -fL \
|
||||
@@ -87,21 +44,24 @@ for u in "https://github.com/iOfficeAI/OfficeCLI/releases/download/$VER/$NAME" \
|
||||
--retry 1 \
|
||||
--progress-bar \
|
||||
-o "$ASSET.tmp" "$u"; then
|
||||
got="$(sha_of "$ASSET.tmp")"
|
||||
got="$(sha256sum "$ASSET.tmp" | cut -d' ' -f1)"
|
||||
if [ "$got" = "$SHA" ]; then
|
||||
mv -f "$ASSET.tmp" "$ASSET"
|
||||
chmod 755 "$ASSET"
|
||||
echo "[office] officecli $VER ($NAME) -> $ASSET ($(( $(date +%s) - t0 ))s)"
|
||||
echo "[office] officecli $VER installed -> $ASSET ($(( $(date +%s) - t0 ))s)"
|
||||
break
|
||||
fi
|
||||
echo "[office] sha256 mismatch (got $got, want $SHA), trying next source"
|
||||
echo "[office] sha256 mismatch (got $got), trying next source"
|
||||
else
|
||||
echo "[office] $(( $(date +%s) - t0 ))s 后失败: $u"
|
||||
fi
|
||||
rm -f "$ASSET.tmp"
|
||||
done
|
||||
|
||||
if ! verify; then
|
||||
echo "[office] 资产获取失败:两个源都没拿到匹配的二进制。稍后重跑本脚本,或手工放置到 $ASSET" >&2
|
||||
if verify; then
|
||||
echo "[office] 就绪:$ASSET"
|
||||
exit 0
|
||||
else
|
||||
echo "[office] 两个源都拉不到 bin/officecli —— 手动放置 $ASSET(sha 对上即认)后 docker compose up -d 重试" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -92,7 +92,7 @@ try {
|
||||
}
|
||||
if (r.error) {
|
||||
if (r.error.code === 'ENOENT') {
|
||||
err('office.core binary missing: ' + BIN + '\nInstall it: bash ' + path.resolve(__dirname, '..', 'install.sh')
|
||||
err('office.core binary missing: ' + BIN + '\nLocal install steps: ' + path.resolve(__dirname, '..', 'INSTALL.md')
|
||||
+ ' (server: docker compose up -d agent-executor-init)');
|
||||
}
|
||||
err(String(r.error.message || r.error));
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# 本机安装渲染后端(x2pdf 技能)
|
||||
|
||||
两条渲染路径,依赖各不相同。`requirements.txt` 列的是 Python 包(服务器 init 也按它装)。
|
||||
下文「技能目录」= `$(dirname "$AGENT_SKILLS_DEPS")/x2pdf`。
|
||||
|
||||
## 文本类(md / txt / html):默认 WeasyPrint
|
||||
|
||||
```bash
|
||||
python3 -m pip install --target "$AGENT_SKILLS_DEPS" -r "$(dirname "$AGENT_SKILLS_DEPS")/x2pdf/requirements.txt"
|
||||
```
|
||||
|
||||
WeasyPrint 除了 Python 包,还要系统库 pango/cairo:
|
||||
|
||||
- macOS:`brew install pango`
|
||||
- Linux:见同目录 `install.sh`(apt 装 那串 `libpango*` / `libcairo2` / 字体)
|
||||
|
||||
**不想装 pango 也行**:装 LibreOffice(见下),技能在 WeasyPrint 不可用时(缺包或缺 pango 符号)
|
||||
会自动回落到 LibreOffice 渲染文本。代价是 `page` 的边距/页码与大部分 CSS 不生效——够看,不够精确。
|
||||
|
||||
## Office 类(docx / xlsx / pptx / odt / ods / odp):必须 LibreOffice
|
||||
|
||||
- macOS:`brew install --cask libreoffice`
|
||||
装完**不需要**把 `soffice` 加进 `PATH`,技能会自己找 `/Applications/LibreOffice.app/Contents/MacOS/soffice`。
|
||||
- Linux:`apt-get install libreoffice-writer libreoffice-calc libreoffice-impress`(服务器镜像已预装)。
|
||||
|
||||
## 验证
|
||||
|
||||
```bash
|
||||
python3 -c "import weasyprint, markdown" # 文本类(走 WeasyPrint)
|
||||
/Applications/LibreOffice.app/Contents/MacOS/soffice --version # LibreOffice
|
||||
```
|
||||
|
||||
两者都没有时,技能会报「这台机器没有可用的 PDF 渲染后端」。装完不需要重启 agent。
|
||||
@@ -90,3 +90,8 @@ output_schema:
|
||||
```json
|
||||
{"input": "layout.html", "css": "print-override.css"}
|
||||
```
|
||||
|
||||
## 环境
|
||||
|
||||
缺渲染后端时按同目录 `INSTALL.md` 自己装(文本类 WeasyPrint/或 LibreOffice;Office 类必须 LibreOffice)。
|
||||
服务器由镜像 + `requirements.txt` / `install.sh` 提供,本机不要跑 `install.sh`。
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ def find_soffice():
|
||||
|
||||
|
||||
def req_hint():
|
||||
return '依赖清单: %s' % (SKILL_DIR / 'requirements.txt')
|
||||
return '安装步骤: %s(依赖清单 requirements.txt)' % (SKILL_DIR / 'INSTALL.md')
|
||||
|
||||
# 默认样式:黑白友好、打印向。字号用 em 相对值,整体缩放只依赖 html font-size
|
||||
# (由 page.font_size 参数注入),因此压单页只需调小字号/边距。
|
||||
|
||||
Reference in New Issue
Block a user