Skip to content

Commit 4ffb9d0

Browse files
msukkariclaude
andcommitted
feat(web): add sourceOverride to getFileSource and getTree
Extend the sourceOverride pattern to getFileSource and getTree so internal callers (chat AI agent) can tag audit events with the correct source instead of relying on the HTTP header. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5f487a3 commit 4ffb9d0

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const createAgentStream = async ({
171171
path: source.path,
172172
repo: source.repo,
173173
ref: source.revision,
174-
});
174+
}, { sourceOverride: 'sourcebot-ask-agent' });
175175

176176
if (isServiceError(fileSource)) {
177177
logger.error("Error fetching file source:", fileSource);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const readFilesTool = tool({
115115
path,
116116
repo: repository,
117117
ref: revision,
118-
});
118+
}, { sourceOverride: 'sourcebot-ask-agent' });
119119
}));
120120

121121
if (responses.some(isServiceError)) {
@@ -221,7 +221,8 @@ export const createCodeSearchTool = (selectedRepos: string[]) => tool({
221221
contextLines: 3,
222222
isCaseSensitivityEnabled: caseSensitive,
223223
isRegexEnabled: useRegex,
224-
}
224+
},
225+
sourceOverride: 'sourcebot-ask-agent',
225226
});
226227

227228
if (isServiceError(response)) {
@@ -253,7 +254,7 @@ export const listReposTool = tool({
253254
description: 'Lists repositories in the organization with optional filtering and pagination.',
254255
inputSchema: listReposQueryParamsSchema,
255256
execute: async (request: ListReposQueryParams) => {
256-
const reposResponse = await listRepos(request);
257+
const reposResponse = await listRepos({ ...request, sourceOverride: 'sourcebot-ask-agent' });
257258

258259
if (isServiceError(reposResponse)) {
259260
return reposResponse;

packages/web/src/features/git/getFileSourceApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export const fileSourceResponseSchema = z.object({
3333
});
3434
export type FileSourceResponse = z.infer<typeof fileSourceResponseSchema>;
3535

36-
export const getFileSource = async ({ path: filePath, repo: repoName, ref }: FileSourceRequest): Promise<FileSourceResponse | ServiceError> => sew(() => withOptionalAuthV2(async ({ org, prisma, user }) => {
36+
export const getFileSource = async ({ path: filePath, repo: repoName, ref }: FileSourceRequest, { sourceOverride }: { sourceOverride?: string } = {}): Promise<FileSourceResponse | ServiceError> => sew(() => withOptionalAuthV2(async ({ org, prisma, user }) => {
3737
if (user) {
38-
const source = (await headers()).get('X-Sourcebot-Client-Source') ?? undefined;
38+
const source = sourceOverride ?? (await headers()).get('X-Sourcebot-Client-Source') ?? undefined;
3939
getAuditService().createAudit({
4040
action: 'user.fetched_file_source',
4141
actor: { id: user.id, type: 'user' },

packages/web/src/features/git/getTreeApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export type GetTreeResponse = z.infer<typeof getTreeResponseSchema>;
2626
* repo/revision, including intermediate directories needed to connect them
2727
* into a single tree.
2828
*/
29-
export const getTree = async ({ repoName, revisionName, paths }: GetTreeRequest): Promise<GetTreeResponse | ServiceError> => sew(() =>
29+
export const getTree = async ({ repoName, revisionName, paths }: GetTreeRequest, { sourceOverride }: { sourceOverride?: string } = {}): Promise<GetTreeResponse | ServiceError> => sew(() =>
3030
withOptionalAuthV2(async ({ org, prisma, user }) => {
3131
if (user) {
32-
const source = (await headers()).get('X-Sourcebot-Client-Source') ?? undefined;
32+
const source = sourceOverride ?? (await headers()).get('X-Sourcebot-Client-Source') ?? undefined;
3333
getAuditService().createAudit({
3434
action: 'user.fetched_file_tree',
3535
actor: { id: user.id, type: 'user' },

0 commit comments

Comments
 (0)