@blaxel/core 0.2.42-preview.92 → 0.2.43-dev.194

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.
@@ -6,7 +6,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.authentication = authentication;
7
7
  const yaml_1 = __importDefault(require("yaml"));
8
8
  const env_js_1 = require("../common/env.js");
9
- const node_js_1 = require("../common/node.js");
9
+ let fs = null;
10
+ let os = null;
11
+ let path = null;
12
+ try {
13
+ const proc = typeof process !== "undefined" ? process : undefined;
14
+ const gw = typeof globalThis !== "undefined" ? globalThis : undefined;
15
+ const hasNodeVersions = (p) => {
16
+ if (typeof p !== "object" || p === null)
17
+ return false;
18
+ const anyP = p;
19
+ if (!("versions" in anyP))
20
+ return false;
21
+ const v = anyP["versions"];
22
+ return !!v && typeof v["node"] === "string";
23
+ };
24
+ const isNode = hasNodeVersions(proc);
25
+ const isBrowser = typeof gw === "object" && gw !== null && typeof gw.window !== "undefined";
26
+ if (isNode && !isBrowser) {
27
+ const req = eval("require");
28
+ fs = req("fs");
29
+ os = req("os");
30
+ path = req("path");
31
+ }
32
+ }
33
+ catch {
34
+ // ignore
35
+ }
10
36
  const apikey_js_1 = require("./apikey.js");
11
37
  const clientcredentials_js_1 = require("./clientcredentials.js");
12
38
  const credentials_js_1 = require("./credentials.js");
@@ -24,12 +50,12 @@ function getCredentials() {
24
50
  workspace: env_js_1.env.BL_WORKSPACE,
25
51
  };
26
52
  }
