@blaxel/core 0.2.16-dev.99 → 0.2.16-preview.34
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/dist/common/node.d.ts +1 -2
- package/dist/common/node.js +2 -15
- package/dist/mcp/client.js +33 -10
- package/package.json +1 -1
package/dist/common/node.d.ts
CHANGED
|
@@ -2,5 +2,4 @@ declare let fs: typeof import("fs") | null;
|
|
|
2
2
|
declare let os: typeof import("os") | null;
|
|
3
3
|
declare let path: typeof import("path") | null;
|
|
4
4
|
declare let dotenv: typeof import("dotenv") | null;
|
|
5
|
-
|
|
6
|
-
export { dotenv, fs, os, path, ws };
|
|
5
|
+
export { dotenv, fs, os, path };
|
package/dist/common/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.path = exports.os = exports.fs = exports.dotenv = void 0;
|
|
4
4
|
/* eslint-disable */
|
|
5
5
|
const isNode = typeof process !== "undefined" &&
|
|
6
6
|
process.versions != null &&
|
|
@@ -13,27 +13,14 @@ let path = null;
|
|
|
13
13
|
exports.path = path;
|
|
14
14
|
let dotenv = null;
|
|
15
15
|
exports.dotenv = dotenv;
|
|
16
|
-
let ws = null;
|
|
17
|
-
exports.ws = ws;
|
|
18
|
-
const isBrowser = typeof globalThis !== "undefined" && globalThis && globalThis.window !== undefined;
|
|
19
16
|
if (isNode) {
|
|
20
17
|
try {
|
|
21
18
|
exports.fs = fs = eval("require")("fs");
|
|
22
19
|
exports.os = os = eval("require")("os");
|
|
23
20
|
exports.path = path = eval("require")("path");
|
|
24
21
|
exports.dotenv = dotenv = eval("require")("dotenv");
|
|
25
|
-
exports.ws = ws = eval("require")("ws");
|
|
26
22
|
}
|
|
27
23
|
catch (e) {
|
|
28
|
-
console.warn("fs
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
// cloudflare
|
|
32
|
-
else if (!isBrowser) {
|
|
33
|
-
try {
|
|
34
|
-
exports.ws = ws = eval("require")("ws");
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
console.warn("ws is not available in this environment");
|
|
24
|
+
console.warn("fs and os are not available in this environment");
|
|
38
25
|
}
|
|
39
26
|
}
|
package/dist/mcp/client.js
CHANGED
|
@@ -3,10 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BlaxelMcpClientTransport = void 0;
|
|
4
4
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
5
5
|
const logger_js_1 = require("../common/logger.js");
|
|
6
|
-
const node_js_1 = require("../common/node.js");
|
|
7
6
|
const settings_js_1 = require("../common/settings.js");
|
|
8
7
|
// Detect environment
|
|
9
|
-
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
9
|
+
const isBrowser = typeof globalThis !== "undefined" && globalThis.window !== undefined;
|
|
10
|
+
// Conditional import for Node.js WebSocket
|
|
11
|
+
let NodeWebSocket;
|
|
12
|
+
if (!isBrowser) {
|
|
13
|
+
try {
|
|
14
|
+
// Dynamic import for Node.js environment
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports
|
|
16
|
+
NodeWebSocket = require("ws");
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
console.warn("ws is not available in this environment");
|
|
20
|
+
// ws is not available
|
|
21
|
+
}
|
|
22
|
+
}
|
|
10
23
|
//const SUBPROTOCOL = "mcp";
|
|
11
24
|
const MAX_RETRIES = 3;
|
|
12
25
|
const RETRY_DELAY_MS = 1000;
|
|
@@ -53,6 +66,7 @@ class BlaxelMcpClientTransport {
|
|
|
53
66
|
}
|
|
54
67
|
}
|
|
55
68
|
_connect() {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
56
70
|
return new Promise((resolve, reject) => {
|
|
57
71
|
try {
|
|
58
72
|
if (this._isBrowser) {
|
|
@@ -62,10 +76,11 @@ class BlaxelMcpClientTransport {
|
|
|
62
76
|
}
|
|
63
77
|
else {
|
|
64
78
|
// Use Node.js WebSocket
|
|
65
|
-
if (!
|
|
79
|
+
if (!NodeWebSocket) {
|
|
66
80
|
throw new Error("WebSocket library not available in Node.js environment");
|
|
67
81
|
}
|
|
68
|
-
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
83
|
+
this._socket = new NodeWebSocket(this._url, {
|
|
69
84
|
//protocols: SUBPROTOCOL,
|
|
70
85
|
headers: this._headers,
|
|
71
86
|
});
|
|
@@ -73,9 +88,12 @@ class BlaxelMcpClientTransport {
|
|
|
73
88
|
this._socket.onerror = (event) => {
|
|
74
89
|
console.error(event);
|
|
75
90
|
const error = this._isBrowser
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
76
92
|
? new Error(`WebSocket error: ${event.message}`)
|
|
77
93
|
: "error" in event
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
78
95
|
? event.error
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
79
97
|
: new Error(`WebSocket error: ${event.message}`);
|
|
80
98
|
reject(error);
|
|
81
99
|
this.onerror?.(error);
|
|
@@ -94,9 +112,11 @@ class BlaxelMcpClientTransport {
|
|
|
94
112
|
if (this._isBrowser) {
|
|
95
113
|
// Browser WebSocket MessageEvent
|
|
96
114
|
const browserEvent = event;
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
97
116
|
dataString = typeof browserEvent.data === "string"
|
|
98
117
|
? browserEvent.data
|
|
99
|
-
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
119
|
+
: browserEvent.data.toString();
|
|
100
120
|
}
|
|
101
121
|
else {
|
|
102
122
|
// Node.js WebSocket MessageEvent
|
|
@@ -114,10 +134,13 @@ class BlaxelMcpClientTransport {
|
|
|
114
134
|
message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(dataString));
|
|
115
135
|
}
|
|
116
136
|
catch (error) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
137
|
+
logger_js_1.logger.error(`Error parsing message: ${
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
139
|
+
typeof event.data === "object"
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
141
|
+
? JSON.stringify(event.data)
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
143
|
+
: event.data}`);
|
|
121
144
|
this.onerror?.(error);
|
|
122
145
|
return;
|
|
123
146
|
}
|
|
@@ -127,7 +150,7 @@ class BlaxelMcpClientTransport {
|
|
|
127
150
|
catch (error) {
|
|
128
151
|
if (error instanceof Error && error.message.includes("ws does not work in the browser")) {
|
|
129
152
|
this._isBrowser = true;
|
|
130
|
-
this._connect().then(resolve).catch(reject);
|
|
153
|
+
return this._connect().then(resolve).catch(reject);
|
|
131
154
|
}
|
|
132
155
|
reject(error);
|
|
133
156
|
}
|