@codebolt/codeboltjs 1.0.0 → 1.0.1
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/.github/workflows/publish-to-npm.yml +18 -0
- package/License.md +21 -0
- package/Readme.md +27 -0
- package/package.json +22 -1
- package/src/index.ts +92 -0
- package/src/modules/browser.ts +266 -0
- package/src/modules/chat.ts +82 -0
- package/src/modules/codeparsers.ts +30 -0
- package/src/modules/codeutils.ts +19 -0
- package/src/modules/crawler.ts +109 -0
- package/src/modules/dbmemory.ts +51 -0
- package/src/modules/docutils.ts +18 -0
- package/src/modules/fs.ts +164 -0
- package/src/modules/git.ts +237 -0
- package/src/modules/knowledge.ts +5 -0
- package/src/modules/llm.ts +36 -0
- package/src/modules/outputparsers.ts +30 -0
- package/src/modules/project.ts +34 -0
- package/src/modules/rag.ts +28 -0
- package/src/modules/search.ts +35 -0
- package/src/modules/terminal.ts +31 -0
- package/src/modules/websocket.ts +59 -0
- package/tests/fs.test.js +89 -0
- package/tests/index.test.js +4 -0
- package/tsconfig.json +122 -0
- package/webpack.config.js +25 -0
- package/index.js +0 -41
- package/modules/browser.js +0 -88
- package/modules/chat.js +0 -27
- package/modules/codeboltfs.js +0 -119
- package/modules/codeparsers.js +0 -9
- package/modules/codeutils.js +0 -9
- package/modules/crawler.js +0 -63
- package/modules/dbmemory.js +0 -7
- package/modules/docutils.js +0 -5
- package/modules/git.js +0 -3
- package/modules/llm.js +0 -29
- package/modules/outputparsers.js +0 -12
- package/modules/rag.js +0 -10
- package/modules/search.js +0 -18
- package/modules/terminal.js +0 -28
- package/modules/websocket.js +0 -24
- /package/{modules/knowledge.js → tests/chat.test.js} +0 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A module for controlling a web crawler through WebSocket messages.
|
|
5
|
+
*/
|
|
6
|
+
const cbcrawler = {
|
|
7
|
+
/**
|
|
8
|
+
* Starts the crawler.
|
|
9
|
+
*/
|
|
10
|
+
start: () => {
|
|
11
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
12
|
+
"type": "crawlerEvent",
|
|
13
|
+
action: 'start'
|
|
14
|
+
}));
|
|
15
|
+
},
|
|
16
|
+
/**
|
|
17
|
+
* Takes a screenshot using the crawler.
|
|
18
|
+
*/
|
|
19
|
+
screenshot: () => {
|
|
20
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
21
|
+
"type": "crawlerEvent",
|
|
22
|
+
action: 'screenshot'
|
|
23
|
+
}));
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* Directs the crawler to navigate to a specified URL.
|
|
27
|
+
* @param url - The URL for the crawler to navigate to.
|
|
28
|
+
*/
|
|
29
|
+
goToPage: (url: string) => {
|
|
30
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
31
|
+
"type": "crawlerEvent",
|
|
32
|
+
action: 'goToPage',
|
|
33
|
+
url
|
|
34
|
+
}));
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Scrolls the crawler in a specified direction.
|
|
38
|
+
* @param direction - The direction to scroll ('up', 'down', 'left', 'right').
|
|
39
|
+
*/
|
|
40
|
+
scroll: (direction: string) => {
|
|
41
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
42
|
+
"type": "crawlerEvent",
|
|
43
|
+
action: 'scroll',
|
|
44
|
+
direction
|
|
45
|
+
}));
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* Simulates a click event on an element with the specified ID.
|
|
49
|
+
* @param id - The ID of the element to be clicked.
|
|
50
|
+
* @returns {Promise<any>} A promise that resolves when the click action is complete.
|
|
51
|
+
*/
|
|
52
|
+
click: (id: string) => {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
55
|
+
"type": "crawlerEvent",
|
|
56
|
+
action: 'click',
|
|
57
|
+
id
|
|
58
|
+
}));
|
|
59
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
60
|
+
const response = JSON.parse(data);
|
|
61
|
+
if (response.event === "clickFinished") {
|
|
62
|
+
resolve(response);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* Types the provided text into an element with the specified ID.
|
|
69
|
+
* @param id - The ID of the element where text will be typed.
|
|
70
|
+
* @param text - The text to type into the element.
|
|
71
|
+
* @returns {Promise<any>} A promise that resolves when the type action is complete.
|
|
72
|
+
*/
|
|
73
|
+
type: (id: string, text: string) => {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
76
|
+
"type": "crawlerEvent",
|
|
77
|
+
action: 'type',
|
|
78
|
+
id,
|
|
79
|
+
text
|
|
80
|
+
}));
|
|
81
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
82
|
+
const response = JSON.parse(data);
|
|
83
|
+
if (response.event === "typeFinished") {
|
|
84
|
+
resolve(response);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* Simulates the Enter key press using the crawler.
|
|
91
|
+
*/
|
|
92
|
+
enter: () => {
|
|
93
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
94
|
+
"type": "crawlerEvent",
|
|
95
|
+
action: 'enter'
|
|
96
|
+
}));
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Initiates a crawl process.
|
|
100
|
+
*/
|
|
101
|
+
crawl: () => {
|
|
102
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
103
|
+
"type": "crawlerEvent",
|
|
104
|
+
action: 'crawl'
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default cbcrawler;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A module for handling in-memory database operations via WebSocket.
|
|
5
|
+
*/
|
|
6
|
+
const dbmemory = {
|
|
7
|
+
/**
|
|
8
|
+
* Adds a key-value pair to the in-memory database.
|
|
9
|
+
* @param {string} key - The key under which to store the value.
|
|
10
|
+
* @param {any} value - The value to be stored.
|
|
11
|
+
* @returns {Promise<any>} A promise that resolves with the response from the memory set event.
|
|
12
|
+
*/
|
|
13
|
+
addKnowledge: (key: string, value: any): Promise<any> => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
16
|
+
"type": "memoryEvent",
|
|
17
|
+
'action': 'set',
|
|
18
|
+
key,
|
|
19
|
+
value
|
|
20
|
+
}));
|
|
21
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
22
|
+
const response = JSON.parse(data);
|
|
23
|
+
if (response.type === "memorySetResponse") {
|
|
24
|
+
resolve(response); // Resolve the Promise with the response data
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves a value from the in-memory database by key.
|
|
31
|
+
* @param {string} key - The key of the value to retrieve.
|
|
32
|
+
* @returns {Promise<any>} A promise that resolves with the response from the memory get event.
|
|
33
|
+
*/
|
|
34
|
+
getKnowledge: (key: string): Promise<any> => {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
37
|
+
"type": "memoryEvent",
|
|
38
|
+
'action': 'get',
|
|
39
|
+
key
|
|
40
|
+
}));
|
|
41
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
42
|
+
const response = JSON.parse(data);
|
|
43
|
+
if (response.type === "memoryGetResponse") {
|
|
44
|
+
resolve(response); // Resolve the Promise with the response data
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default dbmemory;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module for document utility functions.
|
|
3
|
+
*/
|
|
4
|
+
const cbdocutils = {
|
|
5
|
+
/**
|
|
6
|
+
* Converts a PDF document to text.
|
|
7
|
+
* @param pdf_path - The file path to the PDF document to be converted.
|
|
8
|
+
* @returns {Promise<string>} A promise that resolves with the converted text.
|
|
9
|
+
*/
|
|
10
|
+
pdf_to_text: (pdf_path: any): Promise<string> => {
|
|
11
|
+
// Implementation would go here
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
// PDF to text conversion logic
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default cbdocutils;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @module cbfs
|
|
5
|
+
* @description This module provides functionality to interact with the filesystem.
|
|
6
|
+
*/
|
|
7
|
+
const cbfs = {
|
|
8
|
+
/**
|
|
9
|
+
* @function createFile
|
|
10
|
+
* @description Creates a new file.
|
|
11
|
+
* @param {string} fileName - The name of the file to create.
|
|
12
|
+
* @param {string} source - The source content to write into the file.
|
|
13
|
+
* @param {string} filePath - The path where the file should be created.
|
|
14
|
+
* @returns {Promise<any>} A promise that resolves with the server response.
|
|
15
|
+
*/
|
|
16
|
+
createFile: (fileName: string, source: string, filePath: string): Promise<any> => {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
19
|
+
"type":"fsEvent",
|
|
20
|
+
"action": "createFile",
|
|
21
|
+
"message": {
|
|
22
|
+
fileName,
|
|
23
|
+
source,
|
|
24
|
+
filePath
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
28
|
+
const response = JSON.parse(data);
|
|
29
|
+
if (response.type === "createFileResponse") {
|
|
30
|
+
resolve(response);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* @function createFolder
|
|
37
|
+
* @description Creates a new folder.
|
|
38
|
+
* @param {string} folderName - The name of the folder to create.
|
|
39
|
+
* @param {string} folderPath - The path where the folder should be created.
|
|
40
|
+
* @returns {Promise<any>} A promise that resolves with the server response.
|
|
41
|
+
*/
|
|
42
|
+
createFolder: (folderName: string, folderPath: string): Promise<any> => {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
45
|
+
"type":"fsEvent",
|
|
46
|
+
"action": "createFolder",
|
|
47
|
+
"message": {
|
|
48
|
+
folderName,
|
|
49
|
+
folderPath
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
53
|
+
const response = JSON.parse(data);
|
|
54
|
+
if (response.type === "createFolderResponse") {
|
|
55
|
+
resolve(response);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* @function readFile
|
|
62
|
+
* @description Reads the content of a file.
|
|
63
|
+
* @param {string} filename - The name of the file to read.
|
|
64
|
+
* @param {string} filePath - The path of the file to read.
|
|
65
|
+
* @returns {Promise<any>} A promise that resolves with the server response.
|
|
66
|
+
*/
|
|
67
|
+
readFile: (filename: string, filePath: string): Promise<any> => {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
70
|
+
"type":"fsEvent",
|
|
71
|
+
"action": "readFile",
|
|
72
|
+
"message": {
|
|
73
|
+
filename,
|
|
74
|
+
filePath
|
|
75
|
+
},
|
|
76
|
+
}));
|
|
77
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
78
|
+
const response = JSON.parse(data);
|
|
79
|
+
if (response.type === "readFileResponse") {
|
|
80
|
+
resolve(response);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* @function updateFile
|
|
87
|
+
* @description Updates the content of a file.
|
|
88
|
+
* @param {string} filename - The name of the file to update.
|
|
89
|
+
* @param {string} filePath - The path of the file to update.
|
|
90
|
+
* @param {string} newContent - The new content to write into the file.
|
|
91
|
+
* @returns {Promise<any>} A promise that resolves with the server response.
|
|
92
|
+
*/
|
|
93
|
+
updateFile: (filename: string, filePath: string, newContent: string): Promise<any> => {
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
96
|
+
"type":"fsEvent",
|
|
97
|
+
"action": "updateFile",
|
|
98
|
+
"message": {
|
|
99
|
+
filename,
|
|
100
|
+
filePath,
|
|
101
|
+
newContent
|
|
102
|
+
},
|
|
103
|
+
}));
|
|
104
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
105
|
+
const response = JSON.parse(data);
|
|
106
|
+
if (response.type === "commandOutput") {
|
|
107
|
+
resolve(response);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* @function deleteFile
|
|
114
|
+
* @description Deletes a file.
|
|
115
|
+
* @param {string} filename - The name of the file to delete.
|
|
116
|
+
* @param {string} filePath - The path of the file to delete.
|
|
117
|
+
* @returns {Promise<any>} A promise that resolves with the server response.
|
|
118
|
+
*/
|
|
119
|
+
deleteFile: (filename: string, filePath: string): Promise<any> => {
|
|
120
|
+
return new Promise((resolve, reject) => {
|
|
121
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
122
|
+
"type":"fsEvent",
|
|
123
|
+
"action": "deleteFile",
|
|
124
|
+
"message": {
|
|
125
|
+
filename,
|
|
126
|
+
filePath
|
|
127
|
+
},
|
|
128
|
+
}));
|
|
129
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
130
|
+
const response = JSON.parse(data);
|
|
131
|
+
if (response.type === "deleteFileResponse") {
|
|
132
|
+
resolve(response);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
/**
|
|
138
|
+
* @function deleteFolder
|
|
139
|
+
* @description Deletes a folder.
|
|
140
|
+
* @param {string} foldername - The name of the folder to delete.
|
|
141
|
+
* @param {string} folderpath - The path of the folder to delete.
|
|
142
|
+
* @returns {Promise<any>} A promise that resolves with the server response.
|
|
143
|
+
*/
|
|
144
|
+
deleteFolder: (foldername: string, folderpath: string): Promise<any> => {
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
147
|
+
"type":"fsEvent",
|
|
148
|
+
"action": "deleteFolder",
|
|
149
|
+
"message": {
|
|
150
|
+
foldername,
|
|
151
|
+
folderpath
|
|
152
|
+
},
|
|
153
|
+
}));
|
|
154
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
155
|
+
const response = JSON.parse(data);
|
|
156
|
+
if (response.type === "deleteFolderResponse") {
|
|
157
|
+
resolve(response);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export default cbfs;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A service for interacting with Git operations via WebSocket messages.
|
|
5
|
+
*/
|
|
6
|
+
const gitService = {
|
|
7
|
+
/**
|
|
8
|
+
* Initializes a new Git repository at the given path.
|
|
9
|
+
* @param {string} path - The file system path where the Git repository should be initialized.
|
|
10
|
+
* @returns {Promise<any>} A promise that resolves with the response from the init event.
|
|
11
|
+
*/
|
|
12
|
+
init: async (path: string): Promise<any> => {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
15
|
+
"type": "gitEvent",
|
|
16
|
+
"action": "Init",
|
|
17
|
+
"path": path
|
|
18
|
+
}));
|
|
19
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
20
|
+
const response = JSON.parse(data);
|
|
21
|
+
if (response.type === "InitResponse") {
|
|
22
|
+
resolve(response);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* Clones a Git repository from the given URL to the specified path.
|
|
29
|
+
* @param {string} url - The URL of the Git repository to clone.
|
|
30
|
+
* @param {string} path - The file system path where the repository should be cloned to.
|
|
31
|
+
* @returns {Promise<any>} A promise that resolves with the response from the clone event.
|
|
32
|
+
*/
|
|
33
|
+
clone: async (url: string, path: string): Promise<any> => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
36
|
+
"type": "gitEvent",
|
|
37
|
+
"action": "Clone",
|
|
38
|
+
"url": url,
|
|
39
|
+
"path": path
|
|
40
|
+
}));
|
|
41
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
42
|
+
const response = JSON.parse(data);
|
|
43
|
+
if (response.type === "CloneResponse") {
|
|
44
|
+
resolve(response);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* Pulls the latest changes from the remote repository to the local repository at the given path.
|
|
51
|
+
* @param {string} path - The file system path of the local Git repository.
|
|
52
|
+
* @returns {Promise<any>} A promise that resolves with the response from the pull event.
|
|
53
|
+
*/
|
|
54
|
+
pull: async (path: string): Promise<any> => {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
57
|
+
"type": "gitEvent",
|
|
58
|
+
"action": "Pull",
|
|
59
|
+
"path": path
|
|
60
|
+
}));
|
|
61
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
62
|
+
const response = JSON.parse(data);
|
|
63
|
+
if (response.type === "PullResponse") {
|
|
64
|
+
resolve(response);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* Pushes local repository changes to the remote repository at the given path.
|
|
71
|
+
* @param {string} path - The file system path of the local Git repository.
|
|
72
|
+
* @returns {Promise<any>} A promise that resolves with the response from the push event.
|
|
73
|
+
*/
|
|
74
|
+
push: async (path: string): Promise<any> => {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
77
|
+
"type": "gitEvent",
|
|
78
|
+
"action": "Push",
|
|
79
|
+
"path": path
|
|
80
|
+
}));
|
|
81
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
82
|
+
const response = JSON.parse(data);
|
|
83
|
+
if (response.type === "PushResponse") {
|
|
84
|
+
resolve(response);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves the status of the local repository at the given path.
|
|
91
|
+
* @param {string} path - The file system path of the local Git repository.
|
|
92
|
+
* @returns {Promise<any>} A promise that resolves with the response from the status event.
|
|
93
|
+
*/
|
|
94
|
+
status: async (path: string): Promise<any> => {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
97
|
+
"type": "gitEvent",
|
|
98
|
+
"action": "Status",
|
|
99
|
+
"path": path
|
|
100
|
+
}));
|
|
101
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
102
|
+
const response = JSON.parse(data);
|
|
103
|
+
if (response.type === "StatusResponse") {
|
|
104
|
+
resolve(response);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Adds changes in the local repository to the staging area at the given path.
|
|
111
|
+
* @param {string} path - The file system path of the local Git repository.
|
|
112
|
+
* @returns {Promise<any>} A promise that resolves with the response from the add event.
|
|
113
|
+
*/
|
|
114
|
+
add: async (path: string): Promise<any> => {
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
117
|
+
"type": "gitEvent",
|
|
118
|
+
"action": "Add",
|
|
119
|
+
"path": path
|
|
120
|
+
}));
|
|
121
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
122
|
+
const response = JSON.parse(data);
|
|
123
|
+
if (response.type === "AddResponse") {
|
|
124
|
+
resolve(response);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Commits the staged changes in the local repository with the given commit message.
|
|
131
|
+
* @param {string} message - The commit message to use for the commit.
|
|
132
|
+
* @returns {Promise<any>} A promise that resolves with the response from the commit event.
|
|
133
|
+
*/
|
|
134
|
+
commit: async (message: string): Promise<any> => {
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
137
|
+
"type": "gitEvent",
|
|
138
|
+
"action": "Commit",
|
|
139
|
+
"message": message
|
|
140
|
+
}));
|
|
141
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
142
|
+
const response = JSON.parse(data);
|
|
143
|
+
if (response.type === "gitCommitResponse") {
|
|
144
|
+
resolve(response);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* Checks out a branch or commit in the local repository at the given path.
|
|
151
|
+
* @param {string} path - The file system path of the local Git repository.
|
|
152
|
+
* @param {string} branch - The name of the branch or commit to check out.
|
|
153
|
+
* @returns {Promise<any>} A promise that resolves with the response from the checkout event.
|
|
154
|
+
*/
|
|
155
|
+
checkout: async (path: string, branch: string): Promise<any> => {
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
158
|
+
"type": "gitEvent",
|
|
159
|
+
"action": "Checkout",
|
|
160
|
+
"path": path,
|
|
161
|
+
"branch": branch
|
|
162
|
+
}));
|
|
163
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
164
|
+
const response = JSON.parse(data);
|
|
165
|
+
if (response.type === "CheckoutResponse") {
|
|
166
|
+
resolve(response);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
/**
|
|
172
|
+
* Creates a new branch in the local repository at the given path.
|
|
173
|
+
* @param {string} path - The file system path of the local Git repository.
|
|
174
|
+
* @param {string} branch - The name of the new branch to create.
|
|
175
|
+
* @returns {Promise<any>} A promise that resolves with the response from the branch event.
|
|
176
|
+
*/
|
|
177
|
+
branch: async (path: string, branch: string): Promise<any> => {
|
|
178
|
+
return new Promise((resolve, reject) => {
|
|
179
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
180
|
+
"type": "gitEvent",
|
|
181
|
+
"action": "Branch",
|
|
182
|
+
"path": path,
|
|
183
|
+
"branch": branch
|
|
184
|
+
}));
|
|
185
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
186
|
+
const response = JSON.parse(data);
|
|
187
|
+
if (response.type === "BranchResponse") {
|
|
188
|
+
resolve(response);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
/**
|
|
194
|
+
* Retrieves the commit logs for the local repository at the given path.
|
|
195
|
+
* @param {string} path - The file system path of the local Git repository.
|
|
196
|
+
* @returns {Promise<any>} A promise that resolves with the response from the logs event.
|
|
197
|
+
*/
|
|
198
|
+
logs: async (path: string): Promise<any> => {
|
|
199
|
+
return new Promise((resolve, reject) => {
|
|
200
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
201
|
+
"type": "gitEvent",
|
|
202
|
+
"action": "Logs",
|
|
203
|
+
"path": path
|
|
204
|
+
}));
|
|
205
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
206
|
+
const response = JSON.parse(data);
|
|
207
|
+
if (response.type === "LogsResponse") {
|
|
208
|
+
resolve(response);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
/**
|
|
214
|
+
* Retrieves the diff of changes for a specific commit in the local repository.
|
|
215
|
+
* @param {string} commitHash - The hash of the commit to retrieve the diff for.
|
|
216
|
+
* @param {string} path - The file system path of the local Git repository.
|
|
217
|
+
* @returns {Promise<any>} A promise that resolves with the response from the diff event.
|
|
218
|
+
*/
|
|
219
|
+
diff: async (commitHash: string, path: string): Promise<any> => {
|
|
220
|
+
return new Promise((resolve, reject) => {
|
|
221
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
222
|
+
"type": "gitEvent",
|
|
223
|
+
"action": "Diff",
|
|
224
|
+
"path": path,
|
|
225
|
+
"commitHash": commitHash
|
|
226
|
+
}));
|
|
227
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
228
|
+
const response = JSON.parse(data);
|
|
229
|
+
if (response.type === "DiffResponse") {
|
|
230
|
+
resolve(response);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export default gitService;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A module for interacting with language learning models (LLMs) via WebSocket.
|
|
5
|
+
*/
|
|
6
|
+
const cbllm = {
|
|
7
|
+
/**
|
|
8
|
+
* Sends an inference request to the LLM and returns the model's response.
|
|
9
|
+
* The model is selected based on the provided `llmrole`. If the specific model
|
|
10
|
+
* for the role is not found, it falls back to the default model for the current agent,
|
|
11
|
+
* and ultimately to the default application-wide LLM if necessary.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} message - The input message or prompt to be sent to the LLM.
|
|
14
|
+
* @param {string} llmrole - The role of the LLM to determine which model to use.
|
|
15
|
+
* @returns {Promise<any>} A promise that resolves with the LLM's response.
|
|
16
|
+
*/
|
|
17
|
+
inference: async (message: string, llmrole: string): Promise<any> => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
20
|
+
"type": "inference",
|
|
21
|
+
"message": {
|
|
22
|
+
prompt: message,
|
|
23
|
+
llmrole
|
|
24
|
+
},
|
|
25
|
+
}));
|
|
26
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
27
|
+
const response = JSON.parse(data);
|
|
28
|
+
if (response.type === "llmResponse") {
|
|
29
|
+
resolve(response); // Resolve the Promise with the response data
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default cbllm;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A module for parsing output messages to identify errors and warnings.
|
|
3
|
+
*/
|
|
4
|
+
const cboutputparsers = {
|
|
5
|
+
/**
|
|
6
|
+
* Initializes the output parser module.
|
|
7
|
+
* Currently, this function does not perform any operations.
|
|
8
|
+
* @param {any} output - The output to be initialized.
|
|
9
|
+
*/
|
|
10
|
+
init: (output: any) => {
|
|
11
|
+
// Initialization code can be added here if necessary
|
|
12
|
+
},
|
|
13
|
+
/**
|
|
14
|
+
* Parses the given output and returns all the error messages.
|
|
15
|
+
* @param {any} output - The output to parse for error messages.
|
|
16
|
+
* @returns {string[]} An array of error messages.
|
|
17
|
+
*/
|
|
18
|
+
parseErrors: (output: any): string[] => {
|
|
19
|
+
return output.split('\n').filter((line: string) => line.includes('Error:'));
|
|
20
|
+
},
|
|
21
|
+
/**
|
|
22
|
+
* Parses the given output and returns all the warning messages.
|
|
23
|
+
* @param {any} output - The output to parse for warning messages.
|
|
24
|
+
* @returns {string[]} An array of warning messages.
|
|
25
|
+
*/
|
|
26
|
+
parseWarnings: (output: any): string[] => {
|
|
27
|
+
return output.split('\n').filter((line: string) => line.includes('Warning:'));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export default cboutputparsers;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A module for interacting with project settings and paths.
|
|
5
|
+
*/
|
|
6
|
+
const cbproject = {
|
|
7
|
+
/**
|
|
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.
|
|
11
|
+
*/
|
|
12
|
+
getProjectSettings: (output: any) => {
|
|
13
|
+
// Implementation for getting project settings will be added here
|
|
14
|
+
},
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the path of the current project.
|
|
17
|
+
* @returns {Promise<any>} A promise that resolves with the project path response.
|
|
18
|
+
*/
|
|
19
|
+
getProjectPath: (): Promise<any> => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
22
|
+
"type": "settingEvent",
|
|
23
|
+
"action": "getProjectPath"
|
|
24
|
+
}));
|
|
25
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
26
|
+
const response = JSON.parse(data);
|
|
27
|
+
if (response.type === "getProjectPathResponse") {
|
|
28
|
+
resolve(response);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export default cbproject
|