|
| 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 codeboltAgent = { |
| 8 | + /** |
| 9 | + * Retrieves an agent based on the specified task. |
| 10 | + * @param {string} task - The task for which an agent is needed. |
| 11 | + * @returns {Promise<AgentResponse>} A promise that resolves with the agent details. |
| 12 | + */ |
| 13 | + getAgent: (task) => { |
| 14 | + return new Promise((resolve, reject) => { |
| 15 | + websocket_1.default.getWebsocket.send(JSON.stringify({ |
| 16 | + "type": "agentEvent", |
| 17 | + "action": "getAgentByTask", |
| 18 | + "task": task |
| 19 | + })); |
| 20 | + websocket_1.default.getWebsocket.on('message', (data) => { |
| 21 | + const response = JSON.parse(data); |
| 22 | + if (response.type === "getAgentByTaskResponse") { |
| 23 | + resolve(response); // Resolve the Promise with the agent details |
| 24 | + } |
| 25 | + }); |
| 26 | + }); |
| 27 | + }, |
| 28 | + /** |
| 29 | + * Starts an agent for the specified task. |
| 30 | + * @param {string} task - The task for which the agent should be started. |
| 31 | + * @returns {Promise<void>} A promise that resolves when the agent has been successfully started. |
| 32 | + */ |
| 33 | + startAgent: (task) => { |
| 34 | + return new Promise((resolve, reject) => { |
| 35 | + websocket_1.default.getWebsocket.send(JSON.stringify({ |
| 36 | + "type": "agentEvent", |
| 37 | + "action": "startAgent", |
| 38 | + "task": task |
| 39 | + })); |
| 40 | + websocket_1.default.getWebsocket.on('message', (data) => { |
| 41 | + const response = JSON.parse(data); |
| 42 | + if (response.type === "startAgentResponse" && response.task === task) { |
| 43 | + resolve(response); // Resolve the Promise when the agent has been successfully started |
| 44 | + } |
| 45 | + }); |
| 46 | + }); |
| 47 | + } |
| 48 | +}; |
| 49 | +exports.default = codeboltAgent; |
0 commit comments