Compare commits

3 Commits

Author SHA1 Message Date
f3afdff515 Merge branch 'main' into issue/session
Some checks failed
CI / ci (pull_request) Failing after 12s
2026-03-11 23:09:59 +00:00
8826d84e59 Remove redudant session_id from document path
Some checks failed
CI / ci (pull_request) Failing after 12s
2026-03-11 17:28:45 +00:00
ac27d12ed3 Add notification model (#31)
All checks were successful
CI / ci (push) Successful in 21s
Co-authored-by: Anibal Angulo <a8065384@banorte.com>
Reviewed-on: #31
2026-03-10 23:50:41 +00:00
2 changed files with 9 additions and 17 deletions

View File

@@ -78,9 +78,7 @@ class NotificationDocument(BaseModel):
class NotificationBackend(Protocol): class NotificationBackend(Protocol):
"""Backend-agnostic interface for notification storage.""" """Backend-agnostic interface for notification storage."""
async def get_recent_notifications( async def get_recent_notifications(self, phone_number: str) -> list[Notification]:
self, phone_number: str
) -> list[Notification]:
"""Return recent notifications for *phone_number*.""" """Return recent notifications for *phone_number*."""
... ...
@@ -113,9 +111,7 @@ class FirestoreNotificationBackend:
self._max_to_notify = max_to_notify self._max_to_notify = max_to_notify
self._window_hours = window_hours self._window_hours = window_hours
async def get_recent_notifications( async def get_recent_notifications(self, phone_number: str) -> list[Notification]:
self, phone_number: str
) -> list[Notification]:
"""Get recent notifications for a user. """Get recent notifications for a user.
Retrieves notifications created within the configured time window, Retrieves notifications created within the configured time window,
@@ -148,9 +144,7 @@ class FirestoreNotificationBackend:
cutoff = time.time() - (self._window_hours * 3600) cutoff = time.time() - (self._window_hours * 3600)
parsed = [ parsed = [
n n for n in document.notificaciones if n.timestamp_creacion >= cutoff
for n in document.notificaciones
if n.timestamp_creacion >= cutoff
] ]
if not parsed: if not parsed:
@@ -212,9 +206,7 @@ class RedisNotificationBackend:
self._max_to_notify = max_to_notify self._max_to_notify = max_to_notify
self._window_hours = window_hours self._window_hours = window_hours
async def get_recent_notifications( async def get_recent_notifications(self, phone_number: str) -> list[Notification]:
self, phone_number: str
) -> list[Notification]:
"""Get recent notifications for a user from Redis. """Get recent notifications for a user from Redis.
Reads from the ``notification:{phone}`` key, parses the JSON Reads from the ``notification:{phone}`` key, parses the JSON
@@ -246,9 +238,7 @@ class RedisNotificationBackend:
cutoff = time.time() - (self._window_hours * 3600) cutoff = time.time() - (self._window_hours * 3600)
parsed = [ parsed = [
n n for n in document.notificaciones if n.timestamp_creacion >= cutoff
for n in document.notificaciones
if n.timestamp_creacion >= cutoff
] ]
if not parsed: if not parsed:

View File

@@ -43,8 +43,9 @@ class FirestoreSessionService(BaseSessionService):
adk_user_states/{app_name}__{user_id} adk_user_states/{app_name}__{user_id}
→ user-scoped state key/values → user-scoped state key/values
adk_sessions/{app_name}__{user_id}__{session_id} adk_sessions/{app_name}__{user_id}
{app_name, user_id, session_id, state: {…}, last_update_time} {app_name, user_id, session_id, state: {…}, last_update_time}
→ Single continuous session per user (session_id is ignored)
└─ events/{event_id} → serialised Event └─ events/{event_id} → serialised Event
""" """
@@ -96,8 +97,9 @@ class FirestoreSessionService(BaseSessionService):
) )
def _session_ref(self, app_name: str, user_id: str, session_id: str) -> Any: def _session_ref(self, app_name: str, user_id: str, session_id: str) -> Any:
# Single continuous session per user: use only user_id, ignore session_id
return self._db.collection(f"{self._prefix}_sessions").document( return self._db.collection(f"{self._prefix}_sessions").document(
f"{app_name}__{user_id}__{session_id}" f"{app_name}__{user_id}"
) )
def _events_col(self, app_name: str, user_id: str, session_id: str) -> Any: def _events_col(self, app_name: str, user_id: str, session_id: str) -> Any: