ai_co_discuss 0.4.23 → 0.4.24
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/package.json +1 -1
- package/web/app.js +65 -6
- package/web/modern.css +1 -1
- package/web/modern.js +36 -36
package/package.json
CHANGED
package/web/app.js
CHANGED
|
@@ -10,6 +10,11 @@ const WORKING_STATUSES = ["dispatched", "started"];
|
|
|
10
10
|
const UPDATE_BATCH_MS = 100;
|
|
11
11
|
const UPDATE_DRAG_RETRY_MS = 500;
|
|
12
12
|
const TOAST_DURATION_MS = 3500;
|
|
13
|
+
// How long an archived room can be taken back before the archive is saved.
|
|
14
|
+
const ARCHIVE_UNDO_MS = 4000;
|
|
15
|
+
// Limits of the new-room form's title and discussion goal, applied when the welcome page fills them from a message.
|
|
16
|
+
const ROOM_TITLE_MAX_LENGTH = 80;
|
|
17
|
+
const ROOM_GOAL_MAX_LENGTH = 1000;
|
|
13
18
|
const SUBMISSION_ID_BYTES = 16;
|
|
14
19
|
const MAX_MESSAGE_LENGTH = 32000;
|
|
15
20
|
const MAX_SUMMARY_LENGTH = 1000;
|
|
@@ -544,9 +549,9 @@ function room_menu_html(room, index, count) {
|
|
|
544
549
|
function toggle_archives() { state.archive_view = !state.archive_view; render_rooms(); publish_view(); }
|
|
545
550
|
|
|
546
551
|
/** Dispatch directory changes without waiting for unrelated reads. */
|
|
547
|
-
async function manage_channel({ id, action, title, before_id, folder_id }) {
|
|
552
|
+
async function manage_channel({ id, action, title, before_id, folder_id, undo }) {
|
|
548
553
|
if (action === "folder") return assign_channel_folder(id, folder_id ?? null);
|
|
549
|
-
if (["archive", "restore"].includes(action)) return archive_channel(id, action === "archive");
|
|
554
|
+
if (["archive", "restore"].includes(action)) return archive_channel(id, action === "archive", { undo });
|
|
550
555
|
if (action === "rename") return rename_channel(id, title);
|
|
551
556
|
if (action === "move") return reorder_channel(id, before_id);
|
|
552
557
|
if (action === "delete") return delete_channel(id);
|
|
@@ -651,8 +656,19 @@ function display_channel_archive(id, change, expected) {
|
|
|
651
656
|
publish_view();
|
|
652
657
|
}
|
|
653
658
|
|
|
654
|
-
/**
|
|
655
|
-
|
|
659
|
+
/** Offer an undo notice for an archive shown but not yet saved; resolves false when the user takes it back. */
|
|
660
|
+
function archive_undo_window(id, title) {
|
|
661
|
+
return new Promise(resolve => {
|
|
662
|
+
let settled = false;
|
|
663
|
+
const settle = keep => { if (!settled) { settled = true; resolve(keep); } };
|
|
664
|
+
document.dispatchEvent(new CustomEvent("discuss:undo", { detail: { id: `archive:${id}`, message: `已存档「${title}」`,
|
|
665
|
+
duration: ARCHIVE_UNDO_MS, view: () => execute_view_action("room", id), settle } }));
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** Move a channel immediately and reconcile only its archive fields after saving. With undo, an archive waits out
|
|
670
|
+
* the undo notice before it is saved, since saving stops the room's work and restoring would not bring that back. */
|
|
671
|
+
async function archive_channel(id, archived, { undo = false } = {}) {
|
|
656
672
|
const room = state.room?.id === id ? state.room : state.rooms.find((item) => item.id === id);
|
|
657
673
|
if (!room || state.archive_changes.has(id) || Boolean(room.archived) === archived) return;
|
|
658
674
|
const previous = { archived: Boolean(room.archived), phase: room.phase };
|
|
@@ -660,6 +676,15 @@ async function archive_channel(id, archived) {
|
|
|
660
676
|
state.archive_changes.set(id, change);
|
|
661
677
|
state.archive_version++;
|
|
662
678
|
display_channel_archive(id, change);
|
|
679
|
+
if (archived && undo) {
|
|
680
|
+
if (state.room?.id === id) await open_welcome();
|
|
681
|
+
if (!await archive_undo_window(id, room.title)) {
|
|
682
|
+
display_channel_archive(id, previous, change);
|
|
683
|
+
state.archive_changes.delete(id);
|
|
684
|
+
state.archive_version++;
|
|
685
|
+
return publish_view();
|
|
686
|
+
}
|
|
687
|
+
}
|
|
663
688
|
try {
|
|
664
689
|
const saved = await request_json(`/api/rooms/${id}/${archived ? "archive" : "restore"}`, { actor: "用户" });
|
|
665
690
|
display_channel_archive(id, { archived: Boolean(saved.archived), phase: saved.phase }, change);
|
|
@@ -1003,7 +1028,7 @@ async function refresh_room({ room: read_room = true } = {}) {
|
|
|
1003
1028
|
if (directory.last_room !== undefined && !state.room) state.last_room = directory.last_room;
|
|
1004
1029
|
if (state.room && !state.rooms.some((item) => item.id === state.room.id)) return select_room(visible_rooms()[0]?.id);
|
|
1005
1030
|
if (!state.room || !read_room) {
|
|
1006
|
-
if (!state.room && visible_rooms().length) return select_room(opening_room());
|
|
1031
|
+
if (!state.room && !state.welcome && visible_rooms().length) return select_room(opening_room());
|
|
1007
1032
|
render_rooms();
|
|
1008
1033
|
set_connection(true);
|
|
1009
1034
|
return;
|
|
@@ -1038,6 +1063,7 @@ function remember_room(room_id) {
|
|
|
1038
1063
|
}
|
|
1039
1064
|
|
|
1040
1065
|
async function select_room(room_id) {
|
|
1066
|
+
if (room_id) state.welcome = false;
|
|
1041
1067
|
state.navigation_version++;
|
|
1042
1068
|
state.refresh_version++;
|
|
1043
1069
|
state.editing_queued = null;
|
|
@@ -2224,6 +2250,39 @@ async function submit_room(event, folder_id = null) {
|
|
|
2224
2250
|
if (state.navigation_version === navigation) { state.archive_view = false; await select_room(room.id); }
|
|
2225
2251
|
}
|
|
2226
2252
|
|
|
2253
|
+
/** Show the new-room welcome page in the middle, leaving no room selected until the user picks or creates one. */
|
|
2254
|
+
function open_welcome() {
|
|
2255
|
+
state.welcome = true;
|
|
2256
|
+
return select_room(null);
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
/** Whether a member woken through the local service, or the paired computer, can start right away. */
|
|
2260
|
+
function launch_ready(name) {
|
|
2261
|
+
if (!state.launch.available) return Boolean(state.launch.relay?.clients?.[platform_of(name)]);
|
|
2262
|
+
const profile = state.launch.profiles[name] || {};
|
|
2263
|
+
if (profile.adapter === "api") return Boolean(profile.base_url && profile.api_protocol && profile.api_key_ref && profile.model);
|
|
2264
|
+
return Boolean(profile.adapter && (profile.adapter === "antigravity" ? profile.ipc_directory : profile.executable));
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
/** Create a room from the welcome page's first message: the new-room panel's saved defaults, the first AI in its list
|
|
2268
|
+
* that can start as the only member and host, the message's first line as the title; then send the message there. */
|
|
2269
|
+
async function quick_create_room(text) {
|
|
2270
|
+
text = String(text || "").trim();
|
|
2271
|
+
if (!text) return;
|
|
2272
|
+
await reset_create_form(null);
|
|
2273
|
+
const name = Object.keys(IDENTITIES).find(item => item !== "用户" && LAUNCH_CLIENTS[item] && (default_launch_entry(item), launch_ready(item)));
|
|
2274
|
+
if (!name) throw new Error("还没有可直接唤醒的 AI:请先配置本机 AI 的接入");
|
|
2275
|
+
write_view_expert("new-expert-modes", name, "cli");
|
|
2276
|
+
write_view_field("new-room-host", name, { publish: false });
|
|
2277
|
+
write_view_field("new-room-title", text.split("\n")[0].slice(0, ROOM_TITLE_MAX_LENGTH), { publish: false });
|
|
2278
|
+
if (state.create_discussion) write_view_field("new-room-goal", text.slice(0, ROOM_GOAL_MAX_LENGTH), { publish: false });
|
|
2279
|
+
if (state.create_goal) state.create_goal = { ...state.create_goal, objective: text };
|
|
2280
|
+
await submit_room({ preventDefault() {} });
|
|
2281
|
+
if (!state.room || state.room.archived) return;
|
|
2282
|
+
element("message-input").value = text;
|
|
2283
|
+
await send_message({ preventDefault() {} });
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2227
2286
|
/** Open and start the discussion of a room just created; a failure leaves the room as an ordinary free room. */
|
|
2228
2287
|
async function open_discussion_after_creation(room_id, { goal, named_followup, limits }) {
|
|
2229
2288
|
const path = `/api/rooms/${room_id}`;
|
|
@@ -5203,7 +5262,7 @@ async function execute_view_action(name, value) {
|
|
|
5203
5262
|
const actions = { refresh: refresh_room, room: select_room, tab: select_tab,
|
|
5204
5263
|
archives: toggle_archives, backup: backup_room, backup_rooms, import_rooms, manage_channel, move_channel, create_folder, move_folder, rename_folder, delete_folder, sort_directory,
|
|
5205
5264
|
send: () => send_message(event), discard_sending: () => { state.sending_preview = null; }, choose_attachments: () => element("attachment-input").click(), remove_attachment, preview_attachment,
|
|
5206
|
-
create: (folder_id) => submit_room(event, folder_id),
|
|
5265
|
+
create: (folder_id) => submit_room(event, folder_id), quick_create: quick_create_room,
|
|
5207
5266
|
save_context: () => save_context(event), save_topic: () => save_topic(event),
|
|
5208
5267
|
filter: filter_view, reply: set_view_reply, cancel_reply, skip_turn,
|
|
5209
5268
|
copy_cli: () => copy_context(), copy_background,
|