@codebolt/codeboltjs 1.1.22 → 1.1.24

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/index.d.ts CHANGED
@@ -1,14 +1,20 @@
1
- import WebSocket from 'ws';
1
+ /// <reference types="node" />
2
+ import WebSocket, { EventEmitter } from 'ws';
2
3
  /**
3
4
  * @class Codebolt
4
5
  * @description This class provides a unified interface to interact with various modules.
5
6
  */
6
- declare class Codebolt {
7
+ declare class Codebolt extends EventEmitter {
7
8
  /**
8
9
  * @constructor
9
10
  * @description Initializes the websocket connection.
10
11
  */
11
12
  constructor();
13
+ /**
14
+ * @method setupMessageListener
15
+ * @description Sets up a listener for incoming WebSocket messages.
16
+ */
17
+ userMessageListener(): void;
12
18
  /**
13
19
  * @method waitForConnection
14
20
  * @description Waits for the WebSocket connection to open.
@@ -32,6 +38,7 @@ declare class Codebolt {
32
38
  updateFile: (filename: string, filePath: string, newContent: string) => Promise<any>;
33
39
  deleteFile: (filename: string, filePath: string) => Promise<any>;
34
40
  deleteFolder: (foldername: string, folderpath: string) => Promise<any>;
41
+ listFile: (folderPath?: string | undefined) => void;
35
42
  };
36
43
  git: {
37
44
  init: (path: string) => Promise<any>;
@@ -51,7 +58,10 @@ declare class Codebolt {
51
58
  };
52
59
  browser: {
53
60
  newPage: () => void;
54
- getUrl: () => Promise<unknown>;
61
+ getUrl: () => Promise<unknown>; /**
62
+ * @class Codebolt
63
+ * @description This class provides a unified interface to interact with various modules.
64
+ */
55
65
  goToPage: (url: string) => Promise<unknown>;
56
66
  screenshot: () => void;
57
67
  getHTML: () => Promise<unknown>;
@@ -86,6 +96,7 @@ declare class Codebolt {
86
96
  };
87
97
  codeutils: {
88
98
  getCodeTree: (fileName: any, source: any, filePath: any) => Promise<any>;
99
+ getAllFilesAsMarkDown: () => Promise<unknown>;
89
100
  };
90
101
  docutils: {
91
102
  pdf_to_text: (pdf_path: any) => Promise<string>;
@@ -127,10 +138,6 @@ declare class Codebolt {
127
138
  };
128
139
  dbmemory: {
129
140
  addKnowledge: (key: string, value: any) => Promise<any>;
130
- /**
131
- * @constructor
132
- * @description Initializes the websocket connection.
133
- */
134
141
  getKnowledge: (key: string) => Promise<any>;
135
142
  };
136
143
  cbstate: {
@@ -143,16 +150,15 @@ declare class Codebolt {
143
150
  };
144
151
  vectordb: {
145
152
  getVector: (key: string) => Promise<any>;
146
- /**
147
- * @class Codebolt
148
- * @description This class provides a unified interface to interact with various modules.
149
- */
150
153
  addVectorItem: (item: any) => Promise<any>;
151
154
  queryVectorItem: (key: string) => Promise<any>;
152
155
  };
153
156
  debug: {
154
157
  debug(log: string, type: import("./modules/debug").logType): Promise<unknown>;
155
158
  };
159
+ tokenizer: {
160
+ addToken: (key: string) => Promise<any>;
161
+ };
156
162
  }
157
163
  declare const _default: Codebolt;
158
164
  export default _default;
package/index.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -24,17 +47,19 @@ const state_1 = __importDefault(require("./modules/state"));
24
47
  const task_1 = __importDefault(require("./modules/task"));
25
48
  const vectordb_1 = __importDefault(require("./modules/vectordb"));
26
49
  const debug_1 = __importDefault(require("./modules/debug"));
27
- const ws_1 = __importDefault(require("ws"));
50
+ const tokenizer_1 = __importDefault(require("./modules/tokenizer"));
51
+ const ws_1 = __importStar(require("ws"));
28
52
  /**
29
53
  * @class Codebolt
30
54
  * @description This class provides a unified interface to interact with various modules.
31
55
  */
32
- class Codebolt {
56
+ class Codebolt extends ws_1.EventEmitter {
33
57
  /**
34
58
  * @constructor
35
59
  * @description Initializes the websocket connection.
36
60
  */
37
61
  constructor() {
62
+ super();
38
63
  this.websocket = null;
39
64
  this.fs = fs_1.default;
40
65
  this.git = git_1.default;
@@ -56,7 +81,23 @@ class Codebolt {
56
81
  this.taskplaner = task_1.default;
57
82
  this.vectordb = vectordb_1.default;
58
83
  this.debug = debug_1.default;
84
+ this.tokenizer = tokenizer_1.default;
59
85
  this.websocket = websocket_1.default.getWebsocket;
86
+ this.userMessageListener(); // Call setupMessageListener() to subscribe to WebSocket messages
87
+ }
88
+ /**
89
+ * @method setupMessageListener
90
+ * @description Sets up a listener for incoming WebSocket messages.
91
+ */
92
+ userMessageListener() {
93
+ if (!this.websocket)
94
+ return;
95
+ this.websocket.on('message', (data) => {
96
+ const response = JSON.parse(data);
97
+ if (response.type === "messageResponse") {
98
+ this.emit(response.message);
99
+ }
100
+ });
60
101
  }
61
102
  /**
62
103
  * @method waitForConnection
@@ -10,5 +10,6 @@ declare const cbcodeutils: {
10
10
  * @returns {Promise<any>} A promise that resolves with the code tree.
11
11
  */
12
12
  getCodeTree: (fileName: any, source: any, filePath: any) => Promise<any>;
13
+ getAllFilesAsMarkDown: () => Promise<unknown>;
13
14
  };
14
15
  export default cbcodeutils;
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const websocket_1 = __importDefault(require("./websocket"));
3
7
  /**
4
8
  * A utility module for working with code.
5
9
  */
@@ -15,6 +19,20 @@ const cbcodeutils = {
15
19
  return new Promise((resolve, reject) => {
16
20
  // Implementation would go here
17
21
  });
22
+ },
23
+ getAllFilesAsMarkDown: () => {
24
+ return new Promise((resolve, reject) => {
25
+ websocket_1.default.getWebsocket.send(JSON.stringify({
26
+ "type": "codeEvent",
27
+ "action": "getAllFilesMarkdown"
28
+ }));
29
+ websocket_1.default.getWebsocket.on('message', (data) => {
30
+ const response = JSON.parse(data);
31
+ if (response.type === "getAllFilesMarkdownResponse") {
32
+ resolve(response.markdown); // Resolve the Promise with the response data
33
+ }
34
+ });
35
+ });
18
36
  }
19
37
  };
20
38
  exports.default = cbcodeutils;
package/modules/fs.d.ts CHANGED
@@ -53,5 +53,6 @@ declare const cbfs: {
53
53
  * @returns {Promise<any>} A promise that resolves with the server response.
54
54
  */
55
55
  deleteFolder: (foldername: string, folderpath: string) => Promise<any>;
56
+ listFile: (folderPath?: string) => void;
56
57
  };
57
58
  export default cbfs;
package/modules/fs.js CHANGED
@@ -162,6 +162,8 @@ const cbfs = {
162
162
  }
163
163
  });
164
164
  });
