Skip to content

Commit 90a523b

Browse files
committed
2 parents 3e84b87 + e51a8c2 commit 90a523b

File tree

5 files changed

+106
-58
lines changed

5 files changed

+106
-58
lines changed

src/agentlib/agent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ class Agent {
8989
async run(task: TaskInstruction, successCondition: () => boolean = () => true): Promise<{ success: boolean; error: string | null, message: string | null }> {
9090

9191

92-
let mentaionedMCPSTool: any[] = await task.userMessage.getMentionedMcpsTools();
92+
let mentaionedMCPSTool: any[]|undefined = await task.userMessage.getMentionedMcpsTools();
9393

9494
this.tools = [
9595
...this.tools,
96-
...mentaionedMCPSTool,
96+
...(mentaionedMCPSTool || []),
9797

9898
]
9999
let mentionedAgents = await task.userMessage.getMentionedAgents();
@@ -355,7 +355,7 @@ class Agent {
355355
console.log("Toolbox name: ", toolboxName, "Actual tool name: ", actualToolName);
356356
const {data} = await tools.executeTool(toolboxName, actualToolName, toolInput);
357357
console.log("Tool result: ", data);
358-
return data;
358+
return [false, data];
359359
}
360360

361361
/**
@@ -366,7 +366,7 @@ class Agent {
366366
* @returns Promise with tuple [userRejected, result]
367367
*/
368368
private async startSubAgent(agentName: string, params: any): Promise<[boolean, any]> {
369-
return codeboltAgent.startAgent(agentName, params.task);
369+
return [false, await codeboltAgent.startAgent(agentName, params.task)];
370370
}
371371

372372
/**

src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {chatSummary} from './modules/history'
2525
import codeboltTools from './modules/mcp';
2626
import cbagent from './modules/agent';
2727
import cbutils from './modules/utils';
28-
import type { LLMResponse } from './types/cliWebSocketInterfaces';
28+
import type { ChatMessageFromUser, LLMResponse, UserMessage } from './types/cliWebSocketInterfaces';
29+
import { userInfo } from 'os';
2930

3031
/**
3132
* Represents a message in the conversation with roles and content.
@@ -180,14 +181,14 @@ class Codebolt {
180181
* @param {Function} handler - The handler function to call when a message is received.
181182
* @returns {void}
182183
*/
183-
onMessage(handler: (userMessage: any) => void | Promise<void> | any | Promise<any>) {
184+
onMessage(handler: (userMessage: ChatMessageFromUser) => void | Promise<void> | any | Promise<any>) {
184185
// Wait for the WebSocket to be ready before setting up the handler
185186
this.waitForReady().then(() => {
186-
const handleUserMessage = async (response: any) => {
187+
const handleUserMessage = async (response: UserMessage) => {
187188
console.log("Message received By Agent Library Starting Custom Agent Handler Logic");
188189
if (response.type === "messageResponse") {
189190
try {
190-
const result = await handler(response);
191+
const result = await handler(response.message);
191192
// Send processStoped with optional message
192193
const message: any = {
193194
"type": "processStoped"

src/modules/llm.ts

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,18 @@ const cbllm = {
2525
* - stream: Whether to stream the response
2626
* @returns A promise that resolves with the LLM's response
2727
*/
28-
inference: async (message: {
29-
/** Array of messages in the conversation */
30-
messages: Message[];
31-
/** Available tools for the model to use */
32-
tools?: Tool[];
33-
/** How the model should use tools */
34-
tool_choice?: 'auto' | 'none' | 'required' | { type: 'function'; function: { name: string } };
35-
/** The LLM role to determine which model to use */
36-
llmrole: string;
37-
/** Maximum number of tokens to generate */
38-
max_tokens?: number;
39-
/** Temperature for response generation */
40-
temperature?: number;
41-
/** Whether to stream the response */
42-
stream?: boolean;
43-
}): Promise<LLMResponse> => {
28+
inference: async (message: string, llmrole: string): Promise<LLMResponse> => {
4429
return cbws.messageManager.sendAndWaitForResponse(
4530
{
4631
"type": "inference",
4732
"message": {
48-
messages: message.messages,
49-
tools: message.tools,
50-
tool_choice: message.tool_choice,
51-
llmrole: message.llmrole,
52-
full:true
33+
prompt: message,
34+
llmrole
5335
},
5436
},
5537
"llmResponse"
5638
);
57-
},
39+
}
5840

5941
/**
6042
* Legacy method for backward compatibility - converts simple string prompt to message format.
@@ -64,19 +46,19 @@ const cbllm = {
6446
* @param {string} llmrole - The role of the LLM to determine which model to use.
6547
* @returns {Promise<LLMResponse>} A promise that resolves with the LLM's response.
6648
*/
67-
legacyInference: async (message: string, llmrole: string): Promise<LLMResponse> => {
68-
const messages: Message[] = [
69-
{
70-
role: 'user',
71-
content: message
72-
}
73-
];
49+
// legacyInference: async (message: string, llmrole: string): Promise<LLMResponse> => {
50+
// const messages: Message[] = [
51+
// {
52+
// role: 'user',
53+
// content: message
54+
// }
55+
// ];
7456

75-
return cbllm.inference({
76-
messages,
77-
llmrole
78-
});
79-
}
57+
// return cbllm.inference({
58+
// messages,
59+
60+
// }, llmrole);
61+
// }
8062
};
8163

8264
export default cbllm;

src/modules/mcp.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const codeboltMCP = {
2121
*
2222
* @returns Promise with the enabled toolboxes data
2323
*/
24-
getEnabledToolBoxes: (): Promise<GetEnabledToolBoxesResponse> => {
24+
getEnabledMCPServers: (): Promise<GetEnabledToolBoxesResponse> => {
2525
return cbws.messageManager.sendAndWaitForResponse(
2626
{
2727
"type": "codebolttools",
@@ -36,7 +36,7 @@ const codeboltMCP = {
3636
*
3737
* @returns Promise with the local toolboxes data
3838
*/
39-
getLocalToolBoxes: (): Promise<GetLocalToolBoxesResponse> => {
39+
getLocalMCPServers: (): Promise<GetLocalToolBoxesResponse> => {
4040
return cbws.messageManager.sendAndWaitForResponse(
4141
{
4242
"type": "codebolttools",
@@ -52,7 +52,7 @@ const codeboltMCP = {
5252
* @param userMessage - The user message to extract mentions from
5353
* @returns Promise with the mentioned toolboxes
5454
*/
55-
getMentionedToolBoxes: (userMessage: UserMessage): Promise<GetAvailableToolBoxesResponse> => {
55+
getMentionedMCPServers: (userMessage: UserMessage): Promise<GetAvailableToolBoxesResponse> => {
5656
return cbws.messageManager.sendAndWaitForResponse(
5757
{
5858
"type": "codebolttools",
@@ -68,7 +68,7 @@ const codeboltMCP = {
6868
* @param query - The search query string
6969
* @returns Promise with matching toolboxes data
7070
*/
71-
searchAvailableToolBoxes: (query: string): Promise<SearchAvailableToolBoxesResponse> => {
71+
searchAvailableMCPServers: (query: string): Promise<SearchAvailableToolBoxesResponse> => {
7272
return cbws.messageManager.sendAndWaitForResponse(
7373
{
7474
"type": "codebolttools",
@@ -85,7 +85,7 @@ const codeboltMCP = {
8585
* @param toolBoxes - Array of toolbox names to list tools from
8686
* @returns Promise with tools from the specified toolboxes
8787
*/
88-
listToolsFromToolBoxes: (toolBoxes: string[]): Promise<ListToolsFromToolBoxesResponse> => {
88+
listMcpFromServers: (toolBoxes: string[]): Promise<ListToolsFromToolBoxesResponse> => {
8989
return cbws.messageManager.sendAndWaitForResponse(
9090
{
9191
"type": "codebolttools",
@@ -103,7 +103,7 @@ const codeboltMCP = {
103103
* @param config - Configuration object for the toolbox
104104
* @returns Promise with the configuration result
105105
*/
106-
configureToolBox: (name: string, config: any): Promise<ConfigureToolBoxResponse> => {
106+
configureMCPServer: (name: string, config: any): Promise<ConfigureToolBoxResponse> => {
107107
return cbws.messageManager.sendAndWaitForResponse(
108108
{
109109
"type": "codebolttools",

src/types/cliWebSocketInterfaces.ts

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,83 @@ export interface ChatMessage extends BaseWebSocketResponse {
335335
metadata?: Record<string, any>;
336336
}
337337

338-
export interface UserMessage extends BaseWebSocketResponse {
339-
id: string;
340-
content: string;
341-
sender: 'user';
338+
export interface UserMessage {
339+
type: "messageResponse";
340+
message: {
341+
type: "messageResponse";
342+
userMessage: string;
343+
currentFile: string;
344+
selectedAgent: {
345+
id: string;
346+
name: string;
347+
lastMessage: Record<string, any>;
348+
};
349+
mentionedFiles: string[];
350+
mentionedFullPaths: string[];
351+
mentionedFolders: string[];
352+
mentionedMultiFile: string[];
353+
mentionedMCPs: string[];
354+
uploadedImages: string[];
355+
actions: any[];
356+
mentionedAgents: any[];
357+
mentionedDocs: any[];
358+
links: any[];
359+
universalAgentLastMessage: string;
360+
selection: any | null;
361+
controlFiles: any[];
362+
feedbackMessage: string;
363+
terminalMessage: string;
364+
messageId: string;
365+
threadId: string;
366+
templateType: string;
367+
processId: string;
368+
shadowGitHash: string;
369+
};
370+
sender: {
371+
senderType: string;
372+
senderInfo: Record<string, any>;
373+
};
374+
templateType: string;
375+
data: {
376+
text: string;
377+
[key: string]: any;
378+
};
379+
messageId: string;
342380
timestamp: string;
343-
type: string;
344-
text?: string;
345-
images?: any[];
346-
messageId?: string;
347-
threadId?: string;
348381
}
349382

383+
384+
export interface ChatMessageFromUser {
385+
type: "messageResponse";
386+
userMessage: string;
387+
currentFile: string;
388+
selectedAgent: {
389+
id: string;
390+
name: string;
391+
lastMessage: Record<string, any>;
392+
};
393+
mentionedFiles: string[];
394+
mentionedFullPaths: string[];
395+
mentionedFolders: string[];
396+
mentionedMultiFile: string[];
397+
mentionedMCPs: string[];
398+
uploadedImages: string[];
399+
actions: any[];
400+
mentionedAgents: any[];
401+
mentionedDocs: any[];
402+
links: any[];
403+
universalAgentLastMessage: string;
404+
selection: any | null;
405+
controlFiles: any[];
406+
feedbackMessage: string;
407+
terminalMessage: string;
408+
messageId: string;
409+
threadId: string;
410+
templateType: string;
411+
processId: string;
412+
shadowGitHash: string;
413+
}
414+
350415
// ================================
351416
// LLM Types (for llm.ts)
352417
// ================================
@@ -418,7 +483,7 @@ export interface getMatchDetail extends BaseWebSocketResponse {
418483

419484
export interface GetProjectPathResponse extends BaseWebSocketResponse {
420485
type: 'getProjectPathResponse';
421-
path?: string;
486+
projectPath?: string;
422487
projectName?: string;
423488
}
424489

0 commit comments

Comments
 (0)