|
1 | | -import { IFunctionData } from "../application/interfaces"; |
2 | | -import { Logger } from "../infrastructure/logger/logger"; |
3 | | -import { CodeRepository } from "../infrastructure/repository/code"; |
4 | | -import { CodeStructureMapper } from "./code-structure.mapper"; |
5 | | -import { EmbeddingService } from "./embedding"; |
6 | | -import { TypeScriptAtsMapper } from "./typescript-ats.service"; |
7 | | -import { getAPIKeyAndModel } from "../utils/utils"; |
8 | | -import { LogLevel } from "./telemetry"; |
| 1 | +// import { IFunctionData } from "../application/interfaces"; |
| 2 | +// import { Logger } from "../infrastructure/logger/logger"; |
| 3 | +// import { CodeRepository } from "../infrastructure/repository/code"; |
| 4 | +// import { CodeStructureMapper } from "./code-structure.mapper"; |
| 5 | +// import { EmbeddingService } from "./embedding"; |
| 6 | +// import { TypeScriptAtsMapper } from "./typescript-ats.service"; |
| 7 | +// import { getAPIKeyAndModel } from "../utils/utils"; |
| 8 | +// import { LogLevel } from "./telemetry"; |
9 | 9 |
|
10 | | -/** |
11 | | - * Provides a centralized service for managing code indexing, including building function structure maps, |
12 | | - * generating function descriptions, generating embeddings, and inserting function data into a database. |
13 | | - */ |
14 | | -export class CodeIndexingService { |
15 | | - logger: Logger; |
16 | | - embeddingService: EmbeddingService; |
17 | | - codeRepository: CodeRepository | undefined; |
18 | | - private static instance: CodeIndexingService; |
19 | | - constructor() { |
20 | | - this.logger = Logger.initialize("CodeIndexingService", { |
21 | | - minLevel: LogLevel.DEBUG, |
22 | | - }); |
23 | | - const { apiKey, model } = getAPIKeyAndModel("gemini"); |
24 | | - this.embeddingService = new EmbeddingService(apiKey); |
25 | | - } |
| 10 | +// /** |
| 11 | +// * Provides a centralized service for managing code indexing, including building function structure maps, |
| 12 | +// * generating function descriptions, generating embeddings, and inserting function data into a database. |
| 13 | +// */ |
| 14 | +// export class CodeIndexingService { |
| 15 | +// logger: Logger; |
| 16 | +// embeddingService: EmbeddingService; |
| 17 | +// codeRepository: CodeRepository | undefined; |
| 18 | +// private static instance: CodeIndexingService; |
| 19 | +// constructor() { |
| 20 | +// this.logger = Logger.initialize("CodeIndexingService", { |
| 21 | +// minLevel: LogLevel.DEBUG, |
| 22 | +// }); |
| 23 | +// const { apiKey, model } = getAPIKeyAndModel("gemini"); |
| 24 | +// this.embeddingService = new EmbeddingService(apiKey); |
| 25 | +// } |
26 | 26 |
|
27 | | - /** |
28 | | - * Creates a singleton instance of the CodeIndexingService class. |
29 | | - * @returns {CodeIndexingService} The CodeIndexingService instance. |
30 | | - */ |
31 | | - public static createInstance(): CodeIndexingService { |
32 | | - if (!CodeIndexingService.instance) { |
33 | | - CodeIndexingService.instance = new CodeIndexingService(); |
34 | | - } |
35 | | - return CodeIndexingService.instance; |
36 | | - } |
| 27 | +// /** |
| 28 | +// * Creates a singleton instance of the CodeIndexingService class. |
| 29 | +// * @returns {CodeIndexingService} The CodeIndexingService instance. |
| 30 | +// */ |
| 31 | +// public static createInstance(): CodeIndexingService { |
| 32 | +// if (!CodeIndexingService.instance) { |
| 33 | +// CodeIndexingService.instance = new CodeIndexingService(); |
| 34 | +// } |
| 35 | +// return CodeIndexingService.instance; |
| 36 | +// } |
37 | 37 |
|
38 | | - /** |
39 | | - * Retrieves an instance of the CodeRepository, which is used to interact with the database. |
40 | | - * @returns {Promise<void>} A promise that resolves when the repository is initialized. |
41 | | - */ |
42 | | - async getCodeRepository() { |
43 | | - this.codeRepository = await CodeRepository.getInstance(); |
44 | | - } |
| 38 | +// /** |
| 39 | +// * Retrieves an instance of the CodeRepository, which is used to interact with the database. |
| 40 | +// * @returns {Promise<void>} A promise that resolves when the repository is initialized. |
| 41 | +// */ |
| 42 | +// async getCodeRepository() { |
| 43 | +// this.codeRepository = await CodeRepository.getInstance(); |
| 44 | +// } |
45 | 45 |
|
46 | | - /** |
47 | | - * Builds a function structure map using the TypeScript ATS mapper and CodeStructureMapper services. |
48 | | - * @returns {Promise<Partial<IFunctionData>[]>} A promise that resolves with an array of function data. |
49 | | - */ |
50 | | - async buildFunctionStructureMap(): Promise<Partial<IFunctionData>[]> { |
51 | | - try { |
52 | | - // TODO Get all the typescript project compilers information |
53 | | - const codeATS = await TypeScriptAtsMapper.getInstance(); |
54 | | - if (!codeATS) { |
55 | | - throw new Error("Failed to get TypeScriptAtsMapper instance"); |
56 | | - } |
57 | | - const mappedCode = await codeATS.buildCodebaseMap(); |
58 | | - if (!mappedCode) { |
59 | | - throw new Error("Failed to build codebase map"); |
60 | | - } |
61 | | - const ats = Object.values(mappedCode).flatMap((repo) => |
62 | | - Object.values(repo.modules), |
63 | | - ); |
64 | | - const mapper = new CodeStructureMapper(ats); |
65 | | - return mapper.normalizeData(); |
66 | | - } catch (error) { |
67 | | - this.logger.error("Error building function structure map:", error); |
68 | | - throw error; |
69 | | - } |
70 | | - } |
| 46 | +// /** |
| 47 | +// * Builds a function structure map using the TypeScript ATS mapper and CodeStructureMapper services. |
| 48 | +// * @returns {Promise<Partial<IFunctionData>[]>} A promise that resolves with an array of function data. |
| 49 | +// */ |
| 50 | +// async buildFunctionStructureMap(): Promise<Partial<IFunctionData>[]> { |
| 51 | +// try { |
| 52 | +// // TODO Get all the typescript project compilers information |
| 53 | +// const codeATS = await TypeScriptAtsMapper.getInstance(); |
| 54 | +// if (!codeATS) { |
| 55 | +// throw new Error("Failed to get TypeScriptAtsMapper instance"); |
| 56 | +// } |
| 57 | +// const mappedCode = await codeATS.buildCodebaseMap(); |
| 58 | +// if (!mappedCode) { |
| 59 | +// throw new Error("Failed to build codebase map"); |
| 60 | +// } |
| 61 | +// const ats = Object.values(mappedCode).flatMap((repo) => |
| 62 | +// Object.values(repo.modules), |
| 63 | +// ); |
| 64 | +// const mapper = new CodeStructureMapper(ats); |
| 65 | +// return mapper.normalizeData(); |
| 66 | +// } catch (error) { |
| 67 | +// this.logger.error("Error building function structure map:", error); |
| 68 | +// throw error; |
| 69 | +// } |
| 70 | +// } |
71 | 71 |
|
72 | | - /** |
73 | | - * Generates function descriptions using the EmbeddingService. |
74 | | - * @returns {Promise<IFunctionData[]>} A promise that resolves with an array of function data. |
75 | | - */ |
76 | | - async generateFunctionDescription(): Promise<IFunctionData[]> { |
77 | | - try { |
78 | | - const functions = |
79 | | - (await this.buildFunctionStructureMap()) as IFunctionData[]; |
80 | | - if (!functions?.length) { |
81 | | - throw new Error("failed to generate ATS"); |
82 | | - } |
83 | | - return await this.embeddingService.processFunctions(functions); |
84 | | - } catch (error) { |
85 | | - this.logger.error("LLM unable to generate description", error); |
86 | | - throw error; |
87 | | - } |
88 | | - } |
| 72 | +// /** |
| 73 | +// * Generates function descriptions using the EmbeddingService. |
| 74 | +// * @returns {Promise<IFunctionData[]>} A promise that resolves with an array of function data. |
| 75 | +// */ |
| 76 | +// async generateFunctionDescription(): Promise<IFunctionData[]> { |
| 77 | +// try { |
| 78 | +// const functions = |
| 79 | +// (await this.buildFunctionStructureMap()) as IFunctionData[]; |
| 80 | +// if (!functions?.length) { |
| 81 | +// throw new Error("failed to generate ATS"); |
| 82 | +// } |
| 83 | +// return await this.embeddingService.processFunctions(functions); |
| 84 | +// } catch (error) { |
| 85 | +// this.logger.error("LLM unable to generate description", error); |
| 86 | +// throw error; |
| 87 | +// } |
| 88 | +// } |
89 | 89 |
|
90 | | - /** |
91 | | - * Generates embeddings for the given functions using the EmbeddingService. |
92 | | - * @returns {Promise<IFunctionData[]>} A promise that resolves with an array of function data. |
93 | | - */ |
94 | | - async generateEmbeddings(): Promise<IFunctionData[]> { |
95 | | - const functionsWithDescription = await this.generateFunctionDescription(); |
96 | | - functionsWithDescription.forEach((item) => { |
97 | | - if (!item.compositeText) { |
98 | | - item.compositeText = `Description: ${item.description} Function: ${item.name} ${item.returnType} Dependencies: ${(item.dependencies ?? []).join(", ")}`; |
99 | | - } |
100 | | - }); |
101 | | - const functionWithEmbeddings = await this.embeddingService.processFunctions( |
102 | | - functionsWithDescription, |
103 | | - true, |
104 | | - ); |
105 | | - return functionWithEmbeddings; |
106 | | - } |
| 90 | +// /** |
| 91 | +// * Generates embeddings for the given functions using the EmbeddingService. |
| 92 | +// * @returns {Promise<IFunctionData[]>} A promise that resolves with an array of function data. |
| 93 | +// */ |
| 94 | +// async generateEmbeddings(): Promise<IFunctionData[]> { |
| 95 | +// const functionsWithDescription = await this.generateFunctionDescription(); |
| 96 | +// functionsWithDescription.forEach((item) => { |
| 97 | +// if (!item.compositeText) { |
| 98 | +// item.compositeText = `Description: ${item.description} Function: ${item.name} ${item.returnType} Dependencies: ${(item.dependencies ?? []).join(", ")}`; |
| 99 | +// } |
| 100 | +// }); |
| 101 | +// const functionWithEmbeddings = await this.embeddingService.processFunctions( |
| 102 | +// functionsWithDescription, |
| 103 | +// true, |
| 104 | +// ); |
| 105 | +// return functionWithEmbeddings; |
| 106 | +// } |
107 | 107 |
|
108 | | - /** |
109 | | - * Inserts function data into the database using the CodeRepository. |
110 | | - * @returns {Promise<ResultSet | undefined>} A promise that resolves with the result set or undefined. |
111 | | - */ |
112 | | - // async insertFunctionsinDB(): Promise<ResultSet | undefined> { |
113 | | - // await this.getCodeRepository(); |
114 | | - // if (!this.codeRepository) { |
115 | | - // this.logger.info("Unable to connect to the DB"); |
116 | | - // throw new Error("Unable to connect to DB"); |
117 | | - // } |
118 | | - // const dataToInsert = await this.generateEmbeddings(); |
119 | | - // if (dataToInsert?.length) { |
120 | | - // const valuesString = dataToInsert |
121 | | - // .map( |
122 | | - // (value) => |
123 | | - // `('${value.className}', '${value.name}', '${value.path}', '${value.processedAt}', vector32('[${(value.embedding ?? []).join(",")}]'))`, |
124 | | - // ) |
125 | | - // .join(","); |
126 | | - // const result = await this.codeRepository?.insertFunctions(valuesString); |
127 | | - // return result; |
128 | | - // } |
129 | | - // } |
130 | | -} |
| 108 | +// /** |
| 109 | +// * Inserts function data into the database using the CodeRepository. |
| 110 | +// * @returns {Promise<ResultSet | undefined>} A promise that resolves with the result set or undefined. |
| 111 | +// */ |
| 112 | +// // async insertFunctionsinDB(): Promise<ResultSet | undefined> { |
| 113 | +// // await this.getCodeRepository(); |
| 114 | +// // if (!this.codeRepository) { |
| 115 | +// // this.logger.info("Unable to connect to the DB"); |
| 116 | +// // throw new Error("Unable to connect to DB"); |
| 117 | +// // } |
| 118 | +// // const dataToInsert = await this.generateEmbeddings(); |
| 119 | +// // if (dataToInsert?.length) { |
| 120 | +// // const valuesString = dataToInsert |
| 121 | +// // .map( |
| 122 | +// // (value) => |
| 123 | +// // `('${value.className}', '${value.name}', '${value.path}', '${value.processedAt}', vector32('[${(value.embedding ?? []).join(",")}]'))`, |
| 124 | +// // ) |
| 125 | +// // .join(","); |
| 126 | +// // const result = await this.codeRepository?.insertFunctions(valuesString); |
| 127 | +// // return result; |
| 128 | +// // } |
| 129 | +// // } |
| 130 | +// } |
0 commit comments