@bitfab/sdk 0.28.11 → 0.29.1

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
@@ -73,6 +73,76 @@ declare class BitfabError extends Error {
73
73
  constructor(message: string, url?: string | undefined);
74
74
  }
75
75
 
76
+ /**
77
+ * Selective mock overrides for replay.
78
+ *
79
+ * A mock override injects a custom value into a specific span (node) during
80
+ * replay: the matched span short-circuits its real execution and returns the
81
+ * value you supply, so downstream real code runs against the substituted
82
+ * output. This is a third mock mode alongside "run real code" and "replay
83
+ * recorded output" (see {@link MockStrategy}).
84
+ *
85
+ * The matcher and value are deliberately separate so matching stays cheap
86
+ * (structural metadata only, no output fetch) and the recorded output is
87
+ * fetched lazily - and only if the value function actually asks for it via
88
+ * {@link MockOverrideCtx.getOriginalOutput}.
89
+ */
90
+ /**
91
+ * Structural identity of a span during replay, passed to a {@link NodeMatcher}.
92
+ * Carries no output payload - matching must not depend on the recorded output,
93
+ * so the output fetch stays lazy and gated.
94
+ */
95
+ interface SpanNodeMeta {
96
+ /** The `withSpan` key of the executing span (its code-side identity). */
97
+ traceFunctionKey: string;
98
+ /** Resolved span name: `options.name ?? fn.name ?? traceFunctionKey`. */
99
+ spanName: string;
100
+ /** Span type, e.g. "llm", "agent", "tool", "custom". */
101
+ type: string;
102
+ /**
103
+ * The id of this span in the original (replayed) trace, when it exists in
104
+ * that trace's tree. Undefined when the live span has no recorded
105
+ * counterpart (e.g. a span the changed code newly introduced).
106
+ */
107
+ originalSpanId?: string;
108
+ }
109
+ /** Context passed to a {@link MockValue} function for a matched span. */
110
+ interface MockOverrideCtx {
111
+ /** The matched span's structural metadata. */
112
+ node: SpanNodeMeta;
113
+ /** The live replay args passed to the wrapped function this run. */
114
+ inputs: unknown[];
115
+ /**
116
+ * Lazily fetch this span's ORIGINAL recorded output (deserialized). The fetch
117
+ * happens only when called and is memoized per replay item, so a purely flat
118
+ * override that never calls it triggers zero output round trips. Rejects if
119
+ * the span has no recorded counterpart. Being async, it is only usable for
120
+ * spans wrapping async functions.
121
+ */
122
+ getOriginalOutput: () => Promise<unknown>;
123
+ }
124
+ /** Selects which spans an override applies to. Runs on structural metadata. */
125
+ type NodeMatcher = (node: SpanNodeMeta) => boolean;
126
+ /** The function form of {@link MockValue}, receiving the override context. */
127
+ type MockValueFn = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
128
+ /**
129
+ * The value injected for a matched span: either a flat value used as-is, or a
130
+ * function of the {@link MockOverrideCtx} that returns one (or a Promise of
131
+ * one). Full replacement - the value IS the span's output, no merge with the
132
+ * recorded output.
133
+ *
134
+ * The flat side is spelled out (rather than `unknown`) so an inline function
135
+ * still gets a typed `ctx`: `unknown | Fn` would collapse to `unknown` and drop
136
+ * the contextual type. To inject a value that is itself a function, wrap it:
137
+ * `value: () => theFunction`.
138
+ */
139
+ type MockValue = MockValueFn | string | number | boolean | bigint | symbol | object | null | undefined;
140
+ /** One (match, value) pair. */
141
+ interface MockOverride {
142
+ match: NodeMatcher;
143
+ value: MockValue;
144
+ }
145
+
76
146
  /**
77
147
  * HTTP client utilities for Bitfab API requests.
78
148
  *
@@ -654,6 +724,15 @@ interface ReplayOptions {
654
724
  * - "all": every child withSpan returns historical output
655
725
  */
656
726
  mock?: MockStrategy;
