import React, { useEffect } from "react";
import { motion } from "framer-motion";
import { ArrowUpRight, Globe, Text } from "lucide-react";
import { convertRemToPixels } from "@/lib/utils";
import { SpaceIcon } from "@/assets/Memories";
import Markdown from "react-markdown";
import { ChatHistory } from "../../types/memory";
export function ChatAnswer({
children: message,
sources,
loading = false,
}: {
children: string;
sources?: ChatHistory['answer']['sources'];
loading?: boolean;
}) {
return (
{loading ? (
) : (
{message}
)}
{!loading && sources && sources?.length > 0 && (
<>
Related Memories
>
)}
);
}
export function ChatQuestion({ children }: { children: string }) {
return (
200 ? "text-xl" : "text-2xl"}`}
>
{children}
);
}
export function ChatMessage({
children,
isLast = false,
index,
}: {
children: React.ReactNode | React.ReactNode[];
isLast?: boolean;
index: number;
}) {
const messageRef = React.useRef(null);
useEffect(() => {
if (!isLast) return;
messageRef.current?.parentElement?.scrollTo({
top: messageRef.current?.offsetTop,
behavior: "smooth",
});
}, []);
return (
{children}
);
}
function MessageSkeleton() {
return (
);
}
function cleanUrl(url: string) {
if (url.startsWith("https://")) {
url = url.slice(8);
} else if (url.startsWith("http://")) {
url = url.slice(7);
}
if (url.endsWith("/")) {
url = url.slice(0, -1);
}
return url;
}