@codebolt/codeboltjs 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/core/messageManager.d.ts +47 -0
  2. package/dist/core/messageManager.js +128 -0
  3. package/dist/{modules → core}/websocket.d.ts +5 -0
  4. package/dist/{modules → core}/websocket.js +15 -10
  5. package/dist/index.d.ts +98 -68
  6. package/dist/index.js +51 -4
  7. package/dist/modules/agent.js +26 -58
  8. package/dist/modules/browser.d.ts +7 -7
  9. package/dist/modules/browser.js +75 -195
  10. package/dist/modules/chat.d.ts +8 -20
  11. package/dist/modules/chat.js +60 -123
  12. package/dist/modules/codeparsers.d.ts +32 -3
  13. package/dist/modules/codeparsers.js +295 -3
  14. package/dist/modules/codeutils.d.ts +24 -7
  15. package/dist/modules/codeutils.js +113 -126
  16. package/dist/modules/crawler.d.ts +1 -16
  17. package/dist/modules/crawler.js +13 -72
  18. package/dist/modules/dbmemory.js +12 -28
  19. package/dist/modules/debug.js +17 -33
  20. package/dist/modules/docutils.d.ts +1 -4
  21. package/dist/modules/docutils.js +52 -2
  22. package/dist/modules/fs.d.ts +47 -1
  23. package/dist/modules/fs.js +151 -162
  24. package/dist/modules/git.d.ts +7 -14
  25. package/dist/modules/git.js +54 -163
  26. package/dist/modules/history.js +11 -27
  27. package/dist/modules/llm.js +8 -16
  28. package/dist/modules/outputparsers.d.ts +36 -4
  29. package/dist/modules/outputparsers.js +56 -5
  30. package/dist/modules/project.d.ts +4 -5
  31. package/dist/modules/project.js +23 -45
  32. package/dist/modules/state.js +29 -69
  33. package/dist/modules/task.js +19 -43
  34. package/dist/modules/terminal.d.ts +3 -2
  35. package/dist/modules/terminal.js +36 -47
  36. package/dist/modules/tokenizer.js +15 -31
  37. package/dist/modules/tools.d.ts +0 -6
  38. package/dist/modules/tools.js +41 -179
  39. package/dist/modules/utils.js +22 -0
  40. package/dist/modules/vectordb.js +30 -62
  41. package/dist/utils/parse-source-code/index.d.ts +9 -0
  42. package/dist/utils/parse-source-code/index.js +233 -0
  43. package/dist/utils/parse-source-code/languageParser.d.ts +8 -0
  44. package/dist/utils/parse-source-code/languageParser.js +137 -0
  45. package/dist/utils/parse-source-code/queries/c-sharp.d.ts +2 -0
  46. package/dist/utils/parse-source-code/queries/c-sharp.js +25 -0
  47. package/dist/utils/parse-source-code/queries/c.d.ts +2 -0
  48. package/dist/utils/parse-source-code/queries/c.js +17 -0
  49. package/dist/utils/parse-source-code/queries/cpp.d.ts +2 -0
  50. package/dist/utils/parse-source-code/queries/cpp.js +25 -0
  51. package/dist/utils/parse-source-code/queries/go.d.ts +2 -0
  52. package/dist/utils/parse-source-code/queries/go.js +29 -0
  53. package/dist/utils/parse-source-code/queries/index.d.ts +12 -0
  54. package/dist/utils/parse-source-code/queries/index.js +30 -0
  55. package/dist/utils/parse-source-code/queries/java.d.ts +2 -0
  56. package/dist/utils/parse-source-code/queries/java.js +17 -0
  57. package/dist/utils/parse-source-code/queries/javascript.d.ts +2 -0
  58. package/dist/utils/parse-source-code/queries/javascript.js +67 -0
  59. package/dist/utils/parse-source-code/queries/php.d.ts +2 -0
  60. package/dist/utils/parse-source-code/queries/php.js +17 -0
  61. package/dist/utils/parse-source-code/queries/python.d.ts +2 -0
  62. package/dist/utils/parse-source-code/queries/python.js +13 -0
  63. package/dist/utils/parse-source-code/queries/ruby.d.ts +2 -0
  64. package/dist/utils/parse-source-code/queries/ruby.js +54 -0
  65. package/dist/utils/parse-source-code/queries/rust.d.ts +2 -0
  66. package/dist/utils/parse-source-code/queries/rust.js +18 -0
  67. package/dist/utils/parse-source-code/queries/swift.d.ts +2 -0
  68. package/dist/utils/parse-source-code/queries/swift.js +47 -0
  69. package/dist/utils/parse-source-code/queries/typescript.d.ts +2 -0
  70. package/dist/utils/parse-source-code/queries/typescript.js +34 -0
  71. package/dist/utils/parse-source-code/tree-sitter-c.wasm +0 -0
  72. package/dist/utils/parse-source-code/tree-sitter-c_sharp.wasm +0 -0
  73. package/dist/utils/parse-source-code/tree-sitter-cpp.wasm +0 -0
  74. package/dist/utils/parse-source-code/tree-sitter-go.wasm +0 -0
  75. package/dist/utils/parse-source-code/tree-sitter-java.wasm +0 -0
  76. package/dist/utils/parse-source-code/tree-sitter-javascript.wasm +0 -0
  77. package/dist/utils/parse-source-code/tree-sitter-php.wasm +0 -0
  78. package/dist/utils/parse-source-code/tree-sitter-python.wasm +0 -0
  79. package/dist/utils/parse-source-code/tree-sitter-ruby.wasm +0 -0
  80. package/dist/utils/parse-source-code/tree-sitter-rust.wasm +0 -0
  81. package/dist/utils/parse-source-code/tree-sitter-swift.wasm +0 -0
  82. package/dist/utils/parse-source-code/tree-sitter-tsx.wasm +0 -0
  83. package/dist/utils/parse-source-code/tree-sitter-typescript.wasm +0 -0
  84. package/dist/utils/parse-source-code/tree-sitter.wasm +0 -0
  85. package/dist/utils.d.ts +1 -1
  86. package/dist/utils.js +1 -1
  87. package/package.json +6 -2
  88. package/dist/utils/editFile.js +0 -30
  89. /package/dist/{utils/editFile.d.ts → modules/utils.d.ts} +0 -0
  90. /package/dist/{modules → utils}/toolBox.d.ts +0 -0
  91. /package/dist/{modules → utils}/toolBox.js +0 -0
