diff --git a/packages/ui/src/utils/genericHelper.js b/packages/ui/src/utils/genericHelper.js index 7bf8998e..324cc112 100644 --- a/packages/ui/src/utils/genericHelper.js +++ b/packages/ui/src/utils/genericHelper.js @@ -401,3 +401,11 @@ export const getInputVariables = (paramValue) => { } return inputVariables } + +export const isValidURL = (url) => { + try { + return new URL(url) + } catch (err) { + return undefined + } +} diff --git a/packages/ui/src/views/chatmessage/ChatMessage.js b/packages/ui/src/views/chatmessage/ChatMessage.js index b89af7bb..9cfc917b 100644 --- a/packages/ui/src/views/chatmessage/ChatMessage.js +++ b/packages/ui/src/views/chatmessage/ChatMessage.js @@ -30,6 +30,7 @@ import { baseURL, maxScroll } from 'store/constant' import robotPNG from 'assets/images/robot.png' import userPNG from 'assets/images/account.png' +import { isValidURL } from 'utils/genericHelper' export const ChatMessage = ({ open, chatflowid, isDialog }) => { const theme = useTheme() @@ -59,6 +60,24 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => { setSourceDialogOpen(true) } + const onURLClick = (data) => { + window.open(data, '_blank') + } + + const removeDuplicateURL = (message) => { + const visitedURLs = [] + const newSourceDocuments = [] + message.sourceDocuments.forEach((source) => { + if (isValidURL(source.metadata.source) && !visitedURLs.includes(source.metadata.source)) { + visitedURLs.push(source.metadata.source) + newSourceDocuments.push(source) + } else if (!isValidURL(source.metadata.source)) { + newSourceDocuments.push(source) + } + }) + return newSourceDocuments + } + const scrollToBottom = () => { if (ps.current) { ps.current.scrollTo({ top: maxScroll }) @@ -319,17 +338,24 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => { {message.sourceDocuments && (