feat: virtual company module, team projects, PWA dishes app, and startup scripts overhaul

- Add company module (3-tier org, CEO planning, parallel departments)
- Add company orchestrator, knowledge extractor, presets, scheduler
- Add company API endpoints, models, and frontend views
- Add 今天吃啥 PWA app (69 dishes, real images, offline support)
- Add team_projects output directory structure
- Add unified manage.ps1 for service lifecycle
- Add Windows startup guide v1.0
- Add TTS troubleshooting doc
- Update frontend (AgentChat UX overhaul, new views)
- Update backend (voice engine fix, multi-tenant, RBAC)
- Remove deprecated startup scripts and old docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-10 22:37:56 +08:00
parent 3483c6b3be
commit f2e65a8fbb
259 changed files with 39239 additions and 3148 deletions

View File

@@ -0,0 +1,213 @@
# (红头)Windows 服务器启动与重启唯一指南1.0 版本)
> 替代旧版,后续只看这一份。
> 仓库路径:`D:\workspace\aiagent`(若你的路径不同,替换下文所有路径即可)
---
## 0. 快速参考卡片
```powershell
cd D:\workspace\aiagent
# 最常用 — 全套重启
powershell -ExecutionPolicy Bypass -File .\scripts\startup\manage.ps1 restart
# 查看服务状态
powershell -ExecutionPolicy Bypass -File .\scripts\startup\manage.ps1 status
# 只改后端代码后(保留 Redis + 前端)
powershell -ExecutionPolicy Bypass -File .\scripts\startup\restart_backend_celery.ps1
```
| 服务 | 端口 | 说明 |
|------|------|------|
| 前端 Vite | 3001 | `http://localhost:3001` |
| 后端 API | 8037/ 8041 | `http://127.0.0.1:8037/docs` |
| Redis | 6379 | `restart_backend_celery.ps1` 会自动守护 |
| Celery Worker | — | Agent 异步执行 |
| Celery Beat | — | 定时任务调度 |
---
## 1. manage.ps1 — 统一管理(推荐)
一条命令管理所有服务,替代原来散落的 start/stop/restart。
```powershell
cd D:\workspace\aiagent
powershell -ExecutionPolicy Bypass -File .\scripts\startup\manage.ps1 <动作>
```
| 动作 | 功能 |
|------|------|
| `status` | 检查所有服务状态(端口 + 健康检查) |
| `start` | 启动全部Redis → API(自动选端口) → Celery → 前端 |
| `stop` | 停止全部服务,显示端口释放情况 |
| `restart` | = stop + start**推荐用于全套重启** |
### 1.1 start 自动处理
- **端口探测**8037 被占用自动切 8041
- **Redis 守护**:不在运行则自动拉起
- **前端代理对齐**:自动设置 `AIAGENT_API_PROXY` 指向实际 API 端口
- **健康检查**:启动后等待最多 30s确认 API `/docs` 和前端端口可达
### 1.2 输出示例
```
== 启动所有服务 ==
>>> 1/5 Redis
[OK] Redis 已启动 (端口 6379)
>>> 2/5 后端 API 端口探测
[OK] 端口 8037 可用
>>> 3/5 后端 API (端口 8037)
[OK] 后端 API 已启动 (PID=12345)
>>> 4/5 Celery Worker + Beat
[OK] Celery Worker 已在新窗口启动 (PID=12346)
[OK] Celery Beat 已在新窗口启动 (PID=12347)
>>> 5/5 前端 Vite (端口 3001)
[OK] 前端 Vite 已启动 (PID=12348)
>>> 健康检查(等待服务就绪,最多 30 秒)
[OK] 所有服务就绪(耗时 12s
═══════════════════════════════════════════
启动完成
═══════════════════════════════════════════
后端文档: http://127.0.0.1:8037/docs
前端页面: http://localhost:3001
Agent对话: http://localhost:3001/agent-chat
```
---
## 2. restart_backend_celery.ps1 — 仅重启后端(保留 Redis + 前端)
适用场景:只改了 Python 代码、.env、依赖、工具实现。
```powershell
powershell -ExecutionPolicy Bypass -File .\scripts\startup\restart_backend_celery.ps1
```
**关键改进1.0 新增):**
- 重启 API + Celery 后**自动检查 Redis 是否在运行**
- Redis 不在则自动拉起(不再出现"重启后登录报 500"
- 不会主动停止 Redis 或前端
---
## 3. 手动应急启动manage.ps1 不可用时)
开 3~5 个终端:
**1) Redis**
```powershell
D:\workspace\aiagent\backend\redis\redis-server.exe --port 6379
```
**2) API**
```powershell
cd D:\workspace\aiagent\backend
.\venv\Scripts\Activate.ps1
python -m uvicorn app.main:app --host 0.0.0.0 --port 8037
```
**3) Celery Worker**
```powershell
cd D:\workspace\aiagent\backend
.\venv\Scripts\Activate.ps1
python -m celery -A app.core.celery_app worker --loglevel=info --pool=threads --concurrency=8
```
**4) 前端**
```powershell
cd D:\workspace\aiagent\frontend
$env:AIAGENT_API_PROXY='http://127.0.0.1:8037'
npx vite --port 3001 --host 0.0.0.0
```
**5) Celery Beat定时任务可选**
```powershell
cd D:\workspace\aiagent\backend
.\venv\Scripts\Activate.ps1
python -m celery -A app.core.celery_app beat --loglevel=info
```
---
## 4. 常见故障速查
### 4.1 登录报 500 / "服务器内部错误"
**根因Redis 未运行。**
`restart_backend_celery.ps1` 旧版只重启 API+Celery不检查 Redis。1.0 版已修复。
**手动修复:**
```powershell
D:\workspace\aiagent\backend\redis\redis-server.exe --port 6379
```
### 4.2 TTS 朗读声音机械不自然
**根因:** 后端 edge-tts CLI 子进程找不到,降级到浏览器机械语音。
**日志特征:**
```
ERROR | Edge TTS 失败:
POST /api/v1/voice/tts - 状态码: 502
```
**已修复:** `voice.py` 改用 Python 库直接调用,不再依赖外部 CLI PATH。
详细排查见 `docs/troubleshooting/TTS朗读声音机械不自然.md`
### 4.3 端口 8037 被僵尸进程占用
**现象:** `netstat` 显示 8037 LISTENING`tasklist` 找不到对应 PID。
**解决:**
- `manage.ps1 start` 会自动探测并切换到 8041
- 必须清理 8037重启 Windows`netsh interface ipv4 show excludedportrange protocol=tcp` 检查是否与 Hyper-V 动态端口冲突
### 4.4 Agent 执行超时 `timeout of 30000ms exceeded`
**优先检查:**
1. Redis 是否在 6379 监听:`netstat -ano | findstr :6379`
2. `.env``REDIS_URL` 是否与 Redis 实际端口一致(应为 `redis://localhost:6379/0`
3. Celery Worker 是否在运行
### 4.5 一键脚本报 PowerShell 解析错误
```powershell
Set-ExecutionPolicy -Scope Process Bypass
```
或将脚本保存为 UTF-8 with BOM 重新执行。
---
## 5. 端口说明
| 服务 | 主端口 | 备用端口 | 启动方式 |
|------|--------|----------|----------|
| 前端 Vite | 3001 | — | manage.ps1 / 手动 |
| 后端 API | 8037 | 8041 | manage.ps1 自动探测 |
| Redis | 6379 | — | manage.ps1 自动守护 |
---
## 6. 访问地址
- 前端:`http://localhost:3001`
- Agent 对话:`http://localhost:3001/agent-chat`
- 后端文档:`http://127.0.0.1:8037/docs`(若切到 8041 则改端口)
- 健康检查:`curl.exe -s -o NUL -w "%{http_code}" http://127.0.0.1:8037/docs`(返回 200 即正常)
---
## 7. 维护规则(强制)
- 所有启动/重启内容只维护本文件
- 建议用 `manage.ps1` 替代旧脚本进行全套操作
- `restart_backend_celery.ps1` 仅用于"只改后端代码"的场景
- 修改启动逻辑后,先更新本文档

View File

@@ -1,245 +0,0 @@
# (红头)Windows 服务器启动与重启唯一指南
本文是 `D:\aaa\aiagent` 在 Windows 本地开发环境下的**唯一启动/重启文档**。
后续只看这一份即可。
---
## 0. 统一结论(先看)
- 推荐端口:
- 前端:`3001`
- 后端 API`8037`(若被占用,一键启动会自动改用备用 **`8041`**
- Redis`6379`
- **一键脚本目录**:均在仓库内 `scripts\startup\`,在根目录 `D:\aaa\aiagent` 下执行时路径为 `.\scripts\startup\*.ps1`(勿写成根目录下的 `.\start_aiagent.ps1`)。
- `backend/.env` 必须与实际 Redis 端口一致:
- 推荐:`REDIS_URL=redis://localhost:6379/0`
- 任何 `.env` / 依赖 / 工具代码变更后,至少重启:
- API + Celery`scripts\startup\restart_backend_celery.ps1`
- 若出现 `timeout of 30000ms exceeded`,优先检查:
1) Redis 是否可连
2) Celery Worker 是否在跑
3) API 与 Worker 是否使用同一 `backend\venv`
---
## 1. 一键启动 / 停止 / 重启
在 PowerShell 中执行(仓库根目录):
```powershell
cd D:\aaa\aiagent
```
### 1.1 一键启动(全套)
```powershell
powershell -ExecutionPolicy Bypass -File .\scripts\startup\start_aiagent.ps1
```
默认目标:
- 前端:`http://localhost:3001`
- 后端文档:优先 `http://127.0.0.1:8037/docs`;若脚本提示已切到 **8041**,则打开 `http://127.0.0.1:8041/docs`
- Redis`127.0.0.1:6379`
一键启动会为每个进程新开 PowerShell 窗口(含 **Celery Worker****Celery Beat**)。若控制台一闪退出,请到该窗口里看报错。
### 1.2 一键停止(全套)
```powershell
powershell -ExecutionPolicy Bypass -File .\scripts\startup\stop_aiagent.ps1
```
### 1.3 仅重启后端 + Celery最常用
```powershell
powershell -ExecutionPolicy Bypass -File .\scripts\startup\restart_backend_celery.ps1
```
适用场景:改了 `.env`、Python 依赖、内置工具实现、Agent 执行逻辑。
说明:该脚本**固定**把 API 起在 **8037**。若本机 8037 被其它程序或异常状态占用,请先 `stop` 全套或释放端口后再执行。
### 1.4 仅重启前端(不动 Redis / 后端)
适用:只改了前端代码或 Vite 配置,需要刷新 dev 进程。
1. 结束占用 **3001** 的进程(任务管理器结束对应 `node`/`pnpm`,或用资源监视器按端口查 PID 后结束)。
2. 确认当前 API 端口(一般为 **8037**;若全套启动时曾提示改用 **8041**,则与之一致)。
3. 新开 PowerShell
```powershell
cd D:\aaa\aiagent\frontend
$env:AIAGENT_API_PROXY='http://127.0.0.1:8037' # 若 API 在 8041改为 ...8041
pnpm dev --port 3001
```
浏览器请优先用 **`http://localhost:3001`** 访问Vite 常只绑 `[::1]`,用 `127.0.0.1:3001` 可能连不上,属正常现象)。
---
## 2. 标准“重启服务器”流程(推荐照抄)
```powershell
cd D:\aaa\aiagent
powershell -ExecutionPolicy Bypass -File .\scripts\startup\stop_aiagent.ps1
powershell -ExecutionPolicy Bypass -File .\scripts\startup\start_aiagent.ps1
```
`start` 输出中出现 **`Port 8037 is occupied, switching to 8041`**,则本次 API 在 **8041**,下文健康检查与文档地址请改用 **8041**(前端新窗口里的 `AIAGENT_API_PROXY` 已指向该端口)。
完成后立刻验证PowerShell 中 `curl` 多为 `Invoke-WebRequest` 别名,建议用 **`curl.exe`**
```powershell
netstat -ano | findstr :6379
netstat -ano | findstr :8037
netstat -ano | findstr :8041
netstat -ano | findstr :3001
curl.exe -s -o NUL -w "%{http_code}" http://127.0.0.1:8037/health
curl.exe -s -o NUL -w "%{http_code}" http://127.0.0.1:8041/health
```
若 API 实际在 **8041**,刚启动后 **1020 秒内** `/health` 可能仍超时,属 uvicorn 拉起过程;前端 `3001` 可先就绪。
---
## 3. 本次故障复盘(学生作业管理助手超时)
### 3.1 现象
- Agent 对话区报错:`发送失败: timeout of 30000ms exceeded`
- 前端可打开,但执行一直超时。
### 3.2 根因
1. `backend/.env` 配置为:
- `REDIS_URL=redis://localhost:6380/0`
2. 实际 Redis 监听在:
- `6379`
3. 导致 Celery 任务队列链路异常(或 Worker 无法稳定消费Agent 执行超时。
### 3.3 修复
1.`backend/.env` 改为:
- `REDIS_URL=redis://localhost:6379/0`
2. 执行:
- `powershell -ExecutionPolicy Bypass -File .\scripts\startup\restart_backend_celery.ps1`
3. 验证:
- `6379/8037/3001` 监听正常
- `/health` 返回 `200`
- Celery worker 进程存在
### 3.4 预防
- 不要混用两套端口约定(`6379``6380`)。
- 每次重启后先做 1 分钟健康检查(端口 + `/health` + 1 条 Agent 测试消息)。
---
## 4. 常见问题与快速处理
### 4.1 执行策略拦截脚本
```powershell
Set-ExecutionPolicy -Scope Process Bypass
```
### 4.2 `start_aiagent.ps1` 报 PowerShell 解析错误
症状:出现 `ParserError`、字符串终止符缺失、`[OK]` 附近报错。
处理:
1. 临时手动启动(见 4.3
2. 将脚本保存为 **UTF-8建议无 BOM/ ASCII 兼容内容**,避免中文引号或异常字符
### 4.3 一键脚本不可用时的手动拉起(应急)
**5** 个终端(与一键启动对齐;若暂不需要定时任务可省略 Beat
1) Redis
```powershell
cd D:\aaa\aiagent\backend\redis
.\redis-server.exe --port 6379
```
2) API
```powershell
cd D:\aaa\aiagent\backend
.\venv\Scripts\Activate.ps1
python -m uvicorn app.main:app --host 0.0.0.0 --port 8037
```
3) Celery
```powershell
cd D:\aaa\aiagent\backend
.\venv\Scripts\Activate.ps1
python -m celery -A app.core.celery_app worker --loglevel=info --pool=threads --concurrency=8
```
4) 前端
```powershell
cd D:\aaa\aiagent\frontend
$env:AIAGENT_API_PROXY='http://127.0.0.1:8037'
pnpm dev --port 3001
```
5) Celery Beat与一键 `start_aiagent.ps1` 对齐;定时任务依赖此项)
```powershell
cd D:\aaa\aiagent\backend
.\venv\Scripts\Activate.ps1
python -m celery -A app.core.celery_app beat --loglevel=info
```
### 4.4 8037「占用」与 netstat 幽灵 PID实践经验
部分 Windows 环境会出现:
- `start_aiagent.ps1` 提示 **8037 被占用**,自动改用 **8041**
- `netstat` 仍显示 `0.0.0.0:8037 LISTENING` 且带某一 **PID**,但 **`tasklist` 查不到该 PID**(或无法 `Stop-Process`)。
此时以 **`start` 脚本打印的实际端口为准**(多为 **8041**),用 **`http://127.0.0.1:8041/docs`** 与对应 `/health` 验证即可。若必须清理 **8037**,可本机执行 `netsh interface ipv4 show excludedportrange protocol=tcp` 查看是否与 Hyper-V / 动态端口保留冲突,或重启 Windows 后再全套启动。
### 4.5 `stop` 已正常但 `start` 报「8037 与 8041 均占用」
曾出现:`stop` 对后端端口打印 **SKIP**,端口检查却仍显示 **LISTEN**,随后 `start` 抛出双端口占用。根因是旧版 `stop_aiagent.ps1`**`ForEach-Object` 内误用 `return`**(会从整个函数提前返回)以及内层 **`$pid` 变量名与 PowerShell 只读自动变量冲突**,导致未真正枚举监听 PID。
**当前仓库内 `scripts\startup\stop_aiagent.ps1` 已按上述问题修复**;若你本地脚本被回退或拷贝了旧版,请与仓库版本对齐后再执行全套重启。
---
## 5. OCR上传图片识别必查项
`backend/.env` 建议:
```ini
TESSERACT_CMD=C:/Program Files/Tesseract-OCR/tesseract.exe
TESSERACT_TESSDATA_DIR=D:/aaa/aiagent/tessdata
```
自检:
```powershell
cd D:\aaa\aiagent\backend
.\venv\Scripts\python scripts\check_ocr_env.py
```
若新增依赖后仍报 OCR 缺失,重启 Celery。
---
## 6. 访问地址
- 前端:`http://localhost:3001`(推荐用 **localhost**,避免与 `[::1]` 绑定不一致)
- 后端 API默认`http://127.0.0.1:8037`
- 后端文档(默认):`http://127.0.0.1:8037/docs`
- 健康检查(默认):`http://127.0.0.1:8037/health`
- 若一键启动提示改用 **8041**:将上述三项中的端口改为 **8041** 即可。
---
## 7. 维护规则(强制)
- 所有 Windows 启动/重启内容只维护本文件。
- 其他旧文档仅保留跳转,不再写重复步骤。
- 修改启动逻辑后,先更新本文件再通知团队。

