ai_co_discuss 0.5.19 → 0.5.21
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/.agents/skills/discuss-participant/SKILL.md +2 -1
- package/.agents/skills/share-card/SKILL.md +15 -0
- package/.agents/skills/share-card/references/share-card.md +43 -0
- package/.agents/skills/workflow-creator/SKILL.md +3 -0
- package/backend/execution_diagnostics.py +149 -0
- package/backend/free_room.py +133 -40
- package/backend/message_queue.py +6 -4
- package/backend/room_trace.py +219 -0
- package/backend/schema.sql +7 -1
- package/backend/server.py +113 -8
- package/docs/en/guide/cli.md +20 -0
- package/docs/en/guide/faq.md +1 -0
- package/docs/en/guide/members.md +3 -1
- package/docs/en/guide/rooms.md +7 -3
- package/docs/en/guide/workflows.md +2 -0
- package/docs/en/guide/working.md +9 -4
- package/docs/guide/cli.md +20 -0
- package/docs/guide/faq.md +1 -0
- package/docs/guide/members.md +3 -1
- package/docs/guide/rooms.md +7 -3
- package/docs/guide/workflows.md +2 -0
- package/docs/guide/working.md +9 -4
- package/frontend/locales/en/app.json +8 -0
- package/frontend/locales/en/backend.json +5 -0
- package/frontend/locales/en/discussion.json +10 -3
- package/frontend/locales/en/execution-diagnostics.json +32 -0
- package/frontend/locales/en/room.json +1 -0
- package/frontend/locales/en/settings.json +5 -0
- package/package.json +3 -2
- package/runner/adapters/antigravity_cli.mjs +15 -1
- package/runner/adapters/api.mjs +27 -3
- package/runner/adapters/api_images.mjs +1 -1
- package/runner/adapters/api_pi.mjs +30 -1
- package/runner/adapters/cli.mjs +15 -6
- package/runner/adapters/codex_bridge.mjs +20 -6
- package/runner/adapters/codex_cli.mjs +2 -1
- package/runner/codiscuss.mjs +7 -0
- package/runner/discuss.py +24 -2
- package/runner/discussion_launch.mjs +1 -1
- package/runner/discussion_setup.mjs +1 -1
- package/runner/discussion_skills.mjs +1 -1
- package/runner/expert_prompts.mjs +4 -3
- package/runner/free_runner.mjs +102 -24
- package/runner/i18n_en.mjs +45 -2
- package/runner/remote_launch.mjs +2 -2
- package/runner/share_card.mjs +1314 -0
- package/runner/share_service.mjs +25 -7
- package/runner/share_shared.mjs +28 -7
- package/runner/site_deploy.mjs +125 -4
- package/runner/timeline_metrics.mjs +185 -0
- package/runner/workflows.mjs +38 -9
- package/web/app.js +303 -81
- package/web/i18n.js +3 -3
- package/web/modern.css +1 -1
- package/web/modern.js +98 -67
- package/workflows/decision-council/SKILL.md +2 -1
- package/workflows/decision-council/flow.json +15 -15
- package/workflows/story-serial/agents/writer.md +1 -1
- package/workflows/story-serial/flow.json +456 -123
- package/workflows/story-serial/workflows/aigc-reduce/flow.json +134 -13
- package/workflows/story-serial/workflows/character-play/flow.json +212 -25
- package/workflows/story-serial/workflows/jack-sparrow/flow.json +67 -23
- package/workflows/story-serial/workflows/luke-nichols/flow.json +67 -23
- package/workflows/story-serial/workflows/revise-episodes/flow.json +184 -23
- package/workflows/story-serial/workflows/tidy-docs/flow.json +256 -19
- package/workflows/tri-model-dev/SKILL.md +72 -0
- package/workflows/tri-model-dev/agents/advisor.md +22 -0
- package/workflows/tri-model-dev/agents/backend.md +25 -0
- package/workflows/tri-model-dev/agents/reviewer.md +38 -0
- package/workflows/tri-model-dev/flow.json +397 -0
- package/workflows/tri-model-dev/workflows/browser-verify/SKILL.md +22 -0
- package/workflows/tri-model-dev/workflows/browser-verify/agents/browser_ops.md +18 -0
- package/workflows/tri-model-dev/workflows/browser-verify/flow.json +136 -0
- package/workflows/trpg-classic/flow.json +17 -17
package/web/app.js
CHANGED
|
@@ -72,6 +72,13 @@ const SHARE_HOME_FOLDERS = [/(?<![\w./-])[A-Za-z]:[\\/]+Users[\\/]+[^\\/\s"'`<>|
|
|
|
72
72
|
const ABSOLUTE_PATH = /^(?:[A-Za-z]:[\\/]|\/)/;
|
|
73
73
|
// A folder named by fewer parts ("C:", "/home") is too broad to rewrite in text.
|
|
74
74
|
const SHARE_FOLDER_MIN_PARTS = 2;
|
|
75
|
+
/** Identify the receipt headings produced by answering, recommending or delegating a room question. */
|
|
76
|
+
function is_share_question_receipt(text) {
|
|
77
|
+
const heading = String(text || "").trimStart().split("\n", 1)[0].trimEnd();
|
|
78
|
+
return /^(?:回答问题\s*#?\d+|Answer to question #\d+)(?:[::]|$)/iu.test(heading)
|
|
79
|
+
|| /^(?:请主持人先讨论并给推荐|交给主持人决定)(问题 #\d+)$/u.test(heading)
|
|
80
|
+
|| /^(?:Host, please discuss and recommend first|Leaving it to the host to decide) \(question #\d+\)$/iu.test(heading);
|
|
81
|
+
}
|
|
75
82
|
// Attachments whose text is scanned for keys and folders before sharing: plain text up to this size, not packed office files.
|
|
76
83
|
const TEXT_ATTACHMENT = /\.(md|markdown|txt|log|csv|tsv|json|jsonc|ya?ml|toml|ini|xml|html?|css|vue|[cm]?js|jsx|tsx?|py|sql|sh|ps1|bat|srt|vtt|ass|ssa|lrc|fcpxml|kdenlive|mlt|otio|edl|docx|xlsx|xls|ods|pptx|prproj|zip)$/i;
|
|
77
84
|
const SHARE_SCAN_BYTES = 2 * 1024 * 1024;
|
|
@@ -358,20 +365,34 @@ function create_share_core({ t, display_name, collapse_visual_fences, is_text_at
|
|
|
358
365
|
return String(text || "").replace(/```[\s\S]*?```/g, " ").replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[`*_>#|~-]+/g, " ").replace(/\s+/g, " ").trim();
|
|
359
366
|
}
|
|
360
367
|
|
|
368
|
+
function share_card_messages(responses) {
|
|
369
|
+
return Object.entries(responses).filter(([path]) => /\/messages\?/.test(path)).flatMap(([, body]) => body.messages || [])
|
|
370
|
+
.filter(message => message.kind !== "system" && message.text).sort((a, b) => a.id - b.id);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function share_card_materials_info(responses) {
|
|
374
|
+
const messages = share_card_messages(responses);
|
|
375
|
+
return { through: messages.at(-1)?.id ?? null, count: messages.length };
|
|
376
|
+
}
|
|
377
|
+
|
|
361
378
|
/** What the share card shows of a prepared page: members, the first question, the latest outcome and the counts. */
|
|
362
379
|
function share_card(draft, link) {
|
|
363
380
|
const room = draft.responses[`/api/rooms/${draft.room_id}`] || {};
|
|
364
381
|
const members = (room.members || []).filter(member => member.status !== "removed").map(member => member.label || display_name(member.name));
|
|
365
|
-
const messages =
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
const answers = messages.filter(message => message.author !== "用户" && message.id > (question?.id ?? 0));
|
|
382
|
+
const messages = share_card_messages(draft.responses);
|
|
383
|
+
const question = messages.find(message => message.author === "用户" && !is_share_question_receipt(message.text)
|
|
384
|
+
&& !/^\/?(?:继续|好的?|同意|continue|ok)[。.!!\s]*$/iu.test(message.text.trim()));
|
|
385
|
+
const answers = messages.filter(message => message.author !== "用户" && message.author !== "系统" && message.id > (question?.id ?? 0));
|
|
370
386
|
const outcome = answers.findLast(message => message.summary) || answers.at(-1);
|
|
371
387
|
// Text the owner was asked to check stays off the card, which cannot be taken back once posted; it can be typed in.
|
|
372
388
|
const flagged = new Set((draft.spots || []).map(spot => spot.where));
|
|
373
389
|
const text = (message, value) => message && !flagged.has(`#${message.id}`) ? share_plain(value) : "";
|
|
374
|
-
|
|
390
|
+
const result = text(outcome, outcome?.summary || outcome?.text);
|
|
391
|
+
const sentences = result.match(/[^。!?.!?]+(?:[。!?]|[.!?](?=\s|$)|$)/gu) || [];
|
|
392
|
+
const complete = sentences[0]?.trim();
|
|
393
|
+
return { title: draft.title, members, materials: { through: messages.at(-1)?.id ?? null, count: messages.length },
|
|
394
|
+
question: text(question, question?.text).slice(0, 600),
|
|
395
|
+
outcome: (complete && result.startsWith(complete) ? complete : result).slice(0, 600),
|
|
375
396
|
stats: t('{members} 位 AI · {messages} 条消息 · {runs} 次执行', { members: members.length, messages: room.message_count ?? messages.length, runs: draft.runs ?? 0 }),
|
|
376
397
|
url: link.url, expires: t('{time} 前有效', { time: new Date(link.expires_at).toLocaleString(undefined, { hour12: false }) }) };
|
|
377
398
|
}
|
|
@@ -451,10 +472,10 @@ function create_share_core({ t, display_name, collapse_visual_fences, is_text_at
|
|
|
451
472
|
const extra = scanned.filter(item => item.texts), unread = scanned.filter(item => !item.texts);
|
|
452
473
|
return [...share_sensitive_spots({}, extra), ...unread];
|
|
453
474
|
}
|
|
454
|
-
return { share_path, share_clean, share_parallel, share_batch, share_strings, share_sensitive_spots, share_files, share_file_route, share_site_file, share_carried_files, share_file_kind, share_file_kinds, share_responses, share_named_paths, share_folder_pattern, share_payload, share_plain, share_card, share_collect_reads, share_find_delivered, share_scan_files };
|
|
475
|
+
return { share_path, share_clean, share_parallel, share_batch, share_strings, share_sensitive_spots, share_files, share_file_route, share_site_file, share_carried_files, share_file_kind, share_file_kinds, share_responses, share_named_paths, share_folder_pattern, share_payload, share_plain, share_card, share_card_materials_info, share_collect_reads, share_find_delivered, share_scan_files };
|
|
455
476
|
}
|
|
456
477
|
// END generated share core
|
|
457
|
-
var { share_path, share_clean, share_parallel, share_batch, share_strings, share_sensitive_spots, share_files, share_file_route, share_site_file, share_carried_files, share_file_kind, share_file_kinds, share_responses, share_named_paths, share_folder_pattern, share_payload, share_plain, share_card, share_collect_reads, share_find_delivered, share_scan_files } = create_share_core({ t, display_name: name => display_name(name),
|
|
478
|
+
var { share_path, share_clean, share_parallel, share_batch, share_strings, share_sensitive_spots, share_files, share_file_route, share_site_file, share_carried_files, share_file_kind, share_file_kinds, share_responses, share_named_paths, share_folder_pattern, share_payload, share_plain, share_card, share_card_materials_info, share_collect_reads, share_find_delivered, share_scan_files } = create_share_core({ t, display_name: name => display_name(name),
|
|
458
479
|
collapse_visual_fences: (text, label) => window.discuss_markdown.collapse_visual_fences(text, label), is_text_attachment: file => is_text_attachment(file) });
|
|
459
480
|
// Where an earlier version kept a room's published link in this browser; it moves to the room when first read.
|
|
460
481
|
const SHARE_LINK_PREFIX = "codiscuss-share:";
|
|
@@ -746,9 +767,10 @@ function announce_idle_rooms(rooms) {
|
|
|
746
767
|
/** Cards of a later transcript batch replace the same ones read before; each kind is keyed by its id. */
|
|
747
768
|
function merge_history_cards(base, batch) {
|
|
748
769
|
const merged = {};
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
770
|
+
const key_of = (item) => item.key || item.id || item.message_id;
|
|
771
|
+
for (const kind of ["executions", "scheduler_decisions", "host_arrangements", "cancelled_turns", "failure_wakes", "quiet_checkins"]) {
|
|
772
|
+
const items = new Map((base?.[kind] || []).map((item) => [key_of(item), item]));
|
|
773
|
+
for (const item of batch?.[kind] || []) items.set(key_of(item), item);
|
|
752
774
|
merged[kind] = [...items.values()];
|
|
753
775
|
}
|
|
754
776
|
return merged;
|
|
@@ -1359,7 +1381,7 @@ async function delete_channel(id) {
|
|
|
1359
1381
|
state.destroying.set(id, entry);
|
|
1360
1382
|
const dissolving = dissolve_room(id);
|
|
1361
1383
|
try {
|
|
1362
|
-
if (share_link(id)) await take_down_share(id);
|
|
1384
|
+
if (share_changes.has(id) || share_link(id)) await queue_share_change(id, null, () => take_down_share(id));
|
|
1363
1385
|
const result = await request_json(`/api/rooms/${id}/delete`, { actor: "用户" });
|
|
1364
1386
|
if (result.destruction) merge_destruction(result.destruction);
|
|
1365
1387
|
// A cleanup that takes long says where to follow it, once.
|
|
@@ -2159,6 +2181,7 @@ async function refresh_room_content(room_id, version, versions) {
|
|
|
2159
2181
|
cache_room_entry(room_views, room_id, room);
|
|
2160
2182
|
for (const item of confirmed_members) {
|
|
2161
2183
|
const still_present = ["remove", "revoke"].includes(item.action) && room.members?.some(member => member.id === item.member_id);
|
|
2184
|
+
item.debug?.(still_present ? "overlay-retained" : "snapshot-confirmed");
|
|
2162
2185
|
if (!still_present) member_changes.delete(item);
|
|
2163
2186
|
}
|
|
2164
2187
|
state.room = merge_room_folder(room, versions.folder, versions.archive, versions.directory);
|
|
@@ -2221,6 +2244,7 @@ async function refresh_room({ room: read_room = true } = {}) {
|
|
|
2221
2244
|
const directory_version = state.directory_version;
|
|
2222
2245
|
const room_id = state.room?.id;
|
|
2223
2246
|
// The room and its transcript are read beside the directory rather than after it, saving a round trip on every open.
|
|
2247
|
+
const links_at_read = new Map(saved_share_links);
|
|
2224
2248
|
const directory_read = request_json("/api/rooms");
|
|
2225
2249
|
// A room being destroyed is gone from the website; its open conversation stays as it was until it dissolves.
|
|
2226
2250
|
const reading = state.room && read_room && !state.destroying.has(room_id) ? room_id : null;
|
|
@@ -2235,6 +2259,7 @@ async function refresh_room({ room: read_room = true } = {}) {
|
|
|
2235
2259
|
if (!state.directory_pending.size && directory_version === state.directory_version) {
|
|
2236
2260
|
const previous = state.rooms;
|
|
2237
2261
|
state.rooms = with_destroying(directory.rooms.map((room) => merge_room_folder(room, folder_version, archive_version, directory_version)));
|
|
2262
|
+
confirm_share_directory(directory.rooms, links_at_read);
|
|
2238
2263
|
if (directory.destructions) announce_auto_destroyed(previous, state.rooms, directory.destructions);
|
|
2239
2264
|
set_folder_directory(directory);
|
|
2240
2265
|
}
|
|
@@ -2986,7 +3011,9 @@ async function change_member(input) {
|
|
|
2986
3011
|
const active = [...member_changes].filter(item => item.room_id === room_id && !item.done);
|
|
2987
3012
|
for (const item of active) item.overlapped = true;
|
|
2988
3013
|
const change = { ...input, room_id, previous_host_name, access, overlapped: active.length > 0 };
|
|
3014
|
+
change.debug = browser_debug("member-change", { room: room_id, member: input.member_id, action: input.action });
|
|
2989
3015
|
member_changes.add(change);
|
|
3016
|
+
change.debug?.("optimistic", { queuedBehind: previous.length });
|
|
2990
3017
|
publish_view();
|
|
2991
3018
|
change.write = (async () => {
|
|
2992
3019
|
if (previous.length) await Promise.allSettled(previous.map(item => item.write));
|
|
@@ -2994,6 +3021,7 @@ async function change_member(input) {
|
|
|
2994
3021
|
const free = result?.free || result;
|
|
2995
3022
|
change.member = free?.members?.find(member => member.id === input.member_id);
|
|
2996
3023
|
change.done = true;
|
|
3024
|
+
change.debug?.("receipt", { overlapping: change.overlapped, returnedMember: Boolean(change.member) });
|
|
2997
3025
|
// Only apply this member's acknowledgement. Another member may already have a newer response.
|
|
2998
3026
|
if (state.room?.id === room_id && free?.members && state.room.free && !change.overlapped) {
|
|
2999
3027
|
state.room = { ...state.room, free };
|
|
@@ -3007,7 +3035,7 @@ async function change_member(input) {
|
|
|
3007
3035
|
}
|
|
3008
3036
|
})();
|
|
3009
3037
|
try { await change.write; }
|
|
3010
|
-
catch (error) { member_changes.delete(change); throw error; }
|
|
3038
|
+
catch (error) { member_changes.delete(change); change.debug?.("rollback", { status: error.status }); throw error; }
|
|
3011
3039
|
finally { publish_view(); }
|
|
3012
3040
|
}
|
|
3013
3041
|
|
|
@@ -3190,18 +3218,26 @@ async function finish_queued(result, room_id) {
|
|
|
3190
3218
|
}
|
|
3191
3219
|
|
|
3192
3220
|
/** Act on the room's queued owner messages; the site posts what may go and returns the queue. */
|
|
3193
|
-
async function queue_request(payload) {
|
|
3221
|
+
async function queue_request(payload, on_queue = null) {
|
|
3194
3222
|
const room_id = state.room.id;
|
|
3223
|
+
const debug = browser_debug("queue-change", { room: room_id, action: payload.action, item: payload.id, order: payload.ids });
|
|
3224
|
+
debug?.("submitted");
|
|
3195
3225
|
let queue;
|
|
3196
3226
|
try { queue = await request_json(`/api/rooms/${room_id}/queue`, payload); }
|
|
3197
3227
|
catch (error) {
|
|
3228
|
+
debug?.("rejected", { status: error.status });
|
|
3198
3229
|
// A refused action usually means the queue moved on (a message went out meanwhile); show what is queued now.
|
|
3199
3230
|
if (state.room?.id === room_id) await refresh_room().catch(() => {});
|
|
3200
3231
|
throw error;
|
|
3201
3232
|
}
|
|
3233
|
+
debug?.("receipt", { order: queue?.items?.map(item => item.id), message: queue?.message_id });
|
|
3234
|
+
on_queue?.(queue);
|
|
3202
3235
|
if (state.room?.id === room_id && state.room.free) state.room = { ...state.room, free: { ...state.room.free, queued_messages: queue } };
|
|
3203
3236
|
publish_view();
|
|
3204
|
-
if (state.room?.id === room_id)
|
|
3237
|
+
if (state.room?.id === room_id) {
|
|
3238
|
+
await refresh_room();
|
|
3239
|
+
if (state.room?.id === room_id) debug?.("refreshed", { order: state.room.free?.queued_messages?.items?.map(item => item.id) });
|
|
3240
|
+
}
|
|
3205
3241
|
}
|
|
3206
3242
|
|
|
3207
3243
|
/** Answer or cancel one question (`operation`: answer | cancel) with the version the card shows; the room refreshes either way. */
|
|
@@ -3333,10 +3369,12 @@ async function delete_queued(id) {
|
|
|
3333
3369
|
*/
|
|
3334
3370
|
async function send_queued(id) {
|
|
3335
3371
|
const item = state.room?.free?.queued_messages?.items?.find(entry => entry.id === id);
|
|
3336
|
-
const
|
|
3337
|
-
|
|
3372
|
+
const visible = item?.message_id && state.messages.some(message => message.id === item.message_id);
|
|
3373
|
+
const preview = item && !visible && !state.sending_preview
|
|
3374
|
+
? { author: "用户", text: item.text, created_at: new Date().toISOString(), saved_id: item.message_id || null,
|
|
3375
|
+
files: item.attachments.map(file => ({ name: file.file_name })) } : null;
|
|
3338
3376
|
if (preview) { state.sending_preview = preview; publish_view(); }
|
|
3339
|
-
try { await queue_request({ action: "send", id }); }
|
|
3377
|
+
try { await queue_request({ action: "send", id }, (queue) => { if (preview && queue?.message_id) preview.saved_id = queue.message_id; }); }
|
|
3340
3378
|
finally { if (preview && state.sending_preview === preview) { state.sending_preview = null; publish_view(); } }
|
|
3341
3379
|
}
|
|
3342
3380
|
|
|
@@ -3386,7 +3424,9 @@ function room_sending_previews() {
|
|
|
3386
3424
|
const cards = send_queue.filter(job => job.room_id === state.room?.id && !job.saved_message && !job.queueing && !job.queued && !job.preview.failed
|
|
3387
3425
|
&& !(job.preview.saved_id && state.messages.some(message => message.id === job.preview.saved_id)))
|
|
3388
3426
|
.map(job => job.preview);
|
|
3389
|
-
if (state.sending_preview
|
|
3427
|
+
if (state.sending_preview && !(state.sending_preview.saved_id && state.messages.some(message => message.id === state.sending_preview.saved_id))) {
|
|
3428
|
+
cards.push(state.sending_preview);
|
|
3429
|
+
}
|
|
3390
3430
|
return cards;
|
|
3391
3431
|
}
|
|
3392
3432
|
|
|
@@ -3433,6 +3473,8 @@ function enqueue_send(job) {
|
|
|
3433
3473
|
job.queueing = predicted_queue(job.payload, state.room.free?.queued_messages);
|
|
3434
3474
|
job.preview = { ...job.preview, waiting: true };
|
|
3435
3475
|
send_queue.push(job);
|
|
3476
|
+
job.debug = browser_debug("send", { room: job.room_id, send: job.id });
|
|
3477
|
+
job.debug?.("optimistic", { display: job.queueing ? "queue" : "transcript" });
|
|
3436
3478
|
job.done = previous.then(() => deliver_send(job)).finally(() => {
|
|
3437
3479
|
job.finish_submission();
|
|
3438
3480
|
send_queue.splice(send_queue.indexOf(job), 1);
|
|
@@ -3475,6 +3517,7 @@ async function deliver_send(job) {
|
|
|
3475
3517
|
}
|
|
3476
3518
|
}
|
|
3477
3519
|
saved = true;
|
|
3520
|
+
job.debug?.("receipt", { message: result.message?.id ?? result.message_id, queued: Boolean(result.queued) });
|
|
3478
3521
|
job.finish_submission();
|
|
3479
3522
|
// The sender's room rises as soon as the message is saved, without waiting for the next directory read.
|
|
3480
3523
|
if (result.message?.created_at) patch_directory_room(room_id, { latest_speech_at: result.message.created_at });
|
|
@@ -3484,6 +3527,7 @@ async function deliver_send(job) {
|
|
|
3484
3527
|
}
|
|
3485
3528
|
else await finish_message(result, job);
|
|
3486
3529
|
} catch (error) {
|
|
3530
|
+
job.debug?.(saved ? "refresh-failed" : "rejected", { status: error.status, unconfirmed: Boolean(error.unconfirmed) });
|
|
3487
3531
|
if (saved) notify_failure(error, t('留言已保存,但页面刷新失败:{value1}', { value1: error.message }));
|
|
3488
3532
|
else {
|
|
3489
3533
|
job.preview = { ...job.preview, failed: error.message };
|
|
@@ -4259,6 +4303,12 @@ async function submit_room(event, folder_id = null, { accepted = null, rejected
|
|
|
4259
4303
|
const launching = Object.values(payload.experts).includes("cli") || (launchable && Boolean(creation_launch_options().scheduler || state.launch.workspace.cwd || state.launch.workspace.local_project));
|
|
4260
4304
|
if (launching && !launchable) throw new Error(t('本机唤醒的成员需要连接本机服务;也可改为手动接入'));
|
|
4261
4305
|
const launch_draft = launching ? creation_launch_options() : null;
|
|
4306
|
+
const max_rounds = state.create_chain_rounds;
|
|
4307
|
+
const launch_summary = launch_draft && { scheduler: Boolean(launch_draft.scheduler), image_generation: launch_draft.image_generation,
|
|
4308
|
+
host_workflows: launch_draft.host_workflows, host_permissions: launch_draft.host_permissions,
|
|
4309
|
+
api_max_requests: launch_draft.api_max_requests ?? DEFAULT_API_MAX_REQUESTS,
|
|
4310
|
+
participants: Object.fromEntries(Object.entries(payload.experts).filter(([, mode]) => mode === "cli")
|
|
4311
|
+
.map(([name]) => [name, { adapter: launch_draft.participants[name]?.adapter }])) };
|
|
4262
4312
|
// A discussion is only a way to push the room forward: the room is created as a free room, then opened with these limits.
|
|
4263
4313
|
const discussion = state.create_discussion ? { goal: payload.goal.trim(), named_followup: state.named_followup,
|
|
4264
4314
|
limits: read_limits("new-room") } : null;
|
|
@@ -4290,14 +4340,14 @@ async function submit_room(event, folder_id = null, { accepted = null, rejected
|
|
|
4290
4340
|
try {
|
|
4291
4341
|
room = await update_directory({ key: "create-room", label: t('「{value1}」创建', { value1: payload.title }),
|
|
4292
4342
|
error_message: launching ? error => `「${payload.title}」${error.message}` : null,
|
|
4293
|
-
apply: () => { state.creating_room = { ...payload, opened: Boolean(accepted), submission_id: pending.id }; },
|
|
4343
|
+
apply: () => { state.creating_room = { ...payload, launch_summary, free: { max_rounds }, opened: Boolean(accepted), submission_id: pending.id }; },
|
|
4294
4344
|
rollback: () => {
|
|
4295
4345
|
state.creating_room = null;
|
|
4296
4346
|
// Someone who moved on to another room stays there.
|
|
4297
4347
|
if (accepted && !state.room && previous_room) run_action(() => select_room(previous_room));
|
|
4298
4348
|
},
|
|
4299
4349
|
save: async () => {
|
|
4300
|
-
const created = (await submit_local_launch(input, payload.title, !launching, signature)).room;
|
|
4350
|
+
const created = (await submit_local_launch(input, payload.title, !launching, signature, max_rounds)).room;
|
|
4301
4351
|
// Only a placeholder still on screen waits: someone who moved on to another room is not opened into this one.
|
|
4302
4352
|
return accepted && !state.room ? { ...created, ...await preload_room(created.id) } : created;
|
|
4303
4353
|
},
|
|
@@ -5286,7 +5336,7 @@ function refresh_launch_recoveries() {
|
|
|
5286
5336
|
}
|
|
5287
5337
|
|
|
5288
5338
|
/** Persist the complete submitted input before any request can create or start a room. */
|
|
5289
|
-
async function submit_local_launch(input, title, direct = false, signature) {
|
|
5339
|
+
async function submit_local_launch(input, title, direct = false, signature, max_rounds = state.create_chain_rounds) {
|
|
5290
5340
|
const id = input.room?.submission_id || `room-${input.room_id}`;
|
|
5291
5341
|
const key = LAUNCH_PENDING_PREFIX + id;
|
|
5292
5342
|
const previous = localStorage.getItem(key);
|
|
@@ -5307,7 +5357,7 @@ async function submit_local_launch(input, title, direct = false, signature) {
|
|
|
5307
5357
|
await send_descriptions(result.room?.id, record.input.token, Object.fromEntries(names.map(name => [name, description_draft(name)])));
|
|
5308
5358
|
await send_labels(result.room?.id, record.input.token, Object.fromEntries(names.map(name => [name, label_drafts[name]])));
|
|
5309
5359
|
for (const name of names) { delete description_drafts[name]; delete label_drafts[name]; }
|
|
5310
|
-
await send_chain_rounds(result.room?.id, record.input.token,
|
|
5360
|
+
await send_chain_rounds(result.room?.id, record.input.token, max_rounds);
|
|
5311
5361
|
return result;
|
|
5312
5362
|
} catch (error) {
|
|
5313
5363
|
const stage = error.launch?.stage || (record.direct && error.preflight ? "not_started" : undefined);
|
|
@@ -7698,6 +7748,16 @@ function publish_view() {
|
|
|
7698
7748
|
document.dispatchEvent(new CustomEvent("discuss:view"));
|
|
7699
7749
|
}
|
|
7700
7750
|
|
|
7751
|
+
/** Start a browser-only diagnostic sequence. Callers provide only IDs, flags and protocol status. */
|
|
7752
|
+
function browser_debug(event, data) {
|
|
7753
|
+
if (!document.getElementById?.("scrolldebug")) return null;
|
|
7754
|
+
const operation = ++browser_debug_operation;
|
|
7755
|
+
return (phase, details) => document.dispatchEvent(new CustomEvent("discuss:browser-debug", {
|
|
7756
|
+
detail: { event, data: { ...data, operation, phase, ...details } },
|
|
7757
|
+
}));
|
|
7758
|
+
}
|
|
7759
|
+
let browser_debug_operation = 0;
|
|
7760
|
+
|
|
7701
7761
|
/** Read current form drafts without transferring ownership to either renderer. */
|
|
7702
7762
|
function view_snapshot() {
|
|
7703
7763
|
// Searched inside their containers: a whole-document selector walks every transcript node on each publish.
|
|
@@ -7723,15 +7783,16 @@ function view_snapshot() {
|
|
|
7723
7783
|
device: { id: state.device.id, needs: state.device.needs, pairing_code: state.device.pairing_code,
|
|
7724
7784
|
prompt: state.device.prompt ? { title: state.device.prompt.title, description: state.device.prompt.description, confirm_label: state.device.prompt.confirm_label } : null },
|
|
7725
7785
|
share: SHARE ? { exported_at: SHARE.exported_at, home: SHARE_HOME } : null,
|
|
7726
|
-
managed_share_jobs:
|
|
7786
|
+
managed_share_jobs: shown_share_jobs().sort((a,b) => b.created_at.localeCompare(a.created_at)),
|
|
7727
7787
|
share_tasks: Object.fromEntries([...share_tasks].filter(([, draft]) => !draft.managed_id).map(([id, draft]) => [id, { phase: draft.phase, upload: draft.upload ? { ...draft.upload } : null }])),
|
|
7728
7788
|
share_draft: share_draft ? { room_id: share_draft.room_id, title: share_draft.title, phase: share_draft.phase || "ready",
|
|
7789
|
+
materials: share_draft.materials, publication: share_draft.publication,
|
|
7729
7790
|
spots: [...share_draft.spots || [], ...share_draft.include_files ? share_draft.file_spots || [] : []],
|
|
7730
7791
|
files: { count: share_draft.files?.length || 0, bytes: (share_draft.files || []).reduce((total, file) => total + file.size, 0), included: Boolean(share_draft.include_files),
|
|
7731
7792
|
kinds: share_draft.files ? share_file_kinds(share_draft) : [], carried: share_carried_files(share_draft, false).reduce((total, file) => total + file.size, 0),
|
|
7732
7793
|
carried_count: share_carried_files(share_draft, false).length,
|
|
7733
7794
|
site_left_out: (share_draft.files || []).filter(file => !file.site_type).map(file => file.file_name) },
|
|
7734
|
-
days: share_draft.days || SHARE_DEFAULT_DAYS, linked: Boolean(share_draft.linked || share_link(share_draft.room_id)), link: share_draft.link || null, upload: share_draft.upload ? { ...share_draft.upload } : null } : null,
|
|
7795
|
+
days: share_draft.days || SHARE_DEFAULT_DAYS, linked: Boolean(share_draft.linked || share_link(share_draft.room_id)), link: share_draft.link || null, cover_images: share_draft.cover_images || [], upload: share_draft.upload ? { ...share_draft.upload } : null } : null,
|
|
7735
7796
|
share_links: SHARE ? {} : share_links(), share_days: SHARE_DAYS,
|
|
7736
7797
|
tab: state.tab, snapshot_id: state.snapshot_id, context_dirty: state.context_dirty,
|
|
7737
7798
|
theme: document.documentElement.dataset.theme, fields, experts, launch: shown_launch(), named_followup: state.named_followup, create_discussion: state.create_discussion, create_goal: state.create_goal, create_chain_rounds: state.create_chain_rounds, create_host_workflows: state.create_host_workflows, create_host_permissions: state.create_host_permissions, create_api_max_requests: state.create_api_max_requests, create_auto_destroy: state.create_auto_destroy || 0, create_relay_rounds: state.create_relay_rounds ?? 0, create_image_generation: state.create_image_generation };
|
|
@@ -8076,6 +8137,18 @@ async function share_include_files(include) {
|
|
|
8076
8137
|
const share_tasks = new Map();
|
|
8077
8138
|
let share_draft = null;
|
|
8078
8139
|
const managed_share_jobs = new Map();
|
|
8140
|
+
const share_job_changes = new Map();
|
|
8141
|
+
const dismissed_share_jobs = new Set();
|
|
8142
|
+
|
|
8143
|
+
/** Show the latest requested state of each job while its writes finish in order. */
|
|
8144
|
+
function shown_share_jobs() {
|
|
8145
|
+
const jobs = new Map(managed_share_jobs);
|
|
8146
|
+
for (const [id, change] of share_job_changes) {
|
|
8147
|
+
if (change.job) jobs.set(id, change.job);
|
|
8148
|
+
else jobs.delete(id);
|
|
8149
|
+
}
|
|
8150
|
+
return [...jobs.values()];
|
|
8151
|
+
}
|
|
8079
8152
|
let share_job_timer, share_job_read, selection_write = Promise.resolve();
|
|
8080
8153
|
function can_manage_shares() {
|
|
8081
8154
|
return !SHARE && Boolean(state.launch.available || state.remote_rooms || relay_machine || state.admin?.local);
|
|
@@ -8086,14 +8159,14 @@ function share_job_request(op, job, fields = {}) {
|
|
|
8086
8159
|
}
|
|
8087
8160
|
function schedule_share_jobs() {
|
|
8088
8161
|
clearTimeout(share_job_timer);
|
|
8089
|
-
if (!document.hidden &&
|
|
8162
|
+
if (!document.hidden && shown_share_jobs().some(job => ["preparing","publishing"].includes(job.phase)))
|
|
8090
8163
|
share_job_timer = setTimeout(share_job_refresh, 1500);
|
|
8091
8164
|
}
|
|
8092
8165
|
function remember_share_job(job, announce) {
|
|
8093
8166
|
const prior = managed_share_jobs.get(job.id);
|
|
8094
8167
|
if (prior && prior.updated_at > job.updated_at) return;
|
|
8095
8168
|
managed_share_jobs.set(job.id, job);
|
|
8096
|
-
if (job.result && job.phase === "published") show_share_link(job.room_id, job.result);
|
|
8169
|
+
if (job.result && job.phase === "published" && prior && prior.phase !== "published") show_share_link(job.room_id, job.result);
|
|
8097
8170
|
const draft = share_tasks.get(job.room_id);
|
|
8098
8171
|
if (draft?.managed_id === job.id) {
|
|
8099
8172
|
if (["failed", "cancelled"].includes(job.phase)) share_tasks.delete(job.room_id);
|
|
@@ -8110,38 +8183,87 @@ function remember_share_job(job, announce) {
|
|
|
8110
8183
|
async function share_job_refresh() {
|
|
8111
8184
|
if (!can_manage_shares() || share_job_read) return;
|
|
8112
8185
|
const before = new Map(managed_share_jobs);
|
|
8186
|
+
const dismissed = new Set(dismissed_share_jobs);
|
|
8113
8187
|
share_job_read = share_job_request("list");
|
|
8114
8188
|
try {
|
|
8115
8189
|
const { enabled, jobs } = await share_job_read;
|
|
8116
8190
|
if (!enabled) return;
|
|
8117
|
-
for (const job of jobs)
|
|
8118
|
-
|
|
8191
|
+
for (const job of jobs) {
|
|
8192
|
+
if (!share_job_changes.has(job.id) && !dismissed_share_jobs.has(job.id) && before.get(job.id) === managed_share_jobs.get(job.id)) {
|
|
8193
|
+
remember_share_job(job, before.has(job.id));
|
|
8194
|
+
}
|
|
8195
|
+
}
|
|
8196
|
+
const listed = new Set(jobs.map(job => job.id));
|
|
8197
|
+
for (const id of dismissed) if (!listed.has(id)) dismissed_share_jobs.delete(id);
|
|
8198
|
+
for (const [id, job] of before) if (!share_job_changes.has(id) && managed_share_jobs.get(id) === job && !listed.has(id)) managed_share_jobs.delete(id);
|
|
8119
8199
|
publish_view();
|
|
8120
8200
|
} catch { /* A disconnected device resumes on focus or during the next active poll. */ }
|
|
8121
8201
|
finally { share_job_read = null; schedule_share_jobs(); }
|
|
8122
8202
|
}
|
|
8123
|
-
async function
|
|
8203
|
+
async function open_share_job(job) {
|
|
8204
|
+
if (job.phase === "published") return open_share_card(job.room_id, job.result);
|
|
8205
|
+
const loading = { room_id: job.room_id, managed_id: job.id, title: job.room_title, phase: "preparing" };
|
|
8206
|
+
share_draft = loading;
|
|
8207
|
+
publish_view();
|
|
8124
8208
|
try {
|
|
8125
|
-
|
|
8126
|
-
if (
|
|
8127
|
-
|
|
8128
|
-
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8209
|
+
await Promise.all([selection_write, share_job_changes.get(job.id)?.write]);
|
|
8210
|
+
if (share_draft !== loading) return;
|
|
8211
|
+
const { job: fresh } = await share_job_request("get", job);
|
|
8212
|
+
if (share_draft !== loading) return;
|
|
8213
|
+
remember_share_job(fresh, false);
|
|
8214
|
+
if (fresh.phase === "published") return open_share_card(fresh.room_id, fresh.result);
|
|
8215
|
+
if (!fresh.summary && fresh.phase !== "published") { share_draft = null; return; }
|
|
8216
|
+
share_draft = { ...fresh.summary, title: fresh.summary?.title || fresh.room_title, room_id: fresh.room_id, managed_id: fresh.id,
|
|
8217
|
+
phase: fresh.phase === "publishing" ? "publishing" : "ready",
|
|
8218
|
+
upload: fresh.phase === "publishing" || (fresh.phase === "failed" && fresh.progress?.revision) ? fresh.progress : null,
|
|
8219
|
+
link: fresh.result, days: fresh.selection.days,
|
|
8220
|
+
include_files: fresh.selection.include_files, left_files: new Set(fresh.selection.left_files) };
|
|
8221
|
+
share_tasks.set(fresh.room_id, share_draft);
|
|
8222
|
+
} catch (error) {
|
|
8223
|
+
if (share_draft === loading) { share_draft = null; notify("error", error.message); }
|
|
8224
|
+
} finally { publish_view(); }
|
|
8225
|
+
}
|
|
8226
|
+
|
|
8227
|
+
async function share_job_action({ op, job }) {
|
|
8228
|
+
if (op === "copy") return copy_text(job.result.url);
|
|
8229
|
+
if (op === "open") return open_share_job(job);
|
|
8230
|
+
const previous = share_job_changes.get(job.id);
|
|
8231
|
+
const retry_phase = !job.adjustable ? "preparing" : job.progress?.step === "preparing" ? "ready" : "publishing";
|
|
8232
|
+
const preview = op === "retry" ? { ...job, phase: retry_phase, error: "", progress: { step: retry_phase, done: 0, total: 0 } }
|
|
8233
|
+
: op === "cancel" ? { ...job, phase: "cancelled" } : null;
|
|
8234
|
+
const change = { job: preview };
|
|
8235
|
+
const cached = share_tasks.get(job.room_id);
|
|
8236
|
+
const opened = share_draft;
|
|
8237
|
+
if (op !== "retry") {
|
|
8238
|
+
if (cached?.managed_id === job.id) share_tasks.delete(job.room_id);
|
|
8239
|
+
if (opened?.managed_id === job.id) share_draft = null;
|
|
8240
|
+
}
|
|
8241
|
+
share_job_changes.set(job.id, change);
|
|
8242
|
+
change.write = (async () => {
|
|
8243
|
+
if (previous) await previous.write.catch(() => {});
|
|
8244
|
+
const reply = await share_job_request(op, job);
|
|
8245
|
+
if (reply.job) remember_share_job(reply.job, true);
|
|
8246
|
+
else { managed_share_jobs.delete(job.id); dismissed_share_jobs.add(job.id); }
|
|
8247
|
+
if (op !== "retry") {
|
|
8248
|
+
// An earlier queued change may have restored its draft after this click.
|
|
8249
|
+
const restored = share_tasks.get(job.room_id);
|
|
8250
|
+
if (restored?.managed_id === job.id) {
|
|
8251
|
+
share_tasks.delete(job.room_id);
|
|
8252
|
+
if (share_draft === restored) share_draft = null;
|
|
8140
8253
|
}
|
|
8141
|
-
schedule_share_jobs();
|
|
8142
8254
|
}
|
|
8143
|
-
}
|
|
8255
|
+
})();
|
|
8144
8256
|
publish_view();
|
|
8257
|
+
try { await change.write; }
|
|
8258
|
+
catch (error) {
|
|
8259
|
+
if (cached?.managed_id === job.id && !share_tasks.has(job.room_id)) share_tasks.set(job.room_id, cached);
|
|
8260
|
+
if (opened && opened === cached && !share_draft) share_draft = opened;
|
|
8261
|
+
notify("error", error.message);
|
|
8262
|
+
} finally {
|
|
8263
|
+
if (share_job_changes.get(job.id) === change) share_job_changes.delete(job.id);
|
|
8264
|
+
schedule_share_jobs();
|
|
8265
|
+
publish_view();
|
|
8266
|
+
}
|
|
8145
8267
|
}
|
|
8146
8268
|
function managed_selection(draft) {
|
|
8147
8269
|
return { include_files: Boolean(draft.include_files), left_files: [...draft.left_files || []], days: draft.days || SHARE_DEFAULT_DAYS };
|
|
@@ -8159,7 +8281,71 @@ function share_select_days(days) {
|
|
|
8159
8281
|
|
|
8160
8282
|
function share_open(room_id) {
|
|
8161
8283
|
share_draft = share_tasks.get(room_id) || null;
|
|
8284
|
+
if (share_draft?.phase === "published") return open_share_card(room_id, share_draft.link);
|
|
8285
|
+
publish_view();
|
|
8286
|
+
}
|
|
8287
|
+
|
|
8288
|
+
const share_card_writes = new Map();
|
|
8289
|
+
const SHARE_CARD_TEXT_SAVE_MS = 400;
|
|
8290
|
+
|
|
8291
|
+
/** Wake the preceding edit so only the latest value of a field is sent after typing stops. */
|
|
8292
|
+
function share_card_text_delay(draft, field) {
|
|
8293
|
+
const delays = draft.card_delays ||= new Map();
|
|
8294
|
+
delays.get(field)?.();
|
|
8295
|
+
return new Promise(resolve => {
|
|
8296
|
+
const flush = () => { clearTimeout(timer); delays.delete(field); resolve(); };
|
|
8297
|
+
const timer = setTimeout(flush, SHARE_CARD_TEXT_SAVE_MS);
|
|
8298
|
+
delays.set(field, flush);
|
|
8299
|
+
});
|
|
8300
|
+
}
|
|
8301
|
+
|
|
8302
|
+
/** Both the directory and a publication notification open the same saved card. */
|
|
8303
|
+
async function open_share_card(room_id, fallback) {
|
|
8304
|
+
const title = state.rooms.find(room => room.id === room_id)?.title || fallback?.card?.title || "";
|
|
8305
|
+
const loading = { room_id, title, phase: "preparing" };
|
|
8306
|
+
share_draft = loading;
|
|
8307
|
+
publish_view();
|
|
8308
|
+
try {
|
|
8309
|
+
await Promise.allSettled(["question", "outcome", "cover"].map(field => share_card_writes.get(room_id + "/" + field)));
|
|
8310
|
+
const saved = await request_json(`/api/rooms/${encodeURIComponent(room_id)}/share-card`);
|
|
8311
|
+
if (share_draft !== loading) return;
|
|
8312
|
+
const job = shown_share_jobs().find(item => item.result?.url === saved.url);
|
|
8313
|
+
const previous = fallback?.url === saved.url ? fallback : job?.result;
|
|
8314
|
+
const card = { title, members: [], stats: "", question: "", outcome: "", ...previous?.card, ...saved.card };
|
|
8315
|
+
const link = { ...previous, url: saved.url, expires_at: saved.expires_at, share_id: saved.share_id, card };
|
|
8316
|
+
share_draft = { room_id, title: card.title, phase: "published", link, cover_images: saved.images };
|
|
8317
|
+
} catch (error) {
|
|
8318
|
+
if (share_draft === loading) { share_draft = null; notify("error", error.message); }
|
|
8319
|
+
} finally { publish_view(); }
|
|
8320
|
+
}
|
|
8321
|
+
|
|
8322
|
+
/** Preview immediately, then save each field in order. Delayed edits stay bound to the original link. */
|
|
8323
|
+
async function edit_share_card({ field, value, room_id, share_id }) {
|
|
8324
|
+
const draft = share_draft;
|
|
8325
|
+
if (draft?.room_id !== room_id || draft.link?.share_id !== share_id) return;
|
|
8326
|
+
const card = draft.link.card;
|
|
8327
|
+
const key = room_id + "/" + field;
|
|
8328
|
+
const prior = share_card_writes.get(key);
|
|
8329
|
+
draft.saved_card ||= { ...card };
|
|
8330
|
+
draft.link = { ...draft.link, card: { ...card, [field]: value } };
|
|
8331
|
+
const versions = draft.card_versions ||= {};
|
|
8332
|
+
const version = versions[field] = (versions[field] || 0) + 1;
|
|
8162
8333
|
publish_view();
|
|
8334
|
+
const delay = field === "cover" ? undefined : share_card_text_delay(draft, field);
|
|
8335
|
+
const write = Promise.allSettled([prior, delay]).then(async () => {
|
|
8336
|
+
if (versions[field] !== version) return;
|
|
8337
|
+
await request_json(`/api/rooms/${encodeURIComponent(room_id)}/share-card`, { share_id, edits: { [field]: value } });
|
|
8338
|
+
draft.saved_card[field] = value;
|
|
8339
|
+
});
|
|
8340
|
+
share_card_writes.set(key, write);
|
|
8341
|
+
try { await write; }
|
|
8342
|
+
catch (error) {
|
|
8343
|
+
if (versions[field] === version) draft.link = { ...draft.link, card: { ...draft.link.card, [field]: draft.saved_card[field] } };
|
|
8344
|
+
throw error;
|
|
8345
|
+
} finally {
|
|
8346
|
+
if (share_card_writes.get(key) === write) share_card_writes.delete(key);
|
|
8347
|
+
if (share_draft === draft && versions[field] === version) publish_view();
|
|
8348
|
+
}
|
|
8163
8349
|
}
|
|
8164
8350
|
|
|
8165
8351
|
function share_actions(draft, actions) {
|
|
@@ -8183,6 +8369,7 @@ async function browser_share_data(room_id, models) {
|
|
|
8183
8369
|
const members = (room.members || []).filter(member => member.status !== "removed").map(member => member.label || display_name(member.name));
|
|
8184
8370
|
const description = t('{members} 在同一个房间协作 · {messages} 条消息 · {runs} 次执行', { members: members.join("、"), messages: room.message_count, runs: recorded.runs });
|
|
8185
8371
|
return { title: room.title, description, responses, responses_with_files, files, file_spots: null, include_files: false,
|
|
8372
|
+
materials: share_card_materials_info(responses),
|
|
8186
8373
|
exported_at, runs: recorded.runs, spots: share_sensitive_spots(responses), phase: "ready" };
|
|
8187
8374
|
}
|
|
8188
8375
|
|
|
@@ -8190,7 +8377,7 @@ async function browser_share_data(room_id, models) {
|
|
|
8190
8377
|
async function share_prepare(room_id = state.room?.id) {
|
|
8191
8378
|
if (!room_id) return;
|
|
8192
8379
|
const previous = share_tasks.get(room_id);
|
|
8193
|
-
const active =
|
|
8380
|
+
const active = shown_share_jobs().find(job => job.room_id === room_id && ["preparing","publishing","ready"].includes(job.phase));
|
|
8194
8381
|
if (active) {
|
|
8195
8382
|
if (active.phase === "ready") return share_job_action({ op: "open", job: active });
|
|
8196
8383
|
notify("info", t("可在左侧“已分享”查看进度")); return;
|
|
@@ -8226,6 +8413,7 @@ async function share_prepare(room_id = state.room?.id) {
|
|
|
8226
8413
|
|
|
8227
8414
|
/** Dismiss the dialog. Release a reviewed draft while keeping background tasks and published cards available. */
|
|
8228
8415
|
function share_cancel() {
|
|
8416
|
+
for (const flush of share_draft?.card_delays?.values() || []) flush();
|
|
8229
8417
|
if (share_draft?.phase === "ready" && !share_draft.managed_id) share_tasks.delete(share_draft.room_id);
|
|
8230
8418
|
share_draft = null;
|
|
8231
8419
|
publish_view();
|
|
@@ -8272,9 +8460,13 @@ async function share_room() {
|
|
|
8272
8460
|
}
|
|
8273
8461
|
}
|
|
8274
8462
|
|
|
8275
|
-
|
|
8463
|
+
const share_changes = new Map();
|
|
8464
|
+
const saved_share_links = new Map();
|
|
8465
|
+
|
|
8466
|
+
/** Project the latest intent, then the saved result, onto the public directory link. */
|
|
8276
8467
|
function share_link(room_id) {
|
|
8277
|
-
const
|
|
8468
|
+
const entry = share_changes.get(room_id) || saved_share_links.get(room_id);
|
|
8469
|
+
const link = entry ? entry.link : state.rooms.find(room => room.id === room_id)?.share_link;
|
|
8278
8470
|
return link && Date.parse(link.expires_at) > Date.now() ? link : null;
|
|
8279
8471
|
}
|
|
8280
8472
|
|
|
@@ -8285,7 +8477,21 @@ function share_links() {
|
|
|
8285
8477
|
|
|
8286
8478
|
/** Show a room's link as changed at once, before the next directory read carries it. */
|
|
8287
8479
|
function show_share_link(room_id, link) {
|
|
8288
|
-
|
|
8480
|
+
const visible = link ? { url: link.url, expires_at: link.expires_at } : null;
|
|
8481
|
+
saved_share_links.set(room_id, { link: visible });
|
|
8482
|
+
state.rooms = state.rooms.map(room => room.id === room_id ? { ...room, share_link: visible } : room);
|
|
8483
|
+
}
|
|
8484
|
+
|
|
8485
|
+
/** Retire a saved projection only after a fresh directory read confirms the same link and expiry. */
|
|
8486
|
+
function confirm_share_directory(rooms, versions) {
|
|
8487
|
+
for (const room of rooms) {
|
|
8488
|
+
const entry = versions.get(room.id);
|
|
8489
|
+
if (!entry || saved_share_links.get(room.id) !== entry) continue;
|
|
8490
|
+
const link = room.share_link;
|
|
8491
|
+
if (link?.url === entry.link?.url && (!link || Date.parse(link.expires_at) === Date.parse(entry.link.expires_at))) {
|
|
8492
|
+
saved_share_links.delete(room.id);
|
|
8493
|
+
}
|
|
8494
|
+
}
|
|
8289
8495
|
}
|
|
8290
8496
|
|
|
8291
8497
|
/**
|
|
@@ -8389,6 +8595,7 @@ async function share_publish(ttl_days = SHARE_DEFAULT_DAYS) {
|
|
|
8389
8595
|
return;
|
|
8390
8596
|
}
|
|
8391
8597
|
draft.upload = null;
|
|
8598
|
+
draft.publication = null;
|
|
8392
8599
|
if (share_draft === draft) share_draft = null;
|
|
8393
8600
|
publish_view();
|
|
8394
8601
|
notify("info", t('正在后台发布「{name}」', { name: draft.title }));
|
|
@@ -8408,14 +8615,25 @@ async function share_publish(ttl_days = SHARE_DEFAULT_DAYS) {
|
|
|
8408
8615
|
revision = result.revision;
|
|
8409
8616
|
}
|
|
8410
8617
|
// The link is out; keeping it with the room is what lets the owner renew or revoke it later, so a failure here is said.
|
|
8411
|
-
|
|
8618
|
+
const card = share_card(draft, link);
|
|
8619
|
+
const publication = card.publication = draft.publication = { revision, total: carried.length, ...(carried.length ? {} : { done: 0 }) };
|
|
8620
|
+
await save_share_link(draft.room_id, { ...link, card }).catch(error => notify("warning", t('链接已发布,但没能保存到房间,之后无法在这里续期或撤销:{value1}', { value1: error.message })));
|
|
8412
8621
|
// The page is up; its attachments follow. A failed one leaves the link without it, and publishing again sends all anew.
|
|
8413
|
-
if (body.files)
|
|
8414
|
-
|
|
8415
|
-
|
|
8622
|
+
if (body.files) {
|
|
8623
|
+
try { await share_upload_files(draft, link, revision); }
|
|
8624
|
+
catch (error) {
|
|
8625
|
+
throw new Error(t('链接已发布,但附件没有传完,读者会看到“附件读取失败”;可再点“更新链接”重传。{value1}', { value1: error.message }));
|
|
8626
|
+
} finally {
|
|
8627
|
+
publication.done = draft.upload?.done;
|
|
8628
|
+
const route = `/api/rooms/${encodeURIComponent(draft.room_id)}/share-card`;
|
|
8629
|
+
if (revision && Number.isInteger(publication.done)) {
|
|
8630
|
+
await request_json(route, { share_id: link.share_id, publication: { revision, done: publication.done } }).catch(() => {});
|
|
8631
|
+
}
|
|
8632
|
+
}
|
|
8633
|
+
}
|
|
8416
8634
|
const copied = await navigator.clipboard?.writeText(link.url).then(() => true, () => false);
|
|
8417
8635
|
// The dialog turns into the published link itself, to copy or open; the room's own data is no longer needed.
|
|
8418
|
-
Object.assign(draft, { phase: "published", link: { url: link.url, expires_at: link.expires_at, copied: Boolean(copied), updated: Boolean(existing), card
|
|
8636
|
+
Object.assign(draft, { phase: "published", link: { url: link.url, share_id: link.share_id, expires_at: link.expires_at, copied: Boolean(copied), updated: Boolean(existing), card }, responses: null, responses_with_files: null });
|
|
8419
8637
|
notify("info", t('「{name}」的分享链接已发布', { name: draft.title }), share_actions(draft, [
|
|
8420
8638
|
[t('查看分享卡'), () => share_open(draft.room_id)], [t('复制链接'), () => copy_text(link.url)] ]));
|
|
8421
8639
|
} catch (error) {
|
|
@@ -8426,45 +8644,49 @@ async function share_publish(ttl_days = SHARE_DEFAULT_DAYS) {
|
|
|
8426
8644
|
}
|
|
8427
8645
|
}
|
|
8428
8646
|
|
|
8429
|
-
/**
|
|
8430
|
-
async function
|
|
8431
|
-
|
|
8432
|
-
|
|
8647
|
+
/** Display the latest intent immediately; send writes for each room in click order. */
|
|
8648
|
+
async function queue_share_change(room_id, link, write) {
|
|
8649
|
+
const previous = share_changes.get(room_id);
|
|
8650
|
+
const entry = { link };
|
|
8651
|
+
share_changes.set(room_id, entry);
|
|
8652
|
+
entry.write = previous ? previous.write.then(write, write) : Promise.resolve().then(write);
|
|
8433
8653
|
publish_view();
|
|
8434
|
-
try {
|
|
8654
|
+
try { await entry.write; }
|
|
8655
|
+
finally {
|
|
8656
|
+
if (share_changes.get(room_id) === entry) share_changes.delete(room_id);
|
|
8657
|
+
publish_view();
|
|
8658
|
+
}
|
|
8659
|
+
}
|
|
8660
|
+
|
|
8661
|
+
async function share_renew({ room_id, days = SHARE_DEFAULT_DAYS }) {
|
|
8662
|
+
const ttl_days = SHARE_DAYS.includes(Number(days)) ? Number(days) : SHARE_DEFAULT_DAYS;
|
|
8663
|
+
const current = share_link(room_id);
|
|
8664
|
+
const preview = current && { ...current, expires_at: new Date(Date.now() + ttl_days * DAY_MS).toISOString() };
|
|
8665
|
+
const write = async () => {
|
|
8435
8666
|
const link = await share_link_record(room_id);
|
|
8436
8667
|
if (!link) throw new Error(t('这个房间没有可续期的分享链接'));
|
|
8437
|
-
|
|
8668
|
+
let result;
|
|
8669
|
+
try { result = await share_site_request("POST", `/api/shares/${encodeURIComponent(link.share_id)}/renew`, { ttl_days }, link.manage_token); }
|
|
8670
|
+
catch (error) {
|
|
8671
|
+
if ([404, 410].includes(error.status)) await save_share_link(room_id, null).catch(() => {});
|
|
8672
|
+
throw error;
|
|
8673
|
+
}
|
|
8438
8674
|
await save_share_link(room_id, { ...link, expires_at: result.expires_at });
|
|
8439
8675
|
notify("info", t('已续期,{time} 前有效。', { time: new Date(result.expires_at).toLocaleString(undefined, { hour12: false }) }));
|
|
8440
|
-
}
|
|
8441
|
-
|
|
8442
|
-
|
|
8676
|
+
};
|
|
8677
|
+
try { await queue_share_change(room_id, preview, write); }
|
|
8678
|
+
catch (error) {
|
|
8443
8679
|
notify("error", t('续期失败:{value1}', { value1: error.message }));
|
|
8444
|
-
} finally {
|
|
8445
|
-
state.backup_pending = false;
|
|
8446
|
-
publish_view();
|
|
8447
8680
|
}
|
|
8448
8681
|
}
|
|
8449
8682
|
|
|
8450
8683
|
/** Take a room's published link down now; the share site deletes its copy. */
|
|
8451
8684
|
async function share_revoke(room_id) {
|
|
8452
|
-
if (state.backup_pending) return;
|
|
8453
|
-
state.backup_pending = true;
|
|
8454
|
-
publish_view();
|
|
8455
8685
|
try {
|
|
8456
|
-
|
|
8457
|
-
if (link) {
|
|
8458
|
-
try { await share_site_request("DELETE", `/api/shares/${encodeURIComponent(link.share_id)}`, null, link.manage_token); }
|
|
8459
|
-
catch (error) { if (![404, 410].includes(error.status)) throw error; }
|
|
8460
|
-
}
|
|
8461
|
-
await save_share_link(room_id, null);
|
|
8686
|
+
await queue_share_change(room_id, null, () => take_down_share(room_id));
|
|
8462
8687
|
notify("info", t('分享链接已撤销,打开它的人会看到“分享不存在”。'));
|
|
8463
8688
|
} catch (error) {
|
|
8464
8689
|
notify("error", t('撤销分享链接失败:{value1}', { value1: error.message }));
|
|
8465
|
-
} finally {
|
|
8466
|
-
state.backup_pending = false;
|
|
8467
|
-
publish_view();
|
|
8468
8690
|
}
|
|
8469
8691
|
}
|
|
8470
8692
|
|
|
@@ -8618,7 +8840,7 @@ async function import_rooms({ files, folder_id = null }) {
|
|
|
8618
8840
|
async function execute_view_action(name, value) {
|
|
8619
8841
|
if (!["refresh", "create"].includes(name)) state.navigation_version++;
|
|
8620
8842
|
const event = { preventDefault() {} };
|
|
8621
|
-
const actions = { refresh: refresh_room, room: select_room, tab: select_tab,
|
|
8843
|
+
const actions = { open_share_card, edit_share_card, refresh: refresh_room, room: select_room, tab: select_tab,
|
|
8622
8844
|
archives: toggle_archives, backup: backup_room, backup_rooms, share_job_refresh, share_job_action, share_select_days, share_open, share_prepare, share_room, share_cancel, share_publish, share_include_files, share_toggle_kind, share_toggle_file, share_revoke, share_renew, share_copy, import_rooms, manage_channel, retry_destruction, destroy_all_rooms, move_channel, create_folder, move_folder, rename_folder, delete_folder, sort_directory,
|
|
8623
8845
|
send: () => send_from_composer(event), discard_sending, retry_sending, choose_attachments, remove_attachment, preview_attachment,
|
|
8624
8846
|
create: ({ folder_id, accepted, rejected }) => submit_room(event, folder_id, { accepted, rejected }), quick_create: quick_create_room, welcome: open_welcome,
|