docs: 安装指南改为 npm install,不再需要拉源码 build

- Plugin: npm install -g @uncaged/openclaw-plugin-ograph
- Dispatcher: npm install -g @uncaged/ograph-dispatcher
- 加升级和快速参考章节
- 整理常见问题

— 小墨 🖊️(KUMA Team)
This commit is contained in:
小墨 🖊️ 2026-04-13 11:36:41 +00:00
parent 47619f4a16
commit ffe319e1d6

View File

@ -1,6 +1,6 @@
# OGraph Task 集成安装指南 # OGraph Task 集成安装指南
> 在 OpenClaw 上安装 OGraph Plugin + Dispatcher,让你的 Agent 自动接收和处理任务。 > 两条命令安装,五分钟跑通。让你的 Agent 自动接收和处理任务。
--- ---
@ -17,10 +17,10 @@ graph LR
你需要安装两个组件: 你需要安装两个组件:
| 组件 | 作用 | 运行方式 | | 组件 | npm 包 | 作用 |
|------|------|---------| |------|--------|------|
| **OGraph Plugin** | 接收 Dispatcher 推送,管理 agent session | OpenClaw 插件,随 Gateway 启动 | | **OGraph Plugin** | `@uncaged/openclaw-plugin-ograph` | 接收推送,管理 agent session |
| **Dispatcher** | 轮询 OGraph 事件流,发现新任务推给 Plugin | 独立 Node.js 进程 | | **Dispatcher** | `@uncaged/ograph-dispatcher` | 轮询事件流,推给 Plugin |
--- ---
@ -28,7 +28,6 @@ graph LR
- [x] OpenClaw 已安装并运行(参考 [OpenClaw 安装指南](openclaw-install-guide.md)) - [x] OpenClaw 已安装并运行(参考 [OpenClaw 安装指南](openclaw-install-guide.md))
- [x] Node.js v20+ - [x] Node.js v20+
- [x] Git
- [x] 你的 OGraph Agent ID(没有的话下面会创建) - [x] 你的 OGraph Agent ID(没有的话下面会创建)
--- ---
@ -84,17 +83,17 @@ curl -s -X POST https://ograph.shazhou.workers.dev/events \
## Step 2:安装 OGraph Plugin ## Step 2:安装 OGraph Plugin
### 2.1 克隆 Plugin 仓库 ### 2.1 安装
```bash ```bash
cd ~/repos # 或你喜欢的目录 npm install -g @uncaged/openclaw-plugin-ograph
git clone https://github.com/oc-xiaoju/openclaw-plugin-ograph.git
cd openclaw-plugin-ograph
npm install --ignore-scripts && npm run build
``` ```
!!! warning "npm install 报 EPERM?" 查看安装路径(后面配置要用):
如果遇到 `EPERM: operation not permitted, chmod openclaw.mjs`,是因为全局安装的 OpenClaw 文件权限问题。加 `--ignore-scripts` 跳过 postinstall 即可。
```bash
echo $(npm root -g)/@uncaged/openclaw-plugin-ograph
```
### 2.2 注册到 OpenClaw ### 2.2 注册到 OpenClaw
@ -108,14 +107,14 @@ npm install --ignore-scripts && npm run build
], ],
"load": { "load": {
"paths": [ "paths": [
"/absolute/path/to/openclaw-plugin-ograph" "/usr/lib/node_modules/@uncaged/openclaw-plugin-ograph"
] ]
}, },
"entries": { "entries": {
"ograph": { "ograph": {
"enabled": true, "enabled": true,
"config": { "config": {
"secret": "your-gateway-token-here", "secret": "<YOUR_GATEWAY_TOKEN>",
"topics": { "topics": {
"task-execution": { "task-execution": {
"description": "任务执行管理", "description": "任务执行管理",
@ -131,21 +130,23 @@ npm install --ignore-scripts && npm run build
``` ```
!!! warning "路径必须是绝对路径" !!! warning "路径必须是绝对路径"
`load.paths` 里填 clone 目录的**绝对路径**,不能用 `~` `load.paths` 里填 npm 全局安装的**绝对路径**,不能用 `~`
!!! important "secret 字段说明" `npm root -g` 查看你的全局路径:
`config.secret` 字段应填入你的 **OpenClaw Gateway Token**(不是自定义密钥)。 ```bash
echo $(npm root -g)/@uncaged/openclaw-plugin-ograph
获取方法:在 `~/.openclaw/openclaw.json` 中找到 `gateway.auth.token` 的值,复制过来。
```json
"gateway": {
"auth": {
"token": "gw_abcd1234..." // ← 这个值
}
}
``` ```
!!! important "secret = Gateway Token"
`config.secret` 必须填你的 **OpenClaw Gateway Token**(不是自定义密码)。
查看你的 Gateway Token:
```bash
cat ~/.openclaw/openclaw.json | grep -A2 '"auth"'
```
找到 `gateway.auth.token` 的值,填到这里。Dispatcher 的 `agents[].secret` 也要填同一个值。
### 2.3 重启 Gateway ### 2.3 重启 Gateway
```bash ```bash
@ -155,28 +156,21 @@ openclaw gateway restart
验证 Plugin 加载成功: 验证 Plugin 加载成功:
```bash ```bash
# 应该返回 401(unauthorized),说明端点存在
curl -s -X POST http://localhost:18789/plugins/ograph/dispatch \ curl -s -X POST http://localhost:18789/plugins/ograph/dispatch \
-H "Content-Type: application/json" -d '{}' -H "Content-Type: application/json" -d '{}'
``` ```
```json 返回 `{"error":{"message":"Unauthorized"}}` 就对了 ✅(端点存在,鉴权正常)。
{"error": {"message": "Unauthorized", "type": "unauthorized"}} 返回 404 说明 Plugin 没加载成功,检查路径和 `allow` 列表。
```
看到 `Unauthorized` 就对了(没有传 secret)。如果返回 404 说明 Plugin 没加载成功,检查路径和 `allow` 列表。
--- ---
## Step 3:安装 Dispatcher ## Step 3:安装 Dispatcher
### 3.1 克隆并构建 ### 3.1 安装
```bash ```bash
cd ~/repos npm install -g @uncaged/ograph-dispatcher
git clone https://github.com/oc-xiaoju/ograph.git
cd ograph/packages/dispatcher
npm install && npm run build
``` ```
### 3.2 创建配置文件 ### 3.2 创建配置文件
@ -208,7 +202,7 @@ mkdir -p ~/.config/ograph
{ {
"type": "oc-plugin", "type": "oc-plugin",
"url": "http://localhost:18789/plugins/ograph/dispatch", "url": "http://localhost:18789/plugins/ograph/dispatch",
"secret": "your-gateway-token-here", "secret": "<YOUR_GATEWAY_TOKEN>",
"actor": "task-execution" "actor": "task-execution"
} }
], ],
@ -222,37 +216,34 @@ mkdir -p ~/.config/ograph
} }
``` ```
**关键配置说明:** **关键配置:**
| 字段 | 说明 | | 字段 | 说明 |
|------|------| |------|------|
| `discovery.agentId` | 你的 OGraph Agent ID | | `discovery.agentId` | 你的 OGraph Agent ID |
| `discovery.eventTypes` | 监听的事件类型 | | `discovery.eventTypes` | 监听的事件类型 |
| `agents[].secret` | **必须与 OpenClaw Gateway Token 一致**(即 `~/.openclaw/openclaw.json` 中的 `gateway.auth.token` 值) | | `agents[].secret` | **必须与 Step 2 的 `config.secret` 一致**(即 Gateway Token) |
| `agents[].actor` | 对应 Plugin 的 `topics` 里的 key | | `agents[].actor` | 对应 Plugin `topics` 里的 key |
| `intervals.watcherIdle` | 无变化时的 poll 间隔(ms) |
| `intervals.watcherActive` | 有变化时的 poll 间隔(ms) |
### 3.3 启动并验证 ### 3.3 启动并验证
```bash ```bash
cd ~/repos/ograph/packages/dispatcher ograph-dispatcher
npm start
``` ```
!!! warning "代理环境下 fetch 失败?" !!! warning "代理环境下 fetch 失败?"
Node.js 原生 fetch **不读取** `HTTP_PROXY` / `HTTPS_PROXY` 环境变量。如果你的网络需要代理,需要用 undici ProxyAgent 手动注入 Node.js 原生 fetch **不读取** `HTTP_PROXY` / `HTTPS_PROXY` 环境变量。如果你的网络需要代理,创建启动脚本
```js ```js
// start-with-proxy.mjs // start-with-proxy.mjs
import { ProxyAgent, setGlobalDispatcher } from 'undici'; import { ProxyAgent, setGlobalDispatcher } from 'undici';
const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY; const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
if (proxy) setGlobalDispatcher(new ProxyAgent(proxy)); if (proxy) setGlobalDispatcher(new ProxyAgent(proxy));
await import('./dist/index.js'); await import('@uncaged/ograph-dispatcher');
``` ```
```bash ```bash
node start-with-proxy.mjs # 代替 npm start node start-with-proxy.mjs # 代替 ograph-dispatcher
``` ```
正常输出: 正常输出:
@ -276,15 +267,16 @@ npm start
Dispatcher 需要持续运行。用 systemd 管理: Dispatcher 需要持续运行。用 systemd 管理:
```bash ```bash
cat > ~/.config/systemd/user/ograph-dispatcher.service << 'EOF' DISPATCHER_BIN=$(which ograph-dispatcher)
cat > ~/.config/systemd/user/ograph-dispatcher.service << EOF
[Unit] [Unit]
Description=OGraph Dispatcher Description=OGraph Dispatcher
After=network-online.target After=network-online.target
[Service] [Service]
Type=simple Type=simple
WorkingDirectory=%h/repos/ograph/packages/dispatcher ExecStart=$DISPATCHER_BIN
ExecStart=/usr/bin/node dist/index.js
Restart=on-failure Restart=on-failure
RestartSec=10 RestartSec=10
@ -346,15 +338,45 @@ curl -s -X POST "$API/events" \
--- ---
## 快速参考
```bash
# 一键安装
npm install -g @uncaged/openclaw-plugin-ograph @uncaged/ograph-dispatcher
# 查看 Plugin 路径
echo $(npm root -g)/@uncaged/openclaw-plugin-ograph
# 启动 Dispatcher
ograph-dispatcher
# 查看 Dispatcher 配置位置
cat ~/.config/ograph/dispatcher.json
```
---
## 常见问题 ## 常见问题
| 问题 | 原因 | 解决 | | 问题 | 原因 | 解决 |
|------|------|------| |------|------|------|
| Plugin 返回 404 | Plugin 没加载 | 检查 `plugins.allow` 包含 `"ograph"` + `load.paths` 路径正确 | | Plugin 返回 404 | Plugin 没加载 | 检查 `plugins.allow` 包含 `"ograph"` + `load.paths` 路径正确 |
| Dispatcher 连不上 Plugin | gateway token 不匹配 | 确保 dispatcher.json `agents[].secret` 和 openclaw.json `gateway.auth.token` 一致 | | Dispatcher 连不上 Plugin | Gateway Token 不匹配 | 确保 dispatcher.json `agents[].secret` 和 openclaw.json `gateway.auth.token` 一致 |
| Watcher 没发现事件 | agentId 不对 | 确认 `discovery.agentId` 是你的 OGraph Agent ID | | Watcher 没发现事件 | agentId 不对 | 确认 `discovery.agentId` 是你的 OGraph Agent ID |
| Agent 没响应 | session busy / topic 不匹配 | 检查 `agents[].actor` 对应 Plugin `topics` 的 key | | Agent 没响应 | session busy / topic 不匹配 | 检查 `agents[].actor` 对应 Plugin `topics` 的 key |
| `agent #N = unknown` | 没发 profile 事件 | 回到 Step 1 发 `agent_profile_updated` 事件 | | `agent #N = unknown` | 没发 profile 事件 | 回到 Step 1 发 `agent_profile_updated` 事件 |
| npm install 报 EPERM | 全局 OC 权限问题 | 加 `--ignore-scripts``npm install -g --ignore-scripts @uncaged/openclaw-plugin-ograph` |
| fetch 报 network error | 代理环境 | 见 Step 3.3 的代理说明 |
---
## 升级
```bash
npm update -g @uncaged/openclaw-plugin-ograph @uncaged/ograph-dispatcher
openclaw gateway restart
systemctl --user restart ograph-dispatcher
```
--- ---