27
- if (node_js_1.os === null || node_js_1.fs === null || node_js_1.path === null) {
53
+ if (os === null || fs === null || path === null) {
28
54
  return null;
29
55
  }
30
56
  try {
31
- const homeDir = node_js_1.os.homedir();
32
- const config = node_js_1.fs.readFileSync(node_js_1.path.join(homeDir, ".blaxel/config.yaml"), "utf8");
57
+ const homeDir = os.homedir();
58
+ const config = fs.readFileSync(path.join(homeDir, ".blaxel/config.yaml"), "utf8");
33
59
  const configJson = yaml_1.default.parse(config);
34
60
  const workspaceName = env_js_1.env.BL_WORKSPACE || configJson.context.workspace;
35
61
  const credentials = configJson.workspaces.find((wk) => wk.name === workspaceName)?.credentials;
@@ -5,11 +5,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.findFromCache = findFromCache;
7
7
  const yaml_1 = __importDefault(require("yaml"));
8
- const node_js_1 = require("../common/node.js");
8
+ let fs = null;
9
+ try {
10
+ const isNode = typeof process !== "undefined" && typeof process.versions?.node === "string";
11
+ const isBrowser = typeof globalThis !== "undefined" && typeof globalThis?.window !== "undefined";
12
+ if (isNode && !isBrowser) {
13
+ const req = eval("require");
14
+ const loaded = req("fs");
15
+ fs = loaded;
16
+ }
17
+ }
18
+ catch {
19
+ // ignore
20
+ }
9
21
  const cache = new Map();
10
22
  try {
11
- if (node_js_1.fs) {
12
- const cacheString = node_js_1.fs.readFileSync(".cache.yaml", "utf8");
23
+ if (fs !== null) {
24
+ const cacheString = fs.readFileSync(".cache.yaml", "utf8");
13
25
  const cacheData = yaml_1.default.parseAllDocuments(cacheString);
14
26
  for (const doc of cacheData) {
15
27
  const jsonDoc = doc.toJSON();
@@ -6,12 +6,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.env = void 0;
7
7
  /* eslint-disable */
8
8
  const toml_1 = __importDefault(require("toml"));
9
- const node_js_1 = require("./node.js");
9
+ // Avoid importing Node built-ins in environments that don't support them (e.g., Next.js client build)
10
+ const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
11
+ const isBrowser = typeof globalThis !== "undefined" && globalThis?.window !== undefined;
12
+ let fs = null;
13
+ let dotenv = null;
14
+ if (isNode && !isBrowser) {
15
+ try {
16
+ // Use eval to avoid bundler static analysis of 'require(\"fs\")'
17
+ fs = eval("require")("fs");
18
+ }
19
+ catch { }
20
+ try {
21
+ dotenv = eval("require")("dotenv");
22
+ }
23
+ catch { }
24
+ }
10
25
  const secretEnv = {};
11
26
  const configEnv = {};
12
- if (node_js_1.fs !== null) {
27
+ if (fs !== null) {
13
28
  try {
14
- const configFile = node_js_1.fs.readFileSync("blaxel.toml", "utf8");
29
+ const configFile = fs.readFileSync("blaxel.toml", "utf8");
15
30
  const configInfos = toml_1.default.parse(configFile);
16
31
  for (const key in configInfos.env) {
17
32
  configEnv[key] = configInfos.env[key];
@@ -19,9 +34,9 @@ if (node_js_1.fs !== null) {
19
34
  }
20
35
  catch (error) { }
21
36
  try {
22
- const secretFile = node_js_1.fs.readFileSync(".env", "utf8");
23
- if (node_js_1.dotenv) {
24
- const parsed = node_js_1.dotenv.parse(secretFile);
37
+ const secretFile = fs.readFileSync(".env", "utf8");
38
+ if (dotenv) {
39
+ const parsed = dotenv.parse(secretFile);
25
40
  Object.assign(secretEnv, parsed);
26
41
  }
27
42
  else {
@@ -5,6 +5,8 @@ exports.getAlphanumericLimitedHash = getAlphanumericLimitedHash;
5
5
  exports.getGlobalUniqueHash = getGlobalUniqueHash;
6
6
  exports.pluralize = pluralize;
7
7
  exports.getForcedUrl = getForcedUrl;
8
+ exports.getWorkloadTypeShort = getWorkloadTypeShort;
9
+ exports.generateInternalUrl = generateInternalUrl;
8
10
  const env_js_1 = require("./env.js");
9
11
  // Pure JS MD5 implementation that matches standard crypto MD5
10
12
  function md5(input) {
@@ -186,3 +188,41 @@ function getForcedUrl(type, name) {
186
188
  }
187
189
  return null;
188
190
  }
191
+ function getWorkloadTypeShort(type) {
192
+ const lowerType = type.toLowerCase();
193
+ switch (lowerType) {
194
+ case 'agent':
195
+ case 'agents':
196
+ return 'agt';
197
+ case 'mcp':
198
+ case 'mcps':
199
+ case 'function':
200
+ case 'functions':
201
+ return 'mcp';
202
+ case 'sandbox':
203
+ case 'sandboxes':
204
+ return 'sbx';
205
+ case 'job':
206
+ case 'jobs':
207
+ return 'job';
208
+ case 'model':
209
+ case 'models':
210
+ return 'mdl';
211
+ default:
212
+ // fallback to first 3 letters of type
213
+ return lowerType.substring(0, 3);
214
+ }
215
+ }
216
+ function generateInternalUrl(workspace, type, name, env, protocol, hostname, blCloud, workspaceId) {
217
+ if (blCloud && workspaceId) {
218
+ // New cloud format: bl-ENV-WORKLOAD_CALLED_NAME-WORKLOAD_TYPE_SHORT-WORKSPACE_ID
219
+ const workloadTypeShort = getWorkloadTypeShort(type);
220
+ const subdomain = `bl-${env}-${name}-${workloadTypeShort}-${workspaceId}`;
221
+ return `${protocol}://${subdomain}.${hostname}`;
222
+ }
223
+ else {
224
+ // Legacy format: bl-ENV-HASH.internalhostname
225
+ const hash = getGlobalUniqueHash(workspace, type, name);
226
+ return `${protocol}://bl-${env}-${hash}.${hostname}`;
227
+ }
228
+ }
@@ -10,7 +10,7 @@ function getPackageVersion() {
10
10
  if (typeof require !== "undefined") {
11
11
  // Try to require package.json (Node.js only, gracefully fails in browser)
12
12
  // eslint-disable-next-line @typescript-eslint/no-require-imports
13
- const packageJson = {"version":"0.2.42-preview.92","commit":"c4cffc4d7268f062ee0d043334e2d7a6908ea177"};
13
+ const packageJson = {"version":"0.2.43-dev.194","commit":"eaaada70f38d291b78d12e2a295e9987cfc3d09b"};
14
14
  return packageJson.version || "unknown";
15
15
  }
16
16
  else {
@@ -64,7 +64,7 @@ function getCommitHash() {
64
64
  if (typeof require !== "undefined") {
65
65
  // Try to require package.json and look for commit field (set during build)
66
66
  // eslint-disable-next-line @typescript-eslint/no-require-imports
67
- const packageJson = {"version":"0.2.42-preview.92","commit":"c4cffc4d7268f062ee0d043334e2d7a6908ea177"};
67
+ const packageJson = {"version":"0.2.43-dev.194","commit":"eaaada70f38d291b78d12e2a295e9987cfc3d09b"};
68
68
  // Check for commit in various possible locations
69
69
  const commit = packageJson.commit || packageJson.buildInfo?.commit;
70
70
  if (commit) {
@@ -167,6 +167,9 @@ class Settings {
167
167
  get blCloud() {
168
168
  return env_js_1.env.BL_CLOUD === "true";
169
169
  }
170
+ get workspaceId() {
171
+ return env_js_1.env.BL_WORKSPACE_ID || "";
172
+ }
170
173
  get generation() {
171
174
  return env_js_1.env.BL_GENERATION || "";
172
175
  }
package/dist/cjs/index.js CHANGED
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getWebSocket = void 0;
18
17
  require("./common/autoload");
19
18
  __exportStar(require("./agents/index.js"), exports);
20
19
  __exportStar(require("./client/client.js"), exports);
@@ -23,8 +22,6 @@ __exportStar(require("./common/env.js"), exports);
23
22
  __exportStar(require("./common/errors.js"), exports);
24
23
  __exportStar(require("./common/internal.js"), exports);
25
24
  __exportStar(require("./common/logger.js"), exports);
26
- var node_js_1 = require("./common/node.js");
27
- Object.defineProperty(exports, "getWebSocket", { enumerable: true, get: function () { return node_js_1.getWebSocket; } });
28
25
  __exportStar(require("./common/settings.js"), exports);
29
26
  __exportStar(require("./jobs/index.js"), exports);
30
27
  __exportStar(require("./mcp/index.js"), exports);
@@ -20,8 +20,8 @@ class BlJob {
20
20
  return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/jobs/${this.jobName}`);
21
21
  }
22
22
  get internalUrl() {
23
- const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, "job", this.jobName);
24
- return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
23
+ const url = (0, internal_js_1.generateInternalUrl)(settings_js_1.settings.workspace, "job", this.jobName, settings_js_1.settings.env, settings_js_1.settings.runInternalProtocol, settings_js_1.settings.runInternalHostname, settings_js_1.settings.blCloud, settings_js_1.settings.workspaceId);
24
+ return new URL(url);
25
25
  }
26
26
  get forcedUrl() {
27
27
  return (0, internal_js_1.getForcedUrl)('job', this.jobName);
@@ -48,8 +48,7 @@ class SandboxAction {
48
48
  return this.sandbox.metadata?.url ?? `${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/sandboxes/${this.name}`;
49
49
  }
50
50
  get internalUrl() {
51
- const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, "sandbox", this.name);
52
- return `${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`;
51
+ return (0, internal_js_1.generateInternalUrl)(settings_js_1.settings.workspace, "sandbox", this.name, settings_js_1.settings.env, settings_js_1.settings.runInternalProtocol, settings_js_1.settings.runInternalHostname, settings_js_1.settings.blCloud, settings_js_1.settings.workspaceId);
53
52
  }
54
53
  get client() {
55
54
  if (this.sandbox.forceUrl) {
@@ -58,8 +58,8 @@ class McpTool {
58
58
  return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/${this.pluralType}/${this.name}`);
59
59
  }
60
60
  get internalUrl() {
61
- const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, this.type, this.name);
62
- return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
61
+ const url = (0, internal_js_1.generateInternalUrl)(settings_js_1.settings.workspace, this.type, this.name, settings_js_1.settings.env, settings_js_1.settings.runInternalProtocol, settings_js_1.settings.runInternalHostname, settings_js_1.settings.blCloud, settings_js_1.settings.workspaceId);
62
+ return new URL(url);
63
63
  }
64
64
  get forcedUrl() {
65
65
  return (0, internal_js_1.getForcedUrl)(this.type, this.name);
@@ -2,3 +2,5 @@ export declare function getAlphanumericLimitedHash(input: string, maxSize?: numb
2
2
  export declare function getGlobalUniqueHash(workspace: string, type: string, name: string): string;
3
3
  export declare function pluralize(type: string): string;
4
4
  export declare function getForcedUrl(type: string, name: string): import("url").URL | null;
5
+ export declare function getWorkloadTypeShort(type: string): string;
6
+ export declare function generateInternalUrl(workspace: string, type: string, name: string, env: string, protocol: string, hostname: string, blCloud: boolean, workspaceId: string): string;
@@ -23,6 +23,7 @@ declare class Settings {
23
23
  get runInternalHostname(): string;
24
24
  get runInternalProtocol(): string;
25
25
  get blCloud(): boolean;
26
+ get workspaceId(): string;
26
27
  get generation(): string;
27
28
  get loggerType(): string;
28
29
  authenticate(): Promise<void>;
@@ -6,7 +6,6 @@ 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";
10
9
  export * from "./common/settings.js";
11
10
  export * from "./jobs/index.js";
12
11
  export * from "./mcp/index.js";