@blaxel/core 0.2.36-dev.185 → 0.2.36-dev.190
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 -0
- package/dist/{common → cjs/common}/settings.js +2 -2
- package/dist/{tools → cjs/types/tools}/index.d.ts +1 -0
- package/dist/esm/.tsbuildinfo +1 -0
- package/dist/esm/agents/index.js +104 -0
- package/dist/esm/authentication/apikey.js +20 -0
- package/dist/esm/authentication/clientcredentials.js +81 -0
- package/dist/esm/authentication/credentials.js +13 -0
- package/dist/esm/authentication/deviceMode.js +66 -0
- package/dist/esm/authentication/index.js +56 -0
- package/dist/esm/authentication/types.js +1 -0
- package/dist/esm/cache/index.js +20 -0
- package/dist/esm/client/authentication.js +11 -0
- package/dist/esm/client/client.gen.js +5 -0
- package/dist/esm/client/client.js +1 -0
- package/dist/esm/client/index.js +3 -0
- package/dist/esm/client/interceptors.js +14 -0
- package/dist/esm/client/sdk.gen.js +1649 -0
- package/dist/esm/client/types.gen.js +3 -0
- package/dist/esm/common/autoload.js +23 -0
- package/dist/esm/common/env.js +36 -0
- package/dist/esm/common/errors.js +14 -0
- package/dist/esm/common/internal.js +182 -0
- package/dist/esm/common/internal.test.js +37 -0
- package/dist/esm/common/logger.js +65 -0
- package/dist/esm/common/node.js +20 -0
- package/dist/esm/common/settings.js +167 -0
- package/dist/esm/index.browser.test.js +10 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/jobs/index.js +3 -0
- package/dist/esm/jobs/jobs.js +86 -0
- package/dist/esm/jobs/start.js +62 -0
- package/dist/esm/jobs/types.js +1 -0
- package/dist/esm/mcp/client.js +243 -0
- package/dist/esm/mcp/index.js +2 -0
- package/dist/esm/mcp/server.js +176 -0
- package/dist/esm/models/index.js +25 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/sandbox/action.js +79 -0
- package/dist/esm/sandbox/client/client.gen.js +3 -0
- package/dist/esm/sandbox/client/index.js +3 -0
- package/dist/esm/sandbox/client/sdk.gen.js +270 -0
- package/dist/esm/sandbox/client/types.gen.js +2 -0
- package/dist/esm/sandbox/filesystem/filesystem.js +272 -0
- package/dist/esm/sandbox/filesystem/index.js +2 -0
- package/dist/esm/sandbox/filesystem/types.js +1 -0
- package/dist/esm/sandbox/index.js +7 -0
- package/dist/esm/sandbox/network/index.js +1 -0
- package/dist/esm/sandbox/network/network.js +6 -0
- package/dist/esm/sandbox/preview.js +141 -0
- package/dist/esm/sandbox/process/index.js +1 -0
- package/dist/esm/sandbox/process/process.js +185 -0
- package/dist/esm/sandbox/sandbox.js +174 -0
- package/dist/esm/sandbox/session.js +119 -0
- package/dist/esm/sandbox/types.js +76 -0
- package/dist/esm/telemetry/telemetry.js +74 -0
- package/dist/esm/tools/index.js +44 -0
- package/dist/esm/tools/mcpTool.js +213 -0
- package/dist/esm/tools/types.js +1 -0
- package/dist/esm/tools/zodSchema.js +43 -0
- package/dist/esm/volume/index.js +109 -0
- package/package.json +17 -30
- /package/dist/{agents → cjs/agents}/index.js +0 -0
- /package/dist/{authentication → cjs/authentication}/apikey.js +0 -0
- /package/dist/{authentication → cjs/authentication}/clientcredentials.js +0 -0
- /package/dist/{authentication → cjs/authentication}/credentials.js +0 -0
- /package/dist/{authentication → cjs/authentication}/deviceMode.js +0 -0
- /package/dist/{authentication → cjs/authentication}/index.js +0 -0
- /package/dist/{authentication → cjs/authentication}/types.js +0 -0
- /package/dist/{cache → cjs/cache}/index.js +0 -0
- /package/dist/{client → cjs/client}/authentication.js +0 -0
- /package/dist/{client → cjs/client}/client.gen.js +0 -0
- /package/dist/{client → cjs/client}/client.js +0 -0
- /package/dist/{client → cjs/client}/index.js +0 -0
- /package/dist/{client → cjs/client}/interceptors.js +0 -0
- /package/dist/{client → cjs/client}/sdk.gen.js +0 -0
- /package/dist/{client → cjs/client}/types.gen.js +0 -0
- /package/dist/{common → cjs/common}/autoload.js +0 -0
- /package/dist/{common → cjs/common}/env.js +0 -0
- /package/dist/{common → cjs/common}/errors.js +0 -0
- /package/dist/{common → cjs/common}/internal.js +0 -0
- /package/dist/{common → cjs/common}/internal.test.js +0 -0
- /package/dist/{common → cjs/common}/logger.js +0 -0
- /package/dist/{common → cjs/common}/node.js +0 -0
- /package/dist/{index.browser.test.js → cjs/index.browser.test.js} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{jobs → cjs/jobs}/index.js +0 -0
- /package/dist/{jobs → cjs/jobs}/jobs.js +0 -0
- /package/dist/{jobs → cjs/jobs}/start.js +0 -0
- /package/dist/{jobs → cjs/jobs}/types.js +0 -0
- /package/dist/{mcp → cjs/mcp}/client.js +0 -0
- /package/dist/{mcp → cjs/mcp}/index.js +0 -0
- /package/dist/{mcp → cjs/mcp}/server.js +0 -0
- /package/dist/{models → cjs/models}/index.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/action.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/client/client.gen.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/client/index.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/client/sdk.gen.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/client/types.gen.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/filesystem/filesystem.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/filesystem/index.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/filesystem/types.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/index.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/network/index.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/network/network.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/preview.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/process/index.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/process/process.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/sandbox.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/session.js +0 -0
- /package/dist/{sandbox → cjs/sandbox}/types.js +0 -0
- /package/dist/{telemetry → cjs/telemetry}/telemetry.js +0 -0
- /package/dist/{tools → cjs/tools}/index.js +0 -0
- /package/dist/{tools → cjs/tools}/mcpTool.js +0 -0
- /package/dist/{tools → cjs/tools}/types.js +0 -0
- /package/dist/{tools → cjs/tools}/zodSchema.js +0 -0
- /package/dist/{agents → cjs/types/agents}/index.d.ts +0 -0
- /package/dist/{authentication → cjs/types/authentication}/apikey.d.ts +0 -0
- /package/dist/{authentication → cjs/types/authentication}/clientcredentials.d.ts +0 -0
- /package/dist/{authentication → cjs/types/authentication}/credentials.d.ts +0 -0
- /package/dist/{authentication → cjs/types/authentication}/deviceMode.d.ts +0 -0
- /package/dist/{authentication → cjs/types/authentication}/index.d.ts +0 -0
- /package/dist/{authentication → cjs/types/authentication}/types.d.ts +0 -0
- /package/dist/{cache → cjs/types/cache}/index.d.ts +0 -0
- /package/dist/{client → cjs/types/client}/authentication.d.ts +0 -0
- /package/dist/{client → cjs/types/client}/client.d.ts +0 -0
- /package/dist/{client → cjs/types/client}/client.gen.d.ts +0 -0
- /package/dist/{client → cjs/types/client}/index.d.ts +0 -0
- /package/dist/{client → cjs/types/client}/interceptors.d.ts +0 -0
- /package/dist/{client → cjs/types/client}/sdk.gen.d.ts +0 -0
- /package/dist/{client → cjs/types/client}/types.gen.d.ts +0 -0
- /package/dist/{common → cjs/types/common}/autoload.d.ts +0 -0
- /package/dist/{common → cjs/types/common}/env.d.ts +0 -0
- /package/dist/{common → cjs/types/common}/errors.d.ts +0 -0
- /package/dist/{common → cjs/types/common}/internal.d.ts +0 -0
- /package/dist/{common → cjs/types/common}/internal.test.d.ts +0 -0
- /package/dist/{common → cjs/types/common}/logger.d.ts +0 -0
- /package/dist/{common → cjs/types/common}/node.d.ts +0 -0
- /package/dist/{common → cjs/types/common}/settings.d.ts +0 -0
- /package/dist/{index.browser.test.d.ts → cjs/types/index.browser.test.d.ts} +0 -0
- /package/dist/{index.d.ts → cjs/types/index.d.ts} +0 -0
- /package/dist/{jobs → cjs/types/jobs}/index.d.ts +0 -0
- /package/dist/{jobs → cjs/types/jobs}/jobs.d.ts +0 -0
- /package/dist/{jobs → cjs/types/jobs}/start.d.ts +0 -0
- /package/dist/{jobs → cjs/types/jobs}/types.d.ts +0 -0
- /package/dist/{mcp → cjs/types/mcp}/client.d.ts +0 -0
- /package/dist/{mcp → cjs/types/mcp}/index.d.ts +0 -0
- /package/dist/{mcp → cjs/types/mcp}/server.d.ts +0 -0
- /package/dist/{models → cjs/types/models}/index.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/action.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/client/client.gen.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/client/index.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/client/sdk.gen.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/client/types.gen.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/filesystem/filesystem.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/filesystem/index.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/filesystem/types.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/index.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/network/index.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/network/network.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/preview.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/process/index.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/process/process.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/sandbox.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/session.d.ts +0 -0
- /package/dist/{sandbox → cjs/types/sandbox}/types.d.ts +0 -0
- /package/dist/{telemetry → cjs/types/telemetry}/telemetry.d.ts +0 -0
- /package/dist/{tools → cjs/types/tools}/mcpTool.d.ts +0 -0
- /package/dist/{tools → cjs/types/tools}/types.d.ts +0 -0
- /package/dist/{tools → cjs/types/tools}/zodSchema.d.ts +0 -0
- /package/dist/{volume → cjs/types/volume}/index.d.ts +0 -0
- /package/dist/{volume → cjs/volume}/index.js +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @blaxel/core/src/telemetry/interface.ts
|
|
2
|
+
/**
|
|
3
|
+
* No-operation implementation of Span
|
|
4
|
+
*/
|
|
5
|
+
class NoopSpan {
|
|
6
|
+
setAttribute() { }
|
|
7
|
+
setAttributes() { }
|
|
8
|
+
recordException() { }
|
|
9
|
+
setStatus() { }
|
|
10
|
+
end() { }
|
|
11
|
+
getContext() { return null; }
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* No-operation implementation of TelemetryProvider
|
|
15
|
+
*/
|
|
16
|
+
class NoopTelemetryProvider {
|
|
17
|
+
startSpan() {
|
|
18
|
+
return new NoopSpan();
|
|
19
|
+
}
|
|
20
|
+
flush() {
|
|
21
|
+
return Promise.resolve();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Registry for managing the global telemetry provider
|
|
26
|
+
*/
|
|
27
|
+
class TelemetryRegistry {
|
|
28
|
+
static instance;
|
|
29
|
+
provider = new NoopTelemetryProvider();
|
|
30
|
+
constructor() { }
|
|
31
|
+
static getInstance() {
|
|
32
|
+
if (!TelemetryRegistry.instance) {
|
|
33
|
+
TelemetryRegistry.instance = new TelemetryRegistry();
|
|
34
|
+
}
|
|
35
|
+
return TelemetryRegistry.instance;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Register a telemetry provider implementation
|
|
39
|
+
*/
|
|
40
|
+
registerProvider(provider) {
|
|
41
|
+
this.provider = provider;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the current telemetry provider
|
|
45
|
+
*/
|
|
46
|
+
getProvider() {
|
|
47
|
+
return this.provider;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Export singleton instance
|
|
51
|
+
export const telemetryRegistry = TelemetryRegistry.getInstance();
|
|
52
|
+
// Convenience functions that delegate to the provider
|
|
53
|
+
/**
|
|
54
|
+
* Create a span with the registered provider
|
|
55
|
+
*/
|
|
56
|
+
export function startSpan(name, options) {
|
|
57
|
+
return telemetryRegistry.getProvider().startSpan(name, options);
|
|
58
|
+
}
|
|
59
|
+
export async function withSpan(name, fn, options) {
|
|
60
|
+
const span = startSpan(name, options);
|
|
61
|
+
try {
|
|
62
|
+
const result = await fn();
|
|
63
|
+
span.end();
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
span.recordException(error);
|
|
68
|
+
span.end();
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export async function flush() {
|
|
73
|
+
await telemetryRegistry.getProvider().flush();
|
|
74
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { findFromCache } from "../cache/index.js";
|
|
2
|
+
import { getFunction } from "../client/client.js";
|
|
3
|
+
import { getForcedUrl } from "../common/internal.js";
|
|
4
|
+
import { getMcpTool } from "./mcpTool.js";
|
|
5
|
+
export const getTool = async (name, options) => {
|
|
6
|
+
return await getMcpTool(name, options);
|
|
7
|
+
};
|
|
8
|
+
export class BLTools {
|
|
9
|
+
toolNames;
|
|
10
|
+
constructor(toolNames) {
|
|
11
|
+
this.toolNames = toolNames;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export const blTools = (names) => {
|
|
15
|
+
return new BLTools(names);
|
|
16
|
+
};
|
|
17
|
+
export const blTool = (name) => {
|
|
18
|
+
return new BLTools([name]);
|
|
19
|
+
};
|
|
20
|
+
export const getToolMetadata = async (tool) => {
|
|
21
|
+
const forcedUrl = getForcedUrl('function', tool);
|
|
22
|
+
if (forcedUrl) {
|
|
23
|
+
return {
|
|
24
|
+
metadata: {
|
|
25
|
+
name: tool,
|
|
26
|
+
},
|
|
27
|
+
spec: {
|
|
28
|
+
runtime: {
|
|
29
|
+
type: "mcp",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const cacheData = await findFromCache("Function", tool);
|
|
35
|
+
if (cacheData) {
|
|
36
|
+
return cacheData;
|
|
37
|
+
}
|
|
38
|
+
const { data } = await getFunction({
|
|
39
|
+
path: {
|
|
40
|
+
functionName: tool,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return data || null;
|
|
44
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { Client as ModelContextProtocolClient } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { env } from "../common/env.js";
|
|
3
|
+
import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
|
|
4
|
+
import { logger } from "../common/logger.js";
|
|
5
|
+
import { settings } from "../common/settings.js";
|
|
6
|
+
import { authenticate } from "../index.js";
|
|
7
|
+
import { BlaxelMcpClientTransport } from "../mcp/client.js";
|
|
8
|
+
import { startSpan } from "../telemetry/telemetry.js";
|
|
9
|
+
import { schemaToZodSchema } from "./zodSchema.js";
|
|
10
|
+
const McpToolCache = new Map();
|
|
11
|
+
export class McpTool {
|
|
12
|
+
name;
|
|
13
|
+
type;
|
|
14
|
+
pluralType;
|
|
15
|
+
client;
|
|
16
|
+
transport;
|
|
17
|
+
timer;
|
|
18
|
+
ms;
|
|
19
|
+
meta;
|
|
20
|
+
startPromise;
|
|
21
|
+
constructor(name, options = { ms: 5000 }) {
|
|
22
|
+
this.name = name;
|
|
23
|
+
this.type = "function";
|
|
24
|
+
this.pluralType = "functions";
|
|
25
|
+
if (name.startsWith("sandbox/") || name.startsWith("sandboxes/")) {
|
|
26
|
+
this.name = name.split("/")[1];
|
|
27
|
+
this.type = "sandbox";
|
|
28
|
+
this.pluralType = "sandboxes";
|
|
29
|
+
}
|
|
30
|
+
if (env.BL_CLOUD) {
|
|
31
|
+
this.ms = 0;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.ms = typeof options === "number" ? options : options.ms || 5000;
|
|
35
|
+
}
|
|
36
|
+
this.meta = (typeof options === "object" && options.meta) || undefined;
|
|
37
|
+
this.client = new ModelContextProtocolClient({
|
|
38
|
+
name: this.name,
|
|
39
|
+
version: "1.0.0",
|
|
40
|
+
}, {
|
|
41
|
+
capabilities: {
|
|
42
|
+
tools: {},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
get fallbackUrl() {
|
|
47
|
+
if (this.externalUrl != this.url) {
|
|
48
|
+
return this.externalUrl;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
get externalUrl() {
|
|
53
|
+
return new URL(`${settings.runUrl}/${settings.workspace}/${this.pluralType}/${this.name}`);
|
|
54
|
+
}
|
|
55
|
+
get internalUrl() {
|
|
56
|
+
const hash = getGlobalUniqueHash(settings.workspace, this.type, this.name);
|
|
57
|
+
return new URL(`${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`);
|
|
58
|
+
}
|
|
59
|
+
get forcedUrl() {
|
|
60
|
+
return getForcedUrl(this.type, this.name);
|
|
61
|
+
}
|
|
62
|
+
get url() {
|
|
63
|
+
if (this.forcedUrl)
|
|
64
|
+
return this.forcedUrl;
|
|
65
|
+
if (settings.runInternalHostname)
|
|
66
|
+
return this.internalUrl;
|
|
67
|
+
return this.externalUrl;
|
|
68
|
+
}
|
|
69
|
+
async start() {
|
|
70
|
+
logger.debug(`MCP:${this.name}:start`);
|
|
71
|
+
this.stopCloseTimer();
|
|
72
|
+
this.startPromise = this.startPromise || (async () => {
|
|
73
|
+
await authenticate();
|
|
74
|
+
try {
|
|
75
|
+
logger.debug(`MCP:${this.name}:Connecting::${this.url.toString()}`);
|
|
76
|
+
this.transport = new BlaxelMcpClientTransport(this.url.toString(), settings.headers, { retry: { max: 0 } });
|
|
77
|
+
await this.client.connect(this.transport);
|
|
78
|
+
logger.debug(`MCP:${this.name}:Connected`);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (err instanceof Error) {
|
|
82
|
+
logger.error(`MCP ${this.name} connection failed: ${err.message}`, {
|
|
83
|
+
error: err.message,
|
|
84
|
+
stack: err.stack,
|
|
85
|
+
mcpName: this.name,
|
|
86
|
+
url: this.url
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (!this.fallbackUrl) {
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
logger.debug(`MCP:${this.name}:Connecting to fallback`);
|
|
93
|
+
this.transport = new BlaxelMcpClientTransport(this.fallbackUrl.toString(), settings.headers);
|
|
94
|
+
await this.client.connect(this.transport);
|
|
95
|
+
logger.debug(`MCP:${this.name}:Connected to fallback`);
|
|
96
|
+
}
|
|
97
|
+
})();
|
|
98
|
+
return await this.startPromise;
|
|
99
|
+
}
|
|
100
|
+
async close(now = false) {
|
|
101
|
+
logger.debug(`MCP:${this.name}:Close in ${now ? 0 : this.ms}ms`);
|
|
102
|
+
if (now || !this.ms) {
|
|
103
|
+
if (this.timer) {
|
|
104
|
+
clearTimeout(this.timer);
|
|
105
|
+
}
|
|
106
|
+
delete this.startPromise;
|
|
107
|
+
return this.client.close();
|
|
108
|
+
}
|
|
109
|
+
this.timer = setTimeout(() => {
|
|
110
|
+
logger.debug(`MCP:${this.name}:CloseTimer`);
|
|
111
|
+
delete this.startPromise;
|
|
112
|
+
this.client.close().catch((err) => {
|
|
113
|
+
if (err instanceof Error) {
|
|
114
|
+
logger.error(`MCP ${this.name} close failed: ${err.message}`, {
|
|
115
|
+
error: err.message,
|
|
116
|
+
stack: err.stack,
|
|
117
|
+
mcpName: this.name
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}, now ? 0 : this.ms);
|
|
122
|
+
}
|
|
123
|
+
stopCloseTimer() {
|
|
124
|
+
logger.debug(`MCP:${this.name}:StopCloseTimer`);
|
|
125
|
+
if (this.timer) {
|
|
126
|
+
clearTimeout(this.timer);
|
|
127
|
+
this.timer = undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async listTools() {
|
|
131
|
+
const span = startSpan(this.name, {
|
|
132
|
+
attributes: {
|
|
133
|
+
"span.type": "tool.list",
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
logger.debug(`MCP:${this.name}:Listing tools`);
|
|
138
|
+
await this.start();
|
|
139
|
+
const { tools } = (await this.client.listTools());
|
|
140
|
+
await this.close();
|
|
141
|
+
const result = tools.map((tool) => {
|
|
142
|
+
return {
|
|
143
|
+
name: tool.name,
|
|
144
|
+
description: tool.description,
|
|
145
|
+
inputSchema: schemaToZodSchema(tool.inputSchema),
|
|
146
|
+
originalSchema: tool.inputSchema,
|
|
147
|
+
call: (input) => {
|
|
148
|
+
return this.call(tool.name, input);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
span.setAttribute("tool.list.result", JSON.stringify(result));
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
span.setStatus("error");
|
|
157
|
+
span.recordException(err);
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
span.end();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async call(toolName, args) {
|
|
165
|
+
const span = startSpan(this.name + "." + toolName, {
|
|
166
|
+
attributes: {
|
|
167
|
+
"span.type": "tool.call",
|
|
168
|
+
"tool.name": toolName,
|
|
169
|
+
"tool.args": JSON.stringify(args),
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
try {
|
|
173
|
+
logger.debug(`MCP:${this.name}:Tool calling`, toolName, JSON.stringify(args));
|
|
174
|
+
logger.debug(`MCP:${this.name}:Tool calling:start`);
|
|
175
|
+
await this.start();
|
|
176
|
+
logger.debug(`MCP:${this.name}:Tool calling:start2`);
|
|
177
|
+
const result = await this.client.callTool({
|
|
178
|
+
name: toolName,
|
|
179
|
+
arguments: args,
|
|
180
|
+
_meta: this.meta
|
|
181
|
+
});
|
|
182
|
+
logger.debug(`MCP:${this.name}:Tool calling:result`);
|
|
183
|
+
await this.close();
|
|
184
|
+
logger.debug(`MCP:${this.name}:Tool result`, toolName, JSON.stringify(args));
|
|
185
|
+
span.setAttribute("tool.call.result", JSON.stringify(result));
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
if (err instanceof Error) {
|
|
190
|
+
logger.error(`MCP tool call failed: ${err.message}`, {
|
|
191
|
+
error: err.message,
|
|
192
|
+
stack: err.stack,
|
|
193
|
+
mcpName: this.name,
|
|
194
|
+
toolName,
|
|
195
|
+
args: JSON.stringify(args)
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
throw err;
|
|
199
|
+
}
|
|
200
|
+
finally {
|
|
201
|
+
span.end();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
export const getMcpTool = async (name, options) => {
|
|
206
|
+
let tool = McpToolCache.get(name);
|
|
207
|
+
if (!tool) {
|
|
208
|
+
logger.debug(`MCP:${name}:Creating new tool`);
|
|
209
|
+
tool = new McpTool(name, options);
|
|
210
|
+
McpToolCache.set(name, tool);
|
|
211
|
+
}
|
|
212
|
+
return await tool.listTools();
|
|
213
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Converts an array of `FunctionSchema` objects into a Zod schema for validation.
|
|
4
|
+
*
|
|
5
|
+
* @param {FunctionSchema} parameters - The parameters to convert.
|
|
6
|
+
* @returns {z.ZodObject<any>} A Zod object schema representing the parameters.
|
|
7
|
+
*/
|
|
8
|
+
export const schemaToZodSchema = (schema) => {
|
|
9
|
+
const shape = {};
|
|
10
|
+
if (schema.properties) {
|
|
11
|
+
Object.entries(schema.properties).forEach(([key, param]) => {
|
|
12
|
+
let zodType;
|
|
13
|
+
switch (param.type) {
|
|
14
|
+
case "boolean":
|
|
15
|
+
zodType = z.boolean();
|
|
16
|
+
break;
|
|
17
|
+
case "number":
|
|
18
|
+
case "integer":
|
|
19
|
+
zodType = z.number();
|
|
20
|
+
break;
|
|
21
|
+
case "null":
|
|
22
|
+
zodType = z.null();
|
|
23
|
+
break;
|
|
24
|
+
case "array":
|
|
25
|
+
zodType = z.array(schemaToZodSchema(param.items || {}));
|
|
26
|
+
break;
|
|
27
|
+
case "object":
|
|
28
|
+
zodType = schemaToZodSchema(param);
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
zodType = z.string();
|
|
32
|
+
}
|
|
33
|
+
if (param.description) {
|
|
34
|
+
zodType = zodType.describe(param.description);
|
|
35
|
+
}
|
|
36
|
+
shape[key] =
|
|
37
|
+
param.required || schema.required?.includes(key)
|
|
38
|
+
? zodType
|
|
39
|
+
: zodType.optional();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return z.object(shape);
|
|
43
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
|
+
import { createVolume, deleteVolume, getVolume, listVolumes } from "../client/index.js";
|
|
3
|
+
export class VolumeInstance {
|
|
4
|
+
volume;
|
|
5
|
+
constructor(volume) {
|
|
6
|
+
this.volume = volume;
|
|
7
|
+
}
|
|
8
|
+
get metadata() {
|
|
9
|
+
return this.volume.metadata;
|
|
10
|
+
}
|
|
11
|
+
get spec() {
|
|
12
|
+
return this.volume.spec;
|
|
13
|
+
}
|
|
14
|
+
get status() {
|
|
15
|
+
return this.volume.status;
|
|
16
|
+
}
|
|
17
|
+
get name() {
|
|
18
|
+
return this.volume.metadata?.name;
|
|
19
|
+
}
|
|
20
|
+
get displayName() {
|
|
21
|
+
return this.volume.metadata?.displayName;
|
|
22
|
+
}
|
|
23
|
+
get size() {
|
|
24
|
+
return this.volume.spec?.size;
|
|
25
|
+
}
|
|
26
|
+
get region() {
|
|
27
|
+
return this.volume.spec?.region;
|
|
28
|
+
}
|
|
29
|
+
static async create(config) {
|
|
30
|
+
const defaultName = `volume-${uuidv4().replace(/-/g, '').substring(0, 8)}`;
|
|
31
|
+
const defaultSize = 1024; // 1GB in MB
|
|
32
|
+
let volume;
|
|
33
|
+
// Handle VolumeCreateConfiguration or simple config object
|
|
34
|
+
if ('spec' in config && 'metadata' in config) {
|
|
35
|
+
// It's already a Volume object
|
|
36
|
+
volume = config;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// It's a VolumeCreateConfiguration
|
|
40
|
+
const volumeConfig = config;
|
|
41
|
+
volume = {
|
|
42
|
+
metadata: {
|
|
43
|
+
name: volumeConfig.name || defaultName,
|
|
44
|
+
displayName: volumeConfig.displayName || volumeConfig.name || defaultName
|
|
45
|
+
},
|
|
46
|
+
spec: {
|
|
47
|
+
size: volumeConfig.size || defaultSize,
|
|
48
|
+
region: volumeConfig.region
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// Ensure required fields have defaults
|
|
53
|
+
if (!volume.metadata) {
|
|
54
|
+
volume.metadata = { name: defaultName };
|
|
55
|
+
}
|
|
56
|
+
if (!volume.metadata.name) {
|
|
57
|
+
volume.metadata.name = defaultName;
|
|
58
|
+
}
|
|
59
|
+
if (!volume.spec) {
|
|
60
|
+
volume.spec = { size: defaultSize };
|
|
61
|
+
}
|
|
62
|
+
if (!volume.spec.size) {
|
|
63
|
+
volume.spec.size = defaultSize;
|
|
64
|
+
}
|
|
65
|
+
const { data } = await createVolume({
|
|
66
|
+
body: volume,
|
|
67
|
+
throwOnError: true,
|
|
68
|
+
});
|
|
69
|
+
return new VolumeInstance(data);
|
|
70
|
+
}
|
|
71
|
+
static async get(volumeName) {
|
|
72
|
+
const { data } = await getVolume({
|
|
73
|
+
path: {
|
|
74
|
+
volumeName,
|
|
75
|
+
},
|
|
76
|
+
throwOnError: true,
|
|
77
|
+
});
|
|
78
|
+
return new VolumeInstance(data);
|
|
79
|
+
}
|
|
80
|
+
static async list() {
|
|
81
|
+
const { data } = await listVolumes({ throwOnError: true });
|
|
82
|
+
return data.map((volume) => new VolumeInstance(volume));
|
|
83
|
+
}
|
|
84
|
+
static async delete(volumeName) {
|
|
85
|
+
const { data } = await deleteVolume({
|
|
86
|
+
path: {
|
|
87
|
+
volumeName,
|
|
88
|
+
},
|
|
89
|
+
throwOnError: true,
|
|
90
|
+
});
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
static async createIfNotExists(config) {
|
|
94
|
+
try {
|
|
95
|
+
return await VolumeInstance.create(config);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
if (typeof e === "object" && e !== null && "code" in e && (e.code === 409 || e.code === 'VOLUME_ALREADY_EXISTS')) {
|
|
99
|
+
const name = 'name' in config ? config.name : config.metadata?.name;
|
|
100
|
+
if (!name) {
|
|
101
|
+
throw new Error("Volume name is required");
|
|
102
|
+
}
|
|
103
|
+
const volumeInstance = await VolumeInstance.get(name);
|
|
104
|
+
return volumeInstance;
|
|
105
|
+
}
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/core",
|
|
3
|
-
"version": "0.2.36-dev.
|
|
3
|
+
"version": "0.2.36-dev.190",
|
|
4
4
|
"description": "Blaxel Core SDK for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blaxel, INC (https://blaxel.ai)",
|
|
@@ -17,38 +17,22 @@
|
|
|
17
17
|
"agent",
|
|
18
18
|
"mcp"
|
|
19
19
|
],
|
|
20
|
-
"main": "dist/index.js",
|
|
21
|
-
"module": "dist/index.js",
|
|
22
|
-
"types": "dist/index.d.ts",
|
|
20
|
+
"main": "./dist/cjs/index.js",
|
|
21
|
+
"module": "./dist/esm/index.js",
|
|
22
|
+
"types": "./dist/cjs/types/index.d.ts",
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"require": {
|
|
30
|
-
"types": "./dist/index.d.ts",
|
|
31
|
-
"default": "./dist/index.js"
|
|
32
|
-
}
|
|
25
|
+
"types": "./dist/cjs/types/index.d.ts",
|
|
26
|
+
"import": "./dist/esm/index.js",
|
|
27
|
+
"require": "./dist/cjs/index.js",
|
|
28
|
+
"default": "./dist/cjs/index.js"
|
|
33
29
|
},
|
|
34
|
-
"
|
|
35
|
-
"import": {
|
|
36
|
-
"types": "./dist/*.d.ts",
|
|
37
|
-
"default": "./dist/*.js"
|
|
38
|
-
},
|
|
39
|
-
"require": {
|
|
40
|
-
"types": "./dist/*.d.ts",
|
|
41
|
-
"default": "./dist/*.js"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
30
|
+
"./package.json": "./package.json"
|
|
44
31
|
},
|
|
45
32
|
"typesVersions": {
|
|
46
33
|
"*": {
|
|
47
34
|
".": [
|
|
48
|
-
"./dist/index.d.ts"
|
|
49
|
-
],
|
|
50
|
-
"*": [
|
|
51
|
-
"./dist/*"
|
|
35
|
+
"./dist/cjs/types/index.d.ts"
|
|
52
36
|
]
|
|
53
37
|
}
|
|
54
38
|
},
|
|
@@ -79,14 +63,17 @@
|
|
|
79
63
|
"vite": "^5.2.0",
|
|
80
64
|
"vitest": "^1.5.0"
|
|
81
65
|
},
|
|
82
|
-
"commit": "
|
|
66
|
+
"commit": "fcb44cfa2e6fc7b7cc20cf8bf70e3bf380d74146",
|
|
83
67
|
"scripts": {
|
|
84
68
|
"lint": "eslint src/",
|
|
85
69
|
"dev": "tsc --watch",
|
|
86
|
-
"build": "npm run build:inject-commit &&
|
|
87
|
-
"build:
|
|
70
|
+
"build": "npm run build:inject-commit && npm run build:cjs && npm run build:esm && npm run build:fix-esm && npm run build:esm-package && npm run build:replace-imports",
|
|
71
|
+
"build:cjs": "NODE_OPTIONS='--max-old-space-size=8192' tsc -p tsconfig.cjs.json",
|
|
72
|
+
"build:esm": "NODE_OPTIONS='--max-old-space-size=8192' tsc -p tsconfig.esm.json",
|
|
73
|
+
"build:fix-esm": "node fix-esm-imports.js",
|
|
74
|
+
"build:esm-package": "echo '{\"type\":\"module\"}' > dist/esm/package.json",
|
|
88
75
|
"build:inject-commit": "node -e \"const fs=require('fs'),pkg=require('./package.json'),{execSync}=require('child_process');try{const commit=execSync('git rev-parse HEAD',{encoding:'utf8'}).trim();pkg.commit=commit;fs.writeFileSync('./package.json',JSON.stringify(pkg,null,'\\t')+'\\n');console.log('✅ Injected commit:',commit.substring(0,7))}catch(e){console.log('⚠️ Could not inject commit:',e.message)}\"",
|
|
89
|
-
"build:replace-imports": "node -e \"const fs=require('fs'),path=require('path'),pkg=require('./package.json');const
|
|
76
|
+
"build:replace-imports": "node -e \"const fs=require('fs'),path=require('path'),pkg=require('./package.json');const paths=['dist/cjs/common/settings.js','dist/esm/common/settings.js'];paths.forEach(settingsPath=>{if(fs.existsSync(settingsPath)){let content=fs.readFileSync(settingsPath,'utf8');content=content.replace(/require\\(\\\".*?\\/package\\.json\\\"\\)/g,JSON.stringify({version:pkg.version,commit:pkg.commit||'unknown'}));fs.writeFileSync(settingsPath,content);console.log('✅ Replaced imports in',settingsPath);}});\"",
|
|
90
77
|
"test": "vitest --run",
|
|
91
78
|
"test:watch": "vitest --watch"
|
|
92
79
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|