ai_co_discuss 0.4.80 → 0.4.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,8 @@
3
3
  The owner's composer sends with `queue: true`; when the room is busy (or earlier messages still wait) the message is kept
4
4
  here instead of being posted. A message naming only a host with no open request is not queued: it is a side question the host
5
5
  answers beside members still at work, so the owner can ask how the work stands. A host that is itself busy could not answer any
6
- sooner, so that message keeps its place in the queue. Each idle moment posts the head through the normal message path with its own submission_id,
6
+ sooner, so that message waits until the host is free, and then goes ahead of the messages waiting for the whole room. Each idle
7
+ moment posts the next message through the normal message path with its own submission_id,
7
8
  so a repeated drain finds the posted message and only removes the row. A failed post keeps the row with its reason and holds
8
9
  the queue; the owner's stop pauses it. The owner may send one at once, edit, delete, reorder or resume the queue.
9
10
  """
@@ -118,17 +119,27 @@ def post_item(connection, room_id, row, post):
118
119
  return result
119
120
 
120
121
 
122
+ def next_queued(connection, room_id):
123
+ """The queued message that may go now: the head of an idle room; while members work, the first naming only a free host."""
124
+ rows = connection.execute("SELECT * FROM queued_messages WHERE room_id=? ORDER BY position,id", (room_id,)).fetchall()
125
+ if not room_busy(connection, room_id):
126
+ return rows[0] if rows else None
127
+ if host_busy(connection, room_id):
128
+ return None
129
+ return next((row for row in rows if names_only_host(connection, room_id, json.loads(row["payload"]))), None)
130
+
131
+
121
132
  def drain(connection, room_id, post):
122
- """Post the head while the room is idle, unpaused and the head has not failed; stops at the first message that keeps it busy."""
133
+ """Post what may go now, one message at a time, unless the queue is paused; stops at a failed message or when nothing may go."""
123
134
  if not connection.execute("SELECT 1 FROM queued_messages WHERE room_id=? LIMIT 1", (room_id,)).fetchone():
124
135
  return
125
136
  begin_write(connection)
126
137
  archived = connection.execute("SELECT archived FROM room_directory WHERE room_id=?", (room_id,)).fetchone()
127
138
  if archived is None or archived[0] or connection.execute("SELECT 1 FROM queued_message_pauses WHERE room_id=?", (room_id,)).fetchone():
128
139
  return
129
- while not room_busy(connection, room_id):
130
- head = connection.execute("SELECT * FROM queued_messages WHERE room_id=? ORDER BY position,id LIMIT 1", (room_id,)).fetchone()
131
- if head is None or head["failure"] or not post_item(connection, room_id, head, post):
140
+ while True:
141
+ row = next_queued(connection, room_id)
142
+ if row is None or row["failure"] or not post_item(connection, room_id, row, post):
132
143
  return
133
144
 
134
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai_co_discuss",
3
- "version": "0.4.80",
3
+ "version": "0.4.81",
4
4
  "bin": {
5
5
  "codiscuss": "runner/codiscuss.mjs"
6
6
  },