harnessed_agent/wwwroot/api/harnessed_agent_config_update.dspy

34 lines
1.8 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Config update API"""
import json, 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')
record_id = params_kw.get('id', '').strip()
if not record_id:
result['options'] = {'title': 'Error', 'message': '记录ID不能为空', 'type': 'error'}
else:
async with DBPools().sqlorContext(dbname) as sor:
await sor.sqlExe("""UPDATE harnessed_agent_config SET 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}$, updated_at = ${updated_at}$ WHERE id = ${id}$ AND user_id = ${user_id}$""", {
'id': record_id, 'user_id': user_id, 'updated_at': now,
'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,
})
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '更新成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': '更新失败: ' + str(e), 'type': 'error'}
return json.dumps(result, ensure_ascii=False)