@codebolt/codeboltjs 1.1.70 → 1.1.73

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 (82) hide show
  1. package/index.js +2 -0
  2. package/package.json +4 -2
  3. package/src/index.ts +3 -1
  4. package/webpack.config.js +1 -1
  5. package/docs/modules/_internal_.EventEmitter.html +0 -6
  6. package/docs/modules/_internal_.WebSocket.html +0 -21
  7. package/docs/modules/_internal_._node_stream_consumers_.html +0 -6
  8. package/docs/modules/_internal_._node_stream_promises_.html +0 -3
  9. package/docs/modules/_internal_.html +0 -228
  10. package/docs/modules/_internal_.internal.finished.html +0 -2
  11. package/docs/modules/_internal_.internal.html +0 -36
  12. package/docs/modules/_internal_.internal.pipeline.html +0 -2
  13. package/index.d.ts +0 -238
  14. package/modules/browser.d.ts +0 -108
  15. package/modules/browser.js +0 -331
  16. package/modules/chat.d.ts +0 -63
  17. package/modules/chat.js +0 -174
  18. package/modules/codeparsers.d.ts +0 -23
  19. package/modules/codeparsers.js +0 -30
  20. package/modules/codeutils.d.ts +0 -37
  21. package/modules/codeutils.js +0 -166
  22. package/modules/crawler.d.ts +0 -45
  23. package/modules/crawler.js +0 -123
  24. package/modules/dbmemory.d.ts +0 -20
  25. package/modules/dbmemory.js +0 -54
  26. package/modules/debug.d.ts +0 -23
  27. package/modules/debug.js +0 -64
  28. package/modules/docutils.d.ts +0 -12
  29. package/modules/docutils.js +0 -19
  30. package/modules/fs.d.ts +0 -94
  31. package/modules/fs.js +0 -264
  32. package/modules/git.d.ts +0 -76
  33. package/modules/git.js +0 -240
  34. package/modules/history.d.ts +0 -19
  35. package/modules/history.js +0 -46
  36. package/modules/knowledge.d.ts +0 -2
  37. package/modules/knowledge.js +0 -6
  38. package/modules/llm.d.ts +0 -18
  39. package/modules/llm.js +0 -39
  40. package/modules/outputparsers.d.ts +0 -24
  41. package/modules/outputparsers.js +0 -32
  42. package/modules/project.d.ts +0 -21
  43. package/modules/project.js +0 -72
  44. package/modules/rag.d.ts +0 -22
  45. package/modules/rag.js +0 -30
  46. package/modules/search.d.ts +0 -23
  47. package/modules/search.js +0 -37
  48. package/modules/state.d.ts +0 -21
  49. package/modules/state.js +0 -68
  50. package/modules/task.d.ts +0 -23
  51. package/modules/task.js +0 -75
  52. package/modules/terminal.d.ts +0 -46
  53. package/modules/terminal.js +0 -108
  54. package/modules/tokenizer.d.ts +0 -19
  55. package/modules/tokenizer.js +0 -56
  56. package/modules/vectordb.d.ts +0 -33
  57. package/modules/vectordb.js +0 -103
  58. package/modules/websocket.d.ts +0 -27
  59. package/modules/websocket.js +0 -88
  60. package/src/modules/browser.ts +0 -352
  61. package/src/modules/chat.ts +0 -182
  62. package/src/modules/codeparsers.ts +0 -30
  63. package/src/modules/codeutils.ts +0 -181
  64. package/src/modules/crawler.ts +0 -121
  65. package/src/modules/dbmemory.ts +0 -52
  66. package/src/modules/debug.ts +0 -68
  67. package/src/modules/docutils.ts +0 -18
  68. package/src/modules/fs.ts +0 -263
  69. package/src/modules/git.ts +0 -237
  70. package/src/modules/history.ts +0 -61
  71. package/src/modules/knowledge.ts +0 -5
  72. package/src/modules/llm.ts +0 -36
  73. package/src/modules/outputparsers.ts +0 -30
  74. package/src/modules/project.ts +0 -68
  75. package/src/modules/rag.ts +0 -28
  76. package/src/modules/search.ts +0 -35
  77. package/src/modules/state.ts +0 -69
  78. package/src/modules/task.ts +0 -73
  79. package/src/modules/terminal.ts +0 -114
  80. package/src/modules/tokenizer.ts +0 -56
  81. package/src/modules/vectordb.ts +0 -102
  82. package/src/modules/websocket.ts +0 -89
