Name sessions with the model and keep the rail list live

Sessions no longer take their title from the first message: once the first exchange is sent, the text model writes the title and summary, which the rail and sessions list show. The summary records how many messages it covers so a stale one is rewritten before it is carried into the next session.

The sessions hook now reloads on live message and session events, so a session started by the first message, a rollover or another tab appears without a reload. New sessions are pushed as server:bot-session, both from the process that changed them and through the live relay.
This commit is contained in:
2026-10-19 18:05:57 +01:00
parent 9293a55032
commit 4d5195447b
19 changed files with 420 additions and 38 deletions
@@ -14,8 +14,9 @@ type Params = {
/**
* Closes the conversation's active session and starts the next one, which
* carries on from it (its summary is written when the next reply runs).
* An active session with no messages yet is kept as it is.
* carries on from it (its summary goes into the next reply's prompt,
* rewritten first when it covers fewer messages than the session ended
* with). An active session with no messages yet is kept as it is.
*/
export default async function startBotSession({
user_id,
@@ -24,8 +24,9 @@ type Params = {
/**
* Appends a user message (and its files) to a session and bumps its
* activity. The first one titles the session. Callers must check the bot
* and session belong to the session user first.
* activity. The session is named later, from its first exchange with the
* bot (`nameBotSession`). Callers must check the bot and session belong to
* the session user first.
*/
export default async function insertUserMessage({
bot_id,
@@ -66,13 +67,9 @@ export default async function insertUserMessage({
});
}
const title = (text || media[0]?.title || "").replace(/\s+/g, " ").trim().slice(0, 80);
await BunSQLite.sql({
sql: `UPDATE bot_sessions SET last_activity_at = ?,
title = CASE WHEN COALESCE(title, '') = '' THEN ? ELSE title END
WHERE id = ?`,
values: [now, title, session_id],
sql: `UPDATE bot_sessions SET last_activity_at = ? WHERE id = ?`,
values: [now, session_id],
});
return {