@bitfab/sdk 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-SU7EAKOV.js → chunk-5GWBJGYZ.js} +7 -2
- package/dist/{chunk-SU7EAKOV.js.map → chunk-5GWBJGYZ.js.map} +1 -1
- package/dist/{chunk-GFBQ2AMO.js → chunk-J47KPS77.js} +48 -2
- package/dist/chunk-J47KPS77.js.map +1 -0
- package/dist/{chunk-CWXCVY75.js → chunk-NKX3EY35.js} +146 -23
- package/dist/chunk-NKX3EY35.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-A5UVFNZ3.js → replay-O2WFIRM4.js} +2 -2
- package/dist/replayCli.js +620 -0
- package/dist/replayCli.js.map +1 -0
- package/package.json +6 -2
- package/dist/chunk-CWXCVY75.js.map +0 -1
- package/dist/chunk-GFBQ2AMO.js.map +0 -1
- /package/dist/{replay-A5UVFNZ3.js.map → replay-O2WFIRM4.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
|
@@ -7,12 +7,13 @@ import {
|
|
|
7
7
|
BitfabOpenAITracingProcessor,
|
|
8
8
|
BitfabVercelAiHandler,
|
|
9
9
|
SUPPORTED_PROVIDERS,
|
|
10
|
+
defineReplayRegistry,
|
|
10
11
|
finalizers,
|
|
11
12
|
getCurrentReplayBranch,
|
|
12
13
|
getCurrentSpan,
|
|
13
14
|
getCurrentTrace
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-NKX3EY35.js";
|
|
16
|
+
import "./chunk-J47KPS77.js";
|
|
16
17
|
import {
|
|
17
18
|
BITFAB_PROGRESS_PREFIX,
|
|
18
19
|
BitfabError,
|
|
@@ -24,7 +25,7 @@ import {
|
|
|
24
25
|
flushTraces,
|
|
25
26
|
reportReplayProgress,
|
|
26
27
|
serializeReplayResult
|
|
27
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-5GWBJGYZ.js";
|
|
28
29
|
import "./chunk-H6LZRFMN.js";
|
|
29
30
|
export {
|
|
30
31
|
BITFAB_PROGRESS_PREFIX,
|
|
@@ -43,6 +44,7 @@ export {
|
|
|
43
44
|
ReplayError,
|
|
44
45
|
SUPPORTED_PROVIDERS,
|
|
45
46
|
__version__,
|
|
47
|
+
defineReplayRegistry,
|
|
46
48
|
finalizers,
|
|
47
49
|
flushTraces,
|
|
48
50
|
getCurrentReplayBranch,
|
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.
|
|
91
|
+
__version__ = "0.38.4";
|
|
92
92
|
__packageName__ = "@bitfab/sdk";
|
|
93
93
|
}
|
|
94
94
|
});
|
|
@@ -2811,6 +2811,11 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
|
|
|
2811
2811
|
);
|
|
2812
2812
|
}
|
|
2813
2813
|
}
|
|
2814
|
+
if (options?.traceIds !== void 0 && options?.datasetId !== void 0) {
|
|
2815
|
+
throw new BitfabError(
|
|
2816
|
+
"traceIds and datasetId select different replay sources and cannot be used together."
|
|
2817
|
+
);
|
|
2818
|
+
}
|
|
2814
2819
|
if (options?.limit !== void 0 && options?.traceIds !== void 0) {
|
|
2815
2820
|
try {
|
|
2816
2821
|
console.warn(
|
|
@@ -3138,6 +3143,7 @@ __export(node_exports, {
|
|
|
3138
3143
|
ReplayError: () => ReplayError,
|
|
3139
3144
|
SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
|
|
3140
3145
|
__version__: () => __version__,
|
|
3146
|
+
defineReplayRegistry: () => defineReplayRegistry,
|
|
3141
3147
|
finalizers: () => finalizers,
|
|
3142
3148
|
flushTraces: () => flushTraces,
|
|
3143
3149
|
getCurrentReplayBranch: () => getCurrentReplayBranch,
|
|
@@ -3796,6 +3802,29 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
|
|
|
3796
3802
|
autoTraceState.browserScope = previous;
|
|
3797
3803
|
}
|
|
3798
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
|
+
}
|
|
3799
3828
|
function runWithAutoTraceRootContext(context, fn) {
|
|
3800
3829
|
autoTraceState.activeRoots += 1;
|
|
3801
3830
|
let result;
|
|
@@ -3834,6 +3863,29 @@ function wrapAutoTraceAsyncGenerator(context, source) {
|
|
|
3834
3863
|
};
|
|
3835
3864
|
return wrapped;
|
|
3836
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
|
+
}
|
|
3837
3889
|
function __setBitfabAutoTraceCapturePolicy(client, traceFunctionKey, functionIds) {
|
|
3838
3890
|
const policies = autoTraceState.capturePolicies.get(client) ?? /* @__PURE__ */ new Map();
|
|
3839
3891
|
policies.set(traceFunctionKey, new Set(functionIds));
|
|
@@ -5686,6 +5738,102 @@ var Bitfab = class {
|
|
|
5686
5738
|
const name = fn.name !== "" ? fn.name : traceFunctionKey;
|
|
5687
5739
|
return this.createAutoTraceRoot(traceFunctionKey, name, options, fn);
|
|
5688
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
|
+
}
|
|
5689
5837
|
createAutoTraceRoot(traceFunctionKey, name, options, fn) {
|
|
5690
5838
|
const self = this;
|
|
5691
5839
|
const maxDepth = autoTraceLimit(
|
|
@@ -5724,29 +5872,51 @@ var Bitfab = class {
|
|
|
5724
5872
|
);
|
|
5725
5873
|
};
|
|
5726
5874
|
const autoTraceContext = {
|
|
5727
|
-
invoke(definition, inputs, invokeFn, depth) {
|
|
5875
|
+
invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
|
|
5728
5876
|
const nameParts = definition.name.split(".");
|
|
5729
5877
|
const simpleName = nameParts[nameParts.length - 1];
|
|
5730
|
-
|
|
5731
|
-
|
|
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);
|
|
5732
5884
|
}
|
|
5733
5885
|
if (depth >= maxDepth || spansUsed >= maxSpans) {
|
|
5734
5886
|
warnTruncated();
|
|
5735
|
-
return
|
|
5887
|
+
return invokeWithoutNode();
|
|
5736
5888
|
}
|
|
5737
5889
|
spansUsed += 1;
|
|
5738
5890
|
const childOptions = {
|
|
5739
|
-
name: definition.name,
|
|
5740
|
-
type: "function",
|
|
5891
|
+
name: nodeConfiguration?.name ?? definition.name,
|
|
5892
|
+
type: nodeConfiguration?.type ?? "function",
|
|
5741
5893
|
captureWhen: "nested",
|
|
5742
5894
|
functionId: definition.id,
|
|
5743
|
-
captureContent: capturePolicy.has(definition.id),
|
|
5744
|
-
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
|
+
}
|
|
5745
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
|
+
}
|
|
5746
5916
|
const tracedChild = self.withSpan(
|
|
5747
5917
|
traceFunctionKey,
|
|
5748
5918
|
childOptions,
|
|
5749
|
-
(..._inputs) =>
|
|
5919
|
+
(..._inputs) => invokeWithAutoTraceContext()
|
|
5750
5920
|
);
|
|
5751
5921
|
return tracedChild(...inputs);
|
|
5752
5922
|
}
|
|
@@ -6316,18 +6486,17 @@ var Bitfab = class {
|
|
|
6316
6486
|
newStack = [...currentStack, newContext];
|
|
6317
6487
|
const inputs = args;
|
|
6318
6488
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6489
|
+
const replayCtxAtStart = getReplayContext();
|
|
6490
|
+
const testRunId = replayCtxAtStart?.testRunId ?? options.testRunId;
|
|
6319
6491
|
if (isRootSpan && !activeTraceStates.has(traceId)) {
|
|
6320
|
-
const replayCtxAtRoot = getReplayContext();
|
|
6321
6492
|
const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
|
|
6322
6493
|
activeTraceStates.set(traceId, {
|
|
6323
6494
|
traceId,
|
|
6324
6495
|
startedAt,
|
|
6325
6496
|
contexts: [],
|
|
6326
|
-
...
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
...replayCtxAtRoot?.inputSourceTraceId && {
|
|
6330
|
-
inputSourceTraceId: replayCtxAtRoot.inputSourceTraceId
|
|
6497
|
+
...testRunId !== void 0 && { testRunId },
|
|
6498
|
+
...replayCtxAtStart?.inputSourceTraceId && {
|
|
6499
|
+
inputSourceTraceId: replayCtxAtStart.inputSourceTraceId
|
|
6331
6500
|
},
|
|
6332
6501
|
dbSnapshotRef
|
|
6333
6502
|
});
|
|
@@ -6360,9 +6529,7 @@ var Bitfab = class {
|
|
|
6360
6529
|
contexts: newContext.contexts,
|
|
6361
6530
|
prompt: newContext.prompt,
|
|
6362
6531
|
endedAt,
|
|
6363
|
-
...
|
|
6364
|
-
testRunId: replayCtx.testRunId
|
|
6365
|
-
},
|
|
6532
|
+
...testRunId !== void 0 && { testRunId },
|
|
6366
6533
|
...replayCtx?.inputSourceSpanId && {
|
|
6367
6534
|
inputSourceSpanId: replayCtx.inputSourceSpanId
|
|
6368
6535
|
}
|
|
@@ -7078,6 +7245,13 @@ var finalizers = {
|
|
|
7078
7245
|
init_http();
|
|
7079
7246
|
init_replay();
|
|
7080
7247
|
|
|
7248
|
+
// src/replayRegistry.ts
|
|
7249
|
+
init_errors();
|
|
7250
|
+
init_replay();
|
|
7251
|
+
function defineReplayRegistry(registry) {
|
|
7252
|
+
return registry;
|
|
7253
|
+
}
|
|
7254
|
+
|
|
7081
7255
|
// src/node.ts
|
|
7082
7256
|
init_asyncStorage();
|
|
7083
7257
|
assertAsyncStorageRegistered();
|
|
@@ -7099,6 +7273,7 @@ assertAsyncStorageRegistered();
|
|
|
7099
7273
|
ReplayError,
|
|
7100
7274
|
SUPPORTED_PROVIDERS,
|
|
7101
7275
|
__version__,
|
|
7276
|
+
defineReplayRegistry,
|
|
7102
7277
|
finalizers,
|
|
7103
7278
|
flushTraces,
|
|
7104
7279
|
getCurrentReplayBranch,
|