@bitfab/sdk 0.36.12 → 0.38.0

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.cjs CHANGED
@@ -42,7 +42,7 @@ var __version__;
42
42
  var init_version_generated = __esm({
43
43
  "src/version.generated.ts"() {
44
44
  "use strict";
45
- __version__ = "0.36.12";
45
+ __version__ = "0.38.0";
46
46
  }
47
47
  });
48
48
 
@@ -2525,12 +2525,15 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2525
2525
  let lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
2526
2526
  let leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
2527
2527
  let dbSnapshotRef = serverItem.dbSnapshotRef;
2528
+ let dbBranchTimings = includeDbBranchLease ? serverItem.dbBranchTimings : void 0;
2528
2529
  let inputs = [];
2529
2530
  let originalOutput;
2530
2531
  let result;
2531
2532
  let error = null;
2532
2533
  let traceError = null;
2533
2534
  let replayError = null;
2535
+ let replayDurationMs = null;
2536
+ let replayStarted = null;
2534
2537
  const originalTraceId = serverItem.originalTraceId ?? serverItem.sourceTraceId;
2535
2538
  const originalSpanId = serverItem.originalSpanId ?? serverItem.sourceSpanId;
2536
2539
  try {
@@ -2553,6 +2556,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2553
2556
  lease = resolved.lease ?? void 0;
2554
2557
  leaseError = resolved.leaseError ?? void 0;
2555
2558
  dbSnapshotRef = resolved.dbSnapshotRef ?? dbSnapshotRef;
2559
+ dbBranchTimings = resolved.timings ?? dbBranchTimings;
2556
2560
  }
2557
2561
  if (leaseError) {
2558
2562
  throw new DbBranchReplayError(
@@ -2586,20 +2590,17 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2586
2590
  includeOutputs,
2587
2591
  includeRootOutput: false
2588
2592
  });
2589
- if (treeResponse.root) {
2590
- mockTree = buildMockTree(treeResponse.root);
2591
- } else if (mockStrategy === "all" || hasOverrides) {
2593
+ if (!treeResponse.root) {
2592
2594
  throw new BitfabError(
2593
2595
  `Replay mock strategy "${mockStrategy}"${hasOverrides ? " with overrides" : ""} requires a span tree root for original span ${originalSpanId}.`
2594
2596
  );
2595
- } else {
2596
- mockTree = void 0;
2597
2597
  }
2598
- } catch (e) {
2599
- if (mockStrategy === "all" || hasOverrides) {
2600
- throw e;
2598
+ mockTree = buildMockTree(treeResponse.root);
2599
+ } catch (error2) {
2600
+ if (mockStrategy !== "marked" || hasOverrides) {
2601
+ throw error2;
2601
2602
  }
2602
- mockTree = void 0;
2603
+ mockTree = { spans: /* @__PURE__ */ new Map() };
2603
2604
  }
2604
2605
  }
2605
2606
  const outputCache = /* @__PURE__ */ new Map();
@@ -2616,6 +2617,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2616
2617
  return pending;
2617
2618
  } : void 0;
2618
2619
  try {
2620
+ replayStarted = performance.now();
2619
2621
  const maybePromise = runWithReplayContext(
2620
2622
  {
2621
2623
  testRunId,
@@ -2628,16 +2630,24 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2628
2630
  mockStrategy,
2629
2631
  mockOverrides: hasOverrides ? resolvedOverrides : void 0,
2630
2632
  fetchSpanOutput,
2631
- dbBranchLease: lease
2633
+ dbBranchLease: lease,
2634
+ dbBranchTimings
2632
2635
  },
2633
2636
  () => fn(...inputs)
2634
2637
  );
2635
2638
  result = maybePromise instanceof Promise ? await maybePromise : maybePromise;
2639
+ replayDurationMs = Math.round(performance.now() - replayStarted);
2636
2640
  } catch (e) {
2641
+ if (replayStarted !== null) {
2642
+ replayDurationMs = Math.round(performance.now() - replayStarted);
2643
+ }
2637
2644
  traceError = e;
2638
2645
  error = errorMessage(e);
2639
2646
  }
2640
2647
  } catch (e) {
2648
+ if (replayStarted !== null) {
2649
+ replayDurationMs = Math.round(performance.now() - replayStarted);
2650
+ }
2641
2651
  replayError = e;
2642
2652
  error = replayItemErrorMessage(e);
2643
2653
  } finally {
@@ -2654,6 +2664,8 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2654
2664
  }
