docs: document server-side rendering pipeline, response timing middleware, and Telegram pairing API
- Add comprehensive documentation for backend content rendering in AGENTS.md, detailing the new `render_content` and `render_title` Jinja globals built on mistune with media processing, emoji shortcodes, and XSS protection
- Document the `X-Response-Time` header and bottom-left render time indicator in README.md
- Update bot token pricing documentation to clarify fallback vs gateway cost headers
- Add `email_accounts` to soft-delete tables and `idx_users_role` composite index in database schema
- Implement `telegram_pairings` and `telegram_links` table creation with column migration and indexes
- Add `/profile/{username}/telegram` endpoint to docs API with request/unpair actions
- Register `TelegramService` in main.py lifespan and add `response_timing` middleware emitting `X-Response-Time` header
- Introduce `TelegramPairForm` model and `guard_public_host_sync` synchronous host validation function
This commit is contained in:
@@ -9,7 +9,7 @@ import httpx
|
||||
|
||||
from devplacepy import stealth
|
||||
from .config import Settings
|
||||
from .cost import record_usage
|
||||
from .cost import record_cost, record_usage
|
||||
from .errors import LLMError
|
||||
|
||||
logger = logging.getLogger("devii.llm")
|
||||
@@ -67,6 +67,7 @@ class LLMClient:
|
||||
raise LLMError("Model response contained no message.", body=str(data)[:500])
|
||||
|
||||
record_usage(data.get("usage"))
|
||||
self._record_native_cost(response)
|
||||
logger.debug(
|
||||
"LLM response received (tool_calls=%s)", bool(message.get("tool_calls"))
|
||||
)
|
||||
@@ -94,6 +95,7 @@ class LLMClient:
|
||||
except (ValueError, KeyError, IndexError) as exc:
|
||||
raise LLMError("Model endpoint returned an unexpected response.") from exc
|
||||
record_usage(data.get("usage"))
|
||||
self._record_native_cost(response)
|
||||
return content
|
||||
|
||||
async def summarize(self, text: str) -> str:
|
||||
@@ -124,8 +126,19 @@ class LLMClient:
|
||||
"Model summarization returned an unexpected response."
|
||||
) from exc
|
||||
record_usage(data.get("usage"))
|
||||
self._record_native_cost(response)
|
||||
return content
|
||||
|
||||
@staticmethod
|
||||
def _record_native_cost(response: httpx.Response) -> None:
|
||||
raw = response.headers.get("X-Gateway-Cost-USD")
|
||||
if raw is None:
|
||||
return
|
||||
try:
|
||||
record_cost(float(raw))
|
||||
except (TypeError, ValueError):
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def _reason(response: httpx.Response) -> str:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user