feat: add procedural flows with intake forms, navigation, and seed templates
Adds a new "procedural" tree type for linear step-by-step project workflows (domain controller setup, M365 onboarding, VPN config, etc). Includes intake form builder, two-panel step navigation, variable resolution, procedural exports, 3 seed templates, and UI rename from "Trees" to "Flows". Also archives 19 implemented plan docs and creates deferred features backlog. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,69 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional, Any, Literal
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, field_validator, model_validator
|
||||
import re
|
||||
|
||||
|
||||
# --- Tree Type ---
|
||||
|
||||
TreeType = Literal['troubleshooting', 'procedural']
|
||||
|
||||
# --- Intake Form Schemas ---
|
||||
|
||||
FIELD_TYPES = Literal[
|
||||
'text', 'textarea', 'number', 'ip_address', 'email',
|
||||
'select', 'multi_select', 'checkbox', 'password'
|
||||
]
|
||||
|
||||
VARIABLE_NAME_PATTERN = re.compile(r'^[a-z][a-z0-9_]*$')
|
||||
|
||||
|
||||
class IntakeFieldValidation(BaseModel):
|
||||
"""Validation config for an intake form field."""
|
||||
min_length: Optional[int] = None
|
||||
max_length: Optional[int] = None
|
||||
pattern: Optional[str] = None
|
||||
pattern_message: Optional[str] = None
|
||||
format: Optional[Literal['ipv4', 'email']] = None
|
||||
min_value: Optional[float] = None
|
||||
max_value: Optional[float] = None
|
||||
min_selections: Optional[int] = None
|
||||
max_selections: Optional[int] = None
|
||||
|
||||
|
||||
class IntakeFormField(BaseModel):
|
||||
"""Schema for a single intake form field definition."""
|
||||
variable_name: str = Field(..., min_length=1, max_length=50)
|
||||
label: str = Field(..., min_length=1, max_length=100)
|
||||
field_type: FIELD_TYPES
|
||||
required: bool = True
|
||||
options: Optional[list[str]] = None
|
||||
placeholder: Optional[str] = Field(None, max_length=200)
|
||||
help_text: Optional[str] = Field(None, max_length=500)
|
||||
default_value: Optional[str] = None
|
||||
group_name: Optional[str] = Field(None, max_length=100)
|
||||
display_order: int = Field(..., ge=1)
|
||||
validation: Optional[IntakeFieldValidation] = None
|
||||
|
||||
@field_validator('variable_name')
|
||||
@classmethod
|
||||
def validate_variable_name(cls, v: str) -> str:
|
||||
if not VARIABLE_NAME_PATTERN.match(v):
|
||||
raise ValueError(
|
||||
'Variable name must start with a lowercase letter and contain only '
|
||||
'lowercase letters, numbers, and underscores'
|
||||
)
|
||||
return v
|
||||
|
||||
@model_validator(mode='after')
|
||||
def validate_options_for_select(self):
|
||||
if self.field_type in ('select', 'multi_select'):
|
||||
if not self.options or len(self.options) == 0:
|
||||
raise ValueError(
|
||||
f'{self.field_type} fields must have at least one option'
|
||||
)
|
||||
return self
|
||||
|
||||
|
||||
class CategoryInfo(BaseModel):
|
||||
@@ -22,25 +84,45 @@ class TreeBase(BaseModel):
|
||||
|
||||
|
||||
class TreeCreate(TreeBase):
|
||||
tree_type: TreeType = Field('troubleshooting', description="Tree type: troubleshooting or procedural")
|
||||
tree_structure: dict[str, Any] = Field(..., description="The decision tree structure in JSON format")
|
||||
intake_form: Optional[list[IntakeFormField]] = Field(None, description="Intake form field definitions (procedural flows only)")
|
||||
is_public: bool = Field(False, description="Make tree visible to all users")
|
||||
is_default: bool = Field(False, description="Mark as a default/system tree (admin only)")
|
||||
status: Literal['draft', 'published'] = Field('published', description="Status: draft or published")
|
||||
category_id: Optional[UUID] = Field(None, description="Category ID from tree_categories table")
|
||||
tags: Optional[list[str]] = Field(None, max_length=10, description="List of tag names to assign")
|
||||
|
||||
@model_validator(mode='after')
|
||||
def validate_intake_form_unique_variables(self):
|
||||
if self.intake_form:
|
||||
names = [f.variable_name for f in self.intake_form]
|
||||
if len(names) != len(set(names)):
|
||||
raise ValueError('Intake form variable names must be unique')
|
||||
return self
|
||||
|
||||
|
||||
class TreeUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=255)
|
||||
description: Optional[str] = None
|
||||
category: Optional[str] = Field(None, max_length=100)
|
||||
category_id: Optional[UUID] = None
|
||||
tree_type: Optional[TreeType] = None
|
||||
tree_structure: Optional[dict[str, Any]] = None
|
||||
intake_form: Optional[list[IntakeFormField]] = None
|
||||
is_public: Optional[bool] = None
|
||||
is_active: Optional[bool] = None
|
||||
status: Optional[Literal['draft', 'published']] = None
|
||||
tags: Optional[list[str]] = Field(None, max_length=10, description="List of tag names to assign (replaces existing)")
|
||||
|
||||
@model_validator(mode='after')
|
||||
def validate_intake_form_unique_variables(self):
|
||||
if self.intake_form:
|
||||
names = [f.variable_name for f in self.intake_form]
|
||||
if len(names) != len(set(names)):
|
||||
raise ValueError('Intake form variable names must be unique')
|
||||
return self
|
||||
|
||||
|
||||
class ForkCreate(BaseModel):
|
||||
fork_reason: Optional[str] = Field(None, max_length=255, description="Brief reason for forking")
|
||||
@@ -62,7 +144,9 @@ class ForkInfo(BaseModel):
|
||||
|
||||
class TreeResponse(TreeBase):
|
||||
id: UUID
|
||||
tree_type: str = 'troubleshooting'
|
||||
tree_structure: dict[str, Any]
|
||||
intake_form: Optional[list[dict[str, Any]]] = None
|
||||
author_id: Optional[UUID] = None
|
||||
account_id: Optional[UUID] = None
|
||||
category_id: Optional[UUID] = None
|
||||
@@ -86,6 +170,7 @@ class TreeListResponse(BaseModel):
|
||||
id: UUID
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
tree_type: str = 'troubleshooting'
|
||||
category: Optional[str] = None
|
||||
category_id: Optional[UUID] = None
|
||||
category_info: Optional[CategoryInfo] = None
|
||||
|
||||
Reference in New Issue
Block a user