@codebolt/codeboltjs 5.0.6 → 5.0.8

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 (56) hide show
  1. package/dist/core/Codebolt.d.ts +354 -350
  2. package/dist/core/Codebolt.js +2 -0
  3. package/dist/index.d.ts +65 -29
  4. package/dist/index.js +121 -9
  5. package/dist/modules/actionPlan.d.ts +6 -18
  6. package/dist/modules/agentDeliberation.d.ts +1 -1
  7. package/dist/modules/agentDeliberation.js +9 -9
  8. package/dist/modules/agentEventQueue.d.ts +45 -3
  9. package/dist/modules/agentEventQueue.js +172 -20
  10. package/dist/modules/autoTesting.d.ts +1 -1
  11. package/dist/modules/autoTesting.js +19 -19
  12. package/dist/modules/backgroundChildThreads.d.ts +16 -17
  13. package/dist/modules/backgroundChildThreads.js +39 -16
  14. package/dist/modules/browser.d.ts +7 -6
  15. package/dist/modules/browser.js +4 -4
  16. package/dist/modules/chat.d.ts +10 -14
  17. package/dist/modules/chat.js +7 -5
  18. package/dist/modules/codebaseSearch.d.ts +1 -1
  19. package/dist/modules/codemap.d.ts +1 -1
  20. package/dist/modules/contextAssembly.d.ts +1 -1
  21. package/dist/modules/contextRuleEngine.d.ts +1 -1
  22. package/dist/modules/eventLog.d.ts +1 -1
  23. package/dist/modules/fileUpdateIntent.d.ts +1 -1
  24. package/dist/modules/groupFeedback.d.ts +2 -2
  25. package/dist/modules/groupFeedback.js +8 -8
  26. package/dist/modules/hook.d.ts +1 -1
  27. package/dist/modules/job.d.ts +1 -1
  28. package/dist/modules/knowledgeGraph.d.ts +1 -1
  29. package/dist/modules/kvStore.d.ts +1 -1
  30. package/dist/modules/mail.d.ts +2 -91
  31. package/dist/modules/mcp.js +3 -3
  32. package/dist/modules/memoryIngestion.d.ts +1 -1
  33. package/dist/modules/orchestrator.d.ts +3 -43
  34. package/dist/modules/orchestrator.js +2 -2
  35. package/dist/modules/persistentMemory.d.ts +1 -1
  36. package/dist/modules/projectStructure.d.ts +1 -1
  37. package/dist/modules/projectStructureUpdateRequest.d.ts +1 -1
  38. package/dist/modules/reviewMergeRequest.d.ts +6 -2
  39. package/dist/modules/roadmap.d.ts +1 -1
  40. package/dist/modules/swarm.d.ts +2 -2
  41. package/dist/modules/terminal.d.ts +2 -2
  42. package/dist/modules/thread.d.ts +12 -10
  43. package/dist/modules/thread.js +11 -7
  44. package/dist/modules/user-message-manager.js +4 -4
  45. package/dist/tools/actionPlan/action-plan-add-task.d.ts +3 -2
  46. package/dist/tools/agentEventQueue/eventqueue-send-message.js +1 -1
  47. package/dist/tools/chat/chat-send.d.ts +1 -1
  48. package/dist/tools/index.d.ts +2 -2
  49. package/dist/tools/index.js +54 -59
  50. package/dist/tools/planning/plan-add-task.d.ts +2 -22
  51. package/dist/tools/requirementPlan/requirement-plan-add-section.js +1 -1
  52. package/dist/tools/review/review-create.js +1 -1
  53. package/dist/tools/reviewMergeRequest/rmr-create.js +3 -2
  54. package/dist/tools/thread/thread-create-background.d.ts +7 -3
  55. package/dist/tools/thread/thread-create-background.js +31 -11
  56. package/package.json +5 -4
@@ -11,22 +11,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.AgentEventPriority = exports.AgentEventStatus = exports.AgentEventType = void 0;
12
12
  const websocket_1 = __importDefault(require("../core/websocket"));
13
13
  const crypto_1 = require("crypto");
14
- var agentEventQueue_1 = require("../types/agentEventQueue");
15
- Object.defineProperty(exports, "AgentEventType", { enumerable: true, get: function () { return agentEventQueue_1.AgentEventType; } });
16
- Object.defineProperty(exports, "AgentEventStatus", { enumerable: true, get: function () { return agentEventQueue_1.AgentEventStatus; } });
17
- Object.defineProperty(exports, "AgentEventPriority", { enumerable: true, get: function () { return agentEventQueue_1.AgentEventPriority; } });
14
+ var lib_1 = require("@codebolt/types/lib");
15
+ Object.defineProperty(exports, "AgentEventType", { enumerable: true, get: function () { return lib_1.AgentEventType; } });
16
+ Object.defineProperty(exports, "AgentEventStatus", { enumerable: true, get: function () { return lib_1.AgentEventStatus; } });
17
+ Object.defineProperty(exports, "AgentEventPriority", { enumerable: true, get: function () { return lib_1.AgentEventPriority; } });
18
18
  // ============================================================================