@@ -1,4 +1,21 @@
1
1
  import { MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
2
+ export interface JSTreeStructureItem {
3
+ type: string;
4
+ name: string;
5
+ startLine: number;
6
+ endLine: number;
7
+ startColumn: number;
8
+ endColumn: number;
9
+ nodeType: string;
10
+ }
11
+ export interface JSTreeResponse {
12
+ event: string;
13
+ payload?: {
14
+ filePath: string;
15
+ structure: JSTreeStructureItem[];
16
+ };
17
+ error?: string;
18
+ }
2
19
  /**
3
20
  * A utility module for working with code.
4
21
  */
@@ -6,9 +23,9 @@ declare const cbcodeutils: {
6
23
  /**
7
24
  * Retrieves a JavaScript tree structure for a given file path.
8
25
  * @param {string} filePath - The path of the file to retrieve the JS tree for.
9
- * @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
26
+ * @returns {Promise<JSTreeResponse>} A promise that resolves with the JS tree response.
10
27
  */
11
- getJsTree: (filePath?: string) => Promise<unknown>;
28
+ getJsTree: (filePath?: string) => Promise<JSTreeResponse>;
12
29
  /**
13
30
  * Retrieves all files as Markdown.
14
31
  * @returns {Promise<string>} A promise that resolves with the Markdown content of all files.
@@ -16,12 +33,12 @@ declare const cbcodeutils: {
16
33
  getAllFilesAsMarkDown: () => Promise<string>;
17
34
  /**
18
35
  * Performs a matching operation based on the provided matcher definition and problem patterns.
19
- * @param {object} matcherDefinition - The definition of the matcher.
20
- * @param {Array} problemPatterns - The patterns to match against.
21
- * @param {Array} problems - The list of problems.
36
+ * @param {object} matcherDefinition - The definition of the matcher (name, pattern, language, etc.).
37
+ * @param {Array} problemPatterns - The patterns to match against (regex patterns with severity levels).
38
+ * @param {Array} problems - Optional list of pre-existing problems to include.
22
39
  * @returns {Promise<MatchProblemResponse>} A promise that resolves with the matching problem response.
23
40
  */
24
- performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<MatchProblemResponse>;
41
+ performMatch: (matcherDefinition: object, problemPatterns: any[], problems?: any[]) => Promise<MatchProblemResponse>;
25
42
  /**
26
43
  * Retrieves the list of matchers.
27
44
  * @returns {Promise<GetMatcherListTreeResponse>} A promise that resolves with the list of matchers response.
@@ -29,7 +46,7 @@ declare const cbcodeutils: {
29
46
  getMatcherList: () => Promise<GetMatcherListTreeResponse>;
30
47
  /**
31
48
  * Retrieves details of a match.
32
- * @param {string} matcher - The matcher to retrieve details for.
49
+ * @param {string} matcher - The matcher to retrieve details for (by name or identifier).
33
50
  * @returns {Promise<getMatchDetail>} A promise that resolves with the match detail response.
34
51
  */
35
52
  matchDetail: (matcher: string) => Promise<getMatchDetail>;
@@ -1,9 +1,35 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const websocket_1 = __importDefault(require("./websocket"));
29
+ const websocket_1 = __importDefault(require("../core/websocket"));
30
+ const fs = __importStar(require("fs"));
31
+ const path_1 = __importDefault(require("path"));
32
+ const languageParser_1 = require("../utils/parse-source-code/languageParser");
7
33
  /**
8
34
  * A utility module for working with code.
9
35
  */
@@ -11,156 +37,117 @@ const cbcodeutils = {
11
37
  /**
12
38
  * Retrieves a JavaScript tree structure for a given file path.
13
39
  * @param {string} filePath - The path of the file to retrieve the JS tree for.
14
- * @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
40
+ * @returns {Promise<JSTreeResponse>} A promise that resolves with the JS tree response.
15
41
  */
16
- getJsTree: (filePath) => {
17
- return new Promise(async (resolve, reject) => {
18
- websocket_1.default.getWebsocket.send(JSON.stringify({
19
- "type": "settingEvent",
20
- "action": "getProjectPath"
21
- }));
22
- websocket_1.default.getWebsocket.on('message', (data) => {
23
- const response = JSON.parse(data);
24
- if (response.type === "getProjectPathResponse") {
25
- // resolve(response);
26
- // try {
27
- // let pathInput = filePath || response.projectPath;
28
- // let parser = new Parser();
29
- // // Initialize the parser with the JavaScript language
30
- // parser.setLanguage(JavaScript);
31
- // const trees = [];
32
- // const functionNodes = [];
33
- // const processDirectory = (directory: any) => {
34
- // // Read all files in the directory
35
- // const files = fs.readdirSync(directory, { withFileTypes: true });
36
- // files.forEach(file => {
37
- // if (file.isDirectory()) {
38
- // if (file.name !== 'node_modules') { // Ignore node_modules directory
39
- // processDirectory(path.join(directory, file.name)); // Recursive call for subdirectories
40
- // }
41
- // } else if (path.extname(file.name) === '.js') {
42
- // const code = fs.readFileSync(path.join(directory, file.name), 'utf-8');
43
- // let tree: any = parser.parse(code);
44
- // tree.rootNode.path = path.join(directory, file.name); // Set file path for t
45
- // trees.push(tree);
46
- // }
47
- // });
48
- // };
49
- // if (fs.lstatSync(pathInput).isDirectory()) {
50
- // processDirectory(pathInput);
51
- // } else if (path.extname(pathInput) === '.js') {
52
- // // Read a single JavaScript file
53
- // const code = fs.readFileSync(pathInput, 'utf-8');
54
- // let tree: any = parser.parse(code);
55
- // tree.rootNode.path = pathInput; // Set file path for t
56
- // trees.push(tree);
57
- // }
58
- // resolve({ event: 'GetJsTreeResponse', payload: trees }); // Return an array of abstract syntax trees (ASTs)
59
- // } catch (error) {
60
- // console.error('An error occurred:', error);
61
- // return { event: 'GetJsTreeResponse', payload: null }; // Return null in case of error
62
- // }
63
- }
42
+ getJsTree: async (filePath) => {
43
+ try {
44
+ // If no filePath is provided, we can't parse anything
45
+ if (!filePath) {
46
+ throw new Error('No file path provided for parsing');
47
+ }
48
+ // Get absolute path to ensure file can be accessed
49
+ const absolutePath = path_1.default.resolve(filePath);
50
+ // Check if file exists
51
+ await fs.promises.access(absolutePath);
52
+ // Get file extension to determine language parser
53
+ const ext = path_1.default.extname(absolutePath).toLowerCase().slice(1);
54
+ // Load appropriate language parser
55
+ const languageParsers = await (0, languageParser_1.loadRequiredLanguageParsers)([absolutePath]);
56
+ // Get parser for this file type
57
+ const { parser, query } = languageParsers[ext] || {};
58
+ if (!parser || !query) {
59
+ throw new Error(`Unsupported language: ${ext}`);
60
+ }
61
+ // Read file content
62
+ const fileContent = await fs.promises.readFile(absolutePath, 'utf8');
63
+ // Parse file to get AST
64
+ const tree = parser.parse(fileContent);
65
+ // Get captures from the AST using the query
66
+ const captures = query.captures(tree.rootNode);
67
+ // Sort captures by position
68
+ captures.sort((a, b) => a.node.startPosition.row - b.node.startPosition.row ||
69
+ a.node.startPosition.column - b.node.startPosition.column);
70
+ // Transform captures into a structured format
71
+ const structure = captures.map((capture) => {
72
+ const { node, name } = capture;
73
+ return {
74
+ type: name.includes('definition.') ? name.split('definition.')[1] : name,
75
+ name: node.text,
76
+ startLine: node.startPosition.row,
77
+ endLine: node.endPosition.row,
78
+ startColumn: node.startPosition.column,
79
+ endColumn: node.endPosition.column,
80
+ nodeType: node.type
81
+ };
64
82
  });
65
- });
66
- // return new Promise(async (resolve, reject) => {
67
- // cbws.getWebsocket.send(JSON.stringify({
68
- // "type": "codeEvent",
69
- // "action": "getJsTree",
70
- // payload: {
71
- // filePath
72
- // }
73
- // }));
74
- // cbws.getWebsocket.on('message', (data: string) => {
75
- // const response = JSON.parse(data);
76
- // if (response.type === "getJsTreeResponse") {
77
- // resolve(response); // Resolve the Promise with the response data
78
- // }
79
- // });
80
- // });
83
+ // Return response with the appropriate structure
84
+ return {
85
+ event: 'getJsTreeResponse',
86
+ payload: {
87
+ filePath: absolutePath,
88
+ structure
89
+ }
90
+ };
91
+ }
92
+ catch (error) {
93
+ // Return error response
94
+ return {
95
+ event: 'getJsTreeResponse',
96
+ error: error instanceof Error ? error.message : String(error)
97
+ };
98
+ }
81
99
  },
82
100
  /**
83
101
  * Retrieves all files as Markdown.
84
102
  * @returns {Promise<string>} A promise that resolves with the Markdown content of all files.
85
103
  */
86
104
  getAllFilesAsMarkDown: () => {
87
- return new Promise((resolve, reject) => {
88
- websocket_1.default.getWebsocket.send(JSON.stringify({
89
- "type": "codeEvent",
90
- "action": "getAllFilesMarkdown"
91
- }));
92
- websocket_1.default.getWebsocket.on('message', (data) => {
93
- const response = JSON.parse(data);
94
- if (response.type === "getAllFilesMarkdownResponse") {
95
- resolve(response); // Resolve the Promise with the response data
96
- }
97
- });
98
- });
105
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
106
+ "type": "codeEvent",
107
+ "action": "getAllFilesMarkdown"
108
+ }, "getAllFilesMarkdownResponse");
99
109
  },
100
110
  /**
101
111
  * Performs a matching operation based on the provided matcher definition and problem patterns.
102
- * @param {object} matcherDefinition - The definition of the matcher.
103
- * @param {Array} problemPatterns - The patterns to match against.
104
- * @param {Array} problems - The list of problems.
112
+ * @param {object} matcherDefinition - The definition of the matcher (name, pattern, language, etc.).
113
+ * @param {Array} problemPatterns - The patterns to match against (regex patterns with severity levels).
114
+ * @param {Array} problems - Optional list of pre-existing problems to include.
105
115
  * @returns {Promise<MatchProblemResponse>} A promise that resolves with the matching problem response.
106
116
  */
107
- performMatch: (matcherDefinition, problemPatterns, problems) => {
108
- return new Promise((resolve, reject) => {
109
- websocket_1.default.getWebsocket.send(JSON.stringify({
110
- "type": "codeEvent",
111
- "action": "performMatch",
112
- payload: {
113
- matcherDefinition,
114
- problemPatterns,
115
- }
116
- }));
117
- websocket_1.default.getWebsocket.on('message', (data) => {
118
- const response = JSON.parse(data);
119
- if (response.type === "getgetJsTreeResponse") {
120
- resolve(response); // Resolve the Promise with the response data
121
- }
122
- });
123
- });
117
+ performMatch: (matcherDefinition, problemPatterns, problems = []) => {
118
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
119
+ "type": "codeEvent",
120
+ "action": "performMatch",
121
+ payload: {
122
+ matcherDefinition,
123
+ problemPatterns,
124
+ problems
125
+ }
126
+ }, "matchProblemResponse");
124
127
  },
125
128
  /**
126
129
  * Retrieves the list of matchers.
127
130
  * @returns {Promise<GetMatcherListTreeResponse>} A promise that resolves with the list of matchers response.
128
131
  */
129
132
  getMatcherList: () => {
130
- return new Promise((resolve, reject) => {
131
- websocket_1.default.getWebsocket.send(JSON.stringify({
132
- "type": "codeEvent",
133
- "action": "getMatcherList",
134
- }));
135
- websocket_1.default.getWebsocket.on('message', (data) => {
136
- const response = JSON.parse(data);
137
- if (response.type === "getMatcherListTreeResponse") {
138
- resolve(response); // Resolve the Promise with the response data
139
- }
140
- });
141
- });
133
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
134
+ "type": "codeEvent",
135
+ "action": "getMatcherList",
136
+ }, "getMatcherListTreeResponse");
142
137
  },
143
138
  /**
144
139
  * Retrieves details of a match.
145
- * @param {string} matcher - The matcher to retrieve details for.
140
+ * @param {string} matcher - The matcher to retrieve details for (by name or identifier).
146
141
  * @returns {Promise<getMatchDetail>} A promise that resolves with the match detail response.
147
142
  */
148
143
  matchDetail: (matcher) => {
149
- return new Promise((resolve, reject) => {
150
- websocket_1.default.getWebsocket.send(JSON.stringify({
151
- "type": "codeEvent",
152
- "action": "getMatchDetail",
153
- payload: {
154
- match: matcher
155
- }
156
- }));
157
- websocket_1.default.getWebsocket.on('message', (data) => {
158
- const response = JSON.parse(data);
159
- if (response.type === "matchDetailTreeResponse") {
160
- resolve(response); // Resolve the Promise with the response data
161
- }
162
- });
163
- });
144
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
145
+ "type": "codeEvent",
146
+ "action": "getMatchDetail",
147
+ payload: {
148
+ matcher: matcher
149
+ }
150
+ }, "getMatchDetailResponse");
164
151
  }
