diff --git a/app/models.py b/app/models.py index b574f71..2924c39 100644 --- a/app/models.py +++ b/app/models.py @@ -41,6 +41,15 @@ async def init_db(): description TEXT ) """) + await db.execute(""" + CREATE TABLE IF NOT EXISTS agents ( + agent_name TEXT PRIMARY KEY, + agent_type TEXT, + scopes TEXT NOT NULL, + repo_url TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + """) await db.execute(""" CREATE TABLE IF NOT EXISTS memory_entries ( id TEXT PRIMARY KEY, @@ -271,3 +280,30 @@ async def archive_memory_entry(entry_id: str): (entry_id,) ) await db.commit() + + +async def add_agent(agent_name: str, scopes: List[str], agent_type: Optional[str] = None, + repo_url: Optional[str] = None) -> Dict[str, Any]: + agent_name = agent_name.upper() + scopes_json = json.dumps(scopes) + async with aiosqlite.connect(DB_PATH) as db: + await db.execute( + """INSERT INTO agents (agent_name, agent_type, scopes, repo_url) VALUES (?, ?, ?, ?) + ON CONFLICT(agent_name) DO UPDATE SET agent_type=excluded.agent_type, + scopes=excluded.scopes, repo_url=excluded.repo_url""", + (agent_name, agent_type, scopes_json, repo_url) + ) + await db.commit() + return {"agent_name": agent_name, "agent_type": agent_type, "scopes": scopes, "repo_url": repo_url} + +async def list_agents() -> List[Dict[str, Any]]: + async with aiosqlite.connect(DB_PATH) as db: + db.row_factory = aiosqlite.Row + async with db.execute("SELECT agent_name, agent_type, scopes, repo_url, created_at FROM agents ORDER BY agent_name") as cursor: + rows = await cursor.fetchall() + result = [] + for row in rows: + d = dict(row) + d["scopes"] = json.loads(d["scopes"]) + result.append(d) + return result