Files
flutter_opencode_client/README_OPCODE.md
root 0f4fe33003 Add Opencode (opencode.ai) integration via SSH tunnel
Features:
- Opencode AI chat interface
- SSH tunnel for secure API communication
- Auto-install Opencode on remote servers
- API key management with server-side storage
- Session history and management
- Integration with flutter_server_box server list
2026-04-03 00:41:32 +08:00

126 lines
3.2 KiB
Markdown
Raw 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.

# Flutter Opencode Client
基于 [flutter_server_box](https://github.com/lollipopkit/flutter_server_box) 修改的 Android Opencode (opencode.ai) API 访问客户端。
## 功能特性
- 🔐 **SSH 隧道连接**: 通过 SSH 安全连接到远程服务器
- 🤖 **Opencode AI**: 集成 opencode.ai API提供智能助手功能
- 📲 **自动安装**: 一键自动在服务器上安装 Opencode
- 🔑 **密钥管理**: 安全存储 API 密钥到服务器端(明文存储)
- 💬 **聊天界面**: 现代化的聊天界面,支持会话历史
- 📱 **Android 支持**: 专为 Android 优化的原生体验
## 安装
### 要求
- Flutter 3.11.0+
- Dart 3.0+
- Android SDK 21+
### 克隆项目
```bash
git clone https://github.com/yourusername/flutter_opencode_client.git
cd flutter_opencode_client
```
### 安装依赖
```bash
flutter pub get
```
### 运行
```bash
flutter run
```
### 构建 APK
```bash
flutter build apk --release
```
## 使用说明
### 1. 添加服务器
在 ServerBox 界面添加你的 SSH 服务器信息:
- 服务器 IP/域名
- 端口 (默认 22)
- 用户名
- 密码或私钥
### 2. 启动 Opencode
在服务器详情页点击 **Opencode** 按钮:
- 首次使用会显示安装向导
- 配置 Opencode 安装路径(默认 `/usr/local/bin/opencode`
- 配置 API 端口(默认 `8080`
- 输入 Opencode API Key可选
- 点击 "Quick Install & Connect"
### 3. 开始对话
安装完成后自动进入聊天界面:
- 输入消息与 Opencode AI 对话
- 查看会话历史
- 创建多个独立会话
### 4. API 密钥管理
在设置中管理 API 密钥:
- 密钥以明文形式存储在服务器 `~/.config/opencode/api_key.txt`
- 文件权限设置为 600仅所有者可读写
- 每个服务器可配置独立密钥
## 项目结构
```
lib/
├── data/
│ ├── model/opencode/
│ │ ├── models.dart # 数据模型
│ │ └── ssh_tunnel.dart # SSH 隧道管理
│ ├── provider/opencode/
│ │ └── opencode.dart # Riverpod 状态管理
│ ├── store/
│ │ └── opencode_store.dart # 本地存储
│ └── model/app/menu/
│ └── server_func.dart # 服务器功能按钮
├── view/page/opencode/
│ ├── chat_page.dart # 聊天界面
│ ├── setup_page.dart # 安装向导
│ └── key_manager_page.dart # 密钥管理
└── main.dart
```
## 安全性说明
⚠️ **重要提示**
1. **API 密钥存储**: 密钥以明文形式存储在服务器端,文件权限设置为 600
2. **SSH 连接**: 所有通信通过 SSH 隧道加密
3. **服务器安全**: 请确保您的服务器已妥善保护,仅允许授权访问
4. **密钥传输**: 密钥通过 SSH 通道传输到服务器,不在公网明文传输
## 依赖项
- `dartssh2`: SSH 客户端
- `flutter_riverpod`: 状态管理
- `hive_ce_flutter`: 本地存储
- `freezed_annotation`: 代码生成
- 其他 flutter_server_box 原有依赖
## 许可证
基于 flutter_server_box 的许可证 (GPL-3.0)
## 致谢
- [flutter_server_box](https://github.com/lollipopkit/flutter_server_box) - 基础项目
- [Opencode](https://opencode.ai) - AI 助手平台