@codebolt/codeboltjs 1.1.75 → 1.1.77
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 +1 -1
- package/docs/modules/_internal_.EventEmitter.html +6 -0
- package/docs/modules/_internal_.WebSocket.html +21 -0
- package/docs/modules/_internal_._node_stream_consumers_.html +6 -0
- package/docs/modules/_internal_._node_stream_promises_.html +3 -0
- package/docs/modules/_internal_.html +228 -0
- package/docs/modules/_internal_.internal.finished.html +2 -0
- package/docs/modules/_internal_.internal.html +36 -0
- package/docs/modules/_internal_.internal.pipeline.html +2 -0
- package/index.d.ts +254 -0
- package/modules/browser.d.ts +108 -0
- package/modules/browser.js +331 -0
- package/modules/chat.d.ts +64 -0
- package/modules/chat.js +190 -0
- package/modules/codeparsers.d.ts +23 -0
- package/modules/codeparsers.js +30 -0
- package/modules/codeutils.d.ts +37 -0
- package/modules/codeutils.js +166 -0
- package/modules/crawler.d.ts +45 -0
- package/modules/crawler.js +123 -0
- package/modules/dbmemory.d.ts +20 -0
- package/modules/dbmemory.js +54 -0
- package/modules/debug.d.ts +23 -0
- package/modules/debug.js +64 -0
- package/modules/docutils.d.ts +12 -0
- package/modules/docutils.js +19 -0
- package/modules/fs.d.ts +94 -0
- package/modules/fs.js +264 -0
- package/modules/git.d.ts +76 -0
- package/modules/git.js +240 -0
- package/modules/history.d.ts +19 -0
- package/modules/history.js +46 -0
- package/modules/knowledge.d.ts +2 -0
- package/modules/knowledge.js +6 -0
- package/modules/llm.d.ts +18 -0
- package/modules/llm.js +39 -0
- package/modules/mcp.d.ts +8 -0
- package/modules/mcp.js +139 -0
- package/modules/outputparsers.d.ts +24 -0
- package/modules/outputparsers.js +32 -0
- package/modules/project.d.ts +21 -0
- package/modules/project.js +72 -0
- package/modules/rag.d.ts +22 -0
- package/modules/rag.js +30 -0
- package/modules/search.d.ts +23 -0
- package/modules/search.js +37 -0
- package/modules/state.d.ts +21 -0
- package/modules/state.js +68 -0
- package/modules/task.d.ts +23 -0
- package/modules/task.js +75 -0
- package/modules/terminal.d.ts +46 -0
- package/modules/terminal.js +108 -0
- package/modules/tokenizer.d.ts +19 -0
- package/modules/tokenizer.js +56 -0
- package/modules/vectordb.d.ts +33 -0
- package/modules/vectordb.js +103 -0
- package/modules/websocket.d.ts +27 -0
- package/modules/websocket.js +88 -0
- package/package.json +3 -5
- package/src/modules/browser.ts +352 -0
- package/src/modules/chat.ts +193 -0
- package/src/modules/codeparsers.ts +30 -0
- package/src/modules/codeutils.ts +181 -0
- package/src/modules/crawler.ts +121 -0
- package/src/modules/dbmemory.ts +52 -0
- package/src/modules/debug.ts +68 -0
- package/src/modules/docutils.ts +18 -0
- package/src/modules/fs.ts +263 -0
- package/src/modules/git.ts +237 -0
- package/src/modules/history.ts +61 -0
- package/src/modules/knowledge.ts +5 -0
- package/src/modules/llm.ts +36 -0
- package/src/modules/mcp.ts +127 -0
- package/src/modules/outputparsers.ts +30 -0
- package/src/modules/project.ts +68 -0
- package/src/modules/rag.ts +28 -0
- package/src/modules/search.ts +35 -0
- package/src/modules/state.ts +69 -0
- package/src/modules/task.ts +73 -0
- package/src/modules/terminal.ts +114 -0
- package/src/modules/tokenizer.ts +56 -0
- package/src/modules/vectordb.ts +102 -0
- package/src/modules/websocket.ts +89 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
import {CreateFileResponse,CreateFolderResponse,ReadFileResponse,UpdateFileResponse,DeleteFileResponse,DeleteFolderResponse} from '@codebolt/types'
|
|
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<CreateFileResponse>} A promise that resolves with the server response.
|
|
15
|
+
*/
|
|
16
|
+
createFile: (fileName: string, source: string, filePath: string): Promise<CreateFileResponse> => {
|
|
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<CreateFolderResponse>} A promise that resolves with the server response.
|
|
41
|
+
*/
|
|
42
|
+
createFolder: (folderName: string, folderPath: string): Promise<CreateFolderResponse> => {
|
|
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<ReadFileResponse>} A promise that resolves with the server response.
|
|
66
|
+
*/
|
|
67
|
+
readFile: (filePath: string): Promise<ReadFileResponse> => {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
70
|
+
"type":"fsEvent",
|
|
71
|
+
"action": "readFile",
|
|
72
|
+
"message": {
|
|
73
|
+
filePath
|
|
74
|
+
},
|
|
75
|
+
}));
|
|
76
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
77
|
+
const response = JSON.parse(data);
|
|
78
|
+
if (response.type === "readFileResponse") {
|
|
79
|
+
resolve(response);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* @function updateFile
|
|
86
|
+
* @description Updates the content of a file.
|
|
87
|
+
* @param {string} filename - The name of the file to update.
|
|
88
|
+
* @param {string} filePath - The path of the file to update.
|
|
89
|
+
* @param {string} newContent - The new content to write into the file.
|
|
90
|
+
* @returns {Promise<UpdateFileResponse>} A promise that resolves with the server response.
|
|
91
|
+
*/
|
|
92
|
+
updateFile: (filename: string, filePath: string, newContent: string): Promise<UpdateFileResponse> => {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
95
|
+
"type":"fsEvent",
|
|
96
|
+
"action": "updateFile",
|
|
97
|
+
"message": {
|
|
98
|
+
filename,
|
|
99
|
+
filePath,
|
|
100
|
+
newContent
|
|
101
|
+
},
|
|
102
|
+
}));
|
|
103
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
104
|
+
const response = JSON.parse(data);
|
|
105
|
+
if (response.type === "commandOutput") {
|
|
106
|
+
resolve(response);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* @function deleteFile
|
|
113
|
+
* @description Deletes a file.
|
|
114
|
+
* @param {string} filename - The name of the file to delete.
|
|
115
|
+
* @param {string} filePath - The path of the file to delete.
|
|
116
|
+
* @returns {Promise<DeleteFileResponse>} A promise that resolves with the server response.
|
|
117
|
+
*/
|
|
118
|
+
deleteFile: (filename: string, filePath: string): Promise<DeleteFileResponse> => {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
121
|
+
"type":"fsEvent",
|
|
122
|
+
"action": "deleteFile",
|
|
123
|
+
"message": {
|
|
124
|
+
filename,
|
|
125
|
+
filePath
|
|
126
|
+
},
|
|
127
|
+
}));
|
|
128
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
129
|
+
const response = JSON.parse(data);
|
|
130
|
+
if (response.type === "deleteFileResponse") {
|
|
131
|
+
resolve(response);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
/**
|
|
137
|
+
* @function deleteFolder
|
|
138
|
+
* @description Deletes a folder.
|
|
139
|
+
* @param {string} foldername - The name of the folder to delete.
|
|
140
|
+
* @param {string} folderpath - The path of the folder to delete.
|
|
141
|
+
* @returns {Promise<DeleteFolderResponse>} A promise that resolves with the server response.
|
|
142
|
+
*/
|
|
143
|
+
deleteFolder: (foldername: string, folderpath: string): Promise<DeleteFolderResponse> => {
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
146
|
+
"type":"fsEvent",
|
|
147
|
+
"action": "deleteFolder",
|
|
148
|
+
"message": {
|
|
149
|
+
foldername,
|
|
150
|
+
folderpath
|
|
151
|
+
},
|
|
152
|
+
}));
|
|
153
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
154
|
+
const response = JSON.parse(data);
|
|
155
|
+
if (response.type === "deleteFolderResponse") {
|
|
156
|
+
resolve(response);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* @function listFile
|
|
163
|
+
* @description Lists all files.
|
|
164
|
+
* @returns {Promise<FileListResponse>} A promise that resolves with the list of files.
|
|
165
|
+
*/
|
|
166
|
+
listFile: (folderPath:string,isRecursive=false) => {
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
169
|
+
"type": "fsEvent",
|
|
170
|
+
"action": "fileList",
|
|
171
|
+
message:{
|
|
172
|
+
folderPath,
|
|
173
|
+
isRecursive
|
|
174
|
+
}
|
|
175
|
+
}));
|
|
176
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
177
|
+
const response = JSON.parse(data);
|
|
178
|
+
if (response.type === "fileListResponse") {
|
|
179
|
+
resolve(response);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
/**
|
|
185
|
+
* @function listCodeDefinitionNames
|
|
186
|
+
* @description Lists all code definition names in a given path.
|
|
187
|
+
* @param {string} path - The path to search for code definitions.
|
|
188
|
+
* @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the list of code definition names.
|
|
189
|
+
*/
|
|
190
|
+
listCodeDefinitionNames: (path: string): Promise<{success: boolean, result: any}> => {
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
193
|
+
"type": "fsEvent",
|
|
194
|
+
"action": "listCodeDefinitionNames",
|
|
195
|
+
"message": {
|
|
196
|
+
path
|
|
197
|
+
}
|
|
198
|
+
}));
|
|
199
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
200
|
+
const response = JSON.parse(data);
|
|
201
|
+
if (response.type === "listCodeDefinitionNamesResponse") {
|
|
202
|
+
resolve(response);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @function searchFiles
|
|
210
|
+
* @description Searches files in a given path using a regex pattern.
|
|
211
|
+
* @param {string} path - The path to search within.
|
|
212
|
+
* @param {string} regex - The regex pattern to search for.
|
|
213
|
+
* @param {string} filePattern - The file pattern to match files.
|
|
214
|
+
* @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the search results.
|
|
215
|
+
*/
|
|
216
|
+
searchFiles: (path: string, regex: string, filePattern: string): Promise<{success: boolean, result: any}> => {
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
219
|
+
"type": "fsEvent",
|
|
220
|
+
"action": "searchFiles",
|
|
221
|
+
"message": {
|
|
222
|
+
path,
|
|
223
|
+
regex,
|
|
224
|
+
filePattern
|
|
225
|
+
}
|
|
226
|
+
}));
|
|
227
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
228
|
+
const response = JSON.parse(data);
|
|
229
|
+
if (response.type === "searchFilesResponse") {
|
|
230
|
+
resolve(response);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
/**
|
|
236
|
+
* @function writeToFile
|
|
237
|
+
* @description Writes content to a file.
|
|
238
|
+
* @param {string} relPath - The relative path of the file to write to.
|
|
239
|
+
* @param {string} newContent - The new content to write into the file.
|
|
240
|
+
* @returns {Promise<{success: boolean, result: any}>} A promise that resolves with the write operation result.
|
|
241
|
+
*/
|
|
242
|
+
writeToFile: (relPath:string, newContent:string) => {
|
|
243
|
+
return new Promise((resolve, reject) => {
|
|
244
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
245
|
+
"type": "fsEvent",
|
|
246
|
+
"action": "writeToFile",
|
|
247
|
+
"message": {
|
|
248
|
+
relPath,
|
|
249
|
+
newContent
|
|
250
|
+
}
|
|
251
|
+
}));
|
|
252
|
+
cbws.getWebsocket.on('message', (data:string) => {
|
|
253
|
+
const response = JSON.parse(data);
|
|
254
|
+
if (response.type === "writeToFileResponse") {
|
|
255
|
+
resolve(response);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
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,61 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
|
|
3
|
+
export enum logType {
|
|
4
|
+
info = "info",
|
|
5
|
+
error = "error",
|
|
6
|
+
warning = "warning"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export const chatSummary = {
|
|
11
|
+
|
|
12
|
+
summarizeAll: (): Promise<{
|
|
13
|
+
role: string;
|
|
14
|
+
content: string;
|
|
15
|
+
}[]> => {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
18
|
+
"type": "chatSummaryEvent",
|
|
19
|
+
"action": "summarizeAll",
|
|
20
|
+
|
|
21
|
+
}));
|
|
22
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
23
|
+
const response = JSON.parse(data);
|
|
24
|
+
if (response.type === "getSummarizeAllResponse") {
|
|
25
|
+
resolve(response.payload); // Resolve the Promise with the response data
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
},
|
|
32
|
+
summarize: (messages: {
|
|
33
|
+
role: string;
|
|
34
|
+
content: string;
|
|
35
|
+
}[], depth: number): Promise<{
|
|
36
|
+
role: string;
|
|
37
|
+
content: string;
|
|
38
|
+
}[]> => {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
41
|
+
"type": "chatSummaryEvent",
|
|
42
|
+
"action": "summarize",
|
|
43
|
+
messages,
|
|
44
|
+
depth
|
|
45
|
+
}));
|
|
46
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
47
|
+
const response = JSON.parse(data);
|
|
48
|
+
if (response.type === "getSummarizeResponse") {
|
|
49
|
+
resolve(response.payload); // Resolve the Promise with the response data
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export default chatSummary;
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import cbws from './websocket';
|
|
2
|
+
import {LLMResponse } from '@codebolt/types';
|
|
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<LLMResponse>} A promise that resolves with the LLM's response.
|
|
16
|
+
*/
|
|
17
|
+
inference: async (message: string, llmrole: string): Promise<LLMResponse> => {
|
|
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;
|