ai_co_discuss 0.5.21 → 0.5.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/web/app.js CHANGED
@@ -727,6 +727,8 @@ const ROOM_CACHE_LIMIT = 12;
727
727
  const room_views = new Map();
728
728
  // Member settings read for a new room before it opens, used once by its first load_room_models.
729
729
  const preloaded_room_models = new Map();
730
+ const recent_room_models = new Map();
731
+ const ROOM_MODELS_FRESH_MS = 30000;
730
732
  // How long a new room's placeholder waits for the room's content before opening it anyway.
731
733
  const ROOM_PRELOAD_LIMIT_MS = 4000;
732
734
  const message_histories = new Map();
@@ -1900,12 +1902,18 @@ async function move_folder({ id, before_id, direction }) {
1900
1902
  } finally { state.folder_order_pending = false; publish_view(); }
1901
1903
  }
1902
1904
 
1905
+ function directory_parent(room, rooms) {
1906
+ const parent = rooms.find(item => item.id === room?.parent_room_id && !item.archived);
1907
+ return parent && (parent.folder_id || "") === (room.folder_id || "") ? parent.id : null;
1908
+ }
1909
+
1903
1910
  /** Move a channel by one visible slot, also available without drag support. */
1904
1911
  async function move_channel({ id, direction, folder_id }) {
1905
1912
  if (state.directory_sort === "recent") return;
1906
1913
  const rooms = visible_rooms();
1907
1914
  const folder_scoped = folder_id !== undefined;
1908
- const group = folder_scoped ? rooms.filter((room) => (room.folder_id || null) === folder_id) : rooms;
1915
+ const parent = directory_parent(rooms.find(room => room.id === id), rooms);
1916
+ const group = rooms.filter(room => (!folder_scoped || (room.folder_id || null) === folder_id) && directory_parent(room, rooms) === parent);
1909
1917
  const index = group.findIndex((room) => room.id === id);
1910
1918
  if (index < 0 || (direction < 0 ? index === 0 : index === group.length - 1)) return;
1911
1919
  const without_room = rooms.filter((room) => room.id !== id);
@@ -1977,6 +1985,7 @@ function render_host_brief() {
1977
1985
 
1978
1986
  /** Describe roles separately from authors and the actual submitter. */
1979
1987
  function message_provenance(message) {
1988
+ if (message.relay_room) return t('来自房间「{room}」的主持人 {host}', { room: message.relay_title ?? t('已删除的房间'), host: message.relay_host });
1980
1989
  const role = message.kind === "receipt" ? t('运行回执') : message.kind === "moderation" ? t('主持发言') : (message.author === "用户" ? t('用户发言') : t('专家观点'));
1981
1990
  const forwarding = message.submitted_by && message.submitted_by !== message.author ? t(' · {value1} 代发', { value1: display_name(message.submitted_by) }) : "";
1982
1991
  return `${role}${forwarding}`;
@@ -2139,6 +2148,12 @@ async function read_background_room(room_id, mark) {
2139
2148
  if (!history || !wanted()) return;
2140
2149
  cache_room_entry(room_views, room_id, room);
2141
2150
  background_reads.marks.set(room_id, mark);
2151
+ if (state.launch.available && !recent_room_models.has(room_id) && !preloaded_room_models.has(room_id)) {
2152
+ const models = await local_launch_request("room-models", { room_id, quick: true });
2153
+ if (wanted() && models.room_id === room_id) {
2154
+ cache_room_entry(recent_room_models, room_id, { ...room_models_fields(models), room_id, revision: "", loading: false });
2155
+ }
2156
+ }
2142
2157
  } catch (error) {
2143
2158
  // Nothing on screen depends on this read. A refused room waits for its next change; a network failure retries on the next directory read.
2144
2159
  if (error.preflight && wanted()) background_reads.marks.set(room_id, mark);
@@ -2355,6 +2370,11 @@ async function select_room(room_id) {
2355
2370
  const listed = state.rooms.find((room) => room.id === room_id);
2356
2371
  // A room opened before is shown as last read, with the directory's newer title, folder and archive state, until the site answers.
2357
2372
  const cached = listed && room_views.get(room_id);
2373
+ const leaving = state.launch.room_models;
2374
+ if (leaving?.participants && leaving.room_id === state.room?.id) {
2375
+ const incomplete = leaving.loading || Object.values(leaving.participants).some(profile => profile.defaults_pending);
2376
+ cache_room_entry(recent_room_models, leaving.room_id, { ...leaving, loading: false, revision: incomplete ? "" : leaving.revision });
2377
+ }
2358
2378
  state.room = cached ? { ...cached, ...listed } : listed;
2359
2379
  state.upload_status = "";
2360
2380
  state.sending_preview = null;
@@ -2370,7 +2390,10 @@ async function select_room(room_id) {
2370
2390
  for (const stashed of state.stashed_drafts) release_files(stashed.drafts);
2371
2391
  state.stashed_drafts = [];
2372
2392
  state.launch.repair = null;
2373
- state.launch.room_models = null;
2393
+ state.launch.room_models = listed && recent_room_models.get(room_id) || null;
2394
+ if (state.launch.room_models && Date.now() - (state.launch.room_models.read_at || 0) >= ROOM_MODELS_FRESH_MS) {
2395
+ state.launch.room_models.revision = "";
2396
+ }
2374
2397
  state.messages = [];
2375
2398
  state.message_history = null;
2376
2399
  state.history_cards = null;
@@ -3335,6 +3358,7 @@ async function finish_taking_queued(item, room_id, taken) {
3335
3358
  * read leaves the message queued.
3336
3359
  */
3337
3360
  async function edit_queued(item) {
3361
+ if (item.relay_room) return;
3338
3362
  const room_id = state.room.id;
3339
3363
  const files = item.attachments.length ? await read_queued_files(item, room_id) : [];
3340
3364
  if (state.room?.id !== room_id) return;
@@ -3977,7 +4001,9 @@ function attachment_markup(files = []) {
3977
4001
  const tag = file.content_type.startsWith("video/") ? "video" : "audio";
3978
4002
  // The Vue workspace registers the Video.js players (Chinese labels, speed, full screen); the classic page has none.
3979
4003
  const skinned = Boolean(customElements.get(`${tag}-player`));
3980
- const media = `<${tag} ${source} ${skinned ? "" : "controls "}preload="metadata" playsinline aria-label="${name}"></${tag}>`;
4004
+ // A transparent poster lets the themed surface show before the browser decodes the first frame.
4005
+ const poster = tag === "video" ? 'poster="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" ' : "";
4006
+ const media = `<${tag} ${source} ${poster}${skinned ? "" : "controls "}preload="metadata" playsinline aria-label="${name}"></${tag}>`;
3981
4007
  return `<div class="attachment-media attachment-${tag}">${skinned ? `<${tag}-player><${tag}-skin class="attachment-player">${media}</${tag}-skin></${tag}-player>` : media}
3982
4008
  <span class="attachment-media-failed">${escape_html(t("浏览器无法播放这个文件的格式,请点下面的文件名下载后用本机软件打开。"))}</span>
3983
4009
  <a class="attachment-media-name" ${download} download title="${escape_html(t("下载 {name}", { name: file.file_name }))}">${name}<small>${attachment_size(file.size)}</small></a></div>`;
@@ -5217,6 +5243,9 @@ async function show_computer_rooms(remote) {
5217
5243
  state.remote_rooms = Boolean(remote);
5218
5244
  // The two lists share no rooms, so nothing read from one may be shown for the other.
5219
5245
  room_views.clear();
5246
+ recent_room_models.clear();
5247
+ preloaded_room_models.clear();
5248
+ state.launch.room_models = null;
5220
5249
  message_histories.clear();
5221
5250
  history_cards.clear();
5222
5251
  reset_background_reads();
@@ -5413,6 +5442,8 @@ function discard_launch(id) {
5413
5442
  */
5414
5443
  async function load_launch_settings({ relay_known = () => {} } = {}) {
5415
5444
  const local = state.admin.local || ["127.0.0.1", "localhost"].includes(location.hostname);
5445
+ recent_room_models.clear();
5446
+ preloaded_room_models.clear();
5416
5447
  state.launch.room_models = null;
5417
5448
  state.launch.model_catalogs = {};
5418
5449
  state.launch.connect_command = local ? "codiscuss local open" : `codiscuss local connect "${location.origin}"`;
@@ -5550,8 +5581,15 @@ async function load_room_models(force = false) {
5550
5581
  // agy is run to name its default model, which takes seconds; everything else is shown first and agy follows.
5551
5582
  try {
5552
5583
  const result = preloaded || await local_launch_request("room-models", { room_id: room.id, quick: true });
5553
- if (live() && result.room_id === room.id) Object.assign(current, room_models_fields(result));
5554
5584
  if (live() && result.room_id === room.id) {
5585
+ for (const [name, profile] of Object.entries(result.participants || {})) {
5586
+ const prior = current.participants?.[name];
5587
+ if (profile.defaults_pending && prior?.adapter === profile.adapter && prior.default_model) {
5588
+ profile.default_model = prior.default_model;
5589
+ profile.default_effort = prior.default_effort;
5590
+ }
5591
+ }
5592
+ Object.assign(current, room_models_fields(result), { read_at: Date.now() });
5555
5593
  // Compared with the last answer for this room, which a reload clears from the state but not from here.
5556
5594
  if (members_seen?.room_id === room.id) warn_outside_members(members_seen.participants, result.participants);
5557
5595
  members_seen = { room_id: room.id, participants: result.participants };
@@ -5777,7 +5815,7 @@ function participant_model(name, room, saved, brief = false) {
5777
5815
  const profile = saved?.room_id === room.id ? saved.participants?.[name] : null;
5778
5816
  if (!profile) return "";
5779
5817
  // Only an agy member without a chosen model depends on the default that is read later.
5780
- if (!profile.model && !profile.actual_model && profile.defaults_pending) return t('读取中…');
5818
+ if (!profile.model && !profile.actual_model && !profile.default_model && profile.defaults_pending) return t('读取中…');
5781
5819
  // App members choose in their own chat, so only their session log knows.
5782
5820
  const app = ["codex", "antigravity"].includes(profile.adapter);
5783
5821
  // What the session last actually ran with comes first, so a member that says or is set to another model cannot mislead;
@@ -6926,7 +6964,7 @@ async function retract_latest() {
6926
6964
  try { await last.done; } catch { return; }
6927
6965
  if (state.room?.id !== room_id) return;
6928
6966
  }
6929
- const message = state.messages.findLast(item => item.author === "用户" && !item.withdrawn);
6967
+ const message = state.messages.findLast(item => item.author === "用户" && !item.relay_room && !item.withdrawn);
6930
6968
  if (message) await retract_message(message.id);
6931
6969
  }
6932
6970
 
@@ -7391,6 +7429,8 @@ function update_directory_drag(event) {
7391
7429
  if (state.directory_sort === "recent") return;
7392
7430
  const target = hit.closest("[data-drag-room]");
7393
7431
  if (!target || target.dataset.dragRoom === drag.id) return;
7432
+ const rooms = visible_rooms();
7433
+ if (directory_parent(rooms.find(room => room.id === drag.id), rooms) !== directory_parent(rooms.find(room => room.id === target.dataset.dragRoom), rooms)) return;
7394
7434
  const rect = target.getBoundingClientRect();
7395
7435
  const after = event.clientY > rect.top + rect.height / 2;
7396
7436
  drag.target = { action: "move", id: target.dataset.dragRoom, after };
@@ -7897,6 +7937,9 @@ function preview_clicked_attachment(event) {
7897
7937
  function watch_room_files() {
7898
7938
  document.addEventListener("click", download_relay_file, true);
7899
7939
  document.addEventListener("error", mark_failed_media, true);
7940
+ document.addEventListener("loadeddata", event => {
7941
+ if (event.target.matches?.(".attachment-video video")) event.target.removeAttribute("poster");
7942
+ }, true);
7900
7943
  new MutationObserver((records) => { if (files_by_blob()) show_relay_images(records); }).observe(document.body, { childList: true, subtree: true });
7901
7944
  }
7902
7945