feat(agent): 增强 Agent 配置,新增结构化字段与聊天功能支持

This commit is contained in:
hugo committed 2026-07-07 11:10:32 +08:00
1 parent ac4262cd75
commit c8ce77199e
183 files changed
+11690 -2300

No files matched your search

+18 -22
View File
@@ -10,6 +10,7 @@ from app import db
from app.models import User, Agent, QuickQuestion, UserFavoriteAgent, UserDefaultAgent, UserHomepageConfig, LoginAudit, WecomCallbackAudit, GeneralFeedback, ChatLog
from app.services.feedback_notify import send_feedback_group_notification
from app.services.agent_category import serialize_agent_list_item, sort_agent_rows
from app.services.agent_registry.serialization import serialize_registry_fields
from app.services.wecom_notify import mark_wecom_message_opened, send_wecom_event_message
from app.services.wecom_crypto import sha1_hex, decrypt_wecom_aes, extract_encrypt_field
from app.core.auth.jwt import get_current_user as _auth_current_user
@@ -1341,9 +1342,9 @@ def home():
def _load_home_payload():
if user.role == 'admin':
agent_rows = db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url, Agent.extra_config).filter(Agent.is_active.is_(True)).all()
agent_rows = Agent.query.filter(Agent.is_active.is_(True)).all()
else:
agent_rows = [{'id': agent.id, 'name': agent.name, 'description': agent.description, 'icon_url': agent.icon_url, 'extra_config': agent.extra_config} for agent in user.agents if agent.is_active]
agent_rows = [agent for agent in user.agents if agent.is_active]
agent_rows = sort_agent_rows(agent_rows)
favorites = db.session.query(UserFavoriteAgent).filter_by(user_id=user.id).all()
favorite_ids = [f.agent_id for f in favorites]
@@ -1360,7 +1361,14 @@ def home():
for rel in embedded_rel:
agent = db.session.get(Agent, rel.agent_id)
if agent:
embedded_agents.append({'id': agent.id, 'name': agent.name, 'iframe_url': agent.extra_config.get('iframe_url') if agent.extra_config else None})
registry = serialize_registry_fields(agent)
embedded_agents.append({
'id': agent.id,
'name': agent.name,
'iframe_url': registry.get('iframe_url'),
'runtime_provider': registry.get('runtime_provider'),
'conversation_mode': registry.get('conversation_mode'),
})
return jsonify({'user': {'id': user.id, 'username': user.username, 'role': user.role, 'default_agent_id': user.default_agent_id, 'feature_permissions': user.get_feature_permissions(), 'language': user.language, 'theme_preference': user.theme_preference or 'system'}, 'agents': [serialize_agent_list_item(a) for a in agent_rows], 'favorite_agent_ids': favorite_ids, 'quick_questions': [{'id': q.id, 'title': q.title, 'question': q.question, 'agent_id': q.agent_id} for q in qqs], 'embedded_agents': embedded_agents, 'layout': layout})
try:
return _run_db_with_retry(_load_home_payload, label='user.home')
@@ -1813,16 +1821,12 @@ def get_agent_details(id):
has_permission = agent in user.agents
if not has_permission:
raise ForbiddenError('Access denied')
extra_config = agent.extra_config or {}
if isinstance(extra_config, dict):
from app.services.file_check_tools.task_resolver import enrich_agent_extra_if_file_check
extra_config = enrich_agent_extra_if_file_check(agent)
dify_app_type = extra_config.get('dify_app_type') if isinstance(extra_config, dict) else None
from app.services.agent_registry.resolver import resolve_runtime_provider
from app.services.agent_registry.serialization import serialize_agent_for_user_detail
dify_parameters = None
agent_type = str(getattr(agent, 'type', '') or '').strip().lower()
if agent_type == 'api' and getattr(agent, 'dify_api_key', None):
if resolve_runtime_provider(agent) in {'dify', 'hybrid'} and getattr(agent, 'dify_api_key', None):
from app.services.dify import DifyService
try:
@@ -1835,18 +1839,10 @@ def get_agent_details(id):
except Exception as exc:
current_app.logger.warning('[user.agents] dify parameters fetch failed agent_id=%s err=%s', id, exc)
return jsonify({
'id': agent.id,
'name': agent.name,
'description': agent.description,
'type': agent.type,
'icon_url': agent.icon_url,
'extra_config': extra_config if isinstance(extra_config, dict) else {},
'dify_app_type': dify_app_type,
'welcome_message': extra_config.get('welcome_message') if isinstance(extra_config, dict) else None,
'suggested_questions': extra_config.get('suggested_questions', []) if isinstance(extra_config, dict) else [],
'dify_parameters': dify_parameters,
})
return jsonify(serialize_agent_for_user_detail(
agent,
dify_parameters=dify_parameters,
))
@user_bp.route('/db', methods=['GET'])
def get_db():