165
152
  };
166
153
  exports.default = cbcodeutils;
@@ -25,21 +25,6 @@ declare const cbcrawler: {
25
25
  * @param id - The ID of the element to be clicked.
26
26
  * @returns {Promise<any>} A promise that resolves when the click action is complete.
27
27
  */
28
- click: (id: string) => Promise<unknown>;
29
- /**
30
- * Types the provided text into an element with the specified ID.
31
- * @param id - The ID of the element where text will be typed.
32
- * @param text - The text to type into the element.
33
- * @returns {Promise<any>} A promise that resolves when the type action is complete.
34
- */
35
- type: (id: string, text: string) => Promise<unknown>;
36
- /**
37
- * Simulates the Enter key press using the crawler.
38
- */
39
- enter: () => void;
40
- /**
41
- * Initiates a crawl process.
42
- */
43
- crawl: (query: string) => Promise<unknown>;
28
+ click: (id: string) => Promise<any>;
44
29
  };
45
30
  export default cbcrawler;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const websocket_1 = __importDefault(require("./websocket"));
6
+ const websocket_1 = __importDefault(require("../core/websocket"));
7
7
  /**
8
8
  * A module for controlling a web crawler through WebSocket messages.
9
9
  */
@@ -12,41 +12,41 @@ const cbcrawler = {
12
12
  * Starts the crawler.
13
13
  */
14
14
  start: () => {
15
- websocket_1.default.getWebsocket.send(JSON.stringify({
15
+ websocket_1.default.messageManager.send({
16
16
  "type": "crawlerEvent",
17
17
  action: 'start'
18
- }));
18
+ });
19
19
  },
20
20
  /**
21
21
  * Takes a screenshot using the crawler.
22
22
  */
23
23
  screenshot: () => {
24
- websocket_1.default.getWebsocket.send(JSON.stringify({
24
+ websocket_1.default.messageManager.send({
25
25
  "type": "crawlerEvent",
26
26
  action: 'screenshot'
27
- }));
27
+ });
28
28
  },
29
29
  /**
30
30
  * Directs the crawler to navigate to a specified URL.
31
31
  * @param url - The URL for the crawler to navigate to.
32
32
  */
33
33
  goToPage: (url) => {
34
- websocket_1.default.getWebsocket.send(JSON.stringify({
34
+ websocket_1.default.messageManager.send({
35
35
  "type": "crawlerEvent",
36
36
  action: 'goToPage',
37
37
  url
38
- }));
38
+ });
39
39
  },
40
40
  /**
41
41
  * Scrolls the crawler in a specified direction.
42
42
  * @param direction - The direction to scroll ('up', 'down', 'left', 'right').
43
43
  */
44
44
  scroll: (direction) => {
45
- websocket_1.default.getWebsocket.send(JSON.stringify({
45
+ websocket_1.default.messageManager.send({
46
46
  "type": "crawlerEvent",
47
47
  action: 'scroll',
48
48
  direction
49
- }));
49
+ });
50
50
  },
51
51
  /**
52
52
  * Simulates a click event on an element with the specified ID.
@@ -54,70 +54,11 @@ const cbcrawler = {
54
54
  * @returns {Promise<any>} A promise that resolves when the click action is complete.
55
55
  */
56
56
  click: (id) => {
57
- return new Promise((resolve, reject) => {
58
- websocket_1.default.getWebsocket.send(JSON.stringify({
59
- "type": "crawlerEvent",
60
- action: 'click',
61
- id
62
- }));
63
- websocket_1.default.getWebsocket.on('message', (data) => {
64
- const response = JSON.parse(data);
65
- if (response.event === "clickFinished") {
66
- resolve(response);
67
- }
68
- });
69
- });
70
- },
71
- /**
72
- * Types the provided text into an element with the specified ID.
73
- * @param id - The ID of the element where text will be typed.
74
- * @param text - The text to type into the element.
75
- * @returns {Promise<any>} A promise that resolves when the type action is complete.
76
- */
77
- type: (id, text) => {
78
- return new Promise((resolve, reject) => {
79
- websocket_1.default.getWebsocket.send(JSON.stringify({
80
- "type": "crawlerEvent",
81
- action: 'type',
82
- id,
83
- text
84
- }));
85
- websocket_1.default.getWebsocket.on('message', (data) => {
86
- const response = JSON.parse(data);
87
- if (response.event === "typeFinished") {
88
- resolve(response);
89
- }
90
- });
91
- });
92
- },
93
- /**
94
- * Simulates the Enter key press using the crawler.
95
- */
96
- enter: () => {
97
- websocket_1.default.getWebsocket.send(JSON.stringify({
57
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
98
58
  "type": "crawlerEvent",
99
- action: 'enter'
100
- }));
101
- },
102
- /**
103
- * Initiates a crawl process.
104
- */
105
- crawl: (query) => {
106
- return new Promise((resolve, reject) => {
107
- websocket_1.default.getWebsocket.send(JSON.stringify({
108
- "type": "crawlerEvent",
109
- "action": 'crawl',
110
- "message": {
111
- query
112
- }
113
- }));
114
- websocket_1.default.getWebsocket.on('message', (data) => {
115
- const response = JSON.parse(data);
116
- if (response.type === "crawlResponse") {
117
- resolve(response); // Resolve the Promise with the response data
118
- }
119
- });
120
- });
59
+ action: 'click',
60
+ id
61
+ }, "crawlResponse");
121
62
  }
