@blaxel/core 0.3.25 → 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.
@@ -24,8 +24,8 @@ function missingCredentialsMessage() {
24
24
  return "No Blaxel credentials found. Set the BL_API_KEY and BL_WORKSPACE environment variables, or run `bl login`.";
25
25
  }
26
26
  // Build info - these placeholders are replaced at build time by build:replace-imports
27
- const BUILD_VERSION = "0.3.25";
28
- const BUILD_COMMIT = "fb45a5005d56241cc56b832f6a624248e8e34f9f";
27
+ const BUILD_VERSION = "0.3.26-preview.309";
28
+ const BUILD_COMMIT = "314ba709f1a271c3a30cea714a3b97c8e8efb144";
29
29
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
30
30
  const BLAXEL_API_VERSION = "2026-09-22";
31
31
  // Bun < 1.3.11 never sends connection-level WINDOW_UPDATE: the pooled h2
@@ -94,8 +94,14 @@ function getOsArch() {
94
94
  }
95
95
  return "browser/unknown";
96
96
  }
97
+ /**
98
+ * An integration built on this SDK identifies itself with one User-Agent
99
+ * product token: `<name>/<semver>`, lowercase name.
100
+ */
101
+ const INTEGRATION_TOKEN_PATTERN = /^[a-z0-9][a-z0-9._-]*\/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
97
102
  class Settings {
98
103
  _credentials;
104
+ _warnedIntegration = null;
99
105
  config;
100
106
  constructor() {
101
107
  // `credentials` are resolved lazily on first access so that simply
@@ -190,14 +196,38 @@ class Settings {
190
196
  get apiVersion() {
191
197
  return env.BL_API_VERSION || BLAXEL_API_VERSION;
192
198
  }
199
+ /**
200
+ * Product token identifying the integration built on this SDK, or `""`.
201
+ * Resolved from `config.integration`, then `BL_INTEGRATION`. See `Config.integration`.
202
+ */
203
+ get integration() {
204
+ const value = this.config.integration ?? env.BL_INTEGRATION ?? "";
205
+ if (!value) {
206
+ return "";
207
+ }
208
+ if (!INTEGRATION_TOKEN_PATTERN.test(value)) {
209
+ // Resolved on every request, so warn once per invalid value rather than per request.
210
+ if (this._warnedIntegration !== value) {
211
+ this._warnedIntegration = value;
212
+ logger.warn(`Ignoring invalid Blaxel integration token ${JSON.stringify(value)}: expected <name>/<semver> with a lowercase name`);
213
+ }
214
+ return "";
215
+ }
216
+ return value;
217
+ }
218
+ set integration(value) {
219
+ this.config.integration = value;
220
+ }
193
221
  get headers() {
194
222
  this.assertCredentials();
195
223
  const osArch = getOsArch();
224
+ const sdkUserAgent = `blaxel/sdk/typescript/${this.version} (${osArch}) blaxel/${this.commit}`;
225
+ const integration = this.integration;
196
226
  return {
197
227
  "x-blaxel-authorization": this.authorization,
198
228
  "x-blaxel-workspace": this.workspace || "",
199
229
  "Blaxel-Version": this.apiVersion,
200
- "User-Agent": `blaxel/sdk/typescript/${this.version} (${osArch}) blaxel/${this.commit}`,
230
+ "User-Agent": integration ? `${sdkUserAgent} ${integration}` : sdkUserAgent,
201
231
  };
202
232
  }
203
233
  get name() {
@@ -1,4 +1,4 @@
1
- import { afterEach, beforeEach, describe, expect, it } from 'vitest';
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
2
  import { ApiKey } from '../authentication/apikey.js';
3
3
  import { env } from './env.js';
4
4
  import { isBrokenBunH2Runtime } from './h2-runtime.js';
@@ -216,3 +216,73 @@ describe('Settings H2 tuning knobs (config > env > default)', () => {
216
216
  });
217
217
  });
218
218
  });
