@blaxel/core 0.2.16-dev.102 → 0.2.16-dev.103
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 -5
- package/dist/mcp/client.js +35 -19
- 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,17 +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
16
|
if (isNode) {
|
|
19
17
|
try {
|
|
20
18
|
exports.fs = fs = eval("require")("fs");
|
|
21
19
|
exports.os = os = eval("require")("os");
|
|
22
20
|
exports.path = path = eval("require")("path");
|
|
23
21
|
exports.dotenv = dotenv = eval("require")("dotenv");
|
|
24
|
-
exports.ws = ws = eval("require")("ws");
|
|
25
22
|
}
|
|
26
23
|
catch (e) {
|
|
27
|
-
console.warn("fs
|
|
24
|
+
console.warn("fs and os are not available in this environment");
|
|
28
25
|
}
|
|
29
26
|
}
|
package/dist/mcp/client.js
CHANGED
|
@@ -3,14 +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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
}
|
|
14
23
|
//const SUBPROTOCOL = "mcp";
|
|
15
24
|
const MAX_RETRIES = 3;
|
|
16
25
|
const RETRY_DELAY_MS = 1000;
|
|
@@ -57,22 +66,21 @@ class BlaxelMcpClientTransport {
|
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
_connect() {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
60
70
|
return new Promise((resolve, reject) => {
|
|
61
71
|
try {
|
|
62
|
-
let url = this._url.toString();
|
|
63
72
|
if (this._isBrowser) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (isCloudflare || this._isBrowser) {
|
|
67
|
-
// Use native WebSocket (works in both browser and Cloudflare)
|
|
73
|
+
// Use native browser WebSocket
|
|
74
|
+
const url = `${this._url.toString()}?token=${settings_js_1.settings.token}`;
|
|
68
75
|
this._socket = new WebSocket(url);
|
|
69
76
|
}
|
|
70
77
|
else {
|
|
71
78
|
// Use Node.js WebSocket
|
|
72
|
-
if (!
|
|
79
|
+
if (!NodeWebSocket) {
|
|
73
80
|
throw new Error("WebSocket library not available in Node.js environment");
|
|
74
81
|
}
|
|
75
|
-
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
83
|
+
this._socket = new NodeWebSocket(this._url, {
|
|
76
84
|
//protocols: SUBPROTOCOL,
|
|
77
85
|
headers: this._headers,
|
|
78
86
|
});
|
|
@@ -80,9 +88,12 @@ class BlaxelMcpClientTransport {
|
|
|
80
88
|
this._socket.onerror = (event) => {
|
|
81
89
|
console.error(event);
|
|
82
90
|
const error = this._isBrowser
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
83
92
|
? new Error(`WebSocket error: ${event.message}`)
|
|
84
93
|
: "error" in event
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
85
95
|
? event.error
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
86
97
|
: new Error(`WebSocket error: ${event.message}`);
|
|
87
98
|
reject(error);
|
|
88
99
|
this.onerror?.(error);
|
|
@@ -101,9 +112,11 @@ class BlaxelMcpClientTransport {
|
|
|
101
112
|
if (this._isBrowser) {
|
|
102
113
|
// Browser WebSocket MessageEvent
|
|
103
114
|
const browserEvent = event;
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
104
116
|
dataString = typeof browserEvent.data === "string"
|
|
105
117
|
? browserEvent.data
|
|
106
|
-
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
119
|
+
: browserEvent.data.toString();
|
|
107
120
|
}
|
|
108
121
|
else {
|
|
109
122
|
// Node.js WebSocket MessageEvent
|
|
@@ -121,10 +134,13 @@ class BlaxelMcpClientTransport {
|
|
|
121
134
|
message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(dataString));
|
|
122
135
|
}
|
|
123
136
|
catch (error) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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}`);
|
|
128
144
|
this.onerror?.(error);
|
|
129
145
|
return;
|
|
130
146
|
}
|
|
@@ -134,7 +150,7 @@ class BlaxelMcpClientTransport {
|
|
|
134
150
|
catch (error) {
|
|
135
151
|
if (error instanceof Error && error.message.includes("ws does not work in the browser")) {
|
|
136
152
|
this._isBrowser = true;
|
|
137
|
-
this._connect().then(resolve).catch(reject);
|
|
153
|
+
return this._connect().then(resolve).catch(reject);
|
|
138
154
|
}
|
|
139
155
|
reject(error);
|
|
140
156
|
}
|