#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Config 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('-', '') work_dir = params_kw.get('work_dir', '').strip() skills_path = params_kw.get('skills_path', '').strip() max_memory_tokens = params_kw.get('max_memory_tokens', '').strip() default_priority = params_kw.get('default_priority', '').strip() high_priority_threshold = params_kw.get('high_priority_threshold', '').strip() low_priority_threshold = params_kw.get('low_priority_threshold', '').strip() auto_cleanup_enabled = params_kw.get('auto_cleanup_enabled', '').strip() min_retention_days = params_kw.get('min_retention_days', '').strip() async with DBPools().sqlorContext(dbname) as sor: await sor.sqlExe("""INSERT INTO harnessed_agent_config (id, user_id, work_dir, skills_path, max_memory_tokens, default_priority, high_priority_threshold, low_priority_threshold, auto_cleanup_enabled, min_retention_days, created_at, updated_at) VALUES (${id}$, ${user_id}$, ${work_dir}$, ${skills_path}$, ${max_memory_tokens}$, ${default_priority}$, ${high_priority_threshold}$, ${low_priority_threshold}$, ${auto_cleanup_enabled}$, ${min_retention_days}$, ${created_at}$, ${updated_at}$)""", { 'id': new_id, 'user_id': user_id, 'work_dir': work_dir, 'skills_path': skills_path, 'max_memory_tokens': max_memory_tokens, 'default_priority': default_priority, 'high_priority_threshold': high_priority_threshold, 'low_priority_threshold': low_priority_threshold, 'auto_cleanup_enabled': auto_cleanup_enabled, 'min_retention_days': min_retention_days, 'created_at': now, 'updated_at': now }) result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': 'Config创建成功', 'type': 'success'}} except Exception as e: result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'} return json.dumps(result, ensure_ascii=False)