19
19
  // Local Event Cache
20
20
  // ============================================================================
21
- /** Local cache for events received via WebSocket */
21
+ /** Local cache for agent events received via WebSocket */
22
22
  const localEventCache = new Map();
23
+ /** Unified cache for all external events (queue events, background completions, grouped completions) */
24
+ const pendingExternalEvents = [];
23
25
  /** Registered event handlers */
24
26
  const eventHandlers = new Set();
25
27
  /** Event emitter for waiting promises */
26
28
  const events_1 = require("events");
27
29
  const eventEmitter = new events_1.EventEmitter();
28
30
  // ============================================================================
29
- // WebSocket Subscription
31
+ // WebSocket Subscriptions
30
32
  // ============================================================================
31
33
  // Subscribe to agentEvent messages from WebSocket
32
34
  const agentEventSubscription = websocket_1.default.messageManager.subscribe('agentEvent');
@@ -35,8 +37,11 @@ agentEventSubscription.on('message', (message) => {
35
37
  if (event && event.eventId) {
36
38
  // Store in local cache
37
39
  localEventCache.set(event.eventId, event);
40
+ // Also push to unified external events cache
41
+ pendingExternalEvents.push({ type: 'agentQueueEvent', data: event });
38
42
  // Notify waiting promises
39
43
  eventEmitter.emit('newEvent', event);
44
+ eventEmitter.emit('externalEvent', { type: 'agentQueueEvent', data: event });
40
45
  // Call registered handlers
41
46
  for (const handler of eventHandlers) {
42
47
  try {
@@ -48,6 +53,33 @@ agentEventSubscription.on('message', (message) => {
48
53
  }
49
54
  }
50
55
  });
56
+ // Subscribe to background agent completion messages
57
+ const backgroundAgentSubscription = websocket_1.default.messageManager.subscribe('startThreadResponse');
58
+ backgroundAgentSubscription.on('message', (message) => {
59
+ if (message.threadId) {
60
+ const externalEvent = { type: 'backgroundAgentCompletion', data: message };
61
+ pendingExternalEvents.push(externalEvent);
62
+ eventEmitter.emit('externalEvent', externalEvent);
63
+ }
64
+ });
65
+ // Subscribe to ThreadCompleted as an alternative message type
66
+ const threadCompletedSubscription = websocket_1.default.messageManager.subscribe('ThreadCompleted');
67
+ threadCompletedSubscription.on('message', (message) => {
68
+ if (message.threadId) {
69
+ const externalEvent = { type: 'backgroundAgentCompletion', data: message };
70
+ pendingExternalEvents.push(externalEvent);
71
+ eventEmitter.emit('externalEvent', externalEvent);
72
+ }
73
+ });
74
+ // Subscribe to grouped agent completion messages
75
+ const groupedAgentSubscription = websocket_1.default.messageManager.subscribe('backgroundGroupedAgentCompletion');
76
+ groupedAgentSubscription.on('message', (message) => {
77
+ if (message.threadId) {
78
+ const externalEvent = { type: 'backgroundGroupedAgentCompletion', data: message };
79
+ pendingExternalEvents.push(externalEvent);
80
+ eventEmitter.emit('externalEvent', externalEvent);
81
+ }
82
+ });
51
83
  // ============================================================================
52
84
  // Agent Event Queue Module
53
85
  // ============================================================================
@@ -66,7 +98,7 @@ const agentEventQueue = {
66
98
  type: 'agentEventQueue.addEventForAgent',
67
99
  requestId,
68
100
  params
69
- }, 'agentEventQueueResponse');
101
+ }, 'agentEventQueue.addEventForAgentResponse');
70
102
  },
71
103
  /**
72
104
  * Send an inter-agent message (convenience wrapper)
@@ -79,7 +111,7 @@ const agentEventQueue = {
79
111
  type: 'agentEventQueue.sendAgentMessage',
80
112
  requestId,
81
113
  params
82
- }, 'agentEventQueueResponse');
114
+ }, 'agentEventQueue.sendAgentMessageResponse');
83
115
  },
84
116
  /**
85
117
  * Get queue statistics
@@ -91,7 +123,7 @@ const agentEventQueue = {
91
123
  type: 'agentEventQueue.getQueueStats',
92
124
  requestId,
93
125
  params: {}
94
- }, 'agentEventQueueResponse');
126
+ }, 'agentEventQueue.getQueueStatsResponse');
95
127
  },
96
128
  /**
97
129
  * Clear the queue for an agent
@@ -104,7 +136,7 @@ const agentEventQueue = {
104
136
  type: 'agentEventQueue.clearQueue',
105
137
  requestId,
106
138
  params: { agentId }
107
- }, 'agentEventQueueResponse');
139
+ }, 'agentEventQueue.clearQueueResponse');
108
140
  },
109
141
  // ========================================================================
110
142
  // Internal Acknowledgement Helper
@@ -125,7 +157,7 @@ const agentEventQueue = {
125
157
  success,
126
158
  errorMessage
127
159
  }
128
- }, 'agentEventQueueResponse');
160
+ }, 'agentEventQueue.ackEventResponse');
129
161
  },
130
162
  /**
131
163
  * Fetch pending events from backend
@@ -133,15 +165,37 @@ const agentEventQueue = {
133
165
  */
