@codebolt/agent 1.0.0
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.
- package/README.md +120 -0
- package/dist/agent.d.ts +86 -0
- package/dist/agent.js +324 -0
- package/dist/followupquestionbuilder.d.ts +75 -0
- package/dist/followupquestionbuilder.js +197 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +23 -0
- package/dist/llmoutputhandler.d.ts +102 -0
- package/dist/llmoutputhandler.js +452 -0
- package/dist/promptbuilder.d.ts +382 -0
- package/dist/promptbuilder.js +805 -0
- package/dist/systemprompt.d.ts +20 -0
- package/dist/systemprompt.js +48 -0
- package/dist/taskInstruction.d.ts +37 -0
- package/dist/taskInstruction.js +57 -0
- package/dist/types/InternalTypes.d.ts +499 -0
- package/dist/types/InternalTypes.js +30 -0
- package/dist/types/commonTypes.d.ts +369 -0
- package/dist/types/commonTypes.js +37 -0
- package/dist/types/libFunctionTypes.d.ts +695 -0
- package/dist/types/libFunctionTypes.js +11 -0
- package/dist/types/socketMessageTypes.d.ts +952 -0
- package/dist/types/socketMessageTypes.js +50 -0
- package/dist/usermessage.d.ts +70 -0
- package/dist/usermessage.js +123 -0
- package/package.json +49 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TypeScript interfaces for WebSocket message types
|
|
4
|
+
*
|
|
5
|
+
* This file contains all types related to WebSocket messages:
|
|
6
|
+
* - Incoming message types (from client to server)
|
|
7
|
+
* - Outgoing response types (from server to client)
|
|
8
|
+
* - WebSocket communication protocols
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.isSuccessResponse = isSuccessResponse;
|
|
12
|
+
exports.isFailureResponse = isFailureResponse;
|
|
13
|
+
exports.isErrorResponse = isErrorResponse;
|
|
14
|
+
exports.isBrowserResponse = isBrowserResponse;
|
|
15
|
+
exports.isGitResponse = isGitResponse;
|
|
16
|
+
exports.isFsServiceResponse = isFsServiceResponse;
|
|
17
|
+
// ================================
|
|
18
|
+
// Type Guards
|
|
19
|
+
// ================================
|
|
20
|
+
function isSuccessResponse(response) {
|
|
21
|
+
return 'success' in response && response.success === true;
|
|
22
|
+
}
|
|
23
|
+
function isFailureResponse(response) {
|
|
24
|
+
return 'success' in response && response.success === false;
|
|
25
|
+
}
|
|
26
|
+
function isErrorResponse(response) {
|
|
27
|
+
return response.type === 'error';
|
|
28
|
+
}
|
|
29
|
+
function isBrowserResponse(response) {
|
|
30
|
+
return response.type.includes('browser') || response.type.includes('screenshot') || response.type.includes('Content');
|
|
31
|
+
}
|
|
32
|
+
function isGitResponse(response) {
|
|
33
|
+
return response.type.startsWith('git');
|
|
34
|
+
}
|
|
35
|
+
function isFsServiceResponse(response) {
|
|
36
|
+
return response.type.includes('readFileResponse') ||
|
|
37
|
+
response.type.includes('writeToFileResponse') ||
|
|
38
|
+
response.type.includes('fileListResponse') ||
|
|
39
|
+
response.type.includes('listCodeDefinitionNamesResponse') ||
|
|
40
|
+
response.type.includes('searchFilesResponse') ||
|
|
41
|
+
response.type.includes('grepSearchResponse') ||
|
|
42
|
+
response.type.includes('fileSearchResponse') ||
|
|
43
|
+
response.type.includes('createFileResponse') ||
|
|
44
|
+
response.type.includes('createFolderResponse') ||
|
|
45
|
+
response.type.includes('updateFileResponse') ||
|
|
46
|
+
response.type.includes('deleteFileResponse') ||
|
|
47
|
+
response.type.includes('deleteFolderResponse') ||
|
|
48
|
+
response.type.includes('editFileAndApplyDiffResponse') ||
|
|
49
|
+
response.type.includes('fsExecuteToolResponse');
|
|
50
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { UserMessageContent } from "./types/libFunctionTypes";
|
|
2
|
+
import type { Agent } from "./types/commonTypes";
|
|
3
|
+
import type { Message } from "./types/InternalTypes";
|
|
4
|
+
/**
|
|
5
|
+
* Class that processes and manages user messages.
|
|
6
|
+
* Handles converting messages to prompts and extracting mentioned entities.
|
|
7
|
+
*/
|
|
8
|
+
declare class UserMessage {
|
|
9
|
+
/** The message content and metadata */
|
|
10
|
+
message: Message;
|
|
11
|
+
/** Whether to override the default prompt generation */
|
|
12
|
+
promptOverride: boolean;
|
|
13
|
+
/** Array of content blocks for the user message */
|
|
14
|
+
userMessages: UserMessageContent[];
|
|
15
|
+
/** List of MCP tools mentioned in the message */
|
|
16
|
+
mentionedMCPs: {
|
|
17
|
+
toolbox: string;
|
|
18
|
+
toolName: string;
|
|
19
|
+
}[];
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new UserMessage instance.
|
|
22
|
+
*
|
|
23
|
+
* @param message - The message content and metadata
|
|
24
|
+
* @param promptOverride - Whether to override default prompt generation
|
|
25
|
+
*/
|
|
26
|
+
constructor(message: Message, promptOverride?: boolean);
|
|
27
|
+
/**
|
|
28
|
+
* Gets files mentioned in the message.
|
|
29
|
+
* Currently a placeholder for implementation.
|
|
30
|
+
*/
|
|
31
|
+
getFiles(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Converts the user message to a prompt format.
|
|
34
|
+
*
|
|
35
|
+
* @param bAttachFiles - Whether to attach file contents
|
|
36
|
+
* @param bAttachImages - Whether to attach images
|
|
37
|
+
* @param bAttachEnvironment - Whether to attach environment details
|
|
38
|
+
* @returns Promise with an array of content blocks for the prompt
|
|
39
|
+
*/
|
|
40
|
+
toPrompt(bAttachFiles?: boolean, bAttachImages?: boolean, bAttachEnvironment?: boolean, supportRemix?: boolean): Promise<UserMessageContent[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets agents mentioned in the message.
|
|
43
|
+
*
|
|
44
|
+
* @returns Array of agent objects
|
|
45
|
+
*/
|
|
46
|
+
getMentionedAgents(): Agent[];
|
|
47
|
+
/**
|
|
48
|
+
* Gets MCP tools mentioned in the message.
|
|
49
|
+
*
|
|
50
|
+
* @returns Array of MCP tool names
|
|
51
|
+
*/
|
|
52
|
+
getMentionedMcps(): {
|
|
53
|
+
toolbox: string;
|
|
54
|
+
toolName: string;
|
|
55
|
+
}[];
|
|
56
|
+
/**
|
|
57
|
+
* Gets MCP tools in a format suitable for the LLM.
|
|
58
|
+
*
|
|
59
|
+
* @returns Promise with an array of MCP tools
|
|
60
|
+
*/
|
|
61
|
+
getMentionedMcpsTools(): Promise<any[] | undefined>;
|
|
62
|
+
/**
|
|
63
|
+
* Gets environment details for the current working directory.
|
|
64
|
+
*
|
|
65
|
+
* @param cwd - The current working directory path
|
|
66
|
+
* @returns Promise with a string containing environment details
|
|
67
|
+
*/
|
|
68
|
+
private getEnvironmentDetail;
|
|
69
|
+
}
|
|
70
|
+
export { UserMessage };
|
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
exports.UserMessage = void 0;
|
|
7
|
+
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
8
|
+
const { fs: cbfs, project, mcp } = codeboltjs_1.default;
|
|
9
|
+
// All interfaces moved to appropriate type files
|
|
10
|
+
/**
|
|
11
|
+
* Class that processes and manages user messages.
|
|
12
|
+
* Handles converting messages to prompts and extracting mentioned entities.
|
|
13
|
+
*/
|
|
14
|
+
class UserMessage {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new UserMessage instance.
|
|
17
|
+
*
|
|
18
|
+
* @param message - The message content and metadata
|
|
19
|
+
* @param promptOverride - Whether to override default prompt generation
|
|
20
|
+
*/
|
|
21
|
+
constructor(message, promptOverride = false) {
|
|
22
|
+
/**
|
|
23
|
+
* Gets environment details for the current working directory.
|
|
24
|
+
*
|
|
25
|
+
* @param cwd - The current working directory path
|
|
26
|
+
* @returns Promise with a string containing environment details
|
|
27
|
+
*/
|
|
28
|
+
this.getEnvironmentDetail = async (cwd) => {
|
|
29
|
+
let details = "";
|
|
30
|
+
const { success, result } = await cbfs.listFile(cwd, true);
|
|
31
|
+
details += `\n\n# Current Working Directory (${cwd}) Files\n${result}
|
|
32
|
+
? "\n(Note: Only top-level contents shown for Desktop by default. Use list_files to explore further if necessary.)"
|
|
33
|
+
: ""
|
|
34
|
+
}`;
|
|
35
|
+
return `<environment_details>\n${details.trim()}\n</environment_details>`;
|
|
36
|
+
};
|
|
37
|
+
this.message = message;
|
|
38
|
+
this.promptOverride = promptOverride;
|
|
39
|
+
this.userMessages = [];
|
|
40
|
+
this.mentionedMCPs = message.mentionedMCPs || [];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Gets files mentioned in the message.
|
|
44
|
+
* Currently a placeholder for implementation.
|
|
45
|
+
*/
|
|
46
|
+
getFiles() {
|
|
47
|
+
// Implementation to be added
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Converts the user message to a prompt format.
|
|
51
|
+
*
|
|
52
|
+
* @param bAttachFiles - Whether to attach file contents
|
|
53
|
+
* @param bAttachImages - Whether to attach images
|
|
54
|
+
* @param bAttachEnvironment - Whether to attach environment details
|
|
55
|
+
* @returns Promise with an array of content blocks for the prompt
|
|
56
|
+
*/
|
|
57
|
+
async toPrompt(bAttachFiles = true, bAttachImages = true, bAttachEnvironment = true, supportRemix = true) {
|
|
58
|
+
var _a;
|
|
59
|
+
if (bAttachFiles) {
|
|
60
|
+
if (this.promptOverride) {
|
|
61
|
+
// Use a rendering engine
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
let finalPrompt = `
|
|
65
|
+
The user has sent the following query:
|
|
66
|
+
<user_query> ${this.message.userMessage} </user_query>.
|
|
67
|
+
`;
|
|
68
|
+
if ((_a = this.message.mentionedFiles) === null || _a === void 0 ? void 0 : _a.length) {
|
|
69
|
+
finalPrompt += `The Attached files are:`;
|
|
70
|
+
for (const file of this.message.mentionedFiles) {
|
|
71
|
+
let filedata = await cbfs.readFile(file);
|
|
72
|
+
finalPrompt += `File Name: ${file}, File Path: ${file}, Filedata: ${filedata}`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
this.userMessages.push({ type: "text", text: finalPrompt });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (bAttachEnvironment) {
|
|
79
|
+
let { projectPath } = await project.getProjectPath();
|
|
80
|
+
if (projectPath) {
|
|
81
|
+
const environmentDetail = await this.getEnvironmentDetail(projectPath);
|
|
82
|
+
this.userMessages.push({ type: "text", text: environmentDetail });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (supportRemix) {
|
|
86
|
+
if (this.message.remixPrompt)
|
|
87
|
+
this.userMessages.push({ type: "text", text: this.message.remixPrompt });
|
|
88
|
+
}
|
|
89
|
+
return this.userMessages;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Gets agents mentioned in the message.
|
|
93
|
+
*
|
|
94
|
+
* @returns Array of agent objects
|
|
95
|
+
*/
|
|
96
|
+
getMentionedAgents() {
|
|
97
|
+
//TODO : get config in tool format if neede
|
|
98
|
+
return this.message.mentionedAgents || [];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets MCP tools mentioned in the message.
|
|
102
|
+
*
|
|
103
|
+
* @returns Array of MCP tool names
|
|
104
|
+
*/
|
|
105
|
+
getMentionedMcps() {
|
|
106
|
+
return this.message.mentionedMCPs || [];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Gets MCP tools in a format suitable for the LLM.
|
|
110
|
+
*
|
|
111
|
+
* @returns Promise with an array of MCP tools
|
|
112
|
+
*/
|
|
113
|
+
async getMentionedMcpsTools() {
|
|
114
|
+
if (this.mentionedMCPs.length > 0) {
|
|
115
|
+
const { data } = await mcp.getTools(this.mentionedMCPs);
|
|
116
|
+
return data;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.UserMessage = UserMessage;
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codebolt/agent",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CodeBolt Agent utilities for building and managing AI agents",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/**/*",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"clean": "rm -rf dist",
|
|
15
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ai",
|
|
21
|
+
"agent",
|
|
22
|
+
"llm",
|
|
23
|
+
"codebolt",
|
|
24
|
+
"typescript"
|
|
25
|
+
],
|
|
26
|
+
"author": "CodeBolt",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"type": "commonjs",
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@codebolt/codeboltjs": "^2.0.16",
|
|
34
|
+
"js-yaml": "^4.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/js-yaml": "^4.0.9",
|
|
38
|
+
"@types/node": "^20.14.2",
|
|
39
|
+
"@types/uri-templates": "^0.1.34",
|
|
40
|
+
"@types/ws": "^8.5.10",
|
|
41
|
+
"typescript": "^5.4.5"
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"default": "./dist/index.js"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|