ai_co_discuss 0.4.20 → 0.4.22

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.
package/backend/server.py CHANGED
@@ -729,12 +729,15 @@ def list_rooms(connection, params=None):
729
729
  where = "WHERE EXISTS (SELECT 1 FROM room_creations WHERE room_id=rooms.id AND submission_id=?)" if identifier else ""
730
730
  rows = connection.execute(f"""SELECT rooms.*,
731
731
  COALESCE(stats.message_count,0) AS message_count,COALESCE(stats.latest_id,0) AS latest_id,
732
- (SELECT created_at FROM messages WHERE id=stats.latest_id) AS latest_at
732
+ (SELECT created_at FROM messages WHERE id=stats.latest_id) AS latest_at,
733
+ EXISTS (SELECT 1 FROM member_executions e WHERE e.room_id=rooms.id
734
+ AND e.status IN ('dispatched','started') AND e.lease_until>?) AS running
733
735
  FROM rooms LEFT JOIN room_message_stats stats ON stats.room_id=rooms.id {where}
734
- GROUP BY rooms.id ORDER BY rooms.created_at, rooms.id""", (identifier,) if identifier else ())
736
+ GROUP BY rooms.id ORDER BY rooms.created_at, rooms.id""", (int(time.time()), *((identifier,) if identifier else ())))
735
737
  directory = {row["room_id"]: dict(row) for row in connection.execute("SELECT * FROM room_directory")}
736
738
  assignments = {row["room_id"]: row["folder_id"] for row in connection.execute("SELECT room_id,folder_id FROM room_folder_assignments")}
737
- rooms = [{**dict(row), "archived": bool(directory[row["id"]]["archived"]), "folder_id": assignments[row["id"]]} for row in rows]
739
+ rooms = [{**dict(row), "archived": bool(directory[row["id"]]["archived"]), "running": bool(row["running"]),
740
+ "folder_id": assignments[row["id"]]} for row in rows]
738
741
  return {"rooms": sorted(rooms, key=lambda room: directory[room["id"]]["position"]),
739
742
  **folder_directory(connection)}
740
743
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai_co_discuss",
3
- "version": "0.4.20",
3
+ "version": "0.4.22",
4
4
  "bin": {
5
5
  "codiscuss": "runner/codiscuss.mjs"
6
6
  },
package/web/app.js CHANGED
@@ -1055,6 +1055,7 @@ async function select_room(room_id) {
1055
1055
  state.context_dirty = false;
1056
1056
  state.topic_dirty = false;
1057
1057
  state.pending_submission = null;
1058
+ state.sending_drafts = null;
1058
1059
  clear_attachment_drafts();
1059
1060
  state.launch.repair = null;
1060
1061
  state.launch.room_models = null;
@@ -1614,10 +1615,9 @@ async function invite_member({ name, access, project_access = "read", session_id
1614
1615
  /** Clear only the composer that produced the saved message. */
1615
1616
  async function finish_message(result, room_id, drafts) {
1616
1617
  show_toast(`留言已保存 · #${result.message.id}`);
1617
- if (state.room?.id !== room_id || state.attachment_drafts !== drafts) return;
1618
+ if (state.room?.id !== room_id || state.sending_drafts !== drafts) return;
1618
1619
  // The composer was emptied on send; what is in it now was typed since and stays.
1619
1620
  state.pending_submission = null;
1620
- clear_attachment_drafts();
1621
1621
  cancel_reply();
1622
1622
  state.query = "";
1623
1623
  state.mention_only = false;
@@ -1639,9 +1639,8 @@ async function finish_message(result, room_id, drafts) {
1639
1639
 
1640
1640
  /** A message the site queued: clear the composer; it waits above the composer until the room is idle. */
1641
1641
  async function finish_queued(result, room_id, drafts) {
1642
- if (state.room?.id !== room_id || state.attachment_drafts !== drafts) return;
1642
+ if (state.room?.id !== room_id || state.sending_drafts !== drafts) return;
1643
1643
  state.pending_submission = null;
1644
- clear_attachment_drafts();
1645
1644
  cancel_reply();
1646
1645
  state.sending_preview = null;
1647
1646
  if (state.room.free) state.room = { ...state.room, free: { ...state.room.free, queued_messages: result.queue } };
@@ -1685,6 +1684,20 @@ async function delete_queued(id) {
1685
1684
  await queue_request({ action: "delete", id });
1686
1685
  }
1687
1686
 
1687
+ /**
1688
+ * Send a queued message now. The row leaves the tray at once (QueuedMessages hides it) and the message shows as a
1689
+ * sending card until the refreshed transcript carries it; a refusal brings the row back with the reason.
1690
+ */
1691
+ async function send_queued(id) {
1692
+ const item = state.room?.free?.queued_messages?.items?.find(entry => entry.id === id);
1693
+ // A send from the composer already owns the sending card; this one then just waits in its row.
1694
+ const preview = item && !state.sending_preview
1695
+ ? { author: "用户", text: item.text, created_at: new Date().toISOString(), files: item.attachments.map(file => file.file_name) } : null;
1696
+ if (preview) { state.sending_preview = preview; publish_view(); }
1697
+ try { await queue_request({ action: "send", id }); }
1698
+ finally { if (preview && state.sending_preview === preview) { state.sending_preview = null; publish_view(); } }
1699
+ }
1700
+
1688
1701
  /**
1689
1702
  * The message being edited left the queue (sent or deleted elsewhere): stop editing so sending works again,
1690
1703
  * keeping the edited text in the composer as an ordinary draft.
@@ -1723,6 +1736,9 @@ async function send_message(event) {
1723
1736
  const draft = element("message-input").value;
1724
1737
  element("message-input").value = "";
1725
1738
  const preview = { author: payload.author, text: payload.text, created_at: new Date().toISOString(), files: drafts.map(file => file.file.name) };
1739
+ // The files leave with it and upload in the background; a failed send puts them back too.
1740
+ state.sending_drafts = drafts;
1741
+ state.attachment_drafts = [];
1726
1742
  // A message the site will likely queue skips the in-transcript card, which would flash before moving above the composer.
1727
1743
  const queue = state.room.free?.queued_messages;
1728
1744
  const likely_queued = payload.queue && (queue?.busy || queue?.items?.length);
@@ -1745,11 +1761,15 @@ async function send_message(event) {
1745
1761
  // Anything typed meanwhile follows the restored draft, so neither is lost.
1746
1762
  const typed = element("message-input").value;
1747
1763
  element("message-input").value = typed.trim() ? `${draft}\n\n${typed}` : draft;
1764
+ if (state.sending_drafts === drafts) state.attachment_drafts = [...drafts, ...state.attachment_drafts];
1748
1765
  error.notified = true;
1749
1766
  }
1750
1767
  throw error;
1751
1768
  } finally {
1752
1769
  state.sending_message = false;
1770
+ // Previews of files not put back into the composer are no longer shown anywhere.
1771
+ if (!state.attachment_drafts.includes(drafts[0])) for (const file of drafts) if (file.preview_url) URL.revokeObjectURL(file.preview_url);
1772
+ if (state.sending_drafts === drafts) state.sending_drafts = null;
1753
1773
  sent();
1754
1774
  if (!state.sending_preview?.failed) state.sending_preview = null;
1755
1775
  state.upload_status = "";
@@ -1802,7 +1822,7 @@ function attachment_file_icon(file_name) {
1802
1822
 
1803
1823
  /** Keep original files in memory until sending; reject an invalid selection as a whole. */
1804
1824
  function add_attachments(files) {
1805
- if (!state.room || state.sending_message) return;
1825
+ if (!state.room) return;
1806
1826
  const selected = Array.from(files);
1807
1827
  if (state.attachment_drafts.length + selected.length > MAX_MESSAGE_ATTACHMENTS) notify("warning", "每条消息最多 10 个附件");
1808
1828
  else if (selected.some(file => file.size > MAX_ATTACHMENT_BYTES)) notify("warning", "单个附件最多 20 MiB");
@@ -1821,7 +1841,6 @@ function clear_attachment_drafts() {
1821
1841
 
1822
1842
  /** Remove one unsent file without disturbing the text draft. */
1823
1843
  function remove_attachment(id) {
1824
- if (state.sending_message) return;
1825
1844
  const file = state.attachment_drafts.find(item => item.id === id);
1826
1845
  if (file?.preview_url) URL.revokeObjectURL(file.preview_url);
1827
1846
  state.attachment_drafts = state.attachment_drafts.filter(item => item.id !== id);
@@ -1835,9 +1854,8 @@ function render_attachment_drafts() {
1835
1854
  if (!container) return;
1836
1855
  container.innerHTML = state.attachment_drafts.map(item => `<div class="attachment-draft">${item.preview_url ? `<img src="${item.preview_url}" alt="">` : ""}
1837
1856
  <span>${escape_html(item.file.name)}<small>${attachment_size(item.file.size)}</small></span>
1838
- <button type="button" data-remove-attachment="${item.id}" aria-label="移除 ${escape_html(item.file.name)}" ${state.sending_message ? "disabled" : ""}>×</button></div>`).join("");
1857
+ <button type="button" data-remove-attachment="${item.id}" aria-label="移除 ${escape_html(item.file.name)}">×</button></div>`).join("");
1839
1858
  element("attachment-status").textContent = state.upload_status;
1840
- element("choose-attachments").disabled = state.sending_message;
1841
1859
  }
1842
1860
 
1843
1861
  /** Upload once per actual uploader, retaining receipts across ambiguous send failures. */
@@ -4946,8 +4964,7 @@ function view_snapshot() {
4946
4964
  archive_pending: [...state.archive_changes.keys()], import_progress: structuredClone(state.import_progress),
4947
4965
  directory_pending: [...state.directory_pending.keys()], folder_pending: [...state.folder_moves.keys()], creating_room: state.creating_room,
4948
4966
  connected: state.connected, reconnecting: state.reconnecting, observed_until: state.observed_until, backup_pending: Boolean(state.backup_pending), page: state.page, pages: state.pages, query: state.query,
4949
- attachment_drafts: state.attachment_drafts.map(item => ({ id: item.id, file_name: item.file.name, size: item.file.size, preview_url: item.preview_url,
4950
- uploading: state.sending_message && !item.uploaded })),
4967
+ attachment_drafts: state.attachment_drafts.map(item => ({ id: item.id, file_name: item.file.name, size: item.file.size, preview_url: item.preview_url })),
4951
4968
  upload_status: state.upload_status, sending_message: state.sending_message, sending_preview: state.sending_preview,
4952
4969
  mention_only: state.mention_only, host_only: state.host_only, authors: state.authors, card_kinds: state.card_kinds,
4953
4970
  source_filter: state.mention_only || state.host_only || state.authors.length > 0 || state.card_kinds.length > 0, messages_loading: Boolean(state.messages_loading), messages_failure: state.messages_failure || "", reply_to: state.reply_to, editing_queued: state.editing_queued?.id ?? null,
@@ -5195,7 +5212,7 @@ async function execute_view_action(name, value) {
5195
5212
  load_room_configuration, save_room_configuration, interrupt_member, retry_delivery, retract_message, retract_latest, stop_room, stop_host_checkin, rewind_and_send, fork_room, change_member, reorder_speakers, invite_member,
5196
5213
  enable_room_workflow, move_workflow_members, sync_room_workflow, set_room_host_workflows,
5197
5214
  adopt_recommendation, rate_decision,
5198
- queue_send: id => queue_request({ action: "send", id }), queue_delete: delete_queued,
5215
+ queue_send: send_queued, queue_delete: delete_queued,
5199
5216
  queue_reorder: ids => queue_request({ action: "reorder", ids }), queue_resume: () => queue_request({ action: "resume" }),
5200
5217
  queue_toggle: enabled => queue_request({ action: "queueing", enabled }), queue_edit: edit_queued, queue_cancel_edit: cancel_queued_edit,
5201
5218
  busy: () => { throw new Error("上一个操作仍在处理中,请稍候;长时间无响应请刷新页面"); },