Compare commits

2 Commits

Author SHA1 Message Date
4ca4f82f52 Merge branch 'main' into notif-model
Some checks failed
CI / ci (pull_request) Failing after 11s
2026-03-10 23:48:03 +00:00
Anibal Angulo
7926d9881c Add notification model
Some checks failed
CI / ci (pull_request) Failing after 12s
2026-03-10 23:47:11 +00:00
2 changed files with 17 additions and 9 deletions

View File

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

View File

@@ -43,9 +43,8 @@ class FirestoreSessionService(BaseSessionService):
adk_user_states/{app_name}__{user_id}
→ user-scoped state key/values
adk_sessions/{app_name}__{user_id}
adk_sessions/{app_name}__{user_id}__{session_id}
{app_name, user_id, session_id, state: {…}, last_update_time}
→ Single continuous session per user (session_id is ignored)
└─ events/{event_id} → serialised Event
"""
@@ -97,9 +96,8 @@ class FirestoreSessionService(BaseSessionService):
)
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(
f"{app_name}__{user_id}"
f"{app_name}__{user_id}__{session_id}"
)
def _events_col(self, app_name: str, user_id: str, session_id: str) -> Any: