Skip to content

Commit 83bb133

Browse files
fix(web): Fix issue where preview panel and ask file sources were failing to load (#813)
1 parent a8c26dc commit 83bb133

File tree

10 files changed

+37
-34
lines changed

10 files changed

+37
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- Fixed issue where searching for refs/heads/<default_branch> would return no matches. [#809](https://github.com/sourcebot-dev/sourcebot/pull/809)
12+
- Fixed issue where source files would fail to load in the search preview panel and ask client. [#812](https://github.com/sourcebot-dev/sourcebot/issues/812)
1213

1314
## [4.10.19] - 2026-01-28
1415

packages/web/src/app/[domain]/browse/[...path]/components/codePreviewPanel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ interface CodePreviewPanelProps {
1515
export const CodePreviewPanel = async ({ path, repoName, revisionName }: CodePreviewPanelProps) => {
1616
const [fileSourceResponse, repoInfoResponse] = await Promise.all([
1717
getFileSource({
18-
fileName: path,
19-
repository: repoName,
20-
branch: revisionName,
18+
path,
19+
repo: repoName,
20+
ref: revisionName,
2121
}),
2222
getRepoInfoByName(repoName),
2323
]);

packages/web/src/app/[domain]/search/components/codePreviewPanel/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export const CodePreviewPanel = ({
3232
queryKey: ["source", previewedFile, branch],
3333
queryFn: () => unwrapServiceError(
3434
getFileSource({
35-
fileName: previewedFile.fileName.text,
36-
repository: previewedFile.repository,
37-
branch,
35+
path: previewedFile.fileName.text,
36+
repo: previewedFile.repository,
37+
ref: branch,
3838
})
3939
),
4040
select: (data) => {

packages/web/src/app/api/(server)/source/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export const GET = async (request: NextRequest) => {
2929

3030
const { repo, path, ref } = parsed.data;
3131
const response = await getFileSource({
32-
fileName: path,
33-
repository: repo,
34-
branch: ref,
32+
path,
33+
repo,
34+
ref,
3535
});
3636

3737
if (isServiceError(response)) {

packages/web/src/features/agents/review-agent/nodes/fetchFileContent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const fetchFileContent = async (pr_payload: sourcebot_pr_payload, filenam
1111

1212
const repoPath = pr_payload.hostDomain + "/" + pr_payload.owner + "/" + pr_payload.repo;
1313
const fileSourceRequest = {
14-
fileName: filename,
15-
repository: repoPath,
14+
path: filename,
15+
repo: repoPath,
1616
}
1717
logger.debug(JSON.stringify(fileSourceRequest, null, 2));
1818

packages/web/src/features/chat/agent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ ${addLineNumbers(file.source)}
248248

249249
const resolveFileSource = async ({ path, repo, revision }: FileSource) => {
250250
const fileSource = await getFileSource({
251-
fileName: path,
252-
repository: repo,
253-
branch: revision,
251+
path,
252+
repo,
253+
ref: revision,
254254
});
255255

256256
if (isServiceError(fileSource)) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ const ReferencedSourcesListViewComponent = ({
7676
queries: sources.map((file) => ({
7777
queryKey: ['fileSource', file.path, file.repo, file.revision],
7878
queryFn: () => unwrapServiceError(getFileSource({
79-
fileName: file.path,
80-
repository: file.repo,
81-
branch: file.revision,
79+
path: file.path,
80+
repo: file.repo,
81+
ref: file.revision,
8282
})),
8383
staleTime: Infinity,
8484
})),

packages/web/src/features/chat/tools.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ export const readFilesTool = tool({
111111

112112
const responses = await Promise.all(paths.map(async (path) => {
113113
return getFileSource({
114-
fileName: path,
115-
repository,
116-
branch: revision,
114+
path,
115+
repo: repository,
116+
ref: revision,
117117
// @todo(mt): handle multi-tenancy.
118118
});
119119
}));

packages/web/src/features/search/fileSourceApi.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ import escapeStringRegexp from "escape-string-regexp";
1212
// This will allow us to support permalinks to files at a specific revision that may not be indexed
1313
// by zoekt. We should also refactor this out of the /search folder.
1414

15-
export const getFileSource = async ({ fileName, repository, branch }: FileSourceRequest): Promise<FileSourceResponse | ServiceError> => sew(() =>
15+
export const getFileSource = async ({ path, repo, ref }: FileSourceRequest): Promise<FileSourceResponse | ServiceError> => sew(() =>
1616
withOptionalAuthV2(async () => {
1717
const query: QueryIR = {
1818
and: {
1919
children: [
2020
{
2121
repo: {
22-
regexp: `^${escapeStringRegexp(repository)}$`,
22+
regexp: `^${escapeStringRegexp(repo)}$`,
2323
},
2424
},
2525
{
2626
substring: {
27-
pattern: fileName,
27+
pattern: path,
2828
case_sensitive: true,
2929
file_name: true,
3030
content: false,
3131
}
3232
},
33-
...(branch ? [{
33+
...(ref ? [{
3434
branch: {
35-
pattern: branch,
35+
pattern: ref,
3636
exact: true,
3737
},
3838
}]: [])
@@ -56,7 +56,7 @@ export const getFileSource = async ({ fileName, repository, branch }: FileSource
5656
const files = searchResponse.files;
5757

5858
if (!files || files.length === 0) {
59-
return fileNotFound(fileName, repository);
59+
return fileNotFound(path, repo);
6060
}
6161

6262
const file = files[0];
@@ -72,12 +72,12 @@ export const getFileSource = async ({ fileName, repository, branch }: FileSource
7272
return {
7373
source,
7474
language,
75-
path: fileName,
76-
repo: repository,
75+
path,
76+
repo,
7777
repoCodeHostType: repoInfo.codeHostType,
7878
repoDisplayName: repoInfo.displayName,
7979
repoExternalWebUrl: repoInfo.webUrl,
80-
branch,
80+
branch: ref,
8181
webUrl: file.webUrl,
8282
externalWebUrl: file.externalWebUrl,
8383
} satisfies FileSourceResponse;

packages/web/src/features/search/types.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ export const streamedSearchResponseSchema = z.discriminatedUnion('type', [
145145
]);
146146
export type StreamedSearchResponse = z.infer<typeof streamedSearchResponseSchema>;
147147

148-
export interface FileSourceRequest {
149-
fileName: string;
150-
repository: string;
151-
branch?: string;
152-
}
148+
149+
export const fileSourceRequestSchema = z.object({
150+
path: z.string(),
151+
repo: z.string(),
152+
ref: z.string().optional(),
153+
});
154+
export type FileSourceRequest = z.infer<typeof fileSourceRequestSchema>;
153155

154156
export const fileSourceResponseSchema = z.object({
155157
source: z.string(),

0 commit comments

Comments
 (0)