-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathfetch-from-repo.ts
More file actions
50 lines (48 loc) · 1.26 KB
/
fetch-from-repo.ts
File metadata and controls
50 lines (48 loc) · 1.26 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
// src/tools/fetch-from-repo.ts
import { z } from "zod";
import { RemoteIndexer } from "../repo/RemoteIndexer.js";
import { RepositoryFetcher } from "../repo/RepositoryFetcher.js";
export function createFetchFromRepoTool(
indexer: RemoteIndexer,
fetcher: RepositoryFetcher,
) {
return {
name: "fetchFromRepo",
description: "Fetch a file from a remote repository that has been indexed",
inputSchema: z.object({
path: z.string().describe("The file path in the repository"),
}),
handler: async ({ path }: { path: string }) => {
if (!indexer.fileExists(path)) {
return {
content: [
{
type: "text" as const,
text: `Error: File not found in index: ${path}`,
},
],
};
}
try {
const content = await fetcher.getFileContent(path);
return {
content: [
{
type: "text" as const,
text: `File: ${path}\n\n${content}`,
},
],
};
} catch (error: any) {
return {
content: [
{
type: "text" as const,
text: `Error fetching file: ${error.message}`,
},
],
};
}
},
};
}