Add recipe download and copy yaml (#6201)
This commit is contained in:
@@ -392,6 +392,7 @@ derive_utoipa!(Icon as IconSchema);
|
||||
super::routes::recipe::set_recipe_slash_command,
|
||||
super::routes::recipe::save_recipe,
|
||||
super::routes::recipe::parse_recipe,
|
||||
super::routes::recipe::recipe_to_yaml,
|
||||
super::routes::setup::start_openrouter_setup,
|
||||
super::routes::setup::start_tetrate_setup,
|
||||
super::routes::tunnel::start_tunnel,
|
||||
@@ -508,6 +509,8 @@ derive_utoipa!(Icon as IconSchema);
|
||||
super::routes::errors::ErrorResponse,
|
||||
super::routes::recipe::ParseRecipeRequest,
|
||||
super::routes::recipe::ParseRecipeResponse,
|
||||
super::routes::recipe::RecipeToYamlRequest,
|
||||
super::routes::recipe::RecipeToYamlResponse,
|
||||
goose::recipe::Recipe,
|
||||
goose::recipe::Author,
|
||||
goose::recipe::Settings,
|
||||
|
||||
@@ -137,6 +137,16 @@ pub struct SetSlashCommandRequest {
|
||||
slash_command: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct RecipeToYamlRequest {
|
||||
recipe: Recipe,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, ToSchema)]
|
||||
pub struct RecipeToYamlResponse {
|
||||
yaml: String,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/recipes/create",
|
||||
@@ -520,6 +530,27 @@ async fn parse_recipe(
|
||||
Ok(Json(ParseRecipeResponse { recipe }))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/recipes/to-yaml",
|
||||
request_body = RecipeToYamlRequest,
|
||||
responses(
|
||||
(status = 200, description = "Recipe converted to YAML successfully", body = RecipeToYamlResponse),
|
||||
(status = 400, description = "Bad request - Failed to convert recipe to YAML", body = ErrorResponse),
|
||||
),
|
||||
tag = "Recipe Management"
|
||||
)]
|
||||
async fn recipe_to_yaml(
|
||||
Json(request): Json<RecipeToYamlRequest>,
|
||||
) -> Result<Json<RecipeToYamlResponse>, ErrorResponse> {
|
||||
let yaml = request.recipe.to_yaml().map_err(|e| ErrorResponse {
|
||||
message: format!("Failed to convert recipe to YAML: {}", e),
|
||||
status: StatusCode::BAD_REQUEST,
|
||||
})?;
|
||||
|
||||
Ok(Json(RecipeToYamlResponse { yaml }))
|
||||
}
|
||||
|
||||
pub fn routes(state: Arc<AppState>) -> Router {
|
||||
Router::new()
|
||||
.route("/recipes/create", post(create_recipe))
|
||||
@@ -532,6 +563,7 @@ pub fn routes(state: Arc<AppState>) -> Router {
|
||||
.route("/recipes/slash-command", post(set_recipe_slash_command))
|
||||
.route("/recipes/save", post(save_recipe))
|
||||
.route("/recipes/parse", post(parse_recipe))
|
||||
.route("/recipes/to-yaml", post(recipe_to_yaml))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user