@blaxel/core 0.3.25-preview.307 → 0.3.26-preview.309

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.
@@ -30,8 +30,8 @@ function missingCredentialsMessage() {
30
30
  return "No Blaxel credentials found. Set the BL_API_KEY and BL_WORKSPACE environment variables, or run `bl login`.";
31
31
  }
32
32
  // Build info - these placeholders are replaced at build time by build:replace-imports
33
- const BUILD_VERSION = "0.3.25-preview.307";
34
- const BUILD_COMMIT = "fb45a5005d56241cc56b832f6a624248e8e34f9f";
33
+ const BUILD_VERSION = "0.3.26-preview.309";
34
+ const BUILD_COMMIT = "314ba709f1a271c3a30cea714a3b97c8e8efb144";
35
35
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
36
36
  const BLAXEL_API_VERSION = "2026-09-22";
37
37
  // Bun < 1.3.11 never sends connection-level WINDOW_UPDATE: the pooled h2
@@ -100,8 +100,14 @@ function getOsArch() {
100
100
  }
101
101
  return "browser/unknown";
102
102
  }
103
+ /**
104
+ * An integration built on this SDK identifies itself with one User-Agent
105
+ * product token: `<name>/<semver>`, lowercase name.
106
+ */
107
+ const INTEGRATION_TOKEN_PATTERN = /^[a-z0-9][a-z0-9._-]*\/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
103
108
  class Settings {
104
109
  _credentials;
110
+ _warnedIntegration = null;
105
111
  config;
106
112
  constructor() {
107
113
  // `credentials` are resolved lazily on first access so that simply
@@ -196,14 +202,38 @@ class Settings {
196
202
  get apiVersion() {
197
203
  return env_js_1.env.BL_API_VERSION || BLAXEL_API_VERSION;
198
204
  }
205
+ /**
206
+ * Product token identifying the integration built on this SDK, or `""`.
207
+ * Resolved from `config.integration`, then `BL_INTEGRATION`. See `Config.integration`.
208
+ */
209
+ get integration() {
210
+ const value = this.config.integration ?? env_js_1.env.BL_INTEGRATION ?? "";
211
+ if (!value) {
212
+ return "";
213
+ }
214
+ if (!INTEGRATION_TOKEN_PATTERN.test(value)) {
215
+ // Resolved on every request, so warn once per invalid value rather than per request.
216
+ if (this._warnedIntegration !== value) {
217
+ this._warnedIntegration = value;
218
+ logger_js_1.logger.warn(`Ignoring invalid Blaxel integration token ${JSON.stringify(value)}: expected <name>/<semver> with a lowercase name`);
219
+ }
220
+ return "";
221
+ }
222
+ return value;
223
+ }
224
+ set integration(value) {
225
+ this.config.integration = value;
226
+ }
199
227
  get headers() {
200
228
  this.assertCredentials();
201
229
  const osArch = getOsArch();
230
+ const sdkUserAgent = `blaxel/sdk/typescript/${this.version} (${osArch}) blaxel/${this.commit}`;
231
+ const integration = this.integration;
202
232
  return {
203
233
  "x-blaxel-authorization": this.authorization,
204
234
  "x-blaxel-workspace": this.workspace || "",
205
235
  "Blaxel-Version": this.apiVersion,
206
- "User-Agent": `blaxel/sdk/typescript/${this.version} (${osArch}) blaxel/${this.commit}`,
236
+ "User-Agent": integration ? `${sdkUserAgent} ${integration}` : sdkUserAgent,
207
237
  };
208
238
  }
209
239
  get name() {
@@ -251,3 +251,73 @@ const h2_runtime_js_1 = require("./h2-runtime.js");
251
251
  });
252
252
  });
253
253
  });
