use axum::{ extract::{Path, State}, http::StatusCode, Json, }; use serde::Deserialize; use crate::{ model::{ModelConfig, ModelConfigInput}, Result, }; use super::{ ControlService, DiscoveredModels, LegacyModelImportPreview, LegacyModelImportResult, ModelConnectivityResult, ModelDiscoveryInput, }; #[derive(Deserialize)] pub struct SaveModels { pub models: Vec, } #[derive(Deserialize)] pub struct ModelOrder { pub model_hashes: Vec, } pub async fn list(State(service): State) -> Result>> { Ok(Json(service.models().await?)) } pub async fn create( State(service): State, Json(input): Json, ) -> Result<(StatusCode, Json>)> { Ok(( StatusCode::CREATED, Json(service.create_models(&input.models).await?), )) } pub async fn reorder( State(service): State, Json(input): Json, ) -> Result>> { Ok(Json(service.reorder_models(&input.model_hashes).await?)) } pub async fn remove( State(service): State, Path(model_hash): Path, ) -> Result { service.delete_model(&model_hash).await?; Ok(StatusCode::NO_CONTENT) } pub async fn update( State(service): State, Path(model_hash): Path, Json(input): Json, ) -> Result> { Ok(Json(service.update_model(&model_hash, &input).await?)) } pub async fn test( State(service): State, Path((model_hash, test_id)): Path<(String, String)>, ) -> Result> { Ok(Json(service.test_model(&model_hash, &test_id).await?)) } pub async fn cancel( State(service): State, Path((_model_hash, test_id)): Path<(String, String)>, ) -> Result { service.cancel_model_test(&test_id); Ok(StatusCode::NO_CONTENT) } pub async fn discover( State(service): State, Json(input): Json, ) -> Result> { Ok(Json(service.discover_models(&input).await?)) } pub async fn import_v0049( State(service): State, ) -> Result> { Ok(Json(service.import_v0049_models().await?)) } pub async fn preview_v0049( State(service): State, ) -> Result> { Ok(Json(service.preview_v0049_models().await?)) }