Add "Start Workflow" button to trigger CEO agent from web UI
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 49s
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 49s
New endpoint POST /api/cases/{case_number}/start-workflow creates a
Paperclip issue, wakes the CEO agent via wakeup API, and transitions
case status to "processing". Button appears on case page only when
status is "new" or "documents_ready".
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
67
web/app.py
67
web/app.py
@@ -35,7 +35,12 @@ from legal_mcp.tools import cases as cases_tools, search as search_tools, workfl
|
||||
_web_dir = Path(__file__).resolve().parent
|
||||
sys.path.insert(0, str(_web_dir.parent))
|
||||
from web.gitea_client import create_repo, setup_remote_and_push
|
||||
from web.paperclip_client import create_project as pc_create_project, get_project_url
|
||||
from web.paperclip_client import (
|
||||
create_project as pc_create_project,
|
||||
create_workflow_issue as pc_create_workflow_issue,
|
||||
get_project_url,
|
||||
wake_ceo_agent as pc_wake_ceo,
|
||||
)
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -1129,7 +1134,16 @@ async def api_case_git_status(case_number: str):
|
||||
if not git_dir.exists():
|
||||
return {"synced": False, "error": "no_repo"}
|
||||
|
||||
env = {"PATH": os.environ.get("PATH", "/usr/bin:/bin"), "GIT_TERMINAL_PROMPT": "0"}
|
||||
env = {
|
||||
"PATH": os.environ.get("PATH", "/usr/bin:/bin"),
|
||||
"HOME": os.environ.get("HOME", "/root"),
|
||||
"GIT_TERMINAL_PROMPT": "0",
|
||||
"GIT_CONFIG_GLOBAL": "/dev/null",
|
||||
}
|
||||
# Ensure git trusts the case directory regardless of ownership
|
||||
env["GIT_CONFIG_COUNT"] = "1"
|
||||
env["GIT_CONFIG_KEY_0"] = "safe.directory"
|
||||
env["GIT_CONFIG_VALUE_0"] = str(case_dir)
|
||||
|
||||
# Last commit info
|
||||
log = subprocess.run(
|
||||
@@ -2160,6 +2174,55 @@ async def api_paperclip_create_project(req: PaperclipProjectRequest):
|
||||
return project
|
||||
|
||||
|
||||
@app.post("/api/cases/{case_number}/start-workflow")
|
||||
async def api_start_workflow(case_number: str):
|
||||
"""Start the CEO agent workflow for a case.
|
||||
|
||||
Creates a workflow issue in Paperclip and wakes the CEO agent.
|
||||
Only works when case status is 'new' or 'documents_ready'.
|
||||
"""
|
||||
# 1. Verify case exists and status is appropriate
|
||||
case_raw = await cases_tools.case_get(case_number)
|
||||
case_data = json.loads(case_raw)
|
||||
if "error" in case_data:
|
||||
raise HTTPException(404, f"תיק {case_number} לא נמצא")
|
||||
|
||||
status = case_data.get("status", "")
|
||||
allowed = {"new", "documents_ready"}
|
||||
if status not in allowed:
|
||||
raise HTTPException(
|
||||
409,
|
||||
f"לא ניתן להתחיל תהליך — סטטוס נוכחי: {status}. נדרש: {', '.join(allowed)}",
|
||||
)
|
||||
|
||||
# 2. Create workflow issue in Paperclip
|
||||
try:
|
||||
issue = await pc_create_workflow_issue(case_number, case_data.get("title", ""))
|
||||
except ValueError as e:
|
||||
raise HTTPException(404, str(e))
|
||||
except Exception as e:
|
||||
raise HTTPException(502, f"שגיאת Paperclip: {e}")
|
||||
|
||||
# 3. Wake the CEO agent
|
||||
try:
|
||||
wakeup = await pc_wake_ceo(issue["issue_id"], case_number)
|
||||
except Exception as e:
|
||||
logger.warning("CEO wakeup failed for case %s: %s", case_number, e)
|
||||
wakeup = {"error": str(e)}
|
||||
|
||||
# 4. Update case status to processing
|
||||
await cases_tools.case_update(case_number, status="processing")
|
||||
|
||||
return {
|
||||
"case_number": case_number,
|
||||
"status": "processing",
|
||||
"issue_id": issue["issue_id"],
|
||||
"issue_identifier": issue["identifier"],
|
||||
"project_url": issue["project_url"],
|
||||
"wakeup": wakeup,
|
||||
}
|
||||
|
||||
|
||||
# ── Settings: Tag → Company Mappings ──────────────────────────────
|
||||
|
||||
@app.get("/api/settings/paperclip-companies")
|
||||
|
||||
Reference in New Issue
Block a user