@bitfab/sdk 0.33.1 → 0.33.3

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
@@ -794,15 +794,20 @@ interface ReplayOptions {
794
794
  /**
795
795
  * Description of the code change being tested in this replay. Stored on
796
796
  * the resulting experiment so the change can be reviewed alongside results.
797
+ * Supplying a description without `codeChangeFiles` preserves this text
798
+ * while the SDK automatically captures the files.
799
+ * Pass `null` when the replay should have no description; use
800
+ * `codeChangeFiles: null` to suppress automatic file capture.
797
801
  */
798
- codeChangeDescription?: string;
802
+ codeChangeDescription?: string | null;
799
803
  /**
800
804
  * Files edited as part of this code change. Each entry holds the file path
801
805
  * and the full `before`/`after` contents. The agent reads each file before
802
806
  * and after editing and passes the two strings. Use `""` for newly created
803
- * files (`before`) or deleted files (`after`).
807
+ * files (`before`) or deleted files (`after`). Omit this field to capture
808
+ * automatically, or pass `null` to suppress file capture for this replay.
804
809
  */
805
- codeChangeFiles?: CodeChangeFile[];
810
+ codeChangeFiles?: CodeChangeFile[] | null;
806
811
  /**
807
812
  * Mock strategy for child spans during replay.
808
813
  * - "marked": only spans tagged with { mockOnReplay: true } in SpanOptions are mocked (default)
@@ -1963,7 +1968,7 @@ declare class BitfabFunction {
1963
1968
  /**
1964
1969
  * SDK version from package.json (injected at build time)
1965
1970
  */
1966
- declare const __version__ = "0.33.1";
1971
+ declare const __version__ = "0.33.3";
1967
1972
 
1968
1973
  /**
1969
1974
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -794,15 +794,20 @@ interface ReplayOptions {
794
794
  /**
795
795
  * Description of the code change being tested in this replay. Stored on
796
796
  * the resulting experiment so the change can be reviewed alongside results.
797
+ * Supplying a description without `codeChangeFiles` preserves this text
798
+ * while the SDK automatically captures the files.
799
+ * Pass `null` when the replay should have no description; use
800
+ * `codeChangeFiles: null` to suppress automatic file capture.
797
801
  */
798
- codeChangeDescription?: string;
802
+ codeChangeDescription?: string | null;
799
803
  /**
800
804
  * Files edited as part of this code change. Each entry holds the file path
801
805
  * and the full `before`/`after` contents. The agent reads each file before
802
806
  * and after editing and passes the two strings. Use `""` for newly created
803
- * files (`before`) or deleted files (`after`).
807
+ * files (`before`) or deleted files (`after`). Omit this field to capture
808
+ * automatically, or pass `null` to suppress file capture for this replay.
804
809
  */
805
- codeChangeFiles?: CodeChangeFile[];
810
+ codeChangeFiles?: CodeChangeFile[] | null;
806
811
  /**
807
812
  * Mock strategy for child spans during replay.
808
813
  * - "marked": only spans tagged with { mockOnReplay: true } in SpanOptions are mocked (default)
@@ -1963,7 +1968,7 @@ declare class BitfabFunction {
1963
1968
  /**
1964
1969
  * SDK version from package.json (injected at build time)
1965
1970
  */
1966
- declare const __version__ = "0.33.1";
1971
+ declare const __version__ = "0.33.3";
1967
1972
 
1968
1973
  /**
1969
1974
  * 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-7UHJ67MH.js";
17
+ } from "./chunk-NIFTE3J4.js";
18
18
  import {
19
19
  BITFAB_PROGRESS_PREFIX,
20
20
  BitfabError,
21
21
  reportReplayProgress
22
- } from "./chunk-ADUWXWWI.js";
22
+ } from "./chunk-HWQB73HK.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) {
@@ -775,11 +797,13 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
775
797
  await replayContextReady;
776
798
  let codeChangeDescription = options?.codeChangeDescription;
777
799
  let codeChangeFiles = options?.codeChangeFiles;
778
- if (codeChangeDescription === void 0 && codeChangeFiles === void 0) {
800
+ if (codeChangeFiles === void 0) {
779
801
  const captured = await resolveAutoCodeChange(options?.name);
780
802
  if (captured) {
781
- codeChangeDescription = captured.description;
782
803
  codeChangeFiles = captured.files;
804
+ if (codeChangeDescription === void 0) {
805
+ codeChangeDescription = captured.description;
806
+ }
783
807
  }
784
808
  }
785
809
  const {
@@ -819,6 +843,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
819
843
  resolvedOverrides,
820
844
  replayedTraceIds[index],
821
845
  options?.dbBranch !== void 0,
846
+ resolveDbBranchSettings(options?.dbBranch),
822
847
  options?.adaptInputs
823
848
  )
824
849
  );
@@ -994,7 +1019,7 @@ registerAsyncLocalStorageClass(
994
1019
  );
995
1020
 
996
1021
  // src/version.generated.ts
997
- var __version__ = "0.33.1";
1022
+ var __version__ = "0.33.3";
998
1023
 
999
1024
  // src/constants.ts
1000
1025
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1012,6 +1037,7 @@ function unrefTimer(timer) {
1012
1037
 
1013
1038
  // src/http.ts
1014
1039
  init_warnOnce();
1040
+ var REPLAY_DB_BRANCH_REQUEST_TIMEOUT_MS = 3e5;
1015
1041
  function serializePayloadBody(payload) {
1016
1042
  try {
1017
1043
  return { body: JSON.stringify(payload), dropped: [] };
@@ -1372,6 +1398,7 @@ var HttpClient = class {
1372
1398
  }
1373
1399
  if (includeDbBranchLease) {
1374
1400
  payload.includeDbBranchLease = true;
1401
+ payload.lazyDbBranchLease = true;
1375
1402
  }
1376
1403
  if (experimentGroupId !== void 0) {
1377
1404
  payload.experimentGroupId = experimentGroupId;
@@ -1385,7 +1412,7 @@ var HttpClient = class {
1385
1412
  if (dbBranchSettings !== void 0) {
1386
1413
  payload.dbBranchSettings = dbBranchSettings;
1387
1414
  }
1388
- const timeout = includeDbBranchLease ? 3e5 : 3e4;
1415
+ const timeout = includeDbBranchLease ? REPLAY_DB_BRANCH_REQUEST_TIMEOUT_MS : 3e4;
1389
1416
  return this.request("/api/sdk/replay/start", payload, {
1390
1417
  timeout
1391
1418
  });
@@ -1484,11 +1511,11 @@ var HttpClient = class {
1484
1511
  * snapshot + preview branch and polls operations to readiness, which
1485
1512
  * can take seconds.
1486
1513
  */
1487
- async resolveDbBranchLease(testRunId, traceId, dbSnapshotRef) {
1514
+ async resolveDbBranchLease(testRunId, traceId, dbBranchSettings) {
1488
1515
  return this.request(
1489
1516
  "/api/sdk/replay/resolveDbBranchLease",
1490
- { testRunId, traceId, dbSnapshotRef },
1491
- { timeout: 9e4 }
1517
+ { testRunId, traceId, dbBranchSettings },
1518
+ { timeout: REPLAY_DB_BRANCH_REQUEST_TIMEOUT_MS }
1492
1519
  );
1493
1520
  }
1494
1521
  /** Release a previously-resolved DB branch by deleting its Neon branch. Idempotent server-side. */
@@ -3485,8 +3512,22 @@ init_warnOnce();
3485
3512
  var activeTraceStates = /* @__PURE__ */ new Map();
3486
3513
  var pendingSpanPromises = /* @__PURE__ */ new Map();
3487
3514
  var asyncLocalStorage = null;
3515
+ var SPAN_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.spanContextStorage");
3488
3516
  var initializeAsyncContext = () => {
3489
- asyncLocalStorage ?? (asyncLocalStorage = createAsyncLocalStorage());
3517
+ if (asyncLocalStorage) {
3518
+ return;
3519
+ }
3520
+ const shared = globalThis;
3521
+ const existing = shared[SPAN_CONTEXT_STORAGE_SYMBOL];
3522
+ if (existing) {
3523
+ asyncLocalStorage = existing;
3524
+ return;
3525
+ }
3526
+ const created = createAsyncLocalStorage();
3527
+ if (created) {
3528
+ shared[SPAN_CONTEXT_STORAGE_SYMBOL] = created;
3529
+ asyncLocalStorage = created;
3530
+ }
3490
3531
  };
3491
3532
  var asyncLocalStorageReady = asyncStorageReady.then(() => {
3492
3533
  initializeAsyncContext();