feat(automations): implement model eligibility checks for automation creation

- Added model eligibility checks to ensure automations can only use billable models (premium or BYOK).
- Introduced new API endpoint to report model eligibility status for search spaces.
- Updated frontend components to display eligibility alerts and disable creation options when models are not billable.
- Enhanced automation creation forms to reflect model eligibility, preventing users from submitting invalid configurations.
- Implemented server-side logic to capture and preserve model preferences across automation edits, ensuring consistent behavior during execution.
This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-05-29 03:13:46 -07:00
parent 5d90fbe99f
commit 409fec94c3
32 changed files with 1451 additions and 67 deletions

View file

@ -3,6 +3,7 @@
from __future__ import annotations
from fastapi import APIRouter, Depends, Query, status
from pydantic import BaseModel
from app.automations.schemas.api import (
AutomationCreate,
@ -16,6 +17,17 @@ from app.automations.services import AutomationService, get_automation_service
router = APIRouter()
class ModelEligibilityViolation(BaseModel):
kind: str
config_id: int | None
reason: str
class ModelEligibility(BaseModel):
allowed: bool
violations: list[ModelEligibilityViolation]
@router.post(
"/automations",
response_model=AutomationDetail,
@ -47,6 +59,23 @@ async def list_automations(
)
@router.get("/automations/model-eligibility", response_model=ModelEligibility)
async def get_automation_model_eligibility(
search_space_id: int = Query(...),
service: AutomationService = Depends(get_automation_service),
) -> ModelEligibility:
"""Report whether a search space's models are billable for automations.
Used by the frontend to gate creation: automations may only use premium
global models or user BYOK models (free models and Auto mode are blocked).
NOTE: declared before ``/automations/{automation_id}`` so the literal path
isn't captured by the int-typed ``{automation_id}`` route.
"""
result = await service.model_eligibility(search_space_id=search_space_id)
return ModelEligibility.model_validate(result)
@router.get("/automations/{automation_id}", response_model=AutomationDetail)
async def get_automation(
automation_id: int,