Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Fixed issue where opening GitLab file links would result in a 404. [#846](https://github.com/sourcebot-dev/sourcebot/pull/846)
- Fixed issue where file references in copied chat answers were relative paths instead of full browse URLs. [#847](https://github.com/sourcebot-dev/sourcebot/pull/847)

## [4.10.24] - 2026-02-03

Expand Down
8 changes: 4 additions & 4 deletions packages/web/src/app/api/(server)/chat/blocking/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ export const POST = apiHandler(async (request: NextRequest) => {
: undefined;
const answerText = answerPart?.text ?? '';

// Convert to portable markdown (replaces @file: references with markdown links)
const portableAnswer = convertLLMOutputToPortableMarkdown(answerText);

// Build the chat URL
// Build the base URL and chat URL
const baseUrl = env.AUTH_URL;

// Convert to portable markdown (replaces @file: references with markdown links)
const portableAnswer = convertLLMOutputToPortableMarkdown(answerText, baseUrl);
const chatUrl = `${baseUrl}/${org.domain}/chat/${chat.id}`;

logger.debug(`Completed blocking agent for chat ${chat.id}`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const AnswerCardComponent = forwardRef<HTMLDivElement, AnswerCardProps>(({
);

const onCopyAnswer = useCallback(() => {
const markdownText = convertLLMOutputToPortableMarkdown(answerText);
const baseUrl = typeof window !== 'undefined' ? window.location.origin : '';
const markdownText = convertLLMOutputToPortableMarkdown(answerText, baseUrl);
navigator.clipboard.writeText(markdownText);
toast({
description: "✅ Copied to clipboard",
Expand Down
24 changes: 21 additions & 3 deletions packages/web/src/features/chat/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CreateUIMessage, TextUIPart, UIMessagePart } from "ai";
import { Descendant, Editor, Point, Range, Transforms } from "slate";
import { ANSWER_TAG, FILE_REFERENCE_PREFIX, FILE_REFERENCE_REGEX } from "./constants";
import { getBrowsePath, BrowseHighlightRange } from "@/app/[domain]/browse/hooks/utils";
import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants";
import {
CustomEditor,
CustomText,
Expand Down Expand Up @@ -243,10 +245,10 @@ export const createFileReference = ({ repo, path, startLine, endLine }: { repo:
* Markdown format. Practically, this means converting references into Markdown
* links and removing the answer tag.
*/
export const convertLLMOutputToPortableMarkdown = (text: string): string => {
export const convertLLMOutputToPortableMarkdown = (text: string, baseUrl: string): string => {
return text
.replace(ANSWER_TAG, '')
.replace(FILE_REFERENCE_REGEX, (_, _repo, fileName, startLine, endLine) => {
.replace(FILE_REFERENCE_REGEX, (_, repo, fileName, startLine, endLine) => {
const displayName = fileName.split('/').pop() || fileName;

let linkText = displayName;
Expand All @@ -258,7 +260,23 @@ export const convertLLMOutputToPortableMarkdown = (text: string): string => {
}
}

return `[${linkText}](${fileName})`;
// Construct highlight range for line numbers
const highlightRange: BrowseHighlightRange | undefined = startLine ? {
start: { lineNumber: parseInt(startLine) },
end: { lineNumber: parseInt(endLine || startLine) },
} : undefined;

// Construct full browse URL
const browsePath = getBrowsePath({
repoName: repo,
path: fileName,
pathType: 'blob',
domain: SINGLE_TENANT_ORG_DOMAIN,
highlightRange,
});

const fullUrl = `${baseUrl}${browsePath}`;
return `[${linkText}](${fullUrl})`;
})
.trim();
}
Expand Down