diff --git a/frontend/src/components/console/task/message-userinput.tsx b/frontend/src/components/console/task/message-userinput.tsx index 0bc6163c..3386b51a 100644 --- a/frontend/src/components/console/task/message-userinput.tsx +++ b/frontend/src/components/console/task/message-userinput.tsx @@ -2,13 +2,19 @@ import ReactMarkdown from "react-markdown" import remarkGfm from "remark-gfm" import "@/utils/plain-text-markdown.css" import type { MessageType } from "./message" -import { IconFile } from "@tabler/icons-react" +import { IconCopy, IconFile } from "@tabler/icons-react" import { isTaskImageAttachment, type TaskUserInputAttachment } from "./task-shared" import React from "react" import { TaskAttachmentPreviewDialog, type TaskAttachmentPreviewFile } from "./task-attachment-preview-dialog" +import { Button } from "@/components/ui/button" +import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip" +import { toast } from "sonner" +import { useTranslation } from "react-i18next" export const UserInputMessageItem = ({ message }: { message: MessageType }) => { + const { t } = useTranslation() const [previewFile, setPreviewFile] = React.useState(null) + const content = typeof message.data.content === "string" ? message.data.content : "" const attachments = Array.isArray(message.data.attachments) ? message.data.attachments.filter((attachment): attachment is TaskUserInputAttachment => ( !!attachment @@ -19,47 +25,80 @@ export const UserInputMessageItem = ({ message }: { message: MessageType }) => { )) : [] + const handleCopy = async () => { + if (!content) return + + try { + await navigator.clipboard.writeText(content) + toast.success(t("taskDetail.messages.copyUserInputSuccess")) + } catch (error) { + toast.error(t("taskDetail.messages.copyUserInputFailed")) + console.error("Copy user input failed:", error) + } + } + return ( -
- {message.data.content && ( -
- ( -

{line}

- )) - } else { - return

{children}

+
+
+ {content && ( +
+ ( +

{line}

+ )) + } else { + return

{children}

+ } } - } - }}> - {message.data.content} -
-
- )} - {attachments.length > 0 && ( -
- {attachments.map((attachment, index) => ( - - ))} + }}> + {content} + +
+ )} + {attachments.length > 0 && ( +
+ {attachments.map((attachment, index) => ( + + ))} +
+ )} +
+ {content && ( +
+ + + + + {t("taskDetail.messages.copyUserInput")} +
)}