134
166
  _fetchPendingFromBackend: async (params = {}) => {
135
167
  const requestId = (0, crypto_1.randomUUID)();
136
- const response = await websocket_1.default.messageManager.sendAndWaitForResponse({
137
- type: 'agentEventQueue.getPendingEvents',
138
- requestId,
139
- params
140
- }, 'agentEventQueueResponse');
141
- if (response.success && response.data) {
142
- return response.data.events;
168
+ try {
169
+ const response = await websocket_1.default.messageManager.sendAndWaitForResponse({
170
+ type: 'agentEventQueue.getPendingEvents',
171
+ requestId,
172
+ params
173
+ }, 'agentEventQueue.getPendingEventsResponse');
174
+ console.log('[AgentEventQueue] Backend response:', JSON.stringify(response, null, 2));
175
+ if (response.success && response.data) {
176
+ // Handle case where data itself is the array
177
+ if (Array.isArray(response.data)) {
178
+ return response.data;
179
+ }
180
+ // Handle case where events are nested under data.events
181
+ const events = response.data.events;
182
+ if (Array.isArray(events)) {
183
+ return events;
184
+ }
185
+ console.warn('[AgentEventQueue] response.data.events is not an array:', typeof events, events);
186
+ return [];
187
+ }
188
+ // Handle case where events are at response root level (not nested under data)
189
+ const responseAny = response;
190
+ if (response.success && Array.isArray(responseAny.events)) {
191
+ return responseAny.events;
192
+ }
193
+ return [];
194
+ }
195
+ catch (error) {
196
+ console.error('[AgentEventQueue] Error fetching pending events from backend:', error);
197
+ return [];
143
198
  }
144
- return [];
145
199
  },
146
200
  // ========================================================================
147
201
  // Local Event Management Functions
@@ -157,6 +211,7 @@ const agentEventQueue = {
157
211
  getPendingQueueEvents: async (maxDepth) => {
158
212
  const events = [];
159
213
  const eventIds = Array.from(localEventCache.keys());
214
+ console.log('[AgentEventQueue] getPendingQueueEvents - localEventCache size:', localEventCache.size);
160
215
  // Determine how many events to process
161
216
  const limit = maxDepth !== undefined ? Math.min(maxDepth, eventIds.length) : eventIds.length;
162
217
  // Get events from local cache
@@ -164,16 +219,27 @@ const agentEventQueue = {
164
219
  const eventId = eventIds[i];
165
220
  const event = localEventCache.get(eventId);
166
221
  if (event) {
222
+ console.log('[AgentEventQueue] Local cache event:', eventId, 'has eventId field:', !!event.eventId);
167
223
  events.push(event);
168
224
  }
169
225
  }
170
226
  // If no local events, try fetching from backend
171
227
  if (events.length === 0) {
172
228
  const backendEvents = await agentEventQueue._fetchPendingFromBackend({ limit: maxDepth });
229
+ console.log('[AgentEventQueue] getPendingQueueEvents - backendEvents:', Array.isArray(backendEvents) ? `array of ${backendEvents.length}` : typeof backendEvents, JSON.stringify(backendEvents, null, 2));
230
+ // Ensure backendEvents is an array
231
+ if (!Array.isArray(backendEvents)) {
232
+ console.error('[AgentEventQueue] backendEvents is not an array, returning empty array');
233
+ return [];
234
+ }
173
235
  // Acknowledge backend events
174
236
  for (const event of backendEvents) {
175
237
  try {
176
- await agentEventQueue._acknowledgeEvent(event.eventId, true);
238
+ const ackResponse = await agentEventQueue._acknowledgeEvent(event.eventId, true);
239
+ console.log(`[AgentEventQueue] Ack response for ${event.eventId}:`, JSON.stringify(ackResponse));
240
+ if (!ackResponse.success) {
241
+ console.error(`[AgentEventQueue] Failed to acknowledge event ${event.eventId}:`, ackResponse.message);
242
+ }
177
243
  }
178
244
  catch (error) {
179
245
  console.error(`[AgentEventQueue] Error acknowledging event ${event.eventId}:`, error);
@@ -283,6 +349,92 @@ const agentEventQueue = {
283
349
  */
284
350
  clearLocalCache: () => {
285
351
  localEventCache.clear();
352
+ },
353
+ // ========================================================================
354
+ // Unified External Event Handling
355
+ // ========================================================================
356
+ /**
357
+ * Check for any pending external events without waiting.
358
+ * Returns the first pending event or null if none available.
359
+ *
360
+ * @returns {UnifiedExternalEvent | null} The first pending event or null
361
+ */
362
+ checkForPendingExternalEvent: () => {
363
+ if (pendingExternalEvents.length > 0) {
364
+ return pendingExternalEvents.shift() || null;
365
+ }
366
+ return null;
367
+ },
368
+ /**
369
+ * Get all pending external events.
370
+ * Returns all pending events and clears the cache.
371
+ *
372
+ * @returns {UnifiedExternalEvent[]} Array of pending events
373
+ */
374
+ getPendingExternalEvents: () => {
375
+ const events = [...pendingExternalEvents];
376
+ pendingExternalEvents.length = 0;
377
+ return events;
378
+ },
379
+ /**
380
+ * Get the count of pending external events.
381
+ *
382
+ * @returns {number} Number of pending events
383
+ */
384
+ getPendingExternalEventCount: () => {
385
+ return pendingExternalEvents.length;
386
+ },
387
+ /**
388
+ * Waits for any external event from multiple sources:
389
+ * - Agent queue events (from local cache or WebSocket)
390
+ * - Background agent completions
391
+ * - Grouped agent completions
392
+ *
393
+ * Returns the first event that occurs from any source.
394
+ *
395
+ * @returns {Promise<UnifiedExternalEvent>} A promise that resolves with the event type and data
396
+ */
397
+ waitForAnyExternalEvent: async () => {
398
+ var _a;
399
+ // Check if there are already pending events
400
+ if (pendingExternalEvents.length > 0) {
401
+ const event = pendingExternalEvents.shift();
402
+ // If it's an agent queue event, acknowledge it
403
+ if (event.type === 'agentQueueEvent' && ((_a = event.data) === null || _a === void 0 ? void 0 : _a.eventId)) {
404
+ try {
405
+ await agentEventQueue._acknowledgeEvent(event.data.eventId, true);
406
+ localEventCache.delete(event.data.eventId);
407
+ }
408
+ catch (error) {
409
+ console.error(`[AgentEventQueue] Error acknowledging event ${event.data.eventId}:`, error);
410
+ }
411
+ }
412
+ return event;
413
+ }
414
+ // Wait for the next external event
415
+ return new Promise((resolve) => {
416
+ const handler = async (event) => {
417
+ var _a;
418
+ eventEmitter.removeListener('externalEvent', handler);
419
+ // Remove from pending queue (it was added by the subscription)
420
+ const index = pendingExternalEvents.findIndex(e => e === event);
421
+ if (index !== -1) {
422
+ pendingExternalEvents.splice(index, 1);
423
+ }
424
+ // If it's an agent queue event, acknowledge it
425
+ if (event.type === 'agentQueueEvent' && ((_a = event.data) === null || _a === void 0 ? void 0 : _a.eventId)) {
426
+ try {
427
+ await agentEventQueue._acknowledgeEvent(event.data.eventId, true);
428
+ localEventCache.delete(event.data.eventId);
429
+ }
430
+ catch (error) {
431
+ console.error(`[AgentEventQueue] Error acknowledging event ${event.data.eventId}:`, error);
432
+ }
433
+ }
434
+ resolve(event);
435
+ };
436
+ eventEmitter.once('externalEvent', handler);
437
+ });
286
438
  }
287
439
  };
288
440
  exports.default = agentEventQueue;
@@ -1,4 +1,4 @@
1
- import { IAddCaseToSuiteParams, IAddCaseToSuiteResponse, ICreateCaseParams, ICreateCaseResponse, ICreateRunParams, ICreateRunResponse, ICreateSuiteParams, ICreateSuiteResponse, IDeleteCaseParams, IDeleteCaseResponse, IDeleteSuiteParams, IDeleteSuiteResponse, IGetCaseParams, IGetCaseResponse, IGetRunParams, IGetRunResponse, IGetSuiteParams, IGetSuiteResponse, IListCasesParams, IListCasesResponse, IListRunsParams, IListRunsResponse, IListSuitesParams, IListSuitesResponse, IRemoveCaseFromSuiteParams, IRemoveCaseFromSuiteResponse, IUpdateCaseParams, IUpdateCaseResponse, IUpdateRunCaseParams, IUpdateRunCaseResponse, IUpdateRunStatusParams, IUpdateRunStatusResponse, IUpdateRunStepParams, IUpdateRunStepResponse, IUpdateSuiteParams, IUpdateSuiteResponse } from '../types/autoTesting';
1
+ import { IAddCaseToSuiteParams, IAddCaseToSuiteResponse, ICreateCaseParams, ICreateCaseResponse, ICreateRunParams, ICreateRunResponse, ICreateSuiteParams, ICreateSuiteResponse, IDeleteCaseParams, IDeleteCaseResponse, IDeleteSuiteParams, IDeleteSuiteResponse, IGetCaseParams, IGetCaseResponse, IGetRunParams, IGetRunResponse, IGetSuiteParams, IGetSuiteResponse, IListCasesParams, IListCasesResponse, IListRunsParams, IListRunsResponse, IListSuitesParams, IListSuitesResponse, IRemoveCaseFromSuiteParams, IRemoveCaseFromSuiteResponse, IUpdateCaseParams, IUpdateCaseResponse, IUpdateRunCaseParams, IUpdateRunCaseResponse, IUpdateRunStatusParams, IUpdateRunStatusResponse, IUpdateRunStepParams, IUpdateRunStepResponse, IUpdateSuiteParams, IUpdateSuiteResponse } from '@codebolt/types/lib';
2
2
  declare const cbautoTesting: {
3
3
  createSuite: (params: ICreateSuiteParams) => Promise<ICreateSuiteResponse>;
4
4
  getSuite: (params: IGetSuiteParams) => Promise<IGetSuiteResponse>;
@@ -4,28 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const websocket_1 = __importDefault(require("../core/websocket"));
7
- const autoTesting_1 = require("../types/autoTesting");
7
+ const lib_1 = require("@codebolt/types/lib");
8
8
  const cbautoTesting = {
9
9
  // ---- Test Suites ----
10
- createSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.SUITE_CREATE, ...params }, autoTesting_1.AutoTestingResponseType.SUITE_CREATE_RESPONSE),
11
- getSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.SUITE_GET, ...params }, autoTesting_1.AutoTestingResponseType.SUITE_GET_RESPONSE),
12
- listSuites: async (_params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.SUITE_LIST }, autoTesting_1.AutoTestingResponseType.SUITE_LIST_RESPONSE),
13
- updateSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.SUITE_UPDATE, ...params }, autoTesting_1.AutoTestingResponseType.SUITE_UPDATE_RESPONSE),
14
- deleteSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.SUITE_DELETE, ...params }, autoTesting_1.AutoTestingResponseType.SUITE_DELETE_RESPONSE),
15
- addCaseToSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.SUITE_CASE_ADD, ...params }, autoTesting_1.AutoTestingResponseType.SUITE_CASE_ADD_RESPONSE),
16
- removeCaseFromSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.SUITE_CASE_REMOVE, ...params }, autoTesting_1.AutoTestingResponseType.SUITE_CASE_REMOVE_RESPONSE),
10
+ createSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.SUITE_CREATE, ...params }, lib_1.AutoTestingResponseType.SUITE_CREATE_RESPONSE),
11
+ getSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.SUITE_GET, ...params }, lib_1.AutoTestingResponseType.SUITE_GET_RESPONSE),
12
+ listSuites: async (_params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.SUITE_LIST }, lib_1.AutoTestingResponseType.SUITE_LIST_RESPONSE),
13
+ updateSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.SUITE_UPDATE, ...params }, lib_1.AutoTestingResponseType.SUITE_UPDATE_RESPONSE),
14
+ deleteSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.SUITE_DELETE, ...params }, lib_1.AutoTestingResponseType.SUITE_DELETE_RESPONSE),
15
+ addCaseToSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.SUITE_CASE_ADD, ...params }, lib_1.AutoTestingResponseType.SUITE_CASE_ADD_RESPONSE),
16
+ removeCaseFromSuite: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.SUITE_CASE_REMOVE, ...params }, lib_1.AutoTestingResponseType.SUITE_CASE_REMOVE_RESPONSE),
17
17
  // ---- Test Cases ----
