Log client details for API and agent requests
All checks were successful
Deploy to VPS / test (push) Successful in 1m42s
Deploy to VPS / deploy (push) Successful in 14s

This commit is contained in:
Carlos Escalante
2026-07-14 22:55:33 -06:00
parent 8ceed0ab2e
commit 3d0547743f
5 changed files with 112 additions and 2 deletions

View File

@@ -41,7 +41,14 @@ def _last_user_prompt(messages: list[dict[str, Any]]) -> str | None:
def create_chat_run(
*, request_id: str, agui_run_id: str | None, thread_id: str | None, messages: list[dict[str, Any]]
*,
request_id: str,
agui_run_id: str | None,
thread_id: str | None,
messages: list[dict[str, Any]],
client_ip: str | None = None,
user_agent: str | None = None,
browser: str | None = None,
) -> int:
now = utcnow()
with Session(engine) as session:
@@ -50,6 +57,9 @@ def create_chat_run(
agui_run_id=agui_run_id,
requested_thread_id=thread_id,
model=settings.AGENT_MODEL,
client_ip=client_ip,
user_agent=user_agent,
browser=browser,
user_prompt=_last_user_prompt(messages),
expires_at=now + timedelta(days=CHAT_LOG_RETENTION_DAYS),
)