bitfab 0.54.6 → 0.54.8

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
  replayContextReady,
7
7
  runWithReplayContext,
8
8
  warnOnce
9
- } from "./chunk-5FRFNRFA.js";
9
+ } from "./chunk-5H3D7J4K.js";
10
10
  import {
11
11
  runWithCaptureSuppressed
12
12
  } from "./chunk-VCRFFCLY.js";
@@ -1212,4 +1212,4 @@ export {
1212
1212
  sleepForReplayPersistence,
1213
1213
  replay
1214
1214
  };
1215
- //# sourceMappingURL=chunk-EBDVWYCV.js.map
1215
+ //# sourceMappingURL=chunk-RUCVJQBI.js.map
@@ -18,7 +18,7 @@ import {
18
18
  serializeValue,
19
19
  toJsonSafe,
20
20
  toJsonSafeReport
21
- } from "./chunk-EBDVWYCV.js";
21
+ } from "./chunk-RUCVJQBI.js";
22
22
  import {
23
23
  BitfabError,
24
24
  DEFAULT_SERVICE_URL,
@@ -35,7 +35,7 @@ import {
35
35
  recordCallerTraceMetadata,
36
36
  retireTraceMetadata,
37
37
  warnOnce
38
- } from "./chunk-5FRFNRFA.js";
38
+ } from "./chunk-5H3D7J4K.js";
39
39
  import {
40
40
  __privateAdd,
41
41
  __privateGet,
@@ -213,6 +213,7 @@ var BitfabClaudeAgentHandler = class {
213
213
  });
214
214
  this.traceFunctionKey = config.traceFunctionKey;
215
215
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
216
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
216
217
  this.preToolUseHook = this.preToolUseHook.bind(this);
217
218
  this.postToolUseHook = this.postToolUseHook.bind(this);
218
219
  this.postToolUseFailureHook = this.postToolUseFailureHook.bind(this);
@@ -317,6 +318,9 @@ var BitfabClaudeAgentHandler = class {
317
318
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
318
319
  }
319
320
  sendSpan(spanInfo) {
321
+ if (!this.shouldRecord()) {
322
+ return;
323
+ }
320
324
  const spanData = {
321
325
  name: spanInfo.name,
322
326
  type: spanInfo.type
@@ -360,6 +364,9 @@ var BitfabClaudeAgentHandler = class {
360
364
  }
361
365
  }
362
366
  sendTraceCompletion(endedAt, metadata) {
367
+ if (!this.shouldRecord()) {
368
+ return;
369
+ }
363
370
  if (this.traceId === null) {
364
371
  return;
365
372
  }
@@ -1716,6 +1723,7 @@ var BitfabLangGraphCallbackHandler = class {
1716
1723
  });
1717
1724
  this.traceFunctionKey = config.traceFunctionKey;
1718
1725
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
1726
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
1719
1727
  this.captureTools = config.captureTools ?? true;
1720
1728
  }
1721
1729
  /**
@@ -1824,6 +1832,9 @@ var BitfabLangGraphCallbackHandler = class {
1824
1832
  this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
1825
1833
  }
1826
1834
  sendSpan(spanInfo) {
1835
+ if (!this.shouldRecord()) {
1836
+ return;
1837
+ }
1827
1838
  const spanData = {
1828
1839
  name: spanInfo.name,
1829
1840
  type: spanInfo.type
@@ -1867,6 +1878,9 @@ var BitfabLangGraphCallbackHandler = class {
1867
1878
  }
1868
1879
  }
1869
1880
  sendTraceCompletion(rootSpan, activeContext) {
1881
+ if (!this.shouldRecord()) {
1882
+ return;
1883
+ }
1870
1884
  const completed = activeContext === null;
1871
1885
  const traceData = {
1872
1886
  id: rootSpan.traceId,
@@ -1887,6 +1901,9 @@ var BitfabLangGraphCallbackHandler = class {
1887
1901
  }
1888
1902
  }
1889
1903
  sendTraceStart(rootSpan) {
1904
+ if (!this.shouldRecord()) {
1905
+ return;
1906
+ }
1890
1907
  const traceData = {
1891
1908
  id: rootSpan.traceId,
1892
1909
  type: "sdk-function",
@@ -2569,6 +2586,7 @@ var BitfabOpenAITracingProcessor = class {
2569
2586
  timeout: config.timeout ?? 1e4
2570
2587
  });
2571
2588
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
2589
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
2572
2590
  }
2573
2591
  getCanonicalTraceId(sourceTraceId) {
2574
2592
  const existing = this.canonicalTraceIds[sourceTraceId];
@@ -2689,6 +2707,9 @@ var BitfabOpenAITracingProcessor = class {
2689
2707
  * the OpenAI trace into an outer withSpan trace.
2690
2708
  */
