-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathgetDiff.ts
More file actions
63 lines (55 loc) · 1.89 KB
/
Copy pathgetDiff.ts
File metadata and controls
63 lines (55 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { getDiff, GetDiffResult } from '@/features/git';
import { getDiffRequestSchema } from '@/features/git/schemas';
import { isServiceError } from '@/lib/utils';
import description from './getDiff.txt';
import { formatDiffAsGitDiff } from './utils';
import { logger } from './logger';
import { ToolDefinition } from './types';
import { CodeHostType } from '@sourcebot/db';
import { getRepoInfoByName } from '@/actions';
export type GetDiffRepoInfo = {
name: string;
displayName: string;
codeHostType: CodeHostType;
};
export type GetDiffMetadata = GetDiffResult & {
repo: string;
repoInfo: GetDiffRepoInfo;
base: string;
head: string;
};
export const getDiffDefinition: ToolDefinition<'get_diff', typeof getDiffRequestSchema.shape, GetDiffMetadata> = {
name: 'get_diff',
title: 'Get diff',
isReadOnly: true,
isIdempotent: true,
description,
inputSchema: getDiffRequestSchema,
execute: async ({ repo, base, head }, _context) => {
logger.debug('get_diff', { repo, base, head });
const response = await getDiff({ repo, base, head });
if (isServiceError(response)) {
throw new Error(response.message);
}
const repoInfoResult = await getRepoInfoByName(repo);
if (isServiceError(repoInfoResult) || !repoInfoResult) {
throw new Error(`Repository "${repo}" not found.`);
}
const repoInfo: GetDiffRepoInfo = {
name: repoInfoResult.name,
displayName: repoInfoResult.displayName ?? repoInfoResult.name,
codeHostType: repoInfoResult.codeHostType,
};
const gitDiffOutput = formatDiffAsGitDiff(response);
return {
output: gitDiffOutput,
metadata: {
...response,
repo,
repoInfo,
base,
head,
},
};
},
};