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

30 lines
893 B
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;
}
export function UserMessage({ content }: UserMessageProps) {
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>
);
}
2024-11-30 03:02:35 +00:00
function sanitizeUserMessage(content: string | Array<{ type: string; text?: string; image_url?: { url: string } }>) {
2024-11-19 00:55:28 +00:00
if (Array.isArray(content)) {
2024-11-30 03:02:35 +00:00
const textItem = content.find((item) => item.type === 'text');
2024-11-20 22:56:07 +00:00
return textItem?.text?.replace(MODEL_REGEX, '').replace(PROVIDER_REGEX, '') || '';
2024-11-19 00:55:28 +00:00
}
2024-11-30 03:02:35 +00:00
2024-11-20 22:56:07 +00:00
return content.replace(MODEL_REGEX, '').replace(PROVIDER_REGEX, '');
}