Skip to content

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

fix(threads): a first message that opens with pasted text is titled by the paste, not its wrapper

AdityaUmaledb1bd79284c4
diff --git a/server/thread-title.test.ts b/server/thread-title.test.ts
index bd60131d45..016ec6d1b3 100644
--- a/server/thread-title.test.ts
+++ b/server/thread-title.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import type { Message } from "./store.ts";
-import { callTitleExcerpt, threadTitlePrompt, titleConversationExcerpt, TITLE_INPUT_MAX_CHARS } from "./thread-title.ts";
+import { callTitleExcerpt, threadTitlePrompt, titleConversationExcerpt, titleFromMessage, TITLE_INPUT_MAX_CHARS, UNTITLED_TASK } from "./thread-title.ts";
let next = 0;
const message = (role: Message["role"], text: string, extra: Partial<Message> = {}): Message => ({
@@ -110,3 +110,16 @@ describe("a Live call's title", () => {
expect(callTitleExcerpt([message("user", "typed")], "c")).toBe("");
});
});
+
+describe("titleFromMessage", () => {
+ it("names a message that starts with pasted text by the pasted text, not its wrapper", () => {
+ expect(titleFromMessage('<pasted-text index="1">\n\n Stack trace from the build\nline two\n</pasted-text>')).toBe("Stack trace from the build");
+ expect(titleFromMessage('<pasted-text index="1">\n</pasted-text>\n\n<pasted-text index="2">\nSecond paste\n</pasted-text>')).toBe("Second paste");
+ expect(titleFromMessage('<pasted-text index="1">\n\n</pasted-text>')).toBe(UNTITLED_TASK);
+ });
+
+ it("keeps typed text first, and a typed wrapper with no pasted block stays as typed", () => {
+ expect(titleFromMessage('Fix this\n\n<pasted-text index="1">\nerror\n</pasted-text>')).toBe("Fix this");
+ expect(titleFromMessage('<pasted-text index="1">\nnot closed')).toBe('<pasted-text index="1">');
+ });
+});
diff --git a/server/thread-title.ts b/server/thread-title.ts
index 5d8e2a3eb2..4eabf41464 100644
--- a/server/thread-title.ts
+++ b/server/thread-title.ts
@@ -4,8 +4,15 @@ import { toolResultPrefix } from "./tool-results.ts";
export const UNTITLED_TASK = "New task";
+const PASTE_WRAPPER_LINE = /^\s*<\/?pasted-text(?:\s+index="\d+")?\s*>\s*$/i;
+
export function titleFromMessage(text: string): string {
- const line = text.trim().split("\n")[0]!.trim();
+ const lines = text.trim().split("\n");
+ // A message that opens with a paste is named by the pasted text, not the wrapper the composer puts around it.
+ const opensWithPaste = PASTE_WRAPPER_LINE.test(lines[0]!) && /<\/pasted-text>/i.test(text);
+ const line = opensWithPaste
+ ? lines.map((candidate) => candidate.trim()).find((candidate) => candidate && !PASTE_WRAPPER_LINE.test(candidate)) ?? ""
+ : lines[0]!.trim();
return line.length > 48 ? `${toolResultPrefix(line, 47)}…` : line || UNTITLED_TASK;
}