Files
worldquant-alpha-system/backend/app/catalog/research_routes.py
T
yuxuanhui e256d6fef1
Deploy production / deploy (push) Successful in 56s
feat: add Super Alpha research, management and MCP workflows
2026-09-13 12:32:16 +08:00

63 lines
2.3 KiB
Python

"""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,
stage: str | None = None,
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, stage)
@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)