#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Workflow create API""" import json, uuid, time result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid request', 'type': 'error'}} try: dbname = get_module_dbname('harnessed_agent') user_id = await get_user() now = time.strftime('%Y-%m-%d %H:%M:%S') new_id = str(uuid.uuid4()).replace('-', '') name = params_kw.get('name', '').strip() description = params_kw.get('description', '').strip() workflow_type = params_kw.get('workflow_type', '').strip() max_concurrent_tasks = params_kw.get('max_concurrent_tasks', '').strip() timeout_seconds = params_kw.get('timeout_seconds', '').strip() retry_count = params_kw.get('retry_count', '').strip() status = params_kw.get('status', '').strip() async with DBPools().sqlorContext(dbname) as sor: await sor.sqlExe("""INSERT INTO hermes_workflows (id, user_id, name, description, workflow_type, max_concurrent_tasks, timeout_seconds, retry_count, status, created_at, updated_at) VALUES (${id}$, ${user_id}$, ${name}$, ${description}$, ${workflow_type}$, ${max_concurrent_tasks}$, ${timeout_seconds}$, ${retry_count}$, ${status}$, ${created_at}$, ${updated_at}$)""", { 'id': new_id, 'user_id': user_id, 'name': name, 'description': description, 'workflow_type': workflow_type, 'max_concurrent_tasks': max_concurrent_tasks, 'timeout_seconds': timeout_seconds, 'retry_count': retry_count, 'status': status, 'created_at': now, 'updated_at': now }) result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': 'Workflow创建成功', 'type': 'success'}} except Exception as e: result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'} return json.dumps(result, ensure_ascii=False)