165
- }
165
+ },
166
+ listFile: (folderPath) => {
167
+ },
166
168
  };
167
169
  exports.default = cbfs;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Tokenizer module for handling token-related operations.
3
+ */
4
+ declare const tokenizer: {
5
+ /**
6
+ * Adds a token asynchronously.
7
+ * @param {string} key - The key of the token to add.
8
+ * @returns {Promise<any>} A promise that resolves with the response.
9
+ */
10
+ addToken: (key: string) => Promise<any>;
11
+ };
12
+ export default tokenizer;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const websocket_1 = __importDefault(require("./websocket"));
7
+ /**
8
+ * Tokenizer module for handling token-related operations.
9
+ */
10
+ const tokenizer = {
11
+ /**
12
+ * Adds a token asynchronously.
13
+ * @param {string} key - The key of the token to add.
14
+ * @returns {Promise<any>} A promise that resolves with the response.
15
+ */
16
+ addToken: async (key) => {
17
+ return new Promise((resolve, reject) => {
18
+ websocket_1.default.getWebsocket.send(JSON.stringify({
19
+ "type": "tokenizerEvent",
20
+ "action": "addToken",
21
+ "message": {
22
+ item: key
23
+ },
24
+ }));
25
+ websocket_1.default.getWebsocket.on('message', (data) => {
26
+ const response = JSON.parse(data);
27
+ if (response.type === "addTokenResponse") {
28
+ resolve(response);
29
+ }
30
+ });
31
+ });
32
+ }
33
+ };
34
+ exports.default = tokenizer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "1.1.22",
3
+ "version": "1.1.24",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
package/src/index.ts CHANGED
@@ -19,47 +19,63 @@ import cbstate from './modules/state';
19
19
  import task from './modules/task';
20
20
  import vectorDB from './modules/vectordb';
21
21
  import debug from './modules/debug'
22
- import WebSocket from 'ws';
22
+ import tokenizer from './modules/tokenizer'
23
+ import WebSocket, { EventEmitter } from 'ws';
23
24
 
24
25
 
25
26
  /**
26
27
  * @class Codebolt
27
28
  * @description This class provides a unified interface to interact with various modules.
28
29
  */
