@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.
Files changed (83) hide show
  1. package/.github/workflows/publish-to-npm.yml +1 -1
  2. package/docs/modules/_internal_.EventEmitter.html +6 -0
  3. package/docs/modules/_internal_.WebSocket.html +21 -0
  4. package/docs/modules/_internal_._node_stream_consumers_.html +6 -0
  5. package/docs/modules/_internal_._node_stream_promises_.html +3 -0
  6. package/docs/modules/_internal_.html +228 -0
  7. package/docs/modules/_internal_.internal.finished.html +2 -0
  8. package/docs/modules/_internal_.internal.html +36 -0
  9. package/docs/modules/_internal_.internal.pipeline.html +2 -0
  10. package/index.d.ts +254 -0
  11. package/modules/browser.d.ts +108 -0
  12. package/modules/browser.js +331 -0
  13. package/modules/chat.d.ts +64 -0
  14. package/modules/chat.js +190 -0
  15. package/modules/codeparsers.d.ts +23 -0
  16. package/modules/codeparsers.js +30 -0
  17. package/modules/codeutils.d.ts +37 -0
  18. package/modules/codeutils.js +166 -0
  19. package/modules/crawler.d.ts +45 -0
  20. package/modules/crawler.js +123 -0
  21. package/modules/dbmemory.d.ts +20 -0
  22. package/modules/dbmemory.js +54 -0
  23. package/modules/debug.d.ts +23 -0
  24. package/modules/debug.js +64 -0
  25. package/modules/docutils.d.ts +12 -0
  26. package/modules/docutils.js +19 -0
  27. package/modules/fs.d.ts +94 -0
  28. package/modules/fs.js +264 -0
  29. package/modules/git.d.ts +76 -0
  30. package/modules/git.js +240 -0
  31. package/modules/history.d.ts +19 -0
  32. package/modules/history.js +46 -0
  33. package/modules/knowledge.d.ts +2 -0
  34. package/modules/knowledge.js +6 -0
  35. package/modules/llm.d.ts +18 -0
  36. package/modules/llm.js +39 -0
  37. package/modules/mcp.d.ts +8 -0
  38. package/modules/mcp.js +139 -0
  39. package/modules/outputparsers.d.ts +24 -0
  40. package/modules/outputparsers.js +32 -0
  41. package/modules/project.d.ts +21 -0
  42. package/modules/project.js +72 -0
  43. package/modules/rag.d.ts +22 -0
  44. package/modules/rag.js +30 -0
  45. package/modules/search.d.ts +23 -0
  46. package/modules/search.js +37 -0
  47. package/modules/state.d.ts +21 -0
  48. package/modules/state.js +68 -0
  49. package/modules/task.d.ts +23 -0
  50. package/modules/task.js +75 -0
  51. package/modules/terminal.d.ts +46 -0
  52. package/modules/terminal.js +108 -0
  53. package/modules/tokenizer.d.ts +19 -0
  54. package/modules/tokenizer.js +56 -0
  55. package/modules/vectordb.d.ts +33 -0
  56. package/modules/vectordb.js +103 -0
  57. package/modules/websocket.d.ts +27 -0
  58. package/modules/websocket.js +88 -0
  59. package/package.json +3 -5
  60. package/src/modules/browser.ts +352 -0
  61. package/src/modules/chat.ts +193 -0
  62. package/src/modules/codeparsers.ts +30 -0
  63. package/src/modules/codeutils.ts +181 -0
  64. package/src/modules/crawler.ts +121 -0
  65. package/src/modules/dbmemory.ts +52 -0
  66. package/src/modules/debug.ts +68 -0
  67. package/src/modules/docutils.ts +18 -0
  68. package/src/modules/fs.ts +263 -0
  69. package/src/modules/git.ts +237 -0
  70. package/src/modules/history.ts +61 -0
  71. package/src/modules/knowledge.ts +5 -0
  72. package/src/modules/llm.ts +36 -0
  73. package/src/modules/mcp.ts +127 -0
  74. package/src/modules/outputparsers.ts +30 -0
  75. package/src/modules/project.ts +68 -0
  76. package/src/modules/rag.ts +28 -0
  77. package/src/modules/search.ts +35 -0
  78. package/src/modules/state.ts +69 -0
  79. package/src/modules/task.ts +73 -0
  80. package/src/modules/terminal.ts +114 -0
  81. package/src/modules/tokenizer.ts +56 -0
  82. package/src/modules/vectordb.ts +102 -0
  83. package/src/modules/websocket.ts +89 -0
