ai_co_discuss 0.4.59 → 0.4.61

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.
@@ -618,9 +618,15 @@ def failure_class_of(connection, execution_id):
618
618
 
619
619
 
620
620
  def quota_held_until(connection, member_id):
621
- """Until when a member out of quota waits: its latest execution failed on a usage limit and was not retried; else 0."""
621
+ """Until when a member out of quota waits: its latest execution failed on a usage limit and was not retried; else 0.
622
+
623
+ A new request the owner or the host gives it afterwards ends the wait and is tried at once: the reset time is only
624
+ the software's estimate (extra usage, another plan, another account signed in or an earlier reset lift it sooner),
625
+ and work nobody picks up is worse than one more quick failure, which holds the member again."""
622
626
  row = connection.execute("""SELECT f.failed_at,f.reset_at FROM execution_failures f
623
- WHERE f.failure_class='quota' AND f.execution_id=(SELECT MAX(id) FROM member_executions WHERE member_id=?)""", (member_id,)).fetchone()
627
+ WHERE f.failure_class='quota' AND f.execution_id=(SELECT MAX(id) FROM member_executions WHERE member_id=?)
628
+ AND NOT EXISTS(SELECT 1 FROM member_requests r WHERE r.member_id=? AND r.status='pending' AND r.created_by IN ('user','host')
629
+ AND r.created_at>=f.failed_at)""", (member_id, member_id)).fetchone()
624
630
  until = (row["reset_at"] or row["failed_at"] + QUOTA_HOLD_SECONDS) if row else 0
625
631
  return until if until > int(time.time()) else 0
626
632
 
@@ -1062,6 +1068,7 @@ def free_view(connection, room_id):
1062
1068
  member["pending"] = connection.execute("SELECT COUNT(*) FROM member_requests WHERE member_id=? AND status='pending'",
1063
1069
  (row["id"],)).fetchone()[0]
1064
1070
  member["held_until"] = held_until(connection, row["id"])
1071
+ member["quota_until"] = quota_held_until(connection, row["id"])
1065
1072
  members.append(member)
1066
1073
  names = {row["id"]: row["name"] for row in connection.execute("SELECT id,name FROM room_members WHERE room_id=?", (room_id,))}
1067
1074
  requests = [{**dict(row), "member": names.get(row["member_id"], ""),
@@ -2643,15 +2650,17 @@ def hand_over_routes(connection, room_id, routes, departed_id):
2643
2650
  VALUES (?,?,?,?,?,'user',?)""", (room_id, host["id"], message_id, message_id, purpose, int(time.time())))
2644
2651
 
2645
2652
 
2646
- def stop_member_work(connection, member_id, reason, cancel_reason, keep_pending=False):
2653
+ def stop_member_work(connection, member_id, reason, cancel_reason, keep_pending=False, requeue=False):
2647
2654
  """Void a member's live execution and, unless `keep_pending`, every open request, so nothing restarts by itself.
2648
2655
 
2649
2656
  The owner's stop keeps the requests that arrived while the member worked: like interrupting a turn, the member then
2650
- goes on to the messages sent after it, while a member that leaves drops them all.
2657
+ goes on to the messages sent after it, while a member that leaves drops them all. With `requeue` (the owner sending
2658
+ a message at once) the interrupted turn's own requests go back to pending too, so the next delivery carries them with
2659
+ the new message and nothing the owner asked is left unanswered.
2651
2660
  """
2652
2661
  for row in connection.execute("SELECT id FROM member_executions WHERE member_id=? AND status IN ('dispatched','started')",
2653
2662
  (member_id,)).fetchall():
2654
- finish_execution(connection, row["id"], "cancelled", reason, "cancelled", cancel_reason)
2663
+ finish_execution(connection, row["id"], "cancelled", reason, "pending" if requeue else "cancelled", "" if requeue else cancel_reason)
2655
2664
  if not keep_pending:
2656
2665
  record_cancel_reasons(connection, "member_id=? AND status='pending'", (member_id,), cancel_reason)
2657
2666
  connection.execute("UPDATE member_requests SET status='cancelled' WHERE member_id=? AND status='pending'", (member_id,))
@@ -2808,6 +2817,7 @@ def inbox(connection, room_id, token):
2808
2817
  member_view["label"] = shown.get(row["name"], row["name"])
