Add current stream operator status
This commit is contained in:
@@ -144,6 +144,11 @@ class AgentOrchestrator:
|
||||
)
|
||||
message_count = await repo.count_messages(session.id)
|
||||
dashboard = await repo.get_dashboard(session.id)
|
||||
last_hearthkeeper_action = await repo.get_latest_action(
|
||||
session_id=session.id,
|
||||
action_type=AgentActionType.RESPONSE,
|
||||
mode="hearthkeeper",
|
||||
)
|
||||
last_activity_at = (
|
||||
recent_messages[0].timestamp if recent_messages else session.started_at
|
||||
)
|
||||
@@ -154,7 +159,11 @@ class AgentOrchestrator:
|
||||
"message_count": message_count,
|
||||
"theme": session.theme,
|
||||
"dashboard": Repository.serialize_dashboard(dashboard),
|
||||
"last_hearthkeeper_prompt_at": None,
|
||||
"last_hearthkeeper_prompt_at": (
|
||||
last_hearthkeeper_action.timestamp
|
||||
if last_hearthkeeper_action
|
||||
else None
|
||||
),
|
||||
}
|
||||
self.chat_activity.record_activity(session.id, occurred_at=last_activity_at)
|
||||
restored_count += 1
|
||||
@@ -392,6 +401,61 @@ class AgentOrchestrator:
|
||||
"active_session_count": len(self.active_sessions),
|
||||
}
|
||||
|
||||
def get_hearthkeeper_runtime_status(self, session_id: str) -> dict:
|
||||
"""Get Hearthkeeper timing status for an active session."""
|
||||
session_info = self.active_sessions.get(session_id)
|
||||
if not session_info:
|
||||
return {}
|
||||
|
||||
now = datetime.utcnow()
|
||||
last_activity_at = self.chat_activity.last_activity_at(session_id)
|
||||
last_prompt_at = session_info.get("last_hearthkeeper_prompt_at")
|
||||
|
||||
next_from_activity = None
|
||||
if last_activity_at:
|
||||
next_from_activity = last_activity_at + self.chat_activity.inactivity_threshold
|
||||
|
||||
next_from_prompt = None
|
||||
if last_prompt_at:
|
||||
next_from_prompt = last_prompt_at + self.hearthkeeper_prompt_interval
|
||||
|
||||
next_eligible_at = max(
|
||||
[candidate for candidate in (next_from_activity, next_from_prompt) if candidate],
|
||||
default=None,
|
||||
)
|
||||
seconds_until_next_prompt = None
|
||||
if next_eligible_at:
|
||||
seconds_until_next_prompt = max(
|
||||
0,
|
||||
int((next_eligible_at - now).total_seconds()),
|
||||
)
|
||||
quiet_enough = bool(
|
||||
last_activity_at
|
||||
and now - last_activity_at >= self.chat_activity.inactivity_threshold
|
||||
)
|
||||
prompt_interval_elapsed = bool(
|
||||
not last_prompt_at
|
||||
or now - last_prompt_at >= self.hearthkeeper_prompt_interval
|
||||
)
|
||||
|
||||
return {
|
||||
"last_activity_at": last_activity_at.isoformat() if last_activity_at else None,
|
||||
"last_hearthkeeper_prompt_at": (
|
||||
last_prompt_at.isoformat() if last_prompt_at else None
|
||||
),
|
||||
"next_eligible_prompt_at": (
|
||||
next_eligible_at.isoformat() if next_eligible_at else None
|
||||
),
|
||||
"seconds_until_next_prompt": seconds_until_next_prompt,
|
||||
"inactivity_threshold_minutes": int(
|
||||
self.chat_activity.inactivity_threshold.total_seconds() / 60
|
||||
),
|
||||
"prompt_interval_minutes": int(
|
||||
self.hearthkeeper_prompt_interval.total_seconds() / 60
|
||||
),
|
||||
"can_prompt_now": quiet_enough and prompt_interval_elapsed,
|
||||
}
|
||||
|
||||
async def tick(self) -> list[dict]:
|
||||
"""Evaluate active sessions for time-based agent behavior."""
|
||||
results = []
|
||||
|
||||
Reference in New Issue
Block a user