18
- createCase: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.CASE_CREATE, ...params }, autoTesting_1.AutoTestingResponseType.CASE_CREATE_RESPONSE),
19
- getCase: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.CASE_GET, ...params }, autoTesting_1.AutoTestingResponseType.CASE_GET_RESPONSE),
20
- listCases: async (_params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.CASE_LIST }, autoTesting_1.AutoTestingResponseType.CASE_LIST_RESPONSE),
21
- updateCase: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.CASE_UPDATE, ...params }, autoTesting_1.AutoTestingResponseType.CASE_UPDATE_RESPONSE),
22
- deleteCase: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.CASE_DELETE, ...params }, autoTesting_1.AutoTestingResponseType.CASE_DELETE_RESPONSE),
18
+ createCase: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.CASE_CREATE, ...params }, lib_1.AutoTestingResponseType.CASE_CREATE_RESPONSE),
19
+ getCase: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.CASE_GET, ...params }, lib_1.AutoTestingResponseType.CASE_GET_RESPONSE),
20
+ listCases: async (_params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.CASE_LIST }, lib_1.AutoTestingResponseType.CASE_LIST_RESPONSE),
21
+ updateCase: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.CASE_UPDATE, ...params }, lib_1.AutoTestingResponseType.CASE_UPDATE_RESPONSE),
22
+ deleteCase: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.CASE_DELETE, ...params }, lib_1.AutoTestingResponseType.CASE_DELETE_RESPONSE),
23
23
  // ---- Test Runs ----