254
+ (0, vitest_1.describe)('Settings.integration', () => {
255
+ const sdkUserAgent = /^blaxel\/sdk\/typescript\/\S+ \([^)]+\) blaxel\/\S+/;
256
+ async function authenticated() {
257
+ const { settings } = await Promise.resolve().then(() => __importStar(require('./settings.js')));
258
+ settings.credentials = new apikey_js_1.ApiKey({ apiKey: 'test-key', workspace: 'test-ws' });
259
+ delete settings.config.integration;
260
+ delete process.env.BL_INTEGRATION;
261
+ return settings;
262
+ }
263
+ (0, vitest_1.afterEach)(async () => {
264
+ const { settings } = await Promise.resolve().then(() => __importStar(require('./settings.js')));
265
+ delete settings.config.integration;
266
+ delete process.env.BL_INTEGRATION;
267
+ });
268
+ (0, vitest_1.it)('sends the plain SDK User-Agent by default', async () => {
269
+ const settings = await authenticated();
270
+ (0, vitest_1.expect)(settings.integration).toBe('');
271
+ (0, vitest_1.expect)(settings.headers['User-Agent']).toMatch(new RegExp(sdkUserAgent.source + '$'));
272
+ });
273
+ (0, vitest_1.it)('appends the token set programmatically, once', async () => {
274
+ const settings = await authenticated();
275
+ settings.integration = 'deepseek-harness-blaxel-sandbox/0.1.2';
276
+ const userAgent = settings.headers['User-Agent'];
277
+ (0, vitest_1.expect)(userAgent).toMatch(sdkUserAgent);
278
+ (0, vitest_1.expect)(userAgent.endsWith(' deepseek-harness-blaxel-sandbox/0.1.2')).toBe(true);
279
+ (0, vitest_1.expect)(userAgent.split('deepseek-harness-blaxel-sandbox').length).toBe(2);
280
+ });
281
+ (0, vitest_1.it)('reads BL_INTEGRATION when nothing is set programmatically, and config wins', async () => {
282
+ const settings = await authenticated();
283
+ process.env.BL_INTEGRATION = 'herdr/1.4.0-rc.1';
284
+ (0, vitest_1.expect)(settings.headers['User-Agent'].endsWith(' herdr/1.4.0-rc.1')).toBe(true);
285
+ settings.setConfig({ ...settings.config, integration: 'deepseek-harness-blaxel-sandbox/0.1.2' });
286
+ (0, vitest_1.expect)(settings.headers['User-Agent'].endsWith(' deepseek-harness-blaxel-sandbox/0.1.2')).toBe(true);
287
+ });
288
+ vitest_1.it.each(['Deepseek/0.1.2', 'deepseek-harness', 'deepseek/0.1', 'a/1.0.0 b/1.0.0', 'deepseek/0.1.2 (extra)', ' x/1.0.0', 'x/1.0.0\n', 'x/1.0.0\r\n'])('ignores the invalid token %j', async (value) => {
289
+ const settings = await authenticated();
290
+ settings.integration = value;
291
+ (0, vitest_1.expect)(settings.integration).toBe('');
292
+ (0, vitest_1.expect)(settings.headers['User-Agent']).toMatch(new RegExp(sdkUserAgent.source + '$'));
293
+ });
294
+ (0, vitest_1.it)('changes no header other than User-Agent', async () => {
295
+ const settings = await authenticated();
296
+ const plain = { ...settings.headers };
297
+ settings.integration = 'deepseek-harness-blaxel-sandbox/0.1.2';
298
+ const tagged = { ...settings.headers };
299
+ delete plain['User-Agent'];
300
+ delete tagged['User-Agent'];
301
+ (0, vitest_1.expect)(tagged).toEqual(plain);
302
+ });
303
+ });
304
+ (0, vitest_1.describe)('Settings.integration warnings', () => {
305
+ (0, vitest_1.it)('warns once per invalid value, not on every request', async () => {
306
+ const { settings } = await Promise.resolve().then(() => __importStar(require('./settings.js')));
307
+ const { logger } = await Promise.resolve().then(() => __importStar(require('./logger.js')));
308
+ const warn = vitest_1.vi.spyOn(logger, 'warn').mockImplementation(() => { });
309
+ try {
310
+ settings.integration = 'Not-Valid';
311
+ for (let i = 0; i < 5; i++)
312
+ (0, vitest_1.expect)(settings.integration).toBe('');
313
+ (0, vitest_1.expect)(warn).toHaveBeenCalledTimes(1);
314
+ settings.integration = 'also bad';
315
+ (0, vitest_1.expect)(settings.integration).toBe('');
316
+ (0, vitest_1.expect)(warn).toHaveBeenCalledTimes(2);
317
+ }
318
+ finally {
319
+ warn.mockRestore();
320
+ delete settings.config.integration;
321
+ }
322
+ });
323
+ });
@@ -11,6 +11,15 @@ export type Config = {
11
11
  proxy?: string;
12
12
  apikey?: string;
13
13
  workspace?: string;
14
+ /**
15
+ * Product token identifying the integration built on this SDK, appended to
16
+ * the `User-Agent` so Blaxel can attribute traffic to it. Format
17
+ * `<name>/<semver>` with a lowercase name, e.g.
18
+ * `"deepseek-harness-blaxel-sandbox/0.1.2"`. Also settable through
19
+ * `BL_INTEGRATION` or `settings.integration`. An invalid value is ignored
20
+ * with a warning.
21
+ */
22
+ integration?: string;
14
23
  /**
15
24
  * Disables the SDK-managed HTTP/2 transport. Defaults to `false` (H2 on);
16
25
  * set this to `true` (or `BL_DISABLE_H2=1`) to opt out of H2. Note that H2 is
@@ -89,6 +98,7 @@ export type Config = {
89
98
  };
90
99
  declare class Settings {
91
100
  private _credentials;
101
+ private _warnedIntegration;
92
102
  config: Config;
93
103
  constructor();
94
104
  get credentials(): Credentials;
@@ -104,6 +114,12 @@ declare class Settings {
104
114
  get commit(): string;
105
115
  get sentryDsn(): string;
106
116
  get apiVersion(): string;
117
+ /**
118
+ * Product token identifying the integration built on this SDK, or `""`.
119
+ * Resolved from `config.integration`, then `BL_INTEGRATION`. See `Config.integration`.
120
+ */
121
+ get integration(): string;
122
+ set integration(value: string | undefined);
107
123
  get headers(): Record<string, string>;
108
124
  get name(): string;
109
125
  get type(): string;