Add Hearthkeeper preview endpoint
This commit is contained in:
32
app/main.py
32
app/main.py
@@ -302,6 +302,38 @@ async def test_loop_inactivity(
|
||||
}
|
||||
|
||||
|
||||
@app.post("/admin/hearthkeeper/preview", dependencies=[Depends(require_admin)])
|
||||
async def preview_hearthkeeper_prompt(session_id: str | None = Form(None)) -> dict:
|
||||
"""Generate a Hearthkeeper prompt preview without posting to Twitch."""
|
||||
if not orchestrator:
|
||||
raise HTTPException(status_code=503, detail="Orchestrator not initialized")
|
||||
|
||||
resolved_session_id = session_id or get_current_stream_session_id()
|
||||
if not resolved_session_id:
|
||||
raise HTTPException(status_code=404, detail="No active stream session found")
|
||||
|
||||
result = await orchestrator.preview_hearthkeeper_prompt(resolved_session_id)
|
||||
if result.get("reason") == "session_not_found":
|
||||
raise HTTPException(status_code=404, detail="Active session not found")
|
||||
|
||||
live_status = None
|
||||
session_info = orchestrator.active_sessions.get(resolved_session_id)
|
||||
if twitch_live_status and session_info:
|
||||
live_status = (
|
||||
await twitch_live_status.get_status(session_info["channel_name"])
|
||||
).to_dict()
|
||||
|
||||
return {
|
||||
"status": "preview_generated" if result.get("generated") else "failed",
|
||||
"preview": result,
|
||||
"would_post_now": await orchestrator.can_interact_with_chat(
|
||||
session_info["channel_name"]
|
||||
) if session_info else False,
|
||||
"live_status": live_status,
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
}
|
||||
|
||||
|
||||
def serialize_dashboard(dashboard) -> dict:
|
||||
"""Serialize a dashboard database model into an API response."""
|
||||
return Repository.serialize_dashboard(dashboard)
|
||||
|
||||
Reference in New Issue
Block a user