- Add hermes_executions, hermes_tasks, hermes_workflows, task_dependencies models - Add harnessed_agent_config model and view CRUD JSON - Add config_functions.py for agent configuration - Add agent_config.ui and ios_design.css frontend files
117 lines
4.5 KiB
Python
117 lines
4.5 KiB
Python
from typing import Dict, Any
|
|
from datetime import datetime
|
|
import uuid
|
|
|
|
|
|
async def harnessed_get_agent_config(context: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""
|
|
Get agent configuration for current user
|
|
|
|
Args:
|
|
context: Request context containing user information
|
|
|
|
Returns:
|
|
Configuration data for the current user
|
|
"""
|
|
from .core import HermesAgent
|
|
agent = HermesAgent()
|
|
user_id = agent._get_current_user_id(context)
|
|
|
|
# Query database for user configuration
|
|
sql = """
|
|
SELECT * FROM harnessed_agent_config
|
|
WHERE user_id = %(user_id)s
|
|
ORDER BY created_at DESC
|
|
LIMIT 1
|
|
"""
|
|
try:
|
|
rows = await agent.db.sql(sql, {"user_id": user_id})
|
|
if rows:
|
|
config = rows[0]
|
|
# Convert string booleans to actual booleans for UI
|
|
config["auto_cleanup_enabled"] = config["auto_cleanup_enabled"] == "1"
|
|
return {"success": True, "config": config}
|
|
else:
|
|
# Return default configuration
|
|
default_config = {
|
|
"id": f"default_{user_id}",
|
|
"user_id": user_id,
|
|
"work_dir": "./hermes_work",
|
|
"skills_path": "~/.hermes/skills",
|
|
"max_memory_tokens": 2000,
|
|
"default_priority": 50,
|
|
"high_priority_threshold": 70,
|
|
"low_priority_threshold": 30,
|
|
"auto_cleanup_enabled": True,
|
|
"min_retention_days": 30,
|
|
"created_at": datetime.now().isoformat(),
|
|
"updated_at": datetime.now().isoformat()
|
|
}
|
|
return {"success": True, "config": default_config}
|
|
except Exception as e:
|
|
return {"success": False, "error": str(e)}
|
|
|
|
|
|
async def harnessed_save_agent_config(context: Dict[str, Any], config_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""
|
|
Save agent configuration for current user
|
|
|
|
Args:
|
|
context: Request context containing user information
|
|
config_data: Configuration data to save
|
|
|
|
Returns:
|
|
Success status
|
|
"""
|
|
from .core import HermesAgent
|
|
agent = HermesAgent()
|
|
user_id = agent._get_current_user_id(context)
|
|
|
|
# Convert boolean to string for database storage
|
|
config_data["auto_cleanup_enabled"] = "1" if config_data.get("auto_cleanup_enabled") else "0"
|
|
config_data["user_id"] = user_id
|
|
config_data["updated_at"] = datetime.now().isoformat()
|
|
|
|
# Check if config already exists
|
|
sql_check = "SELECT id FROM harnessed_agent_config WHERE user_id = %(user_id)s"
|
|
try:
|
|
rows = await agent.db.sql(sql_check, {"user_id": user_id})
|
|
if rows:
|
|
# Update existing config
|
|
config_data["id"] = rows[0]["id"]
|
|
config_data["created_at"] = rows[0]["created_at"] # Keep original created_at
|
|
sql_update = """
|
|
UPDATE harnessed_agent_config SET
|
|
work_dir = %(work_dir)s,
|
|
skills_path = %(skills_path)s,
|
|
max_memory_tokens = %(max_memory_tokens)s,
|
|
default_priority = %(default_priority)s,
|
|
high_priority_threshold = %(high_priority_threshold)s,
|
|
low_priority_threshold = %(low_priority_threshold)s,
|
|
auto_cleanup_enabled = %(auto_cleanup_enabled)s,
|
|
min_retention_days = %(min_retention_days)s,
|
|
updated_at = %(updated_at)s
|
|
WHERE id = %(id)s
|
|
"""
|
|
await agent.db.sql(sql_update, config_data)
|
|
else:
|
|
# Create new config
|
|
config_data["id"] = str(uuid.uuid4()).replace("-", "")[:32]
|
|
config_data["created_at"] = config_data["updated_at"]
|
|
sql_insert = """
|
|
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)s, %(user_id)s, %(work_dir)s, %(skills_path)s, %(max_memory_tokens)s,
|
|
%(default_priority)s, %(high_priority_threshold)s, %(low_priority_threshold)s,
|
|
%(auto_cleanup_enabled)s, %(min_retention_days)s, %(created_at)s, %(updated_at)s
|
|
)
|
|
"""
|
|
await agent.db.sql(sql_insert, config_data)
|
|
|
|
return {"success": True}
|
|
except Exception as e:
|
|
return {"success": False, "error": str(e)}
|