@bitfab/sdk 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
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
8
11
  var __esm = (fn, res) => function __init() {
9
12
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
13
  };
@@ -29,6 +32,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
32
  mod
30
33
  ));
31
34
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
36
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
37
+ 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);
38
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
32
39
 
33
40
  // src/errors.ts
34
41
  var BitfabError;
@@ -528,10 +535,11 @@ function resolveDbBranchSettings(dbBranch) {
528
535
  if (!dbBranch) {
529
536
  return void 0;
530
537
  }
538
+ const { minCu, maxCu, warmupSql } = dbBranch;
531
539
  const settings = {
532
- ...dbBranch.minCu === void 0 ? {} : { minCu: dbBranch.minCu },
533
- ...dbBranch.maxCu === void 0 ? {} : { maxCu: dbBranch.maxCu },
534
- ...dbBranch.warmupSql === void 0 ? {} : { warmupSql: dbBranch.warmupSql }
540
+ ...minCu === void 0 ? {} : { minCu },
541
+ ...maxCu === void 0 ? {} : { maxCu },
542
+ ...warmupSql === void 0 ? {} : { warmupSql }
535
543
  };
536
544
  return Object.keys(settings).length === 0 ? void 0 : settings;
537
545
  }
@@ -595,9 +603,9 @@ function buildMockTree(rootNode) {
595
603
  }
596
604
  return { spans };
597
605
  }
598
- async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, environment, adaptInputs) {
599
- const lease = environment ? serverItem.dbBranchLease : void 0;
600
- const leaseError = environment ? serverItem.dbBranchLeaseError : void 0;
606
+ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, includeDbBranchLease, adaptInputs) {
607
+ const lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
608
+ const leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
601
609
  let inputs = [];
602
610
  let originalOutput;
603
611
  let result;
@@ -780,7 +788,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
780
788
  options?.name,
781
789
  codeChangeDescription,
782
790
  codeChangeFiles,
783
- options?.environment !== void 0,
791
+ options?.dbBranch !== void 0,
784
792
  // includeDbBranchLease
785
793
  options?.experimentGroupId,
786
794
  options?.datasetId,
@@ -803,7 +811,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
803
811
  mockStrategy,
804
812
  resolvedOverrides,
805
813
  replayedTraceIds[index],
806
- options?.environment,
814
+ options?.dbBranch !== void 0,
807
815
  options?.adaptInputs
808
816
  )
809
817
  );
