Skip to content

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

fix(threads): take a paste-opened title only from pasted-text blocks, skipping attachment tags

AdityaUmale72ae26b6d5cb
diff --git a/server/thread-title.test.ts b/server/thread-title.test.ts
index 016ec6d1b3..c4b42d242b 100644
--- a/server/thread-title.test.ts
+++ b/server/thread-title.test.ts
@@ -116,6 +116,8 @@ describe("titleFromMessage", () => {
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);
+ expect(titleFromMessage('<pasted-text index="1">\n\n</pasted-text>\n\n<attached-file path="/tmp/a.txt" name="a.txt" />')).toBe(UNTITLED_TASK);
+ expect(titleFromMessage('<pasted-text index="1">\n</pasted-text>\n\n<attached-image path="/tmp/b.png" name="b.png" />\n\n<pasted-text index="3">\nThird\n</pasted-text>')).toBe("Third");
});
it("keeps typed text first, and a typed wrapper with no pasted block stays as typed", () => {
diff --git a/server/thread-title.ts b/server/thread-title.ts
index 4eabf41464..b7eb9c963d 100644
--- a/server/thread-title.ts
+++ b/server/thread-title.ts
@@ -10,12 +10,21 @@ export function titleFromMessage(text: string): string {
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();
+ const line = opensWithPaste ? firstPastedLine(lines) : lines[0]!.trim();
return line.length > 48 ? `${toolResultPrefix(line, 47)}…` : line || UNTITLED_TASK;
}
+/** The first non-empty line inside a pasted-text block; attachment tags between blocks are skipped. */
+function firstPastedLine(lines: string[]): string {
+ let inPaste = false;
+ for (const raw of lines) {
+ const line = raw.trim();
+ if (PASTE_WRAPPER_LINE.test(line)) inPaste = !line.startsWith("</");
+ else if (inPaste && line) return line;
+ }
+ return "";
+}
+
export const TITLE_INPUT_MAX_CHARS = 1_500;
const EXCERPT_MAX_MESSAGES = 12;
const EXCERPT_LINE_MAX_CHARS = 300;