@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/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.36.12";
91
+ __version__ = "0.38.0";
92
92
  }
93
93
  });
94
94
 
@@ -2532,12 +2532,15 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2532
2532
  let lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
2533
2533
  let leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
2534
2534
  let dbSnapshotRef = serverItem.dbSnapshotRef;
2535
+ let dbBranchTimings = includeDbBranchLease ? serverItem.dbBranchTimings : void 0;
2535
2536
  let inputs = [];
2536
2537
  let originalOutput;
2537
2538
  let result;
2538
2539
  let error = null;
2539
2540
  let traceError = null;
2540
2541
  let replayError = null;
2542
+ let replayDurationMs = null;
2543
+ let replayStarted = null;
2541
2544
  const originalTraceId = serverItem.originalTraceId ?? serverItem.sourceTraceId;
2542
2545
  const originalSpanId = serverItem.originalSpanId ?? serverItem.sourceSpanId;
2543
2546
  try {
@@ -2560,6 +2563,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2560
2563
  lease = resolved.lease ?? void 0;
2561
2564
  leaseError = resolved.leaseError ?? void 0;
2562
2565
  dbSnapshotRef = resolved.dbSnapshotRef ?? dbSnapshotRef;
2566
+ dbBranchTimings = resolved.timings ?? dbBranchTimings;
2563
2567
  }
2564
2568
  if (leaseError) {
2565
2569
  throw new DbBranchReplayError(
@@ -2593,20 +2597,17 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2593
2597
  includeOutputs,
2594
2598
  includeRootOutput: false
2595
2599
  });
2596
- if (treeResponse.root) {
2597
- mockTree = buildMockTree(treeResponse.root);
2598
- } else if (mockStrategy === "all" || hasOverrides) {
2600
+ if (!treeResponse.root) {
2599
2601
  throw new BitfabError(
2600
2602
  `Replay mock strategy "${mockStrategy}"${hasOverrides ? " with overrides" : ""} requires a span tree root for original span ${originalSpanId}.`
2601
2603
  );
2602
- } else {
2603
- mockTree = void 0;
2604
2604
  }
2605
- } catch (e) {
2606
- if (mockStrategy === "all" || hasOverrides) {
2607
- throw e;
2605
+ mockTree = buildMockTree(treeResponse.root);
2606
+ } catch (error2) {
2607
+ if (mockStrategy !== "marked" || hasOverrides) {
2608
+ throw error2;
2608
2609
  }
2609
- mockTree = void 0;
2610
+ mockTree = { spans: /* @__PURE__ */ new Map() };
2610
2611
  }
2611
2612
  }
2612
2613
  const outputCache = /* @__PURE__ */ new Map();
@@ -2623,6 +2624,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2623
2624
  return pending;
2624
2625
  } : void 0;
2625
2626
  try {
2627
+ replayStarted = performance.now();
2626
2628
  const maybePromise = runWithReplayContext(
2627
2629
  {
2628
2630
  testRunId,
@@ -2635,16 +2637,24 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2635
2637
  mockStrategy,
2636
2638
  mockOverrides: hasOverrides ? resolvedOverrides : void 0,
2637
2639
  fetchSpanOutput,
2638
- dbBranchLease: lease
2640
+ dbBranchLease: lease,
2641
+ dbBranchTimings
2639
2642
  },
2640
2643
  () => fn(...inputs)
2641
2644
  );
2642
2645
  result = maybePromise instanceof Promise ? await maybePromise : maybePromise;
2646
+ replayDurationMs = Math.round(performance.now() - replayStarted);
2643
2647
  } catch (e) {
2648
+ if (replayStarted !== null) {
2649
+ replayDurationMs = Math.round(performance.now() - replayStarted);
2650
+ }
2644
2651
  traceError = e;
2645
2652
  error = errorMessage(e);
2646
2653
  }
2647
2654
  } catch (e) {
2655
+ if (replayStarted !== null) {
2656
+ replayDurationMs = Math.round(performance.now() - replayStarted);
2657
+ }
2648
2658
  replayError = e;
2649
2659
  error = replayItemErrorMessage(e);
2650
2660
  } finally {
@@ -2661,6 +2671,8 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2661
2671
  }
