import { For, onMount } from 'solid-js'; import { Marked } from '@ts-stack/markdown'; import { FileUpload } from '../Bot'; import { cloneDeep } from 'lodash'; type Props = { apiHost?: string; chatflowid: string; chatId: string; agentName: string; agentMessage: string; agentArtifacts?: FileUpload[]; backgroundColor?: string; textColor?: string; fontSize?: number; renderHTML?: boolean; }; const defaultBackgroundColor = '#f7f8ff'; const defaultTextColor = '#303235'; const defaultFontSize = 16; export const AgentReasoningBubble = (props: Props) => { let botMessageEl: HTMLDivElement | undefined; Marked.setOptions({ isNoP: true, sanitize: props.renderHTML !== undefined ? !props.renderHTML : true }); onMount(() => { if (botMessageEl) { botMessageEl.innerHTML = Marked.parse(`**✅ ${props.agentName}** \n\n${props.agentMessage}`); botMessageEl.querySelectorAll('a').forEach((link) => { link.target = '_blank'; }); } }); const agentReasoningArtifacts = (artifacts: FileUpload[]) => { const newArtifacts = cloneDeep(artifacts); for (let i = 0; i < newArtifacts.length; i++) { const artifact = newArtifacts[i]; if (artifact && (artifact.type === 'png' || artifact.type === 'jpeg')) { const data = artifact.data as string; newArtifacts[i].data = `${props.apiHost}/api/v1/get-upload-file?chatflowId=${props.chatflowid}&chatId=${props.chatId}&fileName=${data.replace( 'FILE-STORAGE::', '', )}`; } } return newArtifacts; }; const renderArtifacts = (item: Partial) => { if (item.type === 'png' || item.type === 'jpeg') { const src = item.data as string; return (
); } else if (item.type === 'html') { const src = item.data as string; return (
); } else { const src = item.data as string; return ( ); } }; return (
{props.agentArtifacts && (
{(item) => { return item !== null ? <>{renderArtifacts(item)} : null; }}
)} {props.agentMessage && ( )}
); };