@blaxel/core 0.2.16-dev.102 → 0.2.16-dev.104

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.
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAgentMetadata = exports.blAgent = void 0;
4
4
  const index_js_1 = require("../cache/index.js");
5
5
  const index_js_2 = require("../client/index.js");
6
- const env_js_1 = require("../common/env.js");
7
6
  const internal_js_1 = require("../common/internal.js");
8
7
  const logger_js_1 = require("../common/logger.js");
9
8
  const settings_js_1 = require("../common/settings.js");
@@ -27,11 +26,7 @@ class BlAgent {
27
26
  return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
28
27
  }
29
28
  get forcedUrl() {
30
- const envVar = this.agentName.replace(/-/g, "_").toUpperCase();
31
- if (env_js_1.env[`BL_AGENT_${envVar}_URL`]) {
32
- return new URL(env_js_1.env[`BL_AGENT_${envVar}_URL`]);
33
- }
34
- return null;
29
+ return (0, internal_js_1.getForcedUrl)('function', this.agentName);
35
30
  }
36
31
  get url() {
37
32
  if (this.forcedUrl)
@@ -1,2 +1,4 @@
1
1
  export declare function getAlphanumericLimitedHash(input: string, maxSize?: number): string;
2
2
  export declare function getGlobalUniqueHash(workspace: string, type: string, name: string): string;
3
+ export declare function pluralize(type: string): string;
4
+ export declare function getForcedUrl(type: string, name: string): import("url").URL | null;
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ /* eslint-disable */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.getAlphanumericLimitedHash = getAlphanumericLimitedHash;
4
5
  exports.getGlobalUniqueHash = getGlobalUniqueHash;
5
- /* eslint-disable */
6
+ exports.pluralize = pluralize;
7
+ exports.getForcedUrl = getForcedUrl;
8
+ const process_1 = require("process");
6
9
  // Pure JS MD5 implementation that matches standard crypto MD5
7
10
  function md5(input) {
8
11
  function cmn(q, a, b, x, s, t) {
@@ -139,3 +142,47 @@ function getGlobalUniqueHash(workspace, type, name) {
139
142
  const globalUniqueName = `${workspace}-${type}-${name}`;
140
143
  return getAlphanumericLimitedHash(globalUniqueName, 48);
141
144
  }
145
+ function pluralize(type) {
146
+ const word = type.toLowerCase();
147
+ // Words ending in s, ss, sh, ch, x, z - add 'es'
148
+ if (word.endsWith('s') || word.endsWith('ss') || word.endsWith('sh') ||
149
+ word.endsWith('ch') || word.endsWith('x') || word.endsWith('z')) {
150
+ return type + 'es';
151
+ }
152
+ // Words ending in consonant + y - change y to ies
153
+ if (word.endsWith('y') && word.length > 1) {
154
+ const beforeY = word[word.length - 2];
155
+ if (!'aeiou'.includes(beforeY)) {
156
+ return type.slice(0, -1) + 'ies';
157
+ }
158
+ }
159
+ // Words ending in f or fe - change to ves
160
+ if (word.endsWith('f')) {
161
+ return type.slice(0, -1) + 'ves';
162
+ }
163
+ if (word.endsWith('fe')) {
164
+ return type.slice(0, -2) + 'ves';
165
+ }
166
+ // Words ending in consonant + o - add 'es'
167
+ if (word.endsWith('o') && word.length > 1) {
168
+ const beforeO = word[word.length - 2];
169
+ if (!'aeiou'.includes(beforeO)) {
170
+ return type + 'es';
171
+ }
172
+ }
173
+ // Default case - just add 's'
174
+ return type + 's';
175
+ }
176
+ function getForcedUrl(type, name) {
177
+ const pluralType = pluralize(type);
178
+ const envVar = name.replace(/-/g, "_").toUpperCase();
179
+ // BL_FUNCTIONS_NAME_URL
180
+ if (process_1.env[`BL_${pluralType.toUpperCase()}_${envVar}_URL`]) {
181
+ return new URL(process_1.env[`BL_${pluralType.toUpperCase()}_${envVar}_URL`]);
182
+ }
183
+ // BL_FUNCTION_NAME_URL
184
+ if (process_1.env[`BL_${type.toUpperCase()}_${envVar}_URL`]) {
185
+ return new URL(process_1.env[`BL_${type.toUpperCase()}_${envVar}_URL`]);
186
+ }
187
+ return null;
188
+ }
@@ -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
- declare let ws: typeof import("ws") | null;
6
- export { dotenv, fs, os, path, ws };
5
+ export { dotenv, fs, os, path };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ws = exports.path = exports.os = exports.fs = exports.dotenv = void 0;
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, os, path, dotenv, ws are not available in this environment");
24
+ console.warn("fs and os are not available in this environment");
28
25
  }
29
26
  }
package/dist/jobs/jobs.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.blJob = void 0;
4
- const env_js_1 = require("../common/env.js");
5
4
  const internal_js_1 = require("../common/internal.js");
6
5
  const logger_js_1 = require("../common/logger.js");
7
6
  const settings_js_1 = require("../common/settings.js");
@@ -25,11 +24,7 @@ class BlJob {
25
24
  return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
26
25
  }
27
26
  get forcedUrl() {
28
- const envVar = this.jobName.replace(/-/g, "_").toUpperCase();
29
- if (env_js_1.env[`BL_JOB_${envVar}_URL`]) {
30
- return new URL(env_js_1.env[`BL_JOB_${envVar}_URL`]);
31
- }
32
- return null;
27
+ return (0, internal_js_1.getForcedUrl)('job', this.jobName);
33
28
  }
34
29
  get url() {
35
30
  if (this.forcedUrl)
@@ -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
- 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;
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
- url += `?token=${settings_js_1.settings.token}`;
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 (!node_js_1.ws) {
79
+ if (!NodeWebSocket) {
73
80
  throw new Error("WebSocket library not available in Node.js environment");
74
81
  }
75
- this._socket = new node_js_1.ws(this._url, {
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
- : String(browserEvent.data);
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
- 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)}`);
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
  }
@@ -13,7 +13,7 @@ export declare class SandboxAction {
13
13
  get externalUrl(): string;
14
14
  get internalUrl(): string;
15
15
  get client(): import("@hey-api/client-fetch").Client;
16
- get forcedUrl(): string | null;
16
+ get forcedUrl(): string | import("url").URL | null;
17
17
  get url(): string;
18
18
  handleResponseError(response: Response, data: unknown, error: unknown): void;
19
19
  }
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SandboxAction = exports.ResponseError = void 0;
4
4
  const client_fetch_1 = require("@hey-api/client-fetch");
5
- const env_js_1 = require("../common/env.js");
6
5
  const internal_js_1 = require("../common/internal.js");
7
6
  const settings_js_1 = require("../common/settings.js");
8
7
  const client_gen_js_1 = require("./client/client.gen.js");
@@ -64,16 +63,11 @@ class SandboxAction {
64
63
  get forcedUrl() {
65
64
  if (this.sandbox.forceUrl)
66
65
  return this.sandbox.forceUrl;
67
- const envVar = this.name.replace(/-/g, "_").toUpperCase();
68
- const envName = `BL_SANDBOXES_${envVar}_URL`;
69
- if (env_js_1.env[envName]) {
70
- return env_js_1.env[envName];
71
- }
72
- return null;
66
+ return (0, internal_js_1.getForcedUrl)('sandbox', this.name);
73
67
  }
74
68
  get url() {
75
69
  if (this.forcedUrl)
76
- return this.forcedUrl;
70
+ return this.forcedUrl.toString();
77
71
  // Uncomment and use this when agent and mcp are available in mk3
78
72
  // Update all requests made in this package to use fallbackUrl when internalUrl is not working
79
73
  // if (settings.runInternalHostname) return this.internalUrl;
@@ -56,7 +56,7 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
56
56
  // Build URL
57
57
  let url = `${this.url}/filesystem/${path}`;
58
58
  if (this.forcedUrl) {
59
- url = `${this.forcedUrl}/filesystem/${path}`;
59
+ url = `${this.forcedUrl.toString()}/filesystem/${path}`;
60
60
  }
61
61
  // Make the request using fetch instead of axios for better FormData handling
62
62
  const response = await fetch(url, {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getToolMetadata = exports.blTool = exports.blTools = exports.BLTools = exports.getTool = void 0;
4
4
  const index_js_1 = require("../cache/index.js");
5
5
  const client_js_1 = require("../client/client.js");
6
- const env_js_1 = require("../common/env.js");
6
+ const internal_js_1 = require("../common/internal.js");
7
7
  const mcpTool_js_1 = require("./mcpTool.js");
8
8
  const getTool = async (name, ms) => {
9
9
  return await (0, mcpTool_js_1.getMcpTool)(name, ms);
@@ -25,8 +25,8 @@ const blTool = (name) => {
25
25
  };
26
26
  exports.blTool = blTool;
27
27
  const getToolMetadata = async (tool) => {
28
- const envVar = tool.replace(/-/g, "_").toUpperCase();
29
- if (env_js_1.env[`BL_FUNCTION_${envVar}_URL`]) {
28
+ const forcedUrl = (0, internal_js_1.getForcedUrl)('function', tool);
29
+ if (forcedUrl) {
30
30
  return {
31
31
  metadata: {
32
32
  name: tool,
@@ -58,11 +58,7 @@ class McpTool {
58
58
  return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
59
59
  }
60
60
  get forcedUrl() {
61
- const envVar = this.name.replace(/-/g, "_").toUpperCase();
62
- if (env_js_1.env[`BL_${this.pluralType.toUpperCase()}_${envVar}_URL`]) {
63
- return new URL(env_js_1.env[`BL_${this.pluralType.toUpperCase()}_${envVar}_URL`]);
64
- }
65
- return null;
61
+ return (0, internal_js_1.getForcedUrl)(this.type, this.name);
66
62
  }
67
63
  get url() {
68
64
  if (this.forcedUrl)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.16-dev.102",
3
+ "version": "0.2.16-dev.104",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",