@bitfab/sdk 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-3STIE5QL.js";
9
+ } from "./chunk-OIIMVPTH.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-36EP65LE.js.map
19
+ //# sourceMappingURL=http-I5VDJLSJ.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-PIF5HH3Z.js";
9
+ } from "./chunk-JF56DBPP.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-JQ4RXRWH.js.map
20
+ //# sourceMappingURL=http-RGNLMMZQ.js.map
package/dist/index.cjs CHANGED
@@ -42,7 +42,7 @@ var __version__, __packageName__;
42
42
  var init_version_generated = __esm({
43
43
  "src/version.generated.ts"() {
44
44
  "use strict";
45
- __version__ = "0.54.5";
45
+ __version__ = "0.54.7";
46
46
  __packageName__ = "@bitfab/sdk";
47
47
  }
48
48
  });
@@ -2313,6 +2313,15 @@ var init_http = __esm({
2313
2313
  resolveApiKey() {
2314
2314
  return typeof this.apiKey === "function" ? this.apiKey() : this.apiKey;
2315
2315
  }
2316
+ /** @internal Whether this client currently has credentials for trace delivery. */
2317
+ hasApiKey() {
2318
+ try {
2319
+ const apiKey = this.resolveApiKey();
2320
+ return apiKey !== void 0 && apiKey.trim() !== "";
2321
+ } catch {
2322
+ return false;
2323
+ }
2324
+ }
2316
2325
  /**
2317
2326
  * This client's span transport, built on first use.
2318
2327
  *
@@ -4490,6 +4499,7 @@ var BitfabClaudeAgentHandler = class {
4490
4499
  });
4491
4500
  this.traceFunctionKey = config.traceFunctionKey;
4492
4501
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
4502
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
4493
4503
  this.preToolUseHook = this.preToolUseHook.bind(this);
4494
4504
  this.postToolUseHook = this.postToolUseHook.bind(this);
4495
4505
  this.postToolUseFailureHook = this.postToolUseFailureHook.bind(this);
@@ -4594,6 +4604,9 @@ var BitfabClaudeAgentHandler = class {
4594
4604
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
4595
4605
  }
4596
4606
  sendSpan(spanInfo) {
4607
+ if (!this.shouldRecord()) {
4608
+ return;
4609
+ }
4597
4610
  const spanData = {
4598
4611
  name: spanInfo.name,
4599
4612
  type: spanInfo.type
@@ -4637,6 +4650,9 @@ var BitfabClaudeAgentHandler = class {
4637
4650
  }
4638
4651
  }
4639
4652
  sendTraceCompletion(endedAt, metadata) {
4653
+ if (!this.shouldRecord()) {
4654
+ return;
4655
+ }
4640
4656
  if (this.traceId === null) {
4641
4657
  return;
4642
4658
  }
@@ -6178,6 +6194,7 @@ var BitfabLangGraphCallbackHandler = class {
6178
6194
  });
6179
6195
  this.traceFunctionKey = config.traceFunctionKey;
6180
6196
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
6197
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
6181
6198
  this.captureTools = config.captureTools ?? true;
6182
6199
  }
6183
6200
  /**
@@ -6286,6 +6303,9 @@ var BitfabLangGraphCallbackHandler = class {
6286
6303
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
6287
6304
  }
6288
6305
  sendSpan(spanInfo) {
6306
+ if (!this.shouldRecord()) {
6307
+ return;
6308
+ }
6289
6309
  const spanData = {
6290
6310
  name: spanInfo.name,
6291
6311
  type: spanInfo.type
@@ -6329,6 +6349,9 @@ var BitfabLangGraphCallbackHandler = class {
6329
6349
  }
6330
6350
  }
6331
6351
  sendTraceCompletion(rootSpan, activeContext) {
6352
+ if (!this.shouldRecord()) {
6353
+ return;
6354
+ }
6332
6355
  const completed = activeContext === null;
6333
6356
  const traceData = {
6334
6357
  id: rootSpan.traceId,
@@ -6349,6 +6372,9 @@ var BitfabLangGraphCallbackHandler = class {
6349
6372
  }
6350
6373
  }
6351
6374
  sendTraceStart(rootSpan) {
6375
+ if (!this.shouldRecord()) {
6376
+ return;
6377
+ }
6352
6378
  const traceData = {
6353
6379
  id: rootSpan.traceId,
6354
6380
  type: "sdk-function",
@@ -7000,12 +7026,6 @@ var TracesClient = class {
7000
7026
  constructor(httpClient) {
7001
7027
  this.httpClient = httpClient;
7002
7028
  }
7003
- /**
7004
- * Search traces by exact caller metadata.
7005
- *
7006
- * Keys and values are matched case-insensitively. Up to 10 supplied pairs
7007
- * must match. Use `nextCursor` from the result to fetch another page.
7008
- */
7009
7029
  async search(params) {
7010
7030
  return this.httpClient.request(SEARCH_PATH, params);
7011
7031
  }
@@ -7063,6 +7083,7 @@ var BitfabOpenAITracingProcessor = class {
7063
7083
  timeout: config.timeout ?? 1e4
7064
7084
  });
7065
7085
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
7086
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
7066
7087
  }
