bitfab 0.31.1 → 0.33.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.cjs CHANGED
@@ -14,6 +14,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
14
14
  var __getOwnPropNames = Object.getOwnPropertyNames;
15
15
  var __getProtoOf = Object.getPrototypeOf;
16
16
  var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __typeError = (msg) => {
18
+ throw TypeError(msg);
19
+ };
17
20
  var __esm = (fn, res) => function __init() {
18
21
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
19
22
  };
@@ -38,6 +41,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
38
41
  mod
39
42
  ));
40
43
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
44
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
45
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
46
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
47
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
41
48
 
42
49
  // src/errors.ts
43
50
  var BitfabError;
@@ -537,10 +544,11 @@ function resolveDbBranchSettings(dbBranch) {
537
544
  if (!dbBranch) {
538
545
  return void 0;
539
546
  }
547
+ const { minCu, maxCu, warmupSql } = dbBranch;
540
548
  const settings = {
541
- ...dbBranch.minCu === void 0 ? {} : { minCu: dbBranch.minCu },
542
- ...dbBranch.maxCu === void 0 ? {} : { maxCu: dbBranch.maxCu },
543
- ...dbBranch.warmupSql === void 0 ? {} : { warmupSql: dbBranch.warmupSql }
549
+ ...minCu === void 0 ? {} : { minCu },
550
+ ...maxCu === void 0 ? {} : { maxCu },
551
+ ...warmupSql === void 0 ? {} : { warmupSql }
544
552
  };
545
553
  return Object.keys(settings).length === 0 ? void 0 : settings;
546
554
  }
@@ -604,9 +612,9 @@ function buildMockTree(rootNode) {
604
612
  }
605
613
  return { spans };
606
614
  }
607
- async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, environment, adaptInputs) {
608
- const lease = environment ? serverItem.dbBranchLease : void 0;
609
- const leaseError = environment ? serverItem.dbBranchLeaseError : void 0;
615
+ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, includeDbBranchLease, adaptInputs) {
616
+ const lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
617
+ const leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
610
618
  let inputs = [];
611
619
  let originalOutput;
612
620
  let result;
@@ -789,7 +797,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
789
797
  options?.name,
790
798
  codeChangeDescription,
791
799
  codeChangeFiles,
792
- options?.environment !== void 0,
800
+ options?.dbBranch !== void 0,
793
801
  // includeDbBranchLease
794
802
  options?.experimentGroupId,
795
803
  options?.datasetId,
@@ -812,7 +820,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
812
820
  mockStrategy,
813
821
  resolvedOverrides,
814
822
  replayedTraceIds[index],
815
- options?.environment,
823
+ options?.dbBranch !== void 0,
816
824
  options?.adaptInputs
817
825
  )
818
826
  );
