@blaxel/core 0.2.52-dev.9 → 0.2.52-preview.127

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 (57) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/common/autoload.js +0 -3
  3. package/dist/cjs/common/settings.js +47 -13
  4. package/dist/cjs/common/webhook.js +101 -0
  5. package/dist/cjs/index.js +1 -0
  6. package/dist/cjs/sandbox/client/sdk.gen.js +1 -124
  7. package/dist/cjs/sandbox/filesystem/filesystem.js +1 -81
  8. package/dist/cjs/types/client/types.gen.d.ts +12 -0
  9. package/dist/cjs/types/common/settings.d.ts +1 -2
  10. package/dist/cjs/types/common/webhook.d.ts +89 -0
  11. package/dist/cjs/types/index.d.ts +1 -0
  12. package/dist/cjs/types/sandbox/client/sdk.gen.d.ts +1 -36
  13. package/dist/cjs/types/sandbox/client/types.gen.d.ts +0 -315
  14. package/dist/cjs/types/sandbox/filesystem/filesystem.d.ts +2 -5
  15. package/dist/cjs/types/sandbox/filesystem/types.d.ts +0 -20
  16. package/dist/cjs-browser/.tsbuildinfo +1 -1
  17. package/dist/cjs-browser/common/autoload.js +0 -3
  18. package/dist/cjs-browser/common/settings.js +47 -13
  19. package/dist/cjs-browser/common/webhook.js +101 -0
  20. package/dist/cjs-browser/index.js +1 -0
  21. package/dist/cjs-browser/sandbox/client/sdk.gen.js +1 -124
  22. package/dist/cjs-browser/sandbox/filesystem/filesystem.js +1 -81
  23. package/dist/cjs-browser/types/client/types.gen.d.ts +12 -0
  24. package/dist/cjs-browser/types/common/settings.d.ts +1 -2
  25. package/dist/cjs-browser/types/common/webhook.d.ts +89 -0
  26. package/dist/cjs-browser/types/index.d.ts +1 -0
  27. package/dist/cjs-browser/types/sandbox/client/sdk.gen.d.ts +1 -36
  28. package/dist/cjs-browser/types/sandbox/client/types.gen.d.ts +0 -315
  29. package/dist/cjs-browser/types/sandbox/filesystem/filesystem.d.ts +2 -5
  30. package/dist/cjs-browser/types/sandbox/filesystem/types.d.ts +0 -20
  31. package/dist/esm/.tsbuildinfo +1 -1
  32. package/dist/esm/common/autoload.js +0 -3
  33. package/dist/esm/common/settings.js +47 -13
  34. package/dist/esm/common/webhook.js +97 -0
  35. package/dist/esm/index.js +1 -0
  36. package/dist/esm/sandbox/client/sdk.gen.js +0 -116
  37. package/dist/esm/sandbox/filesystem/filesystem.js +2 -82
  38. package/dist/esm-browser/.tsbuildinfo +1 -1
  39. package/dist/esm-browser/common/autoload.js +0 -3
  40. package/dist/esm-browser/common/settings.js +47 -13
  41. package/dist/esm-browser/common/webhook.js +97 -0
  42. package/dist/esm-browser/index.js +1 -0
  43. package/dist/esm-browser/sandbox/client/sdk.gen.js +0 -116
  44. package/dist/esm-browser/sandbox/filesystem/filesystem.js +2 -82
  45. package/package.json +5 -4
  46. package/dist/cjs/common/sentry.js +0 -219
  47. package/dist/cjs/common/version.js +0 -6
  48. package/dist/cjs/types/common/sentry.d.ts +0 -17
  49. package/dist/cjs/types/common/version.d.ts +0 -2
  50. package/dist/cjs-browser/common/sentry.js +0 -219
  51. package/dist/cjs-browser/common/version.js +0 -6
  52. package/dist/cjs-browser/types/common/sentry.d.ts +0 -17
  53. package/dist/cjs-browser/types/common/version.d.ts +0 -2
  54. package/dist/esm/common/sentry.js +0 -181
  55. package/dist/esm/common/version.js +0 -3
  56. package/dist/esm-browser/common/sentry.js +0 -181
  57. package/dist/esm-browser/common/version.js +0 -3
