bitfab 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
@@ -23,12 +23,12 @@ import {
23
23
  getCurrentReplayBranch,
24
24
  getCurrentSpan,
25
25
  getCurrentTrace
26
- } from "./chunk-7UHJ67MH.js";
26
+ } from "./chunk-NIFTE3J4.js";
27
27
  import {
28
28
  BITFAB_PROGRESS_PREFIX,
29
29
  BitfabError,
30
30
  reportReplayProgress
31
- } from "./chunk-ADUWXWWI.js";
31
+ } from "./chunk-HWQB73HK.js";
32
32
  export {
33
33
  BITFAB_PROGRESS_PREFIX,
34
34
  Bitfab,
package/dist/node.cjs CHANGED
@@ -331,14 +331,25 @@ function runWithReplayContext(ctx, fn) {
331
331
  }
332
332
  return fn();
333
333
  }
334
- var replayContextStorage, replayContextReady;
334
+ var replayContextStorage, REPLAY_CONTEXT_STORAGE_SYMBOL, replayContextReady;
335
335
  var init_replayContext = __esm({
336
336
  "src/replayContext.ts"() {
337
337
  "use strict";
338
338
  init_asyncStorage();
339
339
  replayContextStorage = null;
340
+ REPLAY_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.replayContextStorage");
340
341
  replayContextReady = asyncStorageReady.then(() => {
341
- replayContextStorage = createAsyncLocalStorage();
342
+ const shared = globalThis;
343
+ const existing = shared[REPLAY_CONTEXT_STORAGE_SYMBOL];
344
+ if (existing) {
345
+ replayContextStorage = existing;
346
+ return;
347
+ }
348
+ const created = createAsyncLocalStorage();
349
+ if (created) {
350
+ shared[REPLAY_CONTEXT_STORAGE_SYMBOL] = created;
351
+ replayContextStorage = created;
352
+ }
342
353
  });
343
354
  }
344
355
  });
@@ -619,9 +630,10 @@ function buildMockTree(rootNode) {
619
630
  }
620
631
  return { spans };
621
632
  }
