feat(chat): copy a conversation as Markdown from the More menu (#1884) #1894
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import {
|
||||
Copy,
|
||||
Ellipsis,
|
||||
GitBranch,
|
||||
Pencil,
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
Undo2,
|
||||
} from "@lucide/vue";
|
||||
import { ref } from "vue";
|
||||
import { toast } from "vue-sonner";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
@@ -28,6 +30,7 @@ import { Input } from "@/components/ui/input";
|
||||
import ChatSettings from "./ChatSettings.vue";
|
||||
import {
|
||||
currentSession,
|
||||
messages,
|
||||
runSessionCommand,
|
||||
useEscapeLayer,
|
||||
} from "./state";
|
||||
@@ -51,6 +54,31 @@ function run(command: string): void {
|
||||
void runSessionCommand(command);
|
||||
}
|
||||
|
||||
// Reply text is already Markdown, so the transcript is the messages under a
|
||||
// heading per speaker. Empty turns (tool-only replies) have nothing to paste.
|
||||
async function copyMarkdown(): Promise<void> {
|
||||
open.value = false;
|
||||
const text = messages.value
|
||||
.map((m) => {
|
||||
const body = (m.text ?? m.Text ?? "").trim();
|
||||
if (!body) return "";
|
||||
return `### ${(m.from ?? m.From) === "web" ? "You" : "Archie"}\n\n${body}`;
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join("\n\n");
|
||||
if (!text) {
|
||||
toast.error("Nothing to copy");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch (err) {
|
||||
toast.error(`Not copied: ${(err as Error).message || "clipboard unavailable"}`);
|
||||
return;
|
||||
}
|
||||
toast.success("Copied as Markdown");
|
||||
}
|
||||
|
||||
// Rename and branch ask for a value in a labelled dialog, not window.prompt.
|
||||
const promptOpen = ref(false);
|
||||
const promptCommand = ref("");
|
||||
@@ -124,6 +152,13 @@ function submitPrompt(): void {
|
||||
@click="run('/compress --preview')"
|
||||
><Shrink data-icon="inline-start" />Preview compression</Button
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
class="justify-start"
|
||||
@click="copyMarkdown"
|
||||
><Copy data-icon="inline-start" />Copy as Markdown</Button
|
||||
>
|
||||
<Separator class="my-1" />
|
||||
</template>
|
||||
<ChatSettings />
|
||||
|
||||
Reference in new issue
Block a user