1.排程管理新增企业微信通知功能
2.可用应用以及智能体显示只显示Chatflow类型应用
This commit is contained in:
1 parent
dc8ad4de52
commit
05913f742f
8 files changed
+264
-15
No files matched your search
@@ -20,6 +20,7 @@ def _serialize_agent_row(row) -> dict:
|
||||
'name': row.name,
|
||||
'description': row.description,
|
||||
'icon_url': row.icon_url,
|
||||
'dify_app_type': (row.extra_config or {}).get('dify_app_type') if hasattr(row, 'extra_config') else None,
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +36,7 @@ def list_user_agents():
|
||||
# 管理员:返回所有激活的 Agent
|
||||
if user.role == 'admin':
|
||||
agent_rows = (
|
||||
db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url)
|
||||
db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url, Agent.extra_config)
|
||||
.filter(Agent.is_active.is_(True))
|
||||
.order_by(Agent.id.asc())
|
||||
.all()
|
||||
@@ -48,6 +49,7 @@ def list_user_agents():
|
||||
'name': a.name,
|
||||
'description': a.description,
|
||||
'icon_url': a.icon_url,
|
||||
'extra_config': a.extra_config,
|
||||
})()
|
||||
for a in user.agents
|
||||
if a.is_active
|
||||
@@ -64,7 +66,7 @@ def list_public_agents():
|
||||
"""
|
||||
# 返回所有激活的 Agent,包含基本信息
|
||||
agent_rows = (
|
||||
db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url)
|
||||
db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url, Agent.extra_config)
|
||||
.filter(Agent.is_active.is_(True))
|
||||
.order_by(Agent.id.asc())
|
||||
.all()
|
||||
|
||||
@@ -4,6 +4,9 @@ import threading
|
||||
from datetime import datetime
|
||||
|
||||
from flask import Blueprint, current_app, jsonify, request, send_file
|
||||
from flask import Response
|
||||
from io import BytesIO
|
||||
import json
|
||||
|
||||
from app.decorators import require_admin
|
||||
from app import db
|
||||
@@ -24,6 +27,12 @@ from app.services.schedule.srm_service import _fetch_records
|
||||
schedule_admin_bp = Blueprint('schedule_admin', __name__)
|
||||
|
||||
|
||||
def _serialize_task_for_export(task: ScheduleTask, cfg_model: ScheduleTaskConfig | None) -> dict:
|
||||
payload = serialize_task(task)
|
||||
payload['config'] = _serialize_task_config(cfg_model) if cfg_model else None
|
||||
return payload
|
||||
|
||||
|
||||
def _serialize_task_config(cfg_model: ScheduleTaskConfig) -> dict:
|
||||
return {
|
||||
"row_id_key": cfg_model.row_id_key or "id",
|
||||
@@ -372,6 +381,108 @@ def get_schedules():
|
||||
return jsonify(list_tasks())
|
||||
|
||||
|
||||
@schedule_admin_bp.route('/schedules/<int:task_id>/export', methods=['GET'])
|
||||
@require_admin
|
||||
def export_schedule(task_id: int):
|
||||
task = db.session.get(ScheduleTask, task_id)
|
||||
if not task:
|
||||
return jsonify({'error': 'Not found'}), 404
|
||||
cfg_model = ScheduleTaskConfig.query.filter_by(schedule_task_id=task_id).first()
|
||||
payload = {
|
||||
"schema_version": 1,
|
||||
"exported_at": datetime.utcnow().isoformat(),
|
||||
"schedules": [_serialize_task_for_export(task, cfg_model)],
|
||||
}
|
||||
body = json.dumps(payload, ensure_ascii=False, indent=2)
|
||||
filename = f"{(task.schedule_no or f'schedule_{task.id}')}_export_{datetime.utcnow().strftime('%Y%m%d_%H%M%S')}.json"
|
||||
return Response(
|
||||
body,
|
||||
mimetype='application/json; charset=utf-8',
|
||||
headers={'Content-Disposition': f'attachment; filename="{filename}"'},
|
||||
)
|
||||
|
||||
|
||||
@schedule_admin_bp.route('/schedules/import', methods=['POST'])
|
||||
@require_admin
|
||||
def import_schedules():
|
||||
data = request.get_json(silent=True) or {}
|
||||
schedules = data.get('schedules')
|
||||
if not isinstance(schedules, list):
|
||||
return jsonify({'error': 'Invalid import file: schedules missing'}), 400
|
||||
|
||||
user = get_current_user()
|
||||
imported = 0
|
||||
skipped = 0
|
||||
errors: list[str] = []
|
||||
|
||||
for item in schedules:
|
||||
if not isinstance(item, dict):
|
||||
skipped += 1
|
||||
continue
|
||||
try:
|
||||
name = str(item.get('name') or '').strip()
|
||||
cron_expr = str(item.get('cron_expr') or '').strip()
|
||||
owner_user_id = int(item.get('owner_user_id'))
|
||||
if not name or not cron_expr:
|
||||
raise ValueError('name or cron_expr missing')
|
||||
|
||||
existing = None
|
||||
schedule_no = str(item.get('schedule_no') or '').strip()
|
||||
if schedule_no:
|
||||
existing = db.session.query(ScheduleTask).filter_by(schedule_no=schedule_no).first()
|
||||
|
||||
task_payload = {
|
||||
'name': name,
|
||||
'schedule_type': str(item.get('schedule_type') or 'platform_app'),
|
||||
'owner_user_id': owner_user_id,
|
||||
'cron_expr': cron_expr,
|
||||
'wait_seconds': int(item.get('wait_seconds') or 0),
|
||||
'dify_agent_id': item.get('dify_agent_id'),
|
||||
'platform_api_path': item.get('platform_api_path'),
|
||||
'notify_user_ids_json': item.get('notify_user_ids_json') if isinstance(item.get('notify_user_ids_json'), list) else [],
|
||||
'notify_enabled': bool(item.get('notify_enabled', True)),
|
||||
'enabled': bool(item.get('enabled', True)),
|
||||
'data_source_type': str(item.get('data_source_type') or 'database'),
|
||||
}
|
||||
cfg = item.get('config') if isinstance(item.get('config'), dict) else None
|
||||
|
||||
if existing:
|
||||
update_task(existing, payload=task_payload, actor_id=getattr(user, 'id', None))
|
||||
existing.data_source_type = task_payload['data_source_type']
|
||||
if cfg:
|
||||
upsert_schedule_task_config(existing.id, cfg)
|
||||
else:
|
||||
task = create_task(
|
||||
name=name,
|
||||
schedule_type=task_payload['schedule_type'],
|
||||
owner_user_id=owner_user_id,
|
||||
cron_expr=cron_expr,
|
||||
wait_seconds=task_payload['wait_seconds'],
|
||||
dify_agent_id=task_payload['dify_agent_id'],
|
||||
platform_api_path=task_payload['platform_api_path'],
|
||||
notify_user_ids_json=task_payload['notify_user_ids_json'],
|
||||
notify_enabled=task_payload['notify_enabled'],
|
||||
enabled=task_payload['enabled'],
|
||||
actor_id=getattr(user, 'id', None),
|
||||
)
|
||||
task.data_source_type = task_payload['data_source_type']
|
||||
db.session.commit()
|
||||
if cfg:
|
||||
upsert_schedule_task_config(task.id, cfg)
|
||||
imported += 1
|
||||
except Exception as exc:
|
||||
errors.append(str(exc))
|
||||
skipped += 1
|
||||
|
||||
db.session.commit()
|
||||
return jsonify({
|
||||
'ok': True,
|
||||
'imported': imported,
|
||||
'skipped': skipped,
|
||||
'errors': errors[:20],
|
||||
})
|
||||
|
||||
|
||||
@schedule_admin_bp.route('/schedules', methods=['POST'])
|
||||
@require_admin
|
||||
def post_schedule():
|
||||
|
||||
@@ -1887,7 +1887,7 @@ def home():
|
||||
# Get all agents available to user (including public ones)
|
||||
if user.role == 'admin':
|
||||
agent_rows = (
|
||||
db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url)
|
||||
db.session.query(Agent.id, Agent.name, Agent.description, Agent.icon_url, Agent.extra_config)
|
||||
.filter(Agent.is_active.is_(True))
|
||||
.all()
|
||||
)
|
||||
@@ -1898,6 +1898,7 @@ def home():
|
||||
'name': agent.name,
|
||||
'description': agent.description,
|
||||
'icon_url': agent.icon_url,
|
||||
'extra_config': agent.extra_config,
|
||||
} for agent in user.agents]
|
||||
|
||||
favorites = db.session.query(UserFavoriteAgent).filter_by(user_id=user.id).all()
|
||||
@@ -1934,7 +1935,12 @@ def home():
|
||||
'id': a.id if hasattr(a, 'id') else a['id'],
|
||||
'name': a.name if hasattr(a, 'name') else a['name'],
|
||||
'description': a.description if hasattr(a, 'description') else a['description'],
|
||||
'icon_url': a.icon_url if hasattr(a, 'icon_url') else a['icon_url']
|
||||
'icon_url': a.icon_url if hasattr(a, 'icon_url') else a['icon_url'],
|
||||
'dify_app_type': (
|
||||
(a.extra_config or {}).get('dify_app_type')
|
||||
if hasattr(a, 'extra_config')
|
||||
else (a.get('extra_config') or {}).get('dify_app_type')
|
||||
) or 'chatflow'
|
||||
} for a in agent_rows],
|
||||
'favorite_agent_ids': favorite_ids,
|
||||
'quick_questions': [{
|
||||
|
||||
Reference in new issue
Block a user