@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,127 @@
1
+ import cbws from './websocket';
2
+ const codeboltMCP = {
3
+
4
+ executeTool: ( toolName: string, params: any,mcpServer?: string,): Promise<any> => {
5
+ return new Promise((resolve, reject) => {
6
+ cbws.getWebsocket.send(JSON.stringify({
7
+ "type": "mcpEvent",
8
+ "action": "executeTool",
9
+ "toolName": toolName,
10
+ "params": params
11
+ }));
12
+ cbws.getWebsocket.on('message', (data: string) => {
13
+ try {
14
+ const response = JSON.parse(data);
15
+ if (response.type === "executeToolResponse") {
16
+ resolve(response.data);
17
+ } else {
18
+ reject(new Error("Unexpected response type"));
19
+ }
20
+ } catch (error) {
21
+ reject(new Error("Failed to parse response"));
22
+ }
23
+ });
24
+ cbws.getWebsocket.on('error', (error: Error) => {
25
+ reject(error);
26
+ });
27
+ });
28
+ },
29
+ getMcpTools: (tools: string[]): Promise<any> => {
30
+ return new Promise((resolve, reject) => {
31
+ cbws.getWebsocket.send(JSON.stringify({
32
+ "type": "mcpEvent",
33
+ "action": "getMcpTools",
34
+ "tools": tools
35
+ }));
36
+ cbws.getWebsocket.on('message', (data: string) => {
37
+ try {
38
+ const response = JSON.parse(data);
39
+ if (response.type === "getMcpToolsResponse") {
40
+ resolve(response.data);
41
+ } else {
42
+ reject(new Error("Unexpected response type"));
43
+ }
44
+ } catch (error) {
45
+ reject(new Error("Failed to parse response"));
46
+ }
47
+ });
48
+ cbws.getWebsocket.on('error', (error: Error) => {
49
+ reject(error);
50
+ });
51
+ });
52
+
53
+ },
54
+ getAllMCPTools: (mpcName: string): Promise<any> => {
55
+ return new Promise((resolve, reject) => {
56
+ cbws.getWebsocket.send(JSON.stringify({
57
+ "type": "mcpEvent",
58
+ "action": "getAllMCPTools",
59
+ "mpcName": mpcName
60
+ }));
61
+ cbws.getWebsocket.on('message', (data: string) => {
62
+ try {
63
+ const response = JSON.parse(data);
64
+ if (response.type === "getAllMCPToolsResponse") {
65
+ resolve(response.data);
66
+ } else {
67
+ reject(new Error("Unexpected response type"));
68
+ }
69
+ } catch (error) {
70
+ reject(new Error("Failed to parse response"));
71
+ }
72
+ });
73
+ cbws.getWebsocket.on('error', (error: Error) => {
74
+ reject(error);
75
+ });
76
+ });
77
+ },
78
+ getMCPTool: (name: string): Promise<any> => {
79
+ return new Promise((resolve, reject) => {
80
+ cbws.getWebsocket.send(JSON.stringify({
81
+ "type": "mcpEvent",
82
+ "action": "getMCPTool",
83
+ "mcpName": name
84
+ }));
85
+ cbws.getWebsocket.on('message', (data: string) => {
86
+ try {
87
+ const response = JSON.parse(data);
88
+ if (response.type === "getMCPToolResponse") {
89
+ resolve(response.data);
90
+ } else {
91
+ reject(new Error("Unexpected response type"));
92
+ }
93
+ } catch (error) {
94
+ reject(new Error("Failed to parse response"));
95
+ }
96
+ });
97
+ cbws.getWebsocket.on('error', (error: Error) => {
98
+ reject(error);
99
+ });
100
+ });
101
+ },
102
+ getEnabledMCPS: (): Promise<any> => {
103
+ return new Promise((resolve, reject) => {
104
+ cbws.getWebsocket.send(JSON.stringify({
105
+ "type": "mcpEvent",
106
+ "action": "getEnabledMCPS"
107
+ }));
108
+ cbws.getWebsocket.on('message', (data: string) => {
109
+ try {
110
+ const response = JSON.parse(data);
111
+ if (response.type === "getEnabledMCPSResponse") {
112
+ resolve(response.data);
113
+ } else {
114
+ reject(new Error("Unexpected response type"));
115
+ }
116
+ } catch (error) {
117
+ reject(new Error("Failed to parse response"));
118
+ }
119
+ });
120
+ cbws.getWebsocket.on('error', (error: Error) => {
121
+ reject(error);
122
+ });
123
+ });
124
+ },
125
+ }
126
+
127
+ export default codeboltMCP;
@@ -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,68 @@
1
+ import cbws from './websocket';
2
+ import { GetProjectPathResponse } from '@codebolt/types';
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<GetProjectPathResponse>} A promise that resolves with the project path response.
18
+ */
19
+ getProjectPath: (): Promise<GetProjectPathResponse> => {
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
+ getRepoMap: (message: any): Promise<GetProjectPathResponse> => {
34
+ return new Promise((resolve, reject) => {
35
+ cbws.getWebsocket.send(JSON.stringify({
36
+ "type": "settingEvent",
37
+ "action": "getRepoMap",
38
+ message
39
+ }));
40
+ cbws.getWebsocket.on('message', (data: string) => {
41
+ const response = JSON.parse(data);
42
+ if (response.type === "getRepoMapResponse") {
43
+ resolve(response);
44
+ }
45
+ });
46
+ });
47
+ },
48
+ runProject: () => {
49
+ cbws.getWebsocket.send(JSON.stringify({
50
+ "type": "runProject"
51
+ }));
52
+ },
53
+ getEditorFileStatus:()=>{
54
+ return new Promise((resolve, reject) => {
55
+ cbws.getWebsocket.send(JSON.stringify({
56
+ "type": "settingEvent",
57
+ "action": "getEditorFileStatus",
58
+ }));
59
+ cbws.getWebsocket.on('message', (data: string) => {
60
+ const response = JSON.parse(data);
61
+ if (response.type === "getEditorFileStatusResponse") {
62
+ resolve(response);
63
+ }
64
+ });
65
+ });
66
+ }
67
+ };
68
+ export default cbproject
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A module for managing files within the CodeBolt File System.
3
+ */
4
+ const cbrag = {
5
+ /**
6
+ * Initializes the CodeBolt File System Module.
7
+ */
8
+ init: () => {
9
+ console.log("Initializing CodeBolt File System Module");
10
+ },
11
+ /**
12
+ * Adds a file to the CodeBolt File System.
13
+ * @param {string} filename - The name of the file to add.
14
+ * @param {string} file_path - The path where the file should be added.
15
+ */
16
+ add_file: (filename: string, file_path: string) => {
17
+ // Implementation for adding a file will be added here
18
+ },
19
+ /**
20
+ * Retrieves related knowledge for a given query and filename.
21
+ * @param {string} query - The query to retrieve related knowledge for.
22
+ * @param {string} filename - The name of the file associated with the query.
23
+ */
24
+ retrieve_related_knowledge: (query: string, filename: string) => {
25
+ // Implementation for retrieving related knowledge will be added here
26
+ },
27
+ };
28
+ export default cbrag;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A module for handling search operations.
3
+ */
4
+ const cbsearch = {
5
+ /**
6
+ * Initializes the search module with the specified search engine.
7
+ * @param {string} [engine="bing"] - The search engine to use for initializing the module.
8
+ */
9
+ init: (engine: string = "bing"): void => {
10
+ console.log("Initializing Search Module with engine: " + engine);
11
+ },
12
+ /**
13
+ * Performs a search operation for the given query.
14
+ * @param {string} query - The search query.
15
+ * @returns {Promise<string>} A promise that resolves with the search results.
16
+ */
17
+ search: async (query: string): Promise<string> => {
18
+ console.log("Searching for " + query);
19
+ return new Promise((resolve, reject) => {
20
+ resolve("Search Results for " + query);
21
+ });
22
+ },
23
+ /**
24
+ * Retrieves the first link from the search results for the given query.
25
+ * @param {string} query - The search query.
26
+ * @returns {Promise<string>} A promise that resolves with the first link of the search results.
27
+ */
28
+ get_first_link: async (query: string): Promise<string> => {
29
+ console.log("Getting first link for " + query);
30
+ return new Promise((resolve, reject) => {
31
+ resolve("First Link for " + query);
32
+ });
33
+ }
34
+ };
35
+ export default cbsearch;
@@ -0,0 +1,69 @@
1
+ import cbws from './websocket';
2
+ import {ApplicationState,AddToAgentStateResponse,GetAgentStateResponse } from '@codebolt/types';
3
+
4
+ const cbstate = {
5
+ /**
6
+ * Retrieves the current application state from the server via WebSocket.
7
+ * @returns {Promise<ApplicationState>} A promise that resolves with the application state.
8
+ */
9
+ getApplicationState: async (): Promise<ApplicationState> => {
10
+ return new Promise((resolve, reject) => {
11
+ cbws.getWebsocket.send(JSON.stringify({
12
+ "type": "getAppState",
13
+
14
+ }));
15
+ cbws.getWebsocket.on('message', (data: string) => {
16
+ const response = JSON.parse(data);
17
+ if (response.type === "getAppStateResponse") {
18
+ resolve(response); // Resolve the Promise with the response data
19
+ }
20
+ });
21
+ });
22
+ },
23
+ /**
24
+ * Adds a key-value pair to the agent's state on the server via WebSocket.
25
+ * @param {string} key - The key to add to the agent's state.
26
+ * @param {string} value - The value associated with the key.
27
+ * @returns {Promise<AddToAgentStateResponse>} A promise that resolves with the response to the addition request.
28
+ */
29
+ addToAgentState: async (key: string, value: string): Promise<AddToAgentStateResponse> => {
30
+ return new Promise((resolve, reject) => {
31
+ cbws.getWebsocket.send(JSON.stringify({
32
+ "type": "agentStateEvent",
33
+ "action":"addToAgentState",
34
+ payload:{
35
+ key,
36
+ value
37
+ }
38
+
39
+ }));
40
+ cbws.getWebsocket.on('message', (data: string) => {
41
+ const response = JSON.parse(data);
42
+ if (response.type === "addToAgentStateResponse") {
43
+ resolve(response); // Resolve the Promise with the response data
44
+ }
45
+ });
46
+ });
47
+ },
48
+ /**
49
+ * Retrieves the current state of the agent from the server via WebSocket.
50
+ * @returns {Promise<GetAgentStateResponse>} A promise that resolves with the agent's state.
51
+ */
52
+ getAgentState: async (): Promise<GetAgentStateResponse> => {
53
+ return new Promise((resolve, reject) => {
54
+ cbws.getWebsocket.send(JSON.stringify({
55
+ "type": "agentStateEvent",
56
+ "action":"getAgentState",
57
+
58
+ }));
59
+ cbws.getWebsocket.on('message', (data: string) => {
60
+ const response = JSON.parse(data);
61
+ if (response.type === "getAgentStateResponse") {
62
+ resolve(response); // Resolve the Promise with the response data
63
+ }
64
+ });
65
+ });
66
+ }
67
+ };
68
+
69
+ export default cbstate;
@@ -0,0 +1,73 @@
1
+ import cbws from './websocket';
2
+ // import {AddTaskResponse,GetTasksResponse,UpdateTasksResponse } from '@codebolt/types';
3
+ /**
4
+ * Manages task operations via WebSocket communication.
5
+ */
6
+ const taskplaner = {
7
+ /**
8
+ * Adds a task using a WebSocket message.
9
+ * @param {string} task - The task to be added.
10
+ * @returns {Promise<AddTaskResponse>} A promise that resolves with the response from the add task event.
11
+ */
12
+ addTask: async (task: string): Promise<any> => {
13
+ return new Promise((resolve, reject) => {
14
+ cbws.getWebsocket.send(JSON.stringify({
15
+ "type": "taskEvent",
16
+ "action":"addTask",
17
+ message:{
18
+ "task": task
19
+ }
20
+
21
+ }));
22
+ cbws.getWebsocket.on('message', (data: string) => {
23
+ const response = JSON.parse(data);
24
+ if (response.type === "addTaskResponse") {
25
+ resolve(response); // Resolve the promise with the response data from adding the task
26
+ }
27
+ });
28
+ });
29
+ },
30
+ /**
31
+ * Retrieves all tasks using a WebSocket message.
32
+ * @returns {Promise<GetTasksResponse>} A promise that resolves with the response from the get tasks event.
33
+ */
34
+ getTasks: async (): Promise<any> => {
35
+ return new Promise((resolve, reject) => {
36
+ cbws.getWebsocket.send(JSON.stringify({
37
+ "type":"taskEvent",
38
+ "action": "getTasks"
39
+ }));
40
+ cbws.getWebsocket.on('message', (data: string) => {
41
+ const response = JSON.parse(data);
42
+ if (response.type === "getTasksResponse") {
43
+ resolve(response); // Resolve the promise with the response data from retrieving tasks
44
+ }
45
+ });
46
+ });
47
+ },
48
+
49
+ /**
50
+ * Updates an existing task using a WebSocket message.
51
+ * @param {string} task - The updated task information.
52
+ * @returns {Promise<UpdateTasksResponse>} A promise that resolves with the response from the update task event.
53
+ */
54
+ updateTask: async ( task: string): Promise<any> => {
55
+ return new Promise((resolve, reject) => {
56
+ cbws.getWebsocket.send(JSON.stringify({
57
+ "type": "taskEvent",
58
+ "action": "updateTask",
59
+ message: {
60
+ "task": task
61
+ }
62
+ }));
63
+ cbws.getWebsocket.on('message', (data: string) => {
64
+ const response = JSON.parse(data);
65
+ if (response.type === "updateTaskResponse") {
66
+ resolve(response); // Resolve the promise with the response data from updating the task
67
+ }
68
+ });
69
+ });
70
+ }
71
+ };
72
+
73
+ export default taskplaner;
@@ -0,0 +1,114 @@
1
+ import cbws from './websocket';
2
+ import { EventEmitter } from 'events';
3
+ import {CommandError,CommandFinish,CommandOutput,TerminalInterruptResponse,TerminalInterrupted } from '@codebolt/types';
4
+ /**
5
+ * CustomEventEmitter class that extends the Node.js EventEmitter class.
6
+ */
7
+ class CustomEventEmitter extends EventEmitter {}
8
+ /**
9
+ * A module for executing commands in a terminal-like environment via WebSocket.
10
+ */
11
+ const cbterminal = {
12
+ eventEmitter: new CustomEventEmitter(),
13
+
14
+ /**
15
+ * Executes a given command and returns the result.
16
+ * Listens for messages from the WebSocket that indicate the output, error, or finish state
17
+ * of the executed command and resolves the promise accordingly.
18
+ *
19
+ * @param {string} command - The command to be executed.
20
+ * @returns {Promise<CommandOutput|CommandError>} A promise that resolves with the command's output, error, or finish signal.
21
+ */
22
+ executeCommand: async (command:string, returnEmptyStringOnSuccess:boolean = false) => {
23
+ return new Promise((resolve, reject) => {
24
+ cbws.getWebsocket.send(JSON.stringify({
25
+ "type": "executeCommand",
26
+ "message": command,
27
+ returnEmptyStringOnSuccess
28
+ }));
29
+ let result = "";
30
+ cbws.getWebsocket.on('message', (data:string) => {
31
+ const response = JSON.parse(data);
32
+ if (response.type === "commandError" || response.type === "commandFinish" ) {
33
+ resolve(response)
34
+ }
35
+ });
36
+ });
37
+ },
38
+
39
+ /**
40
+ * Executes a given command and keeps running until an error occurs.
41
+ * Listens for messages from the WebSocket and resolves the promise when an error is encountered.
42
+ *
43
+ * @param {string} command - The command to be executed.
44
+ * @returns {Promise<CommandError>} A promise that resolves when an error occurs during command execution.
45
+ */
46
+ executeCommandRunUntilError: async (command: string,executeInMain=false): Promise<CommandError> => {
47
+ return new Promise((resolve, reject) => {
48
+ cbws.getWebsocket.send(JSON.stringify({
49
+ "type": "executeCommandRunUntilError",
50
+ "message": command,
51
+ executeInMain
52
+ }));
53
+ cbws.getWebsocket.on('message', (data: string) => {
54
+ const response = JSON.parse(data);
55
+ if ( response.type === "commandError") {
56
+ resolve(response);
57
+ }
58
+ });
59
+ });
60
+ },
61
+
62
+
63
+ /**
64
+ * Sends a manual interrupt signal to the terminal.
65
+ *
66
+ * @returns {Promise<TerminalInterruptResponse>}
67
+ */
68
+ sendManualInterrupt(): Promise<TerminalInterruptResponse> {
69
+
70
+ return new Promise((resolve, reject) => {
71
+ cbws.getWebsocket.send(JSON.stringify({
72
+ "type": "sendInterruptToTerminal"
73
+ }));
74
+ cbws.getWebsocket.on('message', (data: string) => {
75
+ const response = JSON.parse(data);
76
+ if (response.type === "terminalInterrupted") {
77
+ resolve(response);
78
+ }
79
+ });
80
+ });
81
+ },
82
+
83
+ /**
84
+ * Executes a given command and streams the output.
85
+ * Listens for messages from the WebSocket and streams the output data.
86
+ *
87
+ * @param {string} command - The command to be executed.
88
+ * @returns {EventEmitter} A promise that streams the output data during command execution.
89
+ */
90
+ executeCommandWithStream(command: string,executeInMain=false):EventEmitter {
91
+ // Send the process started message
92
+ cbws.getWebsocket.send(JSON.stringify({
93
+ "type": "executeCommandWithStream",
94
+ "message": command
95
+ ,executeInMain
96
+ }));
97
+ // Register event listener for WebSocket messages
98
+ cbws.getWebsocket.on('message', (data: string) => {
99
+ const response = JSON.parse(data);
100
+ console.log("Received message:", response);
101
+ if (response.type === "commandOutput" || response.type === "commandError" || response.type === "commandFinish") {
102
+ this.eventEmitter.emit(response.type, response);
103
+ }
104
+ });
105
+
106
+ // Return an object that includes the event emitter and the stopProcess method
107
+ return this.eventEmitter
108
+
109
+ }
110
+
111
+
112
+
113
+ };
114
+ export default cbterminal;
@@ -0,0 +1,56 @@
1
+ import { AddTokenResponse, GetTokenResponse } from '@codebolt/types';
2
+ import cbws from './websocket';
3
+
4
+ /**
5
+ * Tokenizer module for handling token-related operations.
6
+ */
7
+ const tokenizer = {
8
+
9
+ /**
10
+ * Adds a token to the system via WebSocket.
11
+ * @param {string} key - The key associated with the token to be added.
12
+ * @returns {Promise<AddTokenResponse>} A promise that resolves with the response from the add token event.
13
+ */
14
+ addToken: async (key: string): Promise<AddTokenResponse> => {
15
+ return new Promise((resolve, reject) => {
16
+ cbws.getWebsocket.send(JSON.stringify({
17
+ "type":"tokenizerEvent",
18
+ "action": "addToken",
19
+ "message": {
20
+ item: key
21
+ },
22
+ }));
23
+ cbws.getWebsocket.on('message', (data: string) => {
24
+ const response = JSON.parse(data);
25
+ if (response.type === "addTokenResponse") {
26
+ resolve(response);
27
+ }
28
+ });
29
+ });
30
+ },
31
+
32
+ /**
33
+ * Retrieves a token from the system via WebSocket.
34
+ * @param {string} key - The key associated with the token to be retrieved.
35
+ * @returns {Promise<GetTokenResponse>} A promise that resolves with the response from the get token event.
36
+ */
37
+ getToken: async (key: string): Promise<GetTokenResponse> => {
38
+ return new Promise((resolve, reject) => {
39
+ cbws.getWebsocket.send(JSON.stringify({
40
+ "type":"tokenizerEvent",
41
+ "action": "getToken",
42
+ "message": {
43
+ item: key
44
+ },
45
+ }));
46
+ cbws.getWebsocket.on('message', (data: string) => {
47
+ const response = JSON.parse(data);
48
+ if (response.type === "getTokenResponse") {
49
+ resolve(response);
50
+ }
51
+ });
52
+ });
53
+ }
54
+ }
55
+
56
+ export default tokenizer