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