2809
2818
  member_view["review_capability"] = review_capability(connection, room_id, row["id"], token)
2810
2819
  member_view["held_until"] = held_until(connection, row["id"])
2820
+ member_view["quota_until"] = quota_held_until(connection, row["id"])
2811
2821
  # The runner compares this with its adapter's effect and reports a change.
2812
2822
  reported = connection.execute("SELECT rewind,image_model FROM member_capabilities WHERE member_id=?", (row["id"],)).fetchone()
2813
2823
  member_view["rewind"], member_view["image_model"] = (reported[0], reported[1]) if reported else ("", "")
@@ -3584,7 +3594,7 @@ def interrupt_for_message(connection, room_id, message_id):
3584
3594
  if blocked:
3585
3595
  raise FileExistsError(Text("{value1} 正在执行且无法打断,这条消息继续排队,等它答完后发送", value1='、'.join(blocked)))
3586
3596
  for row in busy:
3587
- stop_member_work(connection, row["member_id"], Text("用户立即发送"), "user_stop", keep_pending=True)
3597
+ stop_member_work(connection, row["member_id"], Text("已打断:你立即发送了新消息,它会连同这条一起处理"), "user_stop", keep_pending=True, requeue=True)
3588
3598
  if busy:
3589
3599
  settle_batches(connection, room_id)
3590
3600
 
@@ -25,8 +25,13 @@ def queueing_enabled(connection):
25
25
 
26
26
 
27
27
  def room_busy(connection, room_id):
28
- """A member still has an open request, a one-after-another turn waits, or a discussion runs."""
29
- return connection.execute("""SELECT 1 FROM member_requests WHERE room_id=? AND status IN ('pending','delivering')
28
+ """A member still has an open request, a one-after-another turn waits, or a discussion runs.
29
+
30
+ Work the host left running in the background (sent without a handoff, or kept working beside it, as in
31
+ free_room.BACKGROUND_SQL) does not hold the owner's messages: the room goes on without waiting for it."""
32
+ return connection.execute("""SELECT 1 FROM member_requests r WHERE r.room_id=? AND r.status IN ('pending','delivering')
33
+ AND NOT (r.purpose='ask' AND r.created_by='host' AND (r.batch_id=0 OR EXISTS(
34
+ SELECT 1 FROM member_requests k WHERE k.message_id=r.message_id AND k.purpose='keep_working')))
30
35
  UNION ALL SELECT 1 FROM free_queue_waiting WHERE room_id=?
31
36
  UNION ALL SELECT 1 FROM discussion_sessions WHERE room_id=? AND status='active' LIMIT 1""",
32
37
  (room_id, room_id, room_id)).fetchone() is not None
@@ -534,7 +534,7 @@
534
534
  "用户取消讨论安排": "The user cancelled the discussion plan.",
535
535
  "评审未投递:{reason}": "Review was not delivered: {reason}",
536
536
  "专家 {name} 的讨论请求失败:{reason}。请决定跳过、重排或暂停。": "The discussion request for expert {name} failed: {reason}. Decide whether to skip, reorder, or pause.",
537
- "用户立即发送": "The user sent a message immediately.",
537
+ "已打断:你立即发送了新消息,它会连同这条一起处理": "Interrupted: you sent a new message right away; it takes this one up again together with it",
538
538
  "成员已离开": "The member left.",
539
539
  "成员已移除": "The member was removed.",
540
540
  "主持人已更换": "The host changed.",
@@ -747,5 +747,7 @@
747
747
  "这个会话的末尾没有可显示的对话。": "The end of this session has no messages to show.",
748
748
  "正在读取会话预览…": "Loading the session preview…",
749
749
  "在左侧选择一个会话查看预览。": "Select a session on the left to preview it.",
750
- "接入此会话": "Resume this session"
750
+ "接入此会话": "Resume this session",
751
+ "额度已用尽,预计 {value1} 恢复;给它发新消息会立即再试": "Out of quota, expected back at {value1}; a new message to it is tried at once",
752
+ "保存(Enter)": "Save (Enter)"
751
753
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai_co_discuss",
3
- "version": "0.4.59",
3
+ "version": "0.4.61",
4
4
  "bin": {
5
5
  "codiscuss": "runner/codiscuss.mjs"
6
6
  },
package/web/app.js CHANGED
@@ -1071,7 +1071,10 @@ async function refresh_room_content(room_id, version, versions) {
1071
1071
  cache_room_entry(room_views, room_id, room);
1072
1072
  state.room = merge_room_folder(room, versions.folder, versions.archive, versions.directory);
1073
1073
  render_room();
1074
- publish_view();
1074
+ // With a transcript already shown, the new room state waits for the new transcript and both show in one snapshot:
1075
+ // the room's requests and working cards laid out against the old messages, then again against the new ones, made
1076
+ // the page collapse and refill for a moment after every send. A room opened for the first time shows at once.
1077
+ if (!history_read || !state.messages.length) publish_view();
1075
1078
  load_room_models();
1076
1079
  });