2691
2709
  sendTrace(trace, options = {}) {
2710
+ if (!this.shouldRecord()) {
2711
+ return;
2712
+ }
2692
2713
  try {
2693
2714
  const traceData = trace.toJSON();
2694
2715
  if (options.sourceTraceId) {
@@ -2803,6 +2824,9 @@ var BitfabOpenAITracingProcessor = class {
2803
2824
  * and parent_id are rewritten to link the span into the withSpan tree.
2804
2825
  */
2805
2826
  sendSpan(span) {
2827
+ if (!this.shouldRecord()) {
2828
+ return;
2829
+ }
2806
2830
  const errors = [];
2807
2831
  const [serializedSpan, exportErrors] = this.exportSpan(span);
2808
2832
  errors.push(...exportErrors);
@@ -3371,6 +3395,30 @@ function readEnv2(name) {
3371
3395
  }
3372
3396
  return void 0;
3373
3397
  }
3398
+ var CAPTURE_ENABLED_ENV = "BITFAB_CAPTURE_ENABLED";
3399
+ var TRUE_ENV_VALUES = /* @__PURE__ */ new Set(["1", "true", "yes"]);
3400
+ var FALSE_ENV_VALUES = /* @__PURE__ */ new Set(["0", "false", "no"]);
3401
+ function readBooleanEnv(name) {
3402
+ const raw = readEnv2(name);
3403
+ if (raw === void 0) {
3404
+ return void 0;
3405
+ }
3406
+ const value = raw.trim().toLowerCase();
3407
+ if (value === "") {
3408
+ return void 0;
3409
+ }
3410
+ if (TRUE_ENV_VALUES.has(value)) {
3411
+ return true;
3412
+ }
3413
+ if (FALSE_ENV_VALUES.has(value)) {
3414
+ return false;
3415
+ }
3416
+ warnOnce(
3417
+ `unrecognized-boolean-env:${name}`,
3418
+ `${name}="${raw}" is not 0 or 1; ignoring it.`
3419
+ );
3420
+ return void 0;
3421
+ }
3374
3422
  var DEFAULT_AUTO_TRACE_MAX_DEPTH = 30;
3375
3423
  var DEFAULT_AUTO_TRACE_MAX_SPANS = 500;
3376
3424
  var AUTO_TRACE_PROTOCOL = "ts-auto-v1";
@@ -3425,7 +3473,7 @@ var Bitfab = class {
3425
3473
  "Bitfab({ enabled }) is deprecated; pass captureEnabled instead."
3426
3474
  );
3427
3475
  }
3428
- this.captureConfigured = (config.captureEnabled ?? true) && (config.enabled ?? true);
3476
+ this.captureConfiguredInCode = config.captureEnabled === void 0 && config.enabled === void 0 ? void 0 : (config.captureEnabled ?? true) && (config.enabled ?? true);
3429
3477
  this.strict = config.strict ?? false;
3430
3478
  this.bamlClient = config.bamlClient ?? null;
3431
3479
  if (config.dbSnapshot) {
@@ -3879,7 +3927,7 @@ var Bitfab = class {
3879
3927
  "Bitfab: no API key resolved. Set BITFAB_API_KEY or pass apiKey to new Bitfab(). If a script loads env with dotenv, load it before the module that constructs the client is imported (e.g. `node --env-file=.env script.ts`), or pass `apiKey: () => process.env.BITFAB_API_KEY`."
3880
3928
  );
3881
3929
  }
3882
- if (this.captureConfigured && !this.apiKeyWarned) {
3930
+ if (this.isCaptureConfigured() && !this.apiKeyWarned) {
3883
3931
  this.apiKeyWarned = true;
3884
3932
  console.warn(
3885
3933
  "Bitfab: apiKey is empty - tracing is disabled. Provide a valid API key to enable tracing."
@@ -3887,18 +3935,32 @@ var Bitfab = class {
3887
3935
  }
3888
3936
  return void 0;
3889
3937
  }
3938
+ isCaptureConfigured() {
3939
+ if (this.captureConfiguredInCode !== void 0) {
3940
+ return this.captureConfiguredInCode;
3941
+ }
3942
+ if (this.captureConfiguredFromEnv === void 0) {
3943
+ this.captureConfiguredFromEnv = readBooleanEnv(CAPTURE_ENABLED_ENV) ?? true;
3944
+ }
3945
+ return this.captureConfiguredFromEnv;
3946
+ }
3890
3947
  isCaptureEnabled() {
3891
- if (!this.captureConfigured) {
3948
+ if (!this.isCaptureConfigured()) {
3892
3949
  return false;
3893
3950
  }
3894
3951
  return this.resolveApiKey() !== void 0;
3895
3952
  }
3896
3953
  shouldRecord() {
3897
- if (!this.captureConfigured && !getReplayContext() && !inSeedScope()) {
3954
+ if (!this.isCaptureConfigured() && !getReplayContext() && !inSeedScope()) {
3898
3955
  return false;
3899
3956
  }
3900
3957
  return this.resolveApiKey() !== void 0;
3901
3958
  }
3959
+ prepareFrameworkIntegration() {
3960
+ if (this.isCaptureConfigured() && this.strict) {
3961
+ this.resolveApiKey();
3962
+ }
3963
+ }
3902
3964
  get captureEnabled() {
3903
3965
  return this.isCaptureEnabled();
3904
3966
  }
@@ -3956,14 +4018,16 @@ var Bitfab = class {
3956
4018
  resultStr = String(executionResult.result);
3957
4019
  }
3958
4020
  }
3959
- this.httpClient.sendInternalTrace(functionVersion.id, {
3960
- result: resultStr,
3961
- source: "typescript-sdk",
3962
- ...Object.keys(inputs).length > 0 && { inputs },
3963
- ...executionResult.rawCollector != null && {
3964
- rawCollector: executionResult.rawCollector
3965
- }
3966
- });
4021
+ if (this.shouldRecord()) {
4022
+ this.httpClient.sendInternalTrace(functionVersion.id, {
4023
+ result: resultStr,
4024
+ source: "typescript-sdk",
4025
+ ...Object.keys(inputs).length > 0 && { inputs },
4026
+ ...executionResult.rawCollector != null && {
4027
+ rawCollector: executionResult.rawCollector
4028
+ }
4029
+ });
4030
+ }
3967
4031
  return executionResult.result;
3968
4032
  } catch (error) {
3969
4033
  if (error instanceof BitfabError) {
@@ -3993,11 +4057,10 @@ var Bitfab = class {
3993
4057
  * @returns A BitfabOpenAITracingProcessor instance configured for this client
3994
4058
  */
3995
4059
  getOpenAiTracingProcessor() {
4060
+ this.prepareFrameworkIntegration();
3996
4061
  return new BitfabOpenAITracingProcessor({
3997
- // Resolved at getter-call time (framework handlers are set up after env
3998
- // loads); the withSpan path stays lazy via the constructor HttpClient thunk.
3999
- apiKey: this.resolveApiKey(),
4000
4062
  serviceUrl: this.serviceUrl,
4063
+ shouldRecord: () => this.shouldRecord(),
4001
4064
  getActiveSpanContext: () => {
4002
4065
  const stack = getSpanStack();
4003
4066
  return stack[stack.length - 1] ?? null;
@@ -4055,10 +4118,11 @@ var Bitfab = class {
4055
4118
  * @returns A BitfabLangGraphCallbackHandler configured for this client
4056
4119
  */
4057
4120
  getLangGraphCallbackHandler(traceFunctionKey) {
4121
+ this.prepareFrameworkIntegration();
4058
4122
  return new BitfabLangGraphCallbackHandler({
4059
- apiKey: this.resolveApiKey(),
4060
4123
  traceFunctionKey,
4061
4124
  serviceUrl: this.serviceUrl,
4125
+ shouldRecord: () => this.shouldRecord(),
4062
4126
  getActiveSpanContext: () => {
4063
4127
  const stack = getSpanStack();
4064
4128
  return stack[stack.length - 1] ?? null;
@@ -4097,10 +4161,11 @@ var Bitfab = class {
4097
4161
  * @experimental This API may change before it is stable.
4098
4162
  */
4099
4163
  getLangGraphIntegration(traceFunctionKey, options) {
4164
+ this.prepareFrameworkIntegration();
4100
4165
  const callbackHandler = new BitfabLangGraphCallbackHandler({
4101
- apiKey: this.resolveApiKey(),
4102
4166
  traceFunctionKey,
4103
4167
  serviceUrl: this.serviceUrl,
4168
+ shouldRecord: () => this.shouldRecord(),
4104
4169
  getActiveSpanContext: () => {
4105
4170
  const stack = getSpanStack();
4106
4171
  return stack[stack.length - 1] ?? null;
@@ -4139,10 +4204,11 @@ var Bitfab = class {
4139
4204
  * @returns A BitfabClaudeAgentHandler configured for this client
4140
4205
  */
4141
4206
  getClaudeAgentHandler(traceFunctionKey) {
4207
+ this.prepareFrameworkIntegration();
4142
4208
  return new BitfabClaudeAgentHandler({
4143
- apiKey: this.resolveApiKey(),
4144
4209
  traceFunctionKey,
4145
4210
  serviceUrl: this.serviceUrl,
4211
+ shouldRecord: () => this.shouldRecord(),
4146
4212
  getActiveSpanContext: () => {
4147
4213
  const stack = getSpanStack();
4148
4214
  return stack[stack.length - 1] ?? null;
@@ -5171,7 +5237,7 @@ var Bitfab = class {
5171
5237
  await runWithSeedContext({ traceId }, async () => target(...args));
5172
5238
  } finally {
5173
5239
  try {
5174
- const { flushTraces: flushTraces2 } = await import("./http-EMAHQQ4A.js");
5240
+ const { flushTraces: flushTraces2 } = await import("./http-7PL32JLX.js");
5175
5241
  await flushTraces2(3e4);
5176
5242
  } finally {
5177
5243
  unrecorded = activeTraceStates.delete(traceId);
@@ -5230,7 +5296,7 @@ var Bitfab = class {
5230
5296
  `Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
5231
5297
  );
5232
5298
  }
5233
- const { replay: doReplay } = await import("./replay-XG6LNUN4.js");
5299
+ const { replay: doReplay } = await import("./replay-KWBZ2JQV.js");
5234
5300
  return doReplay(
5235
5301
  this.httpClient,
5236
5302
  this.serviceUrl,
@@ -5514,7 +5580,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
5514
5580
  sessionId: seedCase.sessionId
5515
5581
  })
5516
5582
  );
5517
- const { flushTraces: flushTraces2 } = await import("./http-EMAHQQ4A.js");
5583
+ const { flushTraces: flushTraces2 } = await import("./http-7PL32JLX.js");
5518
5584
  await flushTraces2(3e4);
5519
5585
  return { pipeline, traceFunctionKey, traceIds };
5520
5586
  }
@@ -5552,4 +5618,4 @@ export {
5552
5618
  reseedFromRegistry,
5553
5619
  seedFromRegistry
5554
5620
  };
5555
- //# sourceMappingURL=chunk-FCJHKGEE.js.map
5621
+ //# sourceMappingURL=chunk-XPCVDQDS.js.map