@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
@@ -0,0 +1,47 @@
1
+ /// <reference types="node" />
2
+ import WebSocket from 'ws';
3
+ import { EventEmitter } from 'events';
4
+ export interface PendingRequest {
5
+ resolve: (value: any) => void;
6
+ reject: (reason?: any) => void;
7
+ messageTypes: string[];
8
+ requestId?: string;
9
+ }
10
+ /**
11
+ * Centralized message manager for handling WebSocket communications
12
+ */
13
+ export declare class MessageManager extends EventEmitter {
14
+ pendingRequests: Map<string, PendingRequest>;
15
+ websocket: WebSocket | null;
16
+ requestCounter: number;
17
+ /**
18
+ * Initialize the message manager with a WebSocket instance
19
+ */
20
+ initialize(websocket: WebSocket): void;
21
+ /**
22
+ * Setup the centralized message listener
23
+ */
24
+ setupMessageListener(): void;
25
+ /**
26
+ * Handle incoming messages and resolve pending requests
27
+ */
28
+ handleMessage(response: any): void;
29
+ /**
30
+ * Send a message and wait for a specific response type
31
+ */
32
+ sendAndWaitForResponse<T = any>(message: any, expectedResponseType: string, timeout?: number): Promise<T>;
33
+ /**
34
+ * Send a message without waiting for response
35
+ */
36
+ send(message: any): void;
37
+ /**
38
+ * Get the WebSocket instance
39
+ */
40
+ getWebSocket(): WebSocket | null;
41
+ /**
42
+ * Clean up all pending requests
43
+ */
44
+ cleanup(): void;
45
+ }
46
+ declare const _default: MessageManager;
47
+ export default _default;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageManager = void 0;
4
+ const events_1 = require("events");
5
+ /**
6
+ * Centralized message manager for handling WebSocket communications
7
+ */
8
+ class MessageManager extends events_1.EventEmitter {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.pendingRequests = new Map();
12
+ this.websocket = null;
13
+ this.requestCounter = 0;
14
+ }
15
+ /**
16
+ * Initialize the message manager with a WebSocket instance
17
+ */
18
+ initialize(websocket) {
19
+ this.websocket = websocket;
20
+ this.setupMessageListener();
21
+ }
22
+ /**
23
+ * Setup the centralized message listener
24
+ */
25
+ setupMessageListener() {
26
+ if (!this.websocket)
27
+ return;
28
+ this.websocket.on('message', (data) => {
29
+ try {
30
+ const response = JSON.parse(data.toString());
31
+ this.handleMessage(response);
32
+ }
33
+ catch (error) {
34
+ console.error('Error parsing WebSocket message:', error);
35
+ }
36
+ });
37
+ }
38
+ /**
39
+ * Handle incoming messages and resolve pending requests
40
+ */
41
+ handleMessage(response) {
42
+ const { type, requestId } = response;
43
+ // Handle requests with specific requestId
44
+ if (requestId && this.pendingRequests.has(requestId)) {
45
+ const request = this.pendingRequests.get(requestId);
46
+ this.pendingRequests.delete(requestId);
47
+ request.resolve(response);
48
+ return;
49
+ }
50
+ // Handle requests by message type
51
+ for (const [id, request] of this.pendingRequests.entries()) {
52
+ if (request.messageTypes.includes(type)) {
53
+ this.pendingRequests.delete(id);
54
+ request.resolve(response);
55
+ return;
56
+ }
57
+ }
58
+ // Emit the message for any other listeners (like onUserMessage)
59
+ this.emit('message', response);
60
+ }
61
+ /**
62
+ * Send a message and wait for a specific response type
63
+ */
64
+ sendAndWaitForResponse(message, expectedResponseType, timeout = 30000) {
65
+ return new Promise((resolve, reject) => {
66
+ if (!this.websocket) {
67
+ reject(new Error('WebSocket is not initialized'));
68
+ return;
69
+ }
70
+ const requestId = `req_${++this.requestCounter}_${Date.now()}`;
71
+ // Add requestId to the message if it doesn't have one
72
+ const messageWithId = { ...message, requestId };
73
+ // Parse multiple message types separated by pipe
74
+ const messageTypes = expectedResponseType.split('|').map(type => type.trim());
75
+ // Store the pending request
76
+ this.pendingRequests.set(requestId, {
77
+ resolve,
78
+ reject,
79
+ messageTypes,
80
+ requestId
81
+ });
82
+ // Set timeout
83
+ const timeoutId = setTimeout(() => {
84
+ if (this.pendingRequests.has(requestId)) {
85
+ this.pendingRequests.delete(requestId);
86
+ reject(new Error(`Request timeout after ${timeout}ms for message types: ${expectedResponseType}`));
87
+ }
88
+ }, timeout);
89
+ // Override resolve to clear timeout
90
+ const originalResolve = resolve;
91
+ const wrappedResolve = (value) => {
92
+ clearTimeout(timeoutId);
93
+ originalResolve(value);
94
+ };
95
+ // Update the stored request with wrapped resolve
96
+ const request = this.pendingRequests.get(requestId);
97
+ request.resolve = wrappedResolve;
98
+ // Send the message
99
+ this.websocket.send(JSON.stringify(messageWithId));
100
+ });
101
+ }
102
+ /**
103
+ * Send a message without waiting for response
104
+ */
105
+ send(message) {
106
+ if (!this.websocket) {
107
+ throw new Error('WebSocket is not initialized');
108
+ }
109
+ this.websocket.send(JSON.stringify(message));
110
+ }
111
+ /**
112
+ * Get the WebSocket instance
113
+ */
114
+ getWebSocket() {
115
+ return this.websocket;
116
+ }
117
+ /**
118
+ * Clean up all pending requests
119
+ */
120
+ cleanup() {
121
+ for (const [id, request] of this.pendingRequests.entries()) {
122
+ request.reject(new Error('WebSocket connection closed'));
123
+ }
124
+ this.pendingRequests.clear();
125
+ }
126
+ }
127
+ exports.MessageManager = MessageManager;
128
+ exports.default = new MessageManager();
@@ -1,4 +1,5 @@
1
1
  import WebSocket from 'ws';
