Skip to content

Commit a63102d

Browse files
committed
2 parents df9948f + 6fe76ae commit a63102d

39 files changed

+1473
-901
lines changed

.DS_Store

0 Bytes
Binary file not shown.

package-lock.json

Lines changed: 39 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
"@codebolt/globby": "^1.0.1",
3232
"@codebolt/types": "^1.0.10",
3333
"@modelcontextprotocol/sdk": "^1.4.1",
34+
"@types/pdf-parse": "^1.1.5",
3435
"execa": "^9.5.2",
3536
"file-type": "^19.6.0",
3637
"fuse.js": "^7.0.0",
3738
"js-yaml": "^4.1.0",
3839
"load-esm": "^1.0.1",
3940
"mcp-proxy": "^2.4.0",
41+
"pdf-parse": "^1.1.1",
4042
"strict-event-emitter-types": "^2.0.0",
4143
"timers": "^0.1.1",
4244
"undici": "^7.4.0",

src/modules/codeutils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const cbcodeutils = {
6060
// Get parser for this file type
6161
const { parser, query } = languageParsers[ext] || {};
6262
if (!parser || !query) {
63-
throw new Error(`Unsupported file type: ${ext}`);
63+
throw new Error(`Unsupported language: ${ext}`);
6464
}
6565

6666
// Read file content
@@ -125,19 +125,20 @@ const cbcodeutils = {
125125

126126
/**
127127
* Performs a matching operation based on the provided matcher definition and problem patterns.
128-
* @param {object} matcherDefinition - The definition of the matcher.
129-
* @param {Array} problemPatterns - The patterns to match against.
130-
* @param {Array} problems - The list of problems.
128+
* @param {object} matcherDefinition - The definition of the matcher (name, pattern, language, etc.).
129+
* @param {Array} problemPatterns - The patterns to match against (regex patterns with severity levels).
130+
* @param {Array} problems - Optional list of pre-existing problems to include.
131131
* @returns {Promise<MatchProblemResponse>} A promise that resolves with the matching problem response.
132132
*/
133-
performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]): Promise<MatchProblemResponse> => {
133+
performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[] = []): Promise<MatchProblemResponse> => {
134134
return cbws.messageManager.sendAndWaitForResponse(
135135
{
136136
"type": "codeEvent",
137137
"action": "performMatch",
138138
payload: {
139139
matcherDefinition,
140140
problemPatterns,
141+
problems
141142
}
142143
},
143144
"matchProblemResponse"
@@ -160,7 +161,7 @@ const cbcodeutils = {
160161

161162
/**
162163
* Retrieves details of a match.
163-
* @param {string} matcher - The matcher to retrieve details for.
164+
* @param {string} matcher - The matcher to retrieve details for (by name or identifier).
164165
* @returns {Promise<getMatchDetail>} A promise that resolves with the match detail response.
165166
*/
166167
matchDetail: (matcher: string): Promise<getMatchDetail> => {
@@ -169,7 +170,7 @@ const cbcodeutils = {
169170
"type": "codeEvent",
170171
"action": "getMatchDetail",
171172
payload: {
172-
match: matcher
173+
matcher: matcher
173174
}
174175
},
175176
"getMatchDetailResponse"

src/modules/docutils.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
11
/**
22
* A module for document utility functions.
33
*/
4+
import * as fs from 'fs';
5+
import * as path from 'path';
6+
import pdfParse from 'pdf-parse';
7+
48
const cbdocutils = {
59
/**
610
* Converts a PDF document to text.
711
* @param pdf_path - The file path to the PDF document to be converted.
812
* @returns {Promise<string>} A promise that resolves with the converted text.
913
*/
10-
pdf_to_text: (pdf_path: any): Promise<string> => {
11-
// Implementation would go here
14+
pdf_to_text: (pdf_path: string): Promise<string> => {
1215
return new Promise((resolve, reject) => {
13-
// PDF to text conversion logic
16+
try {
17+
// Check if file exists
18+
if (!fs.existsSync(pdf_path)) {
19+
return reject(new Error(`PDF file not found at path: ${pdf_path}`));
20+
}
21+
22+
// Read the PDF file as buffer
23+
const dataBuffer = fs.readFileSync(pdf_path);
24+
25+
// Parse the PDF document
26+
pdfParse(dataBuffer)
27+
.then((data: { text: string }) => {
28+
resolve(data.text);
29+
})
30+
.catch((error: Error) => {
31+
reject(new Error(`Error parsing PDF: ${error.message}`));
32+
});
33+
} catch (error: unknown) {
34+
if (error instanceof Error) {
35+
reject(new Error(`Error processing PDF: ${error.message}`));
36+
} else {
37+
reject(new Error('Unknown error processing PDF'));
38+
}
39+
}
1440
});
1541
}
1642
};

src/modules/outputparsers.ts

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,70 @@
33
*/
44
const cboutputparsers = {
55
/**
6-
* Initializes the output parser module.
7-
* Currently, this function does not perform any operations.
8-
* @param {any} output - The output to be initialized.
6+
* Parses JSON string and returns a result object.
7+
* @param {string} jsonString - The JSON string to parse.
8+
* @returns {Object} An object with success flag and parsed data or error.
99
*/
10-
init: (output: any) => {
11-
// Initialization code can be added here if necessary
10+
parseJSON: (jsonString: string): { success: boolean; parsed?: any; error?: Error } => {
11+
try {
12+
const parsed = JSON.parse(jsonString);
13+
return { success: true, parsed };
14+
} catch (error) {
15+
return { success: false, error: error as Error };
16+
}
1217
},
18+
19+
/**
20+
* Parses XML string and returns a result object.
21+
* @param {string} xmlString - The XML string to parse.
22+
* @returns {Object} An object with success flag and parsed data.
23+
*/
24+
parseXML: (xmlString: string): { success: boolean; parsed?: any } => {
25+
// Simple XML parsing - in a real implementation, would use a proper XML parser
26+
const hasValidRoot = xmlString.trim().startsWith('<') && xmlString.trim().endsWith('>');
27+
return {
28+
success: hasValidRoot,
29+
parsed: hasValidRoot ? { rootElement: xmlString } : undefined
30+
};
31+
},
32+
33+
/**
34+
* Parses CSV string and returns a result object.
35+
* @param {string} csvString - The CSV string to parse.
36+
* @returns {Object} An object with success flag and parsed data or error.
37+
*/
38+
parseCSV: (csvString: string): { success: boolean; parsed?: any[]; error?: Error } => {
39+
try {
40+
const lines = csvString.split('\n');
41+
const headers = lines[0].split(',');
42+
43+
const results = lines.slice(1).map(line => {
44+
const values = line.split(',');
45+
const obj: Record<string, string> = {};
46+
47+
headers.forEach((header, index) => {
48+
obj[header] = values[index];
49+
});
50+
51+
return obj;
52+
});
53+
54+
return { success: true, parsed: results };
55+
} catch (error) {
56+
return { success: false, error: error as Error };
57+
}
58+
},
59+
60+
/**
61+
* Parses text string and returns a result object with lines.
62+
* @param {string} text - The text to parse.
63+
* @returns {Object} An object with success flag and parsed lines.
64+
*/
65+
parseText: (text: string): { success: boolean; parsed: string[] } => {
66+
const lines = text ? text.split('\n') : [];
67+
return { success: true, parsed: lines };
68+
},
69+
1370
/**
1471
* Parses the given output and returns all the error messages.
1572
* @param {any} output - The output to parse for error messages.

src/modules/project.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ import { GetProjectPathResponse } from '@codebolt/types';
55
*/
66
const cbproject = {
77
/**
8-
* Placeholder for a method to get project settings.
9-
* Currently, this method does not perform any operations.
10-
* @param {any} output - The output where project settings would be stored.
8+
* Retrieves the project settings from the server.
9+
* @returns {Promise<any>} A promise that resolves with the project settings response.
1110
*/
12-
getProjectSettings: (output: any) => {
13-
// Implementation for getting project settings will be added here
11+
getProjectSettings: (): Promise<any> => {
12+
return cbws.messageManager.sendAndWaitForResponse(
13+
{
14+
"type": "settingEvent",
15+
"action": "getProjectSettings"
16+
},
17+
"getProjectSettingsResponse"
18+
);
1419
},
1520
/**
1621
* Retrieves the path of the current project.

testcases/package.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,27 @@
3232
"test:codeparsers": "node tests/codeparsers-test.js",
3333
"test:outputparsers": "node tests/outputparsers-test.js",
3434
"test:history": "node tests/history-test.js",
35-
"test:all": "npm run test:fs && npm run test:git && npm run test:chat && npm run test:terminal && npm run test:browser && npm run test:llm && npm run test:tools && npm run test:vectordb && npm run test:websocket && npm run test:codeutils && npm run test:toolBox && npm run test:debug && npm run test:dbmemory && npm run test:crawler && npm run test:tokenizer && npm run test:task && npm run test:state && npm run test:project && npm run test:agent && npm run test:rag && npm run test:docutils && npm run test:search && npm run test:knowledge && npm run test:codeparsers && npm run test:outputparsers && npm run test:history"
35+
"test:mcp:agent": "node tests/mcp_tools/agent-mcp-test.js",
36+
"test:mcp:browser": "node tests/mcp_tools/browser-mcp-test.js",
37+
"test:mcp:chat": "node tests/mcp_tools/chat-mcp-test.js",
38+
"test:mcp:codebase": "node tests/mcp_tools/codebase-mcp-test.js",
39+
"test:mcp:code-utils": "node tests/mcp_tools/code-utils-mcp-test.js",
40+
"test:mcp:config": "node tests/mcp_tools/config-mcp-test.js",
41+
"test:mcp:debug": "node tests/mcp_tools/debug-mcp-test.js",
42+
"test:mcp:fs": "node tests/mcp_tools/fs-mcp-test.js",
43+
"test:mcp:git": "node tests/mcp_tools/git-mcp-test.js",
44+
"test:mcp:memory": "node tests/mcp_tools/memory-mcp-test.js",
45+
"test:mcp:message": "node tests/mcp_tools/message-mcp-test.js",
46+
"test:mcp:notification": "node tests/mcp_tools/notification-mcp-test.js",
47+
"test:mcp:problem-matcher": "node tests/mcp_tools/problem-matcher-mcp-test.js",
48+
"test:mcp:state": "node tests/mcp_tools/state-mcp-test.js",
49+
"test:mcp:task": "node tests/mcp_tools/task-mcp-test.js",
50+
"test:mcp:terminal": "node tests/mcp_tools/terminal-mcp-test.js",
51+
"test:mcp:tokenizer": "node tests/mcp_tools/tokenizer-mcp-test.js",
52+
"test:mcp:vector": "node tests/mcp_tools/vectordb-mcp-test.js",
53+
"test:mcp:application": "node tests/mcp_tools/application-mcp-test.js",
54+
"test:mcp:all": "node tests/mcp_tools/run-all-mcp-tests.js",
55+
"test:all": "npm run test:fs && npm run test:git && npm run test:chat && npm run test:terminal && npm run test:browser && npm run test:llm && npm run test:tools && npm run test:vectordb && npm run test:websocket && npm run test:codeutils && npm run test:toolBox && npm run test:debug && npm run test:dbmemory && npm run test:crawler && npm run test:tokenizer && npm run test:task && npm run test:state && npm run test:project && npm run test:agent && npm run test:rag && npm run test:docutils && npm run test:search && npm run test:knowledge && npm run test:codeparsers && npm run test:outputparsers && npm run test:history && npm run test:mcp:all"
3656
},
3757
"keywords": [
3858
"codebolt",

0 commit comments

Comments
 (0)