diff --git a/src/lib/components/chat/ChatMessage.svelte b/src/lib/components/chat/ChatMessage.svelte index ff4f9f37915..05fe2ad43dd 100644 --- a/src/lib/components/chat/ChatMessage.svelte +++ b/src/lib/components/chat/ChatMessage.svelte @@ -23,10 +23,12 @@ import OpenWebSearchResults from "../OpenWebSearchResults.svelte"; import { + MessageUpdateType, MessageWebSearchUpdateType, type MessageToolUpdate, type MessageWebSearchSourcesUpdate, type MessageWebSearchUpdate, + type MessageFinalAnswerUpdate, } from "$lib/types/MessageUpdate"; import { base } from "$app/paths"; import { useConvTreeStore } from "$lib/stores/convTree"; @@ -149,6 +151,10 @@ $: searchUpdates = (message.updates?.filter(({ type }) => type === "webSearch") ?? []) as MessageWebSearchUpdate[]; + $: messageFinalAnswer = message.updates?.find( + ({ type }) => type === MessageUpdateType.FinalAnswer + ) as MessageFinalAnswerUpdate; + // filter all updates with type === "tool" then group them by uuid field $: toolUpdates = message.updates @@ -314,7 +320,29 @@ {/each} {/if} + + + {#if messageFinalAnswer?.webSources && messageFinalAnswer.webSources.length} +
+
Sources:
+ {#each messageFinalAnswer.webSources as { uri, title }} + + {title} favicon +
{title}
+
+ {/each} +
+ {/if} + {#if !loading && (message.content || toolUpdates)}
{ + const uri = chunk.web?.uri ?? chunk.retrievedContext?.uri; + const title = chunk.web?.title ?? chunk.retrievedContext?.title; + + if (!uri || !title) { + return null; + } + + return { + uri, + title, + }; + }) + .filter((source) => source !== null); + + if (candidateWebSources) { + webSources.push(...candidateWebSources); + } + const content = firstPart.text; generatedText += content; - const output: TextGenerationStreamOutput = { + const output: TextGenerationStreamOutputWithToolsAndWebSources = { token: { id: tokenId++, text: content, @@ -194,6 +215,7 @@ export function endpointVertex(input: z.input