2
+ import { MessageManager } from './messageManager';
2
3
  /**
3
4
  * Class representing a WebSocket connection.
4
5
  */
@@ -22,6 +23,10 @@ declare class cbws {
22
23
  * @throws {Error} If the WebSocket is not open.
23
24
  */
24
25
  get getWebsocket(): WebSocket;
26
+ /**
27
+ * Get the message manager instance
28
+ */
29
+ get messageManager(): MessageManager;
25
30
  }
26
31
  declare const _default: cbws;
27
32
  export default _default;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const ws_1 = __importDefault(require("ws"));
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const js_yaml_1 = __importDefault(require("js-yaml"));
9
+ const messageManager_1 = __importDefault(require("./messageManager"));
9
10
  /**
10
11
  * Class representing a WebSocket connection.
11
12
  */
@@ -54,22 +55,20 @@ class cbws {
54
55
  const parentIdParam = process.env.parentId ? `&parentId=${process.env.parentId}` : '';
55
56
  const parentAgentInstanceIdParam = process.env.parentAgentInstanceId ? `&parentAgentInstanceId=${process.env.parentAgentInstanceId}` : '';
56
57
  const agentTask = process.env.agentTask ? `&agentTask=${process.env.agentTask}` : '';
57
- this.websocket = new ws_1.default(`ws://localhost:${process.env.SOCKET_PORT}/codebolt?id=${uniqueConnectionId}${agentIdParam}${parentIdParam}${parentAgentInstanceIdParam}${agentTask}${process.env.Is_Dev ? '&dev=true' : ''}`);
58
+ const socketPort = process.env.SOCKET_PORT || '12345';
59
+ this.websocket = new ws_1.default(`ws://localhost:${socketPort}/codebolt?id=${uniqueConnectionId}${agentIdParam}${parentIdParam}${parentAgentInstanceIdParam}${agentTask}${process.env.Is_Dev ? '&dev=true' : ''}`);
58
60
  return new Promise((resolve, reject) => {
59
61
  this.websocket.on('error', (error) => {
60
62
  reject(error);
61
63
  });
62
64
  this.websocket.on('open', () => {
63
- // if (this.websocket) {
64
- // this.websocket.send(JSON.stringify({
65
- // "type": "sendMessage",
66
- // "message": initialMessage
67
- // }));
68
- // resolve(this.websocket);
69
- // }
65
+ // Initialize the message manager with this websocket
66
+ messageManager_1.default.initialize(this.websocket);
67
+ resolve(this.websocket);
70
68
  });
71
- this.websocket.on('message', (data) => {
72
- // Handle incoming WebSocket messages here.
69
+ this.websocket.on('close', () => {
70
+ // Clean up pending requests when connection closes
71
+ messageManager_1.default.cleanup();
73
72
  });
74
73
  });
75
74
  }
@@ -86,5 +85,11 @@ class cbws {
86
85
  return this.websocket;
87
86
  }
88
87
  }
88
+ /**
89
+ * Get the message manager instance
90
+ */
91
+ get messageManager() {
92
+ return messageManager_1.default;
93
+ }
89
94
  }
