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