727
+ /**
728
+ * Selective mock overrides: inject custom values into specific spans during
729
+ * replay, so downstream real code runs against the substituted output. Each
730
+ * override is a `{ match, value }` pair; the first matcher that
731
+ * matches a span wins. These take precedence over any overrides registered on
732
+ * the client via `registerMockOverride`, and over the base `mock` strategy - a
733
+ * span no override matches falls back to that strategy. See {@link MockOverride}.
734
+ */
735
+ mockOverride?: MockOverride | MockOverride[];
657
736
  /**
658
737
  * Per-trace environment. When the source trace carries a DB branching
659
738
  * snapshot, the SDK populates `environment.databaseUrl` before invoking
@@ -706,6 +785,21 @@ interface ReplayOptions {
706
785
  }
707
786
  /** Running totals reported to {@link ReplayOptions.onProgress} as replay proceeds. */
708
787
  interface ReplayProgress {
788
+ /**
789
+ * Event kind. Omitted (or `"item"`) for the per-trace settle events streamed
790
+ * during the run. `"complete"` marks the single terminal event emitted once
791
+ * the run has settled and been enriched server-side; it carries the full
792
+ * {@link ReplayProgress.result} and has no `item`. The Bitfab plugin reads
793
+ * that terminal event to build the run's final result without parsing stdout.
794
+ */
795
+ type?: "item" | "complete";
796
+ /**
797
+ * The full {@link ReplayResult}, present only on the terminal `"complete"`
798
+ * event. Lets the plugin ingest the enriched result (server-aggregated tokens,
799
+ * server trace ids) over the same channel as progress, so a dependency logging
800
+ * to stdout can never block it.
801
+ */
802
+ result?: ReplayResult<unknown>;
709
803
  /** Test run ID created for this replay. */
710
804
  testRunId?: string;
711
805
  /** Items that have finished so far, whether they succeeded or errored. */
@@ -717,18 +811,25 @@ interface ReplayProgress {
717
811
  /** Of the completed items, how many threw (their `item.error` is set). */
718
812
  errored: number;
719
813
  /**
720
- * The single item that just settled to produce this event. `traceId` is the
721
- * source (historical) trace that was replayed (so a UI can identify or link
722
- * it); `error` is its replay error, or null when it ran ok; `durationMs` is how
723
- * long this one trace took to replay. Lets a progress UI show per-trace
724
- * pass/fail and timing as the run streams, without waiting for the full
725
- * {@link ReplayResult}.
814
+ * The single item that just settled to produce this event. `traceId` is null
815
+ * at this stage (the server replay id isn't known until the run completes);
816
+ * `originalTraceId` is the original (historical) trace that was replayed (so
817
+ * a UI can identify or link it); `error` is its replay error, or null when it
818
+ * ran ok; `durationMs` is how long this one trace took to replay. Lets a
819
+ * progress UI show per-trace pass/fail and timing as the run streams, without
820
+ * waiting for the full {@link ReplayResult}.
726
821
  */
727
822
  item?: {
728
- /** Source (historical) trace ID being replayed. */
729
- traceId: string | null;
730
- /** Local SDK replay trace ID, before the server maps it to a row ID. */
731
- replayTraceId?: string | null;
823
+ /** Trace ID of the new replay trace (null during the run; the server id arrives at completion). */
824
+ traceId?: string | null;
825
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
826
+ originalTraceId: string | null;
827
+ /** External span ID the recorded inputs were read from (the original root span). */
828
+ originalSpanId?: string | null;
829
+ /** @deprecated alias for `originalTraceId`. */
830
+ sourceTraceId: string | null;
831
+ /** @deprecated alias for `originalSpanId`. */
832
+ sourceSpanId?: string | null;
732
833
  /** Deserialized inputs from the original trace. */
733
834
  input?: unknown[];
734
835
  /** The result returned by the replayed function, or undefined on error. */
@@ -768,9 +869,13 @@ declare const BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
768
869
  declare function reportReplayProgress(progress: ReplayProgress): void;
769
870
  /** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
770
871
  interface AdaptContext {
771
- /** Bitfab trace ID of the historical trace being replayed. */
772
- traceId: string;
872
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
873
+ originalTraceId: string;
773
874
  /** External span ID the recorded inputs were read from. */
875
+ originalSpanId: string;
876
+ /** @deprecated alias for {@link AdaptContext.originalTraceId}. */
877
+ sourceTraceId: string;
878
+ /** @deprecated alias for {@link AdaptContext.originalSpanId}. */
774
879
  sourceSpanId: string;
775
880
  }
776
881
  /**
@@ -786,8 +891,23 @@ interface AdaptContext {
786
891
  */
787
892
  type AdaptInputsFn = (inputs: unknown[], ctx: AdaptContext) => unknown[];
788
893
  interface ReplayItem<T> {
789
- /** Trace ID of the new trace created during replay. */
894
+ /**
895
+ * Server trace ID of the new replay trace this item produced. Written in by
896
+ * `replay()` from the complete-replay response once the server has minted the
897
+ * trace row; the client-side id used to correlate spans during the run is
898
+ * never surfaced here. Null until completion, on older servers that omit the
899
+ * mapping, or if the item produced no trace. Not the verdict-persistence key:
900
+ * that is the original-trace lineage (`originalTraceId` + `testRunId`).
901
+ */
790
902
  traceId: string | null;
903
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
904
+ originalTraceId: string;
905
+ /** External span ID the recorded inputs were read from (the original root span). */
906
+ originalSpanId: string;
907
+ /** @deprecated alias for {@link ReplayItem.originalTraceId}. */
908
+ sourceTraceId: string;
909
+ /** @deprecated alias for {@link ReplayItem.originalSpanId}. */
910
+ sourceSpanId: string;
791
911
  /** Deserialized inputs from the original trace. */
792
912
  input: unknown[];
793
913
  /** The result returned by the function during replay, or undefined on error. */
@@ -1192,6 +1312,12 @@ declare class Bitfab {
1192
1312
  private readonly httpClient;
1193
1313
  private readonly bamlClient;
1194
1314
  private readonly dbSnapshot;
1315
+ /**
1316
+ * Mock overrides registered via {@link Bitfab.registerMockOverride}, applied
1317
+ * to every `replay` on this client (after any per-call `mockOverride`). In
1318
+ * registration order; first matcher wins within this list.
1319
+ */
1320
+ private readonly mockOverrides;
1195
1321
  /**
1196
1322
  * Initialize the Bitfab client.
1197
1323
  *
@@ -1499,6 +1625,30 @@ declare class Bitfab {
1499
1625
  * determines how many traces replay.
1500
1626
  * @returns ReplayResult with items, testRunId, and testRunUrl
1501
1627
  */
1628
+ /**
1629
+ * Register a mock override applied to every subsequent `replay` on this
1630
+ * client, so downstream real code runs against a value you supply for the
1631
+ * matched span. Instance-scoped (no global state); call {@link clearMockOverrides}
1632
+ * to reset. Per-call `replay({ mockOverride })` overrides take precedence, and
1633
+ * both take precedence over the base `mock` strategy.
1634
+ *
1635
+ * ```ts
1636
+ * // Object form (value is a flat value here)
1637
+ * bitfab.registerMockOverride({
1638
+ * match: (node) => node.traceFunctionKey === "classify-intent",
1639
+ * value: { label: "refund" },
1640
+ * })
1641
+ * // Ordered form (equivalent); value may also be a function of the context
1642
+ * bitfab.registerMockOverride(
1643
+ * (node) => node.traceFunctionKey === "classify-intent",
1644
+ * ({ inputs }) => ({ label: "refund" }),
1645
+ * )
1646
+ * ```
1647
+ */
1648
+ registerMockOverride(override: MockOverride): void;
1649
+ registerMockOverride(match: NodeMatcher, value: MockValue): void;
1650
+ /** Remove all overrides registered via {@link registerMockOverride}. */
1651
+ clearMockOverrides(): void;
1502
1652
  replay<TReturn>(traceFunctionKey: string, fn: (...args: any[]) => TReturn | Promise<TReturn>, options?: ReplayOptions): Promise<ReplayResult<TReturn>>;
1503
1653
  }
1504
1654
  /**
@@ -1649,7 +1799,7 @@ declare class BitfabFunction {
1649
1799
  /**
1650
1800
  * SDK version from package.json (injected at build time)
1651
1801
  */
1652
- declare const __version__ = "0.28.11";
1802
+ declare const __version__ = "0.29.1";
1653
1803
 
1654
1804
  /**
1655
1805
  * Constants for the Bitfab SDK.
@@ -1717,4 +1867,4 @@ declare const finalizers: {
1717
1867
  readableStream: typeof readableStream;
1718
1868
  };
1719
1869
 
1720
- 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 CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace, reportReplayProgress };
1870
+ 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 CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, 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__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace, reportReplayProgress };
package/dist/index.d.ts CHANGED
@@ -73,6 +73,76 @@ declare class BitfabError extends Error {
73
73
  constructor(message: string, url?: string | undefined);
74
74
  }
75
75
 
76
+ /**
77
+ * Selective mock overrides for replay.
78
+ *
79
+ * A mock override injects a custom value into a specific span (node) during
80
+ * replay: the matched span short-circuits its real execution and returns the
81
+ * value you supply, so downstream real code runs against the substituted
82
+ * output. This is a third mock mode alongside "run real code" and "replay
83
+ * recorded output" (see {@link MockStrategy}).
84
+ *
85
+ * The matcher and value are deliberately separate so matching stays cheap
86
+ * (structural metadata only, no output fetch) and the recorded output is
87
+ * fetched lazily - and only if the value function actually asks for it via
88
+ * {@link MockOverrideCtx.getOriginalOutput}.
89
+ */
90
+ /**
91
+ * Structural identity of a span during replay, passed to a {@link NodeMatcher}.
92
+ * Carries no output payload - matching must not depend on the recorded output,
93
+ * so the output fetch stays lazy and gated.
94
+ */
95
+ interface SpanNodeMeta {
96
+ /** The `withSpan` key of the executing span (its code-side identity). */
97
+ traceFunctionKey: string;
98
+ /** Resolved span name: `options.name ?? fn.name ?? traceFunctionKey`. */
99
+ spanName: string;
100
+ /** Span type, e.g. "llm", "agent", "tool", "custom". */
101
+ type: string;
102
+ /**
103
+ * The id of this span in the original (replayed) trace, when it exists in
104
+ * that trace's tree. Undefined when the live span has no recorded
105
+ * counterpart (e.g. a span the changed code newly introduced).
106
+ */
107
+ originalSpanId?: string;
108
+ }
109
+ /** Context passed to a {@link MockValue} function for a matched span. */
110
+ interface MockOverrideCtx {
111
+ /** The matched span's structural metadata. */
112
+ node: SpanNodeMeta;
113
+ /** The live replay args passed to the wrapped function this run. */
114
+ inputs: unknown[];
115
+ /**
116
+ * Lazily fetch this span's ORIGINAL recorded output (deserialized). The fetch
117
+ * happens only when called and is memoized per replay item, so a purely flat
118
+ * override that never calls it triggers zero output round trips. Rejects if
119
+ * the span has no recorded counterpart. Being async, it is only usable for
120
+ * spans wrapping async functions.
121
+ */
122
+ getOriginalOutput: () => Promise<unknown>;
123
+ }
124
+ /** Selects which spans an override applies to. Runs on structural metadata. */
125
+ type NodeMatcher = (node: SpanNodeMeta) => boolean;
126
+ /** The function form of {@link MockValue}, receiving the override context. */
127
+ type MockValueFn = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
128
+ /**
129
+ * The value injected for a matched span: either a flat value used as-is, or a
130
+ * function of the {@link MockOverrideCtx} that returns one (or a Promise of
131
+ * one). Full replacement - the value IS the span's output, no merge with the
132
+ * recorded output.
133
+ *
134
+ * The flat side is spelled out (rather than `unknown`) so an inline function
135
+ * still gets a typed `ctx`: `unknown | Fn` would collapse to `unknown` and drop
136
+ * the contextual type. To inject a value that is itself a function, wrap it:
137
+ * `value: () => theFunction`.
138
+ */
139
+ type MockValue = MockValueFn | string | number | boolean | bigint | symbol | object | null | undefined;
140
+ /** One (match, value) pair. */
141
+ interface MockOverride {
142
+ match: NodeMatcher;
143
+ value: MockValue;
144
+ }
145
+
76
146
  /**
77
147
  * HTTP client utilities for Bitfab API requests.
78
148
  *
@@ -654,6 +724,15 @@ interface ReplayOptions {
654
724
  * - "all": every child withSpan returns historical output
655
725
  */
656
726
  mock?: MockStrategy;
727
+ /**
728
+ * Selective mock overrides: inject custom values into specific spans during
729
+ * replay, so downstream real code runs against the substituted output. Each
730
+ * override is a `{ match, value }` pair; the first matcher that
731
+ * matches a span wins. These take precedence over any overrides registered on
732
+ * the client via `registerMockOverride`, and over the base `mock` strategy - a
733
+ * span no override matches falls back to that strategy. See {@link MockOverride}.
734
+ */
735
+ mockOverride?: MockOverride | MockOverride[];
657
736
  /**
658
737
  * Per-trace environment. When the source trace carries a DB branching
659
738
  * snapshot, the SDK populates `environment.databaseUrl` before invoking
@@ -706,6 +785,21 @@ interface ReplayOptions {
706
785
  }
707
786
  /** Running totals reported to {@link ReplayOptions.onProgress} as replay proceeds. */
708
787
  interface ReplayProgress {
788
+ /**
789
+ * Event kind. Omitted (or `"item"`) for the per-trace settle events streamed
790
+ * during the run. `"complete"` marks the single terminal event emitted once
791
+ * the run has settled and been enriched server-side; it carries the full
792
+ * {@link ReplayProgress.result} and has no `item`. The Bitfab plugin reads
793
+ * that terminal event to build the run's final result without parsing stdout.
794
+ */
795
+ type?: "item" | "complete";
796
+ /**
797
+ * The full {@link ReplayResult}, present only on the terminal `"complete"`
798
+ * event. Lets the plugin ingest the enriched result (server-aggregated tokens,
799
+ * server trace ids) over the same channel as progress, so a dependency logging
800
+ * to stdout can never block it.
801
+ */
802
+ result?: ReplayResult<unknown>;
709
803
  /** Test run ID created for this replay. */
710
804
  testRunId?: string;
711
805
  /** Items that have finished so far, whether they succeeded or errored. */
@@ -717,18 +811,25 @@ interface ReplayProgress {
717
811
  /** Of the completed items, how many threw (their `item.error` is set). */
718
812
  errored: number;
719
813
  /**
720
- * The single item that just settled to produce this event. `traceId` is the
721
- * source (historical) trace that was replayed (so a UI can identify or link
722
- * it); `error` is its replay error, or null when it ran ok; `durationMs` is how
723
- * long this one trace took to replay. Lets a progress UI show per-trace
724
- * pass/fail and timing as the run streams, without waiting for the full
725
- * {@link ReplayResult}.
814
+ * The single item that just settled to produce this event. `traceId` is null
815
+ * at this stage (the server replay id isn't known until the run completes);
816
+ * `originalTraceId` is the original (historical) trace that was replayed (so
817
+ * a UI can identify or link it); `error` is its replay error, or null when it
818
+ * ran ok; `durationMs` is how long this one trace took to replay. Lets a
819
+ * progress UI show per-trace pass/fail and timing as the run streams, without
820
+ * waiting for the full {@link ReplayResult}.
726
821
  */
727
822
  item?: {
728
- /** Source (historical) trace ID being replayed. */
729
- traceId: string | null;
730
- /** Local SDK replay trace ID, before the server maps it to a row ID. */
731
- replayTraceId?: string | null;
823
+ /** Trace ID of the new replay trace (null during the run; the server id arrives at completion). */
824
+ traceId?: string | null;
825
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
826
+ originalTraceId: string | null;
827
+ /** External span ID the recorded inputs were read from (the original root span). */
828
+ originalSpanId?: string | null;
829
+ /** @deprecated alias for `originalTraceId`. */
830
+ sourceTraceId: string | null;
831
+ /** @deprecated alias for `originalSpanId`. */
832
+ sourceSpanId?: string | null;
732
833
  /** Deserialized inputs from the original trace. */
733
834
  input?: unknown[];
734
835
  /** The result returned by the replayed function, or undefined on error. */
@@ -768,9 +869,13 @@ declare const BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
768
869
  declare function reportReplayProgress(progress: ReplayProgress): void;
769
870
  /** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
770
871
  interface AdaptContext {
771
- /** Bitfab trace ID of the historical trace being replayed. */
772
- traceId: string;
872
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
873
+ originalTraceId: string;
773
874
  /** External span ID the recorded inputs were read from. */
875
+ originalSpanId: string;
876
+ /** @deprecated alias for {@link AdaptContext.originalTraceId}. */
877
+ sourceTraceId: string;
878
+ /** @deprecated alias for {@link AdaptContext.originalSpanId}. */
774
879
  sourceSpanId: string;
775
880
  }
776
881
  /**
@@ -786,8 +891,23 @@ interface AdaptContext {
786
891
  */
787
892
  type AdaptInputsFn = (inputs: unknown[], ctx: AdaptContext) => unknown[];
788
893
  interface ReplayItem<T> {
789
- /** Trace ID of the new trace created during replay. */
894
+ /**
895
+ * Server trace ID of the new replay trace this item produced. Written in by
896
+ * `replay()` from the complete-replay response once the server has minted the
897
+ * trace row; the client-side id used to correlate spans during the run is
898
+ * never surfaced here. Null until completion, on older servers that omit the
899
+ * mapping, or if the item produced no trace. Not the verdict-persistence key:
900
+ * that is the original-trace lineage (`originalTraceId` + `testRunId`).
901
+ */
790
902
  traceId: string | null;
903
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
904
+ originalTraceId: string;
905
+ /** External span ID the recorded inputs were read from (the original root span). */
906
+ originalSpanId: string;
907
+ /** @deprecated alias for {@link ReplayItem.originalTraceId}. */
908
+ sourceTraceId: string;
909
+ /** @deprecated alias for {@link ReplayItem.originalSpanId}. */
910
+ sourceSpanId: string;
791
911
  /** Deserialized inputs from the original trace. */
792
912
  input: unknown[];
793
913
  /** The result returned by the function during replay, or undefined on error. */
@@ -1192,6 +1312,12 @@ declare class Bitfab {
1192
1312
  private readonly httpClient;
1193
1313
  private readonly bamlClient;
1194
1314
  private readonly dbSnapshot;
1315
+ /**
1316
+ * Mock overrides registered via {@link Bitfab.registerMockOverride}, applied
1317
+ * to every `replay` on this client (after any per-call `mockOverride`). In
1318
+ * registration order; first matcher wins within this list.
1319
+ */
1320
+ private readonly mockOverrides;
1195
1321
  /**
1196
1322
  * Initialize the Bitfab client.
1197
1323
  *
@@ -1499,6 +1625,30 @@ declare class Bitfab {
1499
1625
  * determines how many traces replay.
1500
1626
  * @returns ReplayResult with items, testRunId, and testRunUrl
1501
1627
  */
1628
+ /**
1629
+ * Register a mock override applied to every subsequent `replay` on this
1630
+ * client, so downstream real code runs against a value you supply for the
1631
+ * matched span. Instance-scoped (no global state); call {@link clearMockOverrides}
1632
+ * to reset. Per-call `replay({ mockOverride })` overrides take precedence, and
1633
+ * both take precedence over the base `mock` strategy.
1634
+ *
1635
+ * ```ts
1636
+ * // Object form (value is a flat value here)
1637
+ * bitfab.registerMockOverride({
1638
+ * match: (node) => node.traceFunctionKey === "classify-intent",
1639
+ * value: { label: "refund" },
1640
+ * })
1641
+ * // Ordered form (equivalent); value may also be a function of the context
1642
+ * bitfab.registerMockOverride(
1643
+ * (node) => node.traceFunctionKey === "classify-intent",
1644
+ * ({ inputs }) => ({ label: "refund" }),
1645
+ * )
1646
+ * ```
1647
+ */
1648
+ registerMockOverride(override: MockOverride): void;
1649
+ registerMockOverride(match: NodeMatcher, value: MockValue): void;
1650
+ /** Remove all overrides registered via {@link registerMockOverride}. */
1651
+ clearMockOverrides(): void;
1502
1652
  replay<TReturn>(traceFunctionKey: string, fn: (...args: any[]) => TReturn | Promise<TReturn>, options?: ReplayOptions): Promise<ReplayResult<TReturn>>;
1503
1653
  }
1504
1654
  /**
@@ -1649,7 +1799,7 @@ declare class BitfabFunction {
1649
1799
  /**
1650
1800
  * SDK version from package.json (injected at build time)
1651
1801
  */
1652
- declare const __version__ = "0.28.11";
1802
+ declare const __version__ = "0.29.1";
1653
1803
 
1654
1804
  /**
1655
1805
  * Constants for the Bitfab SDK.
@@ -1717,4 +1867,4 @@ declare const finalizers: {
1717
1867
  readableStream: typeof readableStream;
1718
1868
  };
1719
1869
 
1720
- 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 CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace, reportReplayProgress };
1870
+ 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 CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, 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__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace, reportReplayProgress };
package/dist/index.js CHANGED
@@ -14,12 +14,12 @@ import {
14
14
  flushTraces,
15
15
  getCurrentSpan,
16
16
  getCurrentTrace
17
- } from "./chunk-ZBWTCBVQ.js";
17
+ } from "./chunk-RTPEBWVO.js";
18
18
  import {
19
19
  BITFAB_PROGRESS_PREFIX,
20
20
  BitfabError,
21
21
  reportReplayProgress
22
- } from "./chunk-5E4BUIYA.js";
22
+ } from "./chunk-YZU6WFG2.js";
23
23
  export {
24
24
  BITFAB_PROGRESS_PREFIX,
25
25
  Bitfab,