import Markdown from "../../Common/Markdown"
import React from "react"
import { Tag, Image, Tooltip, Collapse, Popover } from "antd"
import { WebSearch } from "./WebSearch"
import {
CheckIcon,
ClipboardIcon,
InfoIcon,
Pen,
PlayIcon,
RotateCcw,
Square
} from "lucide-react"
import { EditMessageForm } from "./EditMessageForm"
import { useTranslation } from "react-i18next"
import { MessageSource } from "./MessageSource"
import { useTTS } from "@/hooks/useTTS"
import { tagColors } from "@/utils/color"
import { removeModelSuffix } from "@/db/models"
import { GenerationInfo } from "./GenerationInfo"
import { parseReasoning } from "@/libs/reasoning"
import { humanizeMilliseconds } from "@/utils/humanize-milliseconds"
type Props = {
message: string
message_type?: string
hideCopy?: boolean
botAvatar?: JSX.Element
userAvatar?: JSX.Element
isBot: boolean
name: string
images?: string[]
currentMessageIndex: number
totalMessages: number
onRengerate: () => void
onEditFormSubmit: (value: string, isSend: boolean) => void
isProcessing: boolean
webSearch?: {}
isSearchingInternet?: boolean
webSources?: any[]
iodSources?: any[]
hideEditAndRegenerate?: boolean
onSourceClick?: (source: any) => void
isTTSEnabled?: boolean
generationInfo?: any
isStreaming: boolean
reasoningTimeTaken?: number
}
export const PlaygroundMessage = (props: Props) => {
const [isBtnPressed, setIsBtnPressed] = React.useState(false)
const [editMode, setEditMode] = React.useState(false)
const { t } = useTranslation("common")
const { cancel, isSpeaking, speak } = useTTS()
return (
{/*
*/}
{props.isBot ? (
!props.botAvatar ? (
) : (
props.botAvatar
)
) : !props.userAvatar ? (
) : (
props.userAvatar
)}
{props.isBot
? props.name === "chrome::gemini-nano::page-assist"
? "Gemini Nano"
: removeModelSuffix(
props.name?.replaceAll(/accounts\/[^\/]+\/models\//g, "")
)
: "You"}
{props.isBot &&
props.isSearchingInternet &&
props.currentMessageIndex === props.totalMessages - 1 ? (
) : null}
{props?.message_type && (
{t(`copilot.${props?.message_type}`)}
)}
{!editMode ? (
props.isBot ? (
<>
{parseReasoning(props.message).map((e, i) => {
if (e.type === "reasoning") {
return (
{t("reasoning.thinking")}
) : (
t("reasoning.thought", {
time: humanizeMilliseconds(
props.reasoningTimeTaken
)
})
),
children:
}
]}
/>
)
}
return
})}
>
) : (
{props.message}
)
) : (
setEditMode(false)}
isBot={props.isBot}
/>
)}
{/* source if available */}
{props.images &&
props.images.filter((img) => img.length > 0).length > 0 && (
{props.images
.filter((image) => image.length > 0)
.map((image, index) => (
))}
)}
{props.isBot && props?.webSources && props?.webSources.length > 0 && (
{t("webCitations")}
),
children: (
{props?.webSources?.map((source, index) => (
))}
)
}
]}
/>
)}
{props.isBot && props?.iodSources && props?.iodSources.length > 0 && (
{t("iodCitations")}
),
children: (
{props?.iodSources?.map((source, index) => (
))}
)
}
]}
/>
)}
{!props.isProcessing && !editMode ? (
{props.isTTSEnabled && (
)}
{props.isBot && (
<>
{!props.hideCopy && (
)}
{props.generationInfo && (
}
title={t("generationInfo")}>
)}
{!props.hideEditAndRegenerate &&
props.currentMessageIndex === props.totalMessages - 1 && (
)}
>
)}
{!props.hideEditAndRegenerate && (
)}
) : (
// add invisible div to prevent layout shift
)}
{/* */}
)
}