Add stream dashboard ingestion

This commit is contained in:
2026-05-12 10:18:20 -05:00
parent c65b51c61c
commit c1d6032eb2
3 changed files with 160 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
"""Data access layer for database operations."""
import json
import logging
import uuid
from datetime import datetime
@@ -8,6 +9,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.memory.models import (
StreamSession,
StreamDashboard,
ChatMessage,
AgentAction,
ClipCandidate,
@@ -66,6 +68,61 @@ class Repository:
result = await self.session.execute(stmt)
return list(result.scalars().all())
# Stream Dashboard operations
async def upsert_dashboard(
self,
session_id: str,
raw_markdown: str,
stream_title: str | None = None,
game: str | None = None,
mood: str | None = None,
go_live_notification: str | None = None,
social_post: str | None = None,
session_goals: list[str] | None = None,
content_angle: str | None = None,
) -> StreamDashboard:
"""Create or update a stream dashboard for a session."""
dashboard = await self.get_dashboard(session_id)
now = datetime.utcnow()
goals_json = json.dumps(session_goals or [])
if dashboard is None:
dashboard = StreamDashboard(
session_id=session_id,
raw_markdown=raw_markdown,
stream_title=stream_title,
game=game,
mood=mood,
go_live_notification=go_live_notification,
social_post=social_post,
session_goals=goals_json,
content_angle=content_angle,
created_at=now,
updated_at=now,
)
self.session.add(dashboard)
else:
dashboard.raw_markdown = raw_markdown
dashboard.stream_title = stream_title
dashboard.game = game
dashboard.mood = mood
dashboard.go_live_notification = go_live_notification
dashboard.social_post = social_post
dashboard.session_goals = goals_json
dashboard.content_angle = content_angle
dashboard.updated_at = now
await self.session.commit()
logger.info(f"Saved dashboard for session {session_id}")
return dashboard
async def get_dashboard(self, session_id: str) -> StreamDashboard | None:
"""Retrieve the dashboard for a session."""
stmt = select(StreamDashboard).where(StreamDashboard.session_id == session_id)
result = await self.session.execute(stmt)
return result.scalars().first()
# Chat Message operations
async def add_chat_message(