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.
@@ -18,7 +18,7 @@ import {
18
18
  serializeValue,
19
19
  toJsonSafe,
20
20
  toJsonSafeReport
21
- } from "./chunk-3O5MS4XJ.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-GVK7AES5.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",
@@ -2516,12 +2533,6 @@ var TracesClient = class {
2516
2533
  constructor(httpClient) {
2517
2534
  this.httpClient = httpClient;
2518
2535
  }
2519
- /**
2520
- * Search traces by exact caller metadata.
2521
- *
2522
- * Keys and values are matched case-insensitively. Up to 10 supplied pairs
2523
- * must match. Use `nextCursor` from the result to fetch another page.
2524
- */
2525
2536
  async search(params) {
2526
2537
  return this.httpClient.request(SEARCH_PATH, params);
2527
2538
  }
@@ -2575,6 +2586,7 @@ var BitfabOpenAITracingProcessor = class {
2575
2586
  timeout: config.timeout ?? 1e4
2576
2587
  });
2577
2588
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
2589
+ this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
2578
2590
  }
2579
2591
  getCanonicalTraceId(sourceTraceId) {
2580
2592
  const existing = this.canonicalTraceIds[sourceTraceId];
@@ -2695,6 +2707,9 @@ var BitfabOpenAITracingProcessor = class {
2695
2707
  * the OpenAI trace into an outer withSpan trace.
2696
2708
  */
2697
2709
  sendTrace(trace, options = {}) {
2710
+ if (!this.shouldRecord()) {
2711
+ return;
2712
+ }
2698
2713
  try {
2699
2714
  const traceData = trace.toJSON();
2700
2715
  if (options.sourceTraceId) {
@@ -2809,6 +2824,9 @@ var BitfabOpenAITracingProcessor = class {
2809
2824
  * and parent_id are rewritten to link the span into the withSpan tree.
2810
2825
  */
2811
2826
  sendSpan(span) {
2827
+ if (!this.shouldRecord()) {
2828
+ return;
2829
+ }
2812
2830
  const errors = [];
2813
2831
  const [serializedSpan, exportErrors] = this.exportSpan(span);
2814
2832
  errors.push(...exportErrors);
@@ -3905,6 +3923,11 @@ var Bitfab = class {
3905
3923
  }
3906
3924
  return this.resolveApiKey() !== void 0;
3907
3925
  }
3926
+ prepareFrameworkIntegration() {
3927
+ if (this.captureConfigured && this.strict) {
3928
+ this.resolveApiKey();
3929
+ }
3930
+ }
3908
3931
  get captureEnabled() {
3909
3932
  return this.isCaptureEnabled();
3910
3933
  }
@@ -3962,14 +3985,16 @@ var Bitfab = class {
3962
3985
  resultStr = String(executionResult.result);
3963
3986
  }
3964
3987
  }
3965
- this.httpClient.sendInternalTrace(functionVersion.id, {
3966
- result: resultStr,
3967
- source: "typescript-sdk",
3968
- ...Object.keys(inputs).length > 0 && { inputs },
3969
- ...executionResult.rawCollector != null && {
3970
- rawCollector: executionResult.rawCollector
3971
- }
3972
- });
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
+ }
3973
3998
  return executionResult.result;
3974
3999
  } catch (error) {
3975
4000
  if (error instanceof BitfabError) {
@@ -3999,11 +4024,10 @@ var Bitfab = class {
3999
4024
  * @returns A BitfabOpenAITracingProcessor instance configured for this client
4000
4025
  */
4001
4026
  getOpenAiTracingProcessor() {
4027
+ this.prepareFrameworkIntegration();
4002
4028
  return new BitfabOpenAITracingProcessor({
4003
- // Resolved at getter-call time (framework handlers are set up after env
4004
- // loads); the withSpan path stays lazy via the constructor HttpClient thunk.
4005
- apiKey: this.resolveApiKey(),
4006
4029
  serviceUrl: this.serviceUrl,
4030
+ shouldRecord: () => this.shouldRecord(),
4007
4031
  getActiveSpanContext: () => {
4008
4032
  const stack = getSpanStack();
4009
4033
  return stack[stack.length - 1] ?? null;
@@ -4061,10 +4085,11 @@ var Bitfab = class {
4061
4085
  * @returns A BitfabLangGraphCallbackHandler configured for this client
4062
4086
  */
4063
4087
  getLangGraphCallbackHandler(traceFunctionKey) {
4088
+ this.prepareFrameworkIntegration();
4064
4089
  return new BitfabLangGraphCallbackHandler({
4065
- apiKey: this.resolveApiKey(),
4066
4090
  traceFunctionKey,
4067
4091
  serviceUrl: this.serviceUrl,
4092
+ shouldRecord: () => this.shouldRecord(),
4068
4093
  getActiveSpanContext: () => {
4069
4094
  const stack = getSpanStack();
4070
4095
  return stack[stack.length - 1] ?? null;
@@ -4103,10 +4128,11 @@ var Bitfab = class {
4103
4128
  * @experimental This API may change before it is stable.
4104
4129
  */
4105
4130
  getLangGraphIntegration(traceFunctionKey, options) {
4131
+ this.prepareFrameworkIntegration();
4106
4132
  const callbackHandler = new BitfabLangGraphCallbackHandler({
4107
- apiKey: this.resolveApiKey(),
4108
4133
  traceFunctionKey,
4109
4134
  serviceUrl: this.serviceUrl,
4135
+ shouldRecord: () => this.shouldRecord(),
4110
4136
  getActiveSpanContext: () => {
4111
4137
  const stack = getSpanStack();
4112
4138
  return stack[stack.length - 1] ?? null;
@@ -4145,10 +4171,11 @@ var Bitfab = class {
4145
4171
  * @returns A BitfabClaudeAgentHandler configured for this client
4146
4172
  */
4147
4173
  getClaudeAgentHandler(traceFunctionKey) {
4174
+ this.prepareFrameworkIntegration();
4148
4175
  return new BitfabClaudeAgentHandler({
4149
- apiKey: this.resolveApiKey(),
4150
4176
  traceFunctionKey,
4151
4177
  serviceUrl: this.serviceUrl,
4178
+ shouldRecord: () => this.shouldRecord(),
4152
4179
  getActiveSpanContext: () => {
4153
4180
  const stack = getSpanStack();
4154
4181
  return stack[stack.length - 1] ?? null;
@@ -5177,7 +5204,7 @@ var Bitfab = class {
5177
5204
  await runWithSeedContext({ traceId }, async () => target(...args));
5178
5205
  } finally {
5179
5206
  try {
5180
- const { flushTraces: flushTraces2 } = await import("./http-RW2JO6TU.js");
5207
+ const { flushTraces: flushTraces2 } = await import("./http-DYGY3K7H.js");
5181
5208
  await flushTraces2(3e4);
5182
5209
  } finally {
5183
5210
  unrecorded = activeTraceStates.delete(traceId);
@@ -5236,7 +5263,7 @@ var Bitfab = class {
5236
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.`
5237
5264
  );
5238
5265
  }
5239
- const { replay: doReplay } = await import("./replay-MHYULXCH.js");
5266
+ const { replay: doReplay } = await import("./replay-22RLT3Z4.js");
5240
5267
  return doReplay(
5241
5268
  this.httpClient,
5242
5269
  this.serviceUrl,
@@ -5520,7 +5547,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
5520
5547
  sessionId: seedCase.sessionId
5521
5548
  })
5522
5549
  );
5523
- const { flushTraces: flushTraces2 } = await import("./http-RW2JO6TU.js");
5550
+ const { flushTraces: flushTraces2 } = await import("./http-DYGY3K7H.js");
5524
5551
  await flushTraces2(3e4);
5525
5552
  return { pipeline, traceFunctionKey, traceIds };
5526
5553
  }
@@ -5558,4 +5585,4 @@ export {
5558
5585
  reseedFromRegistry,
5559
5586
  seedFromRegistry
5560
5587
  };
5561
- //# sourceMappingURL=chunk-NATC7L2W.js.map
5588
+ //# sourceMappingURL=chunk-MFMTLYDW.js.map