package/modules/state.js DELETED
@@ -1,68 +0,0 @@
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
- const cbstate = {
8
- /**
9
- * Retrieves the current application state from the server via WebSocket.
10
- * @returns {Promise<ApplicationState>} A promise that resolves with the application state.
11
- */
12
- getApplicationState: async () => {
13
- return new Promise((resolve, reject) => {
14
- websocket_1.default.getWebsocket.send(JSON.stringify({
15
- "type": "getAppState",
16
- }));
17
- websocket_1.default.getWebsocket.on('message', (data) => {
18
- const response = JSON.parse(data);
19
- if (response.type === "getAppStateResponse") {
20
- resolve(response); // Resolve the Promise with the response data
21
- }
22
- });
23
- });
24
- },
25
- /**
26
- * Adds a key-value pair to the agent's state on the server via WebSocket.
27
- * @param {string} key - The key to add to the agent's state.
28
- * @param {string} value - The value associated with the key.
29
- * @returns {Promise<AddToAgentStateResponse>} A promise that resolves with the response to the addition request.
30
- */
31
- addToAgentState: async (key, value) => {
32
- return new Promise((resolve, reject) => {
33
- websocket_1.default.getWebsocket.send(JSON.stringify({
34
- "type": "agentStateEvent",
35
- "action": "addToAgentState",
36
- payload: {
37
- key,
38
- value
39
- }
40
- }));
41
- websocket_1.default.getWebsocket.on('message', (data) => {
42
- const response = JSON.parse(data);
43
- if (response.type === "addToAgentStateResponse") {
44
- resolve(response); // Resolve the Promise with the response data
45
- }
46
- });
47
- });
48
- },
49
- /**
50
- * Retrieves the current state of the agent from the server via WebSocket.
51
- * @returns {Promise<GetAgentStateResponse>} A promise that resolves with the agent's state.
52
- */
53
- getAgentState: async () => {
54
- return new Promise((resolve, reject) => {
55
- websocket_1.default.getWebsocket.send(JSON.stringify({
56
- "type": "agentStateEvent",
57
- "action": "getAgentState",
58
- }));
59
- websocket_1.default.getWebsocket.on('message', (data) => {
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
- exports.default = cbstate;
package/modules/task.d.ts DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * Manages task operations via WebSocket communication.
3
- */
4
- declare const taskplaner: {
5
- /**
6
- * Adds a task using a WebSocket message.
7
- * @param {string} task - The task to be added.
8
- * @returns {Promise<AddTaskResponse>} A promise that resolves with the response from the add task event.
9
- */
10
- addTask: (task: string) => Promise<any>;
11
- /**
12
- * Retrieves all tasks using a WebSocket message.
13
- * @returns {Promise<GetTasksResponse>} A promise that resolves with the response from the get tasks event.
14
- */
15
- getTasks: () => Promise<any>;
16
- /**
17
- * Updates an existing task using a WebSocket message.
18
- * @param {string} task - The updated task information.
19
- * @returns {Promise<UpdateTasksResponse>} A promise that resolves with the response from the update task event.
20
- */
21
- updateTask: (task: string) => Promise<any>;
22
- };
23
- export default taskplaner;
package/modules/task.js DELETED
@@ -1,75 +0,0 @@
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
- // import {AddTaskResponse,GetTasksResponse,UpdateTasksResponse } from '@codebolt/types';
8
- /**
9
- * Manages task operations via WebSocket communication.
10
- */
11
- const taskplaner = {
12
- /**
13
- * Adds a task using a WebSocket message.
14
- * @param {string} task - The task to be added.
15
- * @returns {Promise<AddTaskResponse>} A promise that resolves with the response from the add task event.
16
- */
17
- addTask: async (task) => {
18
- return new Promise((resolve, reject) => {
19
- websocket_1.default.getWebsocket.send(JSON.stringify({
20
- "type": "taskEvent",
21
- "action": "addTask",
22
- message: {
23
- "task": task
24
- }
25
- }));
26
- websocket_1.default.getWebsocket.on('message', (data) => {
27
- const response = JSON.parse(data);
28
- if (response.type === "addTaskResponse") {
29
- resolve(response); // Resolve the promise with the response data from adding the task
30
- }
31
- });
32
- });
33
- },
34
- /**
35
- * Retrieves all tasks using a WebSocket message.
36
- * @returns {Promise<GetTasksResponse>} A promise that resolves with the response from the get tasks event.
37
- */
38
- getTasks: async () => {
39
- return new Promise((resolve, reject) => {
40
- websocket_1.default.getWebsocket.send(JSON.stringify({
41
- "type": "taskEvent",
42
- "action": "getTasks"
43
- }));
44
- websocket_1.default.getWebsocket.on('message', (data) => {
45
- const response = JSON.parse(data);
46
- if (response.type === "getTasksResponse") {
47
- resolve(response); // Resolve the promise with the response data from retrieving tasks
48
- }
49
- });
50
- });
51
- },
52
- /**
53
- * Updates an existing task using a WebSocket message.
54
- * @param {string} task - The updated task information.
55
- * @returns {Promise<UpdateTasksResponse>} A promise that resolves with the response from the update task event.
56
- */
57
- updateTask: async (task) => {
58
- return new Promise((resolve, reject) => {
59
- websocket_1.default.getWebsocket.send(JSON.stringify({
60
- "type": "taskEvent",
61
- "action": "updateTask",
62
- message: {
63
- "task": task
64
- }
65
- }));
66
- websocket_1.default.getWebsocket.on('message', (data) => {
67
- const response = JSON.parse(data);
68
- if (response.type === "updateTaskResponse") {
69
- resolve(response); // Resolve the promise with the response data from updating the task
70
- }
71
- });
72
- });
73
- }
74
- };
75
- exports.default = taskplaner;
@@ -1,46 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { CommandError, TerminalInterruptResponse } from '@codebolt/types';
4
- /**
5
- * CustomEventEmitter class that extends the Node.js EventEmitter class.
6
- */
7
- declare class CustomEventEmitter extends EventEmitter {
8
- }
9
- /**
10
- * A module for executing commands in a terminal-like environment via WebSocket.
11
- */
12
- declare const cbterminal: {
13
- eventEmitter: CustomEventEmitter;
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: (command: string, returnEmptyStringOnSuccess?: boolean) => Promise<unknown>;
23
- /**
24
- * Executes a given command and keeps running until an error occurs.
25
- * Listens for messages from the WebSocket and resolves the promise when an error is encountered.
26
- *
27
- * @param {string} command - The command to be executed.
28
- * @returns {Promise<CommandError>} A promise that resolves when an error occurs during command execution.
29
- */
30
- executeCommandRunUntilError: (command: string, executeInMain?: boolean) => Promise<CommandError>;
31
- /**
32
- * Sends a manual interrupt signal to the terminal.
33
- *
34
- * @returns {Promise<TerminalInterruptResponse>}
35
- */
36
- sendManualInterrupt(): Promise<TerminalInterruptResponse>;
37
- /**
38
- * Executes a given command and streams the output.
39
- * Listens for messages from the WebSocket and streams the output data.
40
- *
41
- * @param {string} command - The command to be executed.
42
- * @returns {EventEmitter} A promise that streams the output data during command execution.
43
- */
44
- executeCommandWithStream(command: string, executeInMain?: boolean): EventEmitter;
45
- };
46
- export default cbterminal;
@@ -1,108 +0,0 @@
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
- const events_1 = require("events");
8
- /**
9
- * CustomEventEmitter class that extends the Node.js EventEmitter class.
10
- */
11
- class CustomEventEmitter extends events_1.EventEmitter {
12
- }
13
- /**
14
- * A module for executing commands in a terminal-like environment via WebSocket.
15
- */
16
- const cbterminal = {
17
- eventEmitter: new CustomEventEmitter(),
18
- /**
19
- * Executes a given command and returns the result.
20
- * Listens for messages from the WebSocket that indicate the output, error, or finish state
21
- * of the executed command and resolves the promise accordingly.
22
- *
23
- * @param {string} command - The command to be executed.
24
- * @returns {Promise<CommandOutput|CommandError>} A promise that resolves with the command's output, error, or finish signal.
25
- */
26
- executeCommand: async (command, returnEmptyStringOnSuccess = false) => {
27
- return new Promise((resolve, reject) => {
28
- websocket_1.default.getWebsocket.send(JSON.stringify({
29
- "type": "executeCommand",
30
- "message": command,
31
- returnEmptyStringOnSuccess
32
- }));
33
- let result = "";
34
- websocket_1.default.getWebsocket.on('message', (data) => {
35
- const response = JSON.parse(data);
36
- if (response.type === "commandError" || response.type === "commandFinish") {
37
- resolve(response);
38
- }
39
- });
40
- });
41
- },
42
- /**
43
- * Executes a given command and keeps running until an error occurs.
44
- * Listens for messages from the WebSocket and resolves the promise when an error is encountered.
45
- *
46
- * @param {string} command - The command to be executed.
47
- * @returns {Promise<CommandError>} A promise that resolves when an error occurs during command execution.
48
- */
49
- executeCommandRunUntilError: async (command, executeInMain = false) => {
50
- return new Promise((resolve, reject) => {
51
- websocket_1.default.getWebsocket.send(JSON.stringify({
52
- "type": "executeCommandRunUntilError",
53
- "message": command,
54
- executeInMain
55
- }));
56
- websocket_1.default.getWebsocket.on('message', (data) => {
57
- const response = JSON.parse(data);
58
- if (response.type === "commandError") {
59
- resolve(response);
60
- }
61
- });
62
- });
63
- },
64
- /**
65
- * Sends a manual interrupt signal to the terminal.
66
- *
67
- * @returns {Promise<TerminalInterruptResponse>}
68
- */
69
- sendManualInterrupt() {
70
- return new Promise((resolve, reject) => {
71
- websocket_1.default.getWebsocket.send(JSON.stringify({
72
- "type": "sendInterruptToTerminal"
73
- }));
74
- websocket_1.default.getWebsocket.on('message', (data) => {
75
- const response = JSON.parse(data);
76
- if (response.type === "terminalInterrupted") {
77
- resolve(response);
78
- }
79
- });
80
- });
81
- },
82
- /**
83
- * Executes a given command and streams the output.
84
- * Listens for messages from the WebSocket and streams the output data.
85
- *
86
- * @param {string} command - The command to be executed.
87
- * @returns {EventEmitter} A promise that streams the output data during command execution.
88
- */
89
- executeCommandWithStream(command, executeInMain = false) {
90
- // Send the process started message
91
- websocket_1.default.getWebsocket.send(JSON.stringify({
92
- "type": "executeCommandWithStream",
93
- "message": command,
94
- executeInMain
95
- }));
96
- // Register event listener for WebSocket messages
97
- websocket_1.default.getWebsocket.on('message', (data) => {
98
- const response = JSON.parse(data);
99
- console.log("Received message:", response);
100
- if (response.type === "commandOutput" || response.type === "commandError" || response.type === "commandFinish") {
101
- this.eventEmitter.emit(response.type, response);
102
- }
103
- });
104
- // Return an object that includes the event emitter and the stopProcess method
105
- return this.eventEmitter;
106
- }
107
- };
108
- exports.default = cbterminal;
@@ -1,19 +0,0 @@
1
- import { AddTokenResponse, GetTokenResponse } from '@codebolt/types';
2
- /**
3
- * Tokenizer module for handling token-related operations.
4
- */
5
- declare const tokenizer: {
6
- /**
7
- * Adds a token to the system via WebSocket.
8
- * @param {string} key - The key associated with the token to be added.
9
- * @returns {Promise<AddTokenResponse>} A promise that resolves with the response from the add token event.
10
- */
11
- addToken: (key: string) => Promise<AddTokenResponse>;
12
- /**
13
- * Retrieves a token from the system via WebSocket.
14
- * @param {string} key - The key associated with the token to be retrieved.
15
- * @returns {Promise<GetTokenResponse>} A promise that resolves with the response from the get token event.
16
- */
17
- getToken: (key: string) => Promise<GetTokenResponse>;
18
- };
19
- export default tokenizer;
@@ -1,56 +0,0 @@
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 to the system via WebSocket.
13
- * @param {string} key - The key associated with the token to be added.
14
- * @returns {Promise<AddTokenResponse>} A promise that resolves with the response from the add token event.
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
- * Retrieves a token from the system via WebSocket.
35
- * @param {string} key - The key associated with the token to be retrieved.
36
- * @returns {Promise<GetTokenResponse>} A promise that resolves with the response from the get token event.
37
- */
38
- getToken: async (key) => {
39
- return new Promise((resolve, reject) => {
40
- websocket_1.default.getWebsocket.send(JSON.stringify({
41
- "type": "tokenizerEvent",
42
- "action": "getToken",
43
- "message": {
44
- item: key
45
- },
46
- }));
47
- websocket_1.default.getWebsocket.on('message', (data) => {
48
- const response = JSON.parse(data);
49
- if (response.type === "getTokenResponse") {
50
- resolve(response);
51
- }
52
- });
53
- });
54
- }
55
- };
56
- exports.default = tokenizer;
@@ -1,33 +0,0 @@
1
- import { AddVectorItemResponse, GetVectorResponse, QueryVectorItemResponse } from '@codebolt/types';
2
- declare const VectorDB: {
3
- /**
4
- * Retrieves a vector from the vector database based on the provided key.
5
- *
6
- * @param {string} key - The key of the vector to retrieve.
7
- * @returns {Promise<GetVectorResponse>} A promise that resolves with the retrieved vector.
8
- */
9
- getVector: (key: string) => Promise<GetVectorResponse>;
10
- /**
11
- * Adds a new vector item to the vector database.
12
- *
13
-
14
- * @param {any} item - The item to add to the vector.
15
- * @returns {Promise<AddVectorItemResponse>} A promise that resolves when the item is successfully added.
16
- */
17
- addVectorItem: (item: any) => Promise<AddVectorItemResponse>;
18
- /**
19
- * Queries a vector item from the vector database based on the provided key.
20
- *
21
- * @param {string} key - The key of the vector to query the item from.
22
- * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
23
- */
24
- queryVectorItem: (key: string) => Promise<QueryVectorItemResponse>;
25
- /**
26
- * Queries a vector item from the vector database based on the provided key.
27
- *
28
- * @param {string} key - The key of the vector to query the item from.
29
- * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
30
- */
31
- queryVectorItems: (items: [], dbPath: string) => Promise<QueryVectorItemResponse>;
32
- };
33
- export default VectorDB;
@@ -1,103 +0,0 @@
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
- const VectorDB = {
8
- /**
9
- * Retrieves a vector from the vector database based on the provided key.
10
- *
11
- * @param {string} key - The key of the vector to retrieve.
12
- * @returns {Promise<GetVectorResponse>} A promise that resolves with the retrieved vector.
13
- */
14
- getVector: async (key) => {
15
- return new Promise((resolve, reject) => {
16
- websocket_1.default.getWebsocket.send(JSON.stringify({
17
- "type": "vectordbEvent",
18
- "action": "getVector",
19
- "message": {
20
- item: key
21
- },
22
- }));
23
- websocket_1.default.getWebsocket.on('message', (data) => {
24
- const response = JSON.parse(data);
25
- if (response.type === "getVectorResponse") {
26
- resolve(response);
27
- }
28
- });
29
- });
30
- },
31
- /**
32
- * Adds a new vector item to the vector database.
33
- *
34
-
35
- * @param {any} item - The item to add to the vector.
36
- * @returns {Promise<AddVectorItemResponse>} A promise that resolves when the item is successfully added.
37
- */
38
- addVectorItem: async (item) => {
39
- return new Promise((resolve, reject) => {
40
- websocket_1.default.getWebsocket.send(JSON.stringify({
41
- "type": "vectordbEvent",
42
- "action": "addVectorItem",
43
- "message": {
44
- item: item
45
- },
46
- }));
47
- websocket_1.default.getWebsocket.on('message', (data) => {
48
- const response = JSON.parse(data);
49
- if (response.type === "addVectorItemResponse") {
50
- resolve(response);
51
- }
52
- });
53
- });
54
- },
55
- /**
56
- * Queries a vector item from the vector database based on the provided key.
57
- *
58
- * @param {string} key - The key of the vector to query the item from.
59
- * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
60
- */
61
- queryVectorItem: async (key) => {
62
- return new Promise((resolve, reject) => {
63
- websocket_1.default.getWebsocket.send(JSON.stringify({
64
- "type": "vectordbEvent",
65
- "action": "queryVectorItem",
66
- "message": {
67
- item: key
68
- },
69
- }));
70
- websocket_1.default.getWebsocket.on('message', (data) => {
71
- const response = JSON.parse(data);
72
- if (response.type === "qeryVectorItemResponse") {
73
- resolve(response);
74
- }
75
- });
76
- });
77
- },
78
- /**
79
- * Queries a vector item from the vector database based on the provided key.
80
- *
81
- * @param {string} key - The key of the vector to query the item from.
82
- * @returns {Promise<QueryVectorItemResponse>} A promise that resolves with the queried vector item.
83
- */
84
- queryVectorItems: async (items, dbPath) => {
85
- return new Promise((resolve, reject) => {
86
- websocket_1.default.getWebsocket.send(JSON.stringify({
87
- "type": "vectordbEvent",
88
- "action": "queryVectorItems",
89
- "message": {
90
- items,
91
- dbPath
92
- },
93
- }));
94
- websocket_1.default.getWebsocket.on('message', (data) => {
95
- const response = JSON.parse(data);
96
- if (response.type === "qeryVectorItemsResponse") {
97
- resolve(response);
98
- }
99
- });
100
- });
101
- },
102
- };
103
- exports.default = VectorDB;
@@ -1,27 +0,0 @@
1
- import WebSocket from 'ws';
2
- /**
3
- * Class representing a WebSocket connection.
4
- */
5
- declare class cbws {
6
- websocket: WebSocket;
7
- /**
8
- * Constructs a new cbws instance and initializes the WebSocket connection.
9
- */
10
- constructor();
11
- private getUniqueConnectionId;
12
- private getInitialMessage;
13
- /**
14
- * Initializes the WebSocket by setting up event listeners and returning a promise that resolves
15
- * when the WebSocket connection is successfully opened.
16
- * @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
17
- */
18
- private initializeWebSocket;
19
- /**
20
- * Getter for the WebSocket instance. Throws an error if the WebSocket is not open.
21
- * @returns {WebSocket} The WebSocket instance.
22
- * @throws {Error} If the WebSocket is not open.
23
- */
24
- get getWebsocket(): WebSocket;
25
- }
26
- declare const _default: cbws;
27
- export default _default;
@@ -1,88 +0,0 @@
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 ws_1 = __importDefault(require("ws"));
7
- const fs_1 = __importDefault(require("fs"));
8
- const js_yaml_1 = __importDefault(require("js-yaml"));
9
- /**
10
- * Class representing a WebSocket connection.
11
- */
12
- class cbws {
13
- /**
14
- * Constructs a new cbws instance and initializes the WebSocket connection.
15
- */
16
- constructor() {
17
- const uniqueConnectionId = this.getUniqueConnectionId();
18
- const initialMessage = this.getInitialMessage();
19
- console.log(uniqueConnectionId);
20
- this.websocket = new ws_1.default(`ws://localhost:${process.env.SOCKET_PORT}/codebolt?id=${uniqueConnectionId}`);
21
- this.initializeWebSocket(initialMessage).catch(error => {
22
- console.error("WebSocket connection failed:", error);
23
- });
24
- }
25
- getUniqueConnectionId() {
26
- try {
27
- let fileContents = fs_1.default.readFileSync('./codeboltagent.yaml', 'utf8');
28
- let data = js_yaml_1.default.load(fileContents);
29
- return data.unique_connectionid;
30
- }
31
- catch (e) {
32
- console.error('Unable to locate codeboltagent.yaml file.');
33
- return '';
34
- }
35
- }
36
- getInitialMessage() {
37
- try {
38
- let fileContents = fs_1.default.readFileSync('./codeboltagent.yaml', 'utf8');
39
- let data = js_yaml_1.default.load(fileContents);
40
- return data.initial_message;
41
- }
42
- catch (e) {
43
- console.error('Unable to locate codeboltagent.yaml file.');
44
- return '';
45
- }
46
- }
47
- /**
48
- * Initializes the WebSocket by setting up event listeners and returning a promise that resolves
49
- * when the WebSocket connection is successfully opened.
50
- * @returns {Promise<WebSocket>} A promise that resolves with the WebSocket instance.
51
- */
52
- async initializeWebSocket(initialMessage) {
53
- return new Promise((resolve, reject) => {
54
- this.websocket.on('error', (error) => {
55
- console.log('WebSocket error:', error);
56
- reject(error);
57
- });
58
- this.websocket.on('open', () => {
59
- console.log('WebSocket connected');
60
- // if (this.websocket) {
61
- // this.websocket.send(JSON.stringify({
62
- // "type": "sendMessage",
63
- // "message": initialMessage
64
- // }));
65
- // resolve(this.websocket);
66
- // }
67
- });
68
- this.websocket.on('message', (data) => {
69
- // Handle incoming WebSocket messages here.
70
- // console.log('WebSocket message received:', data);
71
- });
72
- });
73
- }
74
- /**
75
- * Getter for the WebSocket instance. Throws an error if the WebSocket is not open.
76
- * @returns {WebSocket} The WebSocket instance.
77
- * @throws {Error} If the WebSocket is not open.
78
- */
79
- get getWebsocket() {
80
- if (!this.websocket.OPEN) {
81
- throw new Error('WebSocket is not open');
82
- }
83
- else {
84
- return this.websocket;
85
- }
86
- }
87
- }
88
- exports.default = new cbws();