@bitfab/sdk 0.54.6 → 0.54.7

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
@@ -2878,6 +2886,7 @@ declare class Bitfab {
2878
2886
  private resolveApiKey;
2879
2887
  private isCaptureEnabled;
2880
2888
  private shouldRecord;
2889
+ private prepareFrameworkIntegration;
2881
2890
  get captureEnabled(): boolean;
2882
2891
  /**
2883
2892
  * Fetch the function with its current version and BAML prompt from the server.
@@ -3420,7 +3429,7 @@ interface CommitRef {
3420
3429
  /**
3421
3430
  * SDK version from package.json (injected at build time)
3422
3431
  */
3423
- declare const __version__ = "0.54.6";
3432
+ declare const __version__ = "0.54.7";
3424
3433
 
3425
3434
  /**
3426
3435
  * 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
@@ -2878,6 +2886,7 @@ declare class Bitfab {
2878
2886
  private resolveApiKey;
2879
2887
  private isCaptureEnabled;
2880
2888
  private shouldRecord;
2889
+ private prepareFrameworkIntegration;
2881
2890
  get captureEnabled(): boolean;
2882
2891
  /**
2883
2892
  * Fetch the function with its current version and BAML prompt from the server.
@@ -3420,7 +3429,7 @@ interface CommitRef {
3420
3429
  /**
3421
3430
  * SDK version from package.json (injected at build time)
3422
3431
  */
3423
- declare const __version__ = "0.54.6";
3432
+ declare const __version__ = "0.54.7";
3424
3433
 
3425
3434
  /**
3426
3435
  * 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-X6AIRJJX.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-27WMHYUI.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-JF56DBPP.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.7";
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);
@@ -8402,6 +8435,11 @@ var Bitfab = class {
8402
8435
  }
8403
8436
  return this.resolveApiKey() !== void 0;
8404
8437
  }
8438
+ prepareFrameworkIntegration() {
8439
+ if (this.captureConfigured && this.strict) {
8440
+ this.resolveApiKey();
8441
+ }
8442
+ }
8405
8443
  get captureEnabled() {
8406
8444
  return this.isCaptureEnabled();
8407
8445
  }
@@ -8459,14 +8497,16 @@ var Bitfab = class {
8459
8497
  resultStr = String(executionResult.result);
8460
8498
  }
8461
8499
  }
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
- });
8500
+ if (this.shouldRecord()) {
8501
+ this.httpClient.sendInternalTrace(functionVersion.id, {
8502
+ result: resultStr,
8503
+ source: "typescript-sdk",
8504
+ ...Object.keys(inputs).length > 0 && { inputs },
8505
+ ...executionResult.rawCollector != null && {
8506
+ rawCollector: executionResult.rawCollector
8507
+ }
8508
+ });
8509
+ }
8470
8510
  return executionResult.result;
8471
8511
  } catch (error) {
8472
8512
  if (error instanceof BitfabError) {
@@ -8496,11 +8536,10 @@ var Bitfab = class {
8496
8536
  * @returns A BitfabOpenAITracingProcessor instance configured for this client
8497
8537
  */
8498
8538
  getOpenAiTracingProcessor() {
8539
+ this.prepareFrameworkIntegration();
8499
8540
  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
8541
  serviceUrl: this.serviceUrl,
8542
+ shouldRecord: () => this.shouldRecord(),
8504
8543
  getActiveSpanContext: () => {
8505
8544
  const stack = getSpanStack();
8506
8545
  return stack[stack.length - 1] ?? null;
@@ -8558,10 +8597,11 @@ var Bitfab = class {
8558
8597
  * @returns A BitfabLangGraphCallbackHandler configured for this client
8559
8598
  */
8560
8599
  getLangGraphCallbackHandler(traceFunctionKey) {
8600
+ this.prepareFrameworkIntegration();
8561
8601
  return new BitfabLangGraphCallbackHandler({
8562
- apiKey: this.resolveApiKey(),
8563
8602
  traceFunctionKey,
8564
8603
  serviceUrl: this.serviceUrl,
8604
+ shouldRecord: () => this.shouldRecord(),
8565
8605
  getActiveSpanContext: () => {
8566
8606
  const stack = getSpanStack();
8567
8607
  return stack[stack.length - 1] ?? null;
@@ -8600,10 +8640,11 @@ var Bitfab = class {
8600
8640
  * @experimental This API may change before it is stable.
8601
8641
  */
8602
8642
  getLangGraphIntegration(traceFunctionKey, options) {
8643
+ this.prepareFrameworkIntegration();
8603
8644
  const callbackHandler = new BitfabLangGraphCallbackHandler({
8604
- apiKey: this.resolveApiKey(),
8605
8645
  traceFunctionKey,
8606
8646
  serviceUrl: this.serviceUrl,
8647
+ shouldRecord: () => this.shouldRecord(),
8607
8648
  getActiveSpanContext: () => {
8608
8649
  const stack = getSpanStack();
8609
8650
  return stack[stack.length - 1] ?? null;
@@ -8642,10 +8683,11 @@ var Bitfab = class {
8642
8683
  * @returns A BitfabClaudeAgentHandler configured for this client
8643
8684
  */
8644
8685
  getClaudeAgentHandler(traceFunctionKey) {
8686
+ this.prepareFrameworkIntegration();
8645
8687
  return new BitfabClaudeAgentHandler({
8646
- apiKey: this.resolveApiKey(),
8647
8688
  traceFunctionKey,
8648
8689
  serviceUrl: this.serviceUrl,
8690
+ shouldRecord: () => this.shouldRecord(),
8649
8691
  getActiveSpanContext: () => {
8650
8692
  const stack = getSpanStack();
8651
8693
  return stack[stack.length - 1] ?? null;