Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Chat: Regenerate keeps an automation's line automated

luishron123ef013c2a4637
diff --git a/server/store.test.ts b/server/store.test.ts
index 5ac8fbc8a1..d9d86ee2ff 100644
--- a/server/store.test.ts
+++ b/server/store.test.ts
@@ -20,7 +20,7 @@ import type { ModelSelection } from "./contracts.ts";
import * as mdb from "./message-db.ts";
import { hasTeamAuthority } from "./peer-roster.ts";
import { flushLaterSaves } from "./save-batch.ts";
-import { Store, toWireTask, type BotRecord } from "./store.ts";
+import { Store, toWireTask, type BotRecord, type Message } from "./store.ts";
import type { TeamSetupRequest } from "../shared/team-setup.ts";
import { SECTION_CONTEXTS_FILE, readSectionContext, writeSectionContext } from "./section-context.ts";
import { TeamComputers } from "./team-computers.ts";
@@ -1800,6 +1800,26 @@ describe("Store", () => {
]);
});
+ it("branchMessage keeps an automation's line automated when its words are sent again, and only then", () => {
+ const store = new Store(selection);
+ const bot = store.createBot();
+ const followUp = "[Wait finished: the build] Tell me how it went.";
+ const automatedLine = store.appendMessage(bot.threadId, { role: "user", kind: "text", text: `${followUp}\n`, automated: true });
+ const typed = store.appendMessage(bot.threadId, { role: "user", kind: "text", text: "Thanks" });
+ const live: Message[] = [];
+ store.onChange((change) => { if (change.type === "message") live.push(change.message); });
+
+ const again = store.branchMessage(bot.threadId, automatedLine.id, followUp)!;
+ const edited = store.branchMessage(bot.threadId, automatedLine.id, "Tell me tomorrow instead.")!;
+ const typedAgain = store.branchMessage(bot.threadId, typed.id, "Thanks")!;
+
+ expect(live.map((message) => [message.id, message.automated])).toEqual([[again.id, true], [edited.id, undefined], [typedAgain.id, undefined]]);
+ const reread = new Store(selection).messagesFor(bot.threadId);
+ expect(reread.find((message) => message.id === again.id)).toMatchObject({ text: followUp, automated: true });
+ expect(reread.find((message) => message.id === edited.id)).not.toHaveProperty("automated");
+ expect(reread.find((message) => message.id === typedAgain.id)).not.toHaveProperty("automated");
+ });
+
it("setActiveLeaf switches branches and descends to the newest leaf", () => {
const store = new Store(selection);
const bot = store.createBot();
diff --git a/server/store.ts b/server/store.ts
index 8d6cf32eb4..487d9265db 100644
--- a/server/store.ts
+++ b/server/store.ts
@@ -1208,6 +1208,8 @@ export class Store {
parentId: source.parentId ?? null,
replyToId: source.replyToId,
...(source.reaction && source.text === text ? { reaction: source.reaction } : {}),
+ // Regenerate and Try again send the stored words back: an automation's line stays the automation's.
+ ...(source.automated === true && source.text?.trim() === text.trim() ? { automated: true } : {}),
...(sendId ? { sendId } : {}),
...(sender ? { sender } : {}),
...(dataContext ? { dataContext } : {}), ...from,