622
- async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, includeDbBranchLease, adaptInputs) {
623
- const lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
624
- const leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
633
+ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, includeDbBranchLease, dbBranchSettings, adaptInputs) {
634
+ let lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
635
+ let leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
636
+ let dbSnapshotRef = serverItem.dbSnapshotRef;
625
637
  let inputs = [];
626
638
  let originalOutput;
627
639
  let result;
@@ -630,6 +642,16 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
630
642
  const originalTraceId = serverItem.originalTraceId ?? serverItem.sourceTraceId;
631
643
  const originalSpanId = serverItem.originalSpanId ?? serverItem.sourceSpanId;
632
644
  try {
645
+ if (includeDbBranchLease && !lease && !leaseError) {
646
+ const resolved = await httpClient.resolveDbBranchLease(
647
+ testRunId,
648
+ originalTraceId,
649
+ dbBranchSettings
650
+ );
651
+ lease = resolved.lease ?? void 0;
652
+ leaseError = resolved.leaseError ?? void 0;
653
+ dbSnapshotRef = resolved.dbSnapshotRef ?? dbSnapshotRef;
654
+ }
633
655
  if (leaseError) {
634
656
  throw new BitfabError(
635
657
  `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.`
@@ -741,7 +763,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
741
763
  // Null here (and on older servers) means "replay tokens not known".
742
764
  tokens: null,
743
765
  model: serverItem.model ?? null,
744
- dbSnapshotRef: serverItem.dbSnapshotRef ?? null
766
+ dbSnapshotRef: dbSnapshotRef ?? null
745
767
  };
746
768
  }
747
769
  async function mapWithConcurrency(tasks, maxConcurrency, onSettled) {
@@ -784,11 +806,13 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
784
806
  await replayContextReady;
785
807
  let codeChangeDescription = options?.codeChangeDescription;
786
808
  let codeChangeFiles = options?.codeChangeFiles;
787
- if (codeChangeDescription === void 0 && codeChangeFiles === void 0) {
809
+ if (codeChangeFiles === void 0) {
788
810
  const captured = await resolveAutoCodeChange(options?.name);
789
811
  if (captured) {
790
- codeChangeDescription = captured.description;
791
812
  codeChangeFiles = captured.files;
813
+ if (codeChangeDescription === void 0) {
814
+ codeChangeDescription = captured.description;
815
+ }
792
816
  }
793
817
  }
794
818
  const {
@@ -828,6 +852,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
828
852
  resolvedOverrides,
829
853
  replayedTraceIds[index],
830
854
  options?.dbBranch !== void 0,
855
+ resolveDbBranchSettings(options?.dbBranch),
831
856
  options?.adaptInputs
832
857
  )
833
858
  );
@@ -1003,7 +1028,7 @@ registerAsyncLocalStorageClass(
1003
1028
  );
1004
1029
 
1005
1030
  // src/version.generated.ts
1006
- var __version__ = "0.33.1";
1031
+ var __version__ = "0.33.3";
1007
1032
 
1008
1033
  // src/constants.ts
1009
1034
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1021,6 +1046,7 @@ function unrefTimer(timer) {
1021
1046
 
1022
1047
  // src/http.ts
1023
1048
  init_warnOnce();
1049
+ var REPLAY_DB_BRANCH_REQUEST_TIMEOUT_MS = 3e5;
1024
1050
  function serializePayloadBody(payload) {
1025
1051
  try {
1026
1052
  return { body: JSON.stringify(payload), dropped: [] };
@@ -1381,6 +1407,7 @@ var HttpClient = class {
1381
1407
  }
1382
1408
  if (includeDbBranchLease) {
1383
1409
  payload.includeDbBranchLease = true;
1410
+ payload.lazyDbBranchLease = true;
1384
1411
  }
1385
1412
  if (experimentGroupId !== void 0) {
1386
1413
  payload.experimentGroupId = experimentGroupId;
@@ -1394,7 +1421,7 @@ var HttpClient = class {
1394
1421
  if (dbBranchSettings !== void 0) {
1395
1422
  payload.dbBranchSettings = dbBranchSettings;
1396
1423
  }
1397
- const timeout = includeDbBranchLease ? 3e5 : 3e4;
1424
+ const timeout = includeDbBranchLease ? REPLAY_DB_BRANCH_REQUEST_TIMEOUT_MS : 3e4;
1398
1425
  return this.request("/api/sdk/replay/start", payload, {
1399
1426
  timeout
1400
1427
  });
@@ -1493,11 +1520,11 @@ var HttpClient = class {
1493
1520
  * snapshot + preview branch and polls operations to readiness, which
1494
1521
  * can take seconds.
1495
1522
  */
1496
- async resolveDbBranchLease(testRunId, traceId, dbSnapshotRef) {
1523
+ async resolveDbBranchLease(testRunId, traceId, dbBranchSettings) {
1497
1524
  return this.request(
1498
1525
  "/api/sdk/replay/resolveDbBranchLease",
1499
- { testRunId, traceId, dbSnapshotRef },
1500
- { timeout: 9e4 }
1526
+ { testRunId, traceId, dbBranchSettings },
1527
+ { timeout: REPLAY_DB_BRANCH_REQUEST_TIMEOUT_MS }
1501
1528
  );
1502
1529
  }
1503
1530
  /** Release a previously-resolved DB branch by deleting its Neon branch. Idempotent server-side. */
@@ -3494,8 +3521,22 @@ init_warnOnce();
3494
3521
  var activeTraceStates = /* @__PURE__ */ new Map();
3495
3522
  var pendingSpanPromises = /* @__PURE__ */ new Map();
3496
3523
  var asyncLocalStorage = null;
3524
+ var SPAN_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.spanContextStorage");
3497
3525
  var initializeAsyncContext = () => {
3498
- asyncLocalStorage ?? (asyncLocalStorage = createAsyncLocalStorage());
3526
+ if (asyncLocalStorage) {
3527
+ return;
3528
+ }
3529
+ const shared = globalThis;
3530
+ const existing = shared[SPAN_CONTEXT_STORAGE_SYMBOL];
3531
+ if (existing) {
3532
+ asyncLocalStorage = existing;
3533
+ return;
3534
+ }
3535
+ const created = createAsyncLocalStorage();
3536
+ if (created) {
3537
+ shared[SPAN_CONTEXT_STORAGE_SYMBOL] = created;
3538
+ asyncLocalStorage = created;
3539
+ }
3499
3540
  };
3500
3541
  var asyncLocalStorageReady = asyncStorageReady.then(() => {
3501
3542
  initializeAsyncContext();