feat: load backend config from yaml

This commit is contained in:
2026-07-18 21:01:34 +08:00
parent 250b71951e
commit 62bd3d0455
5 changed files with 183 additions and 32 deletions

View File

@@ -1,27 +1,101 @@
# SenlinAI Agent Workbench
Private project-centered workbench MVP.
SenlinAI Agent Workbench 是一个以项目为中心的私有化工作台 MVP
## Development
## 本地开发
启动本地 PostgreSQL
```powershell
docker compose -f infra/docker-compose.yml up -d
```
启动后端 API
```powershell
Set-Location backend
go run ./cmd/api
```
## Frontend
启动 Web 客户端:
The web client uses Svelte and TypeScript only. The login shell lets users enter a server IP address or domain name, which is saved as the API base URL.
```powershell
Set-Location apps/web
npm run dev
```
## Backend Configuration
## 后端配置
- `PORT`: API listen port, default `8080`.
- `DATABASE_URL`: PostgreSQL connection string. Do not commit real credentials.
- `AUTH_SECRET`: HMAC secret for invite and session tokens.
- `SYSTEM_AI_KEY`: optional fallback AI provider key.
- `AI_KEY_ENCRYPTION_SECRET`: secret used to encrypt user AI keys at rest.
后端配置不再从多个环境变量直接读取,而是从 `backend/etc/agent.<mode>.yaml` 读取。
## Verification
配置模式由环境变量 `SENLIN_APP_MODE` 决定:
See `docs/mvp-verification.md` for backend, web, desktop, PostgreSQL, and manual MVP verification steps.
- 未设置 `SENLIN_APP_MODE` 时,默认读取 `backend/etc/agent.dev.yaml`
- 设置 `SENLIN_APP_MODE=prod` 时,读取 `backend/etc/agent.prod.yaml`
- 设置其他值时,按同样规则读取 `backend/etc/agent.<value>.yaml`
默认开发配置文件:
```text
backend/etc/agent.dev.yaml
```
配置字段:
- `env`: 运行环境,例如 `development`
- `port`: API 监听端口,默认开发值为 `8080`
- `database_url`: PostgreSQL 连接串。不要提交真实生产或测试凭据。
- `storage_dir`: 服务端本地文件存储目录。
- `auth_secret`: 邀请 token 和 session token 的 HMAC 密钥。
- `system_ai_key`: 可选的系统级 AI provider fallback key。
- `ai_key_encryption_secret`: 用户 AI key 静态加密密钥。
## 前端
Web 客户端只使用 Svelte 和 TypeScript。登录界面允许用户输入服务器 IP 地址或域名,并将其保存为 API base URL。
## 桌面端
桌面端使用 Tauri 包装 Web 客户端。
构建桌面可执行文件:
```powershell
Set-Location apps/desktop
npm run build
```
生成安装包:
```powershell
Set-Location apps/desktop
npm run bundle
```
## 验证
后端:
```powershell
Set-Location backend
go test ./... -v
```
Web
```powershell
Set-Location apps/web
npx tsc --noEmit -p tsconfig.app.json
npm test -- --run
npm run build
npx playwright test
```
桌面端:
```powershell
Set-Location apps/desktop
npm run build
```
更多验证说明见 `docs/mvp-verification.md`