29
- class Codebolt {
30
+ class Codebolt extends EventEmitter { // Extend EventEmitter
30
31
 
31
32
  /**
32
33
  * @constructor
33
34
  * @description Initializes the websocket connection.
34
35
  */
35
- constructor(){
36
+ constructor() {
37
+ super()
36
38
  this.websocket = cbws.getWebsocket;
39
+ this.userMessageListener(); // Call setupMessageListener() to subscribe to WebSocket messages
40
+ }
41
+ /**
42
+ * @method setupMessageListener
43
+ * @description Sets up a listener for incoming WebSocket messages.
44
+ */
45
+ userMessageListener() {
46
+ if (!this.websocket) return;
47
+ this.websocket.on('message', (data: string) => {
48
+ const response = JSON.parse(data);
49
+ if (response.type === "messageResponse") {
50
+ this.emit(response.message)
51
+ }
52
+ });
37
53
  }
38
-
39
54
  /**
40
55
  * @method waitForConnection
41
56
  * @description Waits for the WebSocket connection to open.
42
57
  * @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
43
58
  */
44
- async waitForConnection() {
59
+ async waitForConnection() {
45
60
  return new Promise<void>((resolve, reject) => {
46
61
  if (!this.websocket) {
47
62
  reject(new Error('WebSocket is not initialized'));
48
63
  return;
49
64
  }
50
-
65
+
51
66
  if (this.websocket.readyState === WebSocket.OPEN) {
52
67
  resolve();
53
68
  return;
54
69
  }
55
-
70
+
56
71
  this.websocket.addEventListener('open', () => {
57
72
  resolve();
58
73
  });
59
-
74
+
60
75
  this.websocket.addEventListener('error', (error) => {
61
76
  reject(error);
62
77
  });
78
+
63
79
  });
64
80
  }
65
81
 
@@ -71,12 +87,12 @@ class Codebolt {
71
87
  * @param {string} previous_command - The previous command executed.
72
88
  * @param {string} browser_content - The content of the browser.
73
89
  */
74
- start_browser(objective:string, url:string, previous_command:string, browser_content:string) {
90
+ start_browser(objective: string, url: string, previous_command: string, browser_content: string) {
75
91
  cbbrowser.newPage();
76
92
  }
77
93
  websocket: WebSocket | null = null;
78
94
  fs = cbfs;
79
- git=git;
95
+ git = git;
80
96
  llm = cbllm;
81
97
  browser = cbbrowser;
82
98
  chat = cbchat;
@@ -91,10 +107,11 @@ class Codebolt {
91
107
  outputparsers = cboutputparsers;
92
108
  project = cbproject;
93
109
  dbmemory = dbmemory;
94
- cbstate=cbstate;
95
- taskplaner=task;
96
- vectordb=vectorDB;
97
- debug=debug;
110
+ cbstate = cbstate;
111
+ taskplaner = task;
112
+ vectordb = vectorDB;
113
+ debug = debug;
114
+ tokenizer = tokenizer;
98
115
  }
99
116
 
100
117
  export default new Codebolt();
@@ -1,3 +1,5 @@
1
+ import cbws from './websocket';
2
+
1
3
  /**
2
4
  * A utility module for working with code.
3
5
  */
@@ -13,6 +15,20 @@ const cbcodeutils = {
13
15
  return new Promise((resolve, reject) => {
14
16
  // Implementation would go here
15
17
  });
18
+ },
19
+ getAllFilesAsMarkDown:()=>{
20
+ return new Promise((resolve, reject) => {
21
+ cbws.getWebsocket.send(JSON.stringify({
22
+ "type": "codeEvent",
23
+ "action":"getAllFilesMarkdown"
24
+ }));
25
+ cbws.getWebsocket.on('message', (data: string) => {
26
+ const response = JSON.parse(data);
27
+ if (response.type === "getAllFilesMarkdownResponse") {
28
+ resolve(response.markdown); // Resolve the Promise with the response data
29
+ }
30
+ });
31
+ });
16
32
  }
17
33
  };
18
34
 
package/src/modules/fs.ts CHANGED
@@ -158,7 +158,11 @@ const cbfs = {
158
158
  }
159
159
  });
160
160
  });
161
- }
161
+ },
162
+ listFile:(folderPath?:string)=>{
163
+
164
+ },
165
+
162
166
  };
163
167
 
164
168
  export default cbfs;
@@ -0,0 +1,32 @@
1
+ import cbws from './websocket';
2
+
3
+ /**
4
+ * Tokenizer module for handling token-related operations.
5
+ */
6
+ const tokenizer = {
7
+
8
+ /**
9
+ * Adds a token asynchronously.
10
+ * @param {string} key - The key of the token to add.
11
+ * @returns {Promise<any>} A promise that resolves with the response.
12
+ */
13
+ addToken: async (key: string): Promise<any> => {
14
+ return new Promise((resolve, reject) => {
15
+ cbws.getWebsocket.send(JSON.stringify({
16
+ "type":"tokenizerEvent",
17
+ "action": "addToken",
18
+ "message": {
19
+ item: key
20
+ },
21
+ }));
22
+ cbws.getWebsocket.on('message', (data: string) => {
23
+ const response = JSON.parse(data);
24
+ if (response.type === "addTokenResponse") {
25
+ resolve(response);
26
+ }
27
+ });
28
+ });
29
+ }
30
+ }
31
+
32
+ export default tokenizer