@@ -6,8 +6,9 @@ import { FileSourceResponse, getFileSource } from '@/features/git';
66import { findSearchBasedSymbolDefinitions , findSearchBasedSymbolReferences } from "../codeNav/api" ;
77import { addLineNumbers , buildSearchQuery } from "./utils" ;
88import { toolNames } from "./constants" ;
9- import { getRepos } from "@/actions" ;
10- import Fuse from "fuse.js" ;
9+ import { listReposQueryParamsSchema } from "@/lib/schemas" ;
10+ import { ListReposQueryParams } from "@/lib/types" ;
11+ import { listRepos } from "@/app/api/(server)/repos/listReposApi" ;
1112
1213// @NOTE : When adding a new tool, follow these steps:
1314// 1. Add the tool to the `toolNames` constant in `constants.ts`.
@@ -217,58 +218,21 @@ export type SearchCodeToolInput = InferToolInput<ReturnType<typeof createCodeSea
217218export type SearchCodeToolOutput = InferToolOutput < ReturnType < typeof createCodeSearchTool > > ;
218219export type SearchCodeToolUIPart = ToolUIPart < { [ toolNames . searchCode ] : SearchCodeTool } > ;
219220
220- export const searchReposTool = tool ( {
221- description : `Search for repositories by name using fuzzy search. This helps find repositories in the codebase when you know part of their name.` ,
222- inputSchema : z . object ( {
223- query : z . string ( ) . describe ( "The search query to find repositories by name (supports fuzzy matching)" ) ,
224- limit : z . number ( ) . default ( 10 ) . describe ( "Maximum number of repositories to return (default: 10)" )
225- } ) ,
226- execute : async ( { query, limit } ) => {
227- const reposResponse = await getRepos ( ) ;
228-
229- if ( isServiceError ( reposResponse ) ) {
230- return reposResponse ;
231- }
232-
233- // Configure Fuse.js for fuzzy searching
234- const fuse = new Fuse ( reposResponse , {
235- keys : [
236- { name : 'repoName' , weight : 0.7 } ,
237- { name : 'repoDisplayName' , weight : 0.3 }
238- ] ,
239- threshold : 0.4 , // Lower threshold = more strict matching
240- includeScore : true ,
241- minMatchCharLength : 1 ,
242- } ) ;
243-
244- const searchResults = fuse . search ( query , { limit : limit ?? 10 } ) ;
245-
246- searchResults . sort ( ( a , b ) => ( a . score ?? 0 ) - ( b . score ?? 0 ) ) ;
247-
248- return searchResults . map ( ( { item } ) => item . repoName ) ;
249- }
250- } ) ;
251-
252- export type SearchReposTool = InferUITool < typeof searchReposTool > ;
253- export type SearchReposToolInput = InferToolInput < typeof searchReposTool > ;
254- export type SearchReposToolOutput = InferToolOutput < typeof searchReposTool > ;
255- export type SearchReposToolUIPart = ToolUIPart < { [ toolNames . searchRepos ] : SearchReposTool } > ;
256-
257- export const listAllReposTool = tool ( {
258- description : `Lists all repositories in the codebase. This provides a complete overview of all available repositories.` ,
259- inputSchema : z . object ( { } ) ,
260- execute : async ( ) => {
261- const reposResponse = await getRepos ( ) ;
221+ export const listReposTool = tool ( {
222+ description : 'Lists repositories in the organization with optional filtering and pagination.' ,
223+ inputSchema : listReposQueryParamsSchema ,
224+ execute : async ( request : ListReposQueryParams ) => {
225+ const reposResponse = await listRepos ( request ) ;
262226
263227 if ( isServiceError ( reposResponse ) ) {
264228 return reposResponse ;
265229 }
266230
267- return reposResponse . map ( ( repo ) => repo . repoName ) ;
231+ return reposResponse . data . map ( ( repo ) => repo . repoName ) ;
268232 }
269233} ) ;
270234
271- export type ListAllReposTool = InferUITool < typeof listAllReposTool > ;
272- export type ListAllReposToolInput = InferToolInput < typeof listAllReposTool > ;
273- export type ListAllReposToolOutput = InferToolOutput < typeof listAllReposTool > ;
274- export type ListAllReposToolUIPart = ToolUIPart < { [ toolNames . listAllRepos ] : ListAllReposTool } > ;
235+ export type ListReposTool = InferUITool < typeof listReposTool > ;
236+ export type ListReposToolInput = InferToolInput < typeof listReposTool > ;
237+ export type ListReposToolOutput = InferToolOutput < typeof listReposTool > ;
238+ export type ListReposToolUIPart = ToolUIPart < { [ toolNames . listRepos ] : ListReposTool } > ;
0 commit comments