@@ -969,11 +977,11 @@ __export(index_exports, {
969
977
  BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
970
978
  BitfabVercelAiHandler: () => BitfabVercelAiHandler,
971
979
  DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
972
- ReplayEnvironment: () => ReplayEnvironment,
973
980
  SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
974
981
  __version__: () => __version__,
975
982
  finalizers: () => finalizers,
976
983
  flushTraces: () => flushTraces,
984
+ getCurrentReplayBranch: () => getCurrentReplayBranch,
977
985
  getCurrentSpan: () => getCurrentSpan,
978
986
  getCurrentTrace: () => getCurrentTrace,
979
987
  reportReplayProgress: () => reportReplayProgress
@@ -981,7 +989,7 @@ __export(index_exports, {
981
989
  module.exports = __toCommonJS(index_exports);
982
990
 
983
991
  // src/version.generated.ts
984
- var __version__ = "0.31.1";
992
+ var __version__ = "0.33.0";
985
993
 
986
994
  // src/constants.ts
987
995
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1784,7 +1792,7 @@ var BitfabClaudeAgentHandler = class {
1784
1792
  }
1785
1793
  }
1786
1794
  // ── hook callbacks ───────────────────────────────────────────
1787
- async preToolUseHook(inputData, toolUseId, _context) {
1795
+ async preToolUseHook(inputData, toolUseId, _context2) {
1788
1796
  try {
1789
1797
  const sid = inputData.tool_use_id ?? toolUseId ?? randomUuid();
1790
1798
  const toolName = inputData.tool_name ?? "tool";
@@ -1796,7 +1804,7 @@ var BitfabClaudeAgentHandler = class {
1796
1804
  }
1797
1805
  return {};
1798
1806
  }
1799
- async postToolUseHook(inputData, toolUseId, _context) {
1807
+ async postToolUseHook(inputData, toolUseId, _context2) {
1800
1808
  try {
1801
1809
  const sid = inputData.tool_use_id ?? toolUseId ?? "";
1802
1810
  const toolResponse = inputData.tool_response;
@@ -1805,7 +1813,7 @@ var BitfabClaudeAgentHandler = class {
1805
1813
  }
1806
1814
  return {};
1807
1815
  }
1808
- async postToolUseFailureHook(inputData, toolUseId, _context) {
1816
+ async postToolUseFailureHook(inputData, toolUseId, _context2) {
1809
1817
  try {
1810
1818
  const sid = inputData.tool_use_id ?? toolUseId ?? "";
1811
1819
  const error = String(inputData.error ?? "Unknown error");
@@ -1814,7 +1822,7 @@ var BitfabClaudeAgentHandler = class {
1814
1822
  }
1815
1823
  return {};
1816
1824
  }
1817
- async subagentStartHook(inputData, _toolUseId, _context) {
1825
+ async subagentStartHook(inputData, _toolUseId, _context2) {
1818
1826
  try {
1819
1827
  const agentId = inputData.agent_id ?? randomUuid();
1820
1828
  const agentType = inputData.agent_type ?? "subagent";
@@ -1832,7 +1840,7 @@ var BitfabClaudeAgentHandler = class {
1832
1840
  }
1833
1841
  return {};
1834
1842
  }
1835
- async subagentStopHook(inputData, _toolUseId, _context) {
1843
+ async subagentStopHook(inputData, _toolUseId, _context2) {
1836
1844
  try {
1837
1845
  const agentId = inputData.agent_id ?? "";
1838
1846
  const spanId = this.activeSubagentSpans.get(agentId);
@@ -3072,103 +3080,46 @@ var BitfabOpenAIAgentHandler = class {
3072
3080
 
3073
3081
  // src/client.ts
3074
3082
  init_randomUuid();
3075
- init_replayContext();
3076
3083
 
3077
- // src/replayEnvironment.ts
3078
- init_replayContext();
3079
- var ReplayEnvironment = class {
3080
- /**
3081
- * The per-trace branch URL for the item currently being replayed.
3082
- * Throws if read outside a replay item.
3083
- */
3084
- get databaseUrl() {
3085
- const snapshot = this.require();
3086
- this.markAccessed();
3087
- return snapshot.databaseUrl;
3088
- }
3089
- /** When the per-trace branch URL stops being valid. ISO-8601. */
3090
- get expiresAt() {
3091
- return this.require().expiresAt;
3092
- }
3093
- /** Deep link to the branch in the provider console, if available. */
3094
- get providerConsoleUrl() {
3095
- return this.require().providerConsoleUrl;
3084
+ // src/replayBranch.ts
3085
+ var _url, _context;
3086
+ var ReplayBranch = class {
3087
+ /** @internal Built by `getCurrentReplayBranch()`; never constructed by callers. */
3088
+ constructor(lease, traceId, context) {
3089
+ // Genuine JS private fields, not TypeScript `private`: these must be
3090
+ // non-enumerable so neither the connection string nor the whole replay
3091
+ // context can ride along into a log line or a serialized payload.
3092
+ __privateAdd(this, _url);
3093
+ __privateAdd(this, _context);
3094
+ this.expiresAt = lease.expiresAt;
3095
+ this.providerConsoleUrl = lease.providerConsoleUrl;
3096
+ this.readOnly = lease.readOnly;
3097
+ this.region = lease.region;
3098
+ this.traceId = traceId;
3099
+ __privateSet(this, _url, lease.databaseUrl);
3100
+ __privateSet(this, _context, context);
3096
3101
  }
3097
3102
  /**
3098
- * True if the branch is read-only. Customer code can use this to skip
3099
- * write operations during replay when the provider returned a read-only
3100
- * lease.
3101
- */
3102
- get readOnly() {
3103
- return this.require().readOnly;
3104
- }
3105
- /**
3106
- * The branch's region, e.g. `aws-us-east-1`. A compute runs in its project's
3107
- * region, so a replay runner elsewhere pays that round trip on every query.
3108
- */
3109
- get region() {
3110
- return this.require().region;
3111
- }
3112
- /** The historical trace ID that produced the input for this replay item. */
3113
- get traceId() {
3114
- return this.require().traceId;
3115
- }
3116
- /** True when read inside a replay item that has a resolved branch. */
3117
- get active() {
3118
- return this.read() !== null;
3119
- }
3120
- /** Non-throwing variant for callers that handle the inactive case. */
3121
- snapshot() {
3122
- const snapshot = this.read();
3123
- if (snapshot) {
3124
- this.markAccessed();
3125
- }
3126
- return snapshot;
3127
- }
3128
- /**
3129
- * Record on the replay context that customer code obtained the branch
3130
- * URL. Only `databaseUrl` and `snapshot()` count - `active`, `readOnly`
3131
- * and friends inspect the lease without exposing the connection string,
3132
- * so they don't prove the replayed code could have connected to the
3133
- * branch.
3103
+ * Connection string for this item's branch. Point your database client at it
3104
+ * instead of the live database for the duration of the replayed call.
3105
+ *
3106
+ * Reading it records on the trace that the replayed code obtained the branch
3107
+ * URL, which is what separates "a branch was provisioned" from "the branch
3108
+ * was actually used". The other fields inspect the lease without exposing the
3109
+ * connection string, so they deliberately do not record anything. That is
3110
+ * also why this is a getter and not a plain field: the URL is absent from
3111
+ * `JSON.stringify(branch)` and from logging the object.
3134
3112
  */
3135
- markAccessed() {
3136
- const ctx = getReplayContext();
3137
- if (ctx?.dbBranchLease) {
3138
- ctx.dbSnapshotAccessed = true;
3139
- }
3140
- }
3141
- read() {
3142
- const ctx = getReplayContext();
3143
- if (!ctx?.dbBranchLease) {
3144
- return null;
3145
- }
3146
- const traceId = ctx.sourceBitfabTraceId ?? ctx.inputSourceTraceId;
3147
- if (!traceId) {
3148
- return null;
3149
- }
3150
- const lease = ctx.dbBranchLease;
3151
- return {
3152
- databaseUrl: lease.databaseUrl,
3153
- expiresAt: lease.expiresAt,
3154
- providerConsoleUrl: lease.providerConsoleUrl,
3155
- readOnly: lease.readOnly,
3156
- region: lease.region,
3157
- traceId
3158
- };
3159
- }
3160
- require() {
3161
- const snapshot = this.read();
3162
- if (!snapshot) {
3163
- throw new Error(
3164
- "ReplayEnvironment accessed outside of a replay item. Pass it to bitfab.replay({ environment }) and only read it inside the replayed function."
3165
- );
3166
- }
3167
- return snapshot;
3113
+ get databaseUrl() {
3114
+ __privateGet(this, _context).dbSnapshotAccessed = true;
3115
+ return __privateGet(this, _url);
3168
3116
  }
3169
3117
  };
3118
+ _url = new WeakMap();
3119
+ _context = new WeakMap();
3170
3120
 
3171
3121
  // src/client.ts
3122
+ init_replayContext();
3172
3123
  init_serialize();
3173
3124
 
3174
3125
  // src/tracing.ts
@@ -3765,6 +3716,17 @@ function getCurrentSpan() {
3765
3716
  }
3766
3717
  };
3767
3718
  }
3719
+ function getCurrentReplayBranch() {
3720
+ const ctx = getReplayContext();
3721
+ if (!ctx?.dbBranchLease) {
3722
+ return null;
3723
+ }
3724
+ const traceId = ctx.sourceBitfabTraceId ?? ctx.inputSourceTraceId;
3725
+ if (!traceId) {
3726
+ return null;
3727
+ }
3728
+ return new ReplayBranch(ctx.dbBranchLease, traceId, ctx);
3729
+ }
3768
3730
  function getCurrentTrace() {
3769
3731
  const stack = getSpanStack();
3770
3732
  const current = stack[stack.length - 1];
@@ -4839,12 +4801,6 @@ var Bitfab = class {
4839
4801
  );
4840
4802
  }
4841
4803
  };
4842
- /**
4843
- * Per-trace environment for `replay({ environment })`. Construct one,
4844
- * pass it to replay, and read `env.databaseUrl` inside the replayed
4845
- * function to pick up the per-trace branch URL.
4846
- */
4847
- Bitfab.ReplayEnvironment = ReplayEnvironment;
4848
4804
  var BitfabFunction = class {
4849
4805
  constructor(client, traceFunctionKey) {
4850
4806
  this.client = client;
@@ -5052,11 +5008,11 @@ init_replay();
5052
5008
  BitfabOpenAITracingProcessor,
5053
5009
  BitfabVercelAiHandler,
5054
5010
  DEFAULT_SERVICE_URL,
5055
- ReplayEnvironment,
5056
5011
  SUPPORTED_PROVIDERS,
5057
5012
  __version__,
5058
5013
  finalizers,
5059
5014
  flushTraces,
5015
+ getCurrentReplayBranch,
5060
5016
  getCurrentSpan,
5061
5017
  getCurrentTrace,
5062
5018
  reportReplayProgress