@bitfab/sdk 0.38.3 → 0.38.4

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
@@ -2059,6 +2059,8 @@ interface SpanOptions {
2059
2059
  * real child.
2060
2060
  */
2061
2061
  mockOnReplay?: boolean;
2062
+ /** Optional test run ID included on the span and on the trace it starts. */
2063
+ testRunId?: string;
2062
2064
  /**
2063
2065
  * Record a serializable view of a non-serializable result (e.g. a live
2064
2066
  * stream object) as the span output.
@@ -2100,6 +2102,15 @@ interface SpanMethodDecoratorContext<TThis, TValue> {
2100
2102
  }
2101
2103
  /** A standard ECMAScript method decorator produced by {@link Bitfab.span}. */
2102
2104
  type SpanMethodDecorator = <TThis, TArgs extends unknown[], TReturn>(originalMethod: (this: TThis, ...args: TArgs) => TReturn, context: SpanMethodDecoratorContext<TThis, (this: TThis, ...args: TArgs) => TReturn>) => (this: TThis, ...args: TArgs) => TReturn;
2105
+ /** Trace-owned configuration for a function discovered beneath `trace()`. */
2106
+ interface NodeOptions extends Omit<SpanOptions, "captureWhen"> {
2107
+ /** Whether the enclosing trace captures this call. Defaults to true. */
2108
+ capture?: boolean;
2109
+ }
2110
+ type StandardNodeMethodDecorator = SpanMethodDecorator;
2111
+ type LegacyNodeMethodDecorator = <TThis, TArgs extends unknown[], TReturn>(target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<(this: TThis, ...args: TArgs) => TReturn>) => void;
2112
+ /** A method decorator produced by {@link Bitfab.node}. */
2113
+ type NodeMethodDecorator = StandardNodeMethodDecorator & LegacyNodeMethodDecorator;
2103
2114
  /** Options for experimental automatic subtree tracing. */
2104
2115
  interface TraceOptions {
2105
2116
  /** Root span name. Defaults to the decorated or wrapped function name. */
@@ -2182,6 +2193,36 @@ declare class Bitfab {
2182
2193
  */
2183
2194
  withTrace<This, TArgs extends unknown[], TReturn>(traceFunctionKey: string, fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
2184
2195
  withTrace<This, TArgs extends unknown[], TReturn>(traceFunctionKey: string, options: TraceOptions, fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
2196
+ /**
2197
+ * Configure a transformed class method when it is discovered beneath a
2198
+ * {@link Bitfab.trace} root.
2199
+ *
2200
+ * The decorator creates no span or trace by itself. Beneath an active trace,
2201
+ * it can rename or retype the discovered call, capture its contents, mark it
2202
+ * for recorded-output replay, finalize its output, or omit it while leaving
2203
+ * captured descendants attached to the nearest captured parent.
2204
+ *
2205
+ * @param options - Trace-owned call configuration.
2206
+ * @experimental Automatic child-call instrumentation is experimental.
2207
+ */
2208
+ node(options?: NodeOptions): NodeMethodDecorator;
2209
+ /**
2210
+ * Configure a transformed standalone function when it is discovered beneath
2211
+ * a {@link Bitfab.trace} or {@link Bitfab.withTrace} root.
2212
+ *
2213
+ * This is the function-oriented equivalent of {@link Bitfab.node}. Without
2214
+ * an active automatic trace, the returned function runs normally and never
2215
+ * creates a span or trace. The function must be named so configuration can
2216
+ * be bound to its transformed definition without leaking to a descendant.
2217
+ *
2218
+ * @param optionsOrFn - Node options or the function to configure.
2219
+ * @param maybeFn - Function to configure when options are provided.
2220
+ * @experimental Automatic child-call instrumentation is experimental.
2221
+ */
2222
+ withNode<This, TArgs extends unknown[], TReturn>(fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
2223
+ withNode<This, TArgs extends unknown[], TReturn>(options: NodeOptions, fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
2224
+ private resolveNodeConfiguration;
2225
+ private createAutoTraceNode;
2185
2226
  private createAutoTraceRoot;
2186
2227
  private refreshAutoTraceCapturePolicy;
2187
2228
  /**
@@ -2718,7 +2759,7 @@ declare class BitfabFunction {
2718
2759
  /**
2719
2760
  * SDK version from package.json (injected at build time)
2720
2761
  */
2721
- declare const __version__ = "0.38.3";
2762
+ declare const __version__ = "0.38.4";
2722
2763
 
2723
2764
  /**
2724
2765
  * Constants for the Bitfab SDK.
@@ -2821,4 +2862,4 @@ type ReplayRegistry = Record<string, ReplayRegistration>;
2821
2862
  */
2822
2863
  declare function defineReplayRegistry<TRegistry extends ReplayRegistry>(registry: TRegistry): TRegistry;
2823
2864
 
2824
- 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 CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, 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__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
2865
+ 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 CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, 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__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
package/dist/index.d.ts CHANGED
@@ -2059,6 +2059,8 @@ interface SpanOptions {
2059
2059
  * real child.
2060
2060
  */
2061
2061
  mockOnReplay?: boolean;
2062
+ /** Optional test run ID included on the span and on the trace it starts. */
2063
+ testRunId?: string;
2062
2064
  /**
2063
2065
  * Record a serializable view of a non-serializable result (e.g. a live
2064
2066
  * stream object) as the span output.
@@ -2100,6 +2102,15 @@ interface SpanMethodDecoratorContext<TThis, TValue> {
2100
2102
  }
2101
2103
  /** A standard ECMAScript method decorator produced by {@link Bitfab.span}. */
2102
2104
  type SpanMethodDecorator = <TThis, TArgs extends unknown[], TReturn>(originalMethod: (this: TThis, ...args: TArgs) => TReturn, context: SpanMethodDecoratorContext<TThis, (this: TThis, ...args: TArgs) => TReturn>) => (this: TThis, ...args: TArgs) => TReturn;
2105
+ /** Trace-owned configuration for a function discovered beneath `trace()`. */
2106
+ interface NodeOptions extends Omit<SpanOptions, "captureWhen"> {
2107
+ /** Whether the enclosing trace captures this call. Defaults to true. */
2108
+ capture?: boolean;
2109
+ }
2110
+ type StandardNodeMethodDecorator = SpanMethodDecorator;
2111
+ type LegacyNodeMethodDecorator = <TThis, TArgs extends unknown[], TReturn>(target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<(this: TThis, ...args: TArgs) => TReturn>) => void;
2112
+ /** A method decorator produced by {@link Bitfab.node}. */
2113
+ type NodeMethodDecorator = StandardNodeMethodDecorator & LegacyNodeMethodDecorator;
2103
2114
  /** Options for experimental automatic subtree tracing. */
2104
2115
  interface TraceOptions {
2105
2116
  /** Root span name. Defaults to the decorated or wrapped function name. */
@@ -2182,6 +2193,36 @@ declare class Bitfab {
2182
2193
  */
2183
2194
  withTrace<This, TArgs extends unknown[], TReturn>(traceFunctionKey: string, fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
2184
2195
  withTrace<This, TArgs extends unknown[], TReturn>(traceFunctionKey: string, options: TraceOptions, fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
2196
+ /**
2197
+ * Configure a transformed class method when it is discovered beneath a
2198
+ * {@link Bitfab.trace} root.
2199
+ *
2200
+ * The decorator creates no span or trace by itself. Beneath an active trace,
2201
+ * it can rename or retype the discovered call, capture its contents, mark it
2202
+ * for recorded-output replay, finalize its output, or omit it while leaving
2203
+ * captured descendants attached to the nearest captured parent.
2204
+ *
2205
+ * @param options - Trace-owned call configuration.
2206
+ * @experimental Automatic child-call instrumentation is experimental.
2207
+ */
2208
+ node(options?: NodeOptions): NodeMethodDecorator;
2209
+ /**
2210
+ * Configure a transformed standalone function when it is discovered beneath
2211
+ * a {@link Bitfab.trace} or {@link Bitfab.withTrace} root.
2212
+ *
2213
+ * This is the function-oriented equivalent of {@link Bitfab.node}. Without
2214
+ * an active automatic trace, the returned function runs normally and never
2215
+ * creates a span or trace. The function must be named so configuration can
2216
+ * be bound to its transformed definition without leaking to a descendant.
2217
+ *
2218
+ * @param optionsOrFn - Node options or the function to configure.
2219
+ * @param maybeFn - Function to configure when options are provided.
2220
+ * @experimental Automatic child-call instrumentation is experimental.
2221
+ */
2222
+ withNode<This, TArgs extends unknown[], TReturn>(fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
2223
+ withNode<This, TArgs extends unknown[], TReturn>(options: NodeOptions, fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
2224
+ private resolveNodeConfiguration;
2225
+ private createAutoTraceNode;
2185
2226
  private createAutoTraceRoot;
2186
2227
  private refreshAutoTraceCapturePolicy;
2187
2228
  /**
@@ -2718,7 +2759,7 @@ declare class BitfabFunction {
2718
2759
  /**
2719
2760
  * SDK version from package.json (injected at build time)
2720
2761
  */
2721
- declare const __version__ = "0.38.3";
2762
+ declare const __version__ = "0.38.4";
2722
2763
 
2723
2764
  /**
2724
2765
  * Constants for the Bitfab SDK.
@@ -2821,4 +2862,4 @@ type ReplayRegistry = Record<string, ReplayRegistration>;
2821
2862
  */
2822
2863
  declare function defineReplayRegistry<TRegistry extends ReplayRegistry>(registry: TRegistry): TRegistry;
2823
2864
 
2824
- 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 CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, 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__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
2865
+ 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 CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, 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__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
package/dist/index.js CHANGED
@@ -12,8 +12,8 @@ import {
12
12
  getCurrentReplayBranch,
13
13
  getCurrentSpan,
14
14
  getCurrentTrace
15
- } from "./chunk-RJPHMJWO.js";
16
- import "./chunk-GFBQ2AMO.js";
15
+ } from "./chunk-NKX3EY35.js";
16
+ import "./chunk-J47KPS77.js";
17
17
  import {
18
18
  BITFAB_PROGRESS_PREFIX,
19
19
  BitfabError,
@@ -25,7 +25,7 @@ import {
25
25
  flushTraces,
26
26
  reportReplayProgress,
27
27
  serializeReplayResult
28
- } from "./chunk-WX6AEFCP.js";
28
+ } from "./chunk-5GWBJGYZ.js";
29
29
  import "./chunk-H6LZRFMN.js";
30
30
  export {
31
31
  BITFAB_PROGRESS_PREFIX,
package/dist/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__, __packageName__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.38.3";
91
+ __version__ = "0.38.4";
92
92
  __packageName__ = "@bitfab/sdk";
93
93
  }
94
94
  });
@@ -3802,6 +3802,29 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
3802
3802
  autoTraceState.browserScope = previous;
3803
3803
  }
3804
3804
  }
3805
+ function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
3806
+ const scope = currentAutoTraceScope();
3807
+ if (!scope) {
3808
+ return fn();
3809
+ }
3810
+ const configuredScope = { ...scope, nodeConfiguration };
3811
+ let result;
3812
+ if (autoTraceState.storage) {
3813
+ result = autoTraceState.storage.run(configuredScope, fn);
3814
+ } else {
3815
+ const previous = autoTraceState.browserScope;
3816
+ autoTraceState.browserScope = configuredScope;
3817
+ try {
3818
+ result = fn();
3819
+ } finally {
3820
+ autoTraceState.browserScope = previous;
3821
+ }
3822
+ }
3823
+ if (isAutoTraceAsyncGenerator(result)) {
3824
+ return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result);
3825
+ }
3826
+ return result;
3827
+ }
3805
3828
  function runWithAutoTraceRootContext(context, fn) {
3806
3829
  autoTraceState.activeRoots += 1;
3807
3830
  let result;
@@ -3840,6 +3863,29 @@ function wrapAutoTraceAsyncGenerator(context, source) {
3840
3863
  };
3841
3864
  return wrapped;
3842
3865
  }
3866
+ function wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, source) {
3867
+ const step = (method, value) => runWithAutoTraceNodeConfiguration(
3868
+ nodeConfiguration,
3869
+ () => source[method](value)
3870
+ );
3871
+ const wrapped = {
3872
+ next: (value) => step("next", value),
3873
+ return: (value) => step("return", value),
3874
+ throw: (error) => step("throw", error),
3875
+ [Symbol.asyncIterator]: () => wrapped
3876
+ };
3877
+ return wrapped;
3878
+ }
3879
+ function __bitfabAutoTraceActive() {
3880
+ if (autoTraceState.activeRoots === 0) {
3881
+ return false;
3882
+ }
3883
+ return currentAutoTraceScope() !== void 0;
3884
+ }
3885
+ function currentAutoTraceScope() {
3886
+ initializeAutoTraceStorage();
3887
+ return autoTraceState.storage?.getStore() ?? autoTraceState.browserScope;
3888
+ }
3843
3889
  function __setBitfabAutoTraceCapturePolicy(client, traceFunctionKey, functionIds) {
3844
3890
  const policies = autoTraceState.capturePolicies.get(client) ?? /* @__PURE__ */ new Map();
3845
3891
  policies.set(traceFunctionKey, new Set(functionIds));
@@ -5692,6 +5738,102 @@ var Bitfab = class {
5692
5738
  const name = fn.name !== "" ? fn.name : traceFunctionKey;
5693
5739
  return this.createAutoTraceRoot(traceFunctionKey, name, options, fn);
5694
5740
  }
5741
+ /**
5742
+ * Configure a transformed class method when it is discovered beneath a
5743
+ * {@link Bitfab.trace} root.
5744
+ *
5745
+ * The decorator creates no span or trace by itself. Beneath an active trace,
5746
+ * it can rename or retype the discovered call, capture its contents, mark it
5747
+ * for recorded-output replay, finalize its output, or omit it while leaving
5748
+ * captured descendants attached to the nearest captured parent.
5749
+ *
5750
+ * @param options - Trace-owned call configuration.
5751
+ * @experimental Automatic child-call instrumentation is experimental.
5752
+ */
5753
+ node(options = {}) {
5754
+ const configuration = this.resolveNodeConfiguration(options);
5755
+ const decorator = (...args) => {
5756
+ if (args.length === 3) {
5757
+ const descriptor = args[2];
5758
+ if (!descriptor || typeof descriptor.value !== "function") {
5759
+ throw new BitfabError("@bitfab.node can only decorate methods");
5760
+ }
5761
+ if (!this.explicitlyEnabled) {
5762
+ return;
5763
+ }
5764
+ descriptor.value = this.createAutoTraceNode(
5765
+ configuration,
5766
+ descriptor.value,
5767
+ String(args[1])
5768
+ );
5769
+ return;
5770
+ }
5771
+ const method = args[0];
5772
+ const context = args[1];
5773
+ if (typeof method !== "function" || context?.kind !== "method") {
5774
+ throw new BitfabError("@bitfab.node can only decorate methods");
5775
+ }
5776
+ if (!this.explicitlyEnabled) {
5777
+ return method;
5778
+ }
5779
+ return this.createAutoTraceNode(
5780
+ configuration,
5781
+ method,
5782
+ String(context.name)
5783
+ );
5784
+ };
5785
+ return decorator;
5786
+ }
5787
+ withNode(optionsOrFn, maybeFn, internalFunctionName) {
5788
+ const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
5789
+ const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
5790
+ if (!fn) {
5791
+ throw new BitfabError("bitfab.withNode requires a function");
5792
+ }
5793
+ const configuration = this.resolveNodeConfiguration(options);
5794
+ if (!this.explicitlyEnabled) {
5795
+ return fn;
5796
+ }
5797
+ const functionName = internalFunctionName ?? fn.name;
5798
+ if (functionName === "") {
5799
+ throw new BitfabError(
5800
+ "bitfab.withNode requires a named function so the subtree transform can bind its configuration to the correct call."
5801
+ );
5802
+ }
5803
+ return this.createAutoTraceNode(configuration, fn, functionName);
5804
+ }
5805
+ resolveNodeConfiguration(options) {
5806
+ const capture = options.capture ?? true;
5807
+ if (!capture && options.mockOnReplay === true) {
5808
+ throw new BitfabError(
5809
+ "bitfab.node({ capture: false }) cannot use mockOnReplay: true because an uncaptured node has no recorded output."
5810
+ );
5811
+ }
5812
+ return {
5813
+ capture,
5814
+ type: options.type ?? "custom",
5815
+ ...options.name !== void 0 && { name: options.name },
5816
+ ...options.testRunId !== void 0 && {
5817
+ testRunId: options.testRunId
5818
+ },
5819
+ ...options.mockOnReplay !== void 0 && {
5820
+ mockOnReplay: options.mockOnReplay
5821
+ },
5822
+ ...options.finalize !== void 0 && { finalize: options.finalize }
5823
+ };
5824
+ }
5825
+ createAutoTraceNode(configuration, fn, functionName) {
5826
+ const nodeConfiguration = { ...configuration, functionName };
5827
+ return function(...args) {
5828
+ if (!__bitfabAutoTraceActive()) {
5829
+ return fn.apply(this, args);
5830
+ }
5831
+ return runWithAutoTraceNodeConfiguration(
5832
+ nodeConfiguration,
5833
+ () => fn.apply(this, args)
5834
+ );
5835
+ };
5836
+ }
5695
5837
  createAutoTraceRoot(traceFunctionKey, name, options, fn) {
5696
5838
  const self = this;
5697
5839
  const maxDepth = autoTraceLimit(
@@ -5730,29 +5872,51 @@ var Bitfab = class {
5730
5872
  );
5731
5873
  };
5732
5874
  const autoTraceContext = {
5733
- invoke(definition, inputs, invokeFn, depth) {
5875
+ invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
5734
5876
  const nameParts = definition.name.split(".");
5735
5877
  const simpleName = nameParts[nameParts.length - 1];
5736
- if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || definition.wrapper === true && !includeWrappers) {
5737
- return invokeFn();
5878
+ const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
5879
+ if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
5880
+ return invokeWithoutNode();
5881
+ }
5882
+ if (nodeConfiguration?.capture === false) {
5883
+ return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
5738
5884
  }
5739
5885
  if (depth >= maxDepth || spansUsed >= maxSpans) {
5740
5886
  warnTruncated();
5741
- return invokeFn();
5887
+ return invokeWithoutNode();
5742
5888
  }
5743
5889
  spansUsed += 1;
5744
5890
  const childOptions = {
5745
- name: definition.name,
5746
- type: "function",
5891
+ name: nodeConfiguration?.name ?? definition.name,
5892
+ type: nodeConfiguration?.type ?? "function",
5747
5893
  captureWhen: "nested",
5748
5894
  functionId: definition.id,
5749
- captureContent: capturePolicy.has(definition.id),
5750
- autoTraceDefinition: definition
5895
+ captureContent: nodeConfiguration !== void 0 || capturePolicy.has(definition.id),
5896
+ autoTraceDefinition: definition,
5897
+ ...nodeConfiguration?.testRunId !== void 0 && {
5898
+ testRunId: nodeConfiguration.testRunId
5899
+ },
5900
+ ...nodeConfiguration?.mockOnReplay !== void 0 && {
5901
+ mockOnReplay: nodeConfiguration.mockOnReplay
5902
+ },
5903
+ ...nodeConfiguration?.finalize !== void 0 && {
5904
+ finalize: nodeConfiguration.finalize
5905
+ }
5751
5906
  };
5907
+ const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
5908
+ if (definition.async === true) {
5909
+ const tracedAsyncChild = self.withSpan(
5910
+ traceFunctionKey,
5911
+ childOptions,
5912
+ async (..._inputs) => await invokeWithAutoTraceContext()
5913
+ );
5914
+ return tracedAsyncChild(...inputs);
5915
+ }
5752
5916
  const tracedChild = self.withSpan(
5753
5917
  traceFunctionKey,
5754
5918
  childOptions,
5755
- (..._inputs) => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1)
5919
+ (..._inputs) => invokeWithAutoTraceContext()
5756
5920
  );
5757
5921
  return tracedChild(...inputs);
5758
5922
  }
@@ -6322,18 +6486,17 @@ var Bitfab = class {
6322
6486
  newStack = [...currentStack, newContext];
6323
6487
  const inputs = args;
6324
6488
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
6489
+ const replayCtxAtStart = getReplayContext();
6490
+ const testRunId = replayCtxAtStart?.testRunId ?? options.testRunId;
6325
6491
  if (isRootSpan && !activeTraceStates.has(traceId)) {
6326
- const replayCtxAtRoot = getReplayContext();
6327
6492
  const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
6328
6493
  activeTraceStates.set(traceId, {
6329
6494
  traceId,
6330
6495
  startedAt,
6331
6496
  contexts: [],
6332
- ...replayCtxAtRoot?.testRunId && {
6333
- testRunId: replayCtxAtRoot.testRunId
6334
- },
6335
- ...replayCtxAtRoot?.inputSourceTraceId && {
6336
- inputSourceTraceId: replayCtxAtRoot.inputSourceTraceId
6497
+ ...testRunId !== void 0 && { testRunId },
6498
+ ...replayCtxAtStart?.inputSourceTraceId && {
6499
+ inputSourceTraceId: replayCtxAtStart.inputSourceTraceId
6337
6500
  },
6338
6501
  dbSnapshotRef
6339
6502
  });
@@ -6366,9 +6529,7 @@ var Bitfab = class {
6366
6529
  contexts: newContext.contexts,
6367
6530
  prompt: newContext.prompt,
6368
6531
  endedAt,
6369
- ...replayCtx?.testRunId && {
6370
- testRunId: replayCtx.testRunId
6371
- },
6532
+ ...testRunId !== void 0 && { testRunId },
6372
6533
  ...replayCtx?.inputSourceSpanId && {
6373
6534
  inputSourceSpanId: replayCtx.inputSourceSpanId
6374
6535
  }