1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
//! Templates API handler.
use axum::{extract::Query, http::StatusCode, response::IntoResponse, Json};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::llm::templates;
// =============================================================================
// Contract Type Templates
// =============================================================================
/// Contract type template for API response
#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct ContractTypeTemplate {
/// Template identifier (e.g., "simple", "specification")
pub id: String,
/// Display name
pub name: String,
/// Description of the contract type workflow
pub description: String,
/// Ordered list of phases for this contract type
pub phases: Vec<String>,
/// Default starting phase
pub default_phase: String,
/// Whether this is a built-in type (always available)
pub is_builtin: bool,
}
/// Response for listing contract types
#[derive(Debug, Serialize, ToSchema)]
pub struct ListContractTypesResponse {
pub types: Vec<ContractTypeTemplate>,
}
/// List available contract type templates
#[utoipa::path(
get,
path = "/api/v1/contract-types",
responses(
(status = 200, description = "Contract types retrieved successfully", body = ListContractTypesResponse)
),
tag = "contract-types"
)]
pub async fn list_contract_types() -> impl IntoResponse {
let types = vec![
ContractTypeTemplate {
id: "simple".to_string(),
name: "Simple".to_string(),
description: "Plan \u{2192} Execute: Simple workflow with a plan document".to_string(),
phases: vec!["plan".to_string(), "execute".to_string()],
default_phase: "plan".to_string(),
is_builtin: true,
},
ContractTypeTemplate {
id: "specification".to_string(),
name: "Specification".to_string(),
description: "Research \u{2192} Specify \u{2192} Plan \u{2192} Execute \u{2192} Review: Full specification-driven development with TDD".to_string(),
phases: vec![
"research".to_string(),
"specify".to_string(),
"plan".to_string(),
"execute".to_string(),
"review".to_string(),
],
default_phase: "research".to_string(),
is_builtin: true,
},
];
(
StatusCode::OK,
Json(ListContractTypesResponse { types }),
)
.into_response()
}
/// Query parameters for listing templates
#[derive(Debug, Deserialize, ToSchema)]
pub struct ListTemplatesQuery {
/// Filter by contract phase (research, specify, plan, execute, review)
pub phase: Option<String>,
}
/// Template summary for API response
#[derive(Debug, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct TemplateSummary {
/// Template identifier
pub id: String,
/// Display name
pub name: String,
/// Contract phase this template is designed for
pub phase: String,
/// Brief description
pub description: String,
/// Number of body elements in the template
pub element_count: usize,
}
/// Response for listing templates
#[derive(Debug, Serialize, ToSchema)]
pub struct ListTemplatesResponse {
pub templates: Vec<TemplateSummary>,
}
/// List available file templates
#[utoipa::path(
get,
path = "/api/v1/templates",
params(
("phase" = Option<String>, Query, description = "Filter by contract phase")
),
responses(
(status = 200, description = "Templates retrieved successfully", body = ListTemplatesResponse)
),
tag = "templates"
)]
pub async fn list_templates(
Query(query): Query<ListTemplatesQuery>,
) -> impl IntoResponse {
let template_list = match query.phase.as_deref() {
Some(phase) => templates::templates_for_phase(phase),
None => templates::all_templates(),
};
let summaries: Vec<TemplateSummary> = template_list
.iter()
.map(|t| TemplateSummary {
id: t.id.clone(),
name: t.name.clone(),
phase: t.phase.clone(),
description: t.description.clone(),
element_count: t.suggested_body.len(),
})
.collect();
(
StatusCode::OK,
Json(ListTemplatesResponse {
templates: summaries,
}),
)
.into_response()
}
/// Get a specific template by ID
#[utoipa::path(
get,
path = "/api/v1/templates/{id}",
params(
("id" = String, Path, description = "Template ID")
),
responses(
(status = 200, description = "Template retrieved successfully", body = templates::FileTemplate),
(status = 404, description = "Template not found")
),
tag = "templates"
)]
pub async fn get_template(
axum::extract::Path(id): axum::extract::Path<String>,
) -> impl IntoResponse {
let all = templates::all_templates();
let template = all.into_iter().find(|t| t.id == id);
match template {
Some(t) => (StatusCode::OK, Json(serde_json::json!(t))).into_response(),
None => (
StatusCode::NOT_FOUND,
Json(serde_json::json!({
"error": format!("Template '{}' not found", id)
})),
)
.into_response(),
}
}
|