mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-26 01:46:01 +00:00
38ace61617
* feat(web): add conversation export as Markdown and JSON (#976) Add the ability to export conversations in Markdown and JSON formats, accessible from both the chat header and the sidebar context menu. - Add export utility (formatThreadAsMarkdown, formatThreadAsJSON) with support for user/assistant messages, thinking blocks, and tool calls - Add ExportTrigger component in chat header (appears when messages exist) - Add Export submenu to sidebar dropdown (fetches full thread state on demand) - Add i18n translations for en-US and zh-CN Closes #976 Made-with: Cursor * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update thread creation timestamp to updated_at --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
"use client";
|
|
|
|
import { Download, FileJson, FileText } from "lucide-react";
|
|
import { useCallback } from "react";
|
|
import { toast } from "sonner";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { useI18n } from "@/core/i18n/hooks";
|
|
import {
|
|
exportThreadAsJSON,
|
|
exportThreadAsMarkdown,
|
|
} from "@/core/threads/export";
|
|
import type { AgentThread } from "@/core/threads/types";
|
|
|
|
import { useThread } from "./messages/context";
|
|
import { Tooltip } from "./tooltip";
|
|
|
|
export function ExportTrigger({ threadId }: { threadId: string }) {
|
|
const { t } = useI18n();
|
|
const { thread } = useThread();
|
|
|
|
const messages = thread.messages;
|
|
|
|
const handleExport = useCallback(
|
|
(format: "markdown" | "json") => {
|
|
if (messages.length === 0) {
|
|
toast.error(t.conversation.noMessages);
|
|
return;
|
|
}
|
|
const agentThread = {
|
|
thread_id: threadId,
|
|
updated_at: new Date().toISOString(),
|
|
values: thread.values,
|
|
} as AgentThread;
|
|
|
|
if (format === "markdown") {
|
|
exportThreadAsMarkdown(agentThread, messages);
|
|
} else {
|
|
exportThreadAsJSON(agentThread, messages);
|
|
}
|
|
toast.success(t.common.exportSuccess);
|
|
},
|
|
[messages, thread.values, threadId, t],
|
|
);
|
|
|
|
if (messages.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<DropdownMenu>
|
|
<Tooltip content={t.common.export}>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
className="text-muted-foreground hover:text-foreground"
|
|
variant="ghost"
|
|
>
|
|
<Download />
|
|
{t.common.export}
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
</Tooltip>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem onSelect={() => handleExport("markdown")}>
|
|
<FileText className="text-muted-foreground" />
|
|
<span>{t.common.exportAsMarkdown}</span>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onSelect={() => handleExport("json")}>
|
|
<FileJson className="text-muted-foreground" />
|
|
<span>{t.common.exportAsJSON}</span>
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
}
|