View File

@@ -1,7 +0,0 @@
# 前后端服务器启动和停止(已合并)
本文件已停止维护。
请改看唯一文档:`(红头)Windows服务器启动与重启唯一指南.md`
路径:`D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`

View File

@@ -1,7 +0,0 @@
# 启动注意事项(已合并)
本文件已停止维护。
请改看唯一文档:`(红头)Windows服务器启动与重启唯一指南.md`
路径:`D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`

View File

@@ -1,474 +0,0 @@
# Windows 启动指南(已合并)
本文件已停止维护,请只看以下唯一文档:
- `D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`
说明:历史内容已合并至上方文档,后续不再在本文件更新。
# Windows 启动指南(已合并)
本文件已停止维护。
请改看唯一文档:`(红头)Windows服务器启动与重启唯一指南.md`
路径:`D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`
# Windows 本地启动指南
## 前置要求
### 已安装的软件
- ✅ Python 3.12.7(已安装)
- ✅ Node.js 22.13.0(已安装)
- ✅ npm 10.9.2(已安装)
- ✅ pnpm 10.33.0(已安装)
### 需要安装的软件
- ❌ Redis需要安装但可以选择便携版
## 步骤 1安装 Redis选择一种方式
### 选项 A使用 Docker 运行 Redis推荐最简单
如果你不介意使用 Docker 来运行 Redis其他服务仍在本地运行
1. **安装 Docker Desktop**
- 下载地址https://www.docker.com/products/docker-desktop/
- 安装后启动 Docker Desktop
2. **启动 Redis 容器**
```bash
docker run -d --name redis -p 6380:6379 redis:7-alpine
```
3. **验证 Redis 是否运行**
```bash
docker ps
```
应该能看到 Redis 容器正在运行。
### 选项 B使用 Redis 便携版(快速启动,无需安装)
1. **下载 Redis Windows 便携版**
```bash
cd "D:/aaa/aiagent/backend"
curl -L -o redis.zip "https://github.com/microsoftarchive/redis/releases/download/win-3.2.100/Redis-x64-3.2.100.zip"
```
2. **解压 Redis**
```bash
# Windows PowerShell
Expand-Archive -Path redis.zip -DestinationPath redis
# 或使用解压工具解压
```
3. **启动 Redis 服务器**
```bash
cd redis
./redis-server.exe redis.windows.conf
```
Redis 将在端口 6379 启动。
4. **验证 Redis 是否运行**
```bash
./redis-cli.exe ping
```
应该返回:`PONG`
### 选项 C安装 Redis for Windows作为服务
1. **下载 Redis Windows 版本**
- 从 GitHub 下载https://github.com/microsoftarchive/redis/releases
- 下载 `Redis-x64-3.2.100.msi`
2. **安装 Redis**
- 运行安装程序,按照默认设置安装
- 安装完成后Redis 会作为 Windows 服务运行
3. **修改 Redis 端口(可选)**
- 默认 Redis 运行在 6379 端口
- 如果需要使用 6380 端口(与 docker-compose 配置一致),需要修改配置文件
- 配置文件位置:`C:\Program Files\Redis\redis.windows-service.conf`
- 找到 `port 6379` 改为 `port 6380`
- 重启 Redis 服务
### 选项 D使用 WSL 安装 Redis
如果你有 WSLWindows Subsystem for Linux
```bash
# 在 WSL 中运行
sudo apt update
sudo apt install redis-server
sudo service redis-server start
# 需要配置 Redis 允许远程连接
```
## 步骤 2配置后端环境
### 1. 创建虚拟环境并安装依赖
```bash
cd backend
# 创建虚拟环境
python -m venv venv
# 激活虚拟环境
# Windows CMD:
venv\Scripts\activate
# Windows PowerShell:
.\venv\Scripts\Activate.ps1
# Git Bash:
source venv/Scripts/activate
# 安装依赖
pip install -r requirements.txt
```
### 2. 配置环境变量
```bash
# 复制环境变量文件
copy env.example .env
```
编辑 `.env` 文件,确保以下配置正确:
```ini
# 数据库配置已配置为腾讯云MySQL无需修改
DATABASE_URL=mysql+pymysql://root:!Rjb12191@gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com:24936/agent_db?charset=utf8mb4
# Redis配置根据你的Redis安装方式选择
# 如果使用Docker Redis端口6380
REDIS_URL=redis://localhost:6380/0
# 如果使用Windows Redis默认端口6379
# REDIS_URL=redis://localhost:6379/0
# CORS配置
CORS_ORIGINS=http://localhost:3001,http://127.0.0.1:3001,http://localhost:3000,http://127.0.0.1:3000,http://localhost:8038,http://101.43.95.130:8038
# DeepSeek API密钥已有
DEEPSEEK_API_KEY=sk-fdf7cc1c73504e628ec0119b7e11b8cc
DEEPSEEK_BASE_URL=https://api.deepseek.com
```
### 3. 运行数据库迁移
```bash
# 确保虚拟环境已激活
alembic upgrade head
```
### 4. 启动后端服务
```bash
uvicorn app.main:app --host 0.0.0.0 --port 8037 --reload
```
后端服务将在 http://localhost:8037 启动。
### 5. 启动 Celery Worker新终端
```bash
# 在新终端中进入backend目录并激活虚拟环境
cd backend
venv\Scripts\activate
# 启动 Celery Worker
celery -A app.core.celery_app worker --loglevel=info
```
## 步骤 3配置前端环境
### 1. 安装依赖
```bash
cd frontend
pnpm install
```
### 2. 配置 API 地址
编辑 `frontend/vite.config.ts`,确保代理配置正确:
```typescript
export default defineConfig({
server: {
port: 3001,
proxy: {
'/api': {
target: 'http://localhost:8037',
changeOrigin: true,
},
'/ws': {
target: 'ws://localhost:8037',
ws: true,
},
},
},
})
```
### 3. 启动前端服务
```bash
pnpm dev
```
前端服务将在 http://localhost:3001 启动。
注意:访问地址是 http://localhost:3001前端默认使用3001端口。
## 步骤 4验证服务
### 1. 检查服务状态
- **后端API**: http://localhost:8037
- **API文档**: http://localhost:8037/docs
- **前端**: http://localhost:3001
### 2. 测试健康检查
```bash
curl http://localhost:8037/health
```
应该返回:`{"status":"healthy"}`
## 步骤 5创建第一个工作流
1. 访问 http://localhost:3001
2. 注册新用户或使用现有账户登录
3. 点击"创建工作流"进入可视化编辑器
4. 拖拽节点、连接、配置并保存
5. 运行工作流测试
## 常见问题
### 1. Redis 连接失败
**错误信息**
```
redis.exceptions.ConnectionError: Error 10061 connecting to localhost:6380
```
**解决方案**
- 检查 Redis 是否正在运行
- 确认 Redis 端口是否正确
- 检查防火墙是否阻止了 Redis 端口
### 2. 数据库连接失败
**错误信息**
```
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server...")
```
**解决方案**
- 检查网络连接(腾讯云数据库需要互联网访问)
- 确认数据库连接信息正确
- 检查数据库是否允许远程连接
### 3. 前端无法连接后端
**错误信息**
```
Proxy error: Could not proxy request /api/auth/me from localhost:3001 to http://localhost:8037
```
**解决方案**
- 检查后端服务是否正在运行http://localhost:8037
- 检查前端代理配置vite.config.ts
- 检查 CORS 配置(.env 文件中的 CORS_ORIGINS
### 4. Celery 任务不执行
**解决方案**
- 检查 Celery Worker 是否正在运行
- 检查 Redis 连接是否正常
- 查看 Celery Worker 日志
### 5. 端口被占用
**解决方案**
- 检查端口 8037 和 3001 是否被其他程序占用
- 可以修改端口:
- 后端:修改启动命令端口 `--port 8038`
- 前端:修改 `vite.config.ts` 中的 `port`
## 一键启动脚本(推荐)
下面给出一套更稳的 PowerShell 一键启动脚本:
- 自动检查并启动 Redis优先使用 `backend/redis/redis-server.exe`
- 自动拉起后端 API默认 8037若被占用自动切到 8041
- 自动拉起 Celery Worker
- 自动拉起前端(并将前端代理指向实际 API 端口)
### 脚本文件:`start_aiagent.ps1`
> 建议保存到仓库根目录:`D:\aaa\aiagent\start_aiagent.ps1`
```powershell
param(
[int]$ApiPort = 8037,
[int]$FallbackApiPort = 8041,
[int]$FrontendPort = 3001
)
$ErrorActionPreference = "Stop"
$RepoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$Backend = Join-Path $RepoRoot "backend"
$Frontend = Join-Path $RepoRoot "frontend"
$RedisDir = Join-Path $Backend "redis"
$RedisExe = Join-Path $RedisDir "redis-server.exe"
$RedisCli = Join-Path $RedisDir "redis-cli.exe"
function Test-PortListening([int]$Port) {
$line = netstat -ano | Select-String ":$Port\s+.*LISTENING" | Select-Object -First 1
return [bool]$line
}
function Ensure-Redis {
if (Test-PortListening 6379) {
Write-Host "[OK] Redis already listening on 6379" -ForegroundColor Green
return
}
if (-not (Test-Path $RedisExe)) {
throw "Redis 可执行文件不存在:$RedisExe"
}
Write-Host "[RUN] Starting Redis on 6379 ..." -ForegroundColor Yellow
Start-Process -FilePath $RedisExe -ArgumentList "--port 6379" -WorkingDirectory $RedisDir | Out-Null
Start-Sleep -Seconds 2
if (-not (Test-PortListening 6379)) {
throw "Redis 启动失败6379 未监听"
}
if (Test-Path $RedisCli) {
& $RedisCli -p 6379 ping | Out-Null
}
Write-Host "[OK] Redis started" -ForegroundColor Green
}
function Resolve-ApiPort {
if (-not (Test-PortListening $ApiPort)) {
return $ApiPort
}
Write-Host "[WARN] Port $ApiPort is occupied, switching to $FallbackApiPort" -ForegroundColor Yellow
if (Test-PortListening $FallbackApiPort) {
throw "端口 $ApiPort 和 $FallbackApiPort 都被占用,请先释放端口"
}
return $FallbackApiPort
}
Write-Host "== AIAgent Windows 一键启动 ==" -ForegroundColor Cyan
Write-Host "Repo: $RepoRoot"
Ensure-Redis
$RealApiPort = Resolve-ApiPort
$ApiBase = "http://127.0.0.1:$RealApiPort"
Write-Host "[RUN] Starting backend API on $RealApiPort ..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList @(
"-NoExit",
"-Command",
"cd '$Backend'; .\venv\Scripts\Activate.ps1; python -m uvicorn app.main:app --host 0.0.0.0 --port $RealApiPort"
)
Write-Host "[RUN] Starting Celery worker ..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList @(
"-NoExit",
"-Command",
"cd '$Backend'; .\venv\Scripts\Activate.ps1; python -m celery -A app.core.celery_app worker --loglevel=info --pool=threads --concurrency=8"
)
Write-Host "[RUN] Starting frontend on $FrontendPort (proxy -> $ApiBase) ..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList @(
"-NoExit",
"-Command",
"`$env:AIAGENT_API_PROXY='$ApiBase'; cd '$Frontend'; pnpm dev --port $FrontendPort"
)
Write-Host ""
Write-Host "[DONE] 启动命令已下发" -ForegroundColor Green
Write-Host "前端: http://localhost:$FrontendPort" -ForegroundColor Cyan
Write-Host "后端: $ApiBase/docs" -ForegroundColor Cyan
Write-Host "Redis: 127.0.0.1:6379" -ForegroundColor Cyan
```
### 运行方式
```powershell
cd D:\aaa\aiagent
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1
```
### 可选参数
```powershell
# 指定端口
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1 -ApiPort 8037 -FallbackApiPort 8041 -FrontendPort 3001
```
---
## 快速启动脚本(简版)
### Windows CMD 脚本 (`start_all.cmd`)
```batch
@echo off
echo 启动天工智能体平台...
REM 启动后端服务
start cmd /k "cd /d backend && venv\Scripts\activate && uvicorn app.main:app --host 0.0.0.0 --port 8037 --reload"
REM 启动 Celery Worker
start cmd /k "cd /d backend && venv\Scripts\activate && celery -A app.core.celery_app worker --loglevel=info"
REM 启动前端服务
start cmd /k "cd /d frontend && pnpm dev"
echo 服务启动完成!
echo 前端: http://localhost:3001
echo 后端API: http://localhost:8037/docs
```
### PowerShell 脚本 (`start_all.ps1`)
```powershell
Write-Host "启动天工智能体平台..." -ForegroundColor Green
# 启动后端服务
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; .\venv\Scripts\Activate.ps1; uvicorn app.main:app --host 0.0.0.0 --port 8037 --reload"
# 启动 Celery Worker
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; .\venv\Scripts\Activate.ps1; celery -A app.core.celery_app worker --loglevel=info"
# 启动前端服务
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd frontend; pnpm dev"
Write-Host "服务启动完成!" -ForegroundColor Green
Write-Host "前端: http://localhost:3001" -ForegroundColor Yellow
Write-Host "后端API: http://localhost:8037/docs" -ForegroundColor Yellow
```
## 停止服务
### 停止所有服务
1.`Ctrl+C` 停止每个终端中的服务
2. 停止 Redis
- Docker Redis: `docker stop redis`
- Windows Redis 服务: 停止 "Redis" 服务
## 生产环境建议
对于生产环境,建议使用:
1. **Docker Compose**:统一管理和部署所有服务
2. **Nginx**:反向代理和负载均衡
3. **Supervisor**:进程管理
4. **数据库备份**:定期备份腾讯云数据库
---
**文档版本**: 1.1
**最后更新**: 2026-04-09
> 注意:本指南针对 Windows 本地开发环境。生产环境部署请参考 [方案-优化版.md](./方案-优化版.md)。

View File

@@ -1,100 +0,0 @@
# Windows 启动和停止用法(已合并)
本文件已停止维护,请只看以下唯一文档:
- `D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`
说明:历史内容已合并至上方文档,后续不再在本文件更新。
# Windows 启动和停止用法(已合并)
本文件已停止维护。
请改看唯一文档:`(红头)Windows服务器启动与重启唯一指南.md`
路径:`D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`
# AIAgent Windows 启动和停止用法
## 一键启动
在 PowerShell 中执行:
```powershell
cd D:\aaa\aiagent
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1
```
启动后默认访问:
- 前端:`http://localhost:3001`
- 后端文档:`http://127.0.0.1:8037/docs`
- Redis`127.0.0.1:6379`
说明:
-`8037` 被占用,脚本会自动切换到 `8041` 启动后端。
- 前端会自动使用 `AIAGENT_API_PROXY` 指向实际后端端口。
## 启动参数(可选)
```powershell
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1 -ApiPort 8037 -FallbackApiPort 8041 -FrontendPort 3001
```
## 一键停止
在 PowerShell 中执行:
```powershell
cd D:\aaa\aiagent
powershell -ExecutionPolicy Bypass -File .\stop_aiagent.ps1
```
会尝试停止以下进程:
- 后端 API`uvicorn app.main:app`
- Celery Worker`celery -A app.core.celery_app worker`
- 前端 dev`vite` / `pnpm dev` / `npm run dev`
- Redis`redis-server`
并检查端口:
- `3001`
- `8037`
- `8041`
- `6379`
## 常见问题
### 1) 执行策略拦截脚本
先执行:
```powershell
Set-ExecutionPolicy -Scope Process Bypass
```
### 2) 发送消息超时30 秒)
优先检查 Redis 和 Worker
```powershell
netstat -ano | findstr :6379
```
确认 Celery Worker 正在运行。
### 3) 8037 端口被占用
先查占用:
```powershell
netstat -ano | findstr :8037
```
再结束对应 PID管理员 PowerShell
```powershell
taskkill /PID <PID> /T /F
```
## 脚本文件位置
- 启动脚本:`D:\aaa\aiagent\start_aiagent.ps1`
- 停止脚本:`D:\aaa\aiagent\stop_aiagent.ps1`

