Compare commits

...

42 Commits

Author SHA1 Message Date
c439842bb2 feat: 大模型配置添加思考模式和视觉能力属性
- 数据库 llm_configs 表新增 enable_thinking 和 enable_vision 字段
- 后台管理界面大模型列表显示思考模式/视觉能力状态
- 添加/编辑大模型配置支持设置这两个能力开关
- 前端配置API返回LLM能力信息
- 对话界面根据能力显示或隐藏深度思考按钮
- 对话界面根据能力显示或隐藏上传图片选项
- 不支持视觉能力时上传图片提示用户等待升级

enable_thinking: 控制深度思考功能可用性
enable_vision: 控制图片分析功能可用性
2026-04-29 11:37:57 +08:00
d4b1f3dfff fix: 自动拼接/chat/completions到API URL 2026-04-29 00:30:47 +08:00
dc2e822ea9 fix: 普通对话使用后台配置的LLM 2026-04-28 22:53:22 +08:00
53db607b8d feat: TTS文本清理,过滤Markdown特殊字符和表情 2026-04-28 17:59:15 +08:00
c346418d68 feat: TTS流式播放+新对话默认关闭 2026-04-28 17:51:47 +08:00
7de13ffc6d feat: AI回复语音播放功能(Edge TTS) 2026-04-28 17:28:07 +08:00
60db170c0d fix: 添加获取用户信息的GET API路由 2026-04-28 13:09:13 +08:00
336e3cd12f fix: 登录用户换设备后头像同步,初始化从后台获取最新用户信息 2026-04-28 13:05:54 +08:00
f0d9ca09aa fix: init_db兼容旧数据库,自动添加缺失的系统配置字段 2026-04-28 12:57:33 +08:00
36801e9266 feat: 我的页面和关于页面绑定后台系统配置 2026-04-28 12:48:51 +08:00
5acd9f08f1 fix: 发现智能体搜索支持基础智能体 2026-04-28 11:04:28 +08:00
31732a6303 fix: 历史使用左边标题右边智能体名字 2026-04-28 10:57:57 +08:00
7f576827b0 fix: 历史使用记录左边智能体名字右边标题 2026-04-28 10:55:15 +08:00
8287be10ea feat: 智能体对话标题自动更新+历史显示优化 2026-04-28 10:49:33 +08:00
a56bad11f1 feat: 用户头像在对话界面正确显示 2026-04-28 09:13:49 +08:00
92c187d576 fix: 智能体对话界面不显示工具选择按钮 2026-04-28 00:09:58 +08:00
9eeeace88c fix: 工具选择状态记忆 + 过滤联网搜索 + 默认未启用 2026-04-27 23:56:36 +08:00
ba5d49005b feat: 添加更多工具按钮,支持多选工具 2026-04-27 23:44:37 +08:00
c71f27072a feat: 系统设置可配置版本信息、技术基础、开发者等 2026-04-27 23:32:37 +08:00
22a109d6c0 feat: 用户头像上传功能 2026-04-27 20:02:40 +08:00
0244715a8a fix: LLM和搜索调用时记录统计到backend 2026-04-27 18:50:33 +08:00
1c3f7604c9 feat: 后台管理添加查看用户对话记录功能 2026-04-27 18:38:44 +08:00
0086eaa1d6 feat: 智能体数据同步到backend + 初始化时从backend加载完整数据 2026-04-27 18:33:15 +08:00
8e17ef5e15 fix: 登录时保存完整用户数据 2026-04-27 18:20:49 +08:00
773fb89b01 fix: 对话创建和消息发送时同步到backend 2026-04-27 18:20:06 +08:00
8199773ef6 feat: 用户对话数据同步到backend + 用户资料修改同步 2026-04-27 18:06:55 +08:00
d153986f3d fix: 隐藏注册页面验证码功能(暂时跳过验证) 2026-04-27 17:56:46 +08:00
e9357577cb feat: 后台管理添加用户管理功能 + 前端用户注册登录调用backend API 2026-04-27 17:16:44 +08:00
24ba04b3e3 fix: 智能体历史使用记录只显示真正有对话的智能体 2026-04-27 17:03:50 +08:00
d1ddd340c0 fix: API地址改为相对路径,适应不同设备访问 2026-04-27 15:41:46 +08:00
6ab58cb363 fix: 发现页面条件判断缺少结尾 2026-04-27 15:31:06 +08:00
ba8d0ae679 feat: 前端APP智能体从后台配置加载
- 从后台API(/api/config)获取智能体列表
- 热门智能体 = tags中包含hot标签
- 其他类别 = 根据category字段分类(basic/work/study/life)
- 游客限制从后台配置加载
2026-04-27 15:13:21 +08:00
52d98e88c6 fix: 弹框添加滚动功能 2026-04-27 15:02:31 +08:00
25dff98583 fix: 修复admin.js语法错误 2026-04-27 14:41:06 +08:00
6452e4c976 fix: admin.js版本号更新 2026-04-27 14:33:57 +08:00
f85991064f feat: 智能体管理增加上线开关、标签、可使用工具
智能体新增功能:
- 上线开关(is_online):点击快速切换,未上线则APP不可见
- 标签(tags):支持多标签,逗号分隔(hot/popular/new等)
- 可使用工具(enable_tools):配置智能体可用的工具列表

类别调整:
- 热门改为标签,不再是类别
- 类别改为: basic/work/study/life
- hot=热门标签, popular=推荐标签, new=新品标签

数据库变更:
- agents表新增 is_online 字段
- agents表新增 enable_tools 字段
- 移除 enable_search 字段(改为工具)