122
63
  };
123
64
  exports.default = cbcrawler;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const websocket_1 = __importDefault(require("./websocket"));
6
+ const websocket_1 = __importDefault(require("../core/websocket"));
7
7
  /**
8
8
  * A module for handling in-memory database operations via WebSocket.
9
9
  */
@@ -15,20 +15,12 @@ const dbmemory = {
15
15
  * @returns {Promise<MemorySetResponse>} A promise that resolves with the response from the memory set event.
16
16
  */
17
17
  addKnowledge: (key, value) => {
18
- return new Promise((resolve, reject) => {
19
- websocket_1.default.getWebsocket.send(JSON.stringify({
20
- "type": "memoryEvent",
21
- 'action': 'set',
22
- key,
23
- value
24
- }));
25
- websocket_1.default.getWebsocket.on('message', (data) => {
26
- const response = JSON.parse(data);
27
- if (response.type === "memorySetResponse") {
28
- resolve(response); // Resolve the Promise with the response data
29
- }
30
- });
31
- });
18
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
19
+ "type": "memoryEvent",
20
+ 'action': 'set',
21
+ key,
22
+ value
23
+ }, "memorySetResponse");
32
24
  },
33
25
  /**
34
26
  * Retrieves a value from the in-memory database by key.
@@ -36,19 +28,11 @@ const dbmemory = {
36
28
  * @returns {Promise<MemoryGetResponse>} A promise that resolves with the response from the memory get event.
37
29
  */
