@bitfab/sdk 0.33.0 → 0.33.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
@@ -1963,7 +1963,7 @@ declare class BitfabFunction {
1963
1963
  /**
1964
1964
  * SDK version from package.json (injected at build time)
1965
1965
  */
1966
- declare const __version__ = "0.33.0";
1966
+ declare const __version__ = "0.33.2";
1967
1967
 
1968
1968
  /**
1969
1969
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -1963,7 +1963,7 @@ declare class BitfabFunction {
1963
1963
  /**
1964
1964
  * SDK version from package.json (injected at build time)
1965
1965
  */
1966
- declare const __version__ = "0.33.0";
1966
+ declare const __version__ = "0.33.2";
1967
1967
 
1968
1968
  /**
1969
1969
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -14,12 +14,12 @@ import {
14
14
  getCurrentReplayBranch,
15
15
  getCurrentSpan,
16
16
  getCurrentTrace
17
- } from "./chunk-HPLLGCTO.js";
17
+ } from "./chunk-A3WLV5VS.js";
18
18
  import {
19
19
  BITFAB_PROGRESS_PREFIX,
20
20
  BitfabError,
21
21
  reportReplayProgress
22
- } from "./chunk-ADUWXWWI.js";
22
+ } from "./chunk-GT2GSQM2.js";
23
23
  export {
24
24
  BITFAB_PROGRESS_PREFIX,
25
25
  Bitfab,
package/dist/node.cjs CHANGED
@@ -322,14 +322,25 @@ function runWithReplayContext(ctx, fn) {
322
322
  }
323
323
  return fn();
324
324
  }
325
- var replayContextStorage, replayContextReady;
325
+ var replayContextStorage, REPLAY_CONTEXT_STORAGE_SYMBOL, replayContextReady;
326
326
  var init_replayContext = __esm({
327
327
  "src/replayContext.ts"() {
328
328
  "use strict";
329
329
  init_asyncStorage();
330
330
  replayContextStorage = null;
331
+ REPLAY_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.replayContextStorage");
331
332
  replayContextReady = asyncStorageReady.then(() => {
332
- replayContextStorage = createAsyncLocalStorage();
333
+ const shared = globalThis;
334
+ const existing = shared[REPLAY_CONTEXT_STORAGE_SYMBOL];
335
+ if (existing) {
336
+ replayContextStorage = existing;
337
+ return;
338
+ }
339
+ const created = createAsyncLocalStorage();
340
+ if (created) {
341
+ shared[REPLAY_CONTEXT_STORAGE_SYMBOL] = created;
342
+ replayContextStorage = created;
343
+ }
333
344
  });
334
345
  }
335
346
  });
@@ -610,9 +621,10 @@ function buildMockTree(rootNode) {
610
621
  }
611
622
  return { spans };
612
623
  }
613
- async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, includeDbBranchLease, adaptInputs) {
614
- const lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
615
- const leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
624
+ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, includeDbBranchLease, dbBranchSettings, adaptInputs) {
625
+ let lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
626
+ let leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
627
+ let dbSnapshotRef = serverItem.dbSnapshotRef;
616
628
  let inputs = [];
617
629
  let originalOutput;
618
630
  let result;
@@ -621,6 +633,16 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
621
633
  const originalTraceId = serverItem.originalTraceId ?? serverItem.sourceTraceId;
622
634
  const originalSpanId = serverItem.originalSpanId ?? serverItem.sourceSpanId;
623
635
  try {
636
+ if (includeDbBranchLease && !lease && !leaseError) {
637
+ const resolved = await httpClient.resolveDbBranchLease(
638
+ testRunId,
639
+ originalTraceId,
640
+ dbBranchSettings
641
+ );
642
+ lease = resolved.lease ?? void 0;
643
+ leaseError = resolved.leaseError ?? void 0;
644
+ dbSnapshotRef = resolved.dbSnapshotRef ?? dbSnapshotRef;
645
+ }
624
646
  if (leaseError) {
625
647
  throw new BitfabError(
626
648
  `Replay requested a database branch for trace ${originalTraceId} but it could not be resolved (${leaseError.code}): ${leaseError.message}. The function was not run, because replaying it against the live database would produce a result that looks valid but did not use the historical data you asked for.`
@@ -732,7 +754,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
732
754
  // Null here (and on older servers) means "replay tokens not known".
733
755
  tokens: null,
734
756
  model: serverItem.model ?? null,
735
- dbSnapshotRef: serverItem.dbSnapshotRef ?? null
757
+ dbSnapshotRef: dbSnapshotRef ?? null
736
758
  };
737
759
  }
738
760
  async function mapWithConcurrency(tasks, maxConcurrency, onSettled) {
@@ -819,6 +841,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
819
841
  resolvedOverrides,
820
842
  replayedTraceIds[index],
821
843
  options?.dbBranch !== void 0,
844
+ resolveDbBranchSettings(options?.dbBranch),
822
845
  options?.adaptInputs
823
846
  )
824
847
  );
@@ -994,7 +1017,7 @@ registerAsyncLocalStorageClass(
994
1017
  );
995
1018
 
996
1019
  // src/version.generated.ts
997
- var __version__ = "0.33.0";
1020
+ var __version__ = "0.33.2";
998
1021
 
999
1022
  // src/constants.ts
1000
1023
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1012,6 +1035,7 @@ function unrefTimer(timer) {
1012
1035
 
1013
1036
  // src/http.ts
1014
1037
  init_warnOnce();
1038
+ var REPLAY_DB_BRANCH_REQUEST_TIMEOUT_MS = 3e5;
1015
1039
  function serializePayloadBody(payload) {
1016
1040
  try {
1017
1041
  return { body: JSON.stringify(payload), dropped: [] };
@@ -1372,6 +1396,7 @@ var HttpClient = class {
1372
1396
  }
1373
1397
  if (includeDbBranchLease) {
1374
1398
  payload.includeDbBranchLease = true;
1399
+ payload.lazyDbBranchLease = true;
1375
1400
  }
1376
1401
  if (experimentGroupId !== void 0) {
1377
1402
  payload.experimentGroupId = experimentGroupId;
@@ -1385,7 +1410,7 @@ var HttpClient = class {
1385
1410
  if (dbBranchSettings !== void 0) {
1386
1411
  payload.dbBranchSettings = dbBranchSettings;
1387
1412
  }
1388
- const timeout = includeDbBranchLease ? 18e4 : 3e4;
1413
+ const timeout = includeDbBranchLease ? REPLAY_DB_BRANCH_REQUEST_TIMEOUT_MS : 3e4;
1389
1414
  return this.request("/api/sdk/replay/start", payload, {
1390
1415
  timeout
1391
1416
  });
@@ -1484,11 +1509,11 @@ var HttpClient = class {
1484
1509
  * snapshot + preview branch and polls operations to readiness, which
1485
1510
  * can take seconds.
1486
1511
  */
1487
- async resolveDbBranchLease(testRunId, traceId, dbSnapshotRef) {
1512
+ async resolveDbBranchLease(testRunId, traceId, dbBranchSettings) {
1488
1513
  return this.request(
1489
1514
  "/api/sdk/replay/resolveDbBranchLease",
1490
- { testRunId, traceId, dbSnapshotRef },
1491
- { timeout: 9e4 }
1515
+ { testRunId, traceId, dbBranchSettings },
1516
+ { timeout: REPLAY_DB_BRANCH_REQUEST_TIMEOUT_MS }
1492
1517
  );
1493
1518
  }
1494
1519
  /** Release a previously-resolved DB branch by deleting its Neon branch. Idempotent server-side. */
@@ -3485,8 +3510,22 @@ init_warnOnce();
3485
3510
  var activeTraceStates = /* @__PURE__ */ new Map();
3486
3511
  var pendingSpanPromises = /* @__PURE__ */ new Map();
3487
3512
  var asyncLocalStorage = null;
3513
+ var SPAN_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.spanContextStorage");
3488
3514
  var initializeAsyncContext = () => {
3489
- asyncLocalStorage ?? (asyncLocalStorage = createAsyncLocalStorage());
3515
+ if (asyncLocalStorage) {
3516
+ return;
3517
+ }
3518
+ const shared = globalThis;
3519
+ const existing = shared[SPAN_CONTEXT_STORAGE_SYMBOL];
3520
+ if (existing) {
3521
+ asyncLocalStorage = existing;
3522
+ return;
3523
+ }
3524
+ const created = createAsyncLocalStorage();
3525
+ if (created) {
3526
+ shared[SPAN_CONTEXT_STORAGE_SYMBOL] = created;
3527
+ asyncLocalStorage = created;
3528
+ }
3490
3529
  };
3491
3530
  var asyncLocalStorageReady = asyncStorageReady.then(() => {
3492
3531
  initializeAsyncContext();