Merge branch 'test' into prod
This commit is contained in:
commit
6543d3ad7d
3 files changed
+169
-53
No files matched your search
@@ -193,6 +193,59 @@ def get_chat_sessions():
|
||||
return jsonify(sessions)
|
||||
|
||||
|
||||
@chat_bp.route('/sessions', methods=['DELETE'])
|
||||
@require_agent_permission
|
||||
def delete_all_chat_sessions():
|
||||
"""
|
||||
删除当前用户与当前 Agent 的所有历史会话
|
||||
"""
|
||||
user = getattr(g, 'current_user', None)
|
||||
agent = getattr(g, 'current_agent', None)
|
||||
|
||||
if user is None or agent is None:
|
||||
return jsonify({'error': 'Missing context'}), 500
|
||||
|
||||
chat_logs = db.session.query(ChatLog).filter_by(user_id=user.id, agent_id=agent.id).all()
|
||||
chat_log_ids = [log.id for log in chat_logs]
|
||||
if chat_log_ids:
|
||||
from app.models import GeneralFeedback
|
||||
db.session.query(Feedback).filter(Feedback.chat_log_id.in_(chat_log_ids)).delete(synchronize_session=False)
|
||||
db.session.query(GeneralFeedback).filter(GeneralFeedback.chat_log_id.in_(chat_log_ids)).delete(synchronize_session=False)
|
||||
db.session.query(ChatLog).filter(ChatLog.id.in_(chat_log_ids)).delete(synchronize_session=False)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({'status': 'ok'})
|
||||
|
||||
|
||||
@chat_bp.route('/sessions/<conversation_id>', methods=['DELETE'])
|
||||
@require_agent_permission
|
||||
def delete_chat_session(conversation_id):
|
||||
"""
|
||||
删除指定的会话记录
|
||||
"""
|
||||
user = getattr(g, 'current_user', None)
|
||||
agent = getattr(g, 'current_agent', None)
|
||||
|
||||
if user is None or agent is None:
|
||||
return jsonify({'error': 'Missing context'}), 500
|
||||
|
||||
chat_logs = db.session.query(ChatLog).filter_by(
|
||||
user_id=user.id,
|
||||
agent_id=agent.id,
|
||||
conversation_id=conversation_id
|
||||
).all()
|
||||
|
||||
chat_log_ids = [log.id for log in chat_logs]
|
||||
if chat_log_ids:
|
||||
from app.models import GeneralFeedback
|
||||
db.session.query(Feedback).filter(Feedback.chat_log_id.in_(chat_log_ids)).delete(synchronize_session=False)
|
||||
db.session.query(GeneralFeedback).filter(GeneralFeedback.chat_log_id.in_(chat_log_ids)).delete(synchronize_session=False)
|
||||
db.session.query(ChatLog).filter(ChatLog.id.in_(chat_log_ids)).delete(synchronize_session=False)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({'status': 'ok'})
|
||||
|
||||
|
||||
@chat_bp.route('/messages', methods=['GET'])
|
||||
@require_agent_permission
|
||||
def get_chat_messages():
|
||||
|
||||
+42
-35
@@ -1,6 +1,6 @@
|
||||
# HXOPS 新人环境搭建与配置文档(已补齐)
|
||||
# HXOPS 新人环境搭建与配置文档
|
||||
|
||||
> 更新时间:2026-04-25
|
||||
> 更新时间:2026-04-25
|
||||
> 适用对象:开发、测试、运维、实施同学
|
||||
|
||||
## 1. 项目基础信息
|
||||
@@ -8,7 +8,7 @@
|
||||
- 项目名称:`HXOPS / Enterprise AI Gateway`
|
||||
- 代码仓库:`https://gitee.com/justop/hxops.git`
|
||||
- 项目任务看板:`https://www.kdocs.cn/l/ct8FI9gCM5eU`
|
||||
- 服务器部署默认分支:`dev`
|
||||
- 服务器默认分支:`dev`
|
||||
- 当前本地分支(示例):`sophie`
|
||||
- 项目根目录:`hxops/`
|
||||
|
||||
@@ -18,10 +18,11 @@
|
||||
2. Node.js + npm(建议 `Node.js 20 LTS`)
|
||||
3. Python(建议 `3.12`)
|
||||
4. PostgreSQL(建议 `>= 14`)
|
||||
5. Redis(建议 `>= 6`)
|
||||
6. Docker Desktop(推荐)
|
||||
7. VS Code 或 Cursor(推荐插件:Python、Pylance、Vue - Official、ESLint、Prettier、Docker)
|
||||
8. 可选:Postman/Apifox、DBeaver/DataGrip、企业微信客户端
|
||||
5. DBeaver/DataGrip(建议 `>= 6`)
|
||||
6. 企业微信客户端
|
||||
7. VS Code(推荐插件:Python、Pylance、Vue - Official、ESLint、Prettier、Docker)
|
||||
8. Codex 或 Cursor
|
||||
9. 可选:Postman/Apifox、Redis、Warp
|
||||
|
||||
## 3. Git 分支说明与操作原则
|
||||
|
||||
@@ -93,6 +94,7 @@ git push origin feature/your-feature-name
|
||||
### 5.1 后端(本地)
|
||||
|
||||
1. 创建虚拟环境并激活
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
python -m venv .venv
|
||||
@@ -103,11 +105,13 @@ source .venv/bin/activate
|
||||
```
|
||||
|
||||
2. 安装依赖
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. 初始化数据库(2选1)
|
||||
|
||||
```bash
|
||||
# 方案A:PostgreSQL(推荐)
|
||||
python init_db.py
|
||||
@@ -120,6 +124,7 @@ python init_db.py
|
||||
```
|
||||
|
||||
4. 启动后端
|
||||
|
||||
```bash
|
||||
python run.py
|
||||
```
|
||||
@@ -134,16 +139,17 @@ npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
前端本地开发端口:`8881`(`frontend/vite.config.ts`)。
|
||||
前端本地开发端口:`8881`(`frontend/vite.config.ts`)。
|
||||
本地开发时前端 `/api` 已代理到 `http://127.0.0.1:5002`。
|
||||
|
||||
### 5.3 Docker 启动(推荐)
|
||||
### 5.3 Docker 启动(可选)
|
||||
|
||||
```bash
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
当前对外端口映射(`docker-compose.yml`):
|
||||
|
||||
- 前端:`8890:80`
|
||||
- 后端:`5002:5002`
|
||||
|
||||
@@ -154,22 +160,24 @@ docker compose up -d --build
|
||||
### 6.1 登录方式
|
||||
|
||||
1. 账号密码登录
|
||||
2. 企业微信 OAuth 登录(WECOM)
|
||||
2. 企业微信 OAuth 登录(WECOM)(暂时不支持)
|
||||
|
||||
### 6.2 环境入口(已补齐可确定项)
|
||||
|
||||
| 环境 | 前端地址 | 后端地址 | 登录方式 | 备注 |
|
||||
|---|---|---|---|---|
|
||||
| 本地 | `http://localhost:8881` | `http://localhost:5002` | 密码/企业微信(按配置) | |
|
||||
| 测试 | `待定` | `待定` | 密码/企业微信(按配置) | |
|
||||
| 生产 | `http://192.168.100.230:8881/` | | 密码/企业微信(按配置) | |
|
||||
| 服务器部署(脚本) | `<待补:域名>` | `<待补:网关地址>` | 密码/企业微信 | |
|
||||
| Prod | `<待补>` | `<待补>` | `<待补>` | |
|
||||
|
||||
| 环境 | 前端地址 | 后端地址 | 登录方式 | 备注 |
|
||||
| ------- | ------------------------------ | ----------------------- | ----------------------- | ---- |
|
||||
| 本地 | `http://localhost:8881` | `http://localhost:5002` | 密码/企业微信(按配置) | |
|
||||
| 测试 | `待定` | `待定` | 密码/企业微信(按配置) | |
|
||||
| 生产 | `http://192.168.100.230:8881/` | | 密码/企业微信(按配置) | |
|
||||
| Jenkins | `http://8.152.207.171:10240/` | `` | 密码 | |
|
||||
| Casdoor | `http://192.168.100.230:8088` | | 密码 | |
|
||||
|
||||
### 6.3 默认测试账号(仅本地初始化脚本场景)
|
||||
|
||||
| 用户名 | 默认密码 | 角色 | 来源 |
|
||||
|---|---|---|---|
|
||||
|
||||
| 用户名 | 默认密码 | 角色 | 来源 |
|
||||
| ------- | ------------ | ------- | --------------------------------------------------- |
|
||||
| `admin` | `Hxit@54321` | `admin` | `backend/init_local_db.py` / `backend/fix_admin.py` |
|
||||
|
||||
说明:生产环境禁止使用默认密码,首次上线后必须立即重置。
|
||||
@@ -198,19 +206,20 @@ docker compose up -d --build
|
||||
|
||||
## 7. 环境变量清单(交接必填)
|
||||
|
||||
| 变量名 | 用途 | 示例 |
|
||||
|---|---|---|
|
||||
| `SECRET_KEY` | Flask 密钥 | 随机长字符串 |
|
||||
| `DATABASE_URL` | 数据库连接 | `postgresql://user:pwd@host:5432/db` |
|
||||
| `REDIS_URL` | Redis 连接 | `redis://:pwd@host:6379/0` |
|
||||
| `DIFY_API_BASE` | Dify 地址 | `https://api.dify.ai/v1` |
|
||||
| `DIFY_API_KEY` | Dify 密钥 | `sk-...` |
|
||||
| `HR_WORKFLOW_IFRAME_URL` | HR 页面链接 | `https://...` |
|
||||
| `HR_WORKFLOW_API_BASE` | HR API 地址 | `https://...` |
|
||||
| `HR_WORKFLOW_API_KEY` | HR API 密钥 | `<待补>` |
|
||||
| `INTEGRATION_API_BASE` | 集成 API 地址 | `https://...` |
|
||||
| `INTEGRATION_API_KEY` | 集成 API 密钥 | `<待补>` |
|
||||
| `WECOM_*` | 企业微信配置 | 见第 6.4 节 |
|
||||
|
||||
| 变量名 | 用途 | 示例 |
|
||||
| ------------------------ | ------------- | ------------------------------------ |
|
||||
| `SECRET_KEY` | Flask 密钥 | 随机长字符串 |
|
||||
| `DATABASE_URL` | 数据库连接 | `postgresql://user:pwd@host:5432/db` |
|
||||
| `REDIS_URL` | Redis 连接 | `redis://:pwd@host:6379/0` |
|
||||
| `DIFY_API_BASE` | Dify 地址 | `https://api.dify.ai/v1` |
|
||||
| `DIFY_API_KEY` | Dify 密钥 | `sk-...` |
|
||||
| `HR_WORKFLOW_IFRAME_URL` | HR 页面链接 | `https://...` |
|
||||
| `HR_WORKFLOW_API_BASE` | HR API 地址 | `https://...` |
|
||||
| `HR_WORKFLOW_API_KEY` | HR API 密钥 | `<待补>` |
|
||||
| `INTEGRATION_API_BASE` | 集成 API 地址 | `https://...` |
|
||||
| `INTEGRATION_API_KEY` | 集成 API 密钥 | `<待补>` |
|
||||
| `WECOM_*` | 企业微信配置 | 见第 6.4 节 |
|
||||
|
||||
## 8. Codex 配置方案
|
||||
|
||||
@@ -250,8 +259,6 @@ docker compose up -d --build
|
||||
## 10. 待补充信息区
|
||||
|
||||
- 服务器正式访问域名:`ai.well-trust.com:8881`
|
||||
- Dev/UAT/Prod 实际入口地址:`<待补>`
|
||||
- 数据库与 Redis 实际地址:`postgresql://postgres:difyai123456@localhost:5432/hxops_db`
|
||||
- 企业微信应用 `CorpID/AgentID`:
|
||||
- 新人账号申请与审批流程:`OA账号联系李振申`
|
||||
- 值班群与故障升级联系人:
|
||||
- 新人账号申请与审批流程:`OA账号联系李振甲`
|
||||
@@ -13,7 +13,7 @@
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useChat } from '../composables/useChat';
|
||||
import { Send, Bot, Loader2, ArrowLeft, Plus, Menu, Star, Copy, Edit2, RotateCw, Check } from 'lucide-vue-next';
|
||||
import { Send, Bot, Loader2, ArrowLeft, Plus, Menu, Star, Copy, Edit2, RotateCw, Check, X, Trash2 } from 'lucide-vue-next';
|
||||
import { marked } from 'marked';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { config } from '../config';
|
||||
@@ -264,7 +264,9 @@ const getSourceLinks = (resources: any[] = []): SourceFileLink[] => {
|
||||
if (isNoisySourceName(name)) continue;
|
||||
// 根据配置决定是否显示 MD 文件
|
||||
if ( (isMarkdownFileName(name) || isMarkdownByUrl(url))) continue;
|
||||
const key = `${name}|${url}`;
|
||||
|
||||
// Deduplicate by name if it looks like a filename, else by name + base URL
|
||||
const key = looksLikeFileName(name) ? name : `${name}|${url.split('?')[0]}`;
|
||||
if (!map.has(key)) {
|
||||
map.set(key, { name, url });
|
||||
}
|
||||
@@ -289,12 +291,12 @@ const getMessageLinks = (msg: any): SourceFileLink[] => {
|
||||
if (isNoisySourceName(link.name)) continue;
|
||||
if ( (isMarkdownFileName(link.name) || isMarkdownByUrl(link.url))) continue;
|
||||
if (isMarkdownFileName(link.name)) {
|
||||
const key = `${link.name}|${link.url}`;
|
||||
const key = looksLikeFileName(link.name) ? link.name : `${link.name}|${link.url.split('?')[0]}`;
|
||||
if (!map.has(key)) map.set(key, link);
|
||||
continue;
|
||||
}
|
||||
if (isNoisySourceUrl(link.url) && !looksLikeFileName(link.name)) continue;
|
||||
const key = `${link.name}|${link.url}`;
|
||||
const key = looksLikeFileName(link.name) ? link.name : `${link.name}|${link.url.split('?')[0]}`;
|
||||
if (!map.has(key)) map.set(key, link);
|
||||
}
|
||||
};
|
||||
@@ -458,6 +460,43 @@ const loadHistory = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const clearAllHistory = async () => {
|
||||
if (!confirm('确定要清除全部聊天历史记录吗?此操作不可恢复。')) return;
|
||||
try {
|
||||
const res = await fetch(`/api/chat/sessions?agent_id=${agentId}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
if (res.ok) {
|
||||
history.value = [];
|
||||
if (conversationId.value) {
|
||||
startNewChat();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to clear history', e);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteHistoryItem = async (id: string, event: Event) => {
|
||||
event.stopPropagation();
|
||||
if (!confirm('确定要删除这条聊天记录吗?')) return;
|
||||
try {
|
||||
const res = await fetch(`/api/chat/sessions/${id}?agent_id=${agentId}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
if (res.ok) {
|
||||
history.value = history.value.filter(h => h.conversation_id !== id);
|
||||
if (conversationId.value === id) {
|
||||
startNewChat();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to delete history item', e);
|
||||
}
|
||||
};
|
||||
|
||||
const loadConversation = async (id: string) => {
|
||||
if (conversationId.value === id) return;
|
||||
|
||||
@@ -581,25 +620,42 @@ const submitFeedback = async () => {
|
||||
<span class="text-sm font-semibold uppercase tracking-[0.14em] text-slate-500 dark:text-slate-300">{{ $t('chat.history') }}</span>
|
||||
<ThemeToggleButton />
|
||||
</div>
|
||||
<button @click="startNewChat(); isSidebarOpen = false;" class="mt-3 inline-flex w-[92%] max-w-[320px] self-center items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-cyan-500 to-blue-500 px-5 py-2.5 text-sm font-semibold text-white shadow-sm shadow-cyan-500/20 transition-all hover:from-cyan-400 hover:to-blue-400 hover:shadow-md hover:shadow-cyan-500/25 md:mt-4 md:w-[88%] md:max-w-none md:py-3">
|
||||
<Plus class="h-4 w-4" /> {{ $t('chat.newChat') }}
|
||||
</button>
|
||||
<div class="mt-3 flex items-center gap-2 md:mt-4">
|
||||
<button @click="startNewChat(); isSidebarOpen = false;" class="flex-1 inline-flex items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-cyan-500 to-blue-500 px-4 py-2.5 text-sm font-semibold text-white shadow-sm shadow-cyan-500/20 transition-all hover:from-cyan-400 hover:to-blue-400 hover:shadow-md hover:shadow-cyan-500/25 md:py-3">
|
||||
<Plus class="h-4 w-4" /> {{ $t('chat.newChat') }}
|
||||
</button>
|
||||
<button v-if="history.length > 0" @click="clearAllHistory" class="inline-flex items-center justify-center gap-1 rounded-xl border border-red-200 bg-red-50 px-2 py-2.5 text-xs font-semibold text-red-600 transition-all hover:bg-red-100 hover:text-red-700 dark:border-red-900/30 dark:bg-red-900/20 dark:text-red-400 dark:hover:bg-red-900/40 md:px-3 md:py-3" title="全部清除">
|
||||
<Trash2 class="h-4 w-4" /> <span class="hidden md:inline">全部清除</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto px-2.5 py-2.5 scrollbar-thin md:px-3 md:py-3">
|
||||
<div v-if="history.length === 0" class="py-8 text-center text-sm italic text-slate-400 md:py-10">{{ $t('chat.noHistory') }}</div>
|
||||
<div v-else class="divide-y divide-slate-200/70 dark:divide-slate-700/70">
|
||||
<button
|
||||
v-for="item in history"
|
||||
:key="item.conversation_id"
|
||||
class="w-full truncate px-2 py-3 text-left text-sm transition-colors md:px-3"
|
||||
:class="conversationId === item.conversation_id
|
||||
? 'font-semibold text-cyan-700 dark:text-cyan-200'
|
||||
: 'text-slate-600 hover:bg-slate-100/70 hover:text-slate-900 dark:text-slate-300 dark:hover:bg-slate-800/60 dark:hover:text-slate-100'"
|
||||
@click="loadConversation(item.conversation_id); isSidebarOpen = false;"
|
||||
>
|
||||
{{ item.title || $t('chat.newChat') }}
|
||||
</button>
|
||||
<div
|
||||
v-for="item in history"
|
||||
:key="item.conversation_id"
|
||||
class="group relative flex w-full items-center justify-between transition-colors"
|
||||
:class="conversationId === item.conversation_id ? 'bg-slate-100/50 dark:bg-slate-800/30' : 'hover:bg-slate-100/70 dark:hover:bg-slate-800/60'"
|
||||
>
|
||||
<button
|
||||
class="flex-1 truncate px-2 py-3 text-left text-sm md:px-3 pr-8"
|
||||
:class="conversationId === item.conversation_id
|
||||
? 'font-semibold text-cyan-700 dark:text-cyan-200'
|
||||
: 'text-slate-600 hover:text-slate-900 dark:text-slate-300 dark:hover:text-slate-100'"
|
||||
@click="loadConversation(item.conversation_id); isSidebarOpen = false;"
|
||||
>
|
||||
{{ item.title || $t('chat.newChat') }}
|
||||
</button>
|
||||
<button
|
||||
@click="deleteHistoryItem(item.conversation_id, $event)"
|
||||
class="absolute right-2 p-1.5 text-slate-400 opacity-0 transition-opacity hover:text-red-500 group-hover:opacity-100 dark:hover:text-red-400"
|
||||
title="清除该记录"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user