bolt.diy/app/components/chat/UserMessage.tsx

54 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-11-21 21:05:35 +00:00
/*
* @ts-nocheck
* Preventing TS checks with files presented in the video for a better presentation.
*/
import { MODEL_REGEX, PROVIDER_REGEX } from '~/utils/constants';
2024-07-10 16:44:39 +00:00
import { Markdown } from './Markdown';
interface UserMessageProps {
content: string | Array<{ type: string; text?: string; image?: string }>;
2024-07-10 16:44:39 +00:00
}
export function UserMessage({ content }: UserMessageProps) {
if (Array.isArray(content)) {
const textItem = content.find((item) => item.type === 'text');
const textContent = sanitizeUserMessage(textItem?.text || '');
const images = content.filter((item) => item.type === 'image' && item.image);
return (
<div className="overflow-hidden pt-[4px]">
<div className="flex items-start gap-4">
<div className="flex-1">
<Markdown limitedMarkdown>{textContent}</Markdown>
</div>
{images.length > 0 && (
<div className="flex-shrink-0 w-[160px]">
{images.map((item, index) => (
<div key={index} className="relative">
<img
src={item.image}
alt={`Uploaded image ${index + 1}`}
className="w-full h-[160px] rounded-lg object-cover border border-bolt-elements-borderColor"
/>
</div>
))}
</div>
)}
</div>
</div>
);
}
2024-11-20 22:56:07 +00:00
const textContent = sanitizeUserMessage(content);
2024-11-19 00:55:28 +00:00
2024-07-10 16:44:39 +00:00
return (
<div className="overflow-hidden pt-[4px]">
2024-11-19 00:55:28 +00:00
<Markdown limitedMarkdown>{textContent}</Markdown>
2024-07-10 16:44:39 +00:00
</div>
);
}
function sanitizeUserMessage(content: string) {
2024-11-20 22:56:07 +00:00
return content.replace(MODEL_REGEX, '').replace(PROVIDER_REGEX, '');
}