219
+ describe('Settings.integration', () => {
220
+ const sdkUserAgent = /^blaxel\/sdk\/typescript\/\S+ \([^)]+\) blaxel\/\S+/;
221
+ async function authenticated() {
222
+ const { settings } = await import('./settings.js');
223
+ settings.credentials = new ApiKey({ apiKey: 'test-key', workspace: 'test-ws' });
224
+ delete settings.config.integration;
225
+ delete process.env.BL_INTEGRATION;
226
+ return settings;
227
+ }
228
+ afterEach(async () => {
229
+ const { settings } = await import('./settings.js');
230
+ delete settings.config.integration;
231
+ delete process.env.BL_INTEGRATION;
232
+ });
233
+ it('sends the plain SDK User-Agent by default', async () => {
234
+ const settings = await authenticated();
235
+ expect(settings.integration).toBe('');
236
+ expect(settings.headers['User-Agent']).toMatch(new RegExp(sdkUserAgent.source + '$'));
237
+ });
238
+ it('appends the token set programmatically, once', async () => {
239
+ const settings = await authenticated();
240
+ settings.integration = 'deepseek-harness-blaxel-sandbox/0.1.2';
241
+ const userAgent = settings.headers['User-Agent'];
242
+ expect(userAgent).toMatch(sdkUserAgent);
243
+ expect(userAgent.endsWith(' deepseek-harness-blaxel-sandbox/0.1.2')).toBe(true);
244
+ expect(userAgent.split('deepseek-harness-blaxel-sandbox').length).toBe(2);
245
+ });
246
+ it('reads BL_INTEGRATION when nothing is set programmatically, and config wins', async () => {
247
+ const settings = await authenticated();
248
+ process.env.BL_INTEGRATION = 'herdr/1.4.0-rc.1';
249
+ expect(settings.headers['User-Agent'].endsWith(' herdr/1.4.0-rc.1')).toBe(true);
250
+ settings.setConfig({ ...settings.config, integration: 'deepseek-harness-blaxel-sandbox/0.1.2' });
251
+ expect(settings.headers['User-Agent'].endsWith(' deepseek-harness-blaxel-sandbox/0.1.2')).toBe(true);
252
+ });
253
+ 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) => {
254
+ const settings = await authenticated();
255
+ settings.integration = value;
256
+ expect(settings.integration).toBe('');
257
+ expect(settings.headers['User-Agent']).toMatch(new RegExp(sdkUserAgent.source + '$'));
258
+ });
259
+ it('changes no header other than User-Agent', async () => {
260
+ const settings = await authenticated();
261
+ const plain = { ...settings.headers };
262
+ settings.integration = 'deepseek-harness-blaxel-sandbox/0.1.2';
263
+ const tagged = { ...settings.headers };
264
+ delete plain['User-Agent'];
265
+ delete tagged['User-Agent'];
266
+ expect(tagged).toEqual(plain);
267
+ });
268
+ });
269
+ describe('Settings.integration warnings', () => {
270
+ it('warns once per invalid value, not on every request', async () => {
271
+ const { settings } = await import('./settings.js');
272
+ const { logger } = await import('./logger.js');
273
+ const warn = vi.spyOn(logger, 'warn').mockImplementation(() => { });
274
+ try {
275
+ settings.integration = 'Not-Valid';
276
+ for (let i = 0; i < 5; i++)
277
+ expect(settings.integration).toBe('');
278
+ expect(warn).toHaveBeenCalledTimes(1);
279
+ settings.integration = 'also bad';
280
+ expect(settings.integration).toBe('');
281
+ expect(warn).toHaveBeenCalledTimes(2);
282
+ }
283
+ finally {
284
+ warn.mockRestore();
285
+ delete settings.config.integration;
286
+ }
287
+ });
288
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.3.25",
3
+ "version": "0.3.26-preview.309",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",