@codebolt/codeboltjs 1.1.92 → 1.1.94
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/index.d.ts +15 -8
- package/index.js +3 -3
- package/modules/agentlib/agent.d.ts +1 -0
- package/modules/agentlib/agent.js +68 -6
- package/modules/agentlib/usermessage.d.ts +1 -1
- package/modules/agentlib/usermessage.js +4 -4
- package/modules/mcp.d.ts +1 -0
- package/modules/mcp.js +24 -0
- package/modules/toolBox.bkp.d.ts +262 -0
- package/modules/toolBox.bkp.js +721 -0
- package/modules/toolBox.d.ts +36 -17
- package/modules/toolBox.js +62 -21
- package/modules/tools.d.ts +16 -0
- package/modules/tools.js +197 -0
- package/package.json +3 -2
- package/src/index.ts +3 -3
- package/src/modules/agentlib/agent.ts +83 -11
- package/src/modules/agentlib/usermessage.ts +5 -5
- package/src/modules/toolBox.bkp.ts +1165 -0
- package/src/modules/toolBox.ts +108 -66
- package/src/modules/tools.ts +187 -0
- package/src/modules/mcp.ts +0 -117
package/modules/toolBox.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
4
5
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
5
6
|
import { ClientCapabilities, CreateMessageRequestSchema, Root } from "@modelcontextprotocol/sdk/types.js";
|
|
6
7
|
import { z } from "zod";
|
|
7
8
|
import { StrictEventEmitter } from "strict-event-emitter-types";
|
|
8
9
|
import { EventEmitter } from "events";
|
|
9
10
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
11
|
+
import http from "http";
|
|
10
12
|
export type SSEServer = {
|
|
11
13
|
close: () => Promise<void>;
|
|
12
14
|
};
|
|
13
|
-
type FastMCPEvents = {
|
|
15
|
+
type FastMCPEvents<T extends FastMCPSessionAuth> = {
|
|
14
16
|
connect: (event: {
|
|
15
|
-
session: FastMCPSession
|
|
17
|
+
session: FastMCPSession<T>;
|
|
16
18
|
}) => void;
|
|
17
19
|
disconnect: (event: {
|
|
18
|
-
session: FastMCPSession
|
|
20
|
+
session: FastMCPSession<T>;
|
|
19
21
|
}) => void;
|
|
20
22
|
};
|
|
21
23
|
type FastMCPSessionEvents = {
|
|
@@ -65,7 +67,8 @@ type Progress = {
|
|
|
65
67
|
*/
|
|
66
68
|
total?: number;
|
|
67
69
|
};
|
|
68
|
-
type Context = {
|
|
70
|
+
type Context<T extends FastMCPSessionAuth> = {
|
|
71
|
+
session: T | undefined;
|
|
69
72
|
reportProgress: (progress: Progress) => Promise<void>;
|
|
70
73
|
log: {
|
|
71
74
|
debug: (message: string, data?: SerializableValue) => void;
|
|
@@ -93,11 +96,11 @@ type Completion = {
|
|
|
93
96
|
total?: number;
|
|
94
97
|
hasMore?: boolean;
|
|
95
98
|
};
|
|
96
|
-
type Tool<Params extends ToolParameters = ToolParameters> = {
|
|
99
|
+
type Tool<T extends FastMCPSessionAuth, Params extends ToolParameters = ToolParameters> = {
|
|
97
100
|
name: string;
|
|
98
101
|
description?: string;
|
|
99
102
|
parameters?: Params;
|
|
100
|
-
execute: (args: z.infer<Params>, context: Context) => Promise<string | ContentResult | TextContent | ImageContent>;
|
|
103
|
+
execute: (args: z.infer<Params>, context: Context<T>) => Promise<string | ContentResult | TextContent | ImageContent>;
|
|
101
104
|
};
|
|
102
105
|
type ResourceResult = {
|
|
103
106
|
text: string;
|
|
@@ -171,9 +174,10 @@ type Prompt<Arguments extends PromptArgument[] = PromptArgument[], Args = Prompt
|
|
|
171
174
|
load: (args: Args) => Promise<string>;
|
|
172
175
|
name: string;
|
|
173
176
|
};
|
|
174
|
-
type ServerOptions = {
|
|
177
|
+
type ServerOptions<T extends FastMCPSessionAuth> = {
|
|
175
178
|
name: string;
|
|
176
179
|
version: `${number}.${number}.${number}`;
|
|
180
|
+
authenticate?: Authenticate<T>;
|
|
177
181
|
};
|
|
178
182
|
type LoggingLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency";
|
|
179
183
|
declare const FastMCPSessionEventEmitterBase: {
|
|
@@ -187,12 +191,14 @@ type SamplingResponse = {
|
|
|
187
191
|
role: "user" | "assistant";
|
|
188
192
|
content: TextContent | ImageContent;
|
|
189
193
|
};
|
|
190
|
-
|
|
194
|
+
type FastMCPSessionAuth = Record<string, unknown> | undefined;
|
|
195
|
+
export declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends FastMCPSessionEventEmitter {
|
|
191
196
|
#private;
|
|
192
|
-
constructor({ name, version, tools, resources, resourcesTemplates, prompts, }: {
|
|
197
|
+
constructor({ auth, name, version, tools, resources, resourcesTemplates, prompts, }: {
|
|
198
|
+
auth?: T;
|
|
193
199
|
name: string;
|
|
194
200
|
version: string;
|
|
195
|
-
tools: Tool[];
|
|
201
|
+
tools: Tool<T>[];
|
|
196
202
|
resources: Resource[];
|
|
197
203
|
resourcesTemplates: InputResourceTemplate[];
|
|
198
204
|
prompts: Prompt[];
|
|
@@ -217,19 +223,20 @@ export declare class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
217
223
|
private setupPromptHandlers;
|
|
218
224
|
}
|
|
219
225
|
declare const FastMCPEventEmitterBase: {
|
|
220
|
-
new (): StrictEventEmitter<EventEmitter, FastMCPEvents
|
|
226
|
+
new (): StrictEventEmitter<EventEmitter, FastMCPEvents<FastMCPSessionAuth>>;
|
|
221
227
|
};
|
|
222
228
|
declare class FastMCPEventEmitter extends FastMCPEventEmitterBase {
|
|
223
229
|
}
|
|
224
|
-
|
|
230
|
+
type Authenticate<T> = (request: http.IncomingMessage) => Promise<T>;
|
|
231
|
+
export declare class ToolBox<T extends Record<string, unknown> | undefined = undefined> extends FastMCPEventEmitter {
|
|
225
232
|
#private;
|
|
226
|
-
options: ServerOptions
|
|
227
|
-
constructor(options: ServerOptions);
|
|
228
|
-
get sessions(): FastMCPSession[];
|
|
233
|
+
options: ServerOptions<T>;
|
|
234
|
+
constructor(options: ServerOptions<T>);
|
|
235
|
+
get sessions(): FastMCPSession<T>[];
|
|
229
236
|
/**
|
|
230
237
|
* Adds a tool to the server.
|
|
231
238
|
*/
|
|
232
|
-
addTool<Params extends ToolParameters>(tool: Tool<Params>): void;
|
|
239
|
+
addTool<Params extends ToolParameters>(tool: Tool<T, Params>): void;
|
|
233
240
|
/**
|
|
234
241
|
* Adds a resource to the server.
|
|
235
242
|
*/
|
|
@@ -245,7 +252,7 @@ export declare class ToolBox extends FastMCPEventEmitter {
|
|
|
245
252
|
/**
|
|
246
253
|
* Starts the server.
|
|
247
254
|
*/
|
|
248
|
-
|
|
255
|
+
start(options?: {
|
|
249
256
|
transportType: "stdio";
|
|
250
257
|
} | {
|
|
251
258
|
transportType: "sse";
|
|
@@ -258,5 +265,17 @@ export declare class ToolBox extends FastMCPEventEmitter {
|
|
|
258
265
|
* Stops the server.
|
|
259
266
|
*/
|
|
260
267
|
stop(): Promise<void>;
|
|
268
|
+
/**
|
|
269
|
+
* Starts the server.
|
|
270
|
+
*/
|
|
271
|
+
activate(options?: {
|
|
272
|
+
transportType: "stdio";
|
|
273
|
+
} | {
|
|
274
|
+
transportType: "sse";
|
|
275
|
+
sse: {
|
|
276
|
+
endpoint: `/${string}`;
|
|
277
|
+
port: number;
|
|
278
|
+
};
|
|
279
|
+
}): Promise<void>;
|
|
261
280
|
}
|
|
262
281
|
export {};
|
package/modules/toolBox.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
5
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
6
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
7
|
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _FastMCPSession_capabilities, _FastMCPSession_clientCapabilities, _FastMCPSession_loggingLevel, _FastMCPSession_prompts, _FastMCPSession_resources, _FastMCPSession_resourceTemplates, _FastMCPSession_roots, _FastMCPSession_server, _FastMCPSession_pingInterval, _ToolBox_options, _ToolBox_prompts, _ToolBox_resources, _ToolBox_resourcesTemplates, _ToolBox_sessions, _ToolBox_sseServer, _ToolBox_tools;
|
|
16
|
+
var _FastMCPSession_capabilities, _FastMCPSession_clientCapabilities, _FastMCPSession_loggingLevel, _FastMCPSession_prompts, _FastMCPSession_resources, _FastMCPSession_resourceTemplates, _FastMCPSession_roots, _FastMCPSession_server, _FastMCPSession_auth, _FastMCPSession_pingInterval, _ToolBox_options, _ToolBox_prompts, _ToolBox_resources, _ToolBox_resourcesTemplates, _ToolBox_sessions, _ToolBox_sseServer, _ToolBox_tools, _ToolBox_authenticate;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.ToolBox = exports.FastMCPSession = exports.UserError = exports.UnexpectedStateError = exports.imageContent = void 0;
|
|
19
19
|
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
@@ -26,6 +26,7 @@ const promises_2 = require("fs/promises");
|
|
|
26
26
|
const events_1 = require("events");
|
|
27
27
|
const fuse_js_1 = __importDefault(require("fuse.js"));
|
|
28
28
|
const uri_templates_1 = __importDefault(require("uri-templates"));
|
|
29
|
+
const undici_1 = require("undici");
|
|
29
30
|
const load_esm_1 = require("load-esm");
|
|
30
31
|
/**
|
|
31
32
|
* Generates an image content object from a URL, file path, or buffer.
|
|
@@ -34,7 +35,7 @@ const imageContent = async (input) => {
|
|
|
34
35
|
var _a;
|
|
35
36
|
let rawData;
|
|
36
37
|
if ("url" in input) {
|
|
37
|
-
const response = await fetch(input.url);
|
|
38
|
+
const response = await (0, undici_1.fetch)(input.url);
|
|
38
39
|
if (!response.ok) {
|
|
39
40
|
throw new Error(`Failed to fetch image from URL: ${response.statusText}`);
|
|
40
41
|
}
|
|
@@ -133,7 +134,7 @@ const FastMCPSessionEventEmitterBase = events_1.EventEmitter;
|
|
|
133
134
|
class FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase {
|
|
134
135
|
}
|
|
135
136
|
class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
136
|
-
constructor({ name, version, tools, resources, resourcesTemplates, prompts, }) {
|
|
137
|
+
constructor({ auth, name, version, tools, resources, resourcesTemplates, prompts, }) {
|
|
137
138
|
super();
|
|
138
139
|
_FastMCPSession_capabilities.set(this, {});
|
|
139
140
|
_FastMCPSession_clientCapabilities.set(this, void 0);
|
|
@@ -143,7 +144,9 @@ class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
143
144
|
_FastMCPSession_resourceTemplates.set(this, []);
|
|
144
145
|
_FastMCPSession_roots.set(this, []);
|
|
145
146
|
_FastMCPSession_server.set(this, void 0);
|
|
147
|
+
_FastMCPSession_auth.set(this, void 0);
|
|
146
148
|
_FastMCPSession_pingInterval.set(this, null);
|
|
149
|
+
__classPrivateFieldSet(this, _FastMCPSession_auth, auth, "f");
|
|
147
150
|
if (tools.length) {
|
|
148
151
|
__classPrivateFieldGet(this, _FastMCPSession_capabilities, "f").tools = {};
|
|
149
152
|
}
|
|
@@ -259,6 +262,7 @@ class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
259
262
|
let attempt = 0;
|
|
260
263
|
while (attempt++ < 10) {
|
|
261
264
|
const capabilities = await __classPrivateFieldGet(this, _FastMCPSession_server, "f").getClientCapabilities();
|
|
265
|
+
console.log("capabilities", capabilities);
|
|
262
266
|
if (capabilities) {
|
|
263
267
|
__classPrivateFieldSet(this, _FastMCPSession_clientCapabilities, capabilities, "f");
|
|
264
268
|
break;
|
|
@@ -266,7 +270,7 @@ class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
266
270
|
await (0, promises_1.setTimeout)(100);
|
|
267
271
|
}
|
|
268
272
|
if (!__classPrivateFieldGet(this, _FastMCPSession_clientCapabilities, "f")) {
|
|
269
|
-
|
|
273
|
+
console.warn('[warning] toolBox could not infer client capabilities');
|
|
270
274
|
}
|
|
271
275
|
if ((_a = __classPrivateFieldGet(this, _FastMCPSession_clientCapabilities, "f")) === null || _a === void 0 ? void 0 : _a.roots) {
|
|
272
276
|
const roots = await __classPrivateFieldGet(this, _FastMCPSession_server, "f").listRoots();
|
|
@@ -290,7 +294,12 @@ class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
290
294
|
if (__classPrivateFieldGet(this, _FastMCPSession_pingInterval, "f")) {
|
|
291
295
|
clearInterval(__classPrivateFieldGet(this, _FastMCPSession_pingInterval, "f"));
|
|
292
296
|
}
|
|
293
|
-
|
|
297
|
+
try {
|
|
298
|
+
await __classPrivateFieldGet(this, _FastMCPSession_server, "f").close();
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
console.error("[MCP Error]", "could not close server", error);
|
|
302
|
+
}
|
|
294
303
|
}
|
|
295
304
|
setupErrorHandling() {
|
|
296
305
|
__classPrivateFieldGet(this, _FastMCPSession_server, "f").onerror = (error) => {
|
|
@@ -441,6 +450,7 @@ class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
441
450
|
const maybeStringResult = await tool.execute(args, {
|
|
442
451
|
reportProgress,
|
|
443
452
|
log,
|
|
453
|
+
session: __classPrivateFieldGet(this, _FastMCPSession_auth, "f"),
|
|
444
454
|
});
|
|
445
455
|
if (typeof maybeStringResult === "string") {
|
|
446
456
|
result = ContentResultZodSchema.parse({
|
|
@@ -605,7 +615,7 @@ class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
605
615
|
}
|
|
606
616
|
}
|
|
607
617
|
exports.FastMCPSession = FastMCPSession;
|
|
608
|
-
_FastMCPSession_capabilities = new WeakMap(), _FastMCPSession_clientCapabilities = new WeakMap(), _FastMCPSession_loggingLevel = new WeakMap(), _FastMCPSession_prompts = new WeakMap(), _FastMCPSession_resources = new WeakMap(), _FastMCPSession_resourceTemplates = new WeakMap(), _FastMCPSession_roots = new WeakMap(), _FastMCPSession_server = new WeakMap(), _FastMCPSession_pingInterval = new WeakMap();
|
|
618
|
+
_FastMCPSession_capabilities = new WeakMap(), _FastMCPSession_clientCapabilities = new WeakMap(), _FastMCPSession_loggingLevel = new WeakMap(), _FastMCPSession_prompts = new WeakMap(), _FastMCPSession_resources = new WeakMap(), _FastMCPSession_resourceTemplates = new WeakMap(), _FastMCPSession_roots = new WeakMap(), _FastMCPSession_server = new WeakMap(), _FastMCPSession_auth = new WeakMap(), _FastMCPSession_pingInterval = new WeakMap();
|
|
609
619
|
const FastMCPEventEmitterBase = events_1.EventEmitter;
|
|
610
620
|
class FastMCPEventEmitter extends FastMCPEventEmitterBase {
|
|
611
621
|
}
|
|
@@ -620,7 +630,9 @@ class ToolBox extends FastMCPEventEmitter {
|
|
|
620
630
|
_ToolBox_sessions.set(this, []);
|
|
621
631
|
_ToolBox_sseServer.set(this, null);
|
|
622
632
|
_ToolBox_tools.set(this, []);
|
|
633
|
+
_ToolBox_authenticate.set(this, void 0);
|
|
623
634
|
__classPrivateFieldSet(this, _ToolBox_options, options, "f");
|
|
635
|
+
__classPrivateFieldSet(this, _ToolBox_authenticate, options.authenticate, "f");
|
|
624
636
|
}
|
|
625
637
|
get sessions() {
|
|
626
638
|
return __classPrivateFieldGet(this, _ToolBox_sessions, "f");
|
|
@@ -649,6 +661,42 @@ class ToolBox extends FastMCPEventEmitter {
|
|
|
649
661
|
addPrompt(prompt) {
|
|
650
662
|
__classPrivateFieldGet(this, _ToolBox_prompts, "f").push(prompt);
|
|
651
663
|
}
|
|
664
|
+
/**
|
|
665
|
+
* Starts the server.
|
|
666
|
+
*/
|
|
667
|
+
async start(options = {
|
|
668
|
+
transportType: "stdio",
|
|
669
|
+
}) {
|
|
670
|
+
if (options.transportType === "stdio") {
|
|
671
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
672
|
+
const session = new FastMCPSession({
|
|
673
|
+
name: __classPrivateFieldGet(this, _ToolBox_options, "f").name,
|
|
674
|
+
version: __classPrivateFieldGet(this, _ToolBox_options, "f").version,
|
|
675
|
+
tools: __classPrivateFieldGet(this, _ToolBox_tools, "f"),
|
|
676
|
+
resources: __classPrivateFieldGet(this, _ToolBox_resources, "f"),
|
|
677
|
+
resourcesTemplates: __classPrivateFieldGet(this, _ToolBox_resourcesTemplates, "f"),
|
|
678
|
+
prompts: __classPrivateFieldGet(this, _ToolBox_prompts, "f"),
|
|
679
|
+
});
|
|
680
|
+
await session.connect(transport);
|
|
681
|
+
__classPrivateFieldGet(this, _ToolBox_sessions, "f").push(session);
|
|
682
|
+
this.emit("connect", {
|
|
683
|
+
session,
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
else if (options.transportType === "sse") {
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
throw new Error("Invalid transport type");
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Stops the server.
|
|
694
|
+
*/
|
|
695
|
+
async stop() {
|
|
696
|
+
if (__classPrivateFieldGet(this, _ToolBox_sseServer, "f")) {
|
|
697
|
+
__classPrivateFieldGet(this, _ToolBox_sseServer, "f").close();
|
|
698
|
+
}
|
|
699
|
+
}
|
|
652
700
|
/**
|
|
653
701
|
* Starts the server.
|
|
654
702
|
*/
|
|
@@ -657,6 +705,7 @@ class ToolBox extends FastMCPEventEmitter {
|
|
|
657
705
|
}) {
|
|
658
706
|
if (options.transportType === "stdio") {
|
|
659
707
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
708
|
+
// console.log("tools", this.#tools);
|
|
660
709
|
const session = new FastMCPSession({
|
|
661
710
|
name: __classPrivateFieldGet(this, _ToolBox_options, "f").name,
|
|
662
711
|
version: __classPrivateFieldGet(this, _ToolBox_options, "f").version,
|
|
@@ -665,7 +714,7 @@ class ToolBox extends FastMCPEventEmitter {
|
|
|
665
714
|
resourcesTemplates: __classPrivateFieldGet(this, _ToolBox_resourcesTemplates, "f"),
|
|
666
715
|
prompts: __classPrivateFieldGet(this, _ToolBox_prompts, "f"),
|
|
667
716
|
});
|
|
668
|
-
console.log("session", session);
|
|
717
|
+
// console.log("session", session);
|
|
669
718
|
await session.connect(transport);
|
|
670
719
|
__classPrivateFieldGet(this, _ToolBox_sessions, "f").push(session);
|
|
671
720
|
this.emit("connect", {
|
|
@@ -707,14 +756,6 @@ class ToolBox extends FastMCPEventEmitter {
|
|
|
707
756
|
throw new Error("Invalid transport type");
|
|
708
757
|
}
|
|
709
758
|
}
|
|
710
|
-
/**
|
|
711
|
-
* Stops the server.
|
|
712
|
-
*/
|
|
713
|
-
async stop() {
|
|
714
|
-
if (__classPrivateFieldGet(this, _ToolBox_sseServer, "f")) {
|
|
715
|
-
__classPrivateFieldGet(this, _ToolBox_sseServer, "f").close();
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
759
|
}
|
|
719
760
|
exports.ToolBox = ToolBox;
|
|
720
|
-
_ToolBox_options = new WeakMap(), _ToolBox_prompts = new WeakMap(), _ToolBox_resources = new WeakMap(), _ToolBox_resourcesTemplates = new WeakMap(), _ToolBox_sessions = new WeakMap(), _ToolBox_sseServer = new WeakMap(), _ToolBox_tools = new WeakMap();
|
|
761
|
+
_ToolBox_options = new WeakMap(), _ToolBox_prompts = new WeakMap(), _ToolBox_resources = new WeakMap(), _ToolBox_resourcesTemplates = new WeakMap(), _ToolBox_sessions = new WeakMap(), _ToolBox_sseServer = new WeakMap(), _ToolBox_tools = new WeakMap(), _ToolBox_authenticate = new WeakMap();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UserMessage } from '../utils';
|
|
2
|
+
declare const codeboltMCP: {
|
|
3
|
+
getEnabledToolBoxes: () => Promise<any>;
|
|
4
|
+
getLocalToolBoxes: () => Promise<any>;
|
|
5
|
+
getMentionedToolBoxes: (userMessage: UserMessage) => Promise<any>;
|
|
6
|
+
getAvailableToolBoxes: () => Promise<any>;
|
|
7
|
+
searchAvailableToolBoxes: (query: string) => Promise<any>;
|
|
8
|
+
listToolsFromToolBoxes: (toolBoxes: string[]) => Promise<any>;
|
|
9
|
+
configureToolBox: (name: string, config: any) => Promise<any>;
|
|
10
|
+
getTools: (tools: {
|
|
11
|
+
toolbox: string;
|
|
12
|
+
toolName: string;
|
|
13
|
+
}[]) => Promise<any[]>;
|
|
14
|
+
executeTool: (toolbox: string, toolName: string, params: any) => Promise<any>;
|
|
15
|
+
};
|
|
16
|
+
export default codeboltMCP;
|
package/modules/tools.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
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 codeboltMCP = {
|
|
8
|
+
getEnabledToolBoxes: () => {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
11
|
+
"type": "codebolttools",
|
|
12
|
+
"action": "getEnabledToolBoxes"
|
|
13
|
+
}));
|
|
14
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
15
|
+
try {
|
|
16
|
+
const response = JSON.parse(data);
|
|
17
|
+
if (response.type === "getEnabledToolBoxesResponse") {
|
|
18
|
+
resolve(response.data);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
reject(new Error("Failed to parse response"));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
websocket_1.default.getWebsocket.on('error', (error) => {
|
|
26
|
+
reject(error);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
getLocalToolBoxes: () => {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
33
|
+
"type": "codebolttools",
|
|
34
|
+
"action": "getLocalToolBoxes"
|
|
35
|
+
}));
|
|
36
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
37
|
+
try {
|
|
38
|
+
const response = JSON.parse(data);
|
|
39
|
+
if (response.type === "getLocalToolBoxesResponse") {
|
|
40
|
+
resolve(response.data);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
reject(new Error("Failed to parse response"));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
websocket_1.default.getWebsocket.on('error', (error) => {
|
|
48
|
+
reject(error);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
getMentionedToolBoxes: (userMessage) => {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
resolve(userMessage.mentionedMCPs);
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
getAvailableToolBoxes: () => {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
60
|
+
"type": "codebolttools",
|
|
61
|
+
"action": "getAvailableToolBoxes"
|
|
62
|
+
}));
|
|
63
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
64
|
+
try {
|
|
65
|
+
const response = JSON.parse(data);
|
|
66
|
+
if (response.type === "getAvailableToolBoxesResponse") {
|
|
67
|
+
resolve(response.data);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
reject(new Error("Failed to parse response"));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
websocket_1.default.getWebsocket.on('error', (error) => {
|
|
75
|
+
reject(error);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
searchAvailableToolBoxes: (query) => {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
82
|
+
"type": "codebolttools",
|
|
83
|
+
"action": "searchAvailableToolBoxes",
|
|
84
|
+
"query": query
|
|
85
|
+
}));
|
|
86
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
87
|
+
try {
|
|
88
|
+
const response = JSON.parse(data);
|
|
89
|
+
if (response.type === "searchAvailableToolBoxesResponse") {
|
|
90
|
+
resolve(response.data);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
reject(new Error("Failed to parse response"));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
websocket_1.default.getWebsocket.on('error', (error) => {
|
|
98
|
+
reject(error);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
listToolsFromToolBoxes: (toolBoxes) => {
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
105
|
+
"type": "codebolttools",
|
|
106
|
+
"action": "listToolsFromToolBoxes",
|
|
107
|
+
"toolBoxes": toolBoxes
|
|
108
|
+
}));
|
|
109
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
110
|
+
try {
|
|
111
|
+
const response = JSON.parse(data);
|
|
112
|
+
if (response.type === "listToolsFromToolBoxesResponse") {
|
|
113
|
+
resolve(response.data);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
reject(new Error("Failed to parse response"));
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
websocket_1.default.getWebsocket.on('error', (error) => {
|
|
121
|
+
reject(error);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
configureToolBox: (name, config) => {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
128
|
+
"type": "codebolttools",
|
|
129
|
+
"action": "configureToolBox",
|
|
130
|
+
"mcpName": name,
|
|
131
|
+
"config": config
|
|
132
|
+
}));
|
|
133
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
134
|
+
try {
|
|
135
|
+
const response = JSON.parse(data);
|
|
136
|
+
if (response.type === "configureToolBoxResponse") {
|
|
137
|
+
resolve(response.data);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
reject(new Error("Failed to parse response"));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
websocket_1.default.getWebsocket.on('error', (error) => {
|
|
145
|
+
reject(error);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
getTools: (tools) => {
|
|
150
|
+
return new Promise((resolve, reject) => {
|
|
151
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
152
|
+
"type": "codebolttools",
|
|
153
|
+
"action": "getTools",
|
|
154
|
+
"toolboxes": tools
|
|
155
|
+
}));
|
|
156
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
157
|
+
try {
|
|
158
|
+
const response = JSON.parse(data);
|
|
159
|
+
if (response.type === "getToolsResponse") {
|
|
160
|
+
resolve(response.data);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
reject(new Error("Failed to parse response"));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
websocket_1.default.getWebsocket.on('error', (error) => {
|
|
168
|
+
reject(error);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
executeTool: (toolbox, toolName, params) => {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
175
|
+
"type": "codebolttools",
|
|
176
|
+
"action": "executeTool",
|
|
177
|
+
"toolName": `${toolbox}--${toolName}`,
|
|
178
|
+
"params": params
|
|
179
|
+
}));
|
|
180
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
181
|
+
try {
|
|
182
|
+
const response = JSON.parse(data);
|
|
183
|
+
if (response.type === "executeToolResponse") {
|
|
184
|
+
resolve(response.data);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
reject(new Error("Failed to parse response"));
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
websocket_1.default.getWebsocket.on('error', (error) => {
|
|
192
|
+
reject(error);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
exports.default = codeboltMCP;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebolt/codeboltjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.94",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"tree-sitter-javascript": "^0.23.1",
|
|
34
34
|
"tree-sitter-typescript": "^0.23.2",
|
|
35
35
|
"typedoc-plugin-missing-exports": "^2.2.0",
|
|
36
|
+
"undici": "^7.4.0",
|
|
36
37
|
"uri-templates": "^0.2.0",
|
|
37
38
|
"ws": "^8.17.0",
|
|
38
39
|
"yargs": "^17.7.2",
|
|
@@ -68,4 +69,4 @@
|
|
|
68
69
|
"default": "./utils.js"
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
|
-
}
|
|
72
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ import tokenizer from './modules/tokenizer'
|
|
|
23
23
|
import WebSocket from 'ws';
|
|
24
24
|
import { EventEmitter } from 'events';
|
|
25
25
|
import {chatSummary} from './modules/history'
|
|
26
|
-
import
|
|
26
|
+
import codeboltTools from './modules/tools';
|
|
27
27
|
import cbagent from './modules/agent';
|
|
28
28
|
|
|
29
29
|
|
|
@@ -96,8 +96,8 @@ class Codebolt { // Extend EventEmitter
|
|
|
96
96
|
debug = debug;
|
|
97
97
|
tokenizer = tokenizer;
|
|
98
98
|
chatSummary=chatSummary;
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
tools = codeboltTools;
|
|
100
|
+
agent = cbagent;
|
|
101
101
|
|
|
102
102
|
}
|
|
103
103
|
|