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.
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-5FRFNRFA.js";
9
+ } from "./chunk-GGMFD2ZE.js";
10
10
  import "./chunk-VCRFFCLY.js";
11
11
  export {
12
12
  BitfabError,
@@ -17,4 +17,4 @@ export {
17
17
  parseRetryAfterMs,
18
18
  serializePayloadBody
19
19
  };
20
- //# sourceMappingURL=http-EMAHQQ4A.js.map
20
+ //# sourceMappingURL=http-DYGY3K7H.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-IKNIY7JV.js";
9
+ } from "./chunk-VDQAIWLX.js";
10
10
  export {
11
11
  BitfabError,
12
12
  HttpClient,
@@ -16,4 +16,4 @@ export {
16
16
  parseRetryAfterMs,
17
17
  serializePayloadBody
18
18
  };
19
- //# sourceMappingURL=http-DRPXLTJS.js.map
19
+ //# sourceMappingURL=http-NIVPIUA2.js.map
package/dist/index.cjs CHANGED
@@ -51,7 +51,7 @@ var __version__, __packageName__;
51
51
  var init_version_generated = __esm({
52
52
  "src/version.generated.ts"() {
53
53
  "use strict";
54
- __version__ = "0.54.6";
54
+ __version__ = "0.54.7";
55
55
  __packageName__ = "bitfab";
56
56
  }
57
57
  });
@@ -2322,6 +2322,15 @@ var init_http = __esm({
2322
2322
  resolveApiKey() {
2323
2323
  return typeof this.apiKey === "function" ? this.apiKey() : this.apiKey;
2324
2324
  }
2325
+ /** @internal Whether this client currently has credentials for trace delivery. */
2326
+ hasApiKey() {
2327
+ try {
2328
+ const apiKey = this.resolveApiKey();
2329
+ return apiKey !== void 0 && apiKey.trim() !== "";
2330
+ } catch {
2331
+ return false;
2332
+ }
2333
+ }
2325
2334
  /**
2326
2335
  * This client's span transport, built on first use.
2327
2336
  *
@@ -4499,6 +4508,7 @@ var BitfabClaudeAgentHandler = class {
4499
4508
  });
4500
4509
  this.traceFunctionKey = config.traceFunctionKey;
4501
4510
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
4511
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
4502
4512
  this.preToolUseHook = this.preToolUseHook.bind(this);
4503
4513
  this.postToolUseHook = this.postToolUseHook.bind(this);
4504
4514
  this.postToolUseFailureHook = this.postToolUseFailureHook.bind(this);
@@ -4603,6 +4613,9 @@ var BitfabClaudeAgentHandler = class {
4603
4613
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
4604
4614
  }
4605
4615
  sendSpan(spanInfo) {
4616
+ if (!this.shouldRecord()) {
4617
+ return;
4618
+ }
4606
4619
  const spanData = {
4607
4620
  name: spanInfo.name,
4608
4621
  type: spanInfo.type
@@ -4646,6 +4659,9 @@ var BitfabClaudeAgentHandler = class {
4646
4659
  }
4647
4660
  }
4648
4661
  sendTraceCompletion(endedAt, metadata) {
4662
+ if (!this.shouldRecord()) {
4663
+ return;
4664
+ }
4649
4665
  if (this.traceId === null) {
4650
4666
  return;
4651
4667
  }
@@ -6187,6 +6203,7 @@ var BitfabLangGraphCallbackHandler = class {
6187
6203
  });
6188
6204
  this.traceFunctionKey = config.traceFunctionKey;
6189
6205
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
6206
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
6190
6207
  this.captureTools = config.captureTools ?? true;
6191
6208
  }
6192
6209
  /**
@@ -6295,6 +6312,9 @@ var BitfabLangGraphCallbackHandler = class {
6295
6312
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
6296
6313
  }
6297
6314
  sendSpan(spanInfo) {
6315
+ if (!this.shouldRecord()) {
6316
+ return;
6317
+ }
6298
6318
  const spanData = {
6299
6319
  name: spanInfo.name,
6300
6320
  type: spanInfo.type
@@ -6338,6 +6358,9 @@ var BitfabLangGraphCallbackHandler = class {
6338
6358
  }
6339
6359
  }
6340
6360
  sendTraceCompletion(rootSpan, activeContext) {
6361
+ if (!this.shouldRecord()) {
6362
+ return;
6363
+ }
6341
6364
  const completed = activeContext === null;
6342
6365
  const traceData = {
6343
6366
  id: rootSpan.traceId,
@@ -6358,6 +6381,9 @@ var BitfabLangGraphCallbackHandler = class {
6358
6381
  }
6359
6382
  }
6360
6383
  sendTraceStart(rootSpan) {
6384
+ if (!this.shouldRecord()) {
6385
+ return;
6386
+ }
6361
6387
  const traceData = {
6362
6388
  id: rootSpan.traceId,
6363
6389
  type: "sdk-function",
@@ -7066,6 +7092,7 @@ var BitfabOpenAITracingProcessor = class {
7066
7092
  timeout: config.timeout ?? 1e4
7067
7093
  });
7068
7094
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
7095
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
7069
7096
  }
7070
7097
  getCanonicalTraceId(sourceTraceId) {
7071
7098
  const existing = this.canonicalTraceIds[sourceTraceId];
@@ -7186,6 +7213,9 @@ var BitfabOpenAITracingProcessor = class {
7186
7213
  * the OpenAI trace into an outer withSpan trace.
7187
7214
  */
7188
7215
  sendTrace(trace, options = {}) {
7216
+ if (!this.shouldRecord()) {
7217
+ return;
7218
+ }
7189
7219
  try {
7190
7220
  const traceData = trace.toJSON();
7191
7221
  if (options.sourceTraceId) {
@@ -7300,6 +7330,9 @@ var BitfabOpenAITracingProcessor = class {
7300
7330
  * and parent_id are rewritten to link the span into the withSpan tree.
7301
7331
  */
7302
7332
  sendSpan(span) {
7333
+ if (!this.shouldRecord()) {
7334
+ return;
7335
+ }
7303
7336
  const errors = [];
7304
7337
  const [serializedSpan, exportErrors] = this.exportSpan(span);
7305
7338
  errors.push(...exportErrors);
@@ -8397,6 +8430,11 @@ var Bitfab = class {
8397
8430
  }
8398
8431
  return this.resolveApiKey() !== void 0;
8399
8432
  }
8433
+ prepareFrameworkIntegration() {
8434
+ if (this.captureConfigured && this.strict) {
8435
+ this.resolveApiKey();
8436
+ }
8437
+ }
8400
8438
  get captureEnabled() {
8401
8439
  return this.isCaptureEnabled();
8402
8440
  }
@@ -8454,14 +8492,16 @@ var Bitfab = class {
8454
8492
  resultStr = String(executionResult.result);
8455
8493
  }
8456
8494
  }
8457
- this.httpClient.sendInternalTrace(functionVersion.id, {
8458
- result: resultStr,
8459
- source: "typescript-sdk",
8460
- ...Object.keys(inputs).length > 0 && { inputs },
8461
- ...executionResult.rawCollector != null && {
8462
- rawCollector: executionResult.rawCollector
8463
- }
8464
- });
8495
+ if (this.shouldRecord()) {
8496
+ this.httpClient.sendInternalTrace(functionVersion.id, {
8497
+ result: resultStr,
8498
+ source: "typescript-sdk",
8499
+ ...Object.keys(inputs).length > 0 && { inputs },
8500
+ ...executionResult.rawCollector != null && {
8501
+ rawCollector: executionResult.rawCollector
8502
+ }
8503
+ });
8504
+ }
8465
8505
  return executionResult.result;
8466
8506
  } catch (error) {
8467
8507
  if (error instanceof BitfabError) {
@@ -8491,11 +8531,10 @@ var Bitfab = class {
8491
8531
  * @returns A BitfabOpenAITracingProcessor instance configured for this client
8492
8532
  */
8493
8533
  getOpenAiTracingProcessor() {
8534
+ this.prepareFrameworkIntegration();
8494
8535
  return new BitfabOpenAITracingProcessor({
8495
- // Resolved at getter-call time (framework handlers are set up after env
8496
- // loads); the withSpan path stays lazy via the constructor HttpClient thunk.
8497
- apiKey: this.resolveApiKey(),
8498
8536
  serviceUrl: this.serviceUrl,
8537
+ shouldRecord: () => this.shouldRecord(),
8499
8538
  getActiveSpanContext: () => {
8500
8539
  const stack = getSpanStack();
8501
8540
  return stack[stack.length - 1] ?? null;
@@ -8553,10 +8592,11 @@ var Bitfab = class {
8553
8592
  * @returns A BitfabLangGraphCallbackHandler configured for this client
8554
8593
  */
8555
8594
  getLangGraphCallbackHandler(traceFunctionKey) {
8595
+ this.prepareFrameworkIntegration();
8556
8596
  return new BitfabLangGraphCallbackHandler({
8557
- apiKey: this.resolveApiKey(),
8558
8597
  traceFunctionKey,
8559
8598
  serviceUrl: this.serviceUrl,
8599
+ shouldRecord: () => this.shouldRecord(),
8560
8600
  getActiveSpanContext: () => {
8561
8601
  const stack = getSpanStack();
8562
8602
  return stack[stack.length - 1] ?? null;
@@ -8595,10 +8635,11 @@ var Bitfab = class {
8595
8635
  * @experimental This API may change before it is stable.
8596
8636
  */
8597
8637
  getLangGraphIntegration(traceFunctionKey, options) {
8638
+ this.prepareFrameworkIntegration();
8598
8639
  const callbackHandler = new BitfabLangGraphCallbackHandler({
8599
- apiKey: this.resolveApiKey(),
8600
8640
  traceFunctionKey,
8601
8641
  serviceUrl: this.serviceUrl,
8642
+ shouldRecord: () => this.shouldRecord(),
8602
8643
  getActiveSpanContext: () => {
8603
8644
  const stack = getSpanStack();
8604
8645
  return stack[stack.length - 1] ?? null;
@@ -8637,10 +8678,11 @@ var Bitfab = class {
8637
8678
  * @returns A BitfabClaudeAgentHandler configured for this client
8638
8679
  */
8639
8680
  getClaudeAgentHandler(traceFunctionKey) {
8681
+ this.prepareFrameworkIntegration();
8640
8682
  return new BitfabClaudeAgentHandler({
8641
- apiKey: this.resolveApiKey(),
8642
8683
  traceFunctionKey,
8643
8684
  serviceUrl: this.serviceUrl,
8685
+ shouldRecord: () => this.shouldRecord(),
8644
8686
  getActiveSpanContext: () => {
8645
8687
  const stack = getSpanStack();
8646
8688
  return stack[stack.length - 1] ?? null;