Auto-run queued session inputs
This commit is contained in:
@@ -471,6 +471,46 @@ def consume_session_guidance(
|
||||
return [_queue_row_to_dict(row) for row in rows]
|
||||
|
||||
|
||||
def consume_next_session_input(
|
||||
session_id: str,
|
||||
directory: Path | None = None,
|
||||
) -> dict[str, Any] | None:
|
||||
target_dir = directory or DEFAULT_AGENT_SESSION_DIR
|
||||
now = time.time()
|
||||
with _connect_agent_session_db(target_dir) as conn:
|
||||
row = conn.execute(
|
||||
"""
|
||||
select *
|
||||
from agent_input_queue
|
||||
where session_id = ?
|
||||
and status = 'pending'
|
||||
and kind = 'next_turn'
|
||||
order by id asc
|
||||
limit 1
|
||||
""",
|
||||
(session_id,),
|
||||
).fetchone()
|
||||
if row is None:
|
||||
return None
|
||||
cursor = conn.execute(
|
||||
"""
|
||||
update agent_input_queue
|
||||
set status = 'consumed',
|
||||
updated_at = ?,
|
||||
consumed_at = ?
|
||||
where id = ? and status = 'pending'
|
||||
""",
|
||||
(now, now, int(row['id'])),
|
||||
)
|
||||
if int(cursor.rowcount or 0) <= 0:
|
||||
return None
|
||||
item = _queue_row_to_dict(row)
|
||||
item['status'] = 'consumed'
|
||||
item['updated_at'] = now
|
||||
item['consumed_at'] = now
|
||||
return item
|
||||
|
||||
|
||||
def delete_agent_session(session_id: str, directory: Path | None = None) -> bool:
|
||||
target_dir = directory or DEFAULT_AGENT_SESSION_DIR
|
||||
deleted = False
|
||||
|
||||
Reference in New Issue
Block a user