@blaxel/core 0.2.73-preview.111 → 0.2.73

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.
@@ -9,8 +9,8 @@ const index_js_1 = require("../authentication/index.js");
9
9
  const env_js_1 = require("../common/env.js");
10
10
  const node_js_1 = require("../common/node.js");
11
11
  // Build info - these placeholders are replaced at build time by build:replace-imports
12
- const BUILD_VERSION = "0.2.73-preview.111";
13
- const BUILD_COMMIT = "be898ba36d0cf6922cdfac1bd3795180c34f14f4";
12
+ const BUILD_VERSION = "0.2.73";
13
+ const BUILD_COMMIT = "ca69d9d46e02efafefc83f2fe96e377b857b493a";
14
14
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
15
15
  // Cache for config.yaml tracking value
16
16
  let configTrackingValue = null;
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getToolMetadata = exports.blTool = exports.blTools = exports.BLTools = exports.getTool = void 0;
4
- const index_js_1 = require("../cache/index.js");
5
- const client_js_1 = require("../client/client.js");
6
- const internal_js_1 = require("../common/internal.js");
3
+ exports.blTool = exports.blTools = exports.BLTools = exports.getTool = void 0;
7
4
  const mcpTool_js_1 = require("./mcpTool.js");
8
5
  const getTool = async (name, options) => {
9
6
  return await (0, mcpTool_js_1.getMcpTool)(name, options);
@@ -24,27 +21,3 @@ const blTool = (name) => {
24
21
  return new BLTools([name]);
25
22
  };
26
23
  exports.blTool = blTool;
27
- const getToolMetadata = async (tool) => {
28
- const forcedUrl = (0, internal_js_1.getForcedUrl)('function', tool);
29
- if (forcedUrl) {
30
- return {
31
- metadata: {
32
- name: tool,
33
- },
34
- spec: {
35
- runtime: {},
36
- },
37
- };
38
- }
39
- const cacheData = await (0, index_js_1.findFromCache)("Function", tool);
40
- if (cacheData) {
41
- return cacheData;
42
- }
43
- const { data } = await (0, client_js_1.getFunction)({
44
- path: {
45
- functionName: tool,
46
- },
47
- });
48
- return data || null;
49
- };
50
- exports.getToolMetadata = getToolMetadata;
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getMcpTool = exports.McpTool = void 0;
4
4
  const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
5
5
  const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
6
+ const index_js_2 = require("../client/index.js");
6
7
  const env_js_1 = require("../common/env.js");
7
8
  const internal_js_1 = require("../common/internal.js");
8
9
  const logger_js_1 = require("../common/logger.js");
9
10
  const settings_js_1 = require("../common/settings.js");
10
- const index_js_2 = require("../index.js");
11
- const client_js_1 = require("../mcp/client.js");
11
+ const index_js_3 = require("../index.js");
12
12
  const telemetry_js_1 = require("../telemetry/telemetry.js");
13
13
  const zodSchema_js_1 = require("./zodSchema.js");
14
14
  const McpToolCache = new Map();
@@ -17,12 +17,11 @@ class McpTool {
17
17
  type;
18
18
  pluralType;
19
19
  client;
20
- transport;
21
20
  timer;
22
21
  ms;
23
- transportName;
24
22
  meta;
25
23
  startPromise;
24
+ metadataUrl;
26
25
  constructor(name, options = { ms: 5000 }) {
27
26
  this.name = name;
28
27
  this.type = "function";
@@ -44,69 +43,60 @@ class McpTool {
44
43
  version: "1.0.0",
45
44
  });
46
45
  }
47
- get fallbackUrl() {
48
- if (this.externalUrl != this.url) {
49
- return this.externalUrl;
50
- }
51
- return null;
46
+ get forcedUrl() {
47
+ return (0, internal_js_1.getForcedUrl)(this.type, this.name);
52
48
  }
53
49
  get externalUrl() {
54
50
  return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/${this.pluralType}/${this.name}`);
55
51
  }
56
- get internalUrl() {
57
- const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, this.type, this.name);
58
- return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
59
- }
60
- get forcedUrl() {
61
- return (0, internal_js_1.getForcedUrl)(this.type, this.name);
52
+ async fetchMetadataUrl() {
53
+ try {
54
+ if (this.type === "sandbox") {
55
+ const { data } = await (0, index_js_2.getSandbox)({ path: { sandboxName: this.name } });
56
+ if (data?.metadata?.url)
57
+ return data.metadata.url;
58
+ }
59
+ else {
60
+ const { data } = await (0, index_js_2.getFunction)({ path: { functionName: this.name } });
61
+ if (data?.metadata?.url)
62
+ return data.metadata.url;
63
+ }
64
+ }
65
+ catch (err) {
66
+ const message = err instanceof Error ? err.message : String(err);
67
+ logger_js_1.logger.debug(`Failed to fetch metadata URL for ${this.name}: ${message}`);
68
+ }
69
+ return null;
62
70
  }
63
- get url() {
64
- if (this.forcedUrl)
71
+ async resolveUrl() {
72
+ if (this.forcedUrl) {
73
+ logger_js_1.logger.debug(`MCP:${this.name}:ForcedURL:${this.forcedUrl.toString()}`);
65
74
  return this.forcedUrl;
66
- if (settings_js_1.settings.runInternalHostname)
67
- return this.internalUrl;
75
+ }
76
+ if (this.metadataUrl === undefined) {
77
+ this.metadataUrl = await this.fetchMetadataUrl();
78
+ }
79
+ if (this.metadataUrl) {
80
+ logger_js_1.logger.debug(`MCP:${this.name}:MetadataURL:${this.metadataUrl}`);
81
+ return new URL(this.metadataUrl);
82
+ }
83
+ logger_js_1.logger.debug(`MCP:${this.name}:FallingBackToExternalURL:${this.externalUrl.toString()}`);
68
84
  return this.externalUrl;
69
85
  }
70
86
  async start() {
71
87
  logger_js_1.logger.debug(`MCP:${this.name}:start`);
72
88
  this.stopCloseTimer();
73
89
  this.startPromise = this.startPromise || (async () => {
74
- await (0, index_js_2.authenticate)();
75
- // Sandbox using run v2 API
76
- if (this.pluralType == "sandboxes") {
77
- const sandbox = await index_js_2.SandboxInstance.get(this.name);
78
- const url = sandbox.metadata.url + "/mcp";
79
- this.transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(url), {
80
- requestInit: { headers: settings_js_1.settings.headers },
81
- });
82
- await this.client.connect(this.transport);
83
- logger_js_1.logger.debug(`MCP:${this.name}:Connected to sandbox`);
84
- return;
85
- }
86
- try {
87
- logger_js_1.logger.debug(`MCP:${this.name}:Connecting::${this.url.toString()}`);
88
- this.transport = await this.getTransport();
89
- await this.client.connect(this.transport);
90
- logger_js_1.logger.debug(`MCP:${this.name}:Connected`);
91
- }
92
- catch (err) {
93
- if (err instanceof Error) {
94
- logger_js_1.logger.error(`MCP ${this.name} connection failed: ${err.message}`, {
95
- error: err.message,
96
- stack: err.stack,
97
- mcpName: this.name,
98
- url: this.url
99
- });
100
- }
101
- if (!this.fallbackUrl) {
102
- throw err;
103
- }
104
- logger_js_1.logger.debug(`MCP:${this.name}:Connecting to fallback`);
105
- this.transportName = undefined;
106
- this.transport = await this.getTransport(this.fallbackUrl);
107
- await this.client.connect(this.transport);
108
- logger_js_1.logger.debug(`MCP:${this.name}:Connected to fallback`);
109
- }
90
+ await (0, index_js_3.authenticate)();
91
+ const url = await this.resolveUrl();
92
+ const mcpUrl = new URL(url.toString());
93
+ mcpUrl.pathname = mcpUrl.pathname.replace(/\/$/, "") + "/mcp";
94
+ logger_js_1.logger.debug(`MCP:${this.name}:Connecting::${mcpUrl.toString()}`);
95
+ const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(mcpUrl, {
96
+ requestInit: { headers: settings_js_1.settings.headers },
97
+ });
98
+ await this.client.connect(transport);
99
+ logger_js_1.logger.debug(`MCP:${this.name}:Connected`);
110
100
  })();
111
101
  return await this.startPromise;
112
102
  }
@@ -127,7 +117,7 @@ class McpTool {
127
117
  logger_js_1.logger.error(`MCP ${this.name} close failed: ${err.message}`, {
128
118
  error: err.message,
129
119
  stack: err.stack,
130
- mcpName: this.name
120
+ mcpName: this.name,
131
121
  });
132
122
  }
133
123
  });
@@ -184,17 +174,13 @@ class McpTool {
184
174
  });
185
175
  try {
186
176
  logger_js_1.logger.debug(`MCP:${this.name}:Tool calling`, toolName, JSON.stringify(args));
187
- logger_js_1.logger.debug(`MCP:${this.name}:Tool calling:start`);
188
177
  await this.start();
189
- logger_js_1.logger.debug(`MCP:${this.name}:Tool calling:start2`);
190
178
  const result = await this.client.callTool({
191
179
  name: toolName,
192
180
  arguments: args,
193
- _meta: this.meta
181
+ _meta: this.meta,
194
182
  });
195
- logger_js_1.logger.debug(`MCP:${this.name}:Tool calling:result`);
196
183
  await this.close();
197
- logger_js_1.logger.debug(`MCP:${this.name}:Tool result`, toolName, JSON.stringify(args));
198
184
  span.setAttribute("tool.call.result", JSON.stringify(result));
199
185
  return result;
200
186
  }
@@ -205,7 +191,7 @@ class McpTool {
205
191
  stack: err.stack,
206
192
  mcpName: this.name,
207
193
  toolName,
208
- args: JSON.stringify(args)
194
+ args: JSON.stringify(args),
209
195
  });
210
196
  }
211
197
  throw err;
@@ -214,40 +200,6 @@ class McpTool {
214
200
  span.end();
215
201
  }
216
202
  }
217
- async getTransport(forcedUrl) {
218
- if (!this.transportName) {
219
- // Detect transport type dynamically by querying the function's endpoint
220
- try {
221
- const testUrl = (forcedUrl || this.url).toString();
222
- const response = await fetch(testUrl + "/", {
223
- method: "GET",
224
- headers: settings_js_1.settings.headers,
225
- });
226
- const responseText = await response.text();
227
- if (responseText.toLowerCase().includes("websocket")) {
228
- this.transportName = "websocket";
229
- }
230
- else {
231
- this.transportName = "http-stream";
232
- }
233
- logger_js_1.logger.debug(`Detected transport type for ${this.name}: ${this.transportName}`);
234
- }
235
- catch (error) {
236
- // Default to websocket if we can't determine the transport type
237
- const message = error instanceof Error ? error.message : String(error);
238
- logger_js_1.logger.warn(`Failed to detect transport type for ${this.name}: ${message}. Defaulting to websocket.`);
239
- this.transportName = "websocket";
240
- }
241
- }
242
- const url = forcedUrl || this.url;
243
- if (this.transportName === "http-stream") {
244
- url.pathname = url.pathname + "/mcp";
245
- return new streamableHttp_js_1.StreamableHTTPClientTransport(url, { requestInit: { headers: settings_js_1.settings.headers } });
246
- }
247
- else {
248
- return new client_js_1.BlaxelMcpClientTransport(url.toString(), settings_js_1.settings.headers, { retry: { max: 0 } });
249
- }
250
- }
251
203
  }
252
204
  exports.McpTool = McpTool;
253
205
  const getMcpTool = async (name, options) => {
@@ -1,4 +1,3 @@
1
- import { Function } from "../client/client.js";
2
1
  import { ToolOptions } from "./mcpTool.js";
3
2
  import { Tool } from "./types.js";
4
3
  export type { ToolOptions };
@@ -9,4 +8,3 @@ export declare class BLTools {
9
8
  }
10
9
  export declare const blTools: (names: string[]) => BLTools;
11
10
  export declare const blTool: (name: string) => BLTools;
12
- export declare const getToolMetadata: (tool: string) => Promise<Function | null>;
@@ -1,33 +1,27 @@
1
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
2
- import { BlaxelMcpClientTransport } from "../mcp/client.js";
3
1
  import { Tool } from "./types.js";
4
2
  export type ToolOptions = {
5
3
  ms?: number;
6
4
  meta?: Record<string, unknown> | undefined;
7
- transport?: string;
8
5
  };
9
6
  export declare class McpTool {
10
7
  private name;
11
8
  private type;
12
9
  private pluralType;
13
10
  private client;
14
- private transport?;
15
11
  private timer?;
16
12
  private ms;
17
- private transportName?;
18
13
  private meta;
19
14
  private startPromise?;
15
+ private metadataUrl?;
20
16
  constructor(name: string, options?: ToolOptions | number);
21
- get fallbackUrl(): import("url").URL | null;
22
- get externalUrl(): import("url").URL;
23
- get internalUrl(): import("url").URL;
24
- get forcedUrl(): import("url").URL | null;
25
- get url(): import("url").URL;
17
+ get forcedUrl(): URL | null;
18
+ get externalUrl(): URL;
19
+ private fetchMetadataUrl;
20
+ private resolveUrl;
26
21
  start(): Promise<void>;
27
22
  close(now?: boolean): Promise<void>;
28
23
  stopCloseTimer(): void;
29
24
  listTools(): Promise<Tool[]>;
30
25
  call(toolName: string, args: Record<string, unknown> | undefined): Promise<unknown>;
31
- getTransport(forcedUrl?: URL): Promise<BlaxelMcpClientTransport | StreamableHTTPClientTransport>;
32
26
  }
33
27
  export declare const getMcpTool: (name: string, options?: ToolOptions | number) => Promise<Tool[]>;