diff options
| author | soryu <soryu@soryu.co> | 2026-01-25 02:49:47 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-25 03:52:56 +0000 |
| commit | 34bc1296a53d264216c12cbaa74ca9d68dfe8f22 (patch) | |
| tree | ef7cee659e2dbe76a491376a8694409c96bb8697 | |
| parent | 579c983d3efb8f1414ffb45b9e031f741cce5f76 (diff) | |
| download | soryu-34bc1296a53d264216c12cbaa74ca9d68dfe8f22.tar.gz soryu-34bc1296a53d264216c12cbaa74ca9d68dfe8f22.zip | |
feat: Add contract type templates API endpoint
Add a new API endpoint to provide contract type templates (workflow
definitions) separate from file templates. This enables the create
contract page to dynamically show available contract types.
Changes:
- Add ContractTypeTemplate struct in templates.rs with id, name,
description, phases, default_phase, and is_builtin fields
- Add built-in contract types: 'simple' (plan/execute) and
'specification' (research/specify/plan/execute/review)
- Add GET /api/v1/contract-types endpoint returning all contract types
- Add frontend ContractTypeTemplate interface and listContractTypes()
API function
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
| -rw-r--r-- | makima/frontend/src/lib/api.ts | 36 | ||||
| -rw-r--r-- | makima/src/llm/templates.rs | 65 | ||||
| -rw-r--r-- | makima/src/server/handlers/templates.rs | 31 | ||||
| -rw-r--r-- | makima/src/server/mod.rs | 2 |
4 files changed, 134 insertions, 0 deletions
diff --git a/makima/frontend/src/lib/api.ts b/makima/frontend/src/lib/api.ts index 76ee4d4..1ae4103 100644 --- a/makima/frontend/src/lib/api.ts +++ b/makima/frontend/src/lib/api.ts @@ -2008,6 +2008,42 @@ export async function getTemplate(id: string): Promise<FileTemplate> { } // ============================================================================= +// Contract Type Templates (Workflow Definitions) +// ============================================================================= + +/** A contract type template defining a workflow */ +export interface ContractTypeTemplate { + /** Unique identifier (e.g., 'simple', 'specification', 'feature-development') */ + id: string; + /** Display name */ + name: string; + /** What this contract type is for */ + description: string; + /** Ordered list of phases in the workflow */ + phases: string[]; + /** Starting phase */ + defaultPhase: string; + /** True for built-in types ('simple', 'specification') */ + isBuiltin: boolean; +} + +export interface ListContractTypesResponse { + contractTypes: ContractTypeTemplate[]; +} + +/** + * List all available contract type templates. + * Returns built-in types (simple, specification) and any custom types. + */ +export async function listContractTypes(): Promise<ListContractTypesResponse> { + const res = await authFetch(`${API_BASE}/api/v1/contract-types`); + if (!res.ok) { + throw new Error(`Failed to list contract types: ${res.statusText}`); + } + return res.json(); +} + +// ============================================================================= // Supervisor Question Types and Functions // ============================================================================= diff --git a/makima/src/llm/templates.rs b/makima/src/llm/templates.rs index 18ef46d..7a5bd38 100644 --- a/makima/src/llm/templates.rs +++ b/makima/src/llm/templates.rs @@ -8,6 +8,71 @@ use utoipa::ToSchema; use crate::db::models::BodyElement; +// ============================================================================= +// Contract Type Templates (Workflow Definitions) +// ============================================================================= + +/// A contract type template defining a workflow +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct ContractTypeTemplate { + /// Unique identifier (e.g., 'simple', 'specification', 'feature-development') + pub id: String, + /// Display name + pub name: String, + /// What this contract type is for + pub description: String, + /// Ordered list of phases in the workflow + pub phases: Vec<String>, + /// Starting phase + pub default_phase: String, + /// True for built-in types ('simple', 'specification') + pub is_builtin: bool, +} + +/// Get all available contract type templates +pub fn all_contract_types() -> Vec<ContractTypeTemplate> { + vec![ + simple_contract_type(), + specification_contract_type(), + ] +} + +/// Simple contract type with basic plan/execute workflow +fn simple_contract_type() -> ContractTypeTemplate { + ContractTypeTemplate { + id: "simple".to_string(), + name: "Simple".to_string(), + description: "A basic workflow for straightforward tasks with planning and execution phases." + .to_string(), + phases: vec!["plan".to_string(), "execute".to_string()], + default_phase: "plan".to_string(), + is_builtin: true, + } +} + +/// Specification contract type with full research-to-review workflow +fn specification_contract_type() -> ContractTypeTemplate { + ContractTypeTemplate { + id: "specification".to_string(), + name: "Specification".to_string(), + description: "A comprehensive workflow for complex projects requiring research, specification, planning, execution, and review.".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, + } +} + +// ============================================================================= +// File Templates +// ============================================================================= + /// A file template with suggested structure #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct FileTemplate { diff --git a/makima/src/server/handlers/templates.rs b/makima/src/server/handlers/templates.rs index 868d5b4..6d95e86 100644 --- a/makima/src/server/handlers/templates.rs +++ b/makima/src/server/handlers/templates.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::llm::templates; +use crate::llm::templates::ContractTypeTemplate; /// Query parameters for listing templates #[derive(Debug, Deserialize, ToSchema)] @@ -105,3 +106,33 @@ pub async fn get_template( .into_response(), } } + +// ============================================================================= +// Contract Type Templates (Workflow Definitions) +// ============================================================================= + +/// Response for listing contract types +#[derive(Debug, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct ListContractTypesResponse { + pub contract_types: Vec<ContractTypeTemplate>, +} + +/// List all available contract type templates +#[utoipa::path( + get, + path = "/api/v1/contract-types", + responses( + (status = 200, description = "Contract types retrieved successfully", body = ListContractTypesResponse) + ), + tag = "templates" +)] +pub async fn list_contract_types() -> impl IntoResponse { + let contract_types = templates::all_contract_types(); + + ( + StatusCode::OK, + Json(ListContractTypesResponse { contract_types }), + ) + .into_response() +} diff --git a/makima/src/server/mod.rs b/makima/src/server/mod.rs index de20569..75f64c6 100644 --- a/makima/src/server/mod.rs +++ b/makima/src/server/mod.rs @@ -208,6 +208,8 @@ pub fn make_router(state: SharedState) -> Router { // Template endpoints .route("/templates", get(templates::list_templates)) .route("/templates/{id}", get(templates::get_template)) + // Contract type templates (workflow definitions) + .route("/contract-types", get(templates::list_contract_types)) // Settings endpoints .route( "/settings/repository-history", |
