@blaxel/core 0.2.71-dev.101 → 0.2.71-preview.103

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 (37) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/agents/index.js +19 -2
  3. package/dist/cjs/common/settings.js +2 -2
  4. package/dist/cjs/jobs/jobs.js +28 -10
  5. package/dist/cjs/mcp/server.js +65 -4
  6. package/dist/cjs/tools/index.js +1 -3
  7. package/dist/cjs/tools/mcpTool.js +43 -15
  8. package/dist/cjs/types/agents/index.d.ts +2 -1
  9. package/dist/cjs/types/jobs/jobs.d.ts +2 -1
  10. package/dist/cjs/types/sandbox/client/types.gen.d.ts +0 -11
  11. package/dist/cjs/types/tools/index.d.ts +0 -1
  12. package/dist/cjs-browser/.tsbuildinfo +1 -1
  13. package/dist/cjs-browser/agents/index.js +19 -2
  14. package/dist/cjs-browser/common/settings.js +2 -2
  15. package/dist/cjs-browser/jobs/jobs.js +28 -10
  16. package/dist/cjs-browser/mcp/server.js +65 -4
  17. package/dist/cjs-browser/tools/index.js +1 -3
  18. package/dist/cjs-browser/tools/mcpTool.js +43 -15
  19. package/dist/cjs-browser/types/agents/index.d.ts +2 -1
  20. package/dist/cjs-browser/types/jobs/jobs.d.ts +2 -1
  21. package/dist/cjs-browser/types/sandbox/client/types.gen.d.ts +0 -11
  22. package/dist/cjs-browser/types/tools/index.d.ts +0 -1
  23. package/dist/esm/.tsbuildinfo +1 -1
  24. package/dist/esm/agents/index.js +19 -1
  25. package/dist/esm/common/settings.js +2 -2
  26. package/dist/esm/jobs/jobs.js +28 -9
  27. package/dist/esm/mcp/server.js +65 -4
  28. package/dist/esm/tools/index.js +0 -1
  29. package/dist/esm/tools/mcpTool.js +43 -15
  30. package/dist/esm-browser/.tsbuildinfo +1 -1
  31. package/dist/esm-browser/agents/index.js +19 -1
  32. package/dist/esm-browser/common/settings.js +2 -2
  33. package/dist/esm-browser/jobs/jobs.js +28 -9
  34. package/dist/esm-browser/mcp/server.js +65 -4
  35. package/dist/esm-browser/tools/index.js +0 -1
  36. package/dist/esm-browser/tools/mcpTool.js +43 -15
  37. package/package.json +1 -1
@@ -3,7 +3,8 @@ import { getAgent } from "../client/index.js";
3
3
  import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
4
4
  import { logger } from "../common/logger.js";
5
5
  import { settings } from "../common/settings.js";
