@bitfab/sdk 0.16.2 → 0.18.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
@@ -147,9 +147,12 @@ declare class BitfabClaudeAgentHandler {
147
147
  /**
148
148
  * Per-trace database snapshot ref capture.
149
149
  *
150
- * When the customer configures `dbSnapshot`, every root span carries a
151
- * `DbSnapshotRef` that pins the DB state at trace open by wall-clock
152
- * timestamp. The Bitfab service uses that timestamp at replay time to
150
+ * Every root span carries a `DbSnapshotRef` that pins the DB state at trace
151
+ * open by wall-clock timestamp. Capturing the timestamp is free (no IO) and
152
+ * harmless, so it happens on every trace regardless of configuration: that
153
+ * lets any trace be replayed against a historical branch later. A `provider`
154
+ * is attached only when the customer configured `dbSnapshot`; when absent it
155
+ * is resolved at replay time. The Bitfab service uses the timestamp to
153
156
  * materialize an ephemeral branch from `customer-main`.
154
157
  */
155
158
  declare const SUPPORTED_PROVIDERS: readonly ["neon"];
@@ -159,14 +162,19 @@ interface DbSnapshotConfig {
159
162
  provider: DbSnapshotProvider;
160
163
  }
161
164
  interface DbSnapshotRef {
162
- provider: DbSnapshotProvider;
163
165
  /**
164
166
  * The wall-clock ISO timestamp the SDK observed immediately before
165
167
  * invoking the wrapped function. The name encodes its provenance:
166
168
  * SDK-observed, wall clock (not monotonic), captured before user code
167
- * began executing.
169
+ * began executing. Always present.
168
170
  */
169
171
  sdkWallClockBeforeFn: string;
172
+ /**
173
+ * The configured provider for server-side branch resolution. Only set when
174
+ * the customer configured `dbSnapshot`; otherwise the provider is resolved
175
+ * at replay time.
176
+ */
177
+ provider?: DbSnapshotProvider;
170
178
  }
171
179
 
172
180
  /**
@@ -970,11 +978,15 @@ declare class Bitfab {
970
978
  * Fetches the last N traces for the given trace function key, re-runs each
971
979
  * through the provided function, and returns comparison data.
972
980
  *
973
- * The function must have been wrapped with `withSpan` replay injects
974
- * `testRunId` via async context so new spans are linked to the test run.
981
+ * Accepts either a `withSpan`-wrapped function (under the same key) or any
982
+ * plain callable: plain callables are wrapped internally so each replayed
983
+ * invocation records a trace tied to the test run. The plain-callable form
984
+ * is how handler-instrumented workflows (LangGraph/LangChain, Claude Agent
985
+ * SDK) replay — those record traces under a key with no `withSpan`-wrapped
986
+ * root in the app.
975
987
  *
976
988
  * @param traceFunctionKey - The trace function key to replay
977
- * @param fn - The function to replay (must be the return value of `withSpan`)
989
+ * @param fn - The function to run recorded inputs through
978
990
  * @param options - Optional replay options. When `traceIds` is passed,
979
991
  * `limit` is ignored (with a warning): an explicit ID list already
980
992
  * determines how many traces replay.
@@ -1043,7 +1055,7 @@ declare class BitfabFunction {
1043
1055
  /**
1044
1056
  * SDK version from package.json (injected at build time)
1045
1057
  */
1046
- declare const __version__ = "0.16.2";
1058
+ declare const __version__ = "0.18.0";
1047
1059
 
1048
1060
  /**
1049
1061
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -147,9 +147,12 @@ declare class BitfabClaudeAgentHandler {
147
147
  /**
148
148
  * Per-trace database snapshot ref capture.
149
149
  *
150
- * When the customer configures `dbSnapshot`, every root span carries a
151
- * `DbSnapshotRef` that pins the DB state at trace open by wall-clock
152
- * timestamp. The Bitfab service uses that timestamp at replay time to
150
+ * Every root span carries a `DbSnapshotRef` that pins the DB state at trace
151
+ * open by wall-clock timestamp. Capturing the timestamp is free (no IO) and
152
+ * harmless, so it happens on every trace regardless of configuration: that
153
+ * lets any trace be replayed against a historical branch later. A `provider`
154
+ * is attached only when the customer configured `dbSnapshot`; when absent it
155
+ * is resolved at replay time. The Bitfab service uses the timestamp to
153
156
  * materialize an ephemeral branch from `customer-main`.
154
157
  */
155
158
  declare const SUPPORTED_PROVIDERS: readonly ["neon"];
@@ -159,14 +162,19 @@ interface DbSnapshotConfig {
159
162
  provider: DbSnapshotProvider;
160
163
  }
161
164
  interface DbSnapshotRef {
162
- provider: DbSnapshotProvider;
163
165
  /**
164
166
  * The wall-clock ISO timestamp the SDK observed immediately before
165
167
  * invoking the wrapped function. The name encodes its provenance:
166
168
  * SDK-observed, wall clock (not monotonic), captured before user code
167
- * began executing.
169
+ * began executing. Always present.
168
170
  */
169
171
  sdkWallClockBeforeFn: string;
172
+ /**
173
+ * The configured provider for server-side branch resolution. Only set when
174
+ * the customer configured `dbSnapshot`; otherwise the provider is resolved
175
+ * at replay time.
176
+ */
177
+ provider?: DbSnapshotProvider;
170
178
  }
171
179
 
172
180
  /**
@@ -970,11 +978,15 @@ declare class Bitfab {
970
978
  * Fetches the last N traces for the given trace function key, re-runs each
971
979
  * through the provided function, and returns comparison data.
972
980
  *
973
- * The function must have been wrapped with `withSpan` replay injects
974
- * `testRunId` via async context so new spans are linked to the test run.
981
+ * Accepts either a `withSpan`-wrapped function (under the same key) or any
982
+ * plain callable: plain callables are wrapped internally so each replayed
983
+ * invocation records a trace tied to the test run. The plain-callable form
984
+ * is how handler-instrumented workflows (LangGraph/LangChain, Claude Agent
985
+ * SDK) replay — those record traces under a key with no `withSpan`-wrapped
986
+ * root in the app.
975
987
  *
976
988
  * @param traceFunctionKey - The trace function key to replay
977
- * @param fn - The function to replay (must be the return value of `withSpan`)
989
+ * @param fn - The function to run recorded inputs through
978
990
  * @param options - Optional replay options. When `traceIds` is passed,
979
991
  * `limit` is ignored (with a warning): an explicit ID list already
980
992
  * determines how many traces replay.
@@ -1043,7 +1055,7 @@ declare class BitfabFunction {
1043
1055
  /**
1044
1056
  * SDK version from package.json (injected at build time)
1045
1057
  */
1046
- declare const __version__ = "0.16.2";
1058
+ declare const __version__ = "0.18.0";
1047
1059
 
1048
1060
  /**
1049
1061
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  flushTraces,
12
12
  getCurrentSpan,
13
13
  getCurrentTrace
14
- } from "./chunk-4WJPQT2X.js";
14
+ } from "./chunk-S3YLZ47O.js";
15
15
  import {
16
16
  BitfabError
17
17
  } from "./chunk-QT7HWOKU.js";
package/dist/node.cjs CHANGED
@@ -447,7 +447,7 @@ registerAsyncLocalStorageClass(
447
447
  );
448
448
 
449
449
  // src/version.generated.ts
450
- var __version__ = "0.16.2";
450
+ var __version__ = "0.18.0";
451
451
 
452
452
  // src/constants.ts
453
453
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1562,8 +1562,8 @@ function validateDbSnapshotConfig(config) {
1562
1562
  }
1563
1563
  function buildSnapshotRef(config, sdkWallClockBeforeFn) {
1564
1564
  return {
1565
- provider: config.provider,
1566
- sdkWallClockBeforeFn
1565
+ sdkWallClockBeforeFn,
1566
+ ...config && { provider: config.provider }
1567
1567
  };
1568
1568
  }
1569
1569
 
@@ -2938,7 +2938,7 @@ var Bitfab = class {
2938
2938
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
2939
2939
  if (isRootSpan && !activeTraceStates.has(traceId)) {
2940
2940
  const replayCtxAtRoot = getReplayContext();
2941
- const dbSnapshotRef = self.dbSnapshot ? buildSnapshotRef(self.dbSnapshot, startedAt) : void 0;
2941
+ const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
2942
2942
  activeTraceStates.set(traceId, {
2943
2943
  traceId,
2944
2944
  startedAt,
@@ -2949,7 +2949,7 @@ var Bitfab = class {
2949
2949
  ...replayCtxAtRoot?.inputSourceTraceId && {
2950
2950
  inputSourceTraceId: replayCtxAtRoot.inputSourceTraceId
2951
2951
  },
2952
- ...dbSnapshotRef && { dbSnapshotRef }
2952
+ dbSnapshotRef
2953
2953
  });
2954
2954
  pendingSpanPromises.set(traceId, []);
2955
2955
  }
@@ -3079,6 +3079,9 @@ var Bitfab = class {
3079
3079
  };
3080
3080
  return runWithSpanStack(newStack, executeWithContext);
3081
3081
  };
3082
+ Object.defineProperty(wrappedFn, "_bitfabTraceFunctionKey", {
3083
+ value: traceFunctionKey
3084
+ });
3082
3085
  return wrappedFn;
3083
3086
  }
3084
3087
  /**
@@ -3250,23 +3253,40 @@ var Bitfab = class {
3250
3253
  * Fetches the last N traces for the given trace function key, re-runs each
3251
3254
  * through the provided function, and returns comparison data.
3252
3255
  *
3253
- * The function must have been wrapped with `withSpan` replay injects
3254
- * `testRunId` via async context so new spans are linked to the test run.
3256
+ * Accepts either a `withSpan`-wrapped function (under the same key) or any
3257
+ * plain callable: plain callables are wrapped internally so each replayed
3258
+ * invocation records a trace tied to the test run. The plain-callable form
3259
+ * is how handler-instrumented workflows (LangGraph/LangChain, Claude Agent
3260
+ * SDK) replay — those record traces under a key with no `withSpan`-wrapped
3261
+ * root in the app.
3255
3262
  *
3256
3263
  * @param traceFunctionKey - The trace function key to replay
3257
- * @param fn - The function to replay (must be the return value of `withSpan`)
3264
+ * @param fn - The function to run recorded inputs through
3258
3265
  * @param options - Optional replay options. When `traceIds` is passed,
3259
3266
  * `limit` is ignored (with a warning): an explicit ID list already
3260
3267
  * determines how many traces replay.
3261
3268
  * @returns ReplayResult with items, testRunId, and testRunUrl
3262
3269
  */
3263
3270
  async replay(traceFunctionKey, fn, options) {
3271
+ const wrappedKey = fn._bitfabTraceFunctionKey;
3272
+ let replayFn = fn;
3273
+ if (wrappedKey === void 0) {
3274
+ replayFn = this.withSpan(
3275
+ traceFunctionKey,
3276
+ { name: fn.name || "Replay", type: "agent" },
3277
+ fn
3278
+ );
3279
+ } else if (wrappedKey !== traceFunctionKey) {
3280
+ throw new BitfabError(
3281
+ `Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
3282
+ );
3283
+ }
3264
3284
  const { replay: doReplay } = await Promise.resolve().then(() => (init_replay(), replay_exports));
3265
3285
  return doReplay(
3266
3286
  this.httpClient,
3267
3287
  this.serviceUrl,
3268
3288
  traceFunctionKey,
3269
- fn,
3289
+ replayFn,
3270
3290
  options
3271
3291
  );
3272
3292
  }