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.
@@ -18,7 +18,7 @@ import {
18
18
  serializeValue,
19
19
  toJsonSafe,
20
20
  toJsonSafeReport
21
- } from "./chunk-EBDVWYCV.js";
21
+ } from "./chunk-ONMN7WXS.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-GGMFD2ZE.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);
@@ -3899,6 +3923,11 @@ var Bitfab = class {
3899
3923
  }
3900
3924
  return this.resolveApiKey() !== void 0;
3901
3925
  }
3926
+ prepareFrameworkIntegration() {
3927
+ if (this.captureConfigured && this.strict) {
3928
+ this.resolveApiKey();
3929
+ }
3930
+ }
3902
3931
  get captureEnabled() {
3903
3932
  return this.isCaptureEnabled();
3904
3933
  }
@@ -3956,14 +3985,16 @@ var Bitfab = class {
3956
3985
  resultStr = String(executionResult.result);
3957
3986
  }
3958
3987
  }
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
- });
3988
+ if (this.shouldRecord()) {
3989
+ this.httpClient.sendInternalTrace(functionVersion.id, {
3990
+ result: resultStr,
3991
+ source: "typescript-sdk",
3992
+ ...Object.keys(inputs).length > 0 && { inputs },
3993
+ ...executionResult.rawCollector != null && {
3994
+ rawCollector: executionResult.rawCollector
3995
+ }
3996
+ });
3997
+ }
3967
3998
  return executionResult.result;
3968
3999
  } catch (error) {
3969
4000
  if (error instanceof BitfabError) {
@@ -3993,11 +4024,10 @@ var Bitfab = class {
3993
4024
  * @returns A BitfabOpenAITracingProcessor instance configured for this client
3994
4025
  */
3995
4026
  getOpenAiTracingProcessor() {
4027
+ this.prepareFrameworkIntegration();
3996
4028
  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
4029
  serviceUrl: this.serviceUrl,
4030
+ shouldRecord: () => this.shouldRecord(),
4001
4031
  getActiveSpanContext: () => {
4002
4032
  const stack = getSpanStack();
4003
4033
  return stack[stack.length - 1] ?? null;
@@ -4055,10 +4085,11 @@ var Bitfab = class {
4055
4085
  * @returns A BitfabLangGraphCallbackHandler configured for this client
4056
4086
  */
4057
4087
  getLangGraphCallbackHandler(traceFunctionKey) {
4088
+ this.prepareFrameworkIntegration();
4058
4089
  return new BitfabLangGraphCallbackHandler({
4059
- apiKey: this.resolveApiKey(),
4060
4090
  traceFunctionKey,
4061
4091
  serviceUrl: this.serviceUrl,
4092
+ shouldRecord: () => this.shouldRecord(),
4062
4093
  getActiveSpanContext: () => {
4063
4094
  const stack = getSpanStack();
4064
4095
  return stack[stack.length - 1] ?? null;
@@ -4097,10 +4128,11 @@ var Bitfab = class {
4097
4128
  * @experimental This API may change before it is stable.
4098
4129
  */
4099
4130
  getLangGraphIntegration(traceFunctionKey, options) {
4131
+ this.prepareFrameworkIntegration();
4100
4132
  const callbackHandler = new BitfabLangGraphCallbackHandler({
4101
- apiKey: this.resolveApiKey(),
4102
4133
  traceFunctionKey,
4103
4134
  serviceUrl: this.serviceUrl,
4135
+ shouldRecord: () => this.shouldRecord(),
4104
4136
  getActiveSpanContext: () => {
4105
4137
  const stack = getSpanStack();
4106
4138
  return stack[stack.length - 1] ?? null;
@@ -4139,10 +4171,11 @@ var Bitfab = class {
4139
4171
  * @returns A BitfabClaudeAgentHandler configured for this client
4140
4172
  */
4141
4173
  getClaudeAgentHandler(traceFunctionKey) {
4174
+ this.prepareFrameworkIntegration();
4142
4175
  return new BitfabClaudeAgentHandler({
4143
- apiKey: this.resolveApiKey(),
4144
4176
  traceFunctionKey,
4145
4177
  serviceUrl: this.serviceUrl,
4178
+ shouldRecord: () => this.shouldRecord(),
4146
4179
  getActiveSpanContext: () => {
4147
4180
  const stack = getSpanStack();
4148
4181
  return stack[stack.length - 1] ?? null;
@@ -5171,7 +5204,7 @@ var Bitfab = class {
5171
5204
  await runWithSeedContext({ traceId }, async () => target(...args));
5172
5205
  } finally {
5173
5206
  try {
5174
- const { flushTraces: flushTraces2 } = await import("./http-EMAHQQ4A.js");
5207
+ const { flushTraces: flushTraces2 } = await import("./http-DYGY3K7H.js");
5175
5208
  await flushTraces2(3e4);
5176
5209
  } finally {
5177
5210
  unrecorded = activeTraceStates.delete(traceId);
@@ -5230,7 +5263,7 @@ var Bitfab = class {
5230
5263
  `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
5264
  );
5232
5265
  }
5233
- const { replay: doReplay } = await import("./replay-XG6LNUN4.js");
5266
+ const { replay: doReplay } = await import("./replay-22RLT3Z4.js");
5234
5267
  return doReplay(
5235
5268
  this.httpClient,
5236
5269
  this.serviceUrl,
@@ -5514,7 +5547,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
5514
5547
  sessionId: seedCase.sessionId
5515
5548
  })
5516
5549
  );
5517
- const { flushTraces: flushTraces2 } = await import("./http-EMAHQQ4A.js");
5550
+ const { flushTraces: flushTraces2 } = await import("./http-DYGY3K7H.js");
5518
5551
  await flushTraces2(3e4);
5519
5552
  return { pipeline, traceFunctionKey, traceIds };
5520
5553
  }
@@ -5552,4 +5585,4 @@ export {
5552
5585
  reseedFromRegistry,
5553
5586
  seedFromRegistry
5554
5587
  };
5555
- //# sourceMappingURL=chunk-FCJHKGEE.js.map
5588
+ //# sourceMappingURL=chunk-MFMTLYDW.js.map