90
95
  exports.default = new cbws();
package/dist/index.d.ts CHANGED
@@ -34,29 +34,40 @@ declare class Codebolt {
34
34
  success: boolean;
35
35
  result: any;
36
36
  }>;
37
- writeToFile: (relPath: string, newContent: string) => Promise<unknown>;
37
+ writeToFile: (relPath: string, newContent: string) => Promise<any>;
38
+ grepSearch: (path: string, query: string, includePattern?: string | undefined, excludePattern?: string | undefined, caseSensitive?: boolean) => Promise<{
39
+ success: boolean;
40
+ result: any;
41
+ }>;
42
+ fileSearch: (query: string) => Promise<{
43
+ success: boolean;
44
+ result: any;
45
+ }>;
46
+ editFileWithDiff: (targetFile: string, codeEdit: string, diffIdentifier: string, prompt: string, applyModel?: string | undefined) => Promise<{
47
+ success: boolean;
48
+ result: any;
49
+ }>;
38
50
  };
39
51
  git: {
40
52
  init: (path: string) => Promise<any>;
41
- clone: (url: string, path: string) => Promise<any>;
42
- pull: (path: string) => Promise<any>;
43
- push: (path: string) => Promise<any>;
44
- status: (path: string) => Promise<any>;
45
- add: (path: string) => Promise<any>;
53
+ pull: () => Promise<any>;
54
+ push: () => Promise<any>;
55
+ status: () => Promise<any>;
56
+ addAll: () => Promise<any>;
46
57
  commit: (message: string) => Promise<any>;
47
- checkout: (path: string, branch: string) => Promise<any>;
48
- branch: (path: string, branch: string) => Promise<any>;
58
+ checkout: (branch: string) => Promise<any>;
59
+ branch: (branch: string) => Promise<any>;
49
60
  logs: (path: string) => Promise<any>;
50
- diff: (commitHash: string, path: string) => Promise<any>;
61
+ diff: (commitHash: string) => Promise<any>;
51
62
  };
52
63
  llm: {
53
64
  inference: (message: string, llmrole: string) => Promise<import("@codebolt/types").LLMResponse>;
54
65
  };
