@bitfab/sdk 0.54.6 → 0.54.8

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.
package/dist/index.d.cts CHANGED
@@ -426,6 +426,8 @@ declare class HttpClient {
426
426
  * the function form if one was supplied. Never read at construction.
427
427
  */
428
428
  private resolveApiKey;
429
+ /** @internal Whether this client currently has credentials for trace delivery. */
430
+ hasApiKey(): boolean;
429
431
  /**
430
432
  * This client's span transport, built on first use.
431
433
  *
@@ -917,6 +919,7 @@ declare class BitfabClaudeAgentHandler {
917
919
  private readonly ownsHttpClient;
918
920
  private readonly traceFunctionKey;
919
921
  private readonly getActiveSpanContext;
922
+ private readonly shouldRecord;
920
923
  private runToSpan;
921
924
  private traceId;
922
925
  private rootSpanId;
@@ -941,6 +944,7 @@ declare class BitfabClaudeAgentHandler {
941
944
  serviceUrl?: string;
942
945
  timeout?: number;
943
946
  getActiveSpanContext?: () => ActiveSpanContext$2 | null;
947
+ shouldRecord?: () => boolean;
944
948
  /**
945
949
  * The owning `Bitfab` client's HTTP client. Supplied by
946
950
  * `getClaudeAgentHandler()` so this handler shares that client's single
@@ -1412,6 +1416,7 @@ declare class BitfabLangGraphCallbackHandler {
1412
1416
  private readonly ownsHttpClient;
1413
1417
  private readonly traceFunctionKey;
1414
1418
  private readonly getActiveSpanContext;
1419
+ private readonly shouldRecord;
1415
1420
  private readonly captureTools;
1416
1421
  private runToSpan;
1417
1422
  private invocations;
@@ -1421,6 +1426,7 @@ declare class BitfabLangGraphCallbackHandler {
1421
1426
  serviceUrl?: string;
1422
1427
  timeout?: number;
1423
1428
  getActiveSpanContext?: () => ActiveSpanContext$1 | null;
1429
+ shouldRecord?: () => boolean;
1424
1430
  /** Whether callback tool events should emit spans. Defaults to true. */
1425
1431
  captureTools?: boolean;
1426
1432
  /**
@@ -2322,6 +2328,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
2322
2328
  private readonly ownsHttpClient;
2323
2329
  private activeTraces;
2324
2330
  private readonly getActiveSpanContext;
2331
+ private readonly shouldRecord;
2325
2332
  private activeSpanMappings;
2326
2333
  private canonicalTraceIds;
2327
2334
  private getCanonicalTraceId;
@@ -2335,6 +2342,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
2335
2342
  serviceUrl?: string;
2336
2343
  timeout?: number;
2337
2344
  getActiveSpanContext?: () => ActiveSpanContext | null;
2345
+ shouldRecord?: () => boolean;
2338
2346
  /**
2339
2347
  * The owning `Bitfab` client's HTTP client. Supplied by
2340
2348
  * `getOpenAiTracingProcessor()` so this processor shares that client's
@@ -2755,7 +2763,8 @@ declare class Bitfab {
2755
2763
  private readonly serviceUrl;
2756
2764
  private readonly timeout;
2757
2765
  private readonly envVars;
2758
- private readonly captureConfigured;
2766
+ private readonly captureConfiguredInCode;
2767
+ private captureConfiguredFromEnv;
2759
2768
  private readonly strict;
2760
2769
  private readonly httpClient;
2761
2770
  /** Dataset operations for the authenticated organization. */
@@ -2876,8 +2885,10 @@ declare class Bitfab {
2876
2885
  * early resolve that found nothing never poisons a later one.
2877
2886
  */
2878
2887
  private resolveApiKey;
2888
+ private isCaptureConfigured;
2879
2889
  private isCaptureEnabled;
2880
2890
  private shouldRecord;
2891
+ private prepareFrameworkIntegration;
2881
2892
  get captureEnabled(): boolean;
2882
2893
  /**
2883
2894
  * Fetch the function with its current version and BAML prompt from the server.
@@ -3420,7 +3431,7 @@ interface CommitRef {
3420
3431
  /**
3421
3432
  * SDK version from package.json (injected at build time)
3422
3433
  */
3423
- declare const __version__ = "0.54.6";
3434
+ declare const __version__ = "0.54.8";
3424
3435
 
3425
3436
  /**
3426
3437
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -426,6 +426,8 @@ declare class HttpClient {
426
426
  * the function form if one was supplied. Never read at construction.
427
427
  */
428
428
  private resolveApiKey;
429
+ /** @internal Whether this client currently has credentials for trace delivery. */
430
+ hasApiKey(): boolean;
429
431
  /**
430
432
  * This client's span transport, built on first use.
431
433
  *
@@ -917,6 +919,7 @@ declare class BitfabClaudeAgentHandler {
917
919
  private readonly ownsHttpClient;
918
920
  private readonly traceFunctionKey;
919
921
  private readonly getActiveSpanContext;
922
+ private readonly shouldRecord;
920
923
  private runToSpan;
921
924
  private traceId;
922
925
  private rootSpanId;
@@ -941,6 +944,7 @@ declare class BitfabClaudeAgentHandler {
941
944
  serviceUrl?: string;
942
945
  timeout?: number;
943
946
  getActiveSpanContext?: () => ActiveSpanContext$2 | null;
947
+ shouldRecord?: () => boolean;
944
948
  /**
945
949
  * The owning `Bitfab` client's HTTP client. Supplied by
946
950
  * `getClaudeAgentHandler()` so this handler shares that client's single
@@ -1412,6 +1416,7 @@ declare class BitfabLangGraphCallbackHandler {
1412
1416
  private readonly ownsHttpClient;
1413
1417
  private readonly traceFunctionKey;
1414
1418
  private readonly getActiveSpanContext;
1419
+ private readonly shouldRecord;
1415
1420
  private readonly captureTools;
1416
1421
  private runToSpan;
1417
1422
  private invocations;
@@ -1421,6 +1426,7 @@ declare class BitfabLangGraphCallbackHandler {
1421
1426
  serviceUrl?: string;
1422
1427
  timeout?: number;
1423
1428
  getActiveSpanContext?: () => ActiveSpanContext$1 | null;
1429
+ shouldRecord?: () => boolean;
1424
1430
  /** Whether callback tool events should emit spans. Defaults to true. */
1425
1431
  captureTools?: boolean;
1426
1432
  /**
@@ -2322,6 +2328,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
2322
2328
  private readonly ownsHttpClient;
2323
2329
  private activeTraces;
2324
2330
  private readonly getActiveSpanContext;
2331
+ private readonly shouldRecord;
2325
2332
  private activeSpanMappings;
2326
2333
  private canonicalTraceIds;
2327
2334
  private getCanonicalTraceId;
@@ -2335,6 +2342,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
2335
2342
  serviceUrl?: string;
2336
2343
  timeout?: number;
2337
2344
  getActiveSpanContext?: () => ActiveSpanContext | null;
2345
+ shouldRecord?: () => boolean;
2338
2346
  /**
2339
2347
  * The owning `Bitfab` client's HTTP client. Supplied by
2340
2348
  * `getOpenAiTracingProcessor()` so this processor shares that client's
@@ -2755,7 +2763,8 @@ declare class Bitfab {
2755
2763
  private readonly serviceUrl;
2756
2764
  private readonly timeout;
2757
2765
  private readonly envVars;
2758
- private readonly captureConfigured;
2766
+ private readonly captureConfiguredInCode;
2767
+ private captureConfiguredFromEnv;
2759
2768
  private readonly strict;
2760
2769
  private readonly httpClient;
2761
2770
  /** Dataset operations for the authenticated organization. */
@@ -2876,8 +2885,10 @@ declare class Bitfab {
2876
2885
  * early resolve that found nothing never poisons a later one.
2877
2886
  */
2878
2887
  private resolveApiKey;
2888
+ private isCaptureConfigured;
2879
2889
  private isCaptureEnabled;
2880
2890
  private shouldRecord;
2891
+ private prepareFrameworkIntegration;
2881
2892
  get captureEnabled(): boolean;
2882
2893
  /**
2883
2894
  * Fetch the function with its current version and BAML prompt from the server.
@@ -3420,7 +3431,7 @@ interface CommitRef {
3420
3431
  /**
3421
3432
  * SDK version from package.json (injected at build time)
3422
3433
  */
3423
- declare const __version__ = "0.54.6";
3434
+ declare const __version__ = "0.54.8";
3424
3435
 
3425
3436
  /**
3426
3437
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  getCurrentTrace,
21
21
  reseedFromRegistry,
22
22
  seedFromRegistry
23
- } from "./chunk-2ZUDLA5T.js";
23
+ } from "./chunk-L4SB4W3Z.js";
24
24
  import "./chunk-EGWJYCNT.js";
25
25
  import {
26
26
  BITFAB_PROGRESS_PREFIX,
@@ -29,7 +29,7 @@ import {
29
29
  ReplayError,
30
30
  reportReplayProgress,
31
31
  serializeReplayResult
32
- } from "./chunk-2J7QZHRC.js";
32
+ } from "./chunk-M2AEKEZE.js";
33
33
  import {
34
34
  BitfabError,
35
35
  DEFAULT_SERVICE_URL,
@@ -37,7 +37,7 @@ import {
37
37
  MixedTracingError,
38
38
  __version__,
39
39
  flushTraces
40
- } from "./chunk-QEQXIG5A.js";
40
+ } from "./chunk-4LMLPCYL.js";
41
41
  import "./chunk-VCRFFCLY.js";
42
42
  export {
43
43
  AssertionCategoriesClient,
package/dist/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__, __packageName__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.54.6";
91
+ __version__ = "0.54.8";
92
92
  __packageName__ = "@bitfab/sdk";
93
93
  }
94
94
  });
@@ -2320,6 +2320,15 @@ var init_http = __esm({
2320
2320
  resolveApiKey() {
2321
2321
  return typeof this.apiKey === "function" ? this.apiKey() : this.apiKey;
2322
2322
  }
2323
+ /** @internal Whether this client currently has credentials for trace delivery. */
2324
+ hasApiKey() {
2325
+ try {
2326
+ const apiKey = this.resolveApiKey();
2327
+ return apiKey !== void 0 && apiKey.trim() !== "";
2328
+ } catch {
2329
+ return false;
2330
+ }
2331
+ }
2323
2332
  /**
2324
2333
  * This client's span transport, built on first use.
2325
2334
  *
@@ -4504,6 +4513,7 @@ var BitfabClaudeAgentHandler = class {
4504
4513
  });
4505
4514
  this.traceFunctionKey = config.traceFunctionKey;
4506
4515
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
4516
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
4507
4517
  this.preToolUseHook = this.preToolUseHook.bind(this);
4508
4518
  this.postToolUseHook = this.postToolUseHook.bind(this);
4509
4519
  this.postToolUseFailureHook = this.postToolUseFailureHook.bind(this);
@@ -4608,6 +4618,9 @@ var BitfabClaudeAgentHandler = class {
4608
4618
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
4609
4619
  }
4610
4620
  sendSpan(spanInfo) {
4621
+ if (!this.shouldRecord()) {
4622
+ return;
4623
+ }
4611
4624
  const spanData = {
4612
4625
  name: spanInfo.name,
4613
4626
  type: spanInfo.type
@@ -4651,6 +4664,9 @@ var BitfabClaudeAgentHandler = class {
4651
4664
  }
4652
4665
  }
4653
4666
  sendTraceCompletion(endedAt, metadata) {
4667
+ if (!this.shouldRecord()) {
4668
+ return;
4669
+ }
4654
4670
  if (this.traceId === null) {
4655
4671
  return;
4656
4672
  }
@@ -6192,6 +6208,7 @@ var BitfabLangGraphCallbackHandler = class {
6192
6208
  });
6193
6209
  this.traceFunctionKey = config.traceFunctionKey;
6194
6210
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
6211
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
6195
6212
  this.captureTools = config.captureTools ?? true;
6196
6213
  }
6197
6214
  /**
@@ -6300,6 +6317,9 @@ var BitfabLangGraphCallbackHandler = class {
6300
6317
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
6301
6318
  }
6302
6319
  sendSpan(spanInfo) {
6320
+ if (!this.shouldRecord()) {
6321
+ return;
6322
+ }
6303
6323
  const spanData = {
6304
6324
  name: spanInfo.name,
6305
6325
  type: spanInfo.type
@@ -6343,6 +6363,9 @@ var BitfabLangGraphCallbackHandler = class {
6343
6363
  }
6344
6364
  }
6345
6365
  sendTraceCompletion(rootSpan, activeContext) {
6366
+ if (!this.shouldRecord()) {
6367
+ return;
6368
+ }
6346
6369
  const completed = activeContext === null;
6347
6370
  const traceData = {
6348
6371
  id: rootSpan.traceId,
@@ -6363,6 +6386,9 @@ var BitfabLangGraphCallbackHandler = class {
6363
6386
  }
6364
6387
  }
6365
6388
  sendTraceStart(rootSpan) {
6389
+ if (!this.shouldRecord()) {
6390
+ return;
6391
+ }
6366
6392
  const traceData = {
6367
6393
  id: rootSpan.traceId,
6368
6394
  type: "sdk-function",
@@ -7071,6 +7097,7 @@ var BitfabOpenAITracingProcessor = class {
7071
7097
  timeout: config.timeout ?? 1e4
7072
7098
  });
7073
7099
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
7100
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
7074
7101
  }
7075
7102
  getCanonicalTraceId(sourceTraceId) {
7076
7103
  const existing = this.canonicalTraceIds[sourceTraceId];
@@ -7191,6 +7218,9 @@ var BitfabOpenAITracingProcessor = class {
7191
7218
  * the OpenAI trace into an outer withSpan trace.
7192
7219
  */
7193
7220
  sendTrace(trace, options = {}) {
7221
+ if (!this.shouldRecord()) {
7222
+ return;
7223
+ }
7194
7224
  try {
7195
7225
  const traceData = trace.toJSON();
7196
7226
  if (options.sourceTraceId) {
@@ -7305,6 +7335,9 @@ var BitfabOpenAITracingProcessor = class {
7305
7335
  * and parent_id are rewritten to link the span into the withSpan tree.
7306
7336
  */
7307
7337
  sendSpan(span) {
7338
+ if (!this.shouldRecord()) {
7339
+ return;
7340
+ }
7308
7341
  const errors = [];
7309
7342
  const [serializedSpan, exportErrors] = this.exportSpan(span);
7310
7343
  errors.push(...exportErrors);
@@ -7874,6 +7907,30 @@ function readEnv2(name) {
7874
7907
  }
7875
7908
  return void 0;
7876
7909
  }
7910
+ var CAPTURE_ENABLED_ENV = "BITFAB_CAPTURE_ENABLED";
7911
+ var TRUE_ENV_VALUES = /* @__PURE__ */ new Set(["1", "true", "yes"]);
7912
+ var FALSE_ENV_VALUES = /* @__PURE__ */ new Set(["0", "false", "no"]);
7913
+ function readBooleanEnv(name) {
7914
+ const raw = readEnv2(name);
7915
+ if (raw === void 0) {
7916
+ return void 0;
7917
+ }
7918
+ const value = raw.trim().toLowerCase();
7919
+ if (value === "") {
7920
+ return void 0;
7921
+ }
7922
+ if (TRUE_ENV_VALUES.has(value)) {
7923
+ return true;
7924
+ }
7925
+ if (FALSE_ENV_VALUES.has(value)) {
7926
+ return false;
7927
+ }
7928
+ warnOnce(
7929
+ `unrecognized-boolean-env:${name}`,
7930
+ `${name}="${raw}" is not 0 or 1; ignoring it.`
7931
+ );
7932
+ return void 0;
7933
+ }
7877
7934
  var DEFAULT_AUTO_TRACE_MAX_DEPTH = 30;
7878
7935
  var DEFAULT_AUTO_TRACE_MAX_SPANS = 500;
7879
7936
  var AUTO_TRACE_PROTOCOL = "ts-auto-v1";
@@ -7928,7 +7985,7 @@ var Bitfab = class {
7928
7985
  "Bitfab({ enabled }) is deprecated; pass captureEnabled instead."
7929
7986
  );
7930
7987
  }
7931
- this.captureConfigured = (config.captureEnabled ?? true) && (config.enabled ?? true);
7988
+ this.captureConfiguredInCode = config.captureEnabled === void 0 && config.enabled === void 0 ? void 0 : (config.captureEnabled ?? true) && (config.enabled ?? true);
7932
7989
  this.strict = config.strict ?? false;
7933
7990
  this.bamlClient = config.bamlClient ?? null;
7934
7991
  if (config.dbSnapshot) {
@@ -8382,7 +8439,7 @@ var Bitfab = class {
8382
8439
  "Bitfab: no API key resolved. Set BITFAB_API_KEY or pass apiKey to new Bitfab(). If a script loads env with dotenv, load it before the module that constructs the client is imported (e.g. `node --env-file=.env script.ts`), or pass `apiKey: () => process.env.BITFAB_API_KEY`."
8383
8440
  );
8384
8441
  }
8385
- if (this.captureConfigured && !this.apiKeyWarned) {
8442
+ if (this.isCaptureConfigured() && !this.apiKeyWarned) {
8386
8443
  this.apiKeyWarned = true;
8387
8444
  console.warn(
8388
8445
  "Bitfab: apiKey is empty - tracing is disabled. Provide a valid API key to enable tracing."
@@ -8390,18 +8447,32 @@ var Bitfab = class {
8390
8447
  }
8391
8448
  return void 0;
8392
8449
  }
8450
+ isCaptureConfigured() {
8451
+ if (this.captureConfiguredInCode !== void 0) {
8452
+ return this.captureConfiguredInCode;
8453
+ }
8454
+ if (this.captureConfiguredFromEnv === void 0) {
8455
+ this.captureConfiguredFromEnv = readBooleanEnv(CAPTURE_ENABLED_ENV) ?? true;
8456
+ }
8457
+ return this.captureConfiguredFromEnv;
8458
+ }
8393
8459
  isCaptureEnabled() {
8394
- if (!this.captureConfigured) {
8460
+ if (!this.isCaptureConfigured()) {
8395
8461
  return false;
8396
8462
  }
8397
8463
  return this.resolveApiKey() !== void 0;
8398
8464
  }
8399
8465
  shouldRecord() {
8400
- if (!this.captureConfigured && !getReplayContext() && !inSeedScope()) {
8466
+ if (!this.isCaptureConfigured() && !getReplayContext() && !inSeedScope()) {
8401
8467
  return false;
8402
8468
  }
8403
8469
  return this.resolveApiKey() !== void 0;
8404
8470
  }
8471
+ prepareFrameworkIntegration() {
8472
+ if (this.isCaptureConfigured() && this.strict) {
8473
+ this.resolveApiKey();
8474
+ }
8475
+ }
8405
8476
  get captureEnabled() {
8406
8477
  return this.isCaptureEnabled();
8407
8478
  }
@@ -8459,14 +8530,16 @@ var Bitfab = class {
8459
8530
  resultStr = String(executionResult.result);
8460
8531
  }
8461
8532
  }
8462
- this.httpClient.sendInternalTrace(functionVersion.id, {
8463
- result: resultStr,
8464
- source: "typescript-sdk",
8465
- ...Object.keys(inputs).length > 0 && { inputs },
8466
- ...executionResult.rawCollector != null && {
8467
- rawCollector: executionResult.rawCollector
8468
- }
8469
- });
8533
+ if (this.shouldRecord()) {
8534
+ this.httpClient.sendInternalTrace(functionVersion.id, {
8535
+ result: resultStr,
8536
+ source: "typescript-sdk",
8537
+ ...Object.keys(inputs).length > 0 && { inputs },
8538
+ ...executionResult.rawCollector != null && {
8539
+ rawCollector: executionResult.rawCollector
8540
+ }
8541
+ });
8542
+ }
8470
8543
  return executionResult.result;
8471
8544
  } catch (error) {
8472
8545
  if (error instanceof BitfabError) {
@@ -8496,11 +8569,10 @@ var Bitfab = class {
8496
8569
  * @returns A BitfabOpenAITracingProcessor instance configured for this client
8497
8570
  */
8498
8571
  getOpenAiTracingProcessor() {
8572
+ this.prepareFrameworkIntegration();
8499
8573
  return new BitfabOpenAITracingProcessor({
8500
- // Resolved at getter-call time (framework handlers are set up after env
8501
- // loads); the withSpan path stays lazy via the constructor HttpClient thunk.
8502
- apiKey: this.resolveApiKey(),
8503
8574
  serviceUrl: this.serviceUrl,
8575
+ shouldRecord: () => this.shouldRecord(),
8504
8576
  getActiveSpanContext: () => {
8505
8577
  const stack = getSpanStack();
8506
8578
  return stack[stack.length - 1] ?? null;
@@ -8558,10 +8630,11 @@ var Bitfab = class {
8558
8630
  * @returns A BitfabLangGraphCallbackHandler configured for this client
8559
8631
  */
8560
8632
  getLangGraphCallbackHandler(traceFunctionKey) {
8633
+ this.prepareFrameworkIntegration();
8561
8634
  return new BitfabLangGraphCallbackHandler({
8562
- apiKey: this.resolveApiKey(),
8563
8635
  traceFunctionKey,
8564
8636
  serviceUrl: this.serviceUrl,
8637
+ shouldRecord: () => this.shouldRecord(),
8565
8638
  getActiveSpanContext: () => {
8566
8639
  const stack = getSpanStack();
8567
8640
  return stack[stack.length - 1] ?? null;
@@ -8600,10 +8673,11 @@ var Bitfab = class {
8600
8673
  * @experimental This API may change before it is stable.
8601
8674
  */
8602
8675
  getLangGraphIntegration(traceFunctionKey, options) {
8676
+ this.prepareFrameworkIntegration();
8603
8677
  const callbackHandler = new BitfabLangGraphCallbackHandler({
8604
- apiKey: this.resolveApiKey(),
8605
8678
  traceFunctionKey,
8606
8679
  serviceUrl: this.serviceUrl,
8680
+ shouldRecord: () => this.shouldRecord(),
8607
8681
  getActiveSpanContext: () => {
8608
8682
  const stack = getSpanStack();
8609
8683
  return stack[stack.length - 1] ?? null;
@@ -8642,10 +8716,11 @@ var Bitfab = class {
8642
8716
  * @returns A BitfabClaudeAgentHandler configured for this client
8643
8717
  */
8644
8718
  getClaudeAgentHandler(traceFunctionKey) {
8719
+ this.prepareFrameworkIntegration();
8645
8720
  return new BitfabClaudeAgentHandler({
8646
- apiKey: this.resolveApiKey(),
8647
8721
  traceFunctionKey,
8648
8722
  serviceUrl: this.serviceUrl,
8723
+ shouldRecord: () => this.shouldRecord(),
8649
8724
  getActiveSpanContext: () => {
8650
8725
  const stack = getSpanStack();
8651
8726
  return stack[stack.length - 1] ?? null;