API新增:
- /api/admin/agents/<id>/online 切换上线状态
- 前端配置只返回上线且活跃的智能体
2026-04-27 14:15:14 +08:00
c725aeb192 fix: 对话配置扁平化+启用联网搜索移到对话配置
对话配置改为单配置:
- 只有一个默认配置,所有用户共用
- 去掉添加/删除配置按钮和逻辑
- 直接编辑保存配置

配置参数扁平化:
- enable_search 启用联网搜索开关
- LLM配置、可用工具、历史记录数、Temperature、系统提示词

启用联网搜索开关:
- 从系统设置移到对话配置页面
- 开关自动添加/移除 search 工具

系统设置简化:
- 去掉启用联网搜索开关
- 提示用户去对话配置页面设置
2026-04-27 13:04:03 +08:00
423f3aa717 feat: 后台增加对话配置+工具配置管理
新增对话配置页面:
- 配置普通对话使用的LLM、可用工具
- 历史记录数、Temperature、系统提示词
- 支持多配置、设为默认

搜索配置改为工具配置:
- 工具类型: search/calculator/image/code/weather/custom
- 搜索作为工具之一管理
- 支持添加多种工具
- 工具配置: ID、名称、类型、提供商、API、Key、额外配置

API新增:
- /api/admin/chat - 对话配置CRUD
- /api/admin/tools - 工具配置CRUD
- /api/config 返回 tools 和 chat_config
2026-04-27 12:51:44 +08:00
2f60e30169 fix: 端口改为19021 2026-04-27 12:38:50 +08:00
4442d5056a fix: SQL语句错误修复 + 版本号更新 2026-04-27 12:35:24 +08:00
3411de1612 feat: 后台管理系统 (Python Flask)
后台管理功能:
- 大模型接口配置管理(增删改、设为默认)
- 智能体管理(增删改、类别、标签、prompt、LLM配置、热度等)
- 搜索配置管理(Tavily等搜索接口)
- 系统设置(应用名称、版本、游客限制、管理员密码)
- 统计信息(LLM调用、搜索调用、智能体使用排行)

技术方案:
- Python Flask 后端服务 (端口 19020)
- SQLite 数据库存储配置
- 前端后台管理界面 (/admin)
- RESTful API 接口

后台入口:
- URL: http://localhost:19020/admin
- 默认账号: admin / admin123

前端配置获取:
- /api/config 获取LLM、搜索、智能体、系统配置
2026-04-27 12:34:01 +08:00
f24cefb2ab fix: 设置页面返回按钮修复
- switchPage函数增加mainContent存在检查
- 如果当前页面不是主页结构,先调用showMainPage重建页面
- 确保从设置子页面返回能正确回到'我的'页面
2026-04-27 12:22:37 +08:00
9 changed files with 3386 additions and 104 deletions

12
.gitignore vendored Normal file
View File

@@ -0,0 +1,12 @@
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
*.so
*.egg-info/
dist/
build/
*.db
data.db
node_modules/

1011
backend/app.py Normal file

File diff suppressed because it is too large Load Diff

2
backend/requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
flask>=2.0.0
flask-cors>=3.0.0

4
backend/start.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
cd "$(dirname "$0")"
pip install -r requirements.txt -q
python app.py

482
www/admin.html Normal file
View File

