bitfab 0.54.5 → 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-GVK7AES5.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-RW2JO6TU.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-RA3J6A6K.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-K2H4547F.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.5";
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",
@@ -7009,12 +7035,6 @@ var TracesClient = class {
7009
7035
  constructor(httpClient) {
7010
7036
  this.httpClient = httpClient;
7011
7037
  }
7012
- /**
7013
- * Search traces by exact caller metadata.
7014
- *
7015
- * Keys and values are matched case-insensitively. Up to 10 supplied pairs
7016
- * must match. Use `nextCursor` from the result to fetch another page.
7017
- */
7018
7038
  async search(params) {
7019
7039
  return this.httpClient.request(SEARCH_PATH, params);
7020
7040
  }
@@ -7072,6 +7092,7 @@ var BitfabOpenAITracingProcessor = class {
7072
7092
  timeout: config.timeout ?? 1e4
7073
7093
  });
7074
7094
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
7095
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
7075
7096
  }
7076
7097
  getCanonicalTraceId(sourceTraceId) {
7077
7098
  const existing = this.canonicalTraceIds[sourceTraceId];
@@ -7192,6 +7213,9 @@ var BitfabOpenAITracingProcessor = class {
7192
7213
  * the OpenAI trace into an outer withSpan trace.
7193
7214
  */
7194
7215
  sendTrace(trace, options = {}) {
7216
+ if (!this.shouldRecord()) {
7217
+ return;
7218
+ }
7195
7219
  try {
7196
7220
  const traceData = trace.toJSON();
7197
7221
  if (options.sourceTraceId) {
@@ -7306,6 +7330,9 @@ var BitfabOpenAITracingProcessor = class {
7306
7330
  * and parent_id are rewritten to link the span into the withSpan tree.
7307
7331
  */
7308
7332
  sendSpan(span) {
7333
+ if (!this.shouldRecord()) {
7334
+ return;
7335
+ }
7309
7336
  const errors = [];
7310
7337
  const [serializedSpan, exportErrors] = this.exportSpan(span);
7311
7338
  errors.push(...exportErrors);
@@ -8403,6 +8430,11 @@ var Bitfab = class {
8403
8430
  }
8404
8431
  return this.resolveApiKey() !== void 0;
8405
8432
  }
8433
+ prepareFrameworkIntegration() {
8434
+ if (this.captureConfigured && this.strict) {
8435
+ this.resolveApiKey();
8436
+ }
8437
+ }
8406
8438
  get captureEnabled() {
8407
8439
  return this.isCaptureEnabled();
8408
8440
  }
@@ -8460,14 +8492,16 @@ var Bitfab = class {
8460
8492
  resultStr = String(executionResult.result);
8461
8493
  }
8462
8494
  }
8463
- this.httpClient.sendInternalTrace(functionVersion.id, {
8464
- result: resultStr,
8465
- source: "typescript-sdk",
8466
- ...Object.keys(inputs).length > 0 && { inputs },
8467
- ...executionResult.rawCollector != null && {
8468
- rawCollector: executionResult.rawCollector
8469
- }
8470
- });
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
+ }
8471
8505
  return executionResult.result;
8472
8506
  } catch (error) {
8473
8507
  if (error instanceof BitfabError) {
@@ -8497,11 +8531,10 @@ var Bitfab = class {
8497
8531
  * @returns A BitfabOpenAITracingProcessor instance configured for this client
8498
8532
  */
8499
8533
  getOpenAiTracingProcessor() {
8534
+ this.prepareFrameworkIntegration();
8500
8535
  return new BitfabOpenAITracingProcessor({
8501
- // Resolved at getter-call time (framework handlers are set up after env
8502
- // loads); the withSpan path stays lazy via the constructor HttpClient thunk.
8503
- apiKey: this.resolveApiKey(),
8504
8536
  serviceUrl: this.serviceUrl,
8537
+ shouldRecord: () => this.shouldRecord(),
8505
8538
  getActiveSpanContext: () => {
8506
8539
  const stack = getSpanStack();
8507
8540
  return stack[stack.length - 1] ?? null;
@@ -8559,10 +8592,11 @@ var Bitfab = class {
8559
8592
  * @returns A BitfabLangGraphCallbackHandler configured for this client
8560
8593
  */
8561
8594
  getLangGraphCallbackHandler(traceFunctionKey) {
8595
+ this.prepareFrameworkIntegration();
8562
8596
  return new BitfabLangGraphCallbackHandler({
8563
- apiKey: this.resolveApiKey(),
8564
8597
  traceFunctionKey,
8565
8598
  serviceUrl: this.serviceUrl,
8599
+ shouldRecord: () => this.shouldRecord(),
8566
8600
  getActiveSpanContext: () => {
8567
8601
  const stack = getSpanStack();
8568
8602
  return stack[stack.length - 1] ?? null;
@@ -8601,10 +8635,11 @@ var Bitfab = class {
8601
8635
  * @experimental This API may change before it is stable.
8602
8636
  */
8603
8637
  getLangGraphIntegration(traceFunctionKey, options) {
8638
+ this.prepareFrameworkIntegration();
8604
8639
  const callbackHandler = new BitfabLangGraphCallbackHandler({
8605
- apiKey: this.resolveApiKey(),
8606
8640
  traceFunctionKey,
8607
8641
  serviceUrl: this.serviceUrl,
8642
+ shouldRecord: () => this.shouldRecord(),
8608
8643
  getActiveSpanContext: () => {
8609
8644
  const stack = getSpanStack();
8610
8645
  return stack[stack.length - 1] ?? null;
@@ -8643,10 +8678,11 @@ var Bitfab = class {
8643
8678
  * @returns A BitfabClaudeAgentHandler configured for this client
8644
8679
  */
8645
8680
  getClaudeAgentHandler(traceFunctionKey) {
8681
+ this.prepareFrameworkIntegration();
8646
8682
  return new BitfabClaudeAgentHandler({
8647
- apiKey: this.resolveApiKey(),
8648
8683
  traceFunctionKey,
8649
8684
  serviceUrl: this.serviceUrl,
8685
+ shouldRecord: () => this.shouldRecord(),
8650
8686
  getActiveSpanContext: () => {
8651
8687
  const stack = getSpanStack();
8652
8688
  return stack[stack.length - 1] ?? null;