feat: add versioned research templates and alpha variants
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""Metadata snapshots used by research; refreshes never create simulations."""
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, Request
|
||||
|
||||
from ..research.workspace_contracts import FieldAvailabilityInput, OperatorAnnotation
|
||||
from ..security import require_auth
|
||||
from .contracts import Scope
|
||||
from .research_metadata import ResearchMetadata, availability_key
|
||||
|
||||
router = APIRouter(prefix="/api/v1/catalog", tags=["catalog"], dependencies=[Depends(require_auth)])
|
||||
|
||||
|
||||
@router.get("/operators")
|
||||
async def operators(
|
||||
request: Request,
|
||||
q: str = "",
|
||||
category: str | None = None,
|
||||
favorite: bool = False,
|
||||
limit: int = Query(25, ge=1, le=100),
|
||||
offset: int = Query(0, ge=0),
|
||||
):
|
||||
async with request.app.state.sessions() as db:
|
||||
return await ResearchMetadata(db).operators(q, category, favorite, limit, offset)
|
||||
|
||||
|
||||
@router.post("/operators/refresh")
|
||||
async def refresh_operators(request: Request):
|
||||
async with request.app.state.sessions.begin() as db:
|
||||
return await ResearchMetadata(db, request.app.state.runner.client).refresh_operators()
|
||||
|
||||
|
||||
@router.patch("/operators/{name}/research")
|
||||
async def operator_note(name: str, body: OperatorAnnotation, request: Request):
|
||||
async with request.app.state.sessions.begin() as db:
|
||||
return await ResearchMetadata(db).annotate(name, body)
|
||||
|
||||
|
||||
@router.get("/setting-options")
|
||||
async def setting_options(request: Request):
|
||||
async with request.app.state.sessions() as db:
|
||||
return await ResearchMetadata(db).get("settings")
|
||||
|
||||
|
||||
@router.post("/setting-options/refresh")
|
||||
async def refresh_settings(request: Request):
|
||||
async with request.app.state.sessions.begin() as db:
|
||||
return await ResearchMetadata(db, request.app.state.runner.client).refresh_settings()
|
||||
|
||||
|
||||
@router.get("/field-availability/{field_id}")
|
||||
async def availability(field_id: str, scope: Annotated[Scope, Query()], request: Request):
|
||||
async with request.app.state.sessions() as db:
|
||||
return await ResearchMetadata(db).get(availability_key(field_id, scope))
|
||||
|
||||
|
||||
@router.post("/field-availability/refresh")
|
||||
async def refresh_availability(body: FieldAvailabilityInput, request: Request):
|
||||
async with request.app.state.sessions.begin() as db:
|
||||
return await ResearchMetadata(db, request.app.state.runner.client).refresh_availability(body)
|
||||
Reference in New Issue
Block a user