bitfab 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
@@ -29,7 +29,7 @@ import {
29
29
  getCurrentTrace,
30
30
  reseedFromRegistry,
31
31
  seedFromRegistry
32
- } from "./chunk-FCJHKGEE.js";
32
+ } from "./chunk-MFMTLYDW.js";
33
33
  import "./chunk-EGWJYCNT.js";
34
34
  import {
35
35
  BITFAB_PROGRESS_PREFIX,
@@ -38,7 +38,7 @@ import {
38
38
  ReplayError,
39
39
  reportReplayProgress,
40
40
  serializeReplayResult
41
- } from "./chunk-EBDVWYCV.js";
41
+ } from "./chunk-ONMN7WXS.js";
42
42
  import {
43
43
  BitfabError,
44
44
  DEFAULT_SERVICE_URL,
@@ -46,7 +46,7 @@ import {
46
46
  MixedTracingError,
47
47
  __version__,
48
48
  flushTraces
49
- } from "./chunk-5FRFNRFA.js";
49
+ } from "./chunk-GGMFD2ZE.js";
50
50
  import "./chunk-VCRFFCLY.js";
51
51
  export {
52
52
  AssertionCategoriesClient,
package/dist/node.cjs CHANGED
@@ -97,7 +97,7 @@ var __version__, __packageName__;
97
97
  var init_version_generated = __esm({
98
98
  "src/version.generated.ts"() {
99
99
  "use strict";
100
- __version__ = "0.54.6";
100
+ __version__ = "0.54.7";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -2329,6 +2329,15 @@ var init_http = __esm({
2329
2329
  resolveApiKey() {
2330
2330
  return typeof this.apiKey === "function" ? this.apiKey() : this.apiKey;
2331
2331
  }
2332
+ /** @internal Whether this client currently has credentials for trace delivery. */
2333
+ hasApiKey() {
2334
+ try {
2335
+ const apiKey = this.resolveApiKey();
2336
+ return apiKey !== void 0 && apiKey.trim() !== "";
2337
+ } catch {
2338
+ return false;
2339
+ }
2340
+ }
2332
2341
  /**
2333
2342
  * This client's span transport, built on first use.
2334
2343
  *
@@ -4513,6 +4522,7 @@ var BitfabClaudeAgentHandler = class {
4513
4522
  });
4514
4523
  this.traceFunctionKey = config.traceFunctionKey;
4515
4524
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
4525
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
4516
4526
  this.preToolUseHook = this.preToolUseHook.bind(this);
4517
4527
  this.postToolUseHook = this.postToolUseHook.bind(this);
4518
4528
  this.postToolUseFailureHook = this.postToolUseFailureHook.bind(this);
@@ -4617,6 +4627,9 @@ var BitfabClaudeAgentHandler = class {
4617
4627
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
4618
4628
  }
4619
4629
  sendSpan(spanInfo) {
4630
+ if (!this.shouldRecord()) {
4631
+ return;
4632
+ }
4620
4633
  const spanData = {
4621
4634
  name: spanInfo.name,
4622
4635
  type: spanInfo.type
@@ -4660,6 +4673,9 @@ var BitfabClaudeAgentHandler = class {
4660
4673
  }
4661
4674
  }
4662
4675
  sendTraceCompletion(endedAt, metadata) {
4676
+ if (!this.shouldRecord()) {
4677
+ return;
4678
+ }
4663
4679
  if (this.traceId === null) {
4664
4680
  return;
4665
4681
  }
@@ -6201,6 +6217,7 @@ var BitfabLangGraphCallbackHandler = class {
6201
6217
  });
6202
6218
  this.traceFunctionKey = config.traceFunctionKey;
6203
6219
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
6220
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
6204
6221
  this.captureTools = config.captureTools ?? true;
6205
6222
  }
6206
6223
  /**
@@ -6309,6 +6326,9 @@ var BitfabLangGraphCallbackHandler = class {
6309
6326
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
6310
6327
  }
6311
6328
  sendSpan(spanInfo) {
6329
+ if (!this.shouldRecord()) {
6330
+ return;
6331
+ }
6312
6332
  const spanData = {
6313
6333
  name: spanInfo.name,
6314
6334
  type: spanInfo.type
@@ -6352,6 +6372,9 @@ var BitfabLangGraphCallbackHandler = class {
6352
6372
  }
6353
6373
  }
6354
6374
  sendTraceCompletion(rootSpan, activeContext) {
6375
+ if (!this.shouldRecord()) {
6376
+ return;
6377
+ }
6355
6378
  const completed = activeContext === null;
6356
6379
  const traceData = {
6357
6380
  id: rootSpan.traceId,
@@ -6372,6 +6395,9 @@ var BitfabLangGraphCallbackHandler = class {
6372
6395
  }
6373
6396
  }
6374
6397
  sendTraceStart(rootSpan) {
6398
+ if (!this.shouldRecord()) {
6399
+ return;
6400
+ }
6375
6401
  const traceData = {
6376
6402
  id: rootSpan.traceId,
6377
6403
  type: "sdk-function",
@@ -7080,6 +7106,7 @@ var BitfabOpenAITracingProcessor = class {
7080
7106
  timeout: config.timeout ?? 1e4
7081
7107
  });
7082
7108
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
7109
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
7083
7110
  }
7084
7111
  getCanonicalTraceId(sourceTraceId) {
7085
7112
  const existing = this.canonicalTraceIds[sourceTraceId];
@@ -7200,6 +7227,9 @@ var BitfabOpenAITracingProcessor = class {
7200
7227
  * the OpenAI trace into an outer withSpan trace.
7201
7228
  */
7202
7229
  sendTrace(trace, options = {}) {
7230
+ if (!this.shouldRecord()) {
7231
+ return;
7232
+ }
7203
7233
  try {
7204
7234
  const traceData = trace.toJSON();
7205
7235
  if (options.sourceTraceId) {
@@ -7314,6 +7344,9 @@ var BitfabOpenAITracingProcessor = class {
7314
7344
  * and parent_id are rewritten to link the span into the withSpan tree.
7315
7345
  */
7316
7346
  sendSpan(span) {
7347
+ if (!this.shouldRecord()) {
7348
+ return;
7349
+ }
7317
7350
  const errors = [];
7318
7351
  const [serializedSpan, exportErrors] = this.exportSpan(span);
7319
7352
  errors.push(...exportErrors);
@@ -8411,6 +8444,11 @@ var Bitfab = class {
8411
8444
  }
8412
8445
  return this.resolveApiKey() !== void 0;
8413
8446
  }
8447
+ prepareFrameworkIntegration() {
8448
+ if (this.captureConfigured && this.strict) {
8449
+ this.resolveApiKey();
8450
+ }
8451
+ }
8414
8452
  get captureEnabled() {
8415
8453
  return this.isCaptureEnabled();
8416
8454
  }
@@ -8468,14 +8506,16 @@ var Bitfab = class {
8468
8506
  resultStr = String(executionResult.result);
8469
8507
  }
8470
8508
  }
8471
- this.httpClient.sendInternalTrace(functionVersion.id, {
8472
- result: resultStr,
8473
- source: "typescript-sdk",
8474
- ...Object.keys(inputs).length > 0 && { inputs },
8475
- ...executionResult.rawCollector != null && {
8476
- rawCollector: executionResult.rawCollector
8477
- }
8478
- });
8509
+ if (this.shouldRecord()) {
8510
+ this.httpClient.sendInternalTrace(functionVersion.id, {
8511
+ result: resultStr,
8512
+ source: "typescript-sdk",
8513
+ ...Object.keys(inputs).length > 0 && { inputs },
8514
+ ...executionResult.rawCollector != null && {
8515
+ rawCollector: executionResult.rawCollector
8516
+ }
8517
+ });
8518
+ }
8479
8519
  return executionResult.result;
8480
8520
  } catch (error) {
8481
8521
  if (error instanceof BitfabError) {
@@ -8505,11 +8545,10 @@ var Bitfab = class {
8505
8545
  * @returns A BitfabOpenAITracingProcessor instance configured for this client
8506
8546
  */
8507
8547
  getOpenAiTracingProcessor() {
8548
+ this.prepareFrameworkIntegration();
8508
8549
  return new BitfabOpenAITracingProcessor({
8509
- // Resolved at getter-call time (framework handlers are set up after env
8510
- // loads); the withSpan path stays lazy via the constructor HttpClient thunk.
8511
- apiKey: this.resolveApiKey(),
8512
8550
  serviceUrl: this.serviceUrl,
8551
+ shouldRecord: () => this.shouldRecord(),
8513
8552
  getActiveSpanContext: () => {
8514
8553
  const stack = getSpanStack();
8515
8554
  return stack[stack.length - 1] ?? null;
@@ -8567,10 +8606,11 @@ var Bitfab = class {
8567
8606
  * @returns A BitfabLangGraphCallbackHandler configured for this client
8568
8607
  */
8569
8608
  getLangGraphCallbackHandler(traceFunctionKey) {
8609
+ this.prepareFrameworkIntegration();
8570
8610
  return new BitfabLangGraphCallbackHandler({
8571
- apiKey: this.resolveApiKey(),
8572
8611
  traceFunctionKey,
8573
8612
  serviceUrl: this.serviceUrl,
8613
+ shouldRecord: () => this.shouldRecord(),
8574
8614
  getActiveSpanContext: () => {
8575
8615
  const stack = getSpanStack();
8576
8616
  return stack[stack.length - 1] ?? null;
@@ -8609,10 +8649,11 @@ var Bitfab = class {
8609
8649
  * @experimental This API may change before it is stable.
8610
8650
  */
8611
8651
  getLangGraphIntegration(traceFunctionKey, options) {
8652
+ this.prepareFrameworkIntegration();
8612
8653
  const callbackHandler = new BitfabLangGraphCallbackHandler({
8613
- apiKey: this.resolveApiKey(),
8614
8654
  traceFunctionKey,
8615
8655
  serviceUrl: this.serviceUrl,
8656
+ shouldRecord: () => this.shouldRecord(),
8616
8657
  getActiveSpanContext: () => {
8617
8658
  const stack = getSpanStack();
8618
8659
  return stack[stack.length - 1] ?? null;
@@ -8651,10 +8692,11 @@ var Bitfab = class {
8651
8692
  * @returns A BitfabClaudeAgentHandler configured for this client
8652
8693
  */
8653
8694
  getClaudeAgentHandler(traceFunctionKey) {
8695
+ this.prepareFrameworkIntegration();
8654
8696
  return new BitfabClaudeAgentHandler({
8655
- apiKey: this.resolveApiKey(),
8656
8697
  traceFunctionKey,
8657
8698
  serviceUrl: this.serviceUrl,
8699
+ shouldRecord: () => this.shouldRecord(),
8658
8700
  getActiveSpanContext: () => {
8659
8701
  const stack = getSpanStack();
8660
8702
  return stack[stack.length - 1] ?? null;