@codebolt/codeboltjs 5.0.0 → 5.0.1

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.
@@ -392,8 +392,16 @@ declare class Codebolt {
392
392
  * @private
393
393
  */
394
394
  private handleIncomingMessage;
395
+ /**
396
+ * Sets up a background listener for all messageResponse messages from the socket.
397
+ * This ensures that getMessage() promises are always resolved even if onMessage() is not called.
398
+ * @private
399
+ */
400
+ private setupMessageListener;
395
401
  /**
396
402
  * Sets up a listener for incoming messages with a direct handler function.
403
+ * Note: Message extraction and resolver handling is done by setupMessageListener.
404
+ * This method only adds the custom handler logic and sends processStoped response.
397
405
  * @param {Function} handler - The handler function to call when a message is received.
398
406
  * @returns {void}
399
407
  */
@@ -79,6 +79,7 @@ class Codebolt {
79
79
  this.userMessage = user_message_utilities_1.userMessageUtilities;
80
80
  console.log("Codebolt Agent initialized");
81
81
  this.readyPromise = this.initializeConnection();
82
+ this.setupMessageListener();
82
83
  }
83
84
  /**
84
85
  * @method initializeConnection
@@ -154,7 +155,11 @@ class Codebolt {
154
155
  * Otherwise, waits for the next message to arrive.
155
156
  * @returns {Promise<FlatUserMessage>} A promise that resolves with the next message
156
157
  */
157
- getMessage() {
158
+ async getMessage() {
159
+ // Wait for WebSocket to be ready first
160
+ console.log('[Codebolt] getMessage ');
161
+ await this.waitForReady();
162
+ console.log('[Codebolt] getMessage ');
158
163
  // If there are queued messages, return the first one
159
164
  if (this.messageQueue.length > 0) {
160
165
  const message = this.messageQueue.shift();
@@ -181,8 +186,52 @@ class Codebolt {
181
186
  this.messageQueue.push(message);
182
187
  }
183
188
  }
189
+ /**
190
+ * Sets up a background listener for all messageResponse messages from the socket.
191
+ * This ensures that getMessage() promises are always resolved even if onMessage() is not called.
192
+ * @private
193
+ */
194
+ setupMessageListener() {
195
+ this.waitForReady().then(() => {
196
+ const handleSocketMessage = async (response) => {
197
+ var _a, _b;
198
+ if (response.type === "messageResponse") {
199
+ // Extract user-facing message from internal socket message
200
+ const userMessage = {
201
+ userMessage: response.message.userMessage,
202
+ currentFile: response.message.currentFile,
203
+ mentionedFiles: response.message.mentionedFiles || [],
204
+ mentionedFullPaths: response.message.mentionedFullPaths || [],
205
+ mentionedFolders: response.message.mentionedFolders || [],
206
+ uploadedImages: response.message.uploadedImages || [],
207
+ mentionedMCPs: response.message.mentionedMCPs || [],
208
+ selectedAgent: {
209
+ id: ((_a = response.message.selectedAgent) === null || _a === void 0 ? void 0 : _a.id) || '',
210
+ name: ((_b = response.message.selectedAgent) === null || _b === void 0 ? void 0 : _b.name) || ''
211
+ },
212
+ messageId: response.message.messageId,
213
+ threadId: response.message.threadId,
214
+ selection: response.message.selection,
215
+ remixPrompt: response.message.remixPrompt,
216
+ mentionedAgents: response.message.mentionedAgents || [],
217
+ activeFile: response.message.activeFile,
218
+ openedFiles: response.message.activeFile
219
+ };
220
+ // Automatically save the user message globally
221
+ user_message_manager_1.userMessageManager.saveMessage(userMessage);
222
+ // Handle the message in the queue system for getMessage() resolvers
223
+ this.handleIncomingMessage(userMessage);
224
+ }
225
+ };
226
+ websocket_1.default.messageManager.on('message', handleSocketMessage);
227
+ }).catch(error => {
228
+ console.error('Failed to set up background message listener:', error);
229
+ });
230
+ }
184
231
  /**
185
232
  * Sets up a listener for incoming messages with a direct handler function.
233
+ * Note: Message extraction and resolver handling is done by setupMessageListener.
234
+ * This method only adds the custom handler logic and sends processStoped response.
186
235
  * @param {Function} handler - The handler function to call when a message is received.
187
236
  * @returns {void}
188
237
  */
@@ -215,11 +264,7 @@ class Codebolt {
215
264
  activeFile: response.message.activeFile,
216
265
  openedFiles: response.message.activeFile
217
266
  };
218
- // Automatically save the user message globally
219
- user_message_manager_1.userMessageManager.saveMessage(userMessage);
220
- // Handle the message in the queue system
221
- this.handleIncomingMessage(userMessage);
222
- // Call the original handler
267
+ // Call the custom handler
223
268
  const result = await handler(userMessage);
224
269
  // Send processStoped with optional message
225
270
  const message = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -23,6 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
+ "@codebolt/types": "latest",
26
27
  "@types/uuid": "^10.0.0",
27
28
  "buffer": "^6.0.3",
28
29
  "execa": "^9.5.2",
@@ -34,8 +35,7 @@
34
35
  "util": "^0.12.5",
35
36
  "uuid": "^11.1.0",
36
37
  "ws": "^8.18.3",
37
- "yargs": "^17.7.2",
38
- "@codebolt/types": "1.0.22"
38
+ "yargs": "^17.7.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/events": "^3.0.3",