Files
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

142 lines
2.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# WeChat-Nanobot Bridge
微信与 nanobot AI 助手的桥接服务,基于 weixin-agent-sdk 开发。
## 项目概述
本项目实现一个 HTTP API 桥接层,将微信消息转发给 nanobot 处理,并将回复返回给微信用户。
## 架构设计
```
微信用户 → weixin-agent-sdk → HTTP API → nanobot-bridge → nanobot 核心
```
## 目录结构
```
weixin-nanobot-bridge/
├── src/
│ ├── server.py # Flask HTTP 服务
│ ├── nanobot_adapter.py # nanobot 调用适配器
│ ├── session_manager.py # 会话管理
│ └── security.py # 安全控制
├── config/
│ └── config.json # 配置文件
├── scripts/
│ ├── start.sh # 启动脚本
│ └── setup.sh # 安装脚本
├── logs/ # 运行日志
└── README.md
```
## 快速开始
### 1. 安装依赖
```bash
cd weixin-nanobot-bridge
pip install -r requirements.txt
```
### 2. 配置 nanobot
确保 nanobot 可以通过命令行调用:
```bash
which nanobot
# 或
nanobot --version
```
### 3. 启动桥接服务
```bash
./scripts/start.sh
```
服务将在 `http://localhost:5000` 启动。
### 4. 启动 weixin-agent-sdk
在另一个终端:
```bash
# 安装 weixin-agent-sdk
npm install -g weixin-agent-sdk
# 设置桥接地址
export NANOBOT_BRIDGE_URL=http://localhost:5000/chat
# 登录微信
weixin-agent-sdk login
# 启动
weixin-agent-sdk start
```
## 配置说明
编辑 `config/config.json`:
```json
{
"server": {
"host": "0.0.0.0",
"port": 5000,
"debug": false
},
"nanobot": {
"command": "nanobot",
"timeout": 60,
"max_output_length": 4000
},
"security": {
"allowed_tools": ["read", "write", "edit", "exec"],
"blocked_commands": ["rm -rf", "dd", "mkfs", "shutdown"],
"max_requests_per_minute": 10
},
"session": {
"max_history": 10,
"expire_hours": 24
}
}
```
## 安全限制
⚠️ **重要**: 由于微信是开放平台,必须限制 nanobot 的危险操作:
- ✅ 允许: 文件读写、代码编辑、命令执行(受限)
- ❌ 禁止: 删除系统文件、格式化磁盘、关机重启
- ❌ 禁止: 访问敏感配置文件(如 ~/.ssh)
## 开发计划
### Phase 1: 基础版本(当前)
- [x] HTTP API 服务
- [x] 基础会话管理
- [x] 安全控制
### Phase 2: 增强功能
- [ ] 多模态支持(图片、文件)
- [ ] 长消息分段发送
- [ ] 消息队列和限流
- [ ] 用户白名单
### Phase 3: 高级功能
- [ ] 群聊支持
- [ ] 技能选择器
- [ ] 管理员命令
- [ ] 使用统计
## 注意事项
1. **微信封号风险**: 非官方项目,建议用小号测试
2. **隐私保护**: 不要处理敏感个人信息
3. **资源限制**: 每个请求 60 秒超时
4. **输出截断**: 超过 4000 字符会自动截断
## License
仅供学习交流使用,非微信官方项目。