1. 管理后台支持为不同 Agent 应用上传和管理视频、PDF 等新手指南资料。
2. 前端聊天界面根据后台配置,动态展示“新手指南”入口。
3. 用户点击后可直接在系统内预览视频或 PDF 文档。
This commit is contained in:
runny committed 2026-06-04 12:47:21 +08:00
1 parent cc53d29e76
commit f8de4630a5
19 files changed
+742 -122

No files matched your search

+44 -2
View File
@@ -4,11 +4,13 @@ backend/app/api/agents.py
引用文件:flask, models, decorators
逻辑关系:根据当前用户的权限返回其可访问的 Agent 集合
"""
from flask import Blueprint, jsonify
import os
from flask import Blueprint, jsonify, send_from_directory
from app import db
from app.decorators import _get_current_user # 内部工具函数
from app.models import Agent, User
from app.models import Agent, User, AgentGuide
from app.services.minio_service import minio_service
# 定义 Blueprint,将在应用工厂中注册为 /api/agents
agents_bp = Blueprint('agents', __name__)
@@ -58,6 +60,41 @@ def list_user_agents():
# 序列化为前端所需字段
return jsonify([_serialize_agent_row(row) for row in agent_rows])
@agents_bp.route('/<int:agent_id>/guides', methods=['GET'])
def list_agent_guides(agent_id):
"""
获取指定应用的新手指南列表 (需登录)
用途:客户端 Chat 界面点击新手指南
"""
_get_current_user() # 确保已登录
if agent_id == 0:
generic_agent = db.session.query(Agent).filter_by(name='通用入口').first()
if generic_agent:
agent_id = generic_agent.id
else:
return jsonify([])
guides = (
db.session.query(AgentGuide)
.filter_by(agent_id=agent_id, status=1)
.order_by(AgentGuide.sort_order.asc(), AgentGuide.created_at.desc())
.all()
)
result = []
for g in guides:
result.append({
'id': g.id,
'file_name': g.file_name,
'file_type': g.file_type,
'file_url': minio_service.get_public_url(g.file_path),
'file_size': g.file_size,
'remark': g.remark,
'updated_at': g.updated_at.isoformat()
})
return jsonify(result)
@agents_bp.route('/public', methods=['GET'])
def list_public_agents():
"""
@@ -73,4 +110,9 @@ def list_public_agents():
)
return jsonify([_serialize_agent_row(row) for row in agent_rows])
# 为了兼容本地无MinIO的环境,暴露一个静态文件读取接口
@agents_bp.route('/guides/files/<path:filename>', methods=['GET'])
def serve_guide_file(filename):
return send_from_directory(os.path.join(os.getcwd(), 'data', 'agent-guides'), filename)