24
- createRun: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.RUN_CREATE, ...params }, autoTesting_1.AutoTestingResponseType.RUN_CREATE_RESPONSE),
25
- getRun: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.RUN_GET, ...params }, autoTesting_1.AutoTestingResponseType.RUN_GET_RESPONSE),
26
- listRuns: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.RUN_LIST, ...(params || {}) }, autoTesting_1.AutoTestingResponseType.RUN_LIST_RESPONSE),
27
- updateRunStatus: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.RUN_UPDATE_STATUS, ...params }, autoTesting_1.AutoTestingResponseType.RUN_UPDATE_STATUS_RESPONSE),
28
- updateRunCaseStatus: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.RUN_CASE_UPDATE, ...params }, autoTesting_1.AutoTestingResponseType.RUN_CASE_UPDATE_RESPONSE),
29
- updateRunStepStatus: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: autoTesting_1.AutoTestingAction.RUN_STEP_UPDATE, ...params }, autoTesting_1.AutoTestingResponseType.RUN_STEP_UPDATE_RESPONSE),
24
+ createRun: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.RUN_CREATE, ...params }, lib_1.AutoTestingResponseType.RUN_CREATE_RESPONSE),
25
+ getRun: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.RUN_GET, ...params }, lib_1.AutoTestingResponseType.RUN_GET_RESPONSE),
26
+ listRuns: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.RUN_LIST, ...(params || {}) }, lib_1.AutoTestingResponseType.RUN_LIST_RESPONSE),
27
+ updateRunStatus: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.RUN_UPDATE_STATUS, ...params }, lib_1.AutoTestingResponseType.RUN_UPDATE_STATUS_RESPONSE),
28
+ updateRunCaseStatus: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.RUN_CASE_UPDATE, ...params }, lib_1.AutoTestingResponseType.RUN_CASE_UPDATE_RESPONSE),
29
+ updateRunStepStatus: async (params) => websocket_1.default.messageManager.sendAndWaitForResponse({ type: lib_1.AutoTestingAction.RUN_STEP_UPDATE, ...params }, lib_1.AutoTestingResponseType.RUN_STEP_UPDATE_RESPONSE),
30
30
  };
