Files
DeepTutor/web/lib/session-threads.ts
yuanyyt 43b66ac1ad feat: add a message-level Little Tutor entry
Side chats are filed under the message their quoted passage came from:
the turn carries quoted_message_id, the backend stores it as
tutor_source_message_id, and the chat list shows "Little Tutor x N"
under that message with a popover to open or delete each thread.

Threads are read once per conversation and shared with the viewer, only
side-chat turns refresh the session lists, and a turn that omits the
field leaves the stored anchor untouched.

Refs #2118
2026-10-30 13:55:29 +08:00

30 lines
1.1 KiB
TypeScript

/**
* Little Tutor threads filed under the message they were opened from.
*
* A thread records its source message in ``preferences.tutor_source_message_id``
* (the wire field is ``quoted_message_id``). Threads without one — bare side
* chats, and threads created before the field existed — have no message-level
* entry point; they stay reachable from the viewer and Space history.
*
* Keys are strings so SQLite rowids and PocketBase record ids group alike.
*/
import type { SessionSummary } from "@/lib/session-api";
export function groupThreadsByMessage(
threads: readonly SessionSummary[],
): Map<string, SessionSummary[]> {
const grouped = new Map<string, SessionSummary[]>();
for (const thread of threads) {
const preferences = thread.preferences;
if (preferences?.archived) continue;
const source = preferences?.tutor_source_message_id;
if (source == null || source === "") continue;
const key = String(source);
const rows = grouped.get(key);
if (rows) rows.push(thread);
else grouped.set(key, [thread]);
}
return grouped;
}