@codebolt/codeboltjs 1.1.88 → 1.1.90
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/.github/workflows/publish-to-npm.yml +1 -1
- package/index.d.ts +6 -3
- package/index.js +1 -1
- package/modules/agent.d.ts +26 -1
- package/modules/agent.js +65 -4
- package/modules/agentlib/agent.d.ts +23 -0
- package/modules/agentlib/agent.js +175 -0
- package/modules/agentlib/systemprompt.d.ts +20 -0
- package/modules/agentlib/systemprompt.js +48 -0
- package/modules/agentlib/taskInstruction.d.ts +22 -0
- package/modules/agentlib/taskInstruction.js +37 -0
- package/modules/agentlib/usermessage.d.ts +22 -0
- package/modules/agentlib/usermessage.js +70 -0
- package/modules/chat.d.ts +11 -1
- package/modules/chat.js +52 -12
- package/modules/fs.d.ts +1 -1
- package/modules/mcp.js +0 -15
- package/modules/toolBox.d.ts +262 -0
- package/modules/toolBox.js +720 -0
- package/modules/websocket.d.ts +1 -1
- package/modules/websocket.js +13 -11
- package/package.json +28 -4
- package/src/index.ts +6 -2
- package/src/modules/agent.ts +70 -4
- package/src/modules/agentlib/agent.ts +226 -0
- package/src/modules/agentlib/package-lock.json +282 -0
- package/src/modules/agentlib/package.json +6 -0
- package/src/modules/agentlib/systemprompt.ts +55 -0
- package/src/modules/agentlib/taskInstruction.ts +66 -0
- package/src/modules/agentlib/usermessage.ts +97 -0
- package/src/modules/chat.ts +56 -15
- package/src/modules/fs.ts +1 -1
- package/src/modules/mcp.ts +5 -15
- package/src/modules/toolBox.ts +1164 -0
- package/src/modules/websocket.ts +20 -13
- package/src/utils.ts +5 -0
- package/utils.d.ts +5 -0
- package/utils.js +13 -0
package/modules/chat.js
CHANGED
|
@@ -33,25 +33,65 @@ const cbchat = {
|
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
},
|
|
36
|
+
/**
|
|
37
|
+
* Sets a global request handler for all incoming messages
|
|
38
|
+
* @param handler The async handler function
|
|
39
|
+
*/
|
|
40
|
+
setRequestHandler: (handler) => {
|
|
41
|
+
const waitForConnection = () => {
|
|
42
|
+
const setupHandler = () => {
|
|
43
|
+
if (websocket_1.default.getWebsocket) {
|
|
44
|
+
websocket_1.default.getWebsocket.on('message', async (data) => {
|
|
45
|
+
try {
|
|
46
|
+
const request = JSON.parse(data);
|
|
47
|
+
await handler(request, (responseData) => {
|
|
48
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
49
|
+
type: `processStoped`,
|
|
50
|
+
...responseData
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error('Error handling request:', error);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
setTimeout(setupHandler, 100);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
setupHandler();
|
|
64
|
+
};
|
|
65
|
+
waitForConnection();
|
|
66
|
+
},
|
|
36
67
|
/**
|
|
37
68
|
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
|
|
38
69
|
* @returns {EventEmitter} The event emitter used for emitting custom events.
|
|
39
70
|
*/
|
|
71
|
+
/**
|
|
72
|
+
* Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.
|
|
73
|
+
* @returns {EventEmitter} The event emitter used for emitting custom events.
|
|
74
|
+
*/
|
|
40
75
|
onActionMessage: () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
76
|
+
const waitForConnection = () => {
|
|
77
|
+
if (websocket_1.default.getWebsocket) {
|
|
78
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
79
|
+
const response = JSON.parse(data);
|
|
80
|
+
if (response.type === "messageResponse") {
|
|
81
|
+
eventEmitter.emit("userMessage", response, (message) => {
|
|
82
|
+
console.log("Callback function invoked with message:", message);
|
|
83
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
84
|
+
"type": "processStoped"
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
52
88
|
});
|
|
53
89
|
}
|
|
54
|
-
|
|
90
|
+
else {
|
|
91
|
+
setTimeout(waitForConnection, 100);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
waitForConnection();
|
|
55
95
|
return eventEmitter;
|
|
56
96
|
},
|
|
57
97
|
/**
|
package/modules/fs.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ declare const cbfs: {
|
|
|
59
59
|
* @description Lists all files.
|
|
60
60
|
* @returns {Promise<FileListResponse>} A promise that resolves with the list of files.
|
|
61
61
|
*/
|
|
62
|
-
listFile: (folderPath: string, isRecursive?: boolean) => Promise<
|
|
62
|
+
listFile: (folderPath: string, isRecursive?: boolean) => Promise<any>;
|
|
63
63
|
/**
|
|
64
64
|
* @function listCodeDefinitionNames
|
|
65
65
|
* @description Lists all code definition names in a given path.
|
package/modules/mcp.js
CHANGED
|
@@ -19,9 +19,6 @@ const codeboltMCP = {
|
|
|
19
19
|
if (response.type === "executeToolResponse") {
|
|
20
20
|
resolve(response.data);
|
|
21
21
|
}
|
|
22
|
-
else {
|
|
23
|
-
reject(new Error("Unexpected response type"));
|
|
24
|
-
}
|
|
25
22
|
}
|
|
26
23
|
catch (error) {
|
|
27
24
|
reject(new Error("Failed to parse response"));
|
|
@@ -45,9 +42,6 @@ const codeboltMCP = {
|
|
|
45
42
|
if (response.type === "getMcpToolsResponse") {
|
|
46
43
|
resolve(response.data);
|
|
47
44
|
}
|
|
48
|
-
else {
|
|
49
|
-
reject(new Error("Unexpected response type"));
|
|
50
|
-
}
|
|
51
45
|
}
|
|
52
46
|
catch (error) {
|
|
53
47
|
reject(new Error("Failed to parse response"));
|
|
@@ -71,9 +65,6 @@ const codeboltMCP = {
|
|
|
71
65
|
if (response.type === "getAllMCPToolsResponse") {
|
|
72
66
|
resolve(response.data);
|
|
73
67
|
}
|
|
74
|
-
else {
|
|
75
|
-
reject(new Error("Unexpected response type"));
|
|
76
|
-
}
|
|
77
68
|
}
|
|
78
69
|
catch (error) {
|
|
79
70
|
reject(new Error("Failed to parse response"));
|
|
@@ -97,9 +88,6 @@ const codeboltMCP = {
|
|
|
97
88
|
if (response.type === "getMCPToolResponse") {
|
|
98
89
|
resolve(response.data);
|
|
99
90
|
}
|
|
100
|
-
else {
|
|
101
|
-
reject(new Error("Unexpected response type"));
|
|
102
|
-
}
|
|
103
91
|
}
|
|
104
92
|
catch (error) {
|
|
105
93
|
reject(new Error("Failed to parse response"));
|
|
@@ -122,9 +110,6 @@ const codeboltMCP = {
|
|
|
122
110
|
if (response.type === "getEnabledMCPSResponse") {
|
|
123
111
|
resolve(response.data);
|
|
124
112
|
}
|
|
125
|
-
else {
|
|
126
|
-
reject(new Error("Unexpected response type"));
|
|
127
|
-
}
|
|
128
113
|
}
|
|
129
114
|
catch (error) {
|
|
130
115
|
reject(new Error("Failed to parse response"));
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
5
|
+
import { ClientCapabilities, CreateMessageRequestSchema, Root } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { StrictEventEmitter } from "strict-event-emitter-types";
|
|
8
|
+
import { EventEmitter } from "events";
|
|
9
|
+
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
10
|
+
export type SSEServer = {
|
|
11
|
+
close: () => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
type FastMCPEvents = {
|
|
14
|
+
connect: (event: {
|
|
15
|
+
session: FastMCPSession;
|
|
16
|
+
}) => void;
|
|
17
|
+
disconnect: (event: {
|
|
18
|
+
session: FastMCPSession;
|
|
19
|
+
}) => void;
|
|
20
|
+
};
|
|
21
|
+
type FastMCPSessionEvents = {
|
|
22
|
+
rootsChanged: (event: {
|
|
23
|
+
roots: Root[];
|
|
24
|
+
}) => void;
|
|
25
|
+
error: (event: {
|
|
26
|
+
error: Error;
|
|
27
|
+
}) => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Generates an image content object from a URL, file path, or buffer.
|
|
31
|
+
*/
|
|
32
|
+
export declare const imageContent: (input: {
|
|
33
|
+
url: string;
|
|
34
|
+
} | {
|
|
35
|
+
path: string;
|
|
36
|
+
} | {
|
|
37
|
+
buffer: Buffer;
|
|
38
|
+
}) => Promise<ImageContent>;
|
|
39
|
+
declare abstract class FastMCPError extends Error {
|
|
40
|
+
constructor(message?: string);
|
|
41
|
+
}
|
|
42
|
+
type Extra = unknown;
|
|
43
|
+
type Extras = Record<string, Extra>;
|
|
44
|
+
export declare class UnexpectedStateError extends FastMCPError {
|
|
45
|
+
extras?: Extras;
|
|
46
|
+
constructor(message: string, extras?: Extras);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* An error that is meant to be surfaced to the user.
|
|
50
|
+
*/
|
|
51
|
+
export declare class UserError extends UnexpectedStateError {
|
|
52
|
+
}
|
|
53
|
+
type ToolParameters = z.ZodTypeAny;
|
|
54
|
+
type Literal = boolean | null | number | string | undefined;
|
|
55
|
+
type SerializableValue = Literal | SerializableValue[] | {
|
|
56
|
+
[key: string]: SerializableValue;
|
|
57
|
+
};
|
|
58
|
+
type Progress = {
|
|
59
|
+
/**
|
|
60
|
+
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
61
|
+
*/
|
|
62
|
+
progress: number;
|
|
63
|
+
/**
|
|
64
|
+
* Total number of items to process (or total progress required), if known.
|
|
65
|
+
*/
|
|
66
|
+
total?: number;
|
|
67
|
+
};
|
|
68
|
+
type Context = {
|
|
69
|
+
reportProgress: (progress: Progress) => Promise<void>;
|
|
70
|
+
log: {
|
|
71
|
+
debug: (message: string, data?: SerializableValue) => void;
|
|
72
|
+
error: (message: string, data?: SerializableValue) => void;
|
|
73
|
+
info: (message: string, data?: SerializableValue) => void;
|
|
74
|
+
warn: (message: string, data?: SerializableValue) => void;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
type TextContent = {
|
|
78
|
+
type: "text";
|
|
79
|
+
text: string;
|
|
80
|
+
};
|
|
81
|
+
type ImageContent = {
|
|
82
|
+
type: "image";
|
|
83
|
+
data: string;
|
|
84
|
+
mimeType: string;
|
|
85
|
+
};
|
|
86
|
+
type Content = TextContent | ImageContent;
|
|
87
|
+
type ContentResult = {
|
|
88
|
+
content: Content[];
|
|
89
|
+
isError?: boolean;
|
|
90
|
+
};
|
|
91
|
+
type Completion = {
|
|
92
|
+
values: string[];
|
|
93
|
+
total?: number;
|
|
94
|
+
hasMore?: boolean;
|
|
95
|
+
};
|
|
96
|
+
type Tool<Params extends ToolParameters = ToolParameters> = {
|
|
97
|
+
name: string;
|
|
98
|
+
description?: string;
|
|
99
|
+
parameters?: Params;
|
|
100
|
+
execute: (args: z.infer<Params>, context: Context) => Promise<string | ContentResult | TextContent | ImageContent>;
|
|
101
|
+
};
|
|
102
|
+
type ResourceResult = {
|
|
103
|
+
text: string;
|
|
104
|
+
} | {
|
|
105
|
+
blob: string;
|
|
106
|
+
};
|
|
107
|
+
type InputResourceTemplateArgument = Readonly<{
|
|
108
|
+
name: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
complete?: ArgumentValueCompleter;
|
|
111
|
+
}>;
|
|
112
|
+
type ResourceTemplateArgument = Readonly<{
|
|
113
|
+
name: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
complete?: ArgumentValueCompleter;
|
|
116
|
+
}>;
|
|
117
|
+
type ResourceTemplateArgumentsToObject<T extends {
|
|
118
|
+
name: string;
|
|
119
|
+
}[]> = {
|
|
120
|
+
[K in T[number]["name"]]: string;
|
|
121
|
+
};
|
|
122
|
+
type InputResourceTemplate<Arguments extends ResourceTemplateArgument[] = ResourceTemplateArgument[]> = {
|
|
123
|
+
uriTemplate: string;
|
|
124
|
+
name: string;
|
|
125
|
+
description?: string;
|
|
126
|
+
mimeType?: string;
|
|
127
|
+
arguments: Arguments;
|
|
128
|
+
load: (args: ResourceTemplateArgumentsToObject<Arguments>) => Promise<ResourceResult>;
|
|
129
|
+
};
|
|
130
|
+
type Resource = {
|
|
131
|
+
uri: string;
|
|
132
|
+
name: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
mimeType?: string;
|
|
135
|
+
load: () => Promise<ResourceResult | ResourceResult[]>;
|
|
136
|
+
complete?: (name: string, value: string) => Promise<Completion>;
|
|
137
|
+
};
|
|
138
|
+
type ArgumentValueCompleter = (value: string) => Promise<Completion>;
|
|
139
|
+
type InputPromptArgument = Readonly<{
|
|
140
|
+
name: string;
|
|
141
|
+
description?: string;
|
|
142
|
+
required?: boolean;
|
|
143
|
+
complete?: ArgumentValueCompleter;
|
|
144
|
+
enum?: string[];
|
|
145
|
+
}>;
|
|
146
|
+
type PromptArgumentsToObject<T extends {
|
|
147
|
+
name: string;
|
|
148
|
+
required?: boolean;
|
|
149
|
+
}[]> = {
|
|
150
|
+
[K in T[number]["name"]]: Extract<T[number], {
|
|
151
|
+
name: K;
|
|
152
|
+
}>["required"] extends true ? string : string | undefined;
|
|
153
|
+
};
|
|
154
|
+
type InputPrompt<Arguments extends InputPromptArgument[] = InputPromptArgument[], Args = PromptArgumentsToObject<Arguments>> = {
|
|
155
|
+
name: string;
|
|
156
|
+
description?: string;
|
|
157
|
+
arguments?: InputPromptArgument[];
|
|
158
|
+
load: (args: Args) => Promise<string>;
|
|
159
|
+
};
|
|
160
|
+
type PromptArgument = Readonly<{
|
|
161
|
+
name: string;
|
|
162
|
+
description?: string;
|
|
163
|
+
required?: boolean;
|
|
164
|
+
complete?: ArgumentValueCompleter;
|
|
165
|
+
enum?: string[];
|
|
166
|
+
}>;
|
|
167
|
+
type Prompt<Arguments extends PromptArgument[] = PromptArgument[], Args = PromptArgumentsToObject<Arguments>> = {
|
|
168
|
+
arguments?: PromptArgument[];
|
|
169
|
+
complete?: (name: string, value: string) => Promise<Completion>;
|
|
170
|
+
description?: string;
|
|
171
|
+
load: (args: Args) => Promise<string>;
|
|
172
|
+
name: string;
|
|
173
|
+
};
|
|
174
|
+
type ServerOptions = {
|
|
175
|
+
name: string;
|
|
176
|
+
version: `${number}.${number}.${number}`;
|
|
177
|
+
};
|
|
178
|
+
type LoggingLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency";
|
|
179
|
+
declare const FastMCPSessionEventEmitterBase: {
|
|
180
|
+
new (): StrictEventEmitter<EventEmitter, FastMCPSessionEvents>;
|
|
181
|
+
};
|
|
182
|
+
declare class FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase {
|
|
183
|
+
}
|
|
184
|
+
type SamplingResponse = {
|
|
185
|
+
model: string;
|
|
186
|
+
stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
|
|
187
|
+
role: "user" | "assistant";
|
|
188
|
+
content: TextContent | ImageContent;
|
|
189
|
+
};
|
|
190
|
+
export declare class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
191
|
+
#private;
|
|
192
|
+
constructor({ name, version, tools, resources, resourcesTemplates, prompts, }: {
|
|
193
|
+
name: string;
|
|
194
|
+
version: string;
|
|
195
|
+
tools: Tool[];
|
|
196
|
+
resources: Resource[];
|
|
197
|
+
resourcesTemplates: InputResourceTemplate[];
|
|
198
|
+
prompts: Prompt[];
|
|
199
|
+
});
|
|
200
|
+
private addResource;
|
|
201
|
+
private addResourceTemplate;
|
|
202
|
+
private addPrompt;
|
|
203
|
+
get clientCapabilities(): ClientCapabilities | null;
|
|
204
|
+
get server(): Server;
|
|
205
|
+
requestSampling(message: z.infer<typeof CreateMessageRequestSchema>["params"]): Promise<SamplingResponse>;
|
|
206
|
+
connect(transport: Transport): Promise<void>;
|
|
207
|
+
get roots(): Root[];
|
|
208
|
+
close(): Promise<void>;
|
|
209
|
+
private setupErrorHandling;
|
|
210
|
+
get loggingLevel(): LoggingLevel;
|
|
211
|
+
private setupCompleteHandlers;
|
|
212
|
+
private setupRootsHandlers;
|
|
213
|
+
private setupLoggingHandlers;
|
|
214
|
+
private setupToolHandlers;
|
|
215
|
+
private setupResourceHandlers;
|
|
216
|
+
private setupResourceTemplateHandlers;
|
|
217
|
+
private setupPromptHandlers;
|
|
218
|
+
}
|
|
219
|
+
declare const FastMCPEventEmitterBase: {
|
|
220
|
+
new (): StrictEventEmitter<EventEmitter, FastMCPEvents>;
|
|
221
|
+
};
|
|
222
|
+
declare class FastMCPEventEmitter extends FastMCPEventEmitterBase {
|
|
223
|
+
}
|
|
224
|
+
export declare class ToolBox extends FastMCPEventEmitter {
|
|
225
|
+
#private;
|
|
226
|
+
options: ServerOptions;
|
|
227
|
+
constructor(options: ServerOptions);
|
|
228
|
+
get sessions(): FastMCPSession[];
|
|
229
|
+
/**
|
|
230
|
+
* Adds a tool to the server.
|
|
231
|
+
*/
|
|
232
|
+
addTool<Params extends ToolParameters>(tool: Tool<Params>): void;
|
|
233
|
+
/**
|
|
234
|
+
* Adds a resource to the server.
|
|
235
|
+
*/
|
|
236
|
+
addResource(resource: Resource): void;
|
|
237
|
+
/**
|
|
238
|
+
* Adds a resource template to the server.
|
|
239
|
+
*/
|
|
240
|
+
addResourceTemplate<const Args extends InputResourceTemplateArgument[]>(resource: InputResourceTemplate<Args>): void;
|
|
241
|
+
/**
|
|
242
|
+
* Adds a prompt to the server.
|
|
243
|
+
*/
|
|
244
|
+
addPrompt<const Args extends InputPromptArgument[]>(prompt: InputPrompt<Args>): void;
|
|
245
|
+
/**
|
|
246
|
+
* Starts the server.
|
|
247
|
+
*/
|
|
248
|
+
activate(options?: {
|
|
249
|
+
transportType: "stdio";
|
|
250
|
+
} | {
|
|
251
|
+
transportType: "sse";
|
|
252
|
+
sse: {
|
|
253
|
+
endpoint: `/${string}`;
|
|
254
|
+
port: number;
|
|
255
|
+
};
|
|
256
|
+
}): Promise<void>;
|
|
257
|
+
/**
|
|
258
|
+
* Stops the server.
|
|
259
|
+
*/
|
|
260
|
+
stop(): Promise<void>;
|
|
261
|
+
}
|
|
262
|
+
export {};
|