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:
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import parseSessionName from "./parse-session-name";
|
||||
|
||||
describe("parseSessionName", () => {
|
||||
test("reads a title and summary", () => {
|
||||
expect(parseSessionName({ text: `{"title":"Tidy invoices","summary":"- sorted them"}` })).toEqual({
|
||||
title: "Tidy invoices",
|
||||
summary: "- sorted them",
|
||||
});
|
||||
});
|
||||
|
||||
test("tolerates a code fence around the object", () => {
|
||||
expect(
|
||||
parseSessionName({
|
||||
text: "```json\n{\"title\":\"Plans\",\"summary\":\"- a trip\"}\n```",
|
||||
}),
|
||||
).toEqual({ title: "Plans", summary: "- a trip" });
|
||||
});
|
||||
|
||||
test("is null when either part is missing or the JSON is bad", () => {
|
||||
expect(parseSessionName({})).toBeNull();
|
||||
expect(parseSessionName({ text: "" })).toBeNull();
|
||||
expect(parseSessionName({ text: `{"title":"Only a title"}` })).toBeNull();
|
||||
expect(parseSessionName({ text: `{"title":"","summary":"- a trip"}` })).toBeNull();
|
||||
expect(parseSessionName({ text: "{nope" })).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user