Skip to content

Commit ff6172e

Browse files
get agent and start agent added
1 parent 27c1d7a commit ff6172e

File tree

8 files changed

+128
-10
lines changed

8 files changed

+128
-10
lines changed

index.d.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ declare class Codebolt {
1919
waitForConnection(): Promise<void>;
2020
websocket: WebSocket | null;
2121
fs: {
22-
createFile: (fileName: string, source: string, filePath: string) => Promise<import("@codebolt/types").CreateFileResponse>; /**
23-
* @method waitForConnection
24-
* @description Waits for the WebSocket connection to open.
25-
* @returns {Promise<void>} A promise that resolves when the WebSocket connection is open.
26-
*/
22+
createFile: (fileName: string, source: string, filePath: string) => Promise<import("@codebolt/types").CreateFileResponse>;
2723
createFolder: (folderName: string, folderPath: string) => Promise<import("@codebolt/types").CreateFolderResponse>;
2824
readFile: (filePath: string) => Promise<import("@codebolt/types").ReadFileResponse>;
2925
updateFile: (filename: string, filePath: string, newContent: string) => Promise<import("@codebolt/types").UpdateFileResponse>;
@@ -193,10 +189,6 @@ declare class Codebolt {
193189
project: {
194190
getProjectSettings: (output: any) => void;
195191
getProjectPath: () => Promise<import("@codebolt/types").GetProjectPathResponse>;
196-
/**
197-
* @constructor
198-
* @description Initializes the websocket connection.
199-
*/
200192
getRepoMap: (message: any) => Promise<import("@codebolt/types").GetProjectPathResponse>;
201193
runProject: () => void;
202194
getEditorFileStatus: () => Promise<unknown>;
@@ -249,6 +241,10 @@ declare class Codebolt {
249241
getMCPTool: (name: string) => Promise<any>;
250242
getEnabledMCPS: () => Promise<any>;
251243
};
244+
AGENT: {
245+
getAgent: (task: string) => Promise<any>;
246+
startAgent: (task: string) => Promise<any>;
247+
};
252248
}
253249
declare const _default: Codebolt;
254250
export default _default;

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const tokenizer_1 = __importDefault(require("./modules/tokenizer"));
2828
const ws_1 = __importDefault(require("ws"));
2929
const history_1 = require("./modules/history");
3030
const mcp_1 = __importDefault(require("./modules/mcp"));
31+
const agent_1 = __importDefault(require("./modules/agent"));
3132
/**
3233
* @class Codebolt
3334
* @description This class provides a unified interface to interact with various modules.
@@ -62,6 +63,7 @@ class Codebolt {
6263
this.tokenizer = tokenizer_1.default;
6364
this.chatSummary = history_1.chatSummary;
6465
this.MCP = mcp_1.default;
66+
this.AGENT = agent_1.default;
6567
this.websocket = websocket_1.default.getWebsocket;
6668
}
6769
/**

modules/agent.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
declare const codeboltAgent: {
2+
/**
3+
* Retrieves an agent based on the specified task.
4+
* @param {string} task - The task for which an agent is needed.
5+
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
6+
*/
7+
getAgent: (task: string) => Promise<any>;
8+
/**
9+
* Starts an agent for the specified task.
10+
* @param {string} task - The task for which the agent should be started.
11+
* @returns {Promise<void>} A promise that resolves when the agent has been successfully started.
12+
*/
13+
startAgent: (task: string) => Promise<any>;
14+
};
15+
export default codeboltAgent;

modules/agent.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codebolt/codeboltjs",
3-
"version": "1.1.81",
3+
"version": "1.1.82",
44
"description": "",
55
"keywords": [],
66
"author": "",

src/.DS_Store

0 Bytes
Binary file not shown.

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import WebSocket from 'ws';
2424
import { EventEmitter } from 'events';
2525
import {chatSummary} from './modules/history'
2626
import codeboltMCP from './modules/mcp';
27+
import cbagent from './modules/agent';
28+
2729

2830

2931
/**
@@ -93,6 +95,7 @@ class Codebolt { // Extend EventEmitter
9395
tokenizer = tokenizer;
9496
chatSummary=chatSummary;
9597
MCP = codeboltMCP;
98+
AGENT = cbagent;
9699
}
97100

98101
export default new Codebolt();

src/modules/agent.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { GetAgentStateResponse } from '@codebolt/types';
2+
import cbws from './websocket';
3+
4+
const codeboltAgent = {
5+
/**
6+
* Retrieves an agent based on the specified task.
7+
* @param {string} task - The task for which an agent is needed.
8+
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
9+
*/
10+
getAgent: (task: string): Promise<any> => {
11+
return new Promise((resolve, reject) => {
12+
cbws.getWebsocket.send(JSON.stringify({
13+
"type": "agentEvent",
14+
"action": "getAgentByTask",
15+
"task": task
16+
}));
17+
cbws.getWebsocket.on('message', (data: string) => {
18+
const response = JSON.parse(data);
19+
if (response.type === "getAgentByTaskResponse") {
20+
resolve(response); // Resolve the Promise with the agent details
21+
}
22+
});
23+
});
24+
},
25+
26+
/**
27+
* Starts an agent for the specified task.
28+
* @param {string} task - The task for which the agent should be started.
29+
* @returns {Promise<void>} A promise that resolves when the agent has been successfully started.
30+
*/
31+
startAgent: (task: string): Promise<any> => {
32+
return new Promise((resolve, reject) => {
33+
cbws.getWebsocket.send(JSON.stringify({
34+
"type": "agentEvent",
35+
"action": "startAgent",
36+
"task": task
37+
}));
38+
cbws.getWebsocket.on('message', (data: string) => {
39+
const response = JSON.parse(data);
40+
if (response.type === "startAgentResponse" && response.task === task) {
41+
resolve(response); // Resolve the Promise when the agent has been successfully started
42+
}
43+
});
44+
});
45+
}
46+
}
47+
48+
49+
export default codeboltAgent;
50+
51+
52+
53+

0 commit comments

Comments
 (0)