@bitfab/sdk 0.30.2 → 0.31.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.d.cts CHANGED
@@ -646,6 +646,7 @@ interface ReplayEnvironmentSnapshot {
646
646
  expiresAt: string;
647
647
  providerConsoleUrl?: string;
648
648
  readOnly?: boolean;
649
+ region?: string;
649
650
  traceId: string;
650
651
  }
651
652
  declare class ReplayEnvironment {
@@ -664,6 +665,11 @@ declare class ReplayEnvironment {
664
665
  * lease.
665
666
  */
666
667
  get readOnly(): boolean | undefined;
668
+ /**
669
+ * The branch's region, e.g. `aws-us-east-1`. A compute runs in its project's
670
+ * region, so a replay runner elsewhere pays that round trip on every query.
671
+ */
672
+ get region(): string | undefined;
667
673
  /** The historical trace ID that produced the input for this replay item. */
668
674
  get traceId(): string;
669
675
  /** True when read inside a replay item that has a resolved branch. */
@@ -692,6 +698,33 @@ declare class ReplayEnvironment {
692
698
  */
693
699
 
694
700
  type MockStrategy = "none" | "all" | "marked";
701
+ /**
702
+ * Per-lease settings for the DB-snapshot branch a replay item runs against.
703
+ * Only read when `environment` is set, since that is what turns branching on.
704
+ */
705
+ interface DbBranchOptions {
706
+ /**
707
+ * Autoscaling floor for the branch's compute, in Neon Compute Units (0.25 to
708
+ * 56). Omit to keep the mirror project's own default. Raise it when the
709
+ * mirror is provisioned smaller than the database it stands in for, so
710
+ * replay latency reflects your code rather than a cold, undersized branch.
711
+ */
712
+ minCu?: number;
713
+ /**
714
+ * Autoscaling ceiling for the branch's compute, in Neon Compute Units.
715
+ * Setting it equal to `minCu` pins the size, which keeps items comparable:
716
+ * otherwise a later item can run against an endpoint that has already
717
+ * scaled up and post a better number for the same code.
718
+ */
719
+ maxCu?: number;
720
+ /**
721
+ * SQL that warms the branch's cache. The server appends it to the branch's
722
+ * readiness check, so it runs BEFORE your function sees the lease and its
723
+ * time is not charged to the replayed call. Invalid SQL fails the lease
724
+ * rather than silently leaving the branch cold.
725
+ */
726
+ warmupSql?: string;
727
+ }
695
728
  interface ReplayOptions {
696
729
  /**
697
730
  * Maximum number of traces to replay (1-100, default 5). Ignored when
@@ -740,6 +773,8 @@ interface ReplayOptions {
740
773
  * environment to pick up the per-trace branch URL.
741
774
  */
742
775
  environment?: ReplayEnvironment;
776
+ /** Compute size and cache warm-up for the per-item DB snapshot branch. */
777
+ dbBranch?: DbBranchOptions;
743
778
  /** Group ID to associate this replay with an experiment group for live streaming in Studio. */
744
779
  experimentGroupId?: string;
745
780
  /**
@@ -1808,7 +1843,7 @@ declare class BitfabFunction {
1808
1843
  /**
1809
1844
  * SDK version from package.json (injected at build time)
1810
1845
  */
1811
- declare const __version__ = "0.30.2";
1846
+ declare const __version__ = "0.31.0";
1812
1847
 
1813
1848
  /**
1814
1849
  * Constants for the Bitfab SDK.
@@ -1876,4 +1911,4 @@ declare const finalizers: {
1876
1911
  readableStream: typeof readableStream;
1877
1912
  };
1878
1913
 
1879
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace, reportReplayProgress };
1914
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace, reportReplayProgress };
package/dist/index.d.ts CHANGED
@@ -646,6 +646,7 @@ interface ReplayEnvironmentSnapshot {
646
646
  expiresAt: string;
647
647
  providerConsoleUrl?: string;
648
648
  readOnly?: boolean;
649
+ region?: string;
649
650
  traceId: string;
650
651
  }
651
652
  declare class ReplayEnvironment {
@@ -664,6 +665,11 @@ declare class ReplayEnvironment {
664
665
  * lease.
665
666
  */
666
667
  get readOnly(): boolean | undefined;
668
+ /**
669
+ * The branch's region, e.g. `aws-us-east-1`. A compute runs in its project's
670
+ * region, so a replay runner elsewhere pays that round trip on every query.
671
+ */
672
+ get region(): string | undefined;
667
673
  /** The historical trace ID that produced the input for this replay item. */
668
674
  get traceId(): string;
669
675
  /** True when read inside a replay item that has a resolved branch. */
@@ -692,6 +698,33 @@ declare class ReplayEnvironment {
692
698
  */
693
699
 
694
700
  type MockStrategy = "none" | "all" | "marked";
701
+ /**
702
+ * Per-lease settings for the DB-snapshot branch a replay item runs against.
703
+ * Only read when `environment` is set, since that is what turns branching on.
704
+ */
705
+ interface DbBranchOptions {
706
+ /**
707
+ * Autoscaling floor for the branch's compute, in Neon Compute Units (0.25 to
708
+ * 56). Omit to keep the mirror project's own default. Raise it when the
709
+ * mirror is provisioned smaller than the database it stands in for, so
710
+ * replay latency reflects your code rather than a cold, undersized branch.
711
+ */
712
+ minCu?: number;
713
+ /**
714
+ * Autoscaling ceiling for the branch's compute, in Neon Compute Units.
715
+ * Setting it equal to `minCu` pins the size, which keeps items comparable:
716
+ * otherwise a later item can run against an endpoint that has already
717
+ * scaled up and post a better number for the same code.
718
+ */
719
+ maxCu?: number;
720
+ /**
721
+ * SQL that warms the branch's cache. The server appends it to the branch's
722
+ * readiness check, so it runs BEFORE your function sees the lease and its
723
+ * time is not charged to the replayed call. Invalid SQL fails the lease
724
+ * rather than silently leaving the branch cold.
725
+ */
726
+ warmupSql?: string;
727
+ }
695
728
  interface ReplayOptions {
696
729
  /**
697
730
  * Maximum number of traces to replay (1-100, default 5). Ignored when
@@ -740,6 +773,8 @@ interface ReplayOptions {
740
773
  * environment to pick up the per-trace branch URL.
741
774
  */
742
775
  environment?: ReplayEnvironment;
776
+ /** Compute size and cache warm-up for the per-item DB snapshot branch. */
777
+ dbBranch?: DbBranchOptions;
743
778
  /** Group ID to associate this replay with an experiment group for live streaming in Studio. */
744
779
  experimentGroupId?: string;
745
780
  /**
@@ -1808,7 +1843,7 @@ declare class BitfabFunction {
1808
1843
  /**
1809
1844
  * SDK version from package.json (injected at build time)
1810
1845
  */
1811
- declare const __version__ = "0.30.2";
1846
+ declare const __version__ = "0.31.0";
1812
1847
 
1813
1848
  /**
1814
1849
  * Constants for the Bitfab SDK.
@@ -1876,4 +1911,4 @@ declare const finalizers: {
1876
1911
  readableStream: typeof readableStream;
1877
1912
  };
1878
1913
 
1879
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace, reportReplayProgress };
1914
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace, reportReplayProgress };
package/dist/index.js CHANGED
@@ -14,12 +14,12 @@ import {
14
14
  flushTraces,
15
15
  getCurrentSpan,
16
16
  getCurrentTrace
17
- } from "./chunk-CPEQSNVE.js";
17
+ } from "./chunk-A7K5JOBV.js";
18
18
  import {
19
19
  BITFAB_PROGRESS_PREFIX,
20
20
  BitfabError,
21
21
  reportReplayProgress
22
- } from "./chunk-FLVQ7Q3I.js";
22
+ } from "./chunk-6UJ3E3H5.js";
23
23
  export {
24
24
  BITFAB_PROGRESS_PREFIX,
25
25
  Bitfab,
package/dist/node.cjs CHANGED
@@ -531,6 +531,17 @@ __export(replay_exports, {
531
531
  replay: () => replay,
532
532
  reportReplayProgress: () => reportReplayProgress
533
533
  });
534
+ function resolveDbBranchSettings(dbBranch) {
535
+ if (!dbBranch) {
536
+ return void 0;
537
+ }
538
+ const settings = {
539
+ ...dbBranch.minCu === void 0 ? {} : { minCu: dbBranch.minCu },
540
+ ...dbBranch.maxCu === void 0 ? {} : { maxCu: dbBranch.maxCu },
541
+ ...dbBranch.warmupSql === void 0 ? {} : { warmupSql: dbBranch.warmupSql }
542
+ };
543
+ return Object.keys(settings).length === 0 ? void 0 : settings;
544
+ }
534
545
  function reportReplayProgress(progress) {
535
546
  const stderr = typeof process !== "undefined" ? process.stderr : void 0;
536
547
  if (!stderr) {
@@ -593,6 +604,7 @@ function buildMockTree(rootNode) {
593
604
  }
594
605
  async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, environment, adaptInputs) {
595
606
  const lease = environment ? serverItem.dbBranchLease : void 0;
607
+ const leaseError = environment ? serverItem.dbBranchLeaseError : void 0;
596
608
  let inputs = [];
597
609
  let originalOutput;
598
610
  let result;
@@ -601,6 +613,11 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
601
613
  const originalTraceId = serverItem.originalTraceId ?? serverItem.sourceTraceId;
602
614
  const originalSpanId = serverItem.originalSpanId ?? serverItem.sourceSpanId;
603
615
  try {
616
+ if (leaseError) {
617
+ throw new BitfabError(
618
+ `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.`
619
+ );
620
+ }
604
621
  const span = await httpClient.getExternalSpan(originalSpanId);
605
622
  const spanData = span.rawData?.span_data ?? {};
606
623
  inputs = deserializeInputs(spanData);
@@ -774,7 +791,8 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
774
791
  // includeDbBranchLease
775
792
  options?.experimentGroupId,
776
793
  options?.datasetId,
777
- options?.graderIds
794
+ options?.graderIds,
795
+ resolveDbBranchSettings(options?.dbBranch)
778
796
  );
779
797
  const mockStrategy = options?.mock ?? "marked";
780
798
  const maxConcurrency = options?.maxConcurrency ?? 10;
@@ -968,7 +986,7 @@ registerAsyncLocalStorageClass(
968
986
  );
969
987
 
970
988
  // src/version.generated.ts
971
- var __version__ = "0.30.2";
989
+ var __version__ = "0.31.0";
972
990
 
973
991
  // src/constants.ts
974
992
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1327,7 +1345,7 @@ var HttpClient = class {
1327
1345
  * Start a replay session by fetching historical traces.
1328
1346
  * Blocking call - creates a test run and returns lightweight item references.
1329
1347
  */
1330
- async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId, graderIds) {
1348
+ async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId, graderIds, dbBranchSettings) {
1331
1349
  const payload = { traceFunctionKey };
1332
1350
  if (limit !== void 0) {
1333
1351
  payload.limit = limit;
@@ -1356,6 +1374,9 @@ var HttpClient = class {
1356
1374
  if (graderIds !== void 0) {
1357
1375
  payload.graderIds = graderIds;
1358
1376
  }
1377
+ if (dbBranchSettings !== void 0) {
1378
+ payload.dbBranchSettings = dbBranchSettings;
1379
+ }
1359
1380
  const timeout = includeDbBranchLease ? 18e4 : 3e4;
1360
1381
  return this.request("/api/sdk/replay/start", payload, {
1361
1382
  timeout
@@ -3086,6 +3107,13 @@ var ReplayEnvironment = class {
3086
3107
  get readOnly() {
3087
3108
  return this.require().readOnly;
3088
3109
  }
3110
+ /**
3111
+ * The branch's region, e.g. `aws-us-east-1`. A compute runs in its project's
3112
+ * region, so a replay runner elsewhere pays that round trip on every query.
3113
+ */
3114
+ get region() {
3115
+ return this.require().region;
3116
+ }
3089
3117
  /** The historical trace ID that produced the input for this replay item. */
3090
3118
  get traceId() {
3091
3119
  return this.require().traceId;
@@ -3130,6 +3158,7 @@ var ReplayEnvironment = class {
3130
3158
  expiresAt: lease.expiresAt,
3131
3159
  providerConsoleUrl: lease.providerConsoleUrl,
3132
3160
  readOnly: lease.readOnly,
3161
+ region: lease.region,
3133
3162
  traceId
3134
3163
  };
3135
3164
  }