View File

@@ -1,104 +0,0 @@
# 🚀 启动说明
## 使用 Docker Compose 启动(推荐)
### 1. 启动所有服务
```bash
docker-compose -f docker-compose.dev.yml up -d
```
### 2. 查看服务状态
```bash
docker-compose ps
```
### 3. 查看日志
```bash
# 查看所有服务日志
docker-compose logs -f
# 查看特定服务日志
docker-compose logs -f backend
docker-compose logs -f frontend
docker-compose logs -f celery
```
### 4. 停止服务
```bash
docker-compose down
```
### 5. 重启服务
```bash
docker-compose restart
```
## 📍 访问地址
- **前端**: http://localhost:8038
- **后端API**: http://localhost:8037
- **API文档**: http://localhost:8037/docs
- **健康检查**: http://localhost:8037/health
## 🔧 配置说明
### 数据库配置
- **数据库类型**: MySQL腾讯云数据库
- **连接地址**: gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com:24936
- **数据库名**: agent_db
- **字符集**: utf8mb4
### 端口配置
- **前端端口**: 8038容器内3000
- **后端端口**: 8037容器内8000
- **Redis端口**: 6379
## ⚠️ 注意事项
1. **数据库连接**: 确保服务器能够访问腾讯云MySQL数据库
2. **首次启动**: 首次启动可能需要一些时间下载镜像和安装依赖
3. **数据库迁移**: 首次运行需要执行数据库迁移(如果需要)
4. **环境变量**: 数据库连接信息已在docker-compose.dev.yml中配置
## 🐛 常见问题
### 1. 容器启动失败
检查:
- Docker 和 Docker Compose 是否正常运行
- 端口是否被占用8038, 8037, 6379
- 磁盘空间是否充足
### 2. 数据库连接失败
检查:
- 网络是否能够访问腾讯云数据库
- 数据库连接信息是否正确
- 数据库是否已创建
### 3. 前端无法访问后端
检查:
- 后端服务是否正常运行
- 前端配置的API URL是否正确
- CORS配置是否正确
### 4. Celery任务不执行
检查:
- Celery Worker容器是否正常运行
- Redis连接是否正常
- 查看Celery日志`docker-compose logs -f celery`
## 📝 下一步
1. 访问 http://localhost:8037/docs 查看API文档
2. 开始开发功能模块
3. 参考 [方案-优化版.md](./方案-优化版.md) 了解详细技术方案