@codebolt/codeboltjs 2.0.4 → 2.0.5
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.
- package/dist/core/messageManager.d.ts +47 -0
- package/dist/core/messageManager.js +128 -0
- package/dist/{modules → core}/websocket.d.ts +5 -0
- package/dist/{modules → core}/websocket.js +13 -9
- package/dist/index.d.ts +42 -53
- package/dist/index.js +49 -4
- package/dist/modules/agent.js +26 -58
- package/dist/modules/browser.d.ts +7 -7
- package/dist/modules/browser.js +75 -195
- package/dist/modules/chat.d.ts +8 -20
- package/dist/modules/chat.js +60 -123
- package/dist/modules/codeutils.d.ts +1 -1
- package/dist/modules/codeutils.js +30 -107
- package/dist/modules/crawler.d.ts +1 -16
- package/dist/modules/crawler.js +13 -72
- package/dist/modules/dbmemory.js +12 -28
- package/dist/modules/debug.js +17 -33
- package/dist/modules/fs.d.ts +1 -1
- package/dist/modules/fs.js +82 -162
- package/dist/modules/git.js +60 -148
- package/dist/modules/history.js +11 -27
- package/dist/modules/llm.js +8 -16
- package/dist/modules/project.d.ts +1 -1
- package/dist/modules/project.js +16 -40
- package/dist/modules/state.js +29 -69
- package/dist/modules/task.js +19 -43
- package/dist/modules/terminal.d.ts +3 -2
- package/dist/modules/terminal.js +36 -47
- package/dist/modules/tokenizer.js +15 -31
- package/dist/modules/tools.d.ts +0 -6
- package/dist/modules/tools.js +41 -179
- package/dist/modules/utils.js +22 -0
- package/dist/modules/vectordb.js +30 -62
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/dist/utils/editFile.js +0 -30
- /package/dist/{utils/editFile.d.ts → modules/utils.d.ts} +0 -0
- /package/dist/{modules → utils}/toolBox.d.ts +0 -0
- /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
|
*/
|
|
@@ -60,16 +61,13 @@ class cbws {
|
|
|
60
61
|
reject(error);
|
|
61
62
|
});
|
|
62
63
|
this.websocket.on('open', () => {
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// "message": initialMessage
|
|
67
|
-
// }));
|
|
68
|
-
// resolve(this.websocket);
|
|
69
|
-
// }
|
|
64
|
+
// Initialize the message manager with this websocket
|
|
65
|
+
messageManager_1.default.initialize(this.websocket);
|
|
66
|
+
resolve(this.websocket);
|
|
70
67
|
});
|
|
71
|
-
this.websocket.on('
|
|
72
|
-
//
|
|
68
|
+
this.websocket.on('close', () => {
|
|
69
|
+
// Clean up pending requests when connection closes
|
|
70
|
+
messageManager_1.default.cleanup();
|
|
73
71
|
});
|
|
74
72
|
});
|
|
75
73
|
}
|
|
@@ -86,5 +84,11 @@ class cbws {
|
|
|
86
84
|
return this.websocket;
|
|
87
85
|
}
|
|
88
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the message manager instance
|
|
89
|
+
*/
|
|
90
|
+
get messageManager() {
|
|
91
|
+
return messageManager_1.default;
|
|
92
|
+
}
|
|
89
93
|
}
|
|
90
94
|
exports.default = new cbws();
|
package/dist/index.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ declare class Codebolt {
|
|
|
34
34
|
success: boolean;
|
|
35
35
|
result: any;
|
|
36
36
|
}>;
|
|
37
|
-
writeToFile: (relPath: string, newContent: string) => Promise<
|
|
37
|
+
writeToFile: (relPath: string, newContent: string) => Promise<any>;
|
|
38
38
|
};
|
|
39
39
|
git: {
|
|
40
40
|
init: (path: string) => Promise<any>;
|
|
@@ -53,10 +53,10 @@ declare class Codebolt {
|
|
|
53
53
|
inference: (message: string, llmrole: string) => Promise<import("@codebolt/types").LLMResponse>;
|
|
54
54
|
};
|
|
55
55
|
browser: {
|
|
56
|
-
newPage: () => Promise<
|
|
56
|
+
newPage: () => Promise<any>;
|
|
57
57
|
getUrl: () => Promise<import("@codebolt/types").UrlResponse>;
|
|
58
58
|
goToPage: (url: string) => Promise<import("@codebolt/types").GoToPageResponse>;
|
|
59
|
-
screenshot: () => Promise<
|
|
59
|
+
screenshot: () => Promise<any>;
|
|
60
60
|
getHTML: () => Promise<import("@codebolt/types").HtmlReceived>;
|
|
61
61
|
getMarkdown: () => Promise<import("@codebolt/types").GetMarkdownResponse>;
|
|
62
62
|
getPDF: () => void;
|
|
@@ -66,16 +66,33 @@ declare class Codebolt {
|
|
|
66
66
|
getBrowserInfo: () => Promise<any>;
|
|
67
67
|
extractText: () => Promise<import("@codebolt/types").ExtractTextResponse>;
|
|
68
68
|
close: () => void;
|
|
69
|
-
scroll: (direction: string, pixels: string) => Promise<
|
|
70
|
-
type: (elementid: string, text: string) => Promise<
|
|
71
|
-
click: (elementid: string) => Promise<
|
|
72
|
-
enter: () => Promise<
|
|
73
|
-
search: (elementid: string, query: string) => Promise<
|
|
69
|
+
scroll: (direction: string, pixels: string) => Promise<any>;
|
|
70
|
+
type: (elementid: string, text: string) => Promise<any>;
|
|
71
|
+
click: (elementid: string) => Promise<any>;
|
|
72
|
+
enter: () => Promise<any>;
|
|
73
|
+
search: (elementid: string, query: string) => Promise<any>;
|
|
74
74
|
};
|
|
75
75
|
chat: {
|
|
76
76
|
getChatHistory: () => Promise<import("@codebolt/types").ChatMessage[]>;
|
|
77
77
|
setRequestHandler: (handler: (request: any, response: (data: any) => void) => void | Promise<void>) => void;
|
|
78
|
-
|
|
78
|
+
sendMessage: (message: string, payload: any) => void;
|
|
79
|
+
waitforReply: (message: string) => Promise<import("@codebolt/types").UserMessage>;
|
|
80
|
+
processStarted: (onStopClicked?: ((message: any) => void) | undefined) => {
|
|
81
|
+
stopProcess: () => void;
|
|
82
|
+
cleanup: () => void;
|
|
83
|
+
} | {
|
|
84
|
+
stopProcess: () => void;
|
|
85
|
+
cleanup?: undefined;
|
|
86
|
+
};
|
|
87
|
+
stopProcess: () => void;
|
|
88
|
+
processFinished: () => void;
|
|
89
|
+
sendConfirmationRequest: (confirmationMessage: string, buttons?: string[], withFeedback?: boolean) => Promise<string>;
|
|
90
|
+
askQuestion: (question: string, buttons?: string[], withFeedback?: boolean) => Promise<string>;
|
|
91
|
+
sendNotificationEvent: (notificationMessage: string, type: "debug" | "git" | "planner" | "browser" | "editor" | "terminal" | "preview") => void;
|
|
92
|
+
};
|
|
93
|
+
terminal: {
|
|
94
|
+
eventEmitter: {
|
|
95
|
+
cleanup?: (() => void) | undefined;
|
|
79
96
|
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
80
97
|
addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
81
98
|
on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
@@ -93,37 +110,11 @@ declare class Codebolt {
|
|
|
93
110
|
prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
94
111
|
eventNames(): (string | symbol)[];
|
|
95
112
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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: {
|
|
113
|
+
executeCommand: (command: string, returnEmptyStringOnSuccess?: boolean) => Promise<any>;
|
|
114
|
+
executeCommandRunUntilError: (command: string, executeInMain?: boolean) => Promise<import("@codebolt/types").CommandError>;
|
|
115
|
+
sendManualInterrupt(): Promise<import("@codebolt/types").TerminalInterruptResponse>;
|
|
116
|
+
executeCommandWithStream(command: string, executeInMain?: boolean): {
|
|
117
|
+
cleanup?: (() => void) | undefined;
|
|
127
118
|
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
128
119
|
addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
129
120
|
on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
@@ -141,13 +132,9 @@ declare class Codebolt {
|
|
|
141
132
|
prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
142
133
|
eventNames(): (string | symbol)[];
|
|
143
134
|
};
|
|
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
135
|
};
|
|
149
136
|
codeutils: {
|
|
150
|
-
getJsTree: (filePath?: string | undefined) => Promise<
|
|
137
|
+
getJsTree: (filePath?: string | undefined) => Promise<any>;
|
|
151
138
|
getAllFilesAsMarkDown: () => Promise<string>;
|
|
152
139
|
performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<import("@codebolt/types").MatchProblemResponse>;
|
|
153
140
|
getMatcherList: () => Promise<import("@codebolt/types").GetMatcherListTreeResponse>;
|
|
@@ -161,10 +148,7 @@ declare class Codebolt {
|
|
|
161
148
|
screenshot: () => void;
|
|
162
149
|
goToPage: (url: string) => void;
|
|
163
150
|
scroll: (direction: string) => void;
|
|
164
|
-
click: (id: string) => Promise<
|
|
165
|
-
type: (id: string, text: string) => Promise<unknown>;
|
|
166
|
-
enter: () => void;
|
|
167
|
-
crawl: (query: string) => Promise<unknown>;
|
|
151
|
+
click: (id: string) => Promise<any>;
|
|
168
152
|
};
|
|
169
153
|
search: {
|
|
170
154
|
init: (engine?: string) => void;
|
|
@@ -192,7 +176,7 @@ declare class Codebolt {
|
|
|
192
176
|
getProjectPath: () => Promise<import("@codebolt/types").GetProjectPathResponse>;
|
|
193
177
|
getRepoMap: (message: any) => Promise<import("@codebolt/types").GetProjectPathResponse>;
|
|
194
178
|
runProject: () => void;
|
|
195
|
-
getEditorFileStatus: () => Promise<
|
|
179
|
+
getEditorFileStatus: () => Promise<any>;
|
|
196
180
|
};
|
|
197
181
|
dbmemory: {
|
|
198
182
|
addKnowledge: (key: string, value: any) => Promise<import("@codebolt/types").MemorySetResponse>;
|
|
@@ -241,7 +225,6 @@ declare class Codebolt {
|
|
|
241
225
|
getEnabledToolBoxes: () => Promise<any>;
|
|
242
226
|
getLocalToolBoxes: () => Promise<any>;
|
|
243
227
|
getMentionedToolBoxes: (userMessage: import("./utils").UserMessage) => Promise<any>;
|
|
244
|
-
getAvailableToolBoxes: () => Promise<any>;
|
|
245
228
|
searchAvailableToolBoxes: (query: string) => Promise<any>;
|
|
246
229
|
listToolsFromToolBoxes: (toolBoxes: string[]) => Promise<any>;
|
|
247
230
|
configureToolBox: (name: string, config: any) => Promise<any>;
|
|
@@ -260,6 +243,12 @@ declare class Codebolt {
|
|
|
260
243
|
utils: {
|
|
261
244
|
editFileAndApplyDiff: (filePath: string, diff: string, diffIdentifier: string, prompt: string, applyModel?: string | undefined) => Promise<any>;
|
|
262
245
|
};
|
|
246
|
+
/**
|
|
247
|
+
* Sets up a listener for incoming messages with a direct handler function.
|
|
248
|
+
* @param {Function} handler - The handler function to call when a message is received.
|
|
249
|
+
* @returns {void}
|
|
250
|
+
*/
|
|
251
|
+
onMessage(handler: (userMessage: any) => void | Promise<void> | any | Promise<any>): void;
|
|
263
252
|
}
|
|
264
|
-
declare const
|
|
265
|
-
export default
|
|
253
|
+
declare const codebolt: Codebolt;
|
|
254
|
+
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("./
|
|
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
|
|
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,7 @@ 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 =
|
|
68
|
+
this.utils = utils_1.default;
|
|
69
69
|
websocket_1.default.initializeWebSocket();
|
|
70
70
|
this.websocket = websocket_1.default.getWebsocket;
|
|
71
71
|
}
|
|
@@ -92,5 +92,50 @@ class Codebolt {
|
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Sets up a listener for incoming messages with a direct handler function.
|
|
97
|
+
* @param {Function} handler - The handler function to call when a message is received.
|
|
98
|
+
* @returns {void}
|
|
99
|
+
*/
|
|
100
|
+
onMessage(handler) {
|
|
101
|
+
const waitForConnection = () => {
|
|
102
|
+
if (websocket_1.default.messageManager) {
|
|
103
|
+
const handleUserMessage = async (response) => {
|
|
104
|
+
if (response.type === "messageResponse") {
|
|
105
|
+
try {
|
|
106
|
+
const result = await handler(response);
|
|
107
|
+
// Send processStoped with optional message
|
|
108
|
+
const message = {
|
|
109
|
+
"type": "processStoped"
|
|
110
|
+
};
|
|
111
|
+
// If handler returned data, include it as message
|
|
112
|
+
if (result !== undefined && result !== null) {
|
|
113
|
+
message.message = result;
|
|
114
|
+
}
|
|
115
|
+
websocket_1.default.messageManager.send(message);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.error('Error in user message handler:', error);
|
|
119
|
+
// Send processStoped even if there's an error
|
|
120
|
+
websocket_1.default.messageManager.send({
|
|
121
|
+
"type": "processStoped",
|
|
122
|
+
"error": error instanceof Error ? error.message : "Unknown error occurred"
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
websocket_1.default.messageManager.on('message', handleUserMessage);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
setTimeout(waitForConnection, 100);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
waitForConnection();
|
|
134
|
+
}
|
|
95
135
|
}
|
|
96
|
-
|
|
136
|
+
const codebolt = new Codebolt();
|
|
137
|
+
// For ES6 modules (import)
|
|
138
|
+
exports.default = codebolt;
|
|
139
|
+
// For CommonJS compatibility (require)
|
|
140
|
+
module.exports = codebolt;
|
|
141
|
+
module.exports.default = codebolt;
|
package/dist/modules/agent.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.FilterUsing = exports.Agents = exports.AgentLocation = void 0;
|
|
7
|
-
const websocket_1 = __importDefault(require("
|
|
7
|
+
const websocket_1 = __importDefault(require("../core/websocket"));
|
|
8
8
|
var AgentLocation;
|
|
9
9
|
(function (AgentLocation) {
|
|
10
10
|
AgentLocation["ALL"] = "all";
|
|
@@ -30,23 +30,15 @@ const codeboltAgent = {
|
|
|
30
30
|
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
|
|
31
31
|
*/
|
|
32
32
|
findAgent: (task, maxResult = 1, agents = [], agentLocaltion = AgentLocation.ALL, getFrom) => {
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}));
|
|
43
|
-
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
44
|
-
const response = JSON.parse(data);
|
|
45
|
-
if (response.type === "findAgentByTaskResponse") {
|
|
46
|
-
resolve(response); // Resolve the Promise with the agent details
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
33
|
+
return websocket_1.default.messageManager.sendAndWaitForResponse({
|
|
34
|
+
"type": "agentEvent",
|
|
35
|
+
"action": "findAgent",
|
|
36
|
+
"task": task,
|
|
37
|
+
"agents": agents, // for filter in vector db
|
|
38
|
+
"maxResult": maxResult,
|
|
39
|
+
"location": agentLocaltion,
|
|
40
|
+
"getFrom": getFrom
|
|
41
|
+
}, "findAgentByTaskResponse");
|
|
50
42
|
},
|
|
51
43
|
/**
|
|
52
44
|
* Starts an agent for the specified task.
|
|
@@ -54,58 +46,34 @@ const codeboltAgent = {
|
|
|
54
46
|
* @returns {Promise<void>} A promise that resolves when the agent has been successfully started.
|
|
55
47
|
*/
|
|
56
48
|
startAgent: (agentId, task) => {
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}));
|
|
64
|
-
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
65
|
-
const response = JSON.parse(data);
|
|
66
|
-
if (response.type === "taskCompletionResponse" && response.agentId === agentId) {
|
|
67
|
-
resolve(response); // Resolve the Promise when the agent has been successfully started
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
49
|
+
return websocket_1.default.messageManager.sendAndWaitForResponse({
|
|
50
|
+
"type": "agentEvent",
|
|
51
|
+
"action": "startAgent",
|
|
52
|
+
"agentId": agentId,
|
|
53
|
+
"task": task
|
|
54
|
+
}, "taskCompletionResponse");
|
|
71
55
|
},
|
|
72
56
|
/**
|
|
73
57
|
* Lists all available agents.
|
|
74
58
|
* @returns {Promise<any>} A promise that resolves with the list of agents.
|
|
75
59
|
*/
|
|
76
60
|
getAgentsList: (type = Agents.DOWNLOADED) => {
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}));
|
|
83
|
-
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
84
|
-
const response = JSON.parse(data);
|
|
85
|
-
if (response.type === "listAgentsResponse") {
|
|
86
|
-
resolve(response); // Resolve the Promise with the list of agents
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
61
|
+
return websocket_1.default.messageManager.sendAndWaitForResponse({
|
|
62
|
+
"type": "agentEvent",
|
|
63
|
+
"action": "listAgents",
|
|
64
|
+
"agentType": type,
|
|
65
|
+
}, "listAgentsResponse");
|
|
90
66
|
},
|
|
91
67
|
/**
|
|
92
68
|
* Lists all available agents.
|
|
93
69
|
* @returns {Promise<any>} A promise that resolves with the list of agents.
|
|
94
70
|
*/
|
|
95
71
|
getAgentsDetail: (agentList = []) => {
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}));
|
|
102
|
-
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
103
|
-
const response = JSON.parse(data);
|
|
104
|
-
if (response.type === "listAgentsResponse") {
|
|
105
|
-
resolve(response); // Resolve the Promise with the list of agents
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
72
|
+
return websocket_1.default.messageManager.sendAndWaitForResponse({
|
|
73
|
+
"type": "agentEvent",
|
|
74
|
+
"action": "agentsDetail",
|
|
75
|
+
"agentList": agentList
|
|
76
|
+
}, "listAgentsResponse");
|
|
109
77
|
}
|
|
110
78
|
};
|
|
111
79
|
exports.default = codeboltAgent;
|
|
@@ -6,7 +6,7 @@ declare const cbbrowser: {
|
|
|
6
6
|
/**
|
|
7
7
|
* Opens a new page in the browser.
|
|
8
8
|
*/
|
|
9
|
-
newPage: () => Promise<
|
|
9
|
+
newPage: () => Promise<any>;
|
|
10
10
|
/**
|
|
11
11
|
* Retrieves the current URL of the browser's active page.
|
|
12
12
|
* @returns {Promise<UrlResponse>} A promise that resolves with the URL.
|
|
@@ -21,7 +21,7 @@ declare const cbbrowser: {
|
|
|
21
21
|
/**
|
|
22
22
|
* Takes a screenshot of the current page.
|
|
23
23
|
*/
|
|
24
|
-
screenshot: () => Promise<
|
|
24
|
+
screenshot: () => Promise<any>;
|
|
25
25
|
/**
|
|
26
26
|
* Retrieves the HTML content of the current page.
|
|
27
27
|
* @returns {Promise<HtmlReceived>} A promise that resolves with the HTML content.
|
|
@@ -72,32 +72,32 @@ declare const cbbrowser: {
|
|
|
72
72
|
* @param {string} pixels - The number of pixels to scroll.
|
|
73
73
|
* @returns {Promise<any>} A promise that resolves when the scroll action is complete.
|
|
74
74
|
*/
|
|
75
|
-
scroll: (direction: string, pixels: string) => Promise<
|
|
75
|
+
scroll: (direction: string, pixels: string) => Promise<any>;
|
|
76
76
|
/**
|
|
77
77
|
* Types text into a specified element on the page.
|
|
78
78
|
* @param {string} elementid - The ID of the element to type into.
|
|
79
79
|
* @param {string} text - The text to type.
|
|
80
80
|
* @returns {Promise<any>} A promise that resolves when the typing action is complete.
|
|
81
81
|
*/
|
|
82
|
-
type: (elementid: string, text: string) => Promise<
|
|
82
|
+
type: (elementid: string, text: string) => Promise<any>;
|
|
83
83
|
/**
|
|
84
84
|
* Clicks on a specified element on the page.
|
|
85
85
|
* @param {string} elementid - The ID of the element to click.
|
|
86
86
|
* @returns {Promise<any>} A promise that resolves when the click action is complete.
|
|
87
87
|
*/
|
|
88
|
-
click: (elementid: string) => Promise<
|
|
88
|
+
click: (elementid: string) => Promise<any>;
|
|
89
89
|
/**
|
|
90
90
|
* Simulates the Enter key press on the current page.
|
|
91
91
|
* @returns {Promise<any>} A promise that resolves when the Enter action is complete.
|
|
92
92
|
*/
|
|
93
|
-
enter: () => Promise<
|
|
93
|
+
enter: () => Promise<any>;
|
|
94
94
|
/**
|
|
95
95
|
* Performs a search on the current page using a specified query.
|
|
96
96
|
* @param {string} elementid - The ID of the element to perform the search in.
|
|
97
97
|
* @param {string} query - The search query.
|
|
98
98
|
* @returns {Promise<any>} A promise that resolves with the search results.
|
|
99
99
|
*/
|
|
100
|
-
search: (elementid: string, query: string) => Promise<
|
|
100
|
+
search: (elementid: string, query: string) => Promise<any>;
|
|
101
101
|
};
|
|
102
102
|
export default cbbrowser;
|
|
103
103
|
/***
|