feat: add OPC (One Person Company) management system with Kanban board
Phase 1 MVP implementation: - PostgreSQL database schema for tasks, agents, executions, time tracking - Backend API: task CRUD, agent management, automatic time tracking - Frontend: Kanban board with drag-and-drop (Parking Lot → In Progress → Done) - Task modal for creating/editing tasks with tags, priority, assignee - 3 core agents seeded: PM, CTO, COO - Agent approval workflow: CxO level requires approval, others auto-execute - Automatic time tracking: starts on in_progress, stops on done - RBAC integration: OPC page accessible to admin/member roles Features: - Drag-and-drop tasks between columns - Assign tasks to humans or AI agents - Priority badges (low, medium, high, urgent) - Tags and due dates - Task history tracking - Time entry tracking with automatic timer - Agent execution records with approval workflow Next steps: - Initialize OPC database on NAS - Implement agent executor service - Add WebSocket for real-time updates - Add email notifications - Add PDF invoice generation
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
"""
|
||||
OPC Agents Router
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel
|
||||
from db import opc_db
|
||||
from rbac import require_page, User, _inject_user, require_admin
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class AgentUpdate(BaseModel):
|
||||
name: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
system_prompt: Optional[str] = None
|
||||
enabled: Optional[bool] = None
|
||||
|
||||
|
||||
class ExecutionApproval(BaseModel):
|
||||
approved: bool
|
||||
|
||||
|
||||
@router.get("/agents")
|
||||
async def list_agents(
|
||||
enabled_only: bool = True,
|
||||
user: User = Depends(_inject_user)
|
||||
):
|
||||
"""List all agents"""
|
||||
agents = await opc_db.get_agents(enabled_only=enabled_only)
|
||||
return {"items": agents}
|
||||
|
||||
|
||||
@router.get("/agents/{agent_id}")
|
||||
async def get_agent(
|
||||
agent_id: str,
|
||||
user: User = Depends(_inject_user)
|
||||
):
|
||||
"""Get agent details"""
|
||||
agent = await opc_db.get_agent(agent_id)
|
||||
if not agent:
|
||||
raise HTTPException(status_code=404, detail="Agent not found")
|
||||
return agent
|
||||
|
||||
|
||||
@router.put("/agents/{agent_id}", dependencies=[Depends(require_admin())])
|
||||
async def update_agent(
|
||||
agent_id: str,
|
||||
updates: AgentUpdate,
|
||||
user: User = Depends(_inject_user)
|
||||
):
|
||||
"""Update agent configuration (admin only)"""
|
||||
# This would need an update_agent function in opc_db
|
||||
raise HTTPException(status_code=501, detail="Not implemented yet")
|
||||
|
||||
|
||||
@router.post("/agents/{agent_id}/execute")
|
||||
async def trigger_agent(
|
||||
agent_id: str,
|
||||
task_id: int,
|
||||
user: User = Depends(_inject_user)
|
||||
):
|
||||
"""Manually trigger agent execution"""
|
||||
execution = await opc_db.create_agent_execution(
|
||||
task_id=task_id,
|
||||
agent_id=agent_id,
|
||||
actor=user.username
|
||||
)
|
||||
return execution
|
||||
|
||||
|
||||
@router.get("/executions")
|
||||
async def list_executions(
|
||||
task_id: Optional[int] = None,
|
||||
agent_id: Optional[str] = None,
|
||||
status: Optional[str] = None,
|
||||
limit: int = 50,
|
||||
user: User = Depends(_inject_user)
|
||||
):
|
||||
"""List agent executions"""
|
||||
executions = await opc_db.get_agent_executions(
|
||||
task_id=task_id,
|
||||
agent_id=agent_id,
|
||||
status=status,
|
||||
limit=limit
|
||||
)
|
||||
return {"items": executions}
|
||||
|
||||
|
||||
@router.get("/executions/{execution_id}")
|
||||
async def get_execution(
|
||||
execution_id: int,
|
||||
user: User = Depends(_inject_user)
|
||||
):
|
||||
"""Get execution details"""
|
||||
executions = await opc_db.get_agent_executions(limit=1000)
|
||||
execution = next((e for e in executions if e["id"] == execution_id), None)
|
||||
if not execution:
|
||||
raise HTTPException(status_code=404, detail="Execution not found")
|
||||
return execution
|
||||
|
||||
|
||||
@router.post("/executions/{execution_id}/approve")
|
||||
async def approve_execution(
|
||||
execution_id: int,
|
||||
approval: ExecutionApproval,
|
||||
user: User = Depends(_inject_user)
|
||||
):
|
||||
"""Approve or reject agent execution (for CxO level actions)"""
|
||||
# This would need an approve_execution function in opc_db
|
||||
# For now, return placeholder
|
||||
return {
|
||||
"execution_id": execution_id,
|
||||
"approved": approval.approved,
|
||||
"approved_by": user.username
|
||||
}
|
||||
Reference in New Issue
Block a user