31
31
  exports.default = cbautoTesting;
@@ -1,3 +1,5 @@
1
+ import type { BackgroundAgentData, BackgroundAgentCompletion, BackgroundExternalEvent } from '@codebolt/types/sdk';
2
+ export type { BackgroundAgentData, BackgroundAgentCompletion, BackgroundExternalEvent };
1
3
  /**
2
4
  * Background Child Threads module for tracking and managing background agent threads.
3
5
  * This module provides APIs for tracking running background agents and their completion.
@@ -5,11 +7,11 @@
5
7
  declare const backgroundChildThreads: {
6
8
  /**
7
9
  * Adds a running background agent to tracking.
8
- * @param {string} threadId - The thread ID
9
- * @param {any} data - The agent data
10
- * @param {string} [groupId] - Optional group ID
10
+ * @param threadId - The thread ID
11
+ * @param data - The agent data
12
+ * @param groupId - Optional group ID
11
13
  */
12
- addRunningAgent: (threadId: string, data: any, groupId?: string) => void;
14
+ addRunningAgent: (threadId: string, data: BackgroundAgentData, groupId?: string) => void;
13
15
  /**
14
16
  * Gets the number of currently running background agents.
15
17
  * @returns {number} The count
@@ -17,32 +19,29 @@ declare const backgroundChildThreads: {
17
19
  getRunningAgentCount: () => number;
18
20
  /**
19
21
  * Checks if any background agent has completed.
20
- * @returns {any} The completion data if available, or null
22
+ * @returns The completion data if available, or null
21
23
  */
22
- checkForBackgroundAgentCompletion: () => any[] | null;
24
+ checkForBackgroundAgentCompletion: () => BackgroundAgentCompletion[] | null;
23
25
  /**
24
26
  * Waits for background agent completion.
25
- * @returns {Promise<any>} A promise that resolves with the completion data
27
+ * @returns A promise that resolves with the completion data
26
28
  */
27
- onBackgroundAgentCompletion: () => Promise<any>;
29
+ onBackgroundAgentCompletion: () => Promise<BackgroundAgentCompletion[] | null>;
28
30
  /**
29
31
  * Checks if any grouped background agent has completed.
30
- * @returns {any} The completion data if available, or null
32
+ * @returns The completion data if available, or null
31
33
  */
32
- checkForBackgroundGroupedAgentCompletion: () => any;
34
+ checkForBackgroundGroupedAgentCompletion: () => BackgroundAgentCompletion | null;
33
35
  /**
34
36
  * Waits for grouped background agent completion.
35
- * @returns {Promise<any>} A promise that resolves with the completion data
37
+ * @returns A promise that resolves with the completion data
36
38
  */
37
- onBackgroundGroupedAgentCompletion: () => Promise<any>;
39
+ onBackgroundGroupedAgentCompletion: () => Promise<BackgroundAgentCompletion | null>;
38
40
  /**
39
41
  * Waits for any external event (background agent completion, grouped agent completion, or agent event).
40
42
  * Returns the first event that occurs.
41
- * @returns {Promise<{type: string, data: any}>} A promise that resolves with the event type and data
43
+ * @returns A promise that resolves with the event type and data
42
44
  */
