106 lines
2.5 KiB
Markdown
106 lines
2.5 KiB
Markdown
# OpenCLI Integration - 通用CLI集成技能
|
|
|
|
集成 OpenCLI 能力,将任何网站、Electron应用转换为命令行接口,供AI Agent调用。
|
|
|
|
## 🎯 功能特性
|
|
|
|
- ✅ **网站CLI化** - 将任意网站转换为CLI工具
|
|
- ✅ **Electron应用控制** - 控制Antigravity等Electron应用
|
|
- ✅ **AI自动发现** - 自动探索网站API并生成适配器
|
|
- ✅ **浏览器复用** - 复用Chrome登录态,零风控
|
|
- ✅ **动态适配器** - 支持.yaml声明式和.ts编程式适配器
|
|
|
|
## 🚀 使用方法
|
|
|
|
### 前置要求
|
|
|
|
```bash
|
|
# 1. 安装Node.js >= 20.0.0
|
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
|
sudo apt-get install -y nodejs
|
|
|
|
# 2. 安装OpenCLI
|
|
npm install -g @jackwener/opencli
|
|
|
|
# 3. 确保Chrome正在运行且已登录目标网站
|
|
```
|
|
|
|
### 命令行使用
|
|
|
|
```bash
|
|
# 探索网站API
|
|
python3 /home/ubuntu/.nanobot/workspace/skills/opencli-integration/opencli_adapter.py explore https://www.xiaohongshu.com
|
|
|
|
# 生成适配器
|
|
python3 /home/ubuntu/.nanobot/workspace/skills/opencli-integration/opencli_adapter.py synthesize xiaohongshu
|
|
|
|
# 执行CLI命令
|
|
python3 /home/ubuntu/.nanobot/workspace/skills/opencli-integration/opencli_adapter.py exec xiaohongshu search "关键词"
|
|
|
|
# 诊断状态
|
|
python3 /home/ubuntu/.nanobot/workspace/skills/opencli-integration/opencli_adapter.py doctor
|
|
```
|
|
|
|
### Python API
|
|
|
|
```python
|
|
from opencli_adapter import OpenCLIAdapter
|
|
|
|
adapter = OpenCLIAdapter()
|
|
|
|
# 探索网站
|
|
result = adapter.explore("https://www.xiaohongshu.com")
|
|
|
|
# 生成适配器
|
|
adapter.synthesize("xiaohongshu")
|
|
|
|
# 执行命令
|
|
result = adapter.execute("xiaohongshu", "search", query="关键词")
|
|
```
|
|
|
|
## 📋 内置支持
|
|
|
|
OpenCLI官方支持的网站/应用:
|
|
- B站 (bilibili)
|
|
- 知乎 (zhihu)
|
|
- 小红书 (xiaohongshu)
|
|
- Twitter/X
|
|
- Reddit
|
|
- YouTube
|
|
- Antigravity (Electron)
|
|
|
|
## 🔧 高级用法
|
|
|
|
### 自定义适配器
|
|
|
|
```python
|
|
# 创建自定义适配器
|
|
adapter.create_custom_adapter(
|
|
name="mysite",
|
|
base_url="https://example.com",
|
|
selectors={
|
|
"search_box": "input[name='q']",
|
|
"search_button": "button[type='submit']"
|
|
}
|
|
)
|
|
```
|
|
|
|
### Electron应用控制
|
|
|
|
```python
|
|
# 控制Electron应用
|
|
adapter.control_electron("antigravity", "open_file", path="/path/to/file")
|
|
```
|
|
|
|
## ⚠️ 注意事项
|
|
|
|
- 需要Chrome浏览器正在运行
|
|
- 需要Node.js >= 20.0.0
|
|
- 新网站可能需要手动登录
|
|
- AI发现API的准确性需要验证
|
|
|
|
## 📚 参考
|
|
|
|
- OpenCLI GitHub: https://github.com/jackwener/opencli
|
|
- npm包: https://www.npmjs.com/package/@jackwener/opencli
|