Skip to content

Commit 1402cd4

Browse files
lib added for agent
1 parent 6375e67 commit 1402cd4

38 files changed

+5196
-748
lines changed

index.d.ts

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference types="node" />
21
import WebSocket from 'ws';
32
import { EventEmitter } from 'events';
43
/**
@@ -25,7 +24,7 @@ declare class Codebolt {
2524
updateFile: (filename: string, filePath: string, newContent: string) => Promise<import("@codebolt/types").UpdateFileResponse>;
2625
deleteFile: (filename: string, filePath: string) => Promise<import("@codebolt/types").DeleteFileResponse>;
2726
deleteFolder: (foldername: string, folderpath: string) => Promise<import("@codebolt/types").DeleteFolderResponse>;
28-
listFile: (folderPath: string, isRecursive?: boolean) => Promise<unknown>;
27+
listFile: (folderPath: string, isRecursive?: boolean) => Promise<any>;
2928
listCodeDefinitionNames: (path: string) => Promise<{
3029
success: boolean;
3130
result: any;
@@ -74,43 +73,44 @@ declare class Codebolt {
7473
};
7574
chat: {
7675
getChatHistory: () => Promise<import("@codebolt/types").ChatMessage[]>;
76+
setRequestHandler: (handler: (request: any, response: (data: any) => void) => Promise<void> | void) => void;
7777
onActionMessage: () => {
7878
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
79-
addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
80-
on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
81-
once<K_3>(eventName: string | symbol, listener: (...args: any[]) => void): any;
82-
removeListener<K_4>(eventName: string | symbol, listener: (...args: any[]) => void): any;
83-
off<K_5>(eventName: string | symbol, listener: (...args: any[]) => void): any;
84-
removeAllListeners(eventName?: string | symbol | undefined): any;
85-
setMaxListeners(n: number): any;
79+
addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
80+
on<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
81+
once<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
82+
removeListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
83+
off<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
84+
removeAllListeners(eventName?: string | symbol | undefined): /*elided*/ any;
85+
setMaxListeners(n: number): /*elided*/ any;
8686
getMaxListeners(): number;
87-
listeners<K_6>(eventName: string | symbol): Function[];
88-
rawListeners<K_7>(eventName: string | symbol): Function[];
89-
emit<K_8>(eventName: string | symbol, ...args: any[]): boolean;
90-
listenerCount<K_9>(eventName: string | symbol, listener?: Function | undefined): number;
91-
prependListener<K_10>(eventName: string | symbol, listener: (...args: any[]) => void): any;
92-
prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
87+
listeners<K>(eventName: string | symbol): Function[];
88+
rawListeners<K>(eventName: string | symbol): Function[];
89+
emit<K>(eventName: string | symbol, ...args: any[]): boolean;
90+
listenerCount<K>(eventName: string | symbol, listener?: Function | undefined): number;
91+
prependListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
92+
prependOnceListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
9393
eventNames(): (string | symbol)[];
94-
} | undefined;
94+
};
9595
sendMessage: (message: string, payload: any) => void;
9696
waitforReply: (message: string) => Promise<import("@codebolt/types").UserMessage>;
9797
processStarted: () => {
9898
event: {
9999
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
100-
addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
101-
on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
102-
once<K_3>(eventName: string | symbol, listener: (...args: any[]) => void): any;
103-
removeListener<K_4>(eventName: string | symbol, listener: (...args: any[]) => void): any;
104-
off<K_5>(eventName: string | symbol, listener: (...args: any[]) => void): any;
105-
removeAllListeners(eventName?: string | symbol | undefined): any;
106-
setMaxListeners(n: number): any;
100+
addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
101+
on<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
102+
once<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
103+
removeListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
104+
off<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
105+
removeAllListeners(eventName?: string | symbol | undefined): /*elided*/ any;
106+
setMaxListeners(n: number): /*elided*/ any;
107107
getMaxListeners(): number;
108-
listeners<K_6>(eventName: string | symbol): Function[];
109-
rawListeners<K_7>(eventName: string | symbol): Function[];
110-
emit<K_8>(eventName: string | symbol, ...args: any[]): boolean;
111-
listenerCount<K_9>(eventName: string | symbol, listener?: Function | undefined): number;
112-
prependListener<K_10>(eventName: string | symbol, listener: (...args: any[]) => void): any;
113-
prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
108+
listeners<K>(eventName: string | symbol): Function[];
109+
rawListeners<K>(eventName: string | symbol): Function[];
110+
emit<K>(eventName: string | symbol, ...args: any[]): boolean;
111+
listenerCount<K>(eventName: string | symbol, listener?: Function | undefined): number;
112+
prependListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
113+
prependOnceListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
114114
eventNames(): (string | symbol)[];
115115
};
116116
stopProcess: () => void;
@@ -124,29 +124,29 @@ declare class Codebolt {
124124
terminal: {
125125
eventEmitter: {
126126
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
127-
addListener<K_1>(eventName: string | symbol, listener: (...args: any[]) => void): any;
128-
on<K_2>(eventName: string | symbol, listener: (...args: any[]) => void): any;
129-
once<K_3>(eventName: string | symbol, listener: (...args: any[]) => void): any;
130-
removeListener<K_4>(eventName: string | symbol, listener: (...args: any[]) => void): any;
131-
off<K_5>(eventName: string | symbol, listener: (...args: any[]) => void): any;
132-
removeAllListeners(eventName?: string | symbol | undefined): any;
133-
setMaxListeners(n: number): any;
127+
addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
128+
on<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
129+
once<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
130+
removeListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
131+
off<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
132+
removeAllListeners(eventName?: string | symbol | undefined): /*elided*/ any;
133+
setMaxListeners(n: number): /*elided*/ any;
134134
getMaxListeners(): number;
135-
listeners<K_6>(eventName: string | symbol): Function[];
136-
rawListeners<K_7>(eventName: string | symbol): Function[];
137-
emit<K_8>(eventName: string | symbol, ...args: any[]): boolean;
138-
listenerCount<K_9>(eventName: string | symbol, listener?: Function | undefined): number;
139-
prependListener<K_10>(eventName: string | symbol, listener: (...args: any[]) => void): any;
140-
prependOnceListener<K_11>(eventName: string | symbol, listener: (...args: any[]) => void): any;
135+
listeners<K>(eventName: string | symbol): Function[];
136+
rawListeners<K>(eventName: string | symbol): Function[];
137+
emit<K>(eventName: string | symbol, ...args: any[]): boolean;
138+
listenerCount<K>(eventName: string | symbol, listener?: Function | undefined): number;
139+
prependListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
140+
prependOnceListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): /*elided*/ any;
141141
eventNames(): (string | symbol)[];
142142
};
143143
executeCommand: (command: string, returnEmptyStringOnSuccess?: boolean) => Promise<unknown>;
144144
executeCommandRunUntilError: (command: string, executeInMain?: boolean) => Promise<import("@codebolt/types").CommandError>;
145145
sendManualInterrupt(): Promise<import("@codebolt/types").TerminalInterruptResponse>;
146-
executeCommandWithStream(command: string, executeInMain?: boolean): EventEmitter<[never]>;
146+
executeCommandWithStream(command: string, executeInMain?: boolean): EventEmitter;
147147
};
148148
codeutils: {
149-
getJsTree: (filePath?: string | undefined) => Promise<unknown>;
149+
getJsTree: (filePath?: string) => Promise<unknown>;
150150
getAllFilesAsMarkDown: () => Promise<string>;
151151
performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<import("@codebolt/types").MatchProblemResponse>;
152152
getMatcherList: () => Promise<import("@codebolt/types").GetMatcherListTreeResponse>;
@@ -237,15 +237,17 @@ declare class Codebolt {
237237
}[]>;
238238
};
239239
MCP: {
240-
executeTool: (toolName: string, params: any, mcpServer?: string | undefined) => Promise<any>;
240+
executeTool: (toolName: string, params: any, mcpServer?: string) => Promise<any>;
241241
getMcpTools: (tools: string[]) => Promise<any>;
242242
getAllMCPTools: (mpcName: string) => Promise<any>;
243243
getMCPTool: (name: string) => Promise<any>;
244244
getEnabledMCPS: () => Promise<any>;
245245
};
246246
AGENT: {
247-
getAgent: (task: string) => Promise<any>;
247+
findAgent: (task: string, maxResult?: number, agents?: never[], agentLocaltion?: import("./modules/agent").AgentLocation) => Promise<any>;
248248
startAgent: (agentId: string, task: string) => Promise<any>;
249+
getAgentsList: (type?: import("./modules/agent").Agents) => Promise<any>;
250+
getAgentsDetail: (agentList?: never[]) => Promise<any>;
249251
};
250252
}
251253
declare const _default: Codebolt;

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Codebolt {
6464
this.chatSummary = history_1.chatSummary;
6565
this.MCP = mcp_1.default;
6666
this.AGENT = agent_1.default;
67+
websocket_1.default.initializeWebSocket();
6768
this.websocket = websocket_1.default.getWebsocket;
6869
}
6970
/**
@@ -91,4 +92,3 @@ class Codebolt {
9192
}
9293
}
9394
exports.default = new Codebolt();
94-
// module.exports = new Codebolt();

modules/agent.d.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1+
export declare enum AgentLocation {
2+
ALL = "all",
3+
LOCAL_ONLY = "local_only",
4+
REMOTE_ONLY = "remote_only"
5+
}
6+
export declare enum Agents {
7+
LOCAL = "local",
8+
ALL = "all",
9+
DOWNLOADED = "downloaded"
10+
}
111
declare const codeboltAgent: {
212
/**
313
* Retrieves an agent based on the specified task.
414
* @param {string} task - The task for which an agent is needed.
515
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
616
*/
7-
getAgent: (task: string) => Promise<any>;
17+
findAgent: (task: string, maxResult?: number, agents?: never[], agentLocaltion?: AgentLocation) => Promise<any>;
818
/**
919
* Starts an agent for the specified task.
1020
* @param {string} task - The task for which the agent should be started.
1121
* @returns {Promise<void>} A promise that resolves when the agent has been successfully started.
1222
*/
1323
startAgent: (agentId: string, task: string) => Promise<any>;
24+
/**
25+
* Lists all available agents.
26+
* @returns {Promise<any>} A promise that resolves with the list of agents.
27+
*/
28+
getAgentsList: (type?: Agents) => Promise<any>;
29+
/**
30+
* Lists all available agents.
31+
* @returns {Promise<any>} A promise that resolves with the list of agents.
32+
*/
33+
getAgentsDetail: (agentList?: never[]) => Promise<any>;
1434
};
1535
export default codeboltAgent;

