@blaxel/core 0.2.0-dev1

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.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agents/index.d.ts +15 -0
  3. package/dist/agents/index.js +114 -0
  4. package/dist/authentication/apikey.d.ts +10 -0
  5. package/dist/authentication/apikey.js +24 -0
  6. package/dist/authentication/clientcredentials.d.ts +15 -0
  7. package/dist/authentication/clientcredentials.js +70 -0
  8. package/dist/authentication/credentials.d.ts +6 -0
  9. package/dist/authentication/credentials.js +17 -0
  10. package/dist/authentication/deviceMode.d.ts +15 -0
  11. package/dist/authentication/deviceMode.js +70 -0
  12. package/dist/authentication/index.d.ts +3 -0
  13. package/dist/authentication/index.js +63 -0
  14. package/dist/authentication/types.d.ts +9 -0
  15. package/dist/authentication/types.js +2 -0
  16. package/dist/cache/index.d.ts +1 -0
  17. package/dist/cache/index.js +26 -0
  18. package/dist/client/authentication.d.ts +25 -0
  19. package/dist/client/authentication.js +15 -0
  20. package/dist/client/client.d.ts +2 -0
  21. package/dist/client/client.gen.d.ts +12 -0
  22. package/dist/client/client.gen.js +8 -0
  23. package/dist/client/client.js +17 -0
  24. package/dist/client/index.d.ts +2 -0
  25. package/dist/client/index.js +19 -0
  26. package/dist/client/interceptors.d.ts +3 -0
  27. package/dist/client/interceptors.js +17 -0
  28. package/dist/client/sdk.gen.d.ts +410 -0
  29. package/dist/client/sdk.gen.js +1436 -0
  30. package/dist/client/types.gen.d.ts +3534 -0
  31. package/dist/client/types.gen.js +4 -0
  32. package/dist/common/autoload.d.ts +3 -0
  33. package/dist/common/autoload.js +27 -0
  34. package/dist/common/env.d.ts +5 -0
  35. package/dist/common/env.js +43 -0
  36. package/dist/common/errors.d.ts +1 -0
  37. package/dist/common/errors.js +17 -0
  38. package/dist/common/internal.d.ts +2 -0
  39. package/dist/common/internal.js +19 -0
  40. package/dist/common/logger.d.ts +1 -0
  41. package/dist/common/logger.js +4 -0
  42. package/dist/common/node.d.ts +3 -0
  43. package/dist/common/node.js +14 -0
  44. package/dist/common/settings.d.ts +26 -0
  45. package/dist/common/settings.js +84 -0
  46. package/dist/index.d.ts +14 -0
  47. package/dist/index.js +30 -0
  48. package/dist/mcp/client.d.ts +19 -0
  49. package/dist/mcp/client.js +151 -0
  50. package/dist/mcp/index.d.ts +2 -0
  51. package/dist/mcp/index.js +18 -0
  52. package/dist/mcp/server.d.ts +24 -0
  53. package/dist/mcp/server.js +213 -0
  54. package/dist/models/index.d.ts +8 -0
  55. package/dist/models/index.js +31 -0
  56. package/dist/sandbox/action.d.ts +18 -0
  57. package/dist/sandbox/action.js +74 -0
  58. package/dist/sandbox/client/client.gen.d.ts +12 -0
  59. package/dist/sandbox/client/client.gen.js +6 -0
  60. package/dist/sandbox/client/index.d.ts +2 -0
  61. package/dist/sandbox/client/index.js +19 -0
  62. package/dist/sandbox/client/sdk.gen.d.ts +83 -0
  63. package/dist/sandbox/client/sdk.gen.js +153 -0
  64. package/dist/sandbox/client/types.gen.d.ts +410 -0
  65. package/dist/sandbox/client/types.gen.js +4 -0
  66. package/dist/sandbox/filesystem.d.ts +18 -0
  67. package/dist/sandbox/filesystem.js +121 -0
  68. package/dist/sandbox/index.d.ts +1 -0
  69. package/dist/sandbox/index.js +17 -0
  70. package/dist/sandbox/network.d.ts +5 -0
  71. package/dist/sandbox/network.js +10 -0
  72. package/dist/sandbox/process.d.ts +12 -0
  73. package/dist/sandbox/process.js +61 -0
  74. package/dist/sandbox/sandbox.d.ts +23 -0
  75. package/dist/sandbox/sandbox.js +92 -0
  76. package/dist/telemetry/telemetry.d.ts +58 -0
  77. package/dist/telemetry/telemetry.js +59 -0
  78. package/dist/tools/index.d.ts +10 -0
  79. package/dist/tools/index.js +52 -0
  80. package/dist/tools/mcpTool.d.ts +21 -0
  81. package/dist/tools/mcpTool.js +193 -0
  82. package/dist/tools/types.d.ts +8 -0
  83. package/dist/tools/types.js +2 -0
  84. package/dist/tools/zodSchema.d.ts +9 -0
  85. package/dist/tools/zodSchema.js +46 -0
  86. package/package.json +76 -0
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SandboxInstance = void 0;
4
+ const index_js_1 = require("../client/index.js");
5
+ const logger_js_1 = require("../common/logger.js");
6
+ const filesystem_js_1 = require("./filesystem.js");
7
+ const network_js_1 = require("./network.js");
8
+ const process_js_1 = require("./process.js");
9
+ class SandboxInstance {
10
+ sandbox;
11
+ fs;
12
+ network;
13
+ process;
14
+ constructor(sandbox) {
15
+ this.sandbox = sandbox;
16
+ this.fs = new filesystem_js_1.SandboxFileSystem(sandbox);
17
+ this.network = new network_js_1.SandboxNetwork(sandbox);
18
+ this.process = new process_js_1.SandboxProcess(sandbox);
19
+ }
20
+ get metadata() {
21
+ return this.sandbox.metadata;
22
+ }
23
+ get status() {
24
+ return this.sandbox.status;
25
+ }
26
+ get events() {
27
+ return this.sandbox.events;
28
+ }
29
+ get spec() {
30
+ return this.sandbox.spec;
31
+ }
32
+ async wait({ maxWait = 60000, interval = 1000 } = {}) {
33
+ const startTime = Date.now();
34
+ while (this.sandbox.status !== "DEPLOYED") {
35
+ await new Promise((resolve) => setTimeout(resolve, interval));
36
+ try {
37
+ const { data } = await (0, index_js_1.getSandbox)({
38
+ path: {
39
+ sandboxName: this.sandbox.metadata?.name ?? "",
40
+ },
41
+ throwOnError: true,
42
+ });
43
+ logger_js_1.logger.info(`Waiting for sandbox to be deployed, status: ${data.status}`);
44
+ this.sandbox = data;
45
+ }
46
+ catch (e) {
47
+ logger_js_1.logger.error("Could not retrieve sandbox", e);
48
+ }
49
+ if (this.sandbox.status === "FAILED") {
50
+ throw new Error("Sandbox failed to deploy");
51
+ }
52
+ if (Date.now() - startTime > maxWait) {
53
+ throw new Error("Sandbox did not deploy in time");
54
+ }
55
+ }
56
+ }
57
+ static async create(sandbox) {
58
+ if (sandbox.spec?.runtime?.generation == undefined) {
59
+ sandbox.spec = sandbox.spec ?? { runtime: {} };
60
+ sandbox.spec.runtime = sandbox.spec.runtime ?? {};
61
+ sandbox.spec.runtime.generation = "mk3";
62
+ }
63
+ const { data } = await (0, index_js_1.createSandbox)({
64
+ body: sandbox,
65
+ throwOnError: true,
66
+ });
67
+ return new SandboxInstance(data);
68
+ }
69
+ static async get(sandboxName) {
70
+ const { data } = await (0, index_js_1.getSandbox)({
71
+ path: {
72
+ sandboxName,
73
+ },
74
+ throwOnError: true,
75
+ });
76
+ return new SandboxInstance(data);
77
+ }
78
+ static async list() {
79
+ const { data } = await (0, index_js_1.listSandboxes)({ throwOnError: true });
80
+ return data.map((sandbox) => new SandboxInstance(sandbox));
81
+ }
82
+ static async delete(sandboxName) {
83
+ const { data } = await (0, index_js_1.deleteSandbox)({
84
+ path: {
85
+ sandboxName,
86
+ },
87
+ throwOnError: true,
88
+ });
89
+ return data;
90
+ }
91
+ }
92
+ exports.SandboxInstance = SandboxInstance;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Options for creating a span
3
+ */
4
+ export interface SpanOptions {
5
+ /** Key-value attributes to attach to the span */
6
+ attributes?: Record<string, string | number | boolean>;
7
+ /** Parent span context, if any */
8
+ parentContext?: unknown;
9
+ /** Whether this is a root span */
10
+ isRoot?: boolean;
11
+ }
12
+ /**
13
+ * Represents a telemetry span
14
+ */
15
+ export interface Span {
16
+ /** Add an attribute to the span */
17
+ setAttribute(key: string, value: string | number | boolean): void;
18
+ /** Add multiple attributes to the span */
19
+ setAttributes(attributes: Record<string, string | number | boolean>): void;
20
+ /** Record an error on the span */
21
+ recordException(error: Error): void;
22
+ /** Set the status of the span */
23
+ setStatus(status: 'ok' | 'error', message?: string): void;
24
+ /** End the span */
25
+ end(): void;
26
+ /** Get the span context (for passing to child spans) */
27
+ getContext(): unknown;
28
+ }
29
+ /**
30
+ * Provider interface for telemetry functionality
31
+ */
32
+ export interface TelemetryProvider {
33
+ /** Create a new span */
34
+ startSpan(name: string, options?: SpanOptions): Span;
35
+ }
36
+ /**
37
+ * Registry for managing the global telemetry provider
38
+ */
39
+ declare class TelemetryRegistry {
40
+ private static instance;
41
+ private provider;
42
+ private constructor();
43
+ static getInstance(): TelemetryRegistry;
44
+ /**
45
+ * Register a telemetry provider implementation
46
+ */
47
+ registerProvider(provider: TelemetryProvider): void;
48
+ /**
49
+ * Get the current telemetry provider
50
+ */
51
+ getProvider(): TelemetryProvider;
52
+ }
53
+ export declare const telemetryRegistry: TelemetryRegistry;
54
+ /**
55
+ * Create a span with the registered provider
56
+ */
57
+ export declare function startSpan(name: string, options?: SpanOptions): Span;
58
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ // @blaxel/core/src/telemetry/interface.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.telemetryRegistry = void 0;
5
+ exports.startSpan = startSpan;
6
+ /**
7
+ * No-operation implementation of Span
8
+ */
9
+ class NoopSpan {
10
+ setAttribute() { }
11
+ setAttributes() { }
12
+ recordException() { }
13
+ setStatus() { }
14
+ end() { }
15
+ getContext() { return null; }
16
+ }
17
+ /**
18
+ * No-operation implementation of TelemetryProvider
19
+ */
20
+ class NoopTelemetryProvider {
21
+ startSpan() {
22
+ return new NoopSpan();
23
+ }
24
+ }
25
+ /**
26
+ * Registry for managing the global telemetry provider
27
+ */
28
+ class TelemetryRegistry {
29
+ static instance;
30
+ provider = new NoopTelemetryProvider();
31
+ constructor() { }
32
+ static getInstance() {
33
+ if (!TelemetryRegistry.instance) {
34
+ TelemetryRegistry.instance = new TelemetryRegistry();
35
+ }
36
+ return TelemetryRegistry.instance;
37
+ }
38
+ /**
39
+ * Register a telemetry provider implementation
40
+ */
41
+ registerProvider(provider) {
42
+ this.provider = provider;
43
+ }
44
+ /**
45
+ * Get the current telemetry provider
46
+ */
47
+ getProvider() {
48
+ return this.provider;
49
+ }
50
+ }
51
+ // Export singleton instance
52
+ exports.telemetryRegistry = TelemetryRegistry.getInstance();
53
+ // Convenience functions that delegate to the provider
54
+ /**
55
+ * Create a span with the registered provider
56
+ */
57
+ function startSpan(name, options) {
58
+ return exports.telemetryRegistry.getProvider().startSpan(name, options);
59
+ }
@@ -0,0 +1,10 @@
1
+ import { Function } from "../client/client.js";
2
+ import { Tool } from "./types.js";
3
+ export declare const getTool: (name: string) => Promise<Tool[]>;
4
+ export declare class BLTools {
5
+ toolNames: string[];
6
+ constructor(toolNames: string[]);
7
+ }
8
+ export declare const blTools: (names: string[]) => BLTools;
9
+ export declare const blTool: (name: string) => BLTools;
10
+ export declare const getToolMetadata: (tool: string) => Promise<Function | null>;
@@ -0,0 +1,52 @@
1
+ "use strict";
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 env_js_1 = require("../common/env.js");
7
+ const mcpTool_js_1 = require("./mcpTool.js");
8
+ const getTool = async (name) => {
9
+ return await (0, mcpTool_js_1.getMcpTool)(name);
10
+ };
11
+ exports.getTool = getTool;
12
+ class BLTools {
13
+ toolNames;
14
+ constructor(toolNames) {
15
+ this.toolNames = toolNames;
16
+ }
17
+ }
18
+ exports.BLTools = BLTools;
19
+ const blTools = (names) => {
20
+ return new BLTools(names);
21
+ };
22
+ exports.blTools = blTools;
23
+ const blTool = (name) => {
24
+ return new BLTools([name]);
25
+ };
26
+ exports.blTool = blTool;
27
+ const getToolMetadata = async (tool) => {
28
+ const envVar = tool.replace(/-/g, "_").toUpperCase();
29
+ if (env_js_1.env[`BL_FUNCTION_${envVar}_URL`]) {
30
+ return {
31
+ metadata: {
32
+ name: tool,
33
+ },
34
+ spec: {
35
+ runtime: {
36
+ type: "mcp",
37
+ },
38
+ },
39
+ };
40
+ }
41
+ const cacheData = await (0, index_js_1.findFromCache)("Function", tool);
42
+ if (cacheData) {
43
+ return cacheData;
44
+ }
45
+ const { data } = await (0, client_js_1.getFunction)({
46
+ path: {
47
+ functionName: tool,
48
+ },
49
+ });
50
+ return data || null;
51
+ };
52
+ exports.getToolMetadata = getToolMetadata;
@@ -0,0 +1,21 @@
1
+ import { Tool } from "./types.js";
2
+ export declare class McpTool {
3
+ private name;
4
+ private client;
5
+ private transport?;
6
+ private timer?;
7
+ private ms;
8
+ private startPromise?;
9
+ constructor(name: string, ms?: number);
10
+ get fallbackUrl(): import("url").URL | null;
11
+ get externalUrl(): import("url").URL;
12
+ get internalUrl(): import("url").URL;
13
+ get forcedUrl(): import("url").URL | null;
14
+ get url(): import("url").URL;
15
+ start(): Promise<void>;
16
+ close(): Promise<void>;
17
+ stopCloseTimer(): void;
18
+ listTools(): Promise<Tool[]>;
19
+ call(toolName: string, args: Record<string, unknown> | undefined): Promise<unknown>;
20
+ }
21
+ export declare const getMcpTool: (name: string) => Promise<Tool[]>;
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMcpTool = exports.McpTool = void 0;
4
+ const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
5
+ const env_js_1 = require("../common/env.js");
6
+ const internal_js_1 = require("../common/internal.js");
7
+ const logger_js_1 = require("../common/logger.js");
8
+ const settings_js_1 = require("../common/settings.js");
9
+ const index_js_2 = require("../index.js");
10
+ const client_js_1 = require("../mcp/client.js");
11
+ const telemetry_js_1 = require("../telemetry/telemetry.js");
12
+ const zodSchema_js_1 = require("./zodSchema.js");
13
+ const McpToolCache = new Map();
14
+ class McpTool {
15
+ name;
16
+ client;
17
+ transport;
18
+ timer;
19
+ ms;
20
+ startPromise;
21
+ constructor(name, ms = 5000) {
22
+ this.name = name;
23
+ if (env_js_1.env.BL_CLOUD) {
24
+ this.ms = 0;
25
+ }
26
+ else {
27
+ this.ms = ms;
28
+ }
29
+ this.client = new index_js_1.Client({
30
+ name: this.name,
31
+ version: "1.0.0",
32
+ }, {
33
+ capabilities: {
34
+ tools: {},
35
+ },
36
+ });
37
+ }
38
+ get fallbackUrl() {
39
+ if (this.externalUrl != this.url) {
40
+ return this.externalUrl;
41
+ }
42
+ return null;
43
+ }
44
+ get externalUrl() {
45
+ return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/functions/${this.name}`);
46
+ }
47
+ get internalUrl() {
48
+ const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, "function", this.name);
49
+ return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
50
+ }
51
+ get forcedUrl() {
52
+ const envVar = this.name.replace(/-/g, "_").toUpperCase();
53
+ if (env_js_1.env[`BL_FUNCTION_${envVar}_URL`]) {
54
+ return new URL(env_js_1.env[`BL_FUNCTION_${envVar}_URL`]);
55
+ }
56
+ return null;
57
+ }
58
+ get url() {
59
+ if (this.forcedUrl)
60
+ return this.forcedUrl;
61
+ if (settings_js_1.settings.runInternalHostname)
62
+ return this.internalUrl;
63
+ return this.externalUrl;
64
+ }
65
+ async start() {
66
+ logger_js_1.logger.debug(`MCP:${this.name}:start`);
67
+ this.stopCloseTimer();
68
+ this.startPromise = this.startPromise || (async () => {
69
+ await (0, index_js_2.authenticate)();
70
+ try {
71
+ logger_js_1.logger.debug(`MCP:${this.name}:Connecting`);
72
+ this.transport = new client_js_1.BlaxelMcpClientTransport(this.url.toString(), settings_js_1.settings.headers);
73
+ await this.client.connect(this.transport);
74
+ logger_js_1.logger.debug(`MCP:${this.name}:Connected`);
75
+ }
76
+ catch (err) {
77
+ if (err instanceof Error) {
78
+ logger_js_1.logger.error(err.stack);
79
+ }
80
+ if (!this.fallbackUrl) {
81
+ throw err;
82
+ }
83
+ logger_js_1.logger.debug(`MCP:${this.name}:Connecting to fallback`);
84
+ this.transport = new client_js_1.BlaxelMcpClientTransport(this.fallbackUrl.toString(), settings_js_1.settings.headers);
85
+ await this.client.connect(this.transport);
86
+ logger_js_1.logger.debug(`MCP:${this.name}:Connected to fallback`);
87
+ }
88
+ })();
89
+ return await this.startPromise;
90
+ }
91
+ async close() {
92
+ logger_js_1.logger.debug(`MCP:${this.name}:Close in ${this.ms}ms`);
93
+ if (!this.ms) {
94
+ delete this.startPromise;
95
+ return this.client.close();
96
+ }
97
+ this.timer = setTimeout(() => {
98
+ logger_js_1.logger.debug(`MCP:${this.name}:CloseTimer`);
99
+ delete this.startPromise;
100
+ this.client.close().catch((err) => {
101
+ if (err instanceof Error) {
102
+ logger_js_1.logger.error(err.stack);
103
+ }
104
+ });
105
+ }, this.ms);
106
+ }
107
+ stopCloseTimer() {
108
+ logger_js_1.logger.debug(`MCP:${this.name}:StopCloseTimer`);
109
+ if (this.timer) {
110
+ clearTimeout(this.timer);
111
+ this.timer = undefined;
112
+ }
113
+ }
114
+ async listTools() {
115
+ const span = (0, telemetry_js_1.startSpan)(this.name, {
116
+ attributes: {
117
+ "span.type": "tool.list",
118
+ },
119
+ });
120
+ try {
121
+ logger_js_1.logger.debug(`MCP:${this.name}:Listing tools`);
122
+ await this.start();
123
+ const { tools } = (await this.client.listTools());
124
+ logger_js_1.logger.debug(`MCP:${this.name}:Listed tools result`, tools);
125
+ await this.close();
126
+ const result = tools.map((tool) => {
127
+ return {
128
+ name: tool.name,
129
+ description: tool.description,
130
+ inputSchema: (0, zodSchema_js_1.schemaToZodSchema)(tool.inputSchema),
131
+ originalSchema: tool.inputSchema,
132
+ call: (input) => {
133
+ return this.call(tool.name, input);
134
+ },
135
+ };
136
+ });
137
+ span.setAttribute("tool.list.result", JSON.stringify(result));
138
+ return result;
139
+ }
140
+ catch (err) {
141
+ span.setStatus("error");
142
+ span.recordException(err);
143
+ throw err;
144
+ }
145
+ finally {
146
+ span.end();
147
+ }
148
+ }
149
+ async call(toolName, args) {
150
+ const span = (0, telemetry_js_1.startSpan)(this.name + "." + toolName, {
151
+ attributes: {
152
+ "span.type": "tool.call",
153
+ "tool.name": toolName,
154
+ "tool.args": JSON.stringify(args),
155
+ },
156
+ });
157
+ try {
158
+ logger_js_1.logger.debug(`MCP:${this.name}:Tool calling`, toolName, JSON.stringify(args));
159
+ logger_js_1.logger.debug(`MCP:${this.name}:Tool calling:start`);
160
+ await this.start();
161
+ logger_js_1.logger.debug(`MCP:${this.name}:Tool calling:start2`);
162
+ const result = await this.client.callTool({
163
+ name: toolName,
164
+ arguments: args,
165
+ });
166
+ logger_js_1.logger.debug(`MCP:${this.name}:Tool calling:result`);
167
+ await this.close();
168
+ logger_js_1.logger.debug(`MCP:${this.name}:Tool result`, toolName, JSON.stringify(args));
169
+ span.setAttribute("tool.call.result", JSON.stringify(result));
170
+ return result;
171
+ }
172
+ catch (err) {
173
+ if (err instanceof Error) {
174
+ logger_js_1.logger.error(err.stack);
175
+ }
176
+ throw err;
177
+ }
178
+ finally {
179
+ span.end();
180
+ }
181
+ }
182
+ }
183
+ exports.McpTool = McpTool;
184
+ const getMcpTool = async (name) => {
185
+ let tool = McpToolCache.get(name);
186
+ if (!tool) {
187
+ logger_js_1.logger.debug(`MCP:${name}:Creating new tool`);
188
+ tool = new McpTool(name);
189
+ McpToolCache.set(name, tool);
190
+ }
191
+ return await tool.listTools();
192
+ };
193
+ exports.getMcpTool = getMcpTool;
@@ -0,0 +1,8 @@
1
+ import z from "zod";
2
+ export type Tool = {
3
+ name: string;
4
+ description: string;
5
+ inputSchema: z.ZodObject<any>;
6
+ originalSchema: object;
7
+ call(input: unknown): Promise<unknown>;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import z from "zod";
2
+ import { FunctionSchema } from "../client/index.js";
3
+ /**
4
+ * Converts an array of `FunctionSchema` objects into a Zod schema for validation.
5
+ *
6
+ * @param {FunctionSchema} parameters - The parameters to convert.
7
+ * @returns {z.ZodObject<any>} A Zod object schema representing the parameters.
8
+ */
9
+ export declare const schemaToZodSchema: (schema: FunctionSchema) => z.ZodObject<any>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.schemaToZodSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ /**
9
+ * Converts an array of `FunctionSchema` objects into a Zod schema for validation.
10
+ *
11
+ * @param {FunctionSchema} parameters - The parameters to convert.
12
+ * @returns {z.ZodObject<any>} A Zod object schema representing the parameters.
13
+ */
14
+ const schemaToZodSchema = (schema) => {
15
+ const shape = {};
16
+ if (schema.properties) {
17
+ Object.entries(schema.properties).forEach(([key, param]) => {
18
+ let zodType;
19
+ switch (param.type) {
20
+ case "boolean":
21
+ zodType = zod_1.default.boolean();
22
+ break;
23
+ case "number":
24
+ zodType = zod_1.default.number();
25
+ break;
26
+ case "array":
27
+ zodType = zod_1.default.array((0, exports.schemaToZodSchema)(param.items || {}));
28
+ break;
29
+ case "object":
30
+ zodType = (0, exports.schemaToZodSchema)(param);
31
+ break;
32
+ default:
33
+ zodType = zod_1.default.string();
34
+ }
35
+ if (param.description) {
36
+ zodType = zodType.describe(param.description);
37
+ }
38
+ shape[key] =
39
+ param.required || schema.required?.includes(key)
40
+ ? zodType
41
+ : zodType.optional();
42
+ });
43
+ }
44
+ return zod_1.default.object(shape);
45
+ };
46
+ exports.schemaToZodSchema = schemaToZodSchema;
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@blaxel/core",
3
+ "version": "0.2.0-dev1",
4
+ "description": "Blaxel Core SDK for TypeScript",
5
+ "license": "MIT",
6
+ "author": "Blaxel, INC (https://blaxel.ai)",
7
+ "homepage": "https://blaxel.ai",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/blaxel/toolkit/sdk-ts"
11
+ },
12
+ "engines": {
13
+ "node": ">=18"
14
+ },
15
+ "keywords": [
16
+ "blaxel",
17
+ "agent",
18
+ "mcp"
19
+ ],
20
+ "main": "dist/index.js",
21
+ "module": "./dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "require": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
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
+ }
44
+ },
45
+ "typesVersions": {
46
+ "*": {
47
+ "*": [
48
+ "./dist/*"
49
+ ]
50
+ }
51
+ },
52
+ "files": [
53
+ "dist"
54
+ ],
55
+ "dependencies": {
56
+ "@hey-api/client-fetch": "^0.10.0",
57
+ "@modelcontextprotocol/sdk": "^1.11.0",
58
+ "crypto": "^1.0.1",
59
+ "jwt-decode": "^4.0.0",
60
+ "toml": "^3.0.0",
61
+ "uuid": "^11.1.0",
62
+ "ws": "^8.18.2",
63
+ "yaml": "^2.7.1",
64
+ "zod": "^3.24.3"
65
+ },
66
+ "devDependencies": {
67
+ "@eslint/js": "^9.26.0",
68
+ "@types/ws": "^8.18.1",
69
+ "typescript": "^5.0.0",
70
+ "typescript-eslint": "^8.31.1"
71
+ },
72
+ "scripts": {
73
+ "lint": "eslint src/",
74
+ "build": "tsc"
75
+ }
76
+ }