patristic-be / src /lib /queries /models.py
Mario33333's picture
deploy: reader-access security hardening (feature/audiobook@06a5ed8)
7c2d250 verified
Raw
History Blame Contribute Delete
934 Bytes
"""Typed models for the query-history domain."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Literal
QueryPage = Literal["search", "compare", "allusions"]
@dataclass(frozen=True)
class QueryRun:
"""One persisted Research run."""
id: int
timestamp: str
page: QueryPage
mode: str | None # actual final mode (LOOKUP / COMPARISON / CONCEPTUAL)
query: str
params: dict # parsed back from params_json
result: dict # parsed back from result_json
cost_usd: float
duration_ms: int
n_calls: int
pinned: bool
note: str | None
username: str | None = None # who ran it; NULL on rows from before the column existed
@property
def query_preview(self) -> str:
return (self.query or "")[:120] + ("…" if self.query and len(self.query) > 120 else "")