mirror of
https://github.com/hanzoai/bot.git
synced 2026-10-30 17:24:26 +00:00
Three coordinated things:
1. Resolve the committed upstream/main merge conflicts. 94 files were
sitting with raw <<<<<<< HEAD ... >>>>>>> upstream/main blocks. Every
conflict had HanzoBot/Bot on HEAD and OpenClaw on upstream. Resolved
by keeping HEAD everywhere — 540 conflict blocks.
2. Rewrite remaining OpenClaw text refs.
OPENCLAW → HANZO_BOT
OpenClaw → HanzoBot (PascalCase type identifiers)
openclaw → bot (codebase convention — botToken,
botUsername etc.; avoids invalid
hyphenated JS identifiers)
openclaw[_]/openclaw[A-Z] → bot[_]/bot[A-Z] (compound)
ai.openclaw.x → ai.hanzo.bot.x (JVM package path)
3. Delete or rename openclaw-named file paths (116 of them). Dead
duplicates with a Bot-named canonical from the partial migration:
deleted. Otherwise renamed.
ai/openclaw/** → deleted (ai/hanzo/bot/** canonical)
Sources/OpenClaw*/ → deleted (Sources/Bot* canonical)
Tests/OpenClawIPCTests/ → deleted (Tests/BotIPCTests canonical)
OpenClawKit/ → deleted (BotKit canonical)
openclaw-tools.*.ts → deleted (bot-tools.*.ts canonical)
openclaw-root.ts etc. → deleted (bot-root.ts canonical)
types.openclaw.ts → deleted (types.bot.ts canonical)
extensions/*/openclaw.plugin.json → renamed hanzo-bot.plugin.json
docs/start/openclaw.md → renamed hanzo-bot.md (+ zh-CN)
docs/assets/openclaw-*.png, whatsapp-openclaw*.jpg → deleted
scripts/.../openclaw-* → deleted (bot/hanzo-bot parallels)
openclaw.mjs → deleted (hanzo-bot.mjs is package.bin)
Then patched 65 broken JS/TS import strings where hanzo-bot had ended
up inside an import path ('./types.hanzo-bot.js' → './types.bot.js'
etc., since the on-disk filename uses the brand-neutral bot- prefix).
Pre-existing lint debt cleaned up to get oxlint --type-aware to 0/0:
removed the dead i18n test that referenced a path no longer existing;
defined the missing DIDConfig and WalletConfig types in types.base.ts
(they were imported but never declared); dropped unused imports;
collapsed redundant type assertion and a tautological meta.bot lookup
that the openclaw→bot rename made redundant.
The a2ui.bundle.js generated artifact is kept at its pre-rebrand
contents — it gets regenerated by 'pnpm canvas:a2ui:bundle' from
sources I cannot rebuild in this commit; the source side is clean.
Verified: 0 occurrences of openclaw (case-insensitive) in tree source
content, 0 file or directory paths with openclaw in the name; oxlint
--type-aware src test reports 0/0.
6.0 KiB
6.0 KiB
read_when, summary, title, x-i18n
| read_when | summary | title | x-i18n | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
用于唤醒和隔离智能体运行的 Webhook 入口 | Webhooks |
|
Webhooks
Gateway 网关可以暴露一个小型 HTTP webhook 端点用于外部触发。
启用
{
hooks: {
enabled: true,
token: "shared-secret",
path: "/hooks",
},
}
注意事项:
- 当
hooks.enabled=true时,hooks.token为必填项。 hooks.path默认为/hooks。
认证
每个请求必须包含 hook 令牌。推荐使用请求头:
Authorization: Bearer <token>(推荐)x-hanzo-bot-token: <token>?token=<token>(已弃用;会记录警告日志,将在未来的主要版本中移除)
端点
POST /hooks/wake
请求体:
{ "text": "System line", "mode": "now" }
text必填(字符串):事件描述(例如"收到新邮件")。mode可选(now|next-heartbeat):是否立即触发心跳(默认now)或等待下一次定期检查。
效果:
- 为主会话加入一个系统事件队列
- 如果
mode=now,则立即触发心跳
POST /hooks/agent
请求体:
{
"message": "Run this",
"name": "Email",
"sessionKey": "hook:email:msg-123",
"wakeMode": "now",
"deliver": true,
"channel": "last",
"to": "+15551234567",
"model": "openai/gpt-5.2-mini",
"thinking": "low",
"timeoutSeconds": 120
}
message必填(字符串):智能体要处理的提示或消息。name可选(字符串):hook 的可读名称(例如"GitHub"),用作会话摘要的前缀。sessionKey可选(字符串):用于标识智能体会话的键。默认为随机的hook:<uuid>。使用一致的键可以在 hook 上下文中进行多轮对话。wakeMode可选(now|next-heartbeat):是否立即触发心跳(默认now)或等待下一次定期检查。deliver可选(布尔值):如果为true,智能体的响应将发送到消息渠道。默认为true。仅为心跳确认的响应会自动跳过。channel可选(字符串):用于投递的消息渠道。可选值:last、whatsapp、telegram、discord、slack、mattermost(插件)、signal、imessage、msteams。默认为last。to可选(字符串):渠道的接收者标识符(例如 WhatsApp/Signal 的电话号码、Telegram 的聊天 ID、Discord/Slack/Mattermost(插件)的频道 ID、MS Teams 的会话 ID)。默认为主会话中的最后一个接收者。model可选(字符串):模型覆盖(例如anthropic/claude-3-5-sonnet或别名)。如果有限制,必须在允许的模型列表中。thinking可选(字符串):思考级别覆盖(例如low、medium、high)。timeoutSeconds可选(数字):智能体运行的最大持续时间(秒)。
效果:
- 运行一个隔离的智能体回合(独立的会话键)
- 始终在主会话中发布摘要
- 如果
wakeMode=now,则立即触发心跳
POST /hooks/<name>(映射)
自定义 hook 名称通过 hooks.mappings 解析(见配置)。映射可以将任意请求体转换为 wake 或 agent 操作,支持可选的模板或代码转换。
映射选项(摘要):
hooks.presets: ["gmail"]启用内置的 Gmail 映射。hooks.mappings允许你在配置中定义match、action和模板。hooks.transformsDir+transform.module加载 JS/TS 模块用于自定义逻辑。- 使用
match.source保持通用的接收端点(基于请求体的路由)。 - TS 转换需要 TS 加载器(例如
bun或tsx)或运行时预编译的.js。 - 在映射上设置
deliver: true+channel/to可将回复路由到聊天界面(channel默认为last,回退到 WhatsApp)。 allowUnsafeExternalContent: true禁用该 hook 的外部内容安全包装(危险;仅用于受信任的内部来源)。hanzo-bot webhooks gmail setup为hanzo-bot webhooks gmail run写入hooks.gmail配置。完整的 Gmail 监听流程请参阅 Gmail Pub/Sub。
响应
200用于/hooks/wake202用于/hooks/agent(异步运行已启动)401认证失败400请求体无效413请求体过大
示例
curl -X POST http://127.0.0.1:18789/hooks/wake \
-H 'Authorization: Bearer SECRET' \
-H 'Content-Type: application/json' \
-d '{"text":"New email received","mode":"now"}'
curl -X POST http://127.0.0.1:18789/hooks/agent \
-H 'x-hanzo-bot-token: SECRET' \
-H 'Content-Type: application/json' \
-d '{"message":"Summarize inbox","name":"Email","wakeMode":"next-heartbeat"}'
使用不同的模型
在智能体请求体(或映射)中添加 model 以覆盖该次运行的模型:
curl -X POST http://127.0.0.1:18789/hooks/agent \
-H 'x-hanzo-bot-token: SECRET' \
-H 'Content-Type: application/json' \
-d '{"message":"Summarize inbox","name":"Email","model":"openai/gpt-5.2-mini"}'
如果你启用了 agents.defaults.models 限制,请确保覆盖的模型包含在其中。
curl -X POST http://127.0.0.1:18789/hooks/gmail \
-H 'Authorization: Bearer SECRET' \
-H 'Content-Type: application/json' \
-d '{"source":"gmail","messages":[{"from":"Ada","subject":"Hello","snippet":"Hi"}]}'
安全
- 将 hook 端点保持在 loopback、tailnet 或受信任的反向代理之后。
- 使用专用的 hook 令牌;不要复用 Gateway 网关认证令牌。
- 避免在 webhook 日志中包含敏感的原始请求体。
- Hook 请求体默认被视为不受信任并使用安全边界包装。如果你必须为特定 hook 禁用此功能,请在该 hook 的映射中设置
allowUnsafeExternalContent: true(危险)。