Trim page props and page the conversation's messages
Bot and workspace lists in page props leave out instructions, memory and workspace context, and carry the last message as a short preview. The header avatar's edit form loads the bot's instructions when it opens. The conversation renders its latest 30 messages and loads older ones as the thread scrolls to its top. Also: the composer shows a placeholder until its editor loads, and `bun start` no longer builds first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import type { BotWithLastMessage } from "@/src/types";
|
||||
import railBots from "./rail-bots";
|
||||
import railWorkspaces from "./rail-workspaces";
|
||||
|
||||
describe("railBots", () => {
|
||||
test("drops the core instructions and memory", () => {
|
||||
const bots: BotWithLastMessage[] = [
|
||||
{ id: 1, name: "Ada", system_prompt: "Long rules", memory: "Notes" },
|
||||
];
|
||||
const [bot] = railBots({ bots });
|
||||
|
||||
expect(bot).toEqual({ id: 1, name: "Ada", last_message_text: undefined });
|
||||
});
|
||||
|
||||
test("cuts the last message to a plain one-line preview", () => {
|
||||
const bots: BotWithLastMessage[] = [
|
||||
{ id: 1, last_message_text: `**Done.**\n\n${"word ".repeat(100)}` },
|
||||
];
|
||||
const [bot] = railBots({ bots });
|
||||
|
||||
expect(bot?.last_message_text?.startsWith("Done. word")).toBe(true);
|
||||
expect(bot?.last_message_text?.length).toBe(AppData.RailPreviewMaxChars);
|
||||
});
|
||||
});
|
||||
|
||||
describe("railWorkspaces", () => {
|
||||
test("drops the shared context", () => {
|
||||
expect(
|
||||
railWorkspaces({
|
||||
workspaces: [{ id: 2, name: "Site", system_prompt: "Context", unread: 0 }],
|
||||
}),
|
||||
).toEqual([{ id: 2, name: "Site", unread: 0 }]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import type { BotWithLastMessage } from "@/src/types";
|
||||
import messagePreview from "./message-preview";
|
||||
|
||||
/**
|
||||
* Bots as page props carry them for the rail and the crew lists: without
|
||||
* their core instructions and memory (the largest part of a row, and only
|
||||
* the bot's own edit form reads them, loading them when it opens), and
|
||||
* with the last message cut to a one-line preview.
|
||||
*/
|
||||
export default function railBots<T extends BotWithLastMessage>({ bots }: { bots: T[] }): T[] {
|
||||
return bots.map(({ system_prompt, memory, ...bot }) => ({
|
||||
...bot,
|
||||
last_message_text: bot.last_message_text
|
||||
? messagePreview({ text: bot.last_message_text }).slice(0, AppData.RailPreviewMaxChars)
|
||||
: bot.last_message_text,
|
||||
})) as T[];
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { WorkspaceWithActivity } from "@/src/types";
|
||||
|
||||
/**
|
||||
* Workspaces as page props carry them for the rail: without their shared
|
||||
* context (`system_prompt`), which only the open workspace's own pages
|
||||
* read, from their `workspace` prop.
|
||||
*/
|
||||
export default function railWorkspaces({
|
||||
workspaces,
|
||||
}: {
|
||||
workspaces: WorkspaceWithActivity[];
|
||||
}): WorkspaceWithActivity[] {
|
||||
return workspaces.map(({ system_prompt, ...workspace }) => workspace);
|
||||
}
|
||||
Reference in New Issue
Block a user