2655
2665
  }
2656
2666
  }
2667
+ const originalDurationMs = serverItem.originalDurationMs ?? serverItem.durationMs ?? null;
2668
+ const originalModel = serverItem.originalModel ?? serverItem.model ?? null;
2657
2669
  return {
2658
2670
  // Written in by replay() from the complete-replay response once the server
2659
2671
  // has minted this replay trace's row. Null until then: the client-side
@@ -2670,13 +2682,17 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2670
2682
  error,
2671
2683
  traceError,
2672
2684
  replayError,
2673
- durationMs: serverItem.durationMs ?? null,
2685
+ durationMs: replayDurationMs,
2686
+ originalDurationMs,
2687
+ originalTokens: serverItem.originalTokens ?? serverItem.tokens ?? null,
2688
+ originalModel,
2674
2689
  // Filled in by replay() from the complete-replay response once the
2675
2690
  // replay traces are persisted and their spans aggregated server-side.
2676
2691
  // Null here (and on older servers) means "replay tokens not known".
2677
2692
  tokens: null,
2678
- model: serverItem.model ?? null,
2679
- dbSnapshotRef: dbSnapshotRef ?? null
2693
+ model: originalModel,
2694
+ dbSnapshotRef: dbSnapshotRef ?? null,
2695
+ dbBranchTimings: dbBranchTimings ?? null
2680
2696
  };
2681
2697
  }
2682
2698
  async function waitForReplayPersistence(httpClient, testRunId, replayedTraceIds) {
@@ -2903,9 +2919,13 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
2903
2919
  traceError: item.traceError,
2904
2920
  replayError: item.replayError,
2905
2921
  durationMs: item.durationMs,
2922
+ originalDurationMs: item.originalDurationMs,
2923
+ originalTokens: item.originalTokens,
2924
+ originalModel: item.originalModel,
2906
2925
  tokens: item.tokens,
2907
2926
  model: item.model,
2908
- dbSnapshotRef: item.dbSnapshotRef
2927
+ dbSnapshotRef: item.dbSnapshotRef,
2928
+ dbBranchTimings: item.dbBranchTimings
2909
2929
  }
2910
2930
  });
2911
2931
  } catch {
@@ -6084,7 +6104,8 @@ var Bitfab = class {
6084
6104
  snapshotTimestamp: replayCtx.dbBranchLease.snapshotTimestamp,
6085
6105
  region: replayCtx.dbBranchLease.region,
6086
6106
  originalTraceId: replayCtx.sourceBitfabTraceId,
6087
- accessed: replayCtx.dbSnapshotAccessed === true
6107
+ accessed: replayCtx.dbSnapshotAccessed === true,
6108
+ timings: replayCtx.dbBranchTimings
6088
6109
  }
6089
6110
  }
6090
6111
  });
@@ -6174,7 +6195,12 @@ var Bitfab = class {
6174
6195
  }
6175
6196
  }
6176
6197
  const shouldMock = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
6177
- if (shouldMock && mockSpan) {
6198
+ if (shouldMock && !mockSpan) {
6199
+ throw new BitfabError(
6200
+ `Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
6201
+ );
6202
+ }
6203
+ if (shouldMock) {
6178
6204
  const recorded = resolveRecordedOutput();
6179
6205
  if (recorded instanceof Promise) {
6180
6206
  return emitMockAsync(recorded, "recorded");
@@ -6411,7 +6437,13 @@ var Bitfab = class {
6411
6437
  // against servers that predate the rename.
6412
6438
  source_trace_id: params.dbSnapshotUsage.originalTraceId
6413
6439
  },
6414
- accessed: params.dbSnapshotUsage.accessed
6440
+ accessed: params.dbSnapshotUsage.accessed,
6441
+ // Echoed verbatim (camelCase inside) rather than re-cased into this
6442
+ // record's snake_case: it is the server's own object coming back, and
6443
+ // a translation layer here is one more thing to drift.
6444
+ ...params.dbSnapshotUsage.timings && {
6445
+ timings: params.dbSnapshotUsage.timings
6446
+ }
6415
6447
  };
6416
6448
  }
6417
6449
  this.httpClient.sendExternalTrace({