bitfab 0.38.2 → 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/autoTrace.cjs +48 -1
- package/dist/autoTrace.cjs.map +1 -1
- package/dist/autoTrace.d.cts +13 -2
- package/dist/autoTrace.d.ts +13 -2
- package/dist/autoTrace.js +3 -1
- package/dist/{chunk-GFBQ2AMO.js → chunk-J47KPS77.js} +48 -2
- package/dist/chunk-J47KPS77.js.map +1 -0
- package/dist/{chunk-QWV7JDLQ.js → chunk-LHFNHB2J.js} +7 -2
- package/dist/{chunk-QWV7JDLQ.js.map → chunk-LHFNHB2J.js.map} +1 -1
- package/dist/{chunk-JSU2Z2Z7.js → chunk-PXAL7PPD.js} +146 -23
- package/dist/chunk-PXAL7PPD.js.map +1 -0
- package/dist/index.cjs +194 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -4
- package/dist/index.d.ts +81 -4
- package/dist/index.js +5 -3
- package/dist/node.cjs +194 -19
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +5 -3
- package/dist/node.js.map +1 -1
- package/dist/{replay-DDAYVRET.js → replay-BYW5MCLO.js} +2 -2
- package/dist/replayCli.js +620 -0
- package/dist/replayCli.js.map +1 -0
- package/package.json +6 -2
- package/dist/chunk-GFBQ2AMO.js.map +0 -1
- package/dist/chunk-JSU2Z2Z7.js.map +0 -1
- /package/dist/{replay-DDAYVRET.js.map → replay-BYW5MCLO.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1234,7 +1234,7 @@ interface ReplayOptions {
|
|
|
1234
1234
|
* because either source already determines how many traces replay.
|
|
1235
1235
|
*/
|
|
1236
1236
|
limit?: number;
|
|
1237
|
-
/** Optional list of specific trace IDs to replay (max 100). */
|
|
1237
|
+
/** Optional list of specific trace IDs to replay (max 100). Mutually exclusive with `datasetId`. */
|
|
1238
1238
|
traceIds?: string[];
|
|
1239
1239
|
/** Optional display name for the resulting experiment/test run. */
|
|
1240
1240
|
name?: string;
|
|
@@ -1291,7 +1291,8 @@ interface ReplayOptions {
|
|
|
1291
1291
|
/** Group ID to associate this replay with an experiment group for live streaming in Studio. */
|
|
1292
1292
|
experimentGroupId?: string;
|
|
1293
1293
|
/**
|
|
1294
|
-
* Dataset this replay runs against.
|
|
1294
|
+
* Dataset this replay runs against. Mutually exclusive with `traceIds`. When
|
|
1295
|
+
* set, the resulting experiment is
|
|
1295
1296
|
* durably attributed to the dataset (stored on the test run), so it appears
|
|
1296
1297
|
* under the dataset's experiments even if the trace lineage can't be
|
|
1297
1298
|
* reconstructed. Validated server-side against the org.
|
|
@@ -2058,6 +2059,8 @@ interface SpanOptions {
|
|
|
2058
2059
|
* real child.
|
|
2059
2060
|
*/
|
|
2060
2061
|
mockOnReplay?: boolean;
|
|
2062
|
+
/** Optional test run ID included on the span and on the trace it starts. */
|
|
2063
|
+
testRunId?: string;
|
|
2061
2064
|
/**
|
|
2062
2065
|
* Record a serializable view of a non-serializable result (e.g. a live
|
|
2063
2066
|
* stream object) as the span output.
|
|
@@ -2099,6 +2102,15 @@ interface SpanMethodDecoratorContext<TThis, TValue> {
|
|
|
2099
2102
|
}
|
|
2100
2103
|
/** A standard ECMAScript method decorator produced by {@link Bitfab.span}. */
|
|
2101
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;
|
|
2102
2114
|
/** Options for experimental automatic subtree tracing. */
|
|
2103
2115
|
interface TraceOptions {
|
|
2104
2116
|
/** Root span name. Defaults to the decorated or wrapped function name. */
|
|
@@ -2181,6 +2193,36 @@ declare class Bitfab {
|
|
|
2181
2193
|
*/
|
|
2182
2194
|
withTrace<This, TArgs extends unknown[], TReturn>(traceFunctionKey: string, fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
|
|
2183
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;
|
|
2184
2226
|
private createAutoTraceRoot;
|
|
2185
2227
|
private refreshAutoTraceCapturePolicy;
|
|
2186
2228
|
/**
|
|
@@ -2717,7 +2759,7 @@ declare class BitfabFunction {
|
|
|
2717
2759
|
/**
|
|
2718
2760
|
* SDK version from package.json (injected at build time)
|
|
2719
2761
|
*/
|
|
2720
|
-
declare const __version__ = "0.38.
|
|
2762
|
+
declare const __version__ = "0.38.4";
|
|
2721
2763
|
|
|
2722
2764
|
/**
|
|
2723
2765
|
* Constants for the Bitfab SDK.
|
|
@@ -2785,4 +2827,39 @@ declare const finalizers: {
|
|
|
2785
2827
|
readableStream: typeof readableStream;
|
|
2786
2828
|
};
|
|
2787
2829
|
|
|
2788
|
-
|
|
2830
|
+
type ReplayFunction = (...args: any[]) => unknown | Promise<unknown>;
|
|
2831
|
+
type ReplayRegistryOptions = Omit<ReplayOptions, "onItemStart" | "onItemFinish" | "onProgress">;
|
|
2832
|
+
interface ReplayRegistryContext {
|
|
2833
|
+
/** Values supplied through `--params` and repeated `--param name=value`. */
|
|
2834
|
+
params: Readonly<Record<string, unknown>>;
|
|
2835
|
+
}
|
|
2836
|
+
type ReplayOptionsFactory = (context: ReplayRegistryContext) => ReplayRegistryOptions | Promise<ReplayRegistryOptions>;
|
|
2837
|
+
interface ReplayRegistration {
|
|
2838
|
+
/** Client instance used by the production traced function. */
|
|
2839
|
+
client: Bitfab;
|
|
2840
|
+
/** The exact traced function production calls. */
|
|
2841
|
+
fn: ReplayFunction;
|
|
2842
|
+
/**
|
|
2843
|
+
* Required for handler-instrumented or otherwise plain callables. Omit for a
|
|
2844
|
+
* `withSpan`-wrapped function and the registry reads the wrapper's key.
|
|
2845
|
+
*/
|
|
2846
|
+
traceFunctionKey?: string;
|
|
2847
|
+
/**
|
|
2848
|
+
* Per-function replay behavior and defaults. Put executable configuration
|
|
2849
|
+
* such as `mockOverride` and `adaptInputs` here; command-line values override
|
|
2850
|
+
* overlapping scalar defaults such as `mock` and `maxConcurrency`.
|
|
2851
|
+
*/
|
|
2852
|
+
options?: ReplayRegistryOptions;
|
|
2853
|
+
/** Build executable replay behavior from caller-supplied CLI parameters. */
|
|
2854
|
+
optionsFactory?: ReplayOptionsFactory;
|
|
2855
|
+
}
|
|
2856
|
+
type ReplayRegistry = Record<string, ReplayRegistration>;
|
|
2857
|
+
/**
|
|
2858
|
+
* Define the project-owned list of replayable functions.
|
|
2859
|
+
*
|
|
2860
|
+
* The registry is deliberately data-only: the SDK owns the replay CLI, so an
|
|
2861
|
+
* SDK upgrade can add replay features without regenerating the project file.
|
|
2862
|
+
*/
|
|
2863
|
+
declare function defineReplayRegistry<TRegistry extends ReplayRegistry>(registry: TRegistry): TRegistry;
|
|
2864
|
+
|
|
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
|
@@ -1234,7 +1234,7 @@ interface ReplayOptions {
|
|
|
1234
1234
|
* because either source already determines how many traces replay.
|
|
1235
1235
|
*/
|
|
1236
1236
|
limit?: number;
|
|
1237
|
-
/** Optional list of specific trace IDs to replay (max 100). */
|
|
1237
|
+
/** Optional list of specific trace IDs to replay (max 100). Mutually exclusive with `datasetId`. */
|
|
1238
1238
|
traceIds?: string[];
|
|
1239
1239
|
/** Optional display name for the resulting experiment/test run. */
|
|
1240
1240
|
name?: string;
|
|
@@ -1291,7 +1291,8 @@ interface ReplayOptions {
|
|
|
1291
1291
|
/** Group ID to associate this replay with an experiment group for live streaming in Studio. */
|
|
1292
1292
|
experimentGroupId?: string;
|
|
1293
1293
|
/**
|
|
1294
|
-
* Dataset this replay runs against.
|
|
1294
|
+
* Dataset this replay runs against. Mutually exclusive with `traceIds`. When
|
|
1295
|
+
* set, the resulting experiment is
|
|
1295
1296
|
* durably attributed to the dataset (stored on the test run), so it appears
|
|
1296
1297
|
* under the dataset's experiments even if the trace lineage can't be
|
|
1297
1298
|
* reconstructed. Validated server-side against the org.
|
|
@@ -2058,6 +2059,8 @@ interface SpanOptions {
|
|
|
2058
2059
|
* real child.
|
|
2059
2060
|
*/
|
|
2060
2061
|
mockOnReplay?: boolean;
|
|
2062
|
+
/** Optional test run ID included on the span and on the trace it starts. */
|
|
2063
|
+
testRunId?: string;
|
|
2061
2064
|
/**
|
|
2062
2065
|
* Record a serializable view of a non-serializable result (e.g. a live
|
|
2063
2066
|
* stream object) as the span output.
|
|
@@ -2099,6 +2102,15 @@ interface SpanMethodDecoratorContext<TThis, TValue> {
|
|
|
2099
2102
|
}
|
|
2100
2103
|
/** A standard ECMAScript method decorator produced by {@link Bitfab.span}. */
|
|
2101
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;
|
|
2102
2114
|
/** Options for experimental automatic subtree tracing. */
|
|
2103
2115
|
interface TraceOptions {
|
|
2104
2116
|
/** Root span name. Defaults to the decorated or wrapped function name. */
|
|
@@ -2181,6 +2193,36 @@ declare class Bitfab {
|
|
|
2181
2193
|
*/
|
|
2182
2194
|
withTrace<This, TArgs extends unknown[], TReturn>(traceFunctionKey: string, fn: (this: This, ...args: TArgs) => TReturn): (this: This, ...args: TArgs) => TReturn;
|
|
2183
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;
|
|
2184
2226
|
private createAutoTraceRoot;
|
|
2185
2227
|
private refreshAutoTraceCapturePolicy;
|
|
2186
2228
|
/**
|
|
@@ -2717,7 +2759,7 @@ declare class BitfabFunction {
|
|
|
2717
2759
|
/**
|
|
2718
2760
|
* SDK version from package.json (injected at build time)
|
|
2719
2761
|
*/
|
|
2720
|
-
declare const __version__ = "0.38.
|
|
2762
|
+
declare const __version__ = "0.38.4";
|
|
2721
2763
|
|
|
2722
2764
|
/**
|
|
2723
2765
|
* Constants for the Bitfab SDK.
|
|
@@ -2785,4 +2827,39 @@ declare const finalizers: {
|
|
|
2785
2827
|
readableStream: typeof readableStream;
|
|
2786
2828
|
};
|
|
2787
2829
|
|
|
2788
|
-
|
|
2830
|
+
type ReplayFunction = (...args: any[]) => unknown | Promise<unknown>;
|
|
2831
|
+
type ReplayRegistryOptions = Omit<ReplayOptions, "onItemStart" | "onItemFinish" | "onProgress">;
|
|
2832
|
+
interface ReplayRegistryContext {
|
|
2833
|
+
/** Values supplied through `--params` and repeated `--param name=value`. */
|
|
2834
|
+
params: Readonly<Record<string, unknown>>;
|
|
2835
|
+
}
|
|
2836
|
+
type ReplayOptionsFactory = (context: ReplayRegistryContext) => ReplayRegistryOptions | Promise<ReplayRegistryOptions>;
|
|
2837
|
+
interface ReplayRegistration {
|
|
2838
|
+
/** Client instance used by the production traced function. */
|
|
2839
|
+
client: Bitfab;
|
|
2840
|
+
/** The exact traced function production calls. */
|
|
2841
|
+
fn: ReplayFunction;
|
|
2842
|
+
/**
|
|
2843
|
+
* Required for handler-instrumented or otherwise plain callables. Omit for a
|
|
2844
|
+
* `withSpan`-wrapped function and the registry reads the wrapper's key.
|
|
2845
|
+
*/
|
|
2846
|
+
traceFunctionKey?: string;
|
|
2847
|
+
/**
|
|
2848
|
+
* Per-function replay behavior and defaults. Put executable configuration
|
|
2849
|
+
* such as `mockOverride` and `adaptInputs` here; command-line values override
|
|
2850
|
+
* overlapping scalar defaults such as `mock` and `maxConcurrency`.
|
|
2851
|
+
*/
|
|
2852
|
+
options?: ReplayRegistryOptions;
|
|
2853
|
+
/** Build executable replay behavior from caller-supplied CLI parameters. */
|
|
2854
|
+
optionsFactory?: ReplayOptionsFactory;
|
|
2855
|
+
}
|
|
2856
|
+
type ReplayRegistry = Record<string, ReplayRegistration>;
|
|
2857
|
+
/**
|
|
2858
|
+
* Define the project-owned list of replayable functions.
|
|
2859
|
+
*
|
|
2860
|
+
* The registry is deliberately data-only: the SDK owns the replay CLI, so an
|
|
2861
|
+
* SDK upgrade can add replay features without regenerating the project file.
|
|
2862
|
+
*/
|
|
2863
|
+
declare function defineReplayRegistry<TRegistry extends ReplayRegistry>(registry: TRegistry): TRegistry;
|
|
2864
|
+
|
|
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
|
@@ -16,12 +16,13 @@ import {
|
|
|
16
16
|
BitfabOpenAITracingProcessor,
|
|
17
17
|
BitfabVercelAiHandler,
|
|
18
18
|
SUPPORTED_PROVIDERS,
|
|
19
|
+
defineReplayRegistry,
|
|
19
20
|
finalizers,
|
|
20
21
|
getCurrentReplayBranch,
|
|
21
22
|
getCurrentSpan,
|
|
22
23
|
getCurrentTrace
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import "./chunk-
|
|
24
|
+
} from "./chunk-PXAL7PPD.js";
|
|
25
|
+
import "./chunk-J47KPS77.js";
|
|
25
26
|
import {
|
|
26
27
|
BITFAB_PROGRESS_PREFIX,
|
|
27
28
|
BitfabError,
|
|
@@ -33,7 +34,7 @@ import {
|
|
|
33
34
|
flushTraces,
|
|
34
35
|
reportReplayProgress,
|
|
35
36
|
serializeReplayResult
|
|
36
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-LHFNHB2J.js";
|
|
37
38
|
import "./chunk-H6LZRFMN.js";
|
|
38
39
|
export {
|
|
39
40
|
BITFAB_PROGRESS_PREFIX,
|
|
@@ -52,6 +53,7 @@ export {
|
|
|
52
53
|
ReplayError,
|
|
53
54
|
SUPPORTED_PROVIDERS,
|
|
54
55
|
__version__,
|
|
56
|
+
defineReplayRegistry,
|
|
55
57
|
finalizers,
|
|
56
58
|
flushTraces,
|
|
57
59
|
getCurrentReplayBranch,
|
package/dist/node.cjs
CHANGED
|
@@ -97,7 +97,7 @@ var __version__, __packageName__;
|
|
|
97
97
|
var init_version_generated = __esm({
|
|
98
98
|
"src/version.generated.ts"() {
|
|
99
99
|
"use strict";
|
|
100
|
-
__version__ = "0.38.
|
|
100
|
+
__version__ = "0.38.4";
|
|
101
101
|
__packageName__ = "bitfab";
|
|
102
102
|
}
|
|
103
103
|
});
|
|
@@ -2820,6 +2820,11 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
|
|
|
2820
2820
|
);
|
|
2821
2821
|
}
|
|
2822
2822
|
}
|
|
2823
|
+
if (options?.traceIds !== void 0 && options?.datasetId !== void 0) {
|
|
2824
|
+
throw new BitfabError(
|
|
2825
|
+
"traceIds and datasetId select different replay sources and cannot be used together."
|
|
2826
|
+
);
|
|
2827
|
+
}
|
|
2823
2828
|
if (options?.limit !== void 0 && options?.traceIds !== void 0) {
|
|
2824
2829
|
try {
|
|
2825
2830
|
console.warn(
|
|
@@ -3147,6 +3152,7 @@ __export(node_exports, {
|
|
|
3147
3152
|
ReplayError: () => ReplayError,
|
|
3148
3153
|
SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
|
|
3149
3154
|
__version__: () => __version__,
|
|
3155
|
+
defineReplayRegistry: () => defineReplayRegistry,
|
|
3150
3156
|
finalizers: () => finalizers,
|
|
3151
3157
|
flushTraces: () => flushTraces,
|
|
3152
3158
|
getCurrentReplayBranch: () => getCurrentReplayBranch,
|
|
@@ -3805,6 +3811,29 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
|
|
|
3805
3811
|
autoTraceState.browserScope = previous;
|
|
3806
3812
|
}
|
|
3807
3813
|
}
|
|
3814
|
+
function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
|
|
3815
|
+
const scope = currentAutoTraceScope();
|
|
3816
|
+
if (!scope) {
|
|
3817
|
+
return fn();
|
|
3818
|
+
}
|
|
3819
|
+
const configuredScope = { ...scope, nodeConfiguration };
|
|
3820
|
+
let result;
|
|
3821
|
+
if (autoTraceState.storage) {
|
|
3822
|
+
result = autoTraceState.storage.run(configuredScope, fn);
|
|
3823
|
+
} else {
|
|
3824
|
+
const previous = autoTraceState.browserScope;
|
|
3825
|
+
autoTraceState.browserScope = configuredScope;
|
|
3826
|
+
try {
|
|
3827
|
+
result = fn();
|
|
3828
|
+
} finally {
|
|
3829
|
+
autoTraceState.browserScope = previous;
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3832
|
+
if (isAutoTraceAsyncGenerator(result)) {
|
|
3833
|
+
return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result);
|
|
3834
|
+
}
|
|
3835
|
+
return result;
|
|
3836
|
+
}
|
|
3808
3837
|
function runWithAutoTraceRootContext(context, fn) {
|
|
3809
3838
|
autoTraceState.activeRoots += 1;
|
|
3810
3839
|
let result;
|
|
@@ -3843,6 +3872,29 @@ function wrapAutoTraceAsyncGenerator(context, source) {
|
|
|
3843
3872
|
};
|
|
3844
3873
|
return wrapped;
|
|
3845
3874
|
}
|
|
3875
|
+
function wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, source) {
|
|
3876
|
+
const step = (method, value) => runWithAutoTraceNodeConfiguration(
|
|
3877
|
+
nodeConfiguration,
|
|
3878
|
+
() => source[method](value)
|
|
3879
|
+
);
|
|
3880
|
+
const wrapped = {
|
|
3881
|
+
next: (value) => step("next", value),
|
|
3882
|
+
return: (value) => step("return", value),
|
|
3883
|
+
throw: (error) => step("throw", error),
|
|
3884
|
+
[Symbol.asyncIterator]: () => wrapped
|
|
3885
|
+
};
|
|
3886
|
+
return wrapped;
|
|
3887
|
+
}
|
|
3888
|
+
function __bitfabAutoTraceActive() {
|
|
3889
|
+
if (autoTraceState.activeRoots === 0) {
|
|
3890
|
+
return false;
|
|
3891
|
+
}
|
|
3892
|
+
return currentAutoTraceScope() !== void 0;
|
|
3893
|
+
}
|
|
3894
|
+
function currentAutoTraceScope() {
|
|
3895
|
+
initializeAutoTraceStorage();
|
|
3896
|
+
return autoTraceState.storage?.getStore() ?? autoTraceState.browserScope;
|
|
3897
|
+
}
|
|
3846
3898
|
function __setBitfabAutoTraceCapturePolicy(client, traceFunctionKey, functionIds) {
|
|
3847
3899
|
const policies = autoTraceState.capturePolicies.get(client) ?? /* @__PURE__ */ new Map();
|
|
3848
3900
|
policies.set(traceFunctionKey, new Set(functionIds));
|
|
@@ -5695,6 +5747,102 @@ var Bitfab = class {
|
|
|
5695
5747
|
const name = fn.name !== "" ? fn.name : traceFunctionKey;
|
|
5696
5748
|
return this.createAutoTraceRoot(traceFunctionKey, name, options, fn);
|
|
5697
5749
|
}
|
|
5750
|
+
/**
|
|
5751
|
+
* Configure a transformed class method when it is discovered beneath a
|
|
5752
|
+
* {@link Bitfab.trace} root.
|
|
5753
|
+
*
|
|
5754
|
+
* The decorator creates no span or trace by itself. Beneath an active trace,
|
|
5755
|
+
* it can rename or retype the discovered call, capture its contents, mark it
|
|
5756
|
+
* for recorded-output replay, finalize its output, or omit it while leaving
|
|
5757
|
+
* captured descendants attached to the nearest captured parent.
|
|
5758
|
+
*
|
|
5759
|
+
* @param options - Trace-owned call configuration.
|
|
5760
|
+
* @experimental Automatic child-call instrumentation is experimental.
|
|
5761
|
+
*/
|
|
5762
|
+
node(options = {}) {
|
|
5763
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5764
|
+
const decorator = (...args) => {
|
|
5765
|
+
if (args.length === 3) {
|
|
5766
|
+
const descriptor = args[2];
|
|
5767
|
+
if (!descriptor || typeof descriptor.value !== "function") {
|
|
5768
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5769
|
+
}
|
|
5770
|
+
if (!this.explicitlyEnabled) {
|
|
5771
|
+
return;
|
|
5772
|
+
}
|
|
5773
|
+
descriptor.value = this.createAutoTraceNode(
|
|
5774
|
+
configuration,
|
|
5775
|
+
descriptor.value,
|
|
5776
|
+
String(args[1])
|
|
5777
|
+
);
|
|
5778
|
+
return;
|
|
5779
|
+
}
|
|
5780
|
+
const method = args[0];
|
|
5781
|
+
const context = args[1];
|
|
5782
|
+
if (typeof method !== "function" || context?.kind !== "method") {
|
|
5783
|
+
throw new BitfabError("@bitfab.node can only decorate methods");
|
|
5784
|
+
}
|
|
5785
|
+
if (!this.explicitlyEnabled) {
|
|
5786
|
+
return method;
|
|
5787
|
+
}
|
|
5788
|
+
return this.createAutoTraceNode(
|
|
5789
|
+
configuration,
|
|
5790
|
+
method,
|
|
5791
|
+
String(context.name)
|
|
5792
|
+
);
|
|
5793
|
+
};
|
|
5794
|
+
return decorator;
|
|
5795
|
+
}
|
|
5796
|
+
withNode(optionsOrFn, maybeFn, internalFunctionName) {
|
|
5797
|
+
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
5798
|
+
const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
|
|
5799
|
+
if (!fn) {
|
|
5800
|
+
throw new BitfabError("bitfab.withNode requires a function");
|
|
5801
|
+
}
|
|
5802
|
+
const configuration = this.resolveNodeConfiguration(options);
|
|
5803
|
+
if (!this.explicitlyEnabled) {
|
|
5804
|
+
return fn;
|
|
5805
|
+
}
|
|
5806
|
+
const functionName = internalFunctionName ?? fn.name;
|
|
5807
|
+
if (functionName === "") {
|
|
5808
|
+
throw new BitfabError(
|
|
5809
|
+
"bitfab.withNode requires a named function so the subtree transform can bind its configuration to the correct call."
|
|
5810
|
+
);
|
|
5811
|
+
}
|
|
5812
|
+
return this.createAutoTraceNode(configuration, fn, functionName);
|
|
5813
|
+
}
|
|
5814
|
+
resolveNodeConfiguration(options) {
|
|
5815
|
+
const capture = options.capture ?? true;
|
|
5816
|
+
if (!capture && options.mockOnReplay === true) {
|
|
5817
|
+
throw new BitfabError(
|
|
5818
|
+
"bitfab.node({ capture: false }) cannot use mockOnReplay: true because an uncaptured node has no recorded output."
|
|
5819
|
+
);
|
|
5820
|
+
}
|
|
5821
|
+
return {
|
|
5822
|
+
capture,
|
|
5823
|
+
type: options.type ?? "custom",
|
|
5824
|
+
...options.name !== void 0 && { name: options.name },
|
|
5825
|
+
...options.testRunId !== void 0 && {
|
|
5826
|
+
testRunId: options.testRunId
|
|
5827
|
+
},
|
|
5828
|
+
...options.mockOnReplay !== void 0 && {
|
|
5829
|
+
mockOnReplay: options.mockOnReplay
|
|
5830
|
+
},
|
|
5831
|
+
...options.finalize !== void 0 && { finalize: options.finalize }
|
|
5832
|
+
};
|
|
5833
|
+
}
|
|
5834
|
+
createAutoTraceNode(configuration, fn, functionName) {
|
|
5835
|
+
const nodeConfiguration = { ...configuration, functionName };
|
|
5836
|
+
return function(...args) {
|
|
5837
|
+
if (!__bitfabAutoTraceActive()) {
|
|
5838
|
+
return fn.apply(this, args);
|
|
5839
|
+
}
|
|
5840
|
+
return runWithAutoTraceNodeConfiguration(
|
|
5841
|
+
nodeConfiguration,
|
|
5842
|
+
() => fn.apply(this, args)
|
|
5843
|
+
);
|
|
5844
|
+
};
|
|
5845
|
+
}
|
|
5698
5846
|
createAutoTraceRoot(traceFunctionKey, name, options, fn) {
|
|
5699
5847
|
const self = this;
|
|
5700
5848
|
const maxDepth = autoTraceLimit(
|
|
@@ -5733,29 +5881,51 @@ var Bitfab = class {
|
|
|
5733
5881
|
);
|
|
5734
5882
|
};
|
|
5735
5883
|
const autoTraceContext = {
|
|
5736
|
-
invoke(definition, inputs, invokeFn, depth) {
|
|
5884
|
+
invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
|
|
5737
5885
|
const nameParts = definition.name.split(".");
|
|
5738
5886
|
const simpleName = nameParts[nameParts.length - 1];
|
|
5739
|
-
|
|
5740
|
-
|
|
5887
|
+
const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5888
|
+
if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
|
|
5889
|
+
return invokeWithoutNode();
|
|
5890
|
+
}
|
|
5891
|
+
if (nodeConfiguration?.capture === false) {
|
|
5892
|
+
return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
|
|
5741
5893
|
}
|
|
5742
5894
|
if (depth >= maxDepth || spansUsed >= maxSpans) {
|
|
5743
5895
|
warnTruncated();
|
|
5744
|
-
return
|
|
5896
|
+
return invokeWithoutNode();
|
|
5745
5897
|
}
|
|
5746
5898
|
spansUsed += 1;
|
|
5747
5899
|
const childOptions = {
|
|
5748
|
-
name: definition.name,
|
|
5749
|
-
type: "function",
|
|
5900
|
+
name: nodeConfiguration?.name ?? definition.name,
|
|
5901
|
+
type: nodeConfiguration?.type ?? "function",
|
|
5750
5902
|
captureWhen: "nested",
|
|
5751
5903
|
functionId: definition.id,
|
|
5752
|
-
captureContent: capturePolicy.has(definition.id),
|
|
5753
|
-
autoTraceDefinition: definition
|
|
5904
|
+
captureContent: nodeConfiguration !== void 0 || capturePolicy.has(definition.id),
|
|
5905
|
+
autoTraceDefinition: definition,
|
|
5906
|
+
...nodeConfiguration?.testRunId !== void 0 && {
|
|
5907
|
+
testRunId: nodeConfiguration.testRunId
|
|
5908
|
+
},
|
|
5909
|
+
...nodeConfiguration?.mockOnReplay !== void 0 && {
|
|
5910
|
+
mockOnReplay: nodeConfiguration.mockOnReplay
|
|
5911
|
+
},
|
|
5912
|
+
...nodeConfiguration?.finalize !== void 0 && {
|
|
5913
|
+
finalize: nodeConfiguration.finalize
|
|
5914
|
+
}
|
|
5754
5915
|
};
|
|
5916
|
+
const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
|
|
5917
|
+
if (definition.async === true) {
|
|
5918
|
+
const tracedAsyncChild = self.withSpan(
|
|
5919
|
+
traceFunctionKey,
|
|
5920
|
+
childOptions,
|
|
5921
|
+
async (..._inputs) => await invokeWithAutoTraceContext()
|
|
5922
|
+
);
|
|
5923
|
+
return tracedAsyncChild(...inputs);
|
|
5924
|
+
}
|
|
5755
5925
|
const tracedChild = self.withSpan(
|
|
5756
5926
|
traceFunctionKey,
|
|
5757
5927
|
childOptions,
|
|
5758
|
-
(..._inputs) =>
|
|
5928
|
+
(..._inputs) => invokeWithAutoTraceContext()
|
|
5759
5929
|
);
|
|
5760
5930
|
return tracedChild(...inputs);
|
|
5761
5931
|
}
|
|
@@ -6325,18 +6495,17 @@ var Bitfab = class {
|
|
|
6325
6495
|
newStack = [...currentStack, newContext];
|
|
6326
6496
|
const inputs = args;
|
|
6327
6497
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6498
|
+
const replayCtxAtStart = getReplayContext();
|
|
6499
|
+
const testRunId = replayCtxAtStart?.testRunId ?? options.testRunId;
|
|
6328
6500
|
if (isRootSpan && !activeTraceStates.has(traceId)) {
|
|
6329
|
-
const replayCtxAtRoot = getReplayContext();
|
|
6330
6501
|
const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
|
|
6331
6502
|
activeTraceStates.set(traceId, {
|
|
6332
6503
|
traceId,
|
|
6333
6504
|
startedAt,
|
|
6334
6505
|
contexts: [],
|
|
6335
|
-
...
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
...replayCtxAtRoot?.inputSourceTraceId && {
|
|
6339
|
-
inputSourceTraceId: replayCtxAtRoot.inputSourceTraceId
|
|
6506
|
+
...testRunId !== void 0 && { testRunId },
|
|
6507
|
+
...replayCtxAtStart?.inputSourceTraceId && {
|
|
6508
|
+
inputSourceTraceId: replayCtxAtStart.inputSourceTraceId
|
|
6340
6509
|
},
|
|
6341
6510
|
dbSnapshotRef
|
|
6342
6511
|
});
|
|
@@ -6369,9 +6538,7 @@ var Bitfab = class {
|
|
|
6369
6538
|
contexts: newContext.contexts,
|
|
6370
6539
|
prompt: newContext.prompt,
|
|
6371
6540
|
endedAt,
|
|
6372
|
-
...
|
|
6373
|
-
testRunId: replayCtx.testRunId
|
|
6374
|
-
},
|
|
6541
|
+
...testRunId !== void 0 && { testRunId },
|
|
6375
6542
|
...replayCtx?.inputSourceSpanId && {
|
|
6376
6543
|
inputSourceSpanId: replayCtx.inputSourceSpanId
|
|
6377
6544
|
}
|
|
@@ -7087,6 +7254,13 @@ var finalizers = {
|
|
|
7087
7254
|
init_http();
|
|
7088
7255
|
init_replay();
|
|
7089
7256
|
|
|
7257
|
+
// src/replayRegistry.ts
|
|
7258
|
+
init_errors();
|
|
7259
|
+
init_replay();
|
|
7260
|
+
function defineReplayRegistry(registry) {
|
|
7261
|
+
return registry;
|
|
7262
|
+
}
|
|
7263
|
+
|
|
7090
7264
|
// src/node.ts
|
|
7091
7265
|
init_asyncStorage();
|
|
7092
7266
|
assertAsyncStorageRegistered();
|
|
@@ -7108,6 +7282,7 @@ assertAsyncStorageRegistered();
|
|
|
7108
7282
|
ReplayError,
|
|
7109
7283
|
SUPPORTED_PROVIDERS,
|
|
7110
7284
|
__version__,
|
|
7285
|
+
defineReplayRegistry,
|
|
7111
7286
|
finalizers,
|
|
7112
7287
|
flushTraces,
|
|
7113
7288
|
getCurrentReplayBranch,
|