@@ -0,0 +1,482 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI助手 - 后台管理</title>
<link rel="stylesheet" href="admin.css?v=3.6.6">
<style>
:root {
--primary: #667eea;
--primary-dark: #5a67d8;
--bg-color: #f5f7fa;
--card-bg: #ffffff;
--text-color: #2d3748;
--text-light: #718096;
--border-color: #e2e8f0;
--danger: #e53e3e;
--success: #22c55e;
--warning: #f59e0b;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg-color);
color: var(--text-color);
line-height: 1.6;
}
/* 登录页面 */
.login-page {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
}
.login-card {
background: white;
padding: 40px;
border-radius: 16px;
width: 350px;
text-align: center;
}
.login-logo {
font-size: 48px;
margin-bottom: 16px;
}
.login-title {
font-size: 24px;
font-weight: 600;
margin-bottom: 24px;
}
.login-input {
width: 100%;
padding: 12px 16px;
border: 2px solid var(--border-color);
border-radius: 10px;
font-size: 16px;
margin-bottom: 16px;
outline: none;
}
.login-input:focus {
border-color: var(--primary);
}
.login-btn {
width: 100%;
padding: 14px;
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 10px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
margin-top: 8px;
}
.login-btn:hover {
opacity: 0.9;
}
/* 主页面 */
.admin-page {
display: none;
}
.admin-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px 24px;
background: white;
border-bottom: 1px solid var(--border-color);
}
.admin-logo {
display: flex;
align-items: center;
gap: 8px;
font-size: 20px;
font-weight: 600;
}
.admin-logo span {
font-size: 28px;
}
.admin-header-right {
display: flex;
align-items: center;
gap: 16px;
}
.admin-logout {
padding: 8px 16px;
background: var(--danger);
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
}
/* 侧边栏 */
.admin-container {
display: flex;
height: calc(100vh - 60px);
}
.admin-sidebar {
width: 220px;
background: white;
border-right: 1px solid var(--border-color);
padding: 16px;
}
.sidebar-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 16px;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s;
margin-bottom: 4px;
}
.sidebar-item:hover {
background: rgba(102, 126, 234, 0.1);
}
.sidebar-item.active {
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
color: white;
}
.sidebar-icon {
font-size: 20px;
}
/* 内容区 */
.admin-content {
flex: 1;
padding: 24px;
overflow-y: auto;
}
.content-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24px;
}
.content-title {
font-size: 24px;
font-weight: 600;
}
.add-btn {
padding: 10px 20px;
background: var(--primary);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
}
/* 数据卡片 */
.stats-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 16px;
margin-bottom: 24px;
}
.stat-card {
background: white;
padding: 20px;
border-radius: 12px;
text-align: center;
}
.stat-icon {
font-size: 32px;
margin-bottom: 8px;
}
.stat-value {
font-size: 28px;
font-weight: 600;
color: var(--primary);
}
.stat-label {
font-size: 14px;
color: var(--text-light);
}
/* 数据表格 */
.data-table {
background: white;
border-radius: 12px;
overflow: hidden;
}
.data-table table {
width: 100%;
border-collapse: collapse;
}
.data-table th, .data-table td {
padding: 14px 16px;
text-align: left;
border-bottom: 1px solid var(--border-color);
}
.data-table th {
background: var(--bg-color);
font-weight: 600;
color: var(--text-light);
}
.data-table tr:last-child td {
border-bottom: none;
}
.data-table tr:hover td {
background: rgba(102, 126, 234, 0.05);
}
/* 操作按钮 */
.action-btns {
display: flex;
gap: 8px;
}
.action-btn {
padding: 6px 12px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 12px;
}
.action-btn.edit {
background: var(--primary);
color: white;
}
.action-btn.delete {
background: var(--danger);
color: white;
}
.action-btn.default {
background: var(--success);
color: white;
}
/* 默认标记 */
.default-badge {
padding: 4px 8px;
background: var(--success);
color: white;
border-radius: 4px;
font-size: 12px;
}
/* 模态框 */
.modal {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.5);
display: none;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal.show {
display: flex;
}
.modal-content {
background: white;
padding: 24px;
border-radius: 16px;
max-width: 500px;
width: 90%;
max-height: 80vh;
overflow-y: auto;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24px;
}
.modal-title {
font-size: 20px;
font-weight: 600;
}
.modal-close {
font-size: 24px;
cursor: pointer;
color: var(--text-light);
}
.form-group {
margin-bottom: 16px;
}
.form-label {
display: block;
font-size: 14px;
font-weight: 500;
margin-bottom: 8px;
}
.form-input, .form-select, .form-textarea {
width: 100%;
padding: 12px;
border: 1px solid var(--border-color);
border-radius: 8px;
font-size: 14px;
outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
border-color: var(--primary);
}
.form-textarea {
resize: vertical;
min-height: 100px;
}
.form-submit {
width: 100%;
padding: 14px;
background: var(--primary);
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
margin-top: 16px;
}
/* Toast */
.toast {
position: fixed;
top: 80px;
left: 50%;
transform: translateX(-50%);
background: var(--text-color);
color: white;
padding: 12px 24px;
border-radius: 8px;
font-size: 14px;
opacity: 0;
transition: opacity 0.3s;
z-index: 2000;
}
.toast.show {
opacity: 1;
}
</style>
</head>
<body>
<!-- 登录页面 -->
<div class="login-page" id="loginPage">
<div class="login-card">
<div class="login-logo">🤖</div>
<h1 class="login-title">后台管理系统</h1>
<input type="text" class="login-input" id="loginUsername" placeholder="用户名">
<input type="password" class="login-input" id="loginPassword" placeholder="密码">
<button class="login-btn" id="loginBtn">登录</button>
<p style="margin-top: 16px; color: #999; font-size: 12px;">默认: admin / admin123</p>
</div>
</div>
<!-- 管理页面 -->
<div class="admin-page" id="adminPage">
<header class="admin-header">
<div class="admin-logo">
<span>🤖</span>
AI助手 - 后台管理
</div>
<div class="admin-header-right">
<span id="adminName">管理员</span>
<button class="admin-logout" id="logoutBtn">退出</button>
</div>
</header>
<div class="admin-container">
<aside class="admin-sidebar">
<div class="sidebar-item active" data-page="stats">
<span class="sidebar-icon">📊</span>
<span>统计信息</span>
</div>
<div class="sidebar-item" data-page="users">
<span class="sidebar-icon">👥</span>
<span>用户管理</span>
</div>
<div class="sidebar-item" data-page="llm">
<span class="sidebar-icon">🧠</span>
<span>大模型配置</span>
</div>
<div class="sidebar-item" data-page="agents">
<span class="sidebar-icon">🤖</span>
<span>智能体管理</span>
</div>
<div class="sidebar-item" data-page="chat">
<span class="sidebar-icon">💬</span>
<span>对话配置</span>
</div>
<div class="sidebar-item" data-page="tools">
<span class="sidebar-icon">🔧</span>
<span>工具配置</span>
</div>
<div class="sidebar-item" data-page="system">
<span class="sidebar-icon">⚙️</span>
<span>系统设置</span>
</div>
</aside>
<main class="admin-content" id="mainContent">
<!-- 内容区动态加载 -->
</main>
</div>
</div>
<!-- Toast -->
<div class="toast" id="toast"></div>
<!-- 模态框 -->
<div class="modal" id="modal">
<div class="modal-content" id="modalContent">
<!-- 动态内容 -->
</div>
</div>
<script src="admin.js?v=3.6.6"></script>
</body>
</html>