38
30
  getKnowledge: (key) => {
39
- return new Promise((resolve, reject) => {
40
- websocket_1.default.getWebsocket.send(JSON.stringify({
41
- "type": "memoryEvent",
42
- 'action': 'get',
43
- key
44
- }));
45
- websocket_1.default.getWebsocket.on('message', (data) => {
46
- const response = JSON.parse(data);
47
- if (response.type === "memoryGetResponse") {
48
- resolve(response); // Resolve the Promise with the response data
49
- }
50
- });
51
- });
31
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
32
+ "type": "memoryEvent",
33
+ 'action': 'get',
34
+ key
35
+ }, "memoryGetResponse");
52
36
  }
53
37
  };
54
38
  exports.default = dbmemory;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.debug = exports.logType = void 0;
7
- const websocket_1 = __importDefault(require("./websocket"));
7
+ const websocket_1 = __importDefault(require("../core/websocket"));
8
8
  var logType;
9
9
  (function (logType) {
10
10
  logType["info"] = "info";
@@ -19,22 +19,14 @@ exports.debug = {
19
19
  * @returns {Promise<DebugAddLogResponse>} A promise that resolves with the response from the debug event.
20
20
  */
21
21
  debug: (log, type) => {
22
- return new Promise((resolve, reject) => {
23
- websocket_1.default.getWebsocket.send(JSON.stringify({
24
- "type": "debugEvent",
25
- "action": "addLog",
26
- message: {
27
- log,
28
- type
29
- }
30
- }));
31
- websocket_1.default.getWebsocket.on('message', (data) => {
32
- const response = JSON.parse(data);
33
- if (response.type === "debugEventResponse") {
34
- resolve(response); // Resolve the Promise with the response data
35
- }
36
- });
37
- });
22
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
23
+ "type": "debugEvent",
24
+ "action": "addLog",
25
+ message: {
26
+ log,
27
+ type
28
+ }
29
+ }, "debugEventResponse");
38
30
  },
39
31
  /**
40
32
  * Requests to open a debug browser at the specified URL and port.
@@ -43,22 +35,14 @@ exports.debug = {
43
35
  * @returns {Promise<OpenDebugBrowserResponse>} A promise that resolves with the response from the open debug browser event.
44
36
  */
45
37
  openDebugBrowser: (url, port) => {
46
- return new Promise((resolve, reject) => {
47
- websocket_1.default.getWebsocket.send(JSON.stringify({
48
- "type": "debugEvent",
49
- "action": "openDebugBrowser",
50
- message: {
51
- url,
52
- port
53
- }
54
- }));
55
- websocket_1.default.getWebsocket.on('message', (data) => {
56
- const response = JSON.parse(data);
57
- if (response.type === "openDebugBrowserResponse") {
58
- resolve(response); // Resolve the Promise with the response data
59
- }
60
- });
61
- });
38
+ return websocket_1.default.messageManager.sendAndWaitForResponse({
39
+ "type": "debugEvent",
40
+ "action": "openDebugBrowser",
41
+ message: {
42
+ url,
43
+ port
44
+ }
45
+ }, "openDebugBrowserResponse");
62
46
  }
63
47
  };
64
48
  exports.default = exports.debug;
@@ -1,12 +1,9 @@
1
- /**
2
- * A module for document utility functions.
3
- */
4
1
  declare const cbdocutils: {
5
2
  /**
6
3
  * Converts a PDF document to text.
7
4
  * @param pdf_path - The file path to the PDF document to be converted.
8
5
  * @returns {Promise<string>} A promise that resolves with the converted text.
9
6
  */
10
- pdf_to_text: (pdf_path: any) => Promise<string>;
7
+ pdf_to_text: (pdf_path: string) => Promise<string>;
11
8
  };
12
9
  export default cbdocutils;