Skip to content

Commit ca01c2c

Browse files
committed
docs: add automation/help/tools modules and quality improvements
新增模块(41 个文件): - tutorials/automation/:hooks、cron-jobs、webhook、cron-vs-heartbeat、 poll、gmail-pubsub、auth-monitoring、troubleshooting、index - tutorials/help/:faq、debugging、troubleshooting、environment、 scripts、testing、node-issue、index - tutorials/tools/:24 个工具文档,覆盖 browser、exec、skills、 subagents、slash-commands、web、llm-task、firecrawl、lobster 等 配置与导航更新: - config.mts:新增 3 个模块侧边栏路由,顶部导航改为 10 项下拉菜单 - tutorials/index.md:补充 3 个新模块卡片 质量改进(已有文件): - 修复 3 个文件缺失 frontmatter(trusted-proxy-auth、litellm、together) - 批量补全 120 处代码块语言标注(61 个文件) - 统一 help/ 模块末尾导航格式为 `_下一步:[...]_` - 修正 automation/hooks.md 容器语义(info → tip) - 修复 gmail-pubsub.md cron 表达式错误(*/6 → 1) - 修正 agent-send.md 模型 ID(sonnet-4-5 → sonnet-4-6) - 修复 exec.md allowedBinaries 字段说明语义矛盾 - 修复 exec-approvals.md 极端示例(rm -rf /* → rm -rf /) - 修正 chrome-extension.md SSH 命令缺少 -N 标志 - 修复 elevated.md 代码块误标 typescript → text - 统一 multi-agent-sandbox-tools.md frontmatter 标题 - 去除 firecrawl.md 标题括号冗余 - 修正 thinking.md 小标题用词(解决顺序 → 检查顺序) - slash-commands.md 补充内置动作说明
1 parent 651723b commit ca01c2c

82 files changed

Lines changed: 7408 additions & 74 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/.vitepress/config.mts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const tutProvidersCustom: SidebarItem[] = [
8484
{ text: '自定义模型提供商', link: '/tutorials/providers/custom' },
8585
]
8686
const tutConcepts = listMdItems('tutorials/concepts')
87+
const tutAutomation = listMdItems('tutorials/automation')
88+
const tutHelp = listMdItems('tutorials/help')
89+
const tutTools = listMdItems('tutorials/tools')
8790

8891
const SITE_URL = 'https://openclaw-docs.dx3n.cn'
8992

@@ -170,7 +173,21 @@ export default withMermaid(defineConfig({
170173
},
171174
nav: [
172175
{ text: '首页', link: '/' },
173-
{ text: '教程', link: '/tutorials/' },
176+
{
177+
text: '教程',
178+
items: [
179+
{ text: '教程中心', link: '/tutorials/' },
180+
{ text: '快速入门', link: '/tutorials/getting-started/getting-started' },
181+
{ text: '安装部署', link: '/tutorials/installation/' },
182+
{ text: '网关配置', link: '/tutorials/gateway/' },
183+
{ text: '通道接入', link: '/tutorials/channels/' },
184+
{ text: 'AI 模型', link: '/tutorials/providers/' },
185+
{ text: '核心概念', link: '/tutorials/concepts/' },
186+
{ text: '工具系统', link: '/tutorials/tools/' },
187+
{ text: '自动化', link: '/tutorials/automation/' },
188+
{ text: '帮助与调试', link: '/tutorials/help/' },
189+
],
190+
},
174191
{ text: '项目拆解', link: '/beginner-openclaw-guide/' },
175192
{ text: '重点框架', link: '/beginner-openclaw-framework-focus/' },
176193
],
@@ -241,6 +258,33 @@ export default withMermaid(defineConfig({
241258
],
242259
},
243260
],
261+
'/tutorials/tools/': [
262+
{
263+
text: '工具系统',
264+
items: [
265+
{ text: '教程中心', link: '/tutorials/' },
266+
...tutTools,
267+
],
268+
},
269+
],
270+
'/tutorials/automation/': [
271+
{
272+
text: '自动化',
273+
items: [
274+
{ text: '教程中心', link: '/tutorials/' },
275+
...tutAutomation,
276+
],
277+
},
278+
],
279+
'/tutorials/help/': [
280+
{
281+
text: '帮助与故障排查',
282+
items: [
283+
{ text: '教程中心', link: '/tutorials/' },
284+
...tutHelp,
285+
],
286+
},
287+
],
244288
'/beginner-openclaw-guide/': [
245289
{
246290
text: '导航台',
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
---
2+
title: "OAuth 认证监控"
3+
sidebarTitle: "OAuth 认证监控"
4+
---
5+
6+
# OAuth 认证监控(OAuth Token Monitoring)
7+
8+
OAuth 令牌(Token)会过期。当 Token 在凌晨 3 点悄悄失效,你的 Agent 就会停止工作——而你可能要等到早上才发现。这篇文档告诉你如何主动监控 Token 状态,在它过期前自动刷新,保持服务持续运行。
9+
10+
---
11+
12+
## 快速上手
13+
14+
**第一步:检查当前所有 Token 状态**
15+
16+
```bash
17+
openclaw auth status
18+
```
19+
20+
输出示例:
21+
```json5
22+
CHANNEL STATUS EXPIRES_IN SCOPES
23+
gmail valid 6d 14h gmail.readonly, pubsub
24+
slack valid 89d chat:write, channels:read
25+
discord expired - (需要重新授权)
26+
```
27+
28+
**第二步:刷新即将过期的 Token**
29+
30+
```bash
31+
# 刷新指定通道的 Token
32+
openclaw auth refresh --channel gmail
33+
34+
# 刷新所有通道的 Token
35+
openclaw auth refresh --all
36+
```
37+
38+
**第三步:设置自动监控(推荐)**
39+
40+
```json5
41+
{
42+
cron: {
43+
timezone: "Asia/Shanghai",
44+
jobs: [
45+
{
46+
// 每天早上 8 点检查 Token 状态
47+
schedule: "0 8 * * *",
48+
agent: "system-agent",
49+
message: "检查所有 OAuth Token 状态,如有即将过期(7天内)的请提前刷新"
50+
}
51+
]
52+
}
53+
}
54+
```
55+
56+
::: tip 将认证监控纳入日常运维
57+
建议把 Token 状态检查加入到你的日常巡检清单,或者配置 Cron 自动检查,避免服务因认证失效而中断。
58+
:::
59+
60+
---
61+
62+
## 技术说明
63+
64+
### CLI 命令
65+
66+
```bash
67+
# 查看所有通道的认证状态
68+
openclaw auth status
69+
70+
# 输出 JSON 格式(便于脚本处理)
71+
openclaw auth status --json
72+
73+
# 查看指定通道的详细认证信息
74+
openclaw auth status --channel gmail
75+
76+
# 刷新指定通道的 Token
77+
openclaw auth refresh --channel gmail
78+
79+
# 强制重新完整授权(当刷新失败时使用)
80+
openclaw auth login --channel gmail --force
81+
```
82+
83+
---
84+
85+
### 自动化监控脚本
86+
87+
以下是一个简单的 Bash 监控脚本,可以检查 Token 剩余有效期并在即将过期时刷新:
88+
89+
```bash
90+
#!/bin/bash
91+
# check-auth.sh:检查 OAuth Token 有效期
92+
# 建议通过系统 cron 每天运行一次
93+
94+
set -euo pipefail
95+
96+
OPENCLAW_BIN="/usr/local/bin/openclaw"
97+
ALERT_DAYS=7 # 距离过期还有 7 天时触发刷新
98+
99+
# 获取所有通道的 Token 状态(JSON 格式)
100+
STATUS=$($OPENCLAW_BIN auth status --json)
101+
102+
# 检查每个通道的过期时间(需要安装 jq)
103+
echo "$STATUS" | jq -r '.channels[] | "\(.name) \(.expires_in_seconds)"' | \
104+
while read -r channel expires_in; do
105+
THRESHOLD=$((ALERT_DAYS * 86400)) # 转换为秒
106+
107+
if [ "$expires_in" -lt "$THRESHOLD" ]; then
108+
echo "[警告] 通道 $channel 的 Token 将在 $((expires_in / 3600)) 小时内过期,正在刷新..."
109+
$OPENCLAW_BIN auth refresh --channel "$channel"
110+
echo "[完成] 通道 $channel Token 已刷新"
111+
else
112+
echo "[正常] 通道 $channel Token 有效,剩余 $((expires_in / 86400))"
113+
fi
114+
done
115+
```
116+
117+
使用方式:
118+
119+
```bash
120+
# 添加执行权限
121+
chmod +x check-auth.sh
122+
123+
# 手动运行测试
124+
./check-auth.sh
125+
126+
# 添加到系统 cron(每天早上 7 点运行)
127+
echo "0 7 * * * /path/to/check-auth.sh >> /var/log/openclaw-auth.log 2>&1" | crontab -
128+
```
129+
130+
---
131+
132+
### 使用 OpenClaw Cron 自动刷新
133+
134+
不想维护独立脚本?可以直接使用 OpenClaw 的 Cron + Agent 来处理:
135+
136+
```json5
137+
{
138+
cron: {
139+
timezone: "Asia/Shanghai",
140+
jobs: [
141+
{
142+
// 每天早上 7 点执行认证检查
143+
schedule: "0 7 * * *",
144+
agent: "ops-agent",
145+
message: "执行命令 'openclaw auth status --json' 检查所有通道 Token 状态。如果任何通道的 expires_in_seconds 小于 604800(7天),执行 'openclaw auth refresh --channel <name>' 刷新对应 Token,并报告刷新结果。",
146+
isolated: true
147+
}
148+
]
149+
}
150+
}
151+
```
152+
153+
---
154+
155+
### 各通道 Token 特性
156+
157+
| 通道 | Token 类型 | 典型有效期 | 是否支持自动刷新 |
158+
|------|-----------|-----------|----------------|
159+
| Gmail | OAuth 2.0 | Access: 1小时,Refresh: 长期 | 是(通过 Refresh Token)|
160+
| Slack | OAuth 2.0 | 较长(bot token 不过期)| 视配置而定 |
161+
| Discord | Bot Token | 不过期 | 不需要 |
162+
| MS Teams | Azure AD Token | 1小时 | 是(通过 MSAL)|
163+
| WhatsApp | Business API | 60天 | 需要手动刷新 |
164+
165+
::: warning WhatsApp Business API Token 需要手动刷新
166+
WhatsApp Business API 的 Token 有效期为 60 天,且不支持自动刷新。建议:
167+
1. 在日历中设置 50 天提醒
168+
2. 或使用监控脚本检测到期前告警
169+
3. 每次刷新后更新 OpenClaw 配置
170+
:::
171+
172+
---
173+
174+
### 最佳实践
175+
176+
::: tip 认证运维三步法
177+
178+
1. **主动监控**:配置 Cron 每天检查 Token 状态,不要等到失效了才发现
179+
2. **提前刷新**:在 Token 过期前 7 天刷新,留出足够的缓冲时间
180+
3. **告警通知**:配置刷新失败时的告警通道(如发送 Slack 消息),确保人工及时介入
181+
182+
```json5
183+
{
184+
cron: {
185+
jobs: [
186+
{
187+
schedule: "0 7 * * *",
188+
agent: "ops-agent",
189+
message: "检查并刷新即将过期的 OAuth Token,如果刷新失败请通过 Slack 发送告警到 #ops-alerts 频道",
190+
delivery: {
191+
channel: "slack",
192+
target: "#ops-alerts",
193+
// 只在失败时发送
194+
onFailure: true
195+
}
196+
}
197+
]
198+
}
199+
}
200+
```
201+
:::
202+
203+
---
204+
205+
_下一步:[故障排查](./troubleshooting) | [Gmail PubSub 集成](./gmail-pubsub) | [自动化概览](./index)_

0 commit comments

Comments
 (0)