7067
7088
  getCanonicalTraceId(sourceTraceId) {
7068
7089
  const existing = this.canonicalTraceIds[sourceTraceId];
@@ -7183,6 +7204,9 @@ var BitfabOpenAITracingProcessor = class {
7183
7204
  * the OpenAI trace into an outer withSpan trace.
7184
7205
  */
7185
7206
  sendTrace(trace, options = {}) {
7207
+ if (!this.shouldRecord()) {
7208
+ return;
7209
+ }
7186
7210
  try {
7187
7211
  const traceData = trace.toJSON();
7188
7212
  if (options.sourceTraceId) {
@@ -7297,6 +7321,9 @@ var BitfabOpenAITracingProcessor = class {
7297
7321
  * and parent_id are rewritten to link the span into the withSpan tree.
7298
7322
  */
7299
7323
  sendSpan(span) {
7324
+ if (!this.shouldRecord()) {
7325
+ return;
7326
+ }
7300
7327
  const errors = [];
7301
7328
  const [serializedSpan, exportErrors] = this.exportSpan(span);
7302
7329
  errors.push(...exportErrors);
@@ -8394,6 +8421,11 @@ var Bitfab = class {
8394
8421
  }
8395
8422
  return this.resolveApiKey() !== void 0;
8396
8423
  }
8424
+ prepareFrameworkIntegration() {
8425
+ if (this.captureConfigured && this.strict) {
8426
+ this.resolveApiKey();
8427
+ }
8428
+ }
8397
8429
  get captureEnabled() {
8398
8430
  return this.isCaptureEnabled();
8399
8431
  }
@@ -8451,14 +8483,16 @@ var Bitfab = class {
8451
8483
  resultStr = String(executionResult.result);
8452
8484
  }
8453
8485
  }
8454
- this.httpClient.sendInternalTrace(functionVersion.id, {
8455
- result: resultStr,
8456
- source: "typescript-sdk",
8457
- ...Object.keys(inputs).length > 0 && { inputs },
8458
- ...executionResult.rawCollector != null && {
8459
- rawCollector: executionResult.rawCollector
8460
- }
8461
- });
8486
+ if (this.shouldRecord()) {
8487
+ this.httpClient.sendInternalTrace(functionVersion.id, {
8488
+ result: resultStr,
8489
+ source: "typescript-sdk",
8490
+ ...Object.keys(inputs).length > 0 && { inputs },
8491
+ ...executionResult.rawCollector != null && {
8492
+ rawCollector: executionResult.rawCollector
8493
+ }
8494
+ });
8495
+ }
8462
8496
  return executionResult.result;
8463
8497
  } catch (error) {
8464
8498
  if (error instanceof BitfabError) {
@@ -8488,11 +8522,10 @@ var Bitfab = class {
8488
8522
  * @returns A BitfabOpenAITracingProcessor instance configured for this client
8489
8523
  */
8490
8524
  getOpenAiTracingProcessor() {
8525
+ this.prepareFrameworkIntegration();
8491
8526
  return new BitfabOpenAITracingProcessor({
8492
- // Resolved at getter-call time (framework handlers are set up after env
8493
- // loads); the withSpan path stays lazy via the constructor HttpClient thunk.
8494
- apiKey: this.resolveApiKey(),
8495
8527
  serviceUrl: this.serviceUrl,
8528
+ shouldRecord: () => this.shouldRecord(),
8496
8529
  getActiveSpanContext: () => {
8497
8530
  const stack = getSpanStack();
8498
8531
  return stack[stack.length - 1] ?? null;
@@ -8550,10 +8583,11 @@ var Bitfab = class {
8550
8583
  * @returns A BitfabLangGraphCallbackHandler configured for this client
8551
8584
  */
8552
8585
  getLangGraphCallbackHandler(traceFunctionKey) {
8586
+ this.prepareFrameworkIntegration();
8553
8587
  return new BitfabLangGraphCallbackHandler({
8554
- apiKey: this.resolveApiKey(),
8555
8588
  traceFunctionKey,
8556
8589
  serviceUrl: this.serviceUrl,
8590
+ shouldRecord: () => this.shouldRecord(),
8557
8591
  getActiveSpanContext: () => {
8558
8592
  const stack = getSpanStack();
8559
8593
  return stack[stack.length - 1] ?? null;
@@ -8592,10 +8626,11 @@ var Bitfab = class {
8592
8626
  * @experimental This API may change before it is stable.
8593
8627
  */
8594
8628
  getLangGraphIntegration(traceFunctionKey, options) {
8629
+ this.prepareFrameworkIntegration();
8595
8630
  const callbackHandler = new BitfabLangGraphCallbackHandler({
8596
- apiKey: this.resolveApiKey(),
8597
8631
  traceFunctionKey,
8598
8632
  serviceUrl: this.serviceUrl,
8633
+ shouldRecord: () => this.shouldRecord(),
8599
8634
  getActiveSpanContext: () => {
8600
8635
  const stack = getSpanStack();
8601
8636
  return stack[stack.length - 1] ?? null;
@@ -8634,10 +8669,11 @@ var Bitfab = class {
8634
8669
  * @returns A BitfabClaudeAgentHandler configured for this client
8635
8670
  */
8636
8671
  getClaudeAgentHandler(traceFunctionKey) {
8672
+ this.prepareFrameworkIntegration();
8637
8673
  return new BitfabClaudeAgentHandler({
8638
- apiKey: this.resolveApiKey(),
8639
8674
  traceFunctionKey,
8640
8675
  serviceUrl: this.serviceUrl,
8676
+ shouldRecord: () => this.shouldRecord(),
8641
8677
  getActiveSpanContext: () => {
8642
8678
  const stack = getSpanStack();
8643
8679
  return stack[stack.length - 1] ?? null;