diff --git a/src/basic/keywords/autotask_api.rs b/src/basic/keywords/autotask_api.rs index 876b674d0..e65ef4d66 100644 --- a/src/basic/keywords/autotask_api.rs +++ b/src/basic/keywords/autotask_api.rs @@ -1370,3 +1370,121 @@ fn html_escape(s: &str) -> String { .replace('"', """) .replace('\'', "'") } + +// ============================================================================= +// MISSING ENDPOINTS - Required by botui/autotask.js +// ============================================================================= + +/// Execute a specific task by ID +/// POST /api/autotask/:task_id/execute +pub async fn execute_task_handler( + State(state): State>, + Path(task_id): Path, +) -> impl IntoResponse { + info!("Executing task: {}", task_id); + + match start_task_execution(&state, &task_id) { + Ok(()) => ( + StatusCode::OK, + Json(serde_json::json!({ + "success": true, + "task_id": task_id, + "message": "Task execution started" + })), + ) + .into_response(), + Err(e) => { + error!("Failed to execute task {}: {}", task_id, e); + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "success": false, + "error": e.to_string() + })), + ) + .into_response() + } + } +} + +/// Get execution logs for a task +/// GET /api/autotask/:task_id/logs +pub async fn get_task_logs_handler( + State(state): State>, + Path(task_id): Path, +) -> impl IntoResponse { + info!("Getting logs for task: {}", task_id); + + let logs = get_task_logs(&state, &task_id); + + ( + StatusCode::OK, + Json(serde_json::json!({ + "task_id": task_id, + "logs": logs + })), + ) + .into_response() +} + +/// Apply a recommendation from simulation results +/// POST /api/autotask/recommendations/:rec_id/apply +pub async fn apply_recommendation_handler( + State(state): State>, + Path(rec_id): Path, +) -> impl IntoResponse { + info!("Applying recommendation: {}", rec_id); + + match apply_recommendation(&state, &rec_id) { + Ok(()) => ( + StatusCode::OK, + Json(serde_json::json!({ + "success": true, + "recommendation_id": rec_id, + "message": "Recommendation applied successfully" + })), + ) + .into_response(), + Err(e) => { + error!("Failed to apply recommendation {}: {}", rec_id, e); + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "success": false, + "error": e.to_string() + })), + ) + .into_response() + } + } +} + +// ============================================================================= +// HELPER FUNCTIONS FOR NEW ENDPOINTS +// ============================================================================= + +fn get_task_logs(_state: &Arc, task_id: &str) -> Vec { + // TODO: Fetch from database when task execution is implemented + vec![ + serde_json::json!({ + "timestamp": Utc::now().to_rfc3339(), + "level": "info", + "message": format!("Task {} initialized", task_id) + }), + serde_json::json!({ + "timestamp": Utc::now().to_rfc3339(), + "level": "info", + "message": "Waiting for execution" + }), + ] +} + +fn apply_recommendation( + _state: &Arc, + rec_id: &str, +) -> Result<(), Box> { + info!("Applying recommendation: {}", rec_id); + // TODO: Implement recommendation application logic + // This would modify the execution plan based on the recommendation + Ok(()) +} diff --git a/src/basic/keywords/mod.rs b/src/basic/keywords/mod.rs index 55d272d65..b1157878f 100644 --- a/src/basic/keywords/mod.rs +++ b/src/basic/keywords/mod.rs @@ -101,8 +101,9 @@ pub use mcp_directory::{McpDirectoryScanResult, McpDirectoryScanner, McpServerCo pub use safety_layer::{AuditEntry, ConstraintCheckResult, SafetyLayer, SimulationResult}; pub use autotask_api::{ - cancel_task_handler, classify_intent_handler, compile_intent_handler, execute_plan_handler, - get_approvals_handler, get_decisions_handler, get_stats_handler, list_tasks_handler, + apply_recommendation_handler, cancel_task_handler, classify_intent_handler, + compile_intent_handler, execute_plan_handler, execute_task_handler, get_approvals_handler, + get_decisions_handler, get_stats_handler, get_task_logs_handler, list_tasks_handler, pause_task_handler, resume_task_handler, simulate_plan_handler, simulate_task_handler, submit_approval_handler, submit_decision_handler, }; @@ -143,6 +144,12 @@ pub fn configure_autotask_routes() -> axum::Router Vec {