2662
2672
  }
2663
2673
  }
2674
+ const originalDurationMs = serverItem.originalDurationMs ?? serverItem.durationMs ?? null;
2675
+ const originalModel = serverItem.originalModel ?? serverItem.model ?? null;
2664
2676
  return {
2665
2677
  // Written in by replay() from the complete-replay response once the server
2666
2678
  // has minted this replay trace's row. Null until then: the client-side
@@ -2677,13 +2689,17 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2677
2689
  error,
2678
2690
  traceError,
2679
2691
  replayError,
2680
- durationMs: serverItem.durationMs ?? null,
2692
+ durationMs: replayDurationMs,
2693
+ originalDurationMs,
2694
+ originalTokens: serverItem.originalTokens ?? serverItem.tokens ?? null,
2695
+ originalModel,
2681
2696
  // Filled in by replay() from the complete-replay response once the
2682
2697
  // replay traces are persisted and their spans aggregated server-side.
2683
2698
  // Null here (and on older servers) means "replay tokens not known".
2684
2699
  tokens: null,
2685
- model: serverItem.model ?? null,
2686
- dbSnapshotRef: dbSnapshotRef ?? null
2700
+ model: originalModel,
2701
+ dbSnapshotRef: dbSnapshotRef ?? null,
2702
+ dbBranchTimings: dbBranchTimings ?? null
2687
2703
  };
2688
2704
  }
2689
2705
  async function waitForReplayPersistence(httpClient, testRunId, replayedTraceIds) {
@@ -2910,9 +2926,13 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
2910
2926
  traceError: item.traceError,
2911
2927
  replayError: item.replayError,
2912
2928
  durationMs: item.durationMs,
2929
+ originalDurationMs: item.originalDurationMs,
2930
+ originalTokens: item.originalTokens,
2931
+ originalModel: item.originalModel,
2913
2932
  tokens: item.tokens,
2914
2933
  model: item.model,
2915
- dbSnapshotRef: item.dbSnapshotRef
2934
+ dbSnapshotRef: item.dbSnapshotRef,
2935
+ dbBranchTimings: item.dbBranchTimings
2916
2936
  }
2917
2937
  });
2918
2938
  } catch {
@@ -6098,7 +6118,8 @@ var Bitfab = class {
6098
6118
  snapshotTimestamp: replayCtx.dbBranchLease.snapshotTimestamp,
6099
6119
  region: replayCtx.dbBranchLease.region,
6100
6120
  originalTraceId: replayCtx.sourceBitfabTraceId,
6101
- accessed: replayCtx.dbSnapshotAccessed === true
6121
+ accessed: replayCtx.dbSnapshotAccessed === true,
6122
+ timings: replayCtx.dbBranchTimings
6102
6123
  }
6103
6124
  }
6104
6125
  });
@@ -6188,7 +6209,12 @@ var Bitfab = class {
6188
6209
  }
6189
6210
  }
6190
6211
  const shouldMock = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
6191
- if (shouldMock && mockSpan) {
6212
+ if (shouldMock && !mockSpan) {
6213
+ throw new BitfabError(
6214
+ `Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
6215
+ );
6216
+ }
6217
+ if (shouldMock) {
6192
6218
  const recorded = resolveRecordedOutput();
6193
6219
  if (recorded instanceof Promise) {
6194
6220
  return emitMockAsync(recorded, "recorded");
@@ -6425,7 +6451,13 @@ var Bitfab = class {
6425
6451
  // against servers that predate the rename.
6426
6452
  source_trace_id: params.dbSnapshotUsage.originalTraceId
6427
6453
  },
6428
- accessed: params.dbSnapshotUsage.accessed
6454
+ accessed: params.dbSnapshotUsage.accessed,
6455
+ // Echoed verbatim (camelCase inside) rather than re-cased into this
6456
+ // record's snake_case: it is the server's own object coming back, and
6457
+ // a translation layer here is one more thing to drift.
6458
+ ...params.dbSnapshotUsage.timings && {
6459
+ timings: params.dbSnapshotUsage.timings
6460
+ }
6429
6461
  };
6430
6462
  }
6431
6463
  this.httpClient.sendExternalTrace({