bitfab 0.12.0 → 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.0";
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.0";
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-QUCK3IU2.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-VMJPNYAG.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.0";
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
@@ -2617,6 +2619,15 @@ var Bitfab = class {
2617
2619
  const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
2618
2620
  const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
2619
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
+ })();
2620
2631
  const wrappedFn = function(...args) {
2621
2632
  if (!asyncLocalStorage && !isAsyncStorageInitDone()) {
2622
2633
  return asyncLocalStorageReady.then(
@@ -2710,11 +2721,12 @@ var Bitfab = class {
2710
2721
  const replayCtxForMock = getReplayContext();
2711
2722
  if (replayCtxForMock?.mockTree && !isRootSpan) {
2712
2723
  const counters = replayCtxForMock.callCounters;
2713
- const callIndex = counters.get(traceFunctionKey) ?? 0;
2714
- counters.set(traceFunctionKey, callIndex + 1);
2724
+ const counterKey = `${traceFunctionKey}:${baseSpanParams.spanName}`;
2725
+ const callIndex = counters.get(counterKey) ?? 0;
2726
+ counters.set(counterKey, callIndex + 1);
2715
2727
  const shouldMock = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
2716
2728
  if (shouldMock) {
2717
- const mockKey = `${traceFunctionKey}:${callIndex}`;
2729
+ const mockKey = `${counterKey}:${callIndex}`;
2718
2730
  const mockSpan = replayCtxForMock.mockTree.spans.get(mockKey);
2719
2731
  if (mockSpan) {
2720
2732
  let output = mockSpan.output;
@@ -2725,6 +2737,9 @@ var Bitfab = class {
2725
2737
  });
2726
2738
  }
2727
2739
  void sendSpan({ result: output });
2740
+ if (fnReturnsPromise) {
2741
+ return Promise.resolve(output);
2742
+ }
2728
2743
  return output;
2729
2744
  }
2730
2745
  }