bitfab 0.17.0 → 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
@@ -978,11 +978,15 @@ declare class Bitfab {
978
978
  * Fetches the last N traces for the given trace function key, re-runs each
979
979
  * through the provided function, and returns comparison data.
980
980
  *
981
- * The function must have been wrapped with `withSpan` replay injects
982
- * `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.
983
987
  *
984
988
  * @param traceFunctionKey - The trace function key to replay
985
- * @param fn - The function to replay (must be the return value of `withSpan`)
989
+ * @param fn - The function to run recorded inputs through
986
990
  * @param options - Optional replay options. When `traceIds` is passed,
987
991
  * `limit` is ignored (with a warning): an explicit ID list already
988
992
  * determines how many traces replay.
@@ -1051,7 +1055,7 @@ declare class BitfabFunction {
1051
1055
  /**
1052
1056
  * SDK version from package.json (injected at build time)
1053
1057
  */
1054
- declare const __version__ = "0.17.0";
1058
+ declare const __version__ = "0.18.0";
1055
1059
 
1056
1060
  /**
1057
1061
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -978,11 +978,15 @@ declare class Bitfab {
978
978
  * Fetches the last N traces for the given trace function key, re-runs each
979
979
  * through the provided function, and returns comparison data.
980
980
  *
981
- * The function must have been wrapped with `withSpan` replay injects
982
- * `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.
983
987
  *
984
988
  * @param traceFunctionKey - The trace function key to replay
985
- * @param fn - The function to replay (must be the return value of `withSpan`)
989
+ * @param fn - The function to run recorded inputs through
986
990
  * @param options - Optional replay options. When `traceIds` is passed,
987
991
  * `limit` is ignored (with a warning): an explicit ID list already
988
992
  * determines how many traces replay.
@@ -1051,7 +1055,7 @@ declare class BitfabFunction {
1051
1055
  /**
1052
1056
  * SDK version from package.json (injected at build time)
1053
1057
  */
1054
- declare const __version__ = "0.17.0";
1058
+ declare const __version__ = "0.18.0";
1055
1059
 
1056
1060
  /**
1057
1061
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  flushTraces,
21
21
  getCurrentSpan,
22
22
  getCurrentTrace
23
- } from "./chunk-M6N633CX.js";
23
+ } from "./chunk-S3YLZ47O.js";
24
24
  import {
25
25
  BitfabError
26
26
  } from "./chunk-QT7HWOKU.js";
package/dist/node.cjs CHANGED
@@ -456,7 +456,7 @@ registerAsyncLocalStorageClass(
456
456
  );
457
457
 
458
458
  // src/version.generated.ts
459
- var __version__ = "0.17.0";
459
+ var __version__ = "0.18.0";
460
460
 
461
461
  // src/constants.ts
462
462
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -3088,6 +3088,9 @@ var Bitfab = class {
3088
3088
  };
3089
3089
  return runWithSpanStack(newStack, executeWithContext);
3090
3090
  };
3091
+ Object.defineProperty(wrappedFn, "_bitfabTraceFunctionKey", {
3092
+ value: traceFunctionKey
3093
+ });
3091
3094
  return wrappedFn;
3092
3095
  }
3093
3096
  /**
@@ -3259,23 +3262,40 @@ var Bitfab = class {
3259
3262
  * Fetches the last N traces for the given trace function key, re-runs each
3260
3263
  * through the provided function, and returns comparison data.
3261
3264
  *
3262
- * The function must have been wrapped with `withSpan` replay injects
3263
- * `testRunId` via async context so new spans are linked to the test run.
3265
+ * Accepts either a `withSpan`-wrapped function (under the same key) or any
3266
+ * plain callable: plain callables are wrapped internally so each replayed
3267
+ * invocation records a trace tied to the test run. The plain-callable form
3268
+ * is how handler-instrumented workflows (LangGraph/LangChain, Claude Agent
3269
+ * SDK) replay — those record traces under a key with no `withSpan`-wrapped
3270
+ * root in the app.
3264
3271
  *
3265
3272
  * @param traceFunctionKey - The trace function key to replay
3266
- * @param fn - The function to replay (must be the return value of `withSpan`)
3273
+ * @param fn - The function to run recorded inputs through
3267
3274
  * @param options - Optional replay options. When `traceIds` is passed,
3268
3275
  * `limit` is ignored (with a warning): an explicit ID list already
3269
3276
  * determines how many traces replay.
3270
3277
  * @returns ReplayResult with items, testRunId, and testRunUrl
3271
3278
  */
3272
3279
  async replay(traceFunctionKey, fn, options) {
3280
+ const wrappedKey = fn._bitfabTraceFunctionKey;
3281
+ let replayFn = fn;
3282
+ if (wrappedKey === void 0) {
3283
+ replayFn = this.withSpan(
3284
+ traceFunctionKey,
3285
+ { name: fn.name || "Replay", type: "agent" },
3286
+ fn
3287
+ );
3288
+ } else if (wrappedKey !== traceFunctionKey) {
3289
+ throw new BitfabError(
3290
+ `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.`
3291
+ );
3292
+ }
3273
3293
  const { replay: doReplay } = await Promise.resolve().then(() => (init_replay(), replay_exports));
3274
3294
  return doReplay(
3275
3295
  this.httpClient,
3276
3296
  this.serviceUrl,
3277
3297
  traceFunctionKey,
3278
- fn,
3298
+ replayFn,
3279
3299
  options
3280
3300
  );
3281
3301
  }