Skip to content

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

Memory text editor: keep earlier drafts on a second Reload, lock the text while saving; pt-br string

Bugfixer 26e238ade37c8
diff --git a/src/components/bot-panel/MemoryPage.text.test.ts b/src/components/bot-panel/MemoryPage.text.test.ts
index fcea36cb52..15a017c08d 100644
--- a/src/components/bot-panel/MemoryPage.text.test.ts
+++ b/src/components/bot-panel/MemoryPage.text.test.ts
@@ -25,7 +25,6 @@ let root: Root;
beforeEach(() => {
puts.length = 0;
files["MEMORY.md"] = "# Memory\n\n- Prefers short replies.\n";
- // The memory file route, hash check and all: a save against a stale hash is a 409 with the file as it is now.
vi.stubGlobal("fetch", vi.fn(async (input: string, init?: RequestInit) => {
const url = new URL(input, "http://x");
if (init?.method === "PUT") {
@@ -126,3 +125,50 @@ it("closes the text when the person moves to another bot, so coming back shows t
expect(textarea()).toBeNull();
expect(host.querySelector('[data-panel-link="memory-text"]')).toBeTruthy();
});
+
+it("keeps every earlier draft when Reload is needed twice", async () => {
+ await open();
+ await type("# Memory\n\n- First draft.\n");
+ files["MEMORY.md"] += "- The bot's note.\n";
+ await click(host.querySelector('[data-panel-done="memory-text"]'));
+ await click(button("Reload"));
+ await type("# Memory\n\n- Second draft.\n");
+ files["MEMORY.md"] += "- Another bot note.\n";
+ await click(host.querySelector('[data-panel-done="memory-text"]'));
+ await click(button("Reload"));
+ const kept = host.querySelector("[data-memory-draft] pre")?.textContent;
+ expect(kept).toContain("First draft.");
+ expect(kept).toContain("Second draft.");
+});
+
+it("locks the text while it saves, so nothing typed after Save is lost", async () => {
+ await open();
+ let finish!: () => void;
+ const fetchMock = vi.mocked(fetch);
+ const real = fetchMock.getMockImplementation()!;
+ fetchMock.mockImplementationOnce((input, init) => new Promise((resolve) => { finish = () => resolve(real(input as string, init)); }));
+ await type("# Memory\n\n- Saved.\n");
+ await click(host.querySelector('[data-panel-done="memory-text"]'));
+ expect(textarea()?.readOnly).toBe(true);
+ await act(async () => finish());
+ await settle();
+ expect(textarea()).toBeNull();
+});
+
+it("a save that finishes after moving to another bot does not show in that bot's notes", async () => {
+ await open();
+ let finish!: () => void;
+ const fetchMock = vi.mocked(fetch);
+ const real = fetchMock.getMockImplementation()!;
+ fetchMock.mockImplementationOnce((input, init) => new Promise((resolve) => { finish = () => resolve(real(input as string, init)); }));
+ await type("# Memory\n\n- Late note.\n");
+ await click(host.querySelector('[data-panel-done="memory-text"]'));
+ const other = { ...bot, id: "atlas", name: "Atlas" } as Bot;
+ await act(async () => root.render(createElement(MemoryPage, { bot: other, derived: {} as never })));
+ await settle();
+ await act(async () => finish());
+ await settle();
+ expect(files["MEMORY.md"]).toContain("Late note.");
+ expect(host.textContent).toContain("Prefers short replies.");
+ expect(host.textContent).not.toContain("Late note.");
+});
diff --git a/src/components/bot-panel/pages.tsx b/src/components/bot-panel/pages.tsx
index e94bbd5039..c41d31ca15 100644
--- a/src/components/bot-panel/pages.tsx
+++ b/src/components/bot-panel/pages.tsx
@@ -274,8 +274,6 @@ export function MemoryPage({ bot }: PageContext) {
);
}
-/** The whole MEMORY.md as text, saved against the hash it was opened at, so a note the bot writes meanwhile is a
- * conflict to settle, never silently lost: Reload shows the bot's version and keeps what the person typed beside it. */
function MemoryTextEditor({ bot, doc, mine, onDone }: {
bot: Bot;
doc: MemoryDoc;
@@ -312,7 +310,8 @@ function MemoryTextEditor({ bot, doc, mine, onDone }: {
};
const reload = () => {
if (!conflict) return;
- setSavedDraft(text);
+ // A second Reload keeps the first kept draft too.
+ setSavedDraft((kept) => (kept === null || kept === text ? text : `${kept}\n\n${text}`));
setBase({ text: conflict.current, hash: conflict.currentHash });
setText(conflict.current);
setConflict(null);
@@ -328,6 +327,7 @@ function MemoryTextEditor({ bot, doc, mine, onDone }: {
value={text}
placeholder={t("memory.indexPlaceholder")}
aria-label={t("memory.botMemory")}
+ readOnly={saving}
onChange={(event) => setText(event.target.value)}
/>
{error && <div className="text-[13px] text-warning">{error}</div>}
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 3cc07ce43b..1764011eb4 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -7633,6 +7633,7 @@
"botPanel.memory.forget": "Esquecer",
"botPanel.memory.empty": "Nada guardado na memória ainda.",
"botPanel.memory.addPlaceholder": "Diga algo para {name} lembrar",
+ "botPanel.memory.editText": "Editar como texto",
"botPanel.skills.remove": "Remover {name}",
"botPanel.skills.removeConfirm": "Remover a habilidade “{name}”?",
"botPanel.skills.removeFailed": "Não foi possível remover esta habilidade.",
diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.json
index 18c83b2031..3f7e16e8f0 100644
--- a/src/locales/source-hashes.json
+++ b/src/locales/source-hashes.json
@@ -33678,7 +33678,8 @@
"settings.simple.more.limits": "dffb64dc70011ecf3ef3ad62cdd271f08f1b86601d7c2bc54f91978a32ca8cf4",
"settings.simple.more.open": "ed077f3d8125d60dca1979c7133601bd187d47c73ed9975028f677e49e709942",
"memory.journal.actor.teamSetup": "f36c1b27c9eb8da8e6f4df8b6b437eb805508fdb04b145ec229102dff39c96e9",
- "memory.journal.instructions": "57dca9eafc1de092ccb80dfa72f853edcdb3b3e00f9b103f65e83e12aa7cbbc3"
+ "memory.journal.instructions": "57dca9eafc1de092ccb80dfa72f853edcdb3b3e00f9b103f65e83e12aa7cbbc3",
+ "botPanel.memory.editText": "e9938c0a9a18c1996f3d6c806bc9b67a189eb30390b854df8fd4687c86e4a255"
},
"zh": {
"pro.fromPrice": "a48a04a457d60b08b54fc83e7a6c4584ffedb1e23621859084900c8521a3af7b",