diff --git a/ee/tabby-ui/app/files/components/source-code-browser.tsx b/ee/tabby-ui/app/files/components/source-code-browser.tsx index 1f3ba1a97ca6..79fe2ac360e4 100644 --- a/ee/tabby-ui/app/files/components/source-code-browser.tsx +++ b/ee/tabby-ui/app/files/components/source-code-browser.tsx @@ -192,7 +192,12 @@ const SourceCodeBrowserContextProvider: React.FC = ({ }) } else { const setParams: Record = {} - let delList = ['redirect_filepath', 'redirect_git_url', 'line'] + let delList = [ + 'redirect_filepath', + 'redirect_git_url', + 'redirect_rev', + 'line' + ] if (options?.plain) { setParams['plain'] = '1' } else { @@ -501,13 +506,19 @@ const SourceCodeBrowserRenderer: React.FC = ({ const repos = await fetchAllRepositories() const redirect_filepath = searchParams.get('redirect_filepath') const redirect_git_url = searchParams.get('redirect_git_url') + const redirect_rev = searchParams.get('redirect_rev') if (repos?.length && redirect_filepath && redirect_git_url) { const targetRepo = repos.find(repo => repo.gitUrl === redirect_git_url) if (targetRepo) { - // use default rev - const defaultRef = getDefaultRepoRef(targetRepo.refs) - const refName = resolveRepoRef(defaultRef)?.name || '' + let refName = '' + if (redirect_rev) { + refName = redirect_rev + } else { + // use default rev + const defaultRef = getDefaultRepoRef(targetRepo.refs) + refName = resolveRepoRef(defaultRef)?.name || '' + } const lineRangeInHash = parseLineNumberFromHash(window.location.hash) const isValidLineHash = !isNil(lineRangeInHash?.start) diff --git a/ee/tabby-ui/app/search/components/assistant-message-section.tsx b/ee/tabby-ui/app/search/components/assistant-message-section.tsx index 920f21ad8ad4..450ad9cca536 100644 --- a/ee/tabby-ui/app/search/components/assistant-message-section.tsx +++ b/ee/tabby-ui/app/search/components/assistant-message-section.tsx @@ -24,6 +24,7 @@ import { RelevantCodeContext } from '@/lib/types' import { + buildCodeBrowserUrlForContext, cn, formatLineHashForCodeBrowser, getContent, @@ -172,13 +173,14 @@ export function AssistantMessageSection({ filepath: code.filepath, content: code.content, git_url: code.gitUrl, + commit: code.commit ?? undefined, extra: { scores: code?.extra?.scores } } }) ?? [] ) - }, [clientCode, message?.attachment?.code]) + }, [message?.attachment?.code]) const messageAttachmentClientCode = useMemo(() => { return clientCode?.map(o => ({ @@ -200,18 +202,8 @@ export function AssistantMessageSection({ const onCodeContextClick = (ctx: Context) => { if (!ctx.filepath) return - const url = new URL(`${window.location.origin}/files`) - const searchParams = new URLSearchParams() - searchParams.append('redirect_filepath', ctx.filepath) - searchParams.append('redirect_git_url', ctx.git_url) - url.search = searchParams.toString() - - const lineHash = formatLineHashForCodeBrowser(ctx.range) - if (lineHash) { - url.hash = lineHash - } - - window.open(url.toString()) + const url = buildCodeBrowserUrlForContext(window.location.origin, ctx) + window.open(url, '_blank') } const onCodeCitationMouseEnter = (index: number) => { @@ -232,6 +224,9 @@ export function AssistantMessageSection({ const searchParams = new URLSearchParams() searchParams.append('redirect_filepath', code.filepath) searchParams.append('redirect_git_url', code.gitUrl) + if (code.commit) { + searchParams.append('redirect_rev', code.commit) + } url.search = searchParams.toString() const lineHash = formatLineHashForCodeBrowser(range) diff --git a/ee/tabby-ui/components/chat/question-answer.tsx b/ee/tabby-ui/components/chat/question-answer.tsx index 527fdf39b09a..430c7de0353d 100644 --- a/ee/tabby-ui/components/chat/question-answer.tsx +++ b/ee/tabby-ui/components/chat/question-answer.tsx @@ -278,7 +278,8 @@ function AssistantMessageCard(props: AssistantMessageCardProps) { range: getRangeFromAttachmentCode(code), filepath: code.filepath, content: code.content, - git_url: code.gitUrl + git_url: code.gitUrl, + commit: code.commit ?? undefined })) ?? [] ) }, [message?.relevant_code]) diff --git a/ee/tabby-ui/lib/hooks/use-thread-run.ts b/ee/tabby-ui/lib/hooks/use-thread-run.ts index ae8a264ac610..5a834fa9bdf3 100644 --- a/ee/tabby-ui/lib/hooks/use-thread-run.ts +++ b/ee/tabby-ui/lib/hooks/use-thread-run.ts @@ -41,6 +41,7 @@ const CreateThreadAndRunSubscription = graphql(/* GraphQL */ ` hits { code { gitUrl + commit filepath language content @@ -118,6 +119,7 @@ const CreateThreadRunSubscription = graphql(/* GraphQL */ ` hits { code { gitUrl + commit filepath language content diff --git a/ee/tabby-ui/lib/tabby/query.ts b/ee/tabby-ui/lib/tabby/query.ts index 0e3bfa34e57e..ddfc77f0a4fa 100644 --- a/ee/tabby-ui/lib/tabby/query.ts +++ b/ee/tabby-ui/lib/tabby/query.ts @@ -402,6 +402,7 @@ export const listThreadMessages = graphql(/* GraphQL */ ` attachment { code { gitUrl + commit filepath language content diff --git a/ee/tabby-ui/lib/types/chat.ts b/ee/tabby-ui/lib/types/chat.ts index 515c923da74c..13c7ae624db5 100644 --- a/ee/tabby-ui/lib/types/chat.ts +++ b/ee/tabby-ui/lib/types/chat.ts @@ -19,6 +19,7 @@ export interface FileContext { range?: { start: number; end: number } content: string git_url: string + commit?: string } export type Context = FileContext diff --git a/ee/tabby-ui/lib/utils/index.ts b/ee/tabby-ui/lib/utils/index.ts index 27b850442794..9b7f57702a50 100644 --- a/ee/tabby-ui/lib/utils/index.ts +++ b/ee/tabby-ui/lib/utils/index.ts @@ -269,6 +269,10 @@ export function buildCodeBrowserUrlForContext( const searchParams = new URLSearchParams() searchParams.append('redirect_filepath', context.filepath) searchParams.append('redirect_git_url', context.git_url) + if (context.commit) { + searchParams.append('redirect_rev', context.commit) + } + url.search = searchParams.toString() url.hash = formatLineHashForCodeBrowser(context.range)