feagi-api 0.0.8

FEAGI REST API layer with HTTP and ZMQ transport adapters
Documentation
// Copyright 2025 Neuraville Inc.
// SPDX-License-Identifier: Apache-2.0

/*!
 * FEAGI v1 Evolution API
 *
 * Endpoints for evolutionary algorithms and genetic operations
 * Maps to Python: feagi/api/v1/evolution.py
 */

use crate::common::ApiState;
use crate::common::{ApiError, ApiResult, Json, State};
// Removed - using crate::common::State instead
use serde_json::{json, Value};
use std::collections::HashMap;

// ============================================================================
// EVOLUTIONARY ALGORITHMS
// ============================================================================

/// Get evolution system status including generation, population size, and activity state.
#[utoipa::path(
    get,
    path = "/v1/evolution/status",
    tag = "evolution",
    responses(
        (status = 200, description = "Evolution status", body = HashMap<String, serde_json::Value>),
        (status = 500, description = "Internal server error")
    )
)]
pub async fn get_status(State(_state): State<ApiState>) -> ApiResult<Json<HashMap<String, Value>>> {
    // TODO: Retrieve evolution status
    let mut response = HashMap::new();
    response.insert("active".to_string(), json!(false));
    response.insert("generation".to_string(), json!(0));
    response.insert("population_size".to_string(), json!(0));

    Ok(Json(response))
}

/// Configure evolution parameters including mutation rates and selection criteria.
#[utoipa::path(
    post,
    path = "/v1/evolution/config",
    tag = "evolution",
    responses(
        (status = 200, description = "Evolution configured", body = HashMap<String, String>),
        (status = 500, description = "Internal server error")
    )
)]
pub async fn post_config(
    State(_state): State<ApiState>,
    Json(request): Json<HashMap<String, Value>>,
) -> ApiResult<Json<HashMap<String, String>>> {
    // Validate config is provided
    let _config = request
        .get("config")
        .ok_or_else(|| ApiError::invalid_input("Missing 'config' field"))?;

    // TODO: Apply evolution configuration
    tracing::info!(target: "feagi-api", "Evolution configuration updated");

    Ok(Json(HashMap::from([(
        "message".to_string(),
        "Evolution configured successfully".to_string(),
    )])))
}