Let users copy the current chat session as markdown

The conversation header menu gets a Copy chat row that puts the active
session on the clipboard as one markdown document: a summary, then each
message under its author and time, with quotes, attachments and
reactions. Bot and workspace refs read as names, message headings drop
below the message headings and code blocks stay untouched. The clipboard
write starts on the click with a pending ClipboardItem so Safari allows
it after the fetch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 11:49:46 +01:00
co-authored by Claude Opus 5.5
parent d7f88d8dd3
commit 84f8c0cac8
12 changed files with 641 additions and 2 deletions
+34
View File
@@ -0,0 +1,34 @@
import { describe, expect, test } from "bun:test";
import exportMessageText from "./export-message-text";
const names = { bot_names: { 3: "Ada" }, workspace_names: { 2: "Launch" } };
describe("exportMessageText", () => {
test("words refs, naming what is known", () => {
expect(
exportMessageText({
text: "[bot:3] and [bot:9] in [workspace:2] on [computer:4], see [file:12] and [folder:computer:4:seo/raw]. [take-over:4:browser]",
...names,
heading_offset: 0,
}),
).toBe("@Ada and a bot in #Launch on computer 4, see file 12 and `seo/raw`. (take over computer 4, browser)");
});
test("leaves refs that are already links alone", () => {
expect(exportMessageText({ text: "[bot:3](#x)", ...names, heading_offset: 0 })).toBe("[bot:3](#x)");
});
test("drops headings, capped at six", () => {
expect(
exportMessageText({ text: "# Top\n## Next\n##### Deep\n#nottag", ...names, heading_offset: 3 }),
).toBe("#### Top\n##### Next\n###### Deep\n#nottag");
});
test("leaves code blocks exactly as they are", () => {
const text = "```bash\n# comment [bot:3]\n```\n# Title\n~~~~\n## also code\n~~~\n~~~~";
expect(exportMessageText({ text, ...names, heading_offset: 3 })).toBe(
"```bash\n# comment [bot:3]\n```\n#### Title\n~~~~\n## also code\n~~~\n~~~~",
);
});
});