Skip to content

Commit 128fe4d

Browse files
committed
feat(chat): Enhance file reference handling in markdown conversion and add URL builder for code hosts
1 parent 2c0b583 commit 128fe4d

4 files changed

Lines changed: 618 additions & 7 deletions

File tree

packages/web/src/features/chat/components/chatThread/answerCard.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ import useCaptureEvent from "@/hooks/useCaptureEvent";
1818
import { LangfuseWeb } from "langfuse";
1919
import { env } from "@sourcebot/shared/client";
2020
import isEqual from "fast-deep-equal/react";
21+
import { FileSource } from "../../types";
2122

2223
interface AnswerCardProps {
2324
answerText: string;
2425
messageId: string;
2526
chatId: string;
2627
traceId?: string;
28+
sources?: FileSource[];
2729
}
2830

2931
const langfuseWeb = (env.NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT !== undefined && env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY) ? new LangfuseWeb({
@@ -35,7 +37,8 @@ const AnswerCardComponent = forwardRef<HTMLDivElement, AnswerCardProps>(({
3537
answerText,
3638
messageId,
3739
chatId,
38-
traceId,
40+
traceId,
41+
sources,
3942
}, forwardedRef) => {
4043
const markdownRendererRef = useRef<HTMLDivElement>(null);
4144
const { tocItems, activeId } = useExtractTOCItems({ target: markdownRendererRef.current });
@@ -51,13 +54,13 @@ const AnswerCardComponent = forwardRef<HTMLDivElement, AnswerCardProps>(({
5154
);
5255

5356
const onCopyAnswer = useCallback(() => {
54-
const markdownText = convertLLMOutputToPortableMarkdown(answerText);
57+
const markdownText = convertLLMOutputToPortableMarkdown(answerText, { sources });
5558
navigator.clipboard.writeText(markdownText);
5659
toast({
5760
description: "✅ Copied to clipboard",
5861
});
5962
return true;
60-
}, [answerText, toast]);
63+
}, [answerText, sources, toast]);
6164

6265
const onFeedback = useCallback(async (feedbackType: 'like' | 'dislike') => {
6366
setIsSubmittingFeedback(true);

packages/web/src/features/chat/components/chatThread/chatThreadListItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ const ChatThreadListItemComponent = forwardRef<HTMLDivElement, ChatThreadListIte
364364
chatId={chatId}
365365
messageId={assistantMessage.id}
366366
traceId={assistantMessage.metadata?.traceId}
367+
sources={sources.filter((source) => source.type === 'file')}
367368
/>
368369
) : !isStreaming && (
369370
<p className="text-destructive">Error: No answer response was provided</p>

0 commit comments

Comments
 (0)