43
- waitForAnyExternalEvent: () => Promise<{
44
- type: string;
45
- data: any;
46
- }>;
45
+ waitForAnyExternalEvent: () => Promise<BackgroundExternalEvent>;
47
46
  };
48
47
  export default backgroundChildThreads;
@@ -10,25 +10,45 @@ const runningBackgroundAgents = new Map();
10
10
  const completedBackgroundAgents = new Map();
11
11
  const groupedAgentCompletionMap = new Map();
12
12
  const backgroundAgentGroups = new Map();
13
- // Helper to cleanup group membership
14
- const cleanupAgentGroup = (threadId) => {
13
+ // Track completed agents per group for grouped completion
14
+ const groupCompletedAgents = new Map();
15
+ // Helper to cleanup group membership and check for group completion
16
+ const cleanupAgentGroup = (threadId, completion) => {
15
17
  for (const [groupId, agents] of backgroundAgentGroups.entries()) {
16
18
  if (agents.has(threadId)) {
19
+ // Track this completion in the group
20
+ if (!groupCompletedAgents.has(groupId)) {
21
+ groupCompletedAgents.set(groupId, []);
22
+ }
23
+ groupCompletedAgents.get(groupId).push(completion);
17
24
  agents.delete(threadId);
25
+ // Check if all agents in the group have completed
18
26
  if (agents.size === 0) {
27
+ // All agents in this group are done - emit grouped completion
28
+ const groupCompletions = groupCompletedAgents.get(groupId) || [];
29
+ groupedAgentSubscription.emit('message', {
30
+ groupId,
31
+ threadId, // Last completed thread
32
+ completions: groupCompletions,
33
+ success: groupCompletions.every(c => c.success !== false)
34
+ });
35
+ // Cleanup
19
36
  backgroundAgentGroups.delete(groupId);
37
+ groupCompletedAgents.delete(groupId);
20
38
  }
21
39
  }
22
40
  }
23
41
  };
24
42
  // Handler for background agent completion messages
25
43
  const handleBackgroundAgentCompletion = (message) => {
44
+ if (!message.threadId)
45
+ return;
26
46
  // Add to completed queue for orchestrator to process
27
47
  completedBackgroundAgents.set(message.threadId, message);
28
48
  // Remove from running map since agent is now complete
29
49
  runningBackgroundAgents.delete(message.threadId);
30
- // Clean up any group associations
31
- cleanupAgentGroup(message.threadId);
50
+ // Clean up any group associations and check for group completion
51
+ cleanupAgentGroup(message.threadId, message);
32
52
  };
33
53
  // Subscribe to background agent completion - primary message type
34
54
  const backgroundAgentSubscription = websocket_1.default.messageManager.subscribe('startThreadResponse');
@@ -37,7 +57,7 @@ backgroundAgentSubscription.on('message', handleBackgroundAgentCompletion);
37
57
  const threadCompletedSubscription = websocket_1.default.messageManager.subscribe('ThreadCompleted');
38
58
  threadCompletedSubscription.on('message', (message) => {
39
59
  // Only handle if this thread was a background agent
40
- if (runningBackgroundAgents.has(message.threadId)) {
60
+ if (message.threadId && runningBackgroundAgents.has(message.threadId)) {
41
61
  handleBackgroundAgentCompletion(message);
42
62
  // Also emit on the backgroundAgentSubscription for waiters
43
63
  backgroundAgentSubscription.emit('message', message);
@@ -45,7 +65,9 @@ threadCompletedSubscription.on('message', (message) => {
45
65
  });
46
66
  const groupedAgentSubscription = websocket_1.default.messageManager.subscribe('backgroundGroupedAgentCompletion');
47
67
  groupedAgentSubscription.on('message', (message) => {
48
- groupedAgentCompletionMap.set(message.threadId, message);
68
+ if (message.threadId) {
69
+ groupedAgentCompletionMap.set(message.threadId, message);
70
+ }
49
71
  });
50
72
  /**
51
73
  * Background Child Threads module for tracking and managing background agent threads.
@@ -54,9 +76,9 @@ groupedAgentSubscription.on('message', (message) => {
54
76
  const backgroundChildThreads = {
55
77
  /**
56
78
  * Adds a running background agent to tracking.
57
- * @param {string} threadId - The thread ID
58
- * @param {any} data - The agent data
59
- * @param {string} [groupId] - Optional group ID
79
+ * @param threadId - The thread ID
80
+ * @param data - The agent data
81
+ * @param groupId - Optional group ID
60
82
  */
61
83
  addRunningAgent: (threadId, data, groupId) => {
62
84
  runningBackgroundAgents.set(threadId, data);
@@ -76,7 +98,7 @@ const backgroundChildThreads = {
76
98
  },
77
99
  /**
78
100
  * Checks if any background agent has completed.
79
- * @returns {any} The completion data if available, or null
101
+ * @returns The completion data if available, or null
80
102
  */
81
103
  checkForBackgroundAgentCompletion: () => {
82
104
  if (completedBackgroundAgents.size > 0) {
@@ -88,7 +110,7 @@ const backgroundChildThreads = {
88
110
  },
89
111
  /**
90
112
  * Waits for background agent completion.
91
- * @returns {Promise<any>} A promise that resolves with the completion data
113
+ * @returns A promise that resolves with the completion data
92
114
  */
93
115
  onBackgroundAgentCompletion: async () => {
94
116
  const completion = backgroundChildThreads.checkForBackgroundAgentCompletion();
@@ -103,12 +125,13 @@ const backgroundChildThreads = {
103
125
  },
104
126
  /**
105
127
  * Checks if any grouped background agent has completed.
106
- * @returns {any} The completion data if available, or null
128
+ * @returns The completion data if available, or null
107
129
  */
108
130
  checkForBackgroundGroupedAgentCompletion: () => {
109
131
  if (groupedAgentCompletionMap.size > 0) {
110
- const [key, value] = groupedAgentCompletionMap.entries().next().value || [];
111
- if (key) {
132
+ const entry = groupedAgentCompletionMap.entries().next().value;
133
+ if (entry) {
134
+ const [key, value] = entry;
112
135
  groupedAgentCompletionMap.delete(key);
113
136
  return value;
114
137
  }
@@ -117,7 +140,7 @@ const backgroundChildThreads = {
117
140
  },
118
141
  /**
119
142
  * Waits for grouped background agent completion.
120
- * @returns {Promise<any>} A promise that resolves with the completion data
143
+ * @returns A promise that resolves with the completion data
121
144
  */
122
145
  onBackgroundGroupedAgentCompletion: async () => {
123
146
  const completion = backgroundChildThreads.checkForBackgroundGroupedAgentCompletion();
@@ -133,7 +156,7 @@ const backgroundChildThreads = {
133
156
  /**
134
157
  * Waits for any external event (background agent completion, grouped agent completion, or agent event).
135
158
  * Returns the first event that occurs.
136
- * @returns {Promise<{type: string, data: any}>} A promise that resolves with the event type and data
159
+ * @returns A promise that resolves with the event type and data
137
160
  */
138
161
  waitForAnyExternalEvent: async () => {
139
162
  // First check if there are any already completed events
@@ -1,5 +1,6 @@
1
- import { GoToPageResponse, UrlResponse, GetMarkdownResponse, HtmlReceived, ExtractTextResponse, GetContentResponse, BrowserActionResponseData, BrowserScreenshotResponse, BrowserInfoResponse, BrowserSnapshotResponse } from '@codebolt/types/sdk';
1
+ import { GoToPageResponse, UrlResponse, GetMarkdownResponse, HtmlReceived, ExtractTextResponse, GetContentResponse, BrowserActionResponseData, BrowserScreenshotResponse, BrowserInfoResponse, BrowserSnapshotResponse, BrowserOperationType, BrowserOperationParams, BrowserOperationResponse } from '@codebolt/types/sdk';
2
2
  import type { BrowserInstanceOptions, BrowserOperationOptions, BrowserInstanceInfo, BrowserScreenshotOptions } from '../types/libFunctionTypes';
3
+ export type { BrowserOperationType, BrowserOperationParams, BrowserOperationResponse };
3
4
  /**
4
5
  * A module for interacting with a browser through WebSockets.
5
6
  */
@@ -148,12 +149,12 @@ declare const cbbrowser: {
148
149
  closeBrowserInstance: (instanceId: string) => Promise<boolean>;
149
150
  /**
150
151
  * Execute action on specific browser instance
151
- * @param {string} instanceId - The instance ID to execute on
152
- * @param {string} operation - The operation to execute
153
- * @param {any} params - Parameters for the operation
154
- * @returns {Promise<any>} The operation result
152
+ * @param instanceId - The instance ID to execute on
153
+ * @param operation - The operation to execute
154
+ * @param params - Parameters for the operation
155
+ * @returns The operation result
155
156
  */
156
- executeOnInstance: (instanceId: string, operation: string, params: any) => Promise<any>;
157
+ executeOnInstance: (instanceId: string, operation: BrowserOperationType, params: BrowserOperationParams) => Promise<BrowserOperationResponse>;
157
158
  };
158
159
  export default cbbrowser;
159
160
  /***
@@ -360,10 +360,10 @@ const cbbrowser = {
360
360
  },
361
361
  /**
362
362
  * Execute action on specific browser instance
363
- * @param {string} instanceId - The instance ID to execute on
364
- * @param {string} operation - The operation to execute
365
- * @param {any} params - Parameters for the operation
366
- * @returns {Promise<any>} The operation result
363
+ * @param instanceId - The instance ID to execute on
364
+ * @param operation - The operation to execute
365
+ * @param params - Parameters for the operation
366
+ * @returns The operation result
367
367
  */
368
368
  executeOnInstance: async (instanceId, operation, params) => {
369
369
  // This will be implemented with proper backend communication