1342
www/admin.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -19,39 +19,18 @@ let isLoading = false;
// 当前页面状态
let currentPage = 'chats'; // chats | agents | profile
// 系统智能体数据(完整列表
let systemAgents = [
// 热门智能体
{ id: 'assistant', name: '通用助手', avatar: '🤖', category: 'hot', desc: '能回答各类问题,帮助写作、分析、解答疑惑', systemPrompt: '你是一个智能助手,能够回答各类问题,帮助用户解决问题。', heat: 9500 },
{ id: 'writer', name: '写作助手', avatar: '✍️', category: 'hot', desc: '专注于文章写作、文案创作、内容润色', systemPrompt: '你是一个专业的写作助手,擅长各类文章写作、文案创作和内容润色。', heat: 8800 },
{ id: 'coder', name: '编程助手', avatar: '👨‍💻', category: 'hot', desc: '精通编程语言,解答技术问题,生成代码', systemPrompt: '你是一个专业的编程助手,精通各类编程语言,能够解答技术问题并生成高质量代码。', heat: 8500 },
{ id: 'translator', name: '翻译助手', avatar: '🌐', category: 'hot', desc: '多语言翻译,精准表达,文化适配', systemPrompt: '你是一个专业的翻译助手,精通多语言翻译,能够精准表达并适配文化差异。', heat: 7200 },
// 工作助手
{ id: 'assistant-work', name: '工作助手', avatar: '💼', category: 'work', desc: '职场问题解答,工作效率提升', systemPrompt: '你是一个工作助手,帮助解决职场问题,提升工作效率。', heat: 5000 },
{ id: 'ppt', name: 'PPT助手', avatar: '📊', category: 'work', desc: 'PPT内容生成结构优化设计建议', systemPrompt: '你是一个PPT助手擅长PPT内容生成、结构优化和设计建议。', heat: 4500 },
{ id: 'excel', name: 'Excel助手', avatar: '📈', category: 'work', desc: 'Excel公式、数据分析、表格优化', systemPrompt: '你是一个Excel助手精通Excel公式、数据分析和表格优化。', heat: 4000 },
// 学习助手
{ id: 'teacher', name: '学习助手', avatar: '📚', category: 'study', desc: '知识讲解,学习方法,考试辅导', systemPrompt: '你是一个学习助手,擅长知识讲解、学习方法指导和考试辅导。', heat: 5500 },
{ id: 'english', name: '英语助手', avatar: '🔤', category: 'study', desc: '英语学习,语法纠正,口语练习', systemPrompt: '你是一个英语助手,帮助英语学习、语法纠正和口语练习。', heat: 5000 },
{ id: 'math', name: '数学助手', avatar: '🔢', category: 'study', desc: '数学解题,公式推导,概念讲解', systemPrompt: '你是一个数学助手,擅长数学解题、公式推导和概念讲解。', heat: 4500 },
// 生活助手
{ id: 'health', name: '健康助手', avatar: '🏥', category: 'life', desc: '健康咨询,养生建议,运动指导', systemPrompt: '你是一个健康助手,提供健康咨询、养生建议和运动指导。', heat: 3500 },
{ id: 'travel', name: '旅行助手', avatar: '✈️', category: 'life', desc: '旅行规划,景点推荐,美食指南', systemPrompt: '你是一个旅行助手,擅长旅行规划、景点推荐和美食指南。', heat: 3200 },
{ id: 'food', name: '美食助手', avatar: '🍳', category: 'life', desc: '菜谱推荐,烹饪技巧,营养搭配', systemPrompt: '你是一个美食助手,提供菜谱推荐、烹饪技巧和营养搭配建议。', heat: 3000 },
];
// 系统智能体数据(从后台API加载
let systemAgents = [];
// 用户智能体界面显示的智能体(默认显示热门智能体)
// 用户智能体界面显示的智能体
let agents = [];
// 用户添加的智能体(按类别分组)
let myAgents = {
hot: ['assistant', 'writer', 'coder', 'translator'],
work: ['assistant-work', 'ppt', 'excel'],
study: ['teacher', 'english', 'math'],
life: ['health', 'travel', 'food']
basic: [],
work: [],
study: [],
life: []
};
// 收藏的智能体列表
@@ -59,7 +38,7 @@ let favoriteAgents = [];
// 置顶的智能体列表(按类别)
let pinnedAgents = {
hot: [],
basic: [],
work: [],
study: [],
life: []
@@ -67,6 +46,9 @@ let pinnedAgents = {
let currentAgent = null; // 当前选中的智能体
// 后台配置
let backendConfig = null; // 从API获取的配置
// 用户状态
let currentUser = null; // 当前登录用户 { username, password, registeredAt }
@@ -79,12 +61,12 @@ let dailyUsage = {
agentMessages: 0 // 智能体消息数
};
// 未登录用户限制
const GUEST_LIMITS = {
maxChatSessionsPerDay: 1, // 每天最多1个对话会话
maxChatMessagesPerDay: 20, // 每天最多20条对话消息
maxAgentPerDay: 1, // 每天只能用1个智能体通用助手
maxAgentMessagesPerDay: 20 // 每天最多20条智能体消息
// 未登录用户限制(从后台配置加载)
let GUEST_LIMITS = {
maxChatSessionsPerDay: 1,
maxChatMessagesPerDay: 20,
maxAgentPerDay: 1,
maxAgentMessagesPerDay: 20
};
// 获取今日日期字符串
@@ -93,6 +75,66 @@ function getTodayDate() {
return `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`;
}
// 从后台API加载配置
async function loadBackendConfig() {
try {
// 使用相对路径,自动适当前域名
const API_BASE = window.location.origin;
const res = await fetch(`${API_BASE}/api/config`);
backendConfig = await res.json();
// 加载智能体列表
if (backendConfig.agents) {
systemAgents = backendConfig.agents.map(a => ({
id: a.agent_id,
name: a.name,
avatar: a.avatar,
category: a.category,
desc: a.description,
systemPrompt: a.system_prompt,
heat: a.heat || 0,
tags: a.tags || '',
enable_tools: a.enable_tools || ''
}));
// 初始化用户智能体列表(按类别)
systemAgents.forEach(agent => {
if (!myAgents[agent.category]) {
myAgents[agent.category] = [];
}
myAgents[agent.category].push(agent.id);
});
}
// 加载游客限制配置
if (backendConfig.system?.guestLimits) {
GUEST_LIMITS = {
maxChatSessionsPerDay: backendConfig.system.guestLimits.chatSessions || 1,
maxChatMessagesPerDay: backendConfig.system.guestLimits.chatMessages || 20,
maxAgentPerDay: 1, // 游客只能用通用助手
maxAgentMessagesPerDay: backendConfig.system.guestLimits.agentMessages || 20
};
}
// 加载LLM能力配置思考模式、视觉能力
if (backendConfig.llm) {
llmCapabilities.thinking = backendConfig.llm.enable_thinking === 1;
llmCapabilities.vision = backendConfig.llm.enable_vision === 1;
console.log('LLM能力: 思考模式=', llmCapabilities.thinking, '视觉=', llmCapabilities.vision);
}
updateAgentsDisplay();
console.log('后台配置已加载', backendConfig);
} catch (e) {
console.error('加载后台配置失败', e);
// 使用默认配置
systemAgents = [
{ id: 'assistant', name: '通用助手', avatar: '🤖', category: 'basic', desc: '能回答各类问题,帮助写作、分析、解答疑惑', systemPrompt: '你是一个智能助手,能够回答各类问题,帮助用户解决问题。', heat: 9500, tags: 'hot' },
];
updateAgentsDisplay();
}
}
// 检查并重置每日使用统计
function checkDailyUsage() {
const today = getTodayDate();
@@ -228,9 +270,10 @@ function getRemainingQuota() {
}
// 获取使用智能体的对话列表(按时间倒序)
// 只返回真正有对话消息的记录messages.length > 0
function getAgentConversationHistory(limit = 5) {
return conversations
.filter(conv => conv.agentId) // 筛选有智能体的对话
.filter(conv => conv.agentId && conv.messages && conv.messages.length > 0) // 筛选有智能体且有消息的对话
.sort((a, b) => b.updatedAt - a.updatedAt) // 按更新时间倒序
.slice(0, limit)
.map(conv => {
@@ -247,6 +290,12 @@ let enableThinking = false; // 深度思考
let enableSearch = false; // 联网搜索
let autoScrollEnabled = true; // 自动滚动(用户滚动后可关闭)
// LLM 能力标志(从后台配置加载)
let llmCapabilities = {
thinking: false, // 是否支持思考模式
vision: false // 是否支持视觉能力
};
// DOM 元素(初始为 null在 openConversation 时重新获取)
let appContainer = null;
let messagesContainer = null;
@@ -321,7 +370,7 @@ document.addEventListener('DOMContentLoaded', () => {
checkDailyUsage();
// 根据用户配置更新显示的智能体
updateAgentsDisplay();
// updateAgentsDisplay(); // 先不调用,等后台配置加载后再更新
// 加载当前页面状态
const savedPage = localStorage.getItem('currentPage');
@@ -329,8 +378,13 @@ document.addEventListener('DOMContentLoaded', () => {
currentPage = savedPage;
}
// 显示主页
showMainPage();
// 加载后台配置并显示主页
loadBackendConfig().then(() => {
showMainPage();
}).catch(() => {
// 即使加载失败也显示主页
showMainPage();
});
});
// 根据用户配置更新显示的智能体
@@ -429,16 +483,21 @@ function switchPage(page) {
currentPage = page;
localStorage.setItem('currentPage', page);
// 先确保页面结构正确(如果当前不在主页结构)
const mainContent = document.getElementById('mainContent');
if (!mainContent) {
// 重新渲染主页结构
showMainPage();
return; // showMainPage 会自动调用 renderCurrentPage
}
// 更新导航栏状态
document.querySelectorAll('.nav-item').forEach(item => {
item.classList.toggle('active', item.getAttribute('data-page') === page);
});
// 更新内容区
const mainContent = document.getElementById('mainContent');
if (mainContent) {
mainContent.innerHTML = renderCurrentPage();
}
mainContent.innerHTML = renderCurrentPage();
// 绑定页面事件
bindPageEvents();
@@ -639,8 +698,11 @@ function bindChatsPageEvents() {
// ==================== 智能体页面 ====================
function renderAgentsPage() {
// 根据用户配置筛选智能体
const hotAgents = agents.filter(a => a.category === 'hot');
// 根据后台配置筛选智能体
// 热门智能体 = 标签中包含 "hot"
const hotAgents = agents.filter(a => a.tags && a.tags.split(',').includes('hot'));
// 其他类别 = 根据 category 字段分类
const basicAgents = agents.filter(a => a.category === 'basic');
const workAgents = agents.filter(a => a.category === 'work');
const studyAgents = agents.filter(a => a.category === 'study');
const lifeAgents = agents.filter(a => a.category === 'life');
@@ -693,7 +755,7 @@ function renderAgentsPage() {
</div>
` : ''}
<!-- 热门智能体 -->
<!-- 热门智能体标签为hot -->
${hotAgents.length > 0 ? `
<div class="agents-section">
<div class="section-title">🔥 热门智能体</div>
@@ -1027,7 +1089,10 @@ function showAgentDiscoverPage() {
const sortedAgents = [...systemAgents].sort((a, b) => b.heat - a.heat);
// 分类显示
const hotAgents = systemAgents.filter(a => a.category === 'hot');
// 热门智能体 = 标签中包含 "hot"
const hotAgents = systemAgents.filter(a => a.tags && a.tags.split(',').includes('hot'));
// 其他类别
const basicAgents = systemAgents.filter(a => a.category === 'basic');
const workAgents = systemAgents.filter(a => a.category === 'work');
const studyAgents = systemAgents.filter(a => a.category === 'study');
const lifeAgents = systemAgents.filter(a => a.category === 'life');
@@ -1048,37 +1113,55 @@ function showAgentDiscoverPage() {
<input type="text" id="discoverSearchInput" placeholder="搜索智能体名称或描述...">
</div>
<!-- 热门智能体 -->
<!-- 热门智能体标签为hot -->
${hotAgents.length > 0 ? `
<div class="discover-section">
<div class="discover-section-title">🔥 热门智能体</div>
<div class="discover-grid" id="discoverHotGrid">
${hotAgents.map(agent => renderDiscoverCard(agent)).join('')}
</div>
</div>
` : ''}
<!-- 基础智能体 -->
${basicAgents.length > 0 ? `
<div class="discover-section">
<div class="discover-section-title">⭐ 基础智能体</div>
<div class="discover-grid" id="discoverBasicGrid">
${basicAgents.map(agent => renderDiscoverCard(agent)).join('')}
</div>
</div>
` : ''}
<!-- 工作助手 -->
${workAgents.length > 0 ? `
<div class="discover-section">
<div class="discover-section-title">💼 工作助手</div>
<div class="discover-grid" id="discoverWorkGrid">
${workAgents.map(agent => renderDiscoverCard(agent)).join('')}
</div>
</div>
` : ''}
<!-- 学习助手 -->
${studyAgents.length > 0 ? `
<div class="discover-section">
<div class="discover-section-title">📚 学习助手</div>
<div class="discover-grid" id="discoverStudyGrid">
${studyAgents.map(agent => renderDiscoverCard(agent)).join('')}
</div>
</div>
` : ''}
<!-- 生活助手 -->
${lifeAgents.length > 0 ? `
<div class="discover-section">
<div class="discover-section-title">🏠 生活助手</div>
<div class="discover-grid" id="discoverLifeGrid">
${lifeAgents.map(agent => renderDiscoverCard(agent)).join('')}
</div>
</div>
` : ''}
</div>
</div>
`;
@@ -1440,7 +1523,7 @@ function renderProfilePage() {
</div>
<div class="profile-footer">
<p>AI助手 v3.5.0</p>
<p>AI助手 v3.6.0</p>
<p>基于智谱 GLM-4.5-Air</p>
</div>
</div>
@@ -2377,18 +2460,34 @@ function handleLogin() {
return;
}
// 检查本地存储的用户
const users = JSON.parse(localStorage.getItem('registeredUsers') || '[]');
const user = users.find(u => u.username === username && u.password === password);
if (user) {
currentUser = { username: user.username, registeredAt: user.registeredAt };
saveCurrentUser();
showToast('登录成功');
showMainPage();
} else {
showToast('用户名或密码错误');
}
// 调用后台登录API
fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
})
.then(res => res.json())
.then(data => {
if (data.success) {
currentUser = {
id: data.user.id,
username: data.user.username,
phone: data.user.phone,
email: data.user.email || '',
avatar: data.user.avatar || '👤',
signature: data.user.signature || '',
registeredAt: Date.now()
};
saveCurrentUser();
showToast('登录成功');
showMainPage();
} else {
showToast(data.error || '用户名或密码错误');
}
})
.catch(e => {
showToast('网络错误,请重试');
});
}
// ==================== 注册页面 ====================
@@ -2407,12 +2506,21 @@ function showRegisterPage() {
<div class="auth-form">
<div class="auth-input-group">
<label>用户名</label>
<input type="text" id="registerUsername" placeholder="请输入用户名(3-20字符" autocomplete="username">
<input type="text" id="registerUsername" placeholder="请输入用户名(2-20字符" autocomplete="username">
</div>
<div class="auth-input-group">
<label>手机号 <span class="required">*</span></label>
<input type="tel" id="registerPhone" placeholder="请输入手机号" maxlength="11" autocomplete="tel">
</div>
<div class="auth-input-group" style="display: flex; gap: 8px;">
<div style="flex: 1;">
<label>验证码 <span class="required">*</span></label>
<input type="text" id="registerCode" placeholder="请输入验证码" maxlength="6">
</div>
<div style="flex-shrink: 0; align-self: flex-end;">
<button class="send-code-btn" id="getCodeBtn">获取验证码</button>
</div>
</div>
<div class="auth-input-group">
<label>邮箱 <span class="optional">(可选)</span></label>
<input type="email" id="registerEmail" placeholder="请输入邮箱(可选)" autocomplete="email">
@@ -2457,6 +2565,12 @@ function showRegisterPage() {
});
}
// 获取验证码按钮
const getCodeBtn = document.getElementById('getCodeBtn');
if (getCodeBtn) {
getCodeBtn.addEventListener('click', handleGetCode);
}
// 回车注册
document.getElementById('registerPasswordConfirm')?.addEventListener('keydown', (e) => {
if (e.key === 'Enter') handleRegister();
@@ -2469,6 +2583,50 @@ function showRegisterPage() {
e.target.value = e.target.value.replace(/\D/g, '');
});
}
// 验证码输入限制(只允许数字)
const codeInput = document.getElementById('registerCode');
if (codeInput) {
codeInput.addEventListener('input', (e) => {
e.target.value = e.target.value.replace(/\D/g, '');
});
}
}
// 获取验证码(模拟)
let verifyCode = '';
let codeExpireTime = 0;
function handleGetCode() {
const phone = document.getElementById('registerPhone')?.value.trim();
if (!validatePhone(phone)) {
showToast('请先输入正确的手机号');
return;
}
// 生成6位随机验证码
verifyCode = Math.floor(100000 + Math.random() * 900000).toString();
codeExpireTime = Date.now() + 5 * 60 * 1000; // 5分钟有效
// 模拟发送实际项目中应调用短信API
showToast(`验证码已发送: ${verifyCode}(演示)`);
// 60秒倒计时
const getCodeBtn = document.getElementById('getCodeBtn');
if (getCodeBtn) {
getCodeBtn.disabled = true;
let countdown = 60;
const timer = setInterval(() => {
getCodeBtn.textContent = `${countdown}s`;
countdown--;
if (countdown <= 0) {
clearInterval(timer);
getCodeBtn.disabled = false;
getCodeBtn.textContent = '获取验证码';
}
}, 1000);
}
}
// 验证手机号格式
@@ -2489,12 +2647,13 @@ function handleRegister() {
const username = document.getElementById('registerUsername')?.value.trim();
const phone = document.getElementById('registerPhone')?.value.trim();
const email = document.getElementById('registerEmail')?.value.trim();
const code = document.getElementById('registerCode')?.value.trim();
const password = document.getElementById('registerPassword')?.value;
const passwordConfirm = document.getElementById('registerPasswordConfirm')?.value;
// 验证用户名
if (!username || username.length < 3 || username.length > 20) {
showToast('用户名需要3-20个字符');
if (!username || username.length < 2 || username.length > 20) {
showToast('用户名需要2-20个字符');
return;
}
@@ -2504,8 +2663,20 @@ function handleRegister() {
return;
}
// 验证验证码
if (!code || code.length !== 6) {
showToast('请输入6位验证码');
return;
}
// 检查验证码是否正确(模拟)
if (code !== verifyCode || Date.now() > codeExpireTime) {
showToast('验证码不正确或已过期');
return;
}
// 验证邮箱(可选)
if (!validateEmail(email)) {
if (email && !validateEmail(email)) {
showToast('请输入正确的邮箱格式');
return;
}
@@ -2521,37 +2692,39 @@ function handleRegister() {
return;
}
// 检查用户名是否已存在
const users = JSON.parse(localStorage.getItem('registeredUsers') || '[]');
if (users.find(u => u.username === username)) {
showToast('用户名已存在');
return;
}
// 检查手机号是否已注册
if (users.find(u => u.phone === phone)) {
showToast('该手机号已注册');
return;
}
// 注册新用户
const newUser = {
username,
phone,
email: email || '',
password,
registeredAt: Date.now()
};
users.push(newUser);
localStorage.setItem('registeredUsers', JSON.stringify(users));
// 自动登录
currentUser = { username: newUser.username, phone: newUser.phone, registeredAt: newUser.registeredAt };
saveCurrentUser();
showToast('注册成功');
showMainPage();
// 调用后台注册API
fetch('/api/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
username,
phone,
email: email || '',
password,
code
})
})
.then(res => res.json())
.then(data => {
if (data.success) {
// 注册成功,自动登录
currentUser = {
id: data.user_id,
username: username,
phone: phone,
email: email || '',
registeredAt: Date.now()
};
saveCurrentUser();
showToast('注册成功');
showMainPage();
} else {
showToast(data.error || '注册失败');
}
})
.catch(e => {
showToast('网络错误,请重试');
});
}
// ==================== 限制提示 ====================
@@ -2757,10 +2930,12 @@ function showAgentChatPage() {
<!-- 功能开关栏 -->
<div class="feature-bar" id="featureBar">
<div class="feature-left">
${llmCapabilities.thinking ? `
<button class="feature-btn thinking-btn" id="thinkingBtn">
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>
<span>深度思考</span>
</button>
` : ''}
<button class="feature-btn search-btn" id="searchBtn">
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 7 9.5 7 14 9.01 14 9.5 11.99 14 9.5 14z"/></svg>
<span>联网搜索</span>
@@ -2780,7 +2955,7 @@ function showAgentChatPage() {
<button class="attach-btn" id="attachBtn" title="上传文件">
<svg viewBox="0 0 24 24" width="24" height="24"><path fill="currentColor" d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>
</button>
<textarea id="userInput" placeholder="输入消息..." rows="1"></textarea>
<textarea id="userInput" placeholder="${llmCapabilities.vision ? '输入消息或上传图片...' : '输入消息...'}" rows="1"></textarea>
<button class="send-btn" id="sendBtn">
<svg viewBox="0 0 24 24" width="24" height="24"><path fill="currentColor" d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>
</button>
@@ -2789,10 +2964,12 @@ function showAgentChatPage() {
<!-- 上传选项弹窗 -->
<div class="attach-panel" id="attachPanel">
<div class="attach-panel-content">
${llmCapabilities.vision ? `
<div class="attach-item" data-type="image">
<div class="attach-icon">📷</div>
<div class="attach-label">上传图片</div>
</div>
` : ''}
<div class="attach-item" data-type="file">
<div class="attach-icon">📄</div>
<div class="attach-label">上传文件</div>
@@ -3225,10 +3402,12 @@ function openConversation(id) {
<!-- 功能开关栏 -->
<div class="feature-bar">
<div class="feature-left">
${llmCapabilities.thinking ? `
<button class="feature-btn thinking-btn ${enableThinking ? 'active' : ''}" id="thinkingBtn">
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>
<span>深度思考</span>
</button>
` : ''}
<button class="feature-btn search-btn ${enableSearch ? 'active' : ''}" id="searchBtn">
<svg viewBox="0 0 24 24" width="16" height="16"><path fill="currentColor" d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 7 9.5 7 14 9.01 14 9.5 11.99 14 9.5 14z"/></svg>
<span>联网搜索</span>
@@ -3250,7 +3429,7 @@ function openConversation(id) {
</button>
<textarea
id="userInput"
placeholder="输入消息..."
placeholder="${llmCapabilities.vision ? '输入消息或上传图片...' : '输入消息...'}"
rows="1"
></textarea>
<button class="send-btn" id="sendBtn">
@@ -3261,10 +3440,12 @@ function openConversation(id) {
<!-- 上传选项弹窗 -->
<div class="attach-panel" id="attachPanel">
<div class="attach-panel-content">
${llmCapabilities.vision ? `
<div class="attach-item" data-type="image">
<div class="attach-icon">📷</div>
<div class="attach-label">上传图片</div>
</div>
` : ''}
<div class="attach-item" data-type="file">
<div class="attach-icon">📄</div>
<div class="attach-label">上传文件</div>
@@ -4126,6 +4307,13 @@ async function handleImageUpload(e) {
const file = e.target.files[0];
if (!file) return;
// 检查是否支持视觉能力
if (!llmCapabilities.vision) {
showToast('当前大模型不支持图片分析功能,请等待后期升级');
e.target.value = '';
return;
}
// 读取图片为base64
const reader = new FileReader();
reader.onload = async (event) => {

View File

@@ -8,12 +8,12 @@
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>AI助手</title>
<link rel="stylesheet" href="style.css?v=3.5.0">
<link rel="stylesheet" href="style.css?v=3.5.1">
<link rel="manifest" href="manifest.json">
</head>
<body>
<div id="app"></div>
<script src="marked.min.js?v=3.5.0"></script>
<script src="app.js?v=3.5.0"></script>
<script src="marked.min.js?v=3.5.1"></script>
<script src="app.js?v=3.5.1"></script>
</body>
</html>

View File

@@ -1049,6 +1049,31 @@ body {
box-shadow: 0 0 8px rgba(102, 126, 234, 0.3);
}
.avatar-upload-section {
display: flex;
justify-content: center;
margin-bottom: 16px;
}
.avatar-upload-btn {
display: flex;
align-items: center;
gap: 8px;
padding: 12px 24px;
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 10px;
font-size: 14px;
cursor: pointer;
transition: all 0.2s;
}
.avatar-upload-btn:hover {
transform: scale(1.02);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
.edit-input-group {
margin-bottom: 16px;
}
@@ -1705,6 +1730,16 @@ body {
color: var(--primary);
}
.recent-agent-title {
font-size: 14px;
color: #333;
font-weight: 500;
max-width: 120px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.recent-agent-agent-name {
font-size: 12px;
color: var(--primary);
@@ -1782,7 +1817,17 @@ body {
color: var(--primary);
}
.agent-history-agent {
.agent-history-title {
font-size: 14px;
color: #333;
font-weight: 500;
max-width: 150px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.agent-history-agent-name {
font-size: 12px;
color: var(--primary);
background: rgba(102, 126, 234, 0.1);
@@ -2350,7 +2395,8 @@ body {
font-size: 20px;
}
.clear-btn {
/* TTS 语音播放按钮 */
.tts-btn {
background: rgba(255,255,255,0.2);
border: none;
border-radius: 8px;
@@ -2359,10 +2405,18 @@ body {
cursor: pointer;
}
.clear-btn:active {
.tts-btn:hover {
background: rgba(255,255,255,0.3);
}
.tts-btn.active {
background: rgba(255,255,255,0.4);
}
.tts-btn svg {
display: block;
}
.messages-container {
flex: 1;
overflow-y: auto;
@@ -2715,6 +2769,193 @@ body {
flex-shrink: 0;
}
/* 更多工具按钮 */
.tools-btn {
position: relative;
}
.tools-count {
position: absolute;
top: -4px;
right: -4px;
min-width: 16px;
height: 16px;
padding: 0 4px;
background: #ef4444;
color: white;
font-size: 11px;
font-weight: 600;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
}
/* 工具选择弹窗 */
.tools-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.tools-popup-content {
width: 90%;
max-width: 400px;
background: white;
border-radius: 16px;
overflow: hidden;
}
.tools-popup-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
color: white;
}
.tools-popup-header h3 {
margin: 0;
font-size: 18px;
}
.tools-popup-close {
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.2);
border: none;
border-radius: 14px;
color: white;
font-size: 20px;
cursor: pointer;
transition: background 0.2s;
}
.tools-popup-close:hover {
background: rgba(255, 255, 255, 0.3);
}
.tools-popup-body {
padding: 16px 20px;
}
.tools-popup-tip {
color: #718096;
font-size: 13px;
margin-bottom: 16px;
}
.tools-list {
display: flex;
flex-direction: column;
gap: 12px;
max-height: 300px;
overflow-y: auto;
}
.tool-option {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 16px;
background: #f5f7fa;
border: 2px solid transparent;
border-radius: 12px;
cursor: pointer;
transition: all 0.2s;
}
.tool-option:hover {
background: #e8ecf1;
}
.tool-option.selected {
background: rgba(102, 126, 234, 0.1);
border-color: var(--primary);
}
.tool-checkbox {
flex-shrink: 0;
color: #718096;
}
.tool-option.selected .tool-checkbox {
color: var(--primary);
}
.tool-icon {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
background: white;
border-radius: 10px;
font-size: 20px;
}
.tool-info {
flex: 1;
}
.tool-name {
font-weight: 500;
color: #2d3748;
}
.tool-type {
font-size: 12px;
color: #718096;
margin-top: 2px;
}
.tools-popup-footer {
display: flex;
gap: 12px;
padding: 16px 20px;
background: #f5f7fa;
}
.tools-popup-btn {
flex: 1;
padding: 12px;
border: none;
border-radius: 10px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
}
.tools-popup-btn.cancel {
background: #e2e8f0;
color: #4a5568;
}
.tools-popup-btn.cancel:hover {
background: #cbd5e0;
}
.tools-popup-btn.confirm {
background: linear-gradient(135deg, var(--primary) 0%, #764ba2 100%);
color: white;
}
.tools-popup-btn.confirm:hover {
transform: scale(1.02);
}
/* 导航按钮样式 */
.nav-btn {
padding: 6px 8px;