6
- export class BlAgent {
6
+ import { startSpan } from '../telemetry/telemetry.js';
7
+ class BlAgent {
7
8
  agentName;
8
9
  constructor(agentName) {
9
10
  this.agentName = agentName;
@@ -53,25 +54,42 @@ export class BlAgent {
53
54
  }
54
55
  async run(input, headers = {}, params = {}) {
55
56
  logger.debug(`Agent Calling: ${this.agentName}`);
57
+ const span = startSpan(this.agentName, {
58
+ attributes: {
59
+ "agent.name": this.agentName,
60
+ "agent.args": JSON.stringify(input),
61
+ "span.type": "agent.run",
62
+ },
63
+ isRoot: false,
64
+ });
56
65
  try {
57
66
  const response = await this.call(this.url, input, headers, params);
67
+ span.setAttribute("agent.run.result", await response.text());
58
68
  return await response.text();
59
69
  }
60
70
  catch (err) {
61
71
  if (err instanceof Error) {
62
72
  if (!this.fallbackUrl) {
73
+ span.setAttribute("agent.run.error", err.stack);
63
74
  throw err;
64
75
  }
65
76
  try {
66
77
  const response = await this.call(this.fallbackUrl, input, headers, params);
78
+ span.setAttribute("agent.run.result", await response.text());
67
79
  return await response.text();
68
80
  }
69
81
  catch (err) {
82
+ if (err instanceof Error) {
83
+ span.setAttribute("agent.run.error", err.stack);
84
+ }
70
85
  throw err;
71
86
  }
72
87
  }
73
88
  throw err;
74
89
  }
90
+ finally {
91
+ span.end();
92
+ }
75
93
  }
76
94
  }
77
95
  export const blAgent = (agentName) => {
@@ -3,8 +3,8 @@ import { authentication } from "../authentication/index.js";
3
3
  import { env } from "../common/env.js";
4
4
  import { fs, os, path } from "../common/node.js";
5
5
  // Build info - these placeholders are replaced at build time by build:replace-imports
6
- const BUILD_VERSION = "0.2.71-dev.101";
7
- const BUILD_COMMIT = "dccf33c2f51602cd1cd06116b55d326f4645465a";
6
+ const BUILD_VERSION = "0.2.71-preview.103";
7
+ const BUILD_COMMIT = "0638dcc62c9aeebbef9afbf2eabff24a6289fbd9";
8
8
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
9
9
  // Cache for config.yaml tracking value
10
10
  let configTrackingValue = null;
@@ -1,21 +1,40 @@
1
1
  import { createJobExecution, deleteJobExecution, getJobExecution, listJobExecutions, } from "../client/index.js";
2
2
  import { logger } from "../common/logger.js";
3
3
  import { settings } from "../common/settings.js";
4
- export class BlJob {
4
+ import { startSpan } from "../telemetry/telemetry.js";
5
+ class BlJob {
5
6
  jobName;
6
7
  constructor(jobName) {
7
8
  this.jobName = jobName;
8
9
  }
9
10
  async run(tasks, options) {
10
11
  logger.debug(`Job Calling: ${this.jobName}`);
11
- const request = {
12
- tasks,
13
- ...(options?.env && { env: options.env }),
14
- ...(options?.memory && { memory: options.memory }),
15
- ...(options?.executionId && { executionId: options.executionId }),
16
- };
17
- const executionId = await this.createExecution(request);
18
- return executionId;
12
+ const span = startSpan(this.jobName, {
13
+ attributes: {
14
+ "job.name": this.jobName,
15
+ "span.type": "job.run",
16
+ },
17
+ isRoot: false,
18
+ });
19
+ try {
20
+ const request = {
21
+ tasks,
22
+ ...(options?.env && { env: options.env }),
23
+ ...(options?.memory && { memory: options.memory }),
24
+ ...(options?.executionId && { executionId: options.executionId }),
25
+ };
26
+ const executionId = await this.createExecution(request);
27
+ return executionId;
28
+ }
29
+ catch (err) {
30
+ if (err instanceof Error) {
31
+ span.setAttribute("job.run.error", err.stack);
32
+ }
33
+ throw err;
34
+ }
35
+ finally {
36
+ span.end();
37
+ }
19
38
  }
20
39
  /**
21
40
  * Create a new execution for this job and return the execution ID
@@ -2,6 +2,8 @@ import { v4 as uuidv4 } from "uuid";
2
2
  import WebSocket, { WebSocketServer } from "ws";
3
3
  import { env } from "../common/env.js";
4
4
  import { logger } from "../common/logger.js";
5
+ import { startSpan } from "../telemetry/telemetry.js";
6
+ const spans = new Map();
5
7
  export class BlaxelMcpServerTransport {
6
8
  port;
7
9
  wss;
@@ -36,10 +38,26 @@ export class BlaxelMcpServerTransport {
36
38
  ws,
37
39
  });
38
40
  this.onconnection?.(clientId);
39
- ws.on("message", async (data) => {
41
+ ws.on("message", (data) => {
42
+ const span = startSpan("message", {
43
+ attributes: {
44
+ "mcp.client.id": clientId,
45
+ "span.type": "mcp.message",
46
+ },
47
+ isRoot: false,
48
+ });
40
49
  try {
41
50
  const msg = JSON.parse(data.toString());
42
- await this.messageHandler?.(msg, clientId);
51
+ this.messageHandler?.(msg, clientId);
52
+ if ("method" in msg && "id" in msg && "params" in msg) {
53
+ span.setAttributes({
54
+ "mcp.message.parsed": true,
55
+ "mcp.method": msg.method,
56
+ "mcp.messageId": msg.id,
57
+ "mcp.toolName": msg.params?.name,
58
+ });
59
+ spans.set(clientId + ":" + msg.id, span);
60
+ }
43
61
  // Handle msg.id safely
44
62
  const msgId = msg.id ? String(msg.id) : "";
45
63
  const [cId, parsedMsgId] = msgId.split(":");
@@ -47,7 +65,27 @@ export class BlaxelMcpServerTransport {
47
65
  // Use optional chaining for safe access
48
66
  const client = this.clients.get(cId ?? "");
49
67
  if (client?.ws?.readyState === WebSocket.OPEN) {
50
- client.ws.send(JSON.stringify(msg));
68
+ const msgSpan = spans.get(cId + ":" + (msg.id ?? ""));
69
+ try {
70
+ client.ws.send(JSON.stringify(msg));
71
+ if (msgSpan) {
72
+ msgSpan.setAttributes({
73
+ "mcp.message.response_sent": true,
74
+ });
75
+ }
76
+ }
77
+ catch (err) {
78
+ if (msgSpan) {
79
+ msgSpan.setStatus("error"); // Error status
80
+ msgSpan.recordException(err);
81
+ }
82
+ throw err;
83
+ }
84
+ finally {
85
+ if (msgSpan) {
86
+ msgSpan.end();
87
+ }
88
+ }
51
89
  }
52
90
  else {
53
91
  this.clients.delete(cId);
@@ -56,11 +94,14 @@ export class BlaxelMcpServerTransport {
56
94
  }
57
95
  catch (err) {
58
96
  if (err instanceof Error) {
97
+ span.setStatus("error"); // Error status
98
+ span.recordException(err);
59
99
  this.onerror?.(err);
60
100
  }
61
101
  else {
62
102
  this.onerror?.(new Error(`Failed to parse message: ${String(err)}`));
63
103
  }
104
+ span.end();
64
105
  }
65
106
  });
66
107
  ws.on("close", () => {
@@ -82,7 +123,27 @@ export class BlaxelMcpServerTransport {
82
123
  // Send to specific client
83
124
  const client = this.clients.get(cId);
84
125
  if (client?.ws?.readyState === WebSocket.OPEN) {
85
- client.ws.send(data);
126
+ const msgSpan = spans.get(cId + ":" + msg.id);
127
+ try {
128
+ client.ws.send(data);
129
+ if (msgSpan) {
130
+ msgSpan.setAttributes({
131
+ "mcp.message.response_sent": true,
132
+ });
133
+ }
134
+ }
135
+ catch (err) {
136
+ if (msgSpan) {
137
+ msgSpan.setStatus("error"); // Error status
138
+ msgSpan.recordException(err);
139
+ }
140
+ throw err;
141
+ }
142
+ finally {
143
+ if (msgSpan) {
144
+ msgSpan.end();
145
+ }
146
+ }
86
147
  }
87
148
  else {
88
149
  this.clients.delete(cId);
@@ -2,7 +2,6 @@ import { findFromCache } from "../cache/index.js";
2
2
  import { getFunction } from "../client/client.js";
3
3
  import { getForcedUrl } from "../common/internal.js";
4
4
  import { getMcpTool } from "./mcpTool.js";
5
- export { McpTool } from "./mcpTool.js";
6
5
  export const getTool = async (name, options) => {
7
6
  return await getMcpTool(name, options);
8
7
  };
@@ -6,6 +6,7 @@ import { logger } from "../common/logger.js";
6
6
  import { settings } from "../common/settings.js";
7
7
  import { authenticate, SandboxInstance } from "../index.js";
8
8
  import { BlaxelMcpClientTransport } from "../mcp/client.js";
9
+ import { startSpan } from "../telemetry/telemetry.js";
9
10
  import { schemaToZodSchema } from "./zodSchema.js";
10
11
  const McpToolCache = new Map();
11
12
  export class McpTool {
@@ -137,24 +138,47 @@ export class McpTool {
137
138
  }
138
139
  }
139
140
  async listTools() {
140
- logger.debug(`MCP:${this.name}:Listing tools`);
141
- await this.start();
142
- const { tools } = (await this.client.listTools());
143
- await this.close();
144
- const result = tools.map((tool) => {
145
- return {
146
- name: tool.name,
147
- description: tool.description,
148
- inputSchema: schemaToZodSchema(tool.inputSchema),
149
- originalSchema: tool.inputSchema,
150
- call: (input) => {
151
- return this.call(tool.name, input);
152
- },
153
- };
141
+ const span = startSpan(this.name, {
142
+ attributes: {
143
+ "span.type": "tool.list",
144
+ },
154
145
  });
155
- return result;
146
+ try {
147
+ logger.debug(`MCP:${this.name}:Listing tools`);
148
+ await this.start();
149
+ const { tools } = (await this.client.listTools());
150
+ await this.close();
151
+ const result = tools.map((tool) => {
152
+ return {
153
+ name: tool.name,
154
+ description: tool.description,
155
+ inputSchema: schemaToZodSchema(tool.inputSchema),
156
+ originalSchema: tool.inputSchema,
157
+ call: (input) => {
158
+ return this.call(tool.name, input);
159
+ },
160
+ };
161
+ });
162
+ span.setAttribute("tool.list.result", JSON.stringify(result));
163
+ return result;
164
+ }
165
+ catch (err) {
166
+ span.setStatus("error");
167
+ span.recordException(err);
168
+ throw err;
169
+ }
170
+ finally {
171
+ span.end();
172
+ }
156
173
  }
157
174
  async call(toolName, args) {
175
+ const span = startSpan(this.name + "." + toolName, {
176
+ attributes: {
177
+ "span.type": "tool.call",
178
+ "tool.name": toolName,
179
+ "tool.args": JSON.stringify(args),
180
+ },
181
+ });
158
182
  try {
159
183
  logger.debug(`MCP:${this.name}:Tool calling`, toolName, JSON.stringify(args));
160
184
  logger.debug(`MCP:${this.name}:Tool calling:start`);
@@ -168,6 +192,7 @@ export class McpTool {
168
192
  logger.debug(`MCP:${this.name}:Tool calling:result`);
169
193
  await this.close();
170
194
  logger.debug(`MCP:${this.name}:Tool result`, toolName, JSON.stringify(args));
195
+ span.setAttribute("tool.call.result", JSON.stringify(result));
171
196
  return result;
172
197
  }
173
198
  catch (err) {
@@ -182,6 +207,9 @@ export class McpTool {
182
207
  }
183
208
  throw err;
184
209
  }
210
+ finally {
211
+ span.end();
212
+ }
185
213
  }
186
214
  async getTransport(forcedUrl) {
187
215
  if (!this.transportName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.71-dev.101",
3
+ "version": "0.2.71-preview.103",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",