feat(realism): synthetic-files browser API
Adds GET /api/v1/realism/synthetic-files (paginated list, filters by
decky_uuid, persona, content_class) and
GET /api/v1/realism/synthetic-files/{uuid} (single row with last_body
and a truncated:bool flag set when the stored body is at the 64KB cap).
Repo gains count_synthetic_files() and get_synthetic_file(uuid). The
list view drops last_body to keep the wire payload bounded; the detail
endpoint is the only path that returns it. Read-only — orchestrator
remains the sole writer.
This commit is contained in:
@@ -1130,16 +1130,35 @@ class BaseRepository(ABC):
|
||||
*,
|
||||
decky_uuid: Optional[str] = None,
|
||||
persona: Optional[str] = None,
|
||||
content_class: Optional[str] = None,
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Paginated synthetic_files newest-first.
|
||||
|
||||
Optional filters narrow to one decky and/or one persona, used by
|
||||
the dashboard's "files this decky has grown" view.
|
||||
Optional filters narrow to one decky, persona, and/or content
|
||||
class — used by the dashboard's "files this decky has grown"
|
||||
view.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
async def count_synthetic_files(
|
||||
self,
|
||||
*,
|
||||
decky_uuid: Optional[str] = None,
|
||||
persona: Optional[str] = None,
|
||||
content_class: Optional[str] = None,
|
||||
) -> int:
|
||||
"""Total synthetic_files matching the same filters as
|
||||
:meth:`list_synthetic_files`. Used to drive paginated UI."""
|
||||
raise NotImplementedError
|
||||
|
||||
async def get_synthetic_file(
|
||||
self, uuid: str,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
"""Single synthetic_files row by uuid, or ``None``."""
|
||||
raise NotImplementedError
|
||||
|
||||
async def pick_random_synthetic_file_for_edit(
|
||||
self,
|
||||
decky_uuid: str,
|
||||
|
||||
@@ -3365,6 +3365,7 @@ class SQLModelRepository(BaseRepository):
|
||||
*,
|
||||
decky_uuid: Optional[str] = None,
|
||||
persona: Optional[str] = None,
|
||||
content_class: Optional[str] = None,
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
) -> list[dict[str, Any]]:
|
||||
@@ -3374,6 +3375,8 @@ class SQLModelRepository(BaseRepository):
|
||||
stmt = stmt.where(SyntheticFile.decky_uuid == decky_uuid)
|
||||
if persona is not None:
|
||||
stmt = stmt.where(SyntheticFile.persona == persona)
|
||||
if content_class is not None:
|
||||
stmt = stmt.where(SyntheticFile.content_class == content_class)
|
||||
stmt = (
|
||||
stmt.order_by(desc(SyntheticFile.last_modified))
|
||||
.offset(offset)
|
||||
@@ -3382,6 +3385,36 @@ class SQLModelRepository(BaseRepository):
|
||||
result = await session.execute(stmt)
|
||||
return [r.model_dump(mode="json") for r in result.scalars().all()]
|
||||
|
||||
async def count_synthetic_files(
|
||||
self,
|
||||
*,
|
||||
decky_uuid: Optional[str] = None,
|
||||
persona: Optional[str] = None,
|
||||
content_class: Optional[str] = None,
|
||||
) -> int:
|
||||
from sqlalchemy import func as _f
|
||||
async with self._session() as session:
|
||||
stmt = select(_f.count(SyntheticFile.uuid))
|
||||
if decky_uuid is not None:
|
||||
stmt = stmt.where(SyntheticFile.decky_uuid == decky_uuid)
|
||||
if persona is not None:
|
||||
stmt = stmt.where(SyntheticFile.persona == persona)
|
||||
if content_class is not None:
|
||||
stmt = stmt.where(SyntheticFile.content_class == content_class)
|
||||
result = await session.execute(stmt)
|
||||
return int(result.scalar() or 0)
|
||||
|
||||
async def get_synthetic_file(
|
||||
self, uuid: str,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
async with self._session() as session:
|
||||
stmt = select(SyntheticFile).where(SyntheticFile.uuid == uuid)
|
||||
result = await session.execute(stmt)
|
||||
row = result.scalars().first()
|
||||
if row is None:
|
||||
return None
|
||||
return row.model_dump(mode="json")
|
||||
|
||||
async def pick_random_synthetic_file_for_edit(
|
||||
self,
|
||||
decky_uuid: str,
|
||||
|
||||
Reference in New Issue
Block a user