modules/agent.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.Agents = exports.AgentLocation = void 0;
67
const websocket_1 = __importDefault(require("./websocket"));
8+
var AgentLocation;
9+
(function (AgentLocation) {
10+
AgentLocation["ALL"] = "all";
11+
AgentLocation["LOCAL_ONLY"] = "local_only";
12+
AgentLocation["REMOTE_ONLY"] = "remote_only";
13+
})(AgentLocation || (exports.AgentLocation = AgentLocation = {}));
14+
var Agents;
15+
(function (Agents) {
16+
Agents["LOCAL"] = "local";
17+
Agents["ALL"] = "all";
18+
Agents["DOWNLOADED"] = "downloaded";
19+
})(Agents || (exports.Agents = Agents = {}));
720
const codeboltAgent = {
821
/**
922
* Retrieves an agent based on the specified task.
1023
* @param {string} task - The task for which an agent is needed.
1124
* @returns {Promise<AgentResponse>} A promise that resolves with the agent details.
1225
*/
13-
getAgent: (task) => {
26+
findAgent: (task, maxResult = 1, agents = [], agentLocaltion = AgentLocation.ALL) => {
1427
return new Promise((resolve, reject) => {
1528
websocket_1.default.getWebsocket.send(JSON.stringify({
1629
"type": "agentEvent",
1730
"action": "getAgentByTask",
18-
"task": task
31+
"task": task,
32+
"agents": agents,
33+
"maxResult": maxResult,
34+
"location": agentLocaltion
1935
}));
2036
websocket_1.default.getWebsocket.on('message', (data) => {
2137
const response = JSON.parse(data);
@@ -45,6 +61,44 @@ const codeboltAgent = {
4561
}
4662
});
4763
});
64+
},
65+
/**
66+
* Lists all available agents.
67+
* @returns {Promise<any>} A promise that resolves with the list of agents.
68+
*/
69+
getAgentsList: (type = Agents.DOWNLOADED) => {
70+
return new Promise((resolve, reject) => {
71+
websocket_1.default.getWebsocket.send(JSON.stringify({
72+
"type": "agentEvent",
73+
"action": "listAgents",
74+
"agentType": type,
75+
}));
76+
websocket_1.default.getWebsocket.on('message', (data) => {
77+
const response = JSON.parse(data);
78+
if (response.type === "listAgentsResponse") {
79+
resolve(response); // Resolve the Promise with the list of agents
80+
}
81+
});
82+
});
83+
},
84+
/**
85+
* Lists all available agents.
86+
* @returns {Promise<any>} A promise that resolves with the list of agents.
87+
*/
88+
getAgentsDetail: (agentList = []) => {
89+
return new Promise((resolve, reject) => {
90+
websocket_1.default.getWebsocket.send(JSON.stringify({
91+
"type": "agentEvent",
92+
"action": "agentsDetail",
93+
"agentList": agentList
94+
}));
95+
websocket_1.default.getWebsocket.on('message', (data) => {
96+
const response = JSON.parse(data);
97+
if (response.type === "listAgentsResponse") {
98+
resolve(response); // Resolve the Promise with the list of agents
99+
}
100+
});
101+
});
48102
}
49103
};
50104
exports.default = codeboltAgent;

modules/agentlib/agent.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { SystemPrompt } from "./systemprompt";
2+
import { TaskInstruction } from "./taskInstruction";
3+
declare class Agent {
4+
private tools;
5+
private subAgents;
6+
private apiConversationHistory;
7+
private maxRun;
8+
private systemPrompt;
9+
private userMessage;
10+
constructor(tools: any | undefined, systemPrompt: SystemPrompt, maxRun?: number, subAgents?: Agent[]);
11+
run(task: TaskInstruction, successCondition?: () => boolean): Promise<{
12+
success: boolean;
13+
error: string | null;
14+
}>;
15+
private attemptLlmRequest;
16+
private executeTool;
17+
private getToolDetail;
18+
private getToolResult;
19+
private attemptApiRequest;
20+
}
21+
export { Agent };

0 commit comments

Comments
 (0)