@@ -960,11 +968,11 @@ __export(index_exports, {
960
968
  BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
961
969
  BitfabVercelAiHandler: () => BitfabVercelAiHandler,
962
970
  DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
963
- ReplayEnvironment: () => ReplayEnvironment,
964
971
  SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
965
972
  __version__: () => __version__,
966
973
  finalizers: () => finalizers,
967
974
  flushTraces: () => flushTraces,
975
+ getCurrentReplayBranch: () => getCurrentReplayBranch,
968
976
  getCurrentSpan: () => getCurrentSpan,
969
977
  getCurrentTrace: () => getCurrentTrace,
970
978
  reportReplayProgress: () => reportReplayProgress
@@ -972,7 +980,7 @@ __export(index_exports, {
972
980
  module.exports = __toCommonJS(index_exports);
973
981
 
974
982
  // src/version.generated.ts
975
- var __version__ = "0.31.1";
983
+ var __version__ = "0.33.0";
976
984
 
977
985
  // src/constants.ts
978
986
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1775,7 +1783,7 @@ var BitfabClaudeAgentHandler = class {
1775
1783
  }
1776
1784
  }
1777
1785
  // ── hook callbacks ───────────────────────────────────────────
1778
- async preToolUseHook(inputData, toolUseId, _context) {
1786
+ async preToolUseHook(inputData, toolUseId, _context2) {
1779
1787
  try {
1780
1788
  const sid = inputData.tool_use_id ?? toolUseId ?? randomUuid();
1781
1789
  const toolName = inputData.tool_name ?? "tool";
@@ -1787,7 +1795,7 @@ var BitfabClaudeAgentHandler = class {
1787
1795
  }
1788
1796
  return {};
1789
1797
  }
1790
- async postToolUseHook(inputData, toolUseId, _context) {
1798
+ async postToolUseHook(inputData, toolUseId, _context2) {
1791
1799
  try {
1792
1800
  const sid = inputData.tool_use_id ?? toolUseId ?? "";
1793
1801
  const toolResponse = inputData.tool_response;
@@ -1796,7 +1804,7 @@ var BitfabClaudeAgentHandler = class {
1796
1804
  }
1797
1805
  return {};
1798
1806
  }
1799
- async postToolUseFailureHook(inputData, toolUseId, _context) {
1807
+ async postToolUseFailureHook(inputData, toolUseId, _context2) {
1800
1808
  try {
1801
1809
  const sid = inputData.tool_use_id ?? toolUseId ?? "";
1802
1810
  const error = String(inputData.error ?? "Unknown error");
@@ -1805,7 +1813,7 @@ var BitfabClaudeAgentHandler = class {
1805
1813
  }
1806
1814
  return {};
1807
1815
  }
1808
- async subagentStartHook(inputData, _toolUseId, _context) {
1816
+ async subagentStartHook(inputData, _toolUseId, _context2) {
1809
1817
  try {
1810
1818
  const agentId = inputData.agent_id ?? randomUuid();
1811
1819
  const agentType = inputData.agent_type ?? "subagent";
@@ -1823,7 +1831,7 @@ var BitfabClaudeAgentHandler = class {
1823
1831
  }
1824
1832
  return {};
1825
1833
  }
1826
- async subagentStopHook(inputData, _toolUseId, _context) {
1834
+ async subagentStopHook(inputData, _toolUseId, _context2) {
1827
1835
  try {
1828
1836
  const agentId = inputData.agent_id ?? "";
1829
1837
  const spanId = this.activeSubagentSpans.get(agentId);
@@ -3063,103 +3071,46 @@ var BitfabOpenAIAgentHandler = class {
3063
3071
 
3064
3072
  // src/client.ts
3065
3073
  init_randomUuid();
3066
- init_replayContext();
3067
3074
 
3068
- // src/replayEnvironment.ts
3069
- init_replayContext();
3070
- var ReplayEnvironment = class {
3071
- /**
3072
- * The per-trace branch URL for the item currently being replayed.
3073
- * Throws if read outside a replay item.
3074
- */
3075
- get databaseUrl() {
3076
- const snapshot = this.require();
3077
- this.markAccessed();
3078
- return snapshot.databaseUrl;
3079
- }
3080
- /** When the per-trace branch URL stops being valid. ISO-8601. */
3081
- get expiresAt() {
3082
- return this.require().expiresAt;
3083
- }
3084
- /** Deep link to the branch in the provider console, if available. */
3085
- get providerConsoleUrl() {
3086
- return this.require().providerConsoleUrl;
3075
+ // src/replayBranch.ts
3076
+ var _url, _context;
3077
+ var ReplayBranch = class {
3078
+ /** @internal Built by `getCurrentReplayBranch()`; never constructed by callers. */
3079
+ constructor(lease, traceId, context) {
3080
+ // Genuine JS private fields, not TypeScript `private`: these must be
3081
+ // non-enumerable so neither the connection string nor the whole replay
3082
+ // context can ride along into a log line or a serialized payload.
3083
+ __privateAdd(this, _url);
3084
+ __privateAdd(this, _context);
3085
+ this.expiresAt = lease.expiresAt;
3086
+ this.providerConsoleUrl = lease.providerConsoleUrl;
3087
+ this.readOnly = lease.readOnly;
3088
+ this.region = lease.region;
3089
+ this.traceId = traceId;
3090
+ __privateSet(this, _url, lease.databaseUrl);
3091
+ __privateSet(this, _context, context);
3087
3092
  }
3088
3093
  /**
3089
- * True if the branch is read-only. Customer code can use this to skip
3090
- * write operations during replay when the provider returned a read-only
3091
- * lease.
3092
- */
3093
- get readOnly() {
3094
- return this.require().readOnly;
3095
- }
3096
- /**
3097
- * The branch's region, e.g. `aws-us-east-1`. A compute runs in its project's
3098
- * region, so a replay runner elsewhere pays that round trip on every query.
3099
- */
3100
- get region() {
3101
- return this.require().region;
3102
- }
3103
- /** The historical trace ID that produced the input for this replay item. */
3104
- get traceId() {
3105
- return this.require().traceId;
3106
- }
3107
- /** True when read inside a replay item that has a resolved branch. */
3108
- get active() {
3109
- return this.read() !== null;
3110
- }
3111
- /** Non-throwing variant for callers that handle the inactive case. */
3112
- snapshot() {
3113
- const snapshot = this.read();
3114
- if (snapshot) {
3115
- this.markAccessed();
3116
- }
3117
- return snapshot;
3118
- }
3119
- /**
3120
- * Record on the replay context that customer code obtained the branch
3121
- * URL. Only `databaseUrl` and `snapshot()` count - `active`, `readOnly`
3122
- * and friends inspect the lease without exposing the connection string,
3123
- * so they don't prove the replayed code could have connected to the
3124
- * branch.
3094
+ * Connection string for this item's branch. Point your database client at it
3095
+ * instead of the live database for the duration of the replayed call.
3096
+ *
3097
+ * Reading it records on the trace that the replayed code obtained the branch
3098
+ * URL, which is what separates "a branch was provisioned" from "the branch
3099
+ * was actually used". The other fields inspect the lease without exposing the
3100
+ * connection string, so they deliberately do not record anything. That is
3101
+ * also why this is a getter and not a plain field: the URL is absent from
3102
+ * `JSON.stringify(branch)` and from logging the object.
3125
3103
  */
3126
- markAccessed() {
3127
- const ctx = getReplayContext();
3128
- if (ctx?.dbBranchLease) {
3129
- ctx.dbSnapshotAccessed = true;
3130
- }
3131
- }
3132
- read() {
3133
- const ctx = getReplayContext();
3134
- if (!ctx?.dbBranchLease) {
3135
- return null;
3136
- }
3137
- const traceId = ctx.sourceBitfabTraceId ?? ctx.inputSourceTraceId;
3138
- if (!traceId) {
3139
- return null;
3140
- }
3141
- const lease = ctx.dbBranchLease;
3142
- return {
3143
- databaseUrl: lease.databaseUrl,
3144
- expiresAt: lease.expiresAt,
3145
- providerConsoleUrl: lease.providerConsoleUrl,
3146
- readOnly: lease.readOnly,
3147
- region: lease.region,
3148
- traceId
3149
- };
3150
- }
3151
- require() {
3152
- const snapshot = this.read();
3153
- if (!snapshot) {
3154
- throw new Error(
3155
- "ReplayEnvironment accessed outside of a replay item. Pass it to bitfab.replay({ environment }) and only read it inside the replayed function."
3156
- );
3157
- }
3158
- return snapshot;
3104
+ get databaseUrl() {
3105
+ __privateGet(this, _context).dbSnapshotAccessed = true;
3106
+ return __privateGet(this, _url);
3159
3107
  }
3160
3108
  };
3109
+ _url = new WeakMap();
3110
+ _context = new WeakMap();
3161
3111
 
3162
3112
  // src/client.ts
3113
+ init_replayContext();
3163
3114
  init_serialize();
3164
3115
 
3165
3116
  // src/tracing.ts
@@ -3756,6 +3707,17 @@ function getCurrentSpan() {
3756
3707
  }
3757
3708
  };
3758
3709
  }
3710
+ function getCurrentReplayBranch() {
3711
+ const ctx = getReplayContext();
3712
+ if (!ctx?.dbBranchLease) {
3713
+ return null;
3714
+ }
3715
+ const traceId = ctx.sourceBitfabTraceId ?? ctx.inputSourceTraceId;
3716
+ if (!traceId) {
3717
+ return null;
3718
+ }
3719
+ return new ReplayBranch(ctx.dbBranchLease, traceId, ctx);
3720
+ }
3759
3721
  function getCurrentTrace() {
3760
3722
  const stack = getSpanStack();
3761
3723
  const current = stack[stack.length - 1];
@@ -4830,12 +4792,6 @@ var Bitfab = class {
4830
4792
  );
4831
4793
  }
4832
4794
  };
4833
- /**
4834
- * Per-trace environment for `replay({ environment })`. Construct one,
4835
- * pass it to replay, and read `env.databaseUrl` inside the replayed
4836
- * function to pick up the per-trace branch URL.
4837
- */
4838
- Bitfab.ReplayEnvironment = ReplayEnvironment;
4839
4795
  var BitfabFunction = class {
4840
4796
  constructor(client, traceFunctionKey) {
4841
4797
  this.client = client;
@@ -5043,11 +4999,11 @@ init_replay();
5043
4999
  BitfabOpenAITracingProcessor,
5044
5000
  BitfabVercelAiHandler,
5045
5001
  DEFAULT_SERVICE_URL,
5046
- ReplayEnvironment,
5047
5002
  SUPPORTED_PROVIDERS,
5048
5003
  __version__,
5049
5004
  finalizers,
5050
5005
  flushTraces,
5006
+ getCurrentReplayBranch,
5051
5007
  getCurrentSpan,
5052
5008
  getCurrentTrace,
5053
5009
  reportReplayProgress