@blaxel/core 0.2.39 → 0.2.40-preview.88
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/common/env.js +15 -3
- package/dist/cjs/common/node.js +42 -18
- package/dist/cjs/common/settings.js +2 -2
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/mcp/client.js +99 -100
- package/dist/cjs/types/common/node.d.ts +2 -2
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/common/env.js +15 -3
- package/dist/esm/common/node.js +40 -16
- package/dist/esm/common/settings.js +2 -2
- package/dist/esm/index.js +1 -0
- package/dist/esm/mcp/client.js +100 -101
- package/package.json +2 -2
|
@@ -7,7 +7,7 @@ function getPackageVersion() {
|
|
|
7
7
|
if (typeof require !== "undefined") {
|
|
8
8
|
// Try to require package.json (Node.js only, gracefully fails in browser)
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
10
|
-
const packageJson = {"version":"0.2.
|
|
10
|
+
const packageJson = {"version":"0.2.40-preview.88","commit":"16853df8d96d89c029e321ba953f1cef77be5ab3"};
|
|
11
11
|
return packageJson.version || "unknown";
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
@@ -61,7 +61,7 @@ function getCommitHash() {
|
|
|
61
61
|
if (typeof require !== "undefined") {
|
|
62
62
|
// Try to require package.json and look for commit field (set during build)
|
|
63
63
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
64
|
-
const packageJson = {"version":"0.2.
|
|
64
|
+
const packageJson = {"version":"0.2.40-preview.88","commit":"16853df8d96d89c029e321ba953f1cef77be5ab3"};
|
|
65
65
|
// Check for commit in various possible locations
|
|
66
66
|
const commit = packageJson.commit || packageJson.buildInfo?.commit;
|
|
67
67
|
if (commit) {
|
package/dist/esm/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./common/env.js";
|
|
|
6
6
|
export * from "./common/errors.js";
|
|
7
7
|
export * from "./common/internal.js";
|
|
8
8
|
export * from "./common/logger.js";
|
|
9
|
+
export { getWebSocket } from "./common/node.js";
|
|
9
10
|
export * from "./common/settings.js";
|
|
10
11
|
export * from "./jobs/index.js";
|
|
11
12
|
export * from "./mcp/index.js";
|
package/dist/esm/mcp/client.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { JSONRPCMessageSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
import { logger } from "../common/logger.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getWebSocket } from "../common/node.js";
|
|
4
4
|
import { settings } from "../common/settings.js";
|
|
5
|
-
//
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
7
|
-
const NodeWebSocket = ws;
|
|
5
|
+
// WebSocket will be loaded dynamically via getWebSocket() function
|
|
8
6
|
//const SUBPROTOCOL = "mcp";
|
|
9
7
|
// Helper function to wait
|
|
10
8
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -54,113 +52,114 @@ export class BlaxelMcpClientTransport {
|
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
|
-
_connect() {
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
55
|
+
async _connect() {
|
|
59
56
|
return new Promise((resolve, reject) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
else {
|
|
67
|
-
// Use Node.js WebSocket
|
|
68
|
-
if (!NodeWebSocket) {
|
|
69
|
-
throw new Error("WebSocket library not available in Node.js environment");
|
|
57
|
+
const setupConnection = async () => {
|
|
58
|
+
try {
|
|
59
|
+
if (this._isBrowser) {
|
|
60
|
+
// Use native browser WebSocket
|
|
61
|
+
const url = `${this._url.toString()}?token=${settings.token}`;
|
|
62
|
+
this._socket = new WebSocket(url);
|
|
70
63
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
? event.error
|
|
64
|
+
else {
|
|
65
|
+
// Use Node.js WebSocket - get it via the centralized async function
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
67
|
+
const NodeWebSocket = await getWebSocket();
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
69
|
+
this._socket = new NodeWebSocket(this._url, {
|
|
70
|
+
//protocols: SUBPROTOCOL,
|
|
71
|
+
headers: this._headers,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
this._socket.onerror = (event) => {
|
|
75
|
+
// Log websocket error with meaningful information instead of raw event
|
|
76
|
+
const errorInfo = {
|
|
77
|
+
type: 'WebSocket Error',
|
|
78
|
+
url: this._url.toString(),
|
|
79
|
+
readyState: this._socket?.readyState,
|
|
80
|
+
browser: this._isBrowser,
|
|
81
|
+
// Extract any available error details from the event
|
|
82
|
+
eventType: event && typeof event === 'object' && 'type' in event
|
|
83
|
+
? String(event.type)
|
|
84
|
+
: 'unknown',
|
|
85
|
+
// Browser events might have different properties than Node.js
|
|
86
|
+
message: this._isBrowser && event && typeof event === 'object' && 'message' in event
|
|
87
|
+
? String(event.message)
|
|
88
|
+
: undefined,
|
|
89
|
+
error: !this._isBrowser && event && typeof event === 'object' && 'error' in event
|
|
90
|
+
? String(event.error)
|
|
91
|
+
: undefined
|
|
92
|
+
};
|
|
93
|
+
logger.error('WebSocket connection error', errorInfo);
|
|
94
|
+
const error = this._isBrowser
|
|
103
95
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this._socket =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
dataString
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
dataString = nodeEvent.data;
|
|
133
|
-
}
|
|
134
|
-
else if (nodeEvent.data instanceof Buffer) {
|
|
135
|
-
dataString = nodeEvent.data.toString("utf-8");
|
|
96
|
+
? new Error(`WebSocket error: ${event.message}`)
|
|
97
|
+
: "error" in event
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
99
|
+
? event.error
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
101
|
+
: new Error(`WebSocket error: ${event.message}`);
|
|
102
|
+
reject(error);
|
|
103
|
+
this.onerror?.(error);
|
|
104
|
+
};
|
|
105
|
+
this._socket.onopen = () => {
|
|
106
|
+
resolve();
|
|
107
|
+
};
|
|
108
|
+
this._socket.onclose = () => {
|
|
109
|
+
this.onclose?.();
|
|
110
|
+
this._socket = undefined;
|
|
111
|
+
};
|
|
112
|
+
this._socket.onmessage = (event) => {
|
|
113
|
+
let message;
|
|
114
|
+
try {
|
|
115
|
+
let dataString;
|
|
116
|
+
if (this._isBrowser) {
|
|
117
|
+
// Browser WebSocket MessageEvent
|
|
118
|
+
const browserEvent = event;
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
120
|
+
dataString = typeof browserEvent.data === "string"
|
|
121
|
+
? browserEvent.data
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
123
|
+
: browserEvent.data.toString();
|
|
136
124
|
}
|
|
137
125
|
else {
|
|
138
|
-
|
|
126
|
+
// Node.js WebSocket MessageEvent
|
|
127
|
+
const nodeEvent = event;
|
|
128
|
+
if (typeof nodeEvent.data === "string") {
|
|
129
|
+
dataString = nodeEvent.data;
|
|
130
|
+
}
|
|
131
|
+
else if (nodeEvent.data instanceof Buffer) {
|
|
132
|
+
dataString = nodeEvent.data.toString("utf-8");
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
throw new Error("Unsupported data type for event.data");
|
|
136
|
+
}
|
|
139
137
|
}
|
|
138
|
+
message = JSONRPCMessageSchema.parse(JSON.parse(dataString));
|
|
140
139
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
catch (error) {
|
|
144
|
-
logger.error(`Error parsing message: ${
|
|
145
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
146
|
-
typeof event.data === "object"
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
148
|
-
? JSON.stringify(event.data)
|
|
140
|
+
catch (error) {
|
|
141
|
+
logger.error(`Error parsing message: ${
|
|
149
142
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
143
|
+
typeof event.data === "object"
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
145
|
+
? JSON.stringify(event.data)
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
147
|
+
: event.data}`);
|
|
148
|
+
this.onerror?.(error);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
this.onmessage?.(message);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (error instanceof Error && error.message.includes("ws does not work in the browser")) {
|
|
156
|
+
this._isBrowser = true;
|
|
157
|
+
return this._connect().then(resolve).catch(reject);
|
|
153
158
|
}
|
|
154
|
-
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
catch (error) {
|
|
158
|
-
if (error instanceof Error && error.message.includes("ws does not work in the browser")) {
|
|
159
|
-
this._isBrowser = true;
|
|
160
|
-
return this._connect().then(resolve).catch(reject);
|
|
159
|
+
reject(error);
|
|
161
160
|
}
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
};
|
|
162
|
+
setupConnection().catch(reject);
|
|
164
163
|
});
|
|
165
164
|
}
|
|
166
165
|
get isConnected() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.40-preview.88",
|
|
4
4
|
"description": "Blaxel Core SDK for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blaxel, INC (https://blaxel.ai)",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"vite": "^5.2.0",
|
|
64
64
|
"vitest": "^1.5.0"
|
|
65
65
|
},
|
|
66
|
-
"commit": "
|
|
66
|
+
"commit": "16853df8d96d89c029e321ba953f1cef77be5ab3",
|
|
67
67
|
"scripts": {
|
|
68
68
|
"lint": "eslint src/",
|
|
69
69
|
"dev": "tsc --watch",
|