1077
1080
  const history_read = state.tab === "discussion" ? load_message_history(room_id, version).then((result) => {
@@ -1082,6 +1085,7 @@ async function refresh_room_content(room_id, version, versions) {
1082
1085
  if (history_read && !state.messages.length && state.message_history?.key !== history_key) { state.messages_loading = true; publish_view(); }
1083
1086
  try {
1084
1087
  await Promise.all([room_read, history_read]);
1088
+ if (current()) publish_view();
1085
1089
  } catch (error) {
1086
1090
  if (current()) { state.messages_loading = false; state.messages_failure = error.message; publish_view(); }
1087
1091
  throw error;
@@ -1155,8 +1159,32 @@ function remember_room(room_id) {
1155
1159
  request_json("/api/rooms/last", { room_id }).catch(() => {});
1156
1160
  }
1157
1161
 
1162
+ // Each room keeps its unsent composer (text, files, reply) while another room is open, until this page closes.
1163
+ const room_composer_drafts = new Map();
1164
+
1165
+ /** Keep the open room's unsent text, files and reply aside; true when there was something to keep. */
1166
+ function keep_room_composer() {
1167
+ const room_id = state.room?.id;
1168
+ if (!room_id) return false;
1169
+ const text = element("message-input").value;
1170
+ const reply = state.reply_to ? { id: state.reply_to, label: element("reply-label").textContent } : null;
1171
+ if (!text.trim() && !state.attachment_drafts.length && !reply) { room_composer_drafts.delete(room_id); return false; }
1172
+ room_composer_drafts.set(room_id, { text, drafts: state.attachment_drafts, reply });
1173
+ state.attachment_drafts = [];
1174
+ return true;
1175
+ }
1176
+
1177
+ /** Put back what the room had in its composer when it was left. */
1178
+ function restore_room_composer(room_id) {
1179
+ const kept = room_id && room_composer_drafts.get(room_id);
1180
+ if (!kept) return;
1181
+ room_composer_drafts.delete(room_id);
1182
+ fill_composer(kept.text, kept.drafts, kept.reply);
1183
+ }
1184
+
1158
1185
  async function select_room(room_id) {
1159
1186
  if (room_id) { state.welcome = false; state.welcome_folder = null; }
1187
+ keep_room_composer();
1160
1188
  state.navigation_version++;
1161
1189
  state.refresh_version++;
1162
1190
  const listed = state.rooms.find((room) => room.id === room_id);
@@ -1189,6 +1217,7 @@ async function select_room(room_id) {
1189
1217
  element("search-input").value = "";
1190
1218
  element("mention-filter").setAttribute("aria-pressed", "false");
1191
1219
  cancel_reply();
1220
+ restore_room_composer(state.room?.id);
1192
1221
  select_tab("discussion", { refresh: false });
1193
1222
  history.replaceState(null, "", state.room ? `/?room=${encodeURIComponent(room_id)}` : "/");
1194
1223
  if (state.room) remember_room(room_id);
@@ -1754,14 +1783,21 @@ async function finish_message(result, room_id, drafts) {
1754
1783
  element("search-input").value = "";
1755
1784
  element("mention-filter").setAttribute("aria-pressed", "false");
1756
1785
  state.page = 1;
1757
- state.sending_preview = null;
1758
- // Show the saved message at once; the room, its requests and other new messages follow from a background refresh,
1759
- // so the composer does not wait for further round-trips on a slow connection.
1760
- if (!state.messages.some(message => message.id === result.message.id)) {
1761
- render_messages({ messages: [...state.messages, { ...result.message, just_sent: true }], total: state.message_total + 1, page: 1, pages: 1 });
1762
- }
1763
- element("messages").scrollTop = element("messages").scrollHeight;
1764
- run_action(refresh_room);
1786
+ // The sending card stays, now showing the saved number, until the room is read again: the saved card then takes its
1787
+ // place in the same render as the room's other changes (its request, the host's working card). Swapping it in first
1788
+ // and the rest a moment later laid the transcript out twice, and on a phone the page jumped and flashed in between.
1789
+ const saved_id = result.message.id;
1790
+ if (state.sending_preview) state.sending_preview = { ...state.sending_preview, saved_id };
1791
+ publish_view();
1792
+ refresh_room().catch(() => {}).finally(() => {
1793
+ if (state.sending_preview?.saved_id !== saved_id) return;
1794
+ release_files(state.sending_preview.release || []);
1795
+ state.sending_preview = null;
1796
+ if (state.room?.id === room_id && !state.messages.some(message => message.id === saved_id)) {
1797
+ render_messages({ messages: [...state.messages, { ...result.message, just_sent: true }], total: state.message_total + 1, page: 1, pages: 1 });
1798
+ }
1799
+ publish_view();
1800
+ });
1765
1801
  }
1766
1802
 
1767
1803
  /** A message the site queued: clear the composer; it waits above the composer until the room is idle. */
@@ -1899,7 +1935,8 @@ async function send_message(event) {
1899
1935
  const only_host = named.size === 1 && (state.room.free?.members || []).some(member => named.has(member.name) && member.role === "host" && member.status === "active");
1900
1936
  const likely_queued = payload.queue && !only_host && (queue?.busy || queue?.items?.length);
1901
1937
  state.sending_preview = likely_queued ? null : preview;
1902
- state.queueing_preview = likely_queued ? preview : null;
1938
+ // The rows already queued, so the first snapshot listing a new one swaps it in for this row (see publish_view).
1939
+ state.queueing_preview = likely_queued ? { ...preview, queued_ids: (queue.items || []).map(item => item.id) } : null;
1903
1940
  let sent;
1904
1941
  state.sending_done = new Promise(resolve => { sent = resolve; });
1905
1942
  publish_view();
@@ -1927,11 +1964,14 @@ async function send_message(event) {
1927
1964
  throw error;
1928
1965
  } finally {
1929
1966
  state.sending_message = false;
1967
+ // A saved message's card stays until the saved card replaces it (finish_message), and keeps its file previews till then.
1968
+ const kept = saved && state.sending_preview?.saved_id ? state.sending_preview : null;
1969
+ if (kept) kept.release = drafts;
1930
1970
  // Previews of files not kept by a failed card are no longer shown anywhere.
1931
- if (!state.failed_sends.some((failed) => failed.drafts === drafts)) release_files(drafts);
1971
+ else if (!state.failed_sends.some((failed) => failed.drafts === drafts)) release_files(drafts);
1932
1972
  if (state.sending_drafts === drafts) state.sending_drafts = null;
1933
1973
  sent(saved);
1934
- state.sending_preview = null;
1974
+ if (!kept) state.sending_preview = null;
1935
1975
  state.queueing_preview = null;
1936
1976
  state.upload_status = "";
1937
1977
  element("send-message").disabled = false;
@@ -5425,6 +5465,15 @@ async function initialize() {
5425
5465
 
5426
5466
  /** Publish a presentation snapshot shared by the legacy and Vue renderers. */
5427
5467
  function publish_view() {
5468
+ // A sent message's card gives way in the same snapshot that first holds the saved message.
5469
+ if (state.sending_preview?.saved_id && state.messages.some(message => message.id === state.sending_preview.saved_id)) {
5470
+ release_files(state.sending_preview.release || []);
5471
+ state.sending_preview = null;
5472
+ }
5473
+ // Likewise a queued message's row gives way in the first snapshot listing it in the queue: a room refresh started by
5474
+ // a live update can bring it before the site's answer to the send, and both rows showed until that answer came.
5475
+ const queueing = state.queueing_preview;
5476
+ if (queueing && state.room?.free?.queued_messages?.items?.some(item => !queueing.queued_ids.includes(item.id))) state.queueing_preview = null;
5428
5477
  document.dispatchEvent(new CustomEvent("discuss:view"));
5429
5478
  }
5430
5479