Add runtime guidance input queue
This commit is contained in:
@@ -230,6 +230,69 @@ class RunStateStore:
|
||||
return None
|
||||
return self._snapshot_from_row(conn, row)
|
||||
|
||||
def events_since(
|
||||
self,
|
||||
account_key: str,
|
||||
session_id: str,
|
||||
*,
|
||||
after_event_seq: int = 0,
|
||||
limit: int = 500,
|
||||
) -> dict[str, Any]:
|
||||
with self._connect() as conn:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
select e.id, e.recorded_at, e.event_json, s.run_id, s.status
|
||||
from run_events e
|
||||
join run_states s on s.run_id = e.run_id
|
||||
where s.account_key = ?
|
||||
and s.session_id = ?
|
||||
and e.id > ?
|
||||
order by e.id asc
|
||||
limit ?
|
||||
""",
|
||||
(
|
||||
account_key,
|
||||
session_id,
|
||||
max(0, int(after_event_seq)),
|
||||
max(1, int(limit)),
|
||||
),
|
||||
).fetchall()
|
||||
latest_row = conn.execute(
|
||||
"""
|
||||
select max(e.id) as latest_event_seq
|
||||
from run_events e
|
||||
join run_states s on s.run_id = e.run_id
|
||||
where s.account_key = ?
|
||||
and s.session_id = ?
|
||||
""",
|
||||
(account_key, session_id),
|
||||
).fetchone()
|
||||
events: list[dict[str, Any]] = []
|
||||
for row in rows:
|
||||
try:
|
||||
event = json.loads(row['event_json'])
|
||||
except (TypeError, json.JSONDecodeError):
|
||||
continue
|
||||
if not isinstance(event, dict):
|
||||
continue
|
||||
events.append(
|
||||
{
|
||||
'event_seq': int(row['id']),
|
||||
'run_id': row['run_id'],
|
||||
'run_status': row['status'],
|
||||
'recorded_at': float(row['recorded_at'] or 0.0),
|
||||
'event': event,
|
||||
}
|
||||
)
|
||||
latest_event_seq = 0
|
||||
if latest_row is not None and latest_row['latest_event_seq'] is not None:
|
||||
latest_event_seq = int(latest_row['latest_event_seq'])
|
||||
return {
|
||||
'session_id': session_id,
|
||||
'latest_event_seq': latest_event_seq,
|
||||
'events': events,
|
||||
}
|
||||
|
||||
def mark_interrupted_if_active(
|
||||
self,
|
||||
run_id: str,
|
||||
|
||||
Reference in New Issue
Block a user