@@ -1,219 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.initSentry = initSentry;
37
- exports.flushSentry = flushSentry;
38
- exports.isSentryInitialized = isSentryInitialized;
39
- const settings_js_1 = require("./settings.js");
40
- const Sentry = __importStar(require("@sentry/node"));
41
- const node_1 = require("@sentry/node");
42
- // Isolated Sentry client for SDK-only error tracking (doesn't interfere with user's Sentry)
43
- let sentryClient = null;
44
- const capturedExceptions = new Set();
45
- let handlersRegistered = false;
46
- // SDK path patterns to identify errors originating from our SDK
47
- const SDK_PATTERNS = [
48
- "@blaxel/",
49
- "blaxel-sdk",
50
- "/node_modules/@blaxel/",
51
- "/@blaxel/core/",
52
- "/@blaxel/telemetry/",
53
- ];
54
- /**
55
- * Check if an error originated from the SDK based on its stack trace.
56
- * Returns true if the stack trace contains any SDK-related paths.
57
- */
58
- function isFromSDK(error) {
59
- const stack = error.stack || "";
60
- return SDK_PATTERNS.some((pattern) => stack.includes(pattern));
61
- }
62
- /**
63
- * Initialize an isolated Sentry client for SDK error tracking.
64
- * This creates a separate Sentry instance that won't interfere with any
65
- * Sentry configuration the user might have in their application.
66
- */
67
- function initSentry() {
68
- try {
69
- const dsn = settings_js_1.settings.sentryDsn;
70
- if (!dsn) {
71
- return;
72
- }
73
- // Create an isolated Sentry client that doesn't touch the global scope
74
- // This allows users to have their own Sentry.init() without conflicts
75
- sentryClient = new Sentry.NodeClient({
76
- dsn,
77
- environment: settings_js_1.settings.env,
78
- release: `sdk-typescript@${settings_js_1.settings.version}`,
79
- transport: node_1.makeNodeTransport,
80
- stackParser: Sentry.defaultStackParser,
81
- // No integrations - we handle error capturing manually
82
- integrations: [],
83
- // Disable traces for the SDK client
84
- tracesSampleRate: 0,
85
- // Filter errors before sending - only send SDK errors
86
- beforeSend(event, hint) {
87
- const error = hint.originalException;
88
- if (error instanceof Error) {
89
- if (!isFromSDK(error)) {
90
- // Drop errors that don't originate from SDK
91
- return null;
92
- }
93
- }
94
- return event;
95
- },
96
- });
97
- sentryClient.init();
98
- // Set SDK-specific tags
99
- const scope = new Sentry.Scope();
100
- scope.setTag("blaxel.workspace", settings_js_1.settings.workspace);
101
- scope.setTag("blaxel.version", settings_js_1.settings.version);
102
- scope.setTag("blaxel.commit", settings_js_1.settings.commit);
103
- scope.setClient(sentryClient);
104
- // Register process handlers for uncaught errors (Node.js only)
105
- // Only register once to prevent memory leaks
106
- if (typeof process !== "undefined" &&
107
- typeof process.on === "function" &&
108
- !handlersRegistered) {
109
- handlersRegistered = true;
110
- // For SIGTERM/SIGINT, flush before exit
111
- const signalHandler = (signal) => {
112
- flushSentry(500)
113
- .catch(() => {
114
- // Silently fail
115
- })
116
- .finally(() => {
117
- process.exit(signal === "SIGTERM" ? 143 : 130);
118
- });
119
- };
120
- // Uncaught exception handler - only capture SDK errors
121
- const uncaughtExceptionHandler = (error) => {
122
- if (isFromSDK(error)) {
123
- captureException(error);
124
- }
125
- // Let the default Node.js behavior handle the process exit
126
- };
127
- // Unhandled rejection handler - only capture SDK errors
128
- const unhandledRejectionHandler = (reason) => {
129
- const error = reason instanceof Error ? reason : new Error(String(reason));
130
- if (isFromSDK(error)) {
131
- captureException(error);
132
- }
133
- };
134
- process.on("SIGTERM", () => signalHandler("SIGTERM"));
135
- process.on("SIGINT", () => signalHandler("SIGINT"));
136
- process.on("uncaughtException", uncaughtExceptionHandler);
137
- process.on("unhandledRejection", unhandledRejectionHandler);
138
- // Intercept console.error to capture SDK errors that are caught and logged
139
- const originalConsoleError = console.error;
140
- console.error = function (...args) {
141
- // Call the original console.error first
142
- originalConsoleError.apply(console, args);
143
- // Check if any argument is an Error from SDK and capture it
144
- for (const arg of args) {
145
- if (arg instanceof Error && isFromSDK(arg)) {
146
- captureException(arg);
147
- break; // Only capture the first SDK error to avoid duplicates
148
- }
149
- }
150
- };
151
- }
152
- }
153
- catch (error) {
154
- // Silently fail - Sentry initialization should never break the SDK
155
- if (settings_js_1.settings.env !== "production") {
156
- console.error("[Blaxel SDK] Error initializing Sentry:", error);
157
- }
158
- }
159
- }
160
- /**
161
- * Capture an exception to the SDK's isolated Sentry client.
162
- * Only errors originating from SDK code will be captured.
163
- *
164
- * @param error - The error to capture
165
- */
166
- function captureException(error) {
167
- if (sentryClient === null) {
168
- return;
169
- }
170
- // Double-check that error is from SDK (defense in depth)
171
- if (!isFromSDK(error)) {
172
- return;
173
- }
174
- try {
175
- // Create a unique identifier for this exception to avoid duplicates
176
- const errorKey = `${error.name}:${error.message}:${error.stack?.slice(0, 200)}`;
177
- if (capturedExceptions.has(errorKey)) {
178
- return;
179
- }
180
- capturedExceptions.add(errorKey);
181
- // Clean up old exception keys to prevent memory leak
182
- if (capturedExceptions.size > 1000) {
183
- capturedExceptions.clear();
184
- }
185
- // Create a scope with SDK tags and capture the exception
186
- const scope = new Sentry.Scope();
187
- scope.setTag("blaxel.workspace", settings_js_1.settings.workspace);
188
- scope.setTag("blaxel.version", settings_js_1.settings.version);
189
- scope.setTag("blaxel.commit", settings_js_1.settings.commit);
190
- scope.setClient(sentryClient);
191
- scope.captureException(error);
192
- }
193
- catch {
194
- // Silently fail - error capturing should never break the SDK
195
- }
196
- }
197
- /**
198
- * Flush pending Sentry events.
199
- * This should be called before the process exits to ensure all events are sent.
200
- *
201
- * @param timeout - Maximum time in milliseconds to wait for flush (default: 2000)
202
- */
203
- async function flushSentry(timeout = 2000) {
204
- if (sentryClient === null) {
205
- return;
206
- }
207
- try {
208
- await sentryClient.flush(timeout);
209
- }
210
- catch {
211
- // Silently fail
212
- }
213
- }
214
- /**
215
- * Check if Sentry is initialized and available.
216
- */
217
- function isSentryInitialized() {
218
- return sentryClient !== null;
219
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PACKAGE_COMMIT = exports.PACKAGE_VERSION = void 0;
4
- // This file is auto-generated during build. Do not edit manually.
5
- exports.PACKAGE_VERSION = "0.2.50";
6
- exports.PACKAGE_COMMIT = "4a74989dcb65a6ff8d826aed7976436c64554f6a";
@@ -1,17 +0,0 @@
1
- /**
2
- * Initialize an isolated Sentry client for SDK error tracking.
3
- * This creates a separate Sentry instance that won't interfere with any
4
- * Sentry configuration the user might have in their application.
5
- */
6
- export declare function initSentry(): void;
7
- /**
8
- * Flush pending Sentry events.
9
- * This should be called before the process exits to ensure all events are sent.
10
- *
11
- * @param timeout - Maximum time in milliseconds to wait for flush (default: 2000)
12
- */
13
- export declare function flushSentry(timeout?: number): Promise<void>;
14
- /**
15
- * Check if Sentry is initialized and available.
16
- */
17
- export declare function isSentryInitialized(): boolean;
@@ -1,2 +0,0 @@
1
- export declare const PACKAGE_VERSION = "0.2.50";
2
- export declare const PACKAGE_COMMIT = "4a74989dcb65a6ff8d826aed7976436c64554f6a";
@@ -1,219 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.initSentry = initSentry;
37
- exports.flushSentry = flushSentry;
38
- exports.isSentryInitialized = isSentryInitialized;
39
- const settings_js_1 = require("./settings.js");
40
- const Sentry = __importStar(require("@sentry/node"));
41
- const node_1 = require("@sentry/node");
42
- // Isolated Sentry client for SDK-only error tracking (doesn't interfere with user's Sentry)
43
- let sentryClient = null;
44
- const capturedExceptions = new Set();
45
- let handlersRegistered = false;
46
- // SDK path patterns to identify errors originating from our SDK
47
- const SDK_PATTERNS = [
48
- "@blaxel/",
49
- "blaxel-sdk",
50
- "/node_modules/@blaxel/",
51
- "/@blaxel/core/",
52
- "/@blaxel/telemetry/",
53
- ];
54
- /**
55
- * Check if an error originated from the SDK based on its stack trace.
56
- * Returns true if the stack trace contains any SDK-related paths.
57
- */
58
- function isFromSDK(error) {
59
- const stack = error.stack || "";
60
- return SDK_PATTERNS.some((pattern) => stack.includes(pattern));
61
- }
62
- /**
63
- * Initialize an isolated Sentry client for SDK error tracking.
64
- * This creates a separate Sentry instance that won't interfere with any
65
- * Sentry configuration the user might have in their application.
66
- */
67
- function initSentry() {
68
- try {
69
- const dsn = settings_js_1.settings.sentryDsn;
70
- if (!dsn) {
71
- return;
72
- }
73
- // Create an isolated Sentry client that doesn't touch the global scope
74
- // This allows users to have their own Sentry.init() without conflicts
75
- sentryClient = new Sentry.NodeClient({
76
- dsn,
77
- environment: settings_js_1.settings.env,
78
- release: `sdk-typescript@${settings_js_1.settings.version}`,
79
- transport: node_1.makeNodeTransport,
80
- stackParser: Sentry.defaultStackParser,
81
- // No integrations - we handle error capturing manually
82
- integrations: [],
83
- // Disable traces for the SDK client
84
- tracesSampleRate: 0,
85
- // Filter errors before sending - only send SDK errors
86
- beforeSend(event, hint) {
87
- const error = hint.originalException;
88
- if (error instanceof Error) {
89
- if (!isFromSDK(error)) {
90
- // Drop errors that don't originate from SDK
91
- return null;
92
- }
93
- }
94
- return event;
95
- },
96
- });
97
- sentryClient.init();
98
- // Set SDK-specific tags
99
- const scope = new Sentry.Scope();
100
- scope.setTag("blaxel.workspace", settings_js_1.settings.workspace);
101
- scope.setTag("blaxel.version", settings_js_1.settings.version);
102
- scope.setTag("blaxel.commit", settings_js_1.settings.commit);
103
- scope.setClient(sentryClient);
104
- // Register process handlers for uncaught errors (Node.js only)
105
- // Only register once to prevent memory leaks
106
- if (typeof process !== "undefined" &&
107
- typeof process.on === "function" &&
108
- !handlersRegistered) {
109
- handlersRegistered = true;
110
- // For SIGTERM/SIGINT, flush before exit
111
- const signalHandler = (signal) => {
112
- flushSentry(500)
113
- .catch(() => {
114
- // Silently fail
115
- })
116
- .finally(() => {
117
- process.exit(signal === "SIGTERM" ? 143 : 130);
118
- });
119
- };
120
- // Uncaught exception handler - only capture SDK errors
121
- const uncaughtExceptionHandler = (error) => {
122
- if (isFromSDK(error)) {
123
- captureException(error);
124
- }
125
- // Let the default Node.js behavior handle the process exit
126
- };
127
- // Unhandled rejection handler - only capture SDK errors
128
- const unhandledRejectionHandler = (reason) => {
129
- const error = reason instanceof Error ? reason : new Error(String(reason));
130
- if (isFromSDK(error)) {
131
- captureException(error);
132
- }
133
- };
134
- process.on("SIGTERM", () => signalHandler("SIGTERM"));
135
- process.on("SIGINT", () => signalHandler("SIGINT"));
136
- process.on("uncaughtException", uncaughtExceptionHandler);
137
- process.on("unhandledRejection", unhandledRejectionHandler);
138
- // Intercept console.error to capture SDK errors that are caught and logged
139
- const originalConsoleError = console.error;
140
- console.error = function (...args) {
141
- // Call the original console.error first
142
- originalConsoleError.apply(console, args);
143
- // Check if any argument is an Error from SDK and capture it
144
- for (const arg of args) {
145
- if (arg instanceof Error && isFromSDK(arg)) {
146
- captureException(arg);
147
- break; // Only capture the first SDK error to avoid duplicates
148
- }
149
- }
150
- };
151
- }
152
- }
153
- catch (error) {
154
- // Silently fail - Sentry initialization should never break the SDK
155
- if (settings_js_1.settings.env !== "production") {
156
- console.error("[Blaxel SDK] Error initializing Sentry:", error);
157
- }
158
- }
159
- }
160
- /**
161
- * Capture an exception to the SDK's isolated Sentry client.
162
- * Only errors originating from SDK code will be captured.
163
- *
164
- * @param error - The error to capture
165
- */
166
- function captureException(error) {
167
- if (sentryClient === null) {
168
- return;
169
- }
170
- // Double-check that error is from SDK (defense in depth)
171
- if (!isFromSDK(error)) {
172
- return;
173
- }
174
- try {
175
- // Create a unique identifier for this exception to avoid duplicates
176
- const errorKey = `${error.name}:${error.message}:${error.stack?.slice(0, 200)}`;
177
- if (capturedExceptions.has(errorKey)) {
178
- return;
179
- }
180
- capturedExceptions.add(errorKey);
181
- // Clean up old exception keys to prevent memory leak
182
- if (capturedExceptions.size > 1000) {
183
- capturedExceptions.clear();
184
- }
185
- // Create a scope with SDK tags and capture the exception
186
- const scope = new Sentry.Scope();
187
- scope.setTag("blaxel.workspace", settings_js_1.settings.workspace);
188
- scope.setTag("blaxel.version", settings_js_1.settings.version);
189
- scope.setTag("blaxel.commit", settings_js_1.settings.commit);
190
- scope.setClient(sentryClient);
191
- scope.captureException(error);
192
- }
193
- catch {
194
- // Silently fail - error capturing should never break the SDK
195
- }
196
- }
197
- /**
198
- * Flush pending Sentry events.
199
- * This should be called before the process exits to ensure all events are sent.
200
- *
201
- * @param timeout - Maximum time in milliseconds to wait for flush (default: 2000)
202
- */
203
- async function flushSentry(timeout = 2000) {
204
- if (sentryClient === null) {
205
- return;
206
- }
207
- try {
208
- await sentryClient.flush(timeout);
209
- }
210
- catch {
211
- // Silently fail
212
- }
213
- }
214
- /**
215
- * Check if Sentry is initialized and available.
216
- */
217
- function isSentryInitialized() {
218
- return sentryClient !== null;
219
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PACKAGE_COMMIT = exports.PACKAGE_VERSION = void 0;
4
- // This file is auto-generated during build. Do not edit manually.
5
- exports.PACKAGE_VERSION = "0.2.50";
6
- exports.PACKAGE_COMMIT = "4a74989dcb65a6ff8d826aed7976436c64554f6a";
@@ -1,17 +0,0 @@
1
- /**
2
- * Initialize an isolated Sentry client for SDK error tracking.
3
- * This creates a separate Sentry instance that won't interfere with any
4
- * Sentry configuration the user might have in their application.
5
- */
6
- export declare function initSentry(): void;
7
- /**
8
- * Flush pending Sentry events.
9
- * This should be called before the process exits to ensure all events are sent.
10
- *
11
- * @param timeout - Maximum time in milliseconds to wait for flush (default: 2000)
12
- */
13
- export declare function flushSentry(timeout?: number): Promise<void>;
14
- /**
15
- * Check if Sentry is initialized and available.
16
- */
17
- export declare function isSentryInitialized(): boolean;
@@ -1,2 +0,0 @@
1
- export declare const PACKAGE_VERSION = "0.2.50";
2
- export declare const PACKAGE_COMMIT = "4a74989dcb65a6ff8d826aed7976436c64554f6a";
@@ -1,181 +0,0 @@
1
- import { settings } from "./settings.js";
2
- import * as Sentry from "@sentry/node";
3
- import { makeNodeTransport } from "@sentry/node";
4
- // Isolated Sentry client for SDK-only error tracking (doesn't interfere with user's Sentry)
5
- let sentryClient = null;
6
- const capturedExceptions = new Set();
7
- let handlersRegistered = false;
8
- // SDK path patterns to identify errors originating from our SDK
9
- const SDK_PATTERNS = [
10
- "@blaxel/",
11
- "blaxel-sdk",
12
- "/node_modules/@blaxel/",
13
- "/@blaxel/core/",
14
- "/@blaxel/telemetry/",
15
- ];
16
- /**
17
- * Check if an error originated from the SDK based on its stack trace.
18
- * Returns true if the stack trace contains any SDK-related paths.
19
- */
20
- function isFromSDK(error) {
21
- const stack = error.stack || "";
22
- return SDK_PATTERNS.some((pattern) => stack.includes(pattern));
23
- }
24
- /**
25
- * Initialize an isolated Sentry client for SDK error tracking.
26
- * This creates a separate Sentry instance that won't interfere with any
27
- * Sentry configuration the user might have in their application.
28
- */
29
- export function initSentry() {
30
- try {
31
- const dsn = settings.sentryDsn;
32
- if (!dsn) {
33
- return;
34
- }
35
- // Create an isolated Sentry client that doesn't touch the global scope
36
- // This allows users to have their own Sentry.init() without conflicts
37
- sentryClient = new Sentry.NodeClient({
38
- dsn,
39
- environment: settings.env,
40
- release: `sdk-typescript@${settings.version}`,
41
- transport: makeNodeTransport,
42
- stackParser: Sentry.defaultStackParser,
43
- // No integrations - we handle error capturing manually
44
- integrations: [],
45
- // Disable traces for the SDK client
46
- tracesSampleRate: 0,
47
- // Filter errors before sending - only send SDK errors
48
- beforeSend(event, hint) {
49
- const error = hint.originalException;
50
- if (error instanceof Error) {
51
- if (!isFromSDK(error)) {
52
- // Drop errors that don't originate from SDK
53
- return null;
54
- }
55
- }
56
- return event;
57
- },
58
- });
59
- sentryClient.init();
60
- // Set SDK-specific tags
61
- const scope = new Sentry.Scope();
62
- scope.setTag("blaxel.workspace", settings.workspace);
63
- scope.setTag("blaxel.version", settings.version);
64
- scope.setTag("blaxel.commit", settings.commit);
65
- scope.setClient(sentryClient);
66
- // Register process handlers for uncaught errors (Node.js only)
67
- // Only register once to prevent memory leaks
68
- if (typeof process !== "undefined" &&
69
- typeof process.on === "function" &&
70
- !handlersRegistered) {
71
- handlersRegistered = true;
72
- // For SIGTERM/SIGINT, flush before exit
73
- const signalHandler = (signal) => {
74
- flushSentry(500)
75
- .catch(() => {
76
- // Silently fail
77
- })
78
- .finally(() => {
79
- process.exit(signal === "SIGTERM" ? 143 : 130);
80
- });
81
- };
82
- // Uncaught exception handler - only capture SDK errors
83
- const uncaughtExceptionHandler = (error) => {
84
- if (isFromSDK(error)) {
85
- captureException(error);
86
- }
87
- // Let the default Node.js behavior handle the process exit
88
- };
89
- // Unhandled rejection handler - only capture SDK errors
90
- const unhandledRejectionHandler = (reason) => {
91
- const error = reason instanceof Error ? reason : new Error(String(reason));
92
- if (isFromSDK(error)) {
93
- captureException(error);
94
- }
95
- };
96
- process.on("SIGTERM", () => signalHandler("SIGTERM"));
97
- process.on("SIGINT", () => signalHandler("SIGINT"));
98
- process.on("uncaughtException", uncaughtExceptionHandler);
99
- process.on("unhandledRejection", unhandledRejectionHandler);
100
- // Intercept console.error to capture SDK errors that are caught and logged
101
- const originalConsoleError = console.error;
102
- console.error = function (...args) {
103
- // Call the original console.error first
104
- originalConsoleError.apply(console, args);
105
- // Check if any argument is an Error from SDK and capture it
106
- for (const arg of args) {
107
- if (arg instanceof Error && isFromSDK(arg)) {
108
- captureException(arg);
109
- break; // Only capture the first SDK error to avoid duplicates
110
- }
111
- }
112
- };
113
- }
114
- }
115
- catch (error) {
116
- // Silently fail - Sentry initialization should never break the SDK
117
- if (settings.env !== "production") {
118
- console.error("[Blaxel SDK] Error initializing Sentry:", error);
119
- }
120
- }
121
- }
122
- /**
123
- * Capture an exception to the SDK's isolated Sentry client.
124
- * Only errors originating from SDK code will be captured.
125
- *
126
- * @param error - The error to capture
127
- */
128
- function captureException(error) {
129
- if (sentryClient === null) {
130
- return;
131
- }
132
- // Double-check that error is from SDK (defense in depth)
133
- if (!isFromSDK(error)) {
134
- return;
135
- }
136
- try {
137
- // Create a unique identifier for this exception to avoid duplicates
138
- const errorKey = `${error.name}:${error.message}:${error.stack?.slice(0, 200)}`;
139
- if (capturedExceptions.has(errorKey)) {
140
- return;
141
- }
142
- capturedExceptions.add(errorKey);
143
- // Clean up old exception keys to prevent memory leak
144
- if (capturedExceptions.size > 1000) {
145
- capturedExceptions.clear();
146
- }
147
- // Create a scope with SDK tags and capture the exception
148
- const scope = new Sentry.Scope();
149
- scope.setTag("blaxel.workspace", settings.workspace);
150
- scope.setTag("blaxel.version", settings.version);
151
- scope.setTag("blaxel.commit", settings.commit);
152
- scope.setClient(sentryClient);
153
- scope.captureException(error);
154
- }
155
- catch {
156
- // Silently fail - error capturing should never break the SDK
157
- }
158
- }
159
- /**
160
- * Flush pending Sentry events.
161
- * This should be called before the process exits to ensure all events are sent.
162
- *
163
- * @param timeout - Maximum time in milliseconds to wait for flush (default: 2000)
164
- */
165
- export async function flushSentry(timeout = 2000) {
166
- if (sentryClient === null) {
167
- return;
168
- }
169
- try {
170
- await sentryClient.flush(timeout);
171
- }
172
- catch {
173
- // Silently fail
174
- }
175
- }
176
- /**
177
- * Check if Sentry is initialized and available.
178
- */
179
- export function isSentryInitialized() {
180
- return sentryClient !== null;
181
- }
@@ -1,3 +0,0 @@
1
- // This file is auto-generated during build. Do not edit manually.
2
- export const PACKAGE_VERSION = "0.2.50";
3
- export const PACKAGE_COMMIT = "4a74989dcb65a6ff8d826aed7976436c64554f6a";