bitfab 0.12.1 → 0.12.2

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.
package/dist/index.d.cts CHANGED
@@ -822,7 +822,7 @@ declare class BitfabFunction {
822
822
  /**
823
823
  * SDK version from package.json (injected at build time)
824
824
  */
825
- declare const __version__ = "0.12.1";
825
+ declare const __version__ = "0.12.2";
826
826
 
827
827
  /**
828
828
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -822,7 +822,7 @@ declare class BitfabFunction {
822
822
  /**
823
823
  * SDK version from package.json (injected at build time)
824
824
  */
825
- declare const __version__ = "0.12.1";
825
+ declare const __version__ = "0.12.2";
826
826
 
827
827
  /**
828
828
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -6,13 +6,13 @@ import {
6
6
  BitfabOpenAITracingProcessor,
7
7
  getCurrentSpan,
8
8
  getCurrentTrace
9
- } from "./chunk-NU52P7HA.js";
9
+ } from "./chunk-3HBV4GQO.js";
10
10
  import {
11
11
  BitfabError,
12
12
  DEFAULT_SERVICE_URL,
13
13
  __version__,
14
14
  flushTraces
15
- } from "./chunk-OOKZ6S64.js";
15
+ } from "./chunk-HUSTKOQI.js";
16
16
  export {
17
17
  Bitfab,
18
18
  BitfabClaudeAgentHandler,
package/dist/node.cjs CHANGED
@@ -81,7 +81,7 @@ var __version__;
81
81
  var init_version_generated = __esm({
82
82
  "src/version.generated.ts"() {
83
83
  "use strict";
84
- __version__ = "0.12.1";
84
+ __version__ = "0.12.2";
85
85
  }
86
86
  });
87
87
 
@@ -473,9 +473,11 @@ function buildMockTree(rootNode) {
473
473
  function walk(node) {
474
474
  const key = node.traceFunctionKey;
475
475
  if (key) {
476
- const index = counters.get(key) ?? 0;
477
- counters.set(key, index + 1);
478
- spans.set(`${key}:${index}`, {
476
+ const name = node.spanName;
477
+ const counterKey = `${key}:${name}`;
478
+ const index = counters.get(counterKey) ?? 0;
479
+ counters.set(counterKey, index + 1);
480
+ spans.set(`${counterKey}:${index}`, {
479
481
  sourceSpanId: node.sourceSpanId,
480
482
  output: node.output,
481
483
  outputMeta: node.outputMeta
@@ -485,7 +487,9 @@ function buildMockTree(rootNode) {
485
487
  walk(child);
486
488
  }
487
489
  }
488
- walk(rootNode);
490
+ for (const child of rootNode.children) {
491
+ walk(child);
492
+ }
489
493
  return { spans };
490
494
  }
491
495
  async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy) {
@@ -2615,6 +2619,15 @@ var Bitfab = class {
2615
2619
  const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
2616
2620
  const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
2617
2621
  const self = this;
2622
+ const fnIsAsyncFunction = fn.constructor.name === "AsyncFunction";
2623
+ const fnReturnsPromise = fnIsAsyncFunction || (() => {
2624
+ try {
2625
+ const src = fn.toString();
2626
+ return /\b(?:Promise|await)\b/.test(src);
2627
+ } catch {
2628
+ return false;
2629
+ }
2630
+ })();
2618
2631
  const wrappedFn = function(...args) {
2619
2632
  if (!asyncLocalStorage && !isAsyncStorageInitDone()) {
2620
2633
  return asyncLocalStorageReady.then(
@@ -2708,11 +2721,12 @@ var Bitfab = class {
2708
2721
  const replayCtxForMock = getReplayContext();
2709
2722
  if (replayCtxForMock?.mockTree && !isRootSpan) {
2710
2723
  const counters = replayCtxForMock.callCounters;
2711
- const callIndex = counters.get(traceFunctionKey) ?? 0;
2712
- counters.set(traceFunctionKey, callIndex + 1);
2724
+ const counterKey = `${traceFunctionKey}:${baseSpanParams.spanName}`;
2725
+ const callIndex = counters.get(counterKey) ?? 0;
2726
+ counters.set(counterKey, callIndex + 1);
2713
2727
  const shouldMock = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
2714
2728
  if (shouldMock) {
2715
- const mockKey = `${traceFunctionKey}:${callIndex}`;
2729
+ const mockKey = `${counterKey}:${callIndex}`;
2716
2730
  const mockSpan = replayCtxForMock.mockTree.spans.get(mockKey);
2717
2731
  if (mockSpan) {
2718
2732
  let output = mockSpan.output;
@@ -2723,7 +2737,7 @@ var Bitfab = class {
2723
2737
  });
2724
2738
  }
2725
2739
  void sendSpan({ result: output });
2726
- if (fn.constructor.name === "AsyncFunction") {
2740
+ if (fnReturnsPromise) {
2727
2741
  return Promise.resolve(output);
2728
2742
  }
2729
2743
  return output;