55
66
  browser: {
56
- newPage: () => Promise<unknown>;
67
+ newPage: () => Promise<any>;
57
68
  getUrl: () => Promise<import("@codebolt/types").UrlResponse>;
58
69
  goToPage: (url: string) => Promise<import("@codebolt/types").GoToPageResponse>;
59
- screenshot: () => Promise<unknown>;
70
+ screenshot: () => Promise<any>;
60
71
  getHTML: () => Promise<import("@codebolt/types").HtmlReceived>;
61
72
  getMarkdown: () => Promise<import("@codebolt/types").GetMarkdownResponse>;
62
73
  getPDF: () => void;
@@ -66,16 +77,33 @@ declare class Codebolt {
66
77
  getBrowserInfo: () => Promise<any>;
67
78
  extractText: () => Promise<import("@codebolt/types").ExtractTextResponse>;
68
79
  close: () => void;
69
- scroll: (direction: string, pixels: string) => Promise<unknown>;
70
- type: (elementid: string, text: string) => Promise<unknown>;
71
- click: (elementid: string) => Promise<unknown>;
72
- enter: () => Promise<unknown>;
73
- search: (elementid: string, query: string) => Promise<unknown>;
80
+ scroll: (direction: string, pixels: string) => Promise<any>;
81
+ type: (elementid: string, text: string) => Promise<any>;
82
+ click: (elementid: string) => Promise<any>;
83
+ enter: () => Promise<any>;
84
+ search: (elementid: string, query: string) => Promise<any>;
74
85
  };
75
86
  chat: {
76
87
  getChatHistory: () => Promise<import("@codebolt/types").ChatMessage[]>;
77
88
  setRequestHandler: (handler: (request: any, response: (data: any) => void) => void | Promise<void>) => void;
78
- onActionMessage: () => {
89
+ sendMessage: (message: string, payload: any) => void;
90
+ waitforReply: (message: string) => Promise<import("@codebolt/types").UserMessage>;
91
+ processStarted: (onStopClicked?: ((message: any) => void) | undefined) => {
92
+ stopProcess: () => void;
93
+ cleanup: () => void;
94
+ } | {
95
+ stopProcess: () => void;
96
+ cleanup?: undefined;
97
+ };
98
+ stopProcess: () => void;
99
+ processFinished: () => void;
100
+ sendConfirmationRequest: (confirmationMessage: string, buttons?: string[], withFeedback?: boolean) => Promise<string>;
101
+ askQuestion: (question: string, buttons?: string[], withFeedback?: boolean) => Promise<string>;
102
+ sendNotificationEvent: (notificationMessage: string, type: "debug" | "git" | "planner" | "browser" | "editor" | "terminal" | "preview") => void;
103
+ };
104
+ terminal: {
105
+ eventEmitter: {
106
+ cleanup?: (() => void) | undefined;
79
107
  [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
80
108
  addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
81
109
  on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
@@ -93,37 +121,11 @@ declare class Codebolt {
93
121
  prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
94
122
  eventNames(): (string | symbol)[];
95
123
  };
96
- sendMessage: (message: string, payload: any) => void;
97
- waitforReply: (message: string) => Promise<import("@codebolt/types").UserMessage>;
98
- processStarted: () => {
99
- event: {
100
- [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
101
- addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
102
- on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
103
- once<K_3>(eventName: string | symbol, listener: (...args: any[]) => void): any;
104
- removeListener<K_4>(eventName: string | symbol, listener: (...args: any[]) => void): any;
105
- off<K_5>(eventName: string | symbol, listener: (...args: any[]) => void): any;
106
- removeAllListeners(eventName?: string | symbol | undefined): any;
107
- setMaxListeners(n: number): any;
108
- getMaxListeners(): number;
109
- listeners<K_6>(eventName: string | symbol): Function[];
110
- rawListeners<K_7>(eventName: string | symbol): Function[];
111
- emit<K_8>(eventName: string | symbol, ...args: any[]): boolean;
112
- listenerCount<K_9>(eventName: string | symbol, listener?: Function | undefined): number;
113
- prependListener<K_10>(eventName: string | symbol, listener: (...args: any[]) => void): any;
114
- prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
115
- eventNames(): (string | symbol)[];
116
- };
117
- stopProcess: () => void;
118
- };
119
- stopProcess: () => void;
120
- processFinished: () => void;
121
- sendConfirmationRequest: (confirmationMessage: string, buttons?: string[], withFeedback?: boolean) => Promise<string>;
122
- askQuestion: (question: string, buttons?: string[], withFeedback?: boolean) => Promise<string>;
123
- sendNotificationEvent: (notificationMessage: string, type: "debug" | "git" | "planner" | "browser" | "editor" | "terminal" | "preview") => void;
124
- };
125
- terminal: {
126
- eventEmitter: {
124
+ executeCommand: (command: string, returnEmptyStringOnSuccess?: boolean) => Promise<any>;
125
+ executeCommandRunUntilError: (command: string, executeInMain?: boolean) => Promise<import("@codebolt/types").CommandError>;
126
+ sendManualInterrupt(): Promise<import("@codebolt/types").TerminalInterruptResponse>;
127
+ executeCommandWithStream(command: string, executeInMain?: boolean): {
128
+ cleanup?: (() => void) | undefined;
127
129
  [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
128
130
  addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
129
131
  on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
@@ -141,30 +143,23 @@ declare class Codebolt {
141
143
  prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
142
144
  eventNames(): (string | symbol)[];
143
145
  };
144
- executeCommand: (command: string, returnEmptyStringOnSuccess?: boolean) => Promise<unknown>;
145
- executeCommandRunUntilError: (command: string, executeInMain?: boolean) => Promise<import("@codebolt/types").CommandError>;
146
- sendManualInterrupt(): Promise<import("@codebolt/types").TerminalInterruptResponse>;
147
- executeCommandWithStream(command: string, executeInMain?: boolean): EventEmitter<[never]>;
148
146
  };
149
147
  codeutils: {
150
- getJsTree: (filePath?: string | undefined) => Promise<unknown>;
148
+ getJsTree: (filePath?: string | undefined) => Promise<import("./modules/codeutils").JSTreeResponse>;
151
149
  getAllFilesAsMarkDown: () => Promise<string>;
152
- performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<import("@codebolt/types").MatchProblemResponse>;
150
+ performMatch: (matcherDefinition: object, problemPatterns: any[], problems?: any[]) => Promise<import("@codebolt/types").MatchProblemResponse>;
153
151
  getMatcherList: () => Promise<import("@codebolt/types").GetMatcherListTreeResponse>;
154
152
  matchDetail: (matcher: string) => Promise<import("@codebolt/types").getMatchDetail>;
155
153
  };
156
154
  docutils: {
157
- pdf_to_text: (pdf_path: any) => Promise<string>;
155
+ pdf_to_text: (pdf_path: string) => Promise<string>;
158
156
  };
159
157
  crawler: {
160
158
  start: () => void;
161
159
  screenshot: () => void;
162
160
  goToPage: (url: string) => void;
163
161
  scroll: (direction: string) => void;
164
- click: (id: string) => Promise<unknown>;
165
- type: (id: string, text: string) => Promise<unknown>;
166
- enter: () => void;
167
- crawl: (query: string) => Promise<unknown>;
162
+ click: (id: string) => Promise<any>;
168
163
  };
169
164
  search: {
170
165
  init: (engine?: string) => void;
@@ -178,21 +173,51 @@ declare class Codebolt {
178
173
  retrieve_related_knowledge: (query: string, filename: string) => void;
179
174
  };
180
175
  codeparsers: {
181
- getClassesInFile: (file: any) => void;
182
- getFunctionsinClass: (file: any, className: any) => void;
183
- getAstTreeInFile: (file: any, className: any) => void;
176
+ getClassesInFile: (file: string) => Promise<{
177
+ error: string;
178
+ } | {
179
+ name: any;
180
+ location: string;
181
+ }[]>;
182
+ getFunctionsinClass: (file: string, className: string) => Promise<{
183
+ error: string;
184
+ } | {
185
+ name: string;
186
+ class: string;
187
+ location: string;
188
+ }[]>;
189
+ getAstTreeInFile: (file: string, className?: string | undefined) => Promise<import("./modules/codeparsers").ASTNode | {
190
+ error: string;
191
+ }>;
184
192
  };
185
193
  outputparsers: {
186
- init: (output: any) => void;
194
+ parseJSON: (jsonString: string) => {
195
+ success: boolean;
196
+ parsed?: any;
197
+ error?: Error | undefined;
198
+ };
199
+ parseXML: (xmlString: string) => {
200
+ success: boolean;
201
+ parsed?: any;
202
+ };
203
+ parseCSV: (csvString: string) => {
204
+ success: boolean;
205
+ parsed?: any[] | undefined;
206
+ error?: Error | undefined;
207
+ };
208
+ parseText: (text: string) => {
209
+ success: boolean;
210
+ parsed: string[];
211
+ };
187
212
  parseErrors: (output: any) => string[];
188
213
  parseWarnings: (output: any) => string[];
189
214
  };
190
215
  project: {
191
- getProjectSettings: (output: any) => void;
216
+ getProjectSettings: () => Promise<any>;
192
217
  getProjectPath: () => Promise<import("@codebolt/types").GetProjectPathResponse>;
193
218
  getRepoMap: (message: any) => Promise<import("@codebolt/types").GetProjectPathResponse>;
194
219
  runProject: () => void;
195
- getEditorFileStatus: () => Promise<unknown>;
220
+ getEditorFileStatus: () => Promise<any>;
196
221
  };
197
222
  dbmemory: {
198
223
  addKnowledge: (key: string, value: any) => Promise<import("@codebolt/types").MemorySetResponse>;
@@ -241,7 +266,6 @@ declare class Codebolt {
241
266
  getEnabledToolBoxes: () => Promise<any>;
242
267
  getLocalToolBoxes: () => Promise<any>;
243
268
  getMentionedToolBoxes: (userMessage: import("./utils").UserMessage) => Promise<any>;
244
- getAvailableToolBoxes: () => Promise<any>;
245
269
  searchAvailableToolBoxes: (query: string) => Promise<any>;
246
270
  listToolsFromToolBoxes: (toolBoxes: string[]) => Promise<any>;
247
271
  configureToolBox: (name: string, config: any) => Promise<any>;
@@ -260,6 +284,12 @@ declare class Codebolt {
260
284
  utils: {
261
285
  editFileAndApplyDiff: (filePath: string, diff: string, diffIdentifier: string, prompt: string, applyModel?: string | undefined) => Promise<any>;
262
286
  };
287
+ /**
288
+ * Sets up a listener for incoming messages with a direct handler function.
289
+ * @param {Function} handler - The handler function to call when a message is received.
290
+ * @returns {void}
291
+ */
292
+ onMessage(handler: (userMessage: any) => void | Promise<void> | any | Promise<any>): void;
263
293
  }
264
- declare const _default: Codebolt;
265
- export default _default;
294
+ declare const codebolt: Codebolt;
295
+ export default codebolt;
package/dist/index.js CHANGED
@@ -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("./modules/websocket"));
6
+ const websocket_1 = __importDefault(require("./core/websocket"));
7
7
  const fs_1 = __importDefault(require("./modules/fs"));
8
8
  const llm_1 = __importDefault(require("./modules/llm"));
9
9
  const terminal_1 = __importDefault(require("./modules/terminal"));
@@ -29,7 +29,7 @@ const ws_1 = __importDefault(require("ws"));
29
29
  const history_1 = require("./modules/history");
30
30
  const tools_1 = __importDefault(require("./modules/tools"));
31
31
  const agent_1 = __importDefault(require("./modules/agent"));
32
- const editFile_1 = __importDefault(require("./utils/editFile"));
32
+ const utils_1 = __importDefault(require("./modules/utils"));
33
33
  /**
34
34
  * @class Codebolt
35
35
  * @description This class provides a unified interface to interact with various modules.
@@ -65,7 +65,8 @@ class Codebolt {
65
65
  this.chatSummary = history_1.chatSummary;
66
66
  this.tools = tools_1.default;
67
67
  this.agent = agent_1.default;
68
- this.utils = editFile_1.default;
68
+ this.utils = utils_1.default;
69
+ console.log("Codebolt Agent initialized");
69
70
  websocket_1.default.initializeWebSocket();
70
71
  this.websocket = websocket_1.default.getWebsocket;
71
72
  }
@@ -92,5 +93,51 @@ class Codebolt {
92
93
  });
93
94
  });
94
95
  }
96
+ /**
97
+ * Sets up a listener for incoming messages with a direct handler function.
98
+ * @param {Function} handler - The handler function to call when a message is received.
99
+ * @returns {void}
100
+ */
101
+ onMessage(handler) {
102
+ const waitForConnection = () => {
103
+ if (websocket_1.default.messageManager) {
104
+ const handleUserMessage = async (response) => {
105
+ console.log("Message received By Agent Library Starting Custom Agent Handler Logic", response);
106
+ if (response.type === "messageResponse") {
107
+ try {
108
+ const result = await handler(response);
109
+ // Send processStoped with optional message
110
+ const message = {
111
+ "type": "processStoped"
112
+ };
113
+ // If handler returned data, include it as message
114
+ if (result !== undefined && result !== null) {
115
+ message.message = result;
116
+ }
117
+ websocket_1.default.messageManager.send(message);
118
+ }
119
+ catch (error) {
120
+ console.error('Error in user message handler:', error);
121
+ // Send processStoped even if there's an error
122
+ websocket_1.default.messageManager.send({
123
+ "type": "processStoped",
124
+ "error": error instanceof Error ? error.message : "Unknown error occurred"
125
+ });
126
+ }
127
+ }
128
+ };
129
+ websocket_1.default.messageManager.on('message', handleUserMessage);
130
+ }
131
+ else {
132
+ setTimeout(waitForConnection, 100);
133
+ }
134
+ };
135
+ waitForConnection();
136
+ }
95
137
  }
96
- exports.default = new Codebolt();
138
+ const codebolt = new Codebolt();
139
+ // For ES6 modules (import)
140
+ exports.default = codebolt;
141
+ // For CommonJS compatibility (require)
142
+ module.exports = codebolt;
143
+ module.exports.default = codebolt;