@@ -0,0 +1,102 @@
1
+ import cbws from './websocket';
2
+ import { AddVectorItemResponse,GetVectorResponse,QueryVectorItemResponse } from '@codebolt/types';
3
+ const VectorDB = {
4
+ /**
5
+ * Retrieves a vector from the vector database based on the provided key.
6
+ *
7
+ * @param {string} key - The key of the vector to retrieve.
8
+ * @returns {Promise<GetVectorResponse>} A promise that resolves with the retrieved vector.
9
+ */
10
+ getVector: async (key: string): Promise<GetVectorResponse> => {
11
+ return new Promise((resolve, reject) => {
12
+ cbws.getWebsocket.send(JSON.stringify({
13
+ "type":"vectordbEvent",
14
+ "action": "getVector",
15
+ "message": {
16
+ item: key
17
+ },
18
+ }));
19
+ cbws.getWebsocket.on('message', (data: string) => {
20
+ const response = JSON.parse(data);
21
+ if (response.type === "getVectorResponse") {
22
+ resolve(response);
23
+ }
24
+ });
25
+ });
26
+ },
27
+
28
+ /**
29
+ * Adds a new vector item to the vector database.
30
+ *
31
+
32
+ * @param {any} item - The item to add to the vector.
33
+ * @returns {Promise<AddVectorItemResponse>} A promise that resolves when the item is successfully added.
34
+ */
35
+ addVectorItem: async ( item: any): Promise<AddVectorItemResponse> => {
36
+ return new Promise((resolve, reject) => {
37
+ cbws.getWebsocket.send(JSON.stringify({
38
+ "type":"vectordbEvent",
39
+ "action": "addVectorItem",
40
+ "message": {
41
+ item: item
42
+ },
43
+ }));
44
+ cbws.getWebsocket.on('message', (data: string) => {
45
+ const response = JSON.parse(data);
46
+ if (response.type === "addVectorItemResponse") {
47
+ resolve(response);
48
+ }
49
+ });
50
+ });
51
+ },
52
+
53
+ /**
54
+ * Queries a vector item from the vector database based on the provided key.
55
+ *
56
+ * @param {string} key - The key of the vector to query the item from.
57
+ * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
58
+ */
59
+ queryVectorItem: async (key: string): Promise<QueryVectorItemResponse> => {
60
+ return new Promise((resolve, reject) => {
61
+ cbws.getWebsocket.send(JSON.stringify({
62
+ "type":"vectordbEvent",
63
+ "action": "queryVectorItem",
64
+ "message": {
65
+ item: key
66
+ },
67
+ }));
68
+ cbws.getWebsocket.on('message', (data: string) => {
69
+ const response = JSON.parse(data);
70
+ if (response.type === "qeryVectorItemResponse") {
71
+ resolve(response);
72
+ }
73
+ });
74
+ });
75
+ },
76
+ /**
77
+ * Queries a vector item from the vector database based on the provided key.
78
+ *
79
+ * @param {string} key - The key of the vector to query the item from.
80
+ * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
81
+ */
82
+ queryVectorItems: async (items: [],dbPath:string): Promise<QueryVectorItemResponse> => {
83
+ return new Promise((resolve, reject) => {
84
+ cbws.getWebsocket.send(JSON.stringify({
85
+ "type":"vectordbEvent",
86
+ "action": "queryVectorItems",
87
+ "message": {
88
+ items,
89
+ dbPath
90
+ },
91
+ }));
92
+ cbws.getWebsocket.on('message', (data: string) => {
93
+ const response = JSON.parse(data);
94
+ if (response.type === "qeryVectorItemsResponse") {
95
+ resolve(response);
96
+ }
97
+ });
98
+ });
99
+ },
100
+ };
101
+
102
+ export default VectorDB;
@@ -0,0 +1,89 @@
1
+ import WebSocket from 'ws';
2
+ import fs from 'fs';
3
+ import yaml from 'js-yaml';
4
+
5
+ /**
6
+ * Class representing a WebSocket connection.
7
+ */
8
+ class cbws {
9
+ websocket: WebSocket;
10
+
11
+ /**
12
+ * Constructs a new cbws instance and initializes the WebSocket connection.
13
+ */
14
+ constructor() {
15
+ const uniqueConnectionId = this.getUniqueConnectionId();
16
+ const initialMessage = this.getInitialMessage();
17
+ console.log(uniqueConnectionId)
18
+ this.websocket = new WebSocket(`ws://localhost:${process.env.SOCKET_PORT}/codebolt?id=${uniqueConnectionId}${process.env.Is_Dev ? '&dev=true' : ''}`);
19
+ this.initializeWebSocket(initialMessage).catch(error => {
20
+ console.error("WebSocket connection failed:", error);
21
+ });
22
+ }
23
+ private getUniqueConnectionId(): string {
24
+ try {
25
+ let fileContents = fs.readFileSync('./codeboltagent.yaml', 'utf8');
26
+ let data: any = yaml.load(fileContents);
27
+ return data.unique_connectionid;
28
+ } catch (e) {
29
+ console.error('Unable to locate codeboltagent.yaml file.');
30
+ return '';
31
+ }
32
+ }
33
+
34
+ private getInitialMessage(): string {
35
+ try {
36
+ let fileContents = fs.readFileSync('./codeboltagent.yaml', 'utf8');
37
+ let data: any = yaml.load(fileContents);
38
+ return data.initial_message;
39
+ } catch (e) {
40
+ console.error('Unable to locate codeboltagent.yaml file.');
41
+ return '';
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Initializes the WebSocket by setting up event listeners and returning a promise that resolves
47
+ * when the WebSocket connection is successfully opened.
48
+ * @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
49
+ */
50
+ private async initializeWebSocket(initialMessage: string): Promise<WebSocket> {
51
+ return new Promise((resolve, reject) => {
52
+ this.websocket.on('error', (error: Error) => {
53
+ console.log('WebSocket error:', error);
54
+ reject(error);
55
+ });
56
+
57
+ this.websocket.on('open', () => {
58
+ console.log('WebSocket connected');
59
+ // if (this.websocket) {
60
+ // this.websocket.send(JSON.stringify({
61
+ // "type": "sendMessage",
62
+ // "message": initialMessage
63
+ // }));
64
+ // resolve(this.websocket);
65
+ // }
66
+ });
67
+
68
+ this.websocket.on('message', (data: WebSocket.Data) => {
69
+ // Handle incoming WebSocket messages here.
70
+ // console.log('WebSocket message received:', data);
71
+ });
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Getter for the WebSocket instance. Throws an error if the WebSocket is not open.
77
+ * @returns {WebSocket} The WebSocket instance.
78
+ * @throws {Error} If the WebSocket is not open.
79
+ */
80
+ get getWebsocket(): WebSocket {
81
+ if (!this.websocket.OPEN) {
82
+ throw new Error('WebSocket is not open');
83
+ } else {
84
+ return this.websocket;
85
+ }
86
+ }
87
+ }
88
+
89
+ export default new cbws();