@bitfab/sdk 0.38.4 → 0.38.6
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 +8 -1
- package/dist/autoTrace.cjs.map +1 -1
- package/dist/autoTrace.d.cts +2 -2
- package/dist/autoTrace.d.ts +2 -2
- package/dist/autoTrace.js +1 -1
- package/dist/{chunk-NKX3EY35.js → chunk-P2MYK27A.js} +154 -68
- package/dist/chunk-P2MYK27A.js.map +1 -0
- package/dist/{chunk-5GWBJGYZ.js → chunk-QTTKZMHM.js} +8 -3
- package/dist/{chunk-5GWBJGYZ.js.map → chunk-QTTKZMHM.js.map} +1 -1
- package/dist/{chunk-J47KPS77.js → chunk-ZUD7OFYB.js} +9 -2
- package/dist/{chunk-J47KPS77.js.map → chunk-ZUD7OFYB.js.map} +1 -1
- package/dist/index.cjs +167 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -11
- package/dist/index.d.ts +41 -11
- package/dist/index.js +5 -3
- package/dist/node.cjs +167 -67
- 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-O2WFIRM4.js → replay-H3AS4IF2.js} +2 -2
- package/dist/replayCli.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-NKX3EY35.js.map +0 -1
- /package/dist/{replay-O2WFIRM4.js.map → replay-H3AS4IF2.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -147,10 +147,23 @@ interface MockOverrideCtx {
|
|
|
147
147
|
*/
|
|
148
148
|
getOriginalOutput: () => Promise<unknown>;
|
|
149
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Return this from a mock override resolver to decline the override for the
|
|
152
|
+
* current span. Resolution continues with the next override, then the replay's
|
|
153
|
+
* base mock strategy.
|
|
154
|
+
*/
|
|
155
|
+
declare const NO_MOCK_OVERRIDE: unique symbol;
|
|
150
156
|
/** Selects which spans an override applies to. Runs on structural metadata. */
|
|
151
157
|
type NodeMatcher = (node: SpanNodeMeta) => boolean;
|
|
152
158
|
/** The function form of {@link MockValue}, receiving the override context. */
|
|
153
159
|
type MockValueFn = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
|
|
160
|
+
/**
|
|
161
|
+
* A client-wide, keyed, or per-replay resolver. A global resolver can route on
|
|
162
|
+
* `ctx.node.traceFunctionKey`; a keyed resolver is only invoked for spans with
|
|
163
|
+
* its registered key. Return {@link NO_MOCK_OVERRIDE} for spans the resolver
|
|
164
|
+
* does not want to override.
|
|
165
|
+
*/
|
|
166
|
+
type MockOverrideResolver = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
|
|
154
167
|
/**
|
|
155
168
|
* The value injected for a matched span: either a flat value used as-is, or a
|
|
156
169
|
* function of the {@link MockOverrideCtx} that returns one (or a Promise of
|
|
@@ -168,6 +181,8 @@ interface MockOverride {
|
|
|
168
181
|
match: NodeMatcher;
|
|
169
182
|
value: MockValue;
|
|
170
183
|
}
|
|
184
|
+
/** Accepted shape for one mock override declaration. */
|
|
185
|
+
type MockOverrideInput = MockOverride | MockOverrideResolver;
|
|
171
186
|
|
|
172
187
|
/**
|
|
173
188
|
* Replay context propagation via AsyncLocalStorage.
|
|
@@ -1268,12 +1283,12 @@ interface ReplayOptions {
|
|
|
1268
1283
|
/**
|
|
1269
1284
|
* Selective mock overrides: inject custom values into specific spans during
|
|
1270
1285
|
* replay, so downstream real code runs against the substituted output. Each
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1286
|
+
* Pass `{ match, value }` pairs, or one resolver invoked for every child span.
|
|
1287
|
+
* A resolver can route on `ctx.node.traceFunctionKey` and return
|
|
1288
|
+
* `NO_MOCK_OVERRIDE` to continue to the next override and base strategy.
|
|
1289
|
+
* Per-call overrides take precedence over registrations on the client.
|
|
1275
1290
|
*/
|
|
1276
|
-
mockOverride?:
|
|
1291
|
+
mockOverride?: MockOverrideInput | MockOverrideInput[];
|
|
1277
1292
|
/**
|
|
1278
1293
|
* Run each item against a database branch restored to the state its source
|
|
1279
1294
|
* trace saw. Pass `true` to branch with the mirror project's own sizing, or a
|
|
@@ -2168,8 +2183,9 @@ declare class Bitfab {
|
|
|
2168
2183
|
* Decorate a class method as an automatically expanded trace root.
|
|
2169
2184
|
*
|
|
2170
2185
|
* Build instrumentation turns repository functions called beneath this
|
|
2171
|
-
* method into nested spans
|
|
2172
|
-
*
|
|
2186
|
+
* method into nested spans that capture inputs, outputs, and errors by
|
|
2187
|
+
* default. A confirmed capture policy can narrow rich capture to selected
|
|
2188
|
+
* function IDs.
|
|
2173
2189
|
* Without a compatible build transform, this still records the decorated
|
|
2174
2190
|
* method as a normal rich root span but cannot discover child calls.
|
|
2175
2191
|
*
|
|
@@ -2183,8 +2199,10 @@ declare class Bitfab {
|
|
|
2183
2199
|
*
|
|
2184
2200
|
* This is the function-oriented equivalent of {@link Bitfab.trace}. Build
|
|
2185
2201
|
* instrumentation turns repository functions called beneath the wrapped
|
|
2186
|
-
* function into nested spans
|
|
2187
|
-
*
|
|
2202
|
+
* function into nested spans that capture inputs, outputs, and errors by
|
|
2203
|
+
* default. A confirmed capture policy can narrow rich capture to selected
|
|
2204
|
+
* function IDs. Without a compatible transform, this still records one
|
|
2205
|
+
* normal rich root span and runs the function unchanged.
|
|
2188
2206
|
*
|
|
2189
2207
|
* @param traceFunctionKey - Groups traces and their capture policy.
|
|
2190
2208
|
* @param optionsOrFn - Options or the workflow entrypoint to wrap.
|
|
@@ -2584,10 +2602,22 @@ declare class Bitfab {
|
|
|
2584
2602
|
* (node) => node.traceFunctionKey === "classify-intent",
|
|
2585
2603
|
* ({ inputs }) => ({ label: "refund" }),
|
|
2586
2604
|
* )
|
|
2605
|
+
* // Keyed form: the resolver only sees spans for this trace function key.
|
|
2606
|
+
* bitfab.registerMockOverride("classify-intent", ({ inputs }) => ({
|
|
2607
|
+
* label: String(inputs[0]),
|
|
2608
|
+
* }))
|
|
2609
|
+
* // Or one resolver for every child span:
|
|
2610
|
+
* bitfab.registerMockOverride(({ node }) =>
|
|
2611
|
+
* node.traceFunctionKey === "classify-intent"
|
|
2612
|
+
* ? { label: "refund" }
|
|
2613
|
+
* : NO_MOCK_OVERRIDE,
|
|
2614
|
+
* )
|
|
2587
2615
|
* ```
|
|
2588
2616
|
*/
|
|
2589
2617
|
registerMockOverride(override: MockOverride): void;
|
|
2618
|
+
registerMockOverride(resolver: MockOverrideResolver): void;
|
|
2590
2619
|
registerMockOverride(match: NodeMatcher, value: MockValue): void;
|
|
2620
|
+
registerMockOverride(traceFunctionKey: string, override: MockOverride | MockOverrideResolver): void;
|
|
2591
2621
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
2592
2622
|
clearMockOverrides(): void;
|
|
2593
2623
|
replay<TReturn>(traceFunctionKey: string, fn: (...args: any[]) => TReturn | Promise<TReturn>, options?: ReplayOptions): Promise<ReplayResult<TReturn>>;
|
|
@@ -2759,7 +2789,7 @@ declare class BitfabFunction {
|
|
|
2759
2789
|
/**
|
|
2760
2790
|
* SDK version from package.json (injected at build time)
|
|
2761
2791
|
*/
|
|
2762
|
-
declare const __version__ = "0.38.
|
|
2792
|
+
declare const __version__ = "0.38.6";
|
|
2763
2793
|
|
|
2764
2794
|
/**
|
|
2765
2795
|
* Constants for the Bitfab SDK.
|
|
@@ -2862,4 +2892,4 @@ type ReplayRegistry = Record<string, ReplayRegistration>;
|
|
|
2862
2892
|
*/
|
|
2863
2893
|
declare function defineReplayRegistry<TRegistry extends ReplayRegistry>(registry: TRegistry): TRegistry;
|
|
2864
2894
|
|
|
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 };
|
|
2895
|
+
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 MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, 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
|
@@ -147,10 +147,23 @@ interface MockOverrideCtx {
|
|
|
147
147
|
*/
|
|
148
148
|
getOriginalOutput: () => Promise<unknown>;
|
|
149
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Return this from a mock override resolver to decline the override for the
|
|
152
|
+
* current span. Resolution continues with the next override, then the replay's
|
|
153
|
+
* base mock strategy.
|
|
154
|
+
*/
|
|
155
|
+
declare const NO_MOCK_OVERRIDE: unique symbol;
|
|
150
156
|
/** Selects which spans an override applies to. Runs on structural metadata. */
|
|
151
157
|
type NodeMatcher = (node: SpanNodeMeta) => boolean;
|
|
152
158
|
/** The function form of {@link MockValue}, receiving the override context. */
|
|
153
159
|
type MockValueFn = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
|
|
160
|
+
/**
|
|
161
|
+
* A client-wide, keyed, or per-replay resolver. A global resolver can route on
|
|
162
|
+
* `ctx.node.traceFunctionKey`; a keyed resolver is only invoked for spans with
|
|
163
|
+
* its registered key. Return {@link NO_MOCK_OVERRIDE} for spans the resolver
|
|
164
|
+
* does not want to override.
|
|
165
|
+
*/
|
|
166
|
+
type MockOverrideResolver = (ctx: MockOverrideCtx) => unknown | Promise<unknown>;
|
|
154
167
|
/**
|
|
155
168
|
* The value injected for a matched span: either a flat value used as-is, or a
|
|
156
169
|
* function of the {@link MockOverrideCtx} that returns one (or a Promise of
|
|
@@ -168,6 +181,8 @@ interface MockOverride {
|
|
|
168
181
|
match: NodeMatcher;
|
|
169
182
|
value: MockValue;
|
|
170
183
|
}
|
|
184
|
+
/** Accepted shape for one mock override declaration. */
|
|
185
|
+
type MockOverrideInput = MockOverride | MockOverrideResolver;
|
|
171
186
|
|
|
172
187
|
/**
|
|
173
188
|
* Replay context propagation via AsyncLocalStorage.
|
|
@@ -1268,12 +1283,12 @@ interface ReplayOptions {
|
|
|
1268
1283
|
/**
|
|
1269
1284
|
* Selective mock overrides: inject custom values into specific spans during
|
|
1270
1285
|
* replay, so downstream real code runs against the substituted output. Each
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1286
|
+
* Pass `{ match, value }` pairs, or one resolver invoked for every child span.
|
|
1287
|
+
* A resolver can route on `ctx.node.traceFunctionKey` and return
|
|
1288
|
+
* `NO_MOCK_OVERRIDE` to continue to the next override and base strategy.
|
|
1289
|
+
* Per-call overrides take precedence over registrations on the client.
|
|
1275
1290
|
*/
|
|
1276
|
-
mockOverride?:
|
|
1291
|
+
mockOverride?: MockOverrideInput | MockOverrideInput[];
|
|
1277
1292
|
/**
|
|
1278
1293
|
* Run each item against a database branch restored to the state its source
|
|
1279
1294
|
* trace saw. Pass `true` to branch with the mirror project's own sizing, or a
|
|
@@ -2168,8 +2183,9 @@ declare class Bitfab {
|
|
|
2168
2183
|
* Decorate a class method as an automatically expanded trace root.
|
|
2169
2184
|
*
|
|
2170
2185
|
* Build instrumentation turns repository functions called beneath this
|
|
2171
|
-
* method into nested spans
|
|
2172
|
-
*
|
|
2186
|
+
* method into nested spans that capture inputs, outputs, and errors by
|
|
2187
|
+
* default. A confirmed capture policy can narrow rich capture to selected
|
|
2188
|
+
* function IDs.
|
|
2173
2189
|
* Without a compatible build transform, this still records the decorated
|
|
2174
2190
|
* method as a normal rich root span but cannot discover child calls.
|
|
2175
2191
|
*
|
|
@@ -2183,8 +2199,10 @@ declare class Bitfab {
|
|
|
2183
2199
|
*
|
|
2184
2200
|
* This is the function-oriented equivalent of {@link Bitfab.trace}. Build
|
|
2185
2201
|
* instrumentation turns repository functions called beneath the wrapped
|
|
2186
|
-
* function into nested spans
|
|
2187
|
-
*
|
|
2202
|
+
* function into nested spans that capture inputs, outputs, and errors by
|
|
2203
|
+
* default. A confirmed capture policy can narrow rich capture to selected
|
|
2204
|
+
* function IDs. Without a compatible transform, this still records one
|
|
2205
|
+
* normal rich root span and runs the function unchanged.
|
|
2188
2206
|
*
|
|
2189
2207
|
* @param traceFunctionKey - Groups traces and their capture policy.
|
|
2190
2208
|
* @param optionsOrFn - Options or the workflow entrypoint to wrap.
|
|
@@ -2584,10 +2602,22 @@ declare class Bitfab {
|
|
|
2584
2602
|
* (node) => node.traceFunctionKey === "classify-intent",
|
|
2585
2603
|
* ({ inputs }) => ({ label: "refund" }),
|
|
2586
2604
|
* )
|
|
2605
|
+
* // Keyed form: the resolver only sees spans for this trace function key.
|
|
2606
|
+
* bitfab.registerMockOverride("classify-intent", ({ inputs }) => ({
|
|
2607
|
+
* label: String(inputs[0]),
|
|
2608
|
+
* }))
|
|
2609
|
+
* // Or one resolver for every child span:
|
|
2610
|
+
* bitfab.registerMockOverride(({ node }) =>
|
|
2611
|
+
* node.traceFunctionKey === "classify-intent"
|
|
2612
|
+
* ? { label: "refund" }
|
|
2613
|
+
* : NO_MOCK_OVERRIDE,
|
|
2614
|
+
* )
|
|
2587
2615
|
* ```
|
|
2588
2616
|
*/
|
|
2589
2617
|
registerMockOverride(override: MockOverride): void;
|
|
2618
|
+
registerMockOverride(resolver: MockOverrideResolver): void;
|
|
2590
2619
|
registerMockOverride(match: NodeMatcher, value: MockValue): void;
|
|
2620
|
+
registerMockOverride(traceFunctionKey: string, override: MockOverride | MockOverrideResolver): void;
|
|
2591
2621
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
2592
2622
|
clearMockOverrides(): void;
|
|
2593
2623
|
replay<TReturn>(traceFunctionKey: string, fn: (...args: any[]) => TReturn | Promise<TReturn>, options?: ReplayOptions): Promise<ReplayResult<TReturn>>;
|
|
@@ -2759,7 +2789,7 @@ declare class BitfabFunction {
|
|
|
2759
2789
|
/**
|
|
2760
2790
|
* SDK version from package.json (injected at build time)
|
|
2761
2791
|
*/
|
|
2762
|
-
declare const __version__ = "0.38.
|
|
2792
|
+
declare const __version__ = "0.38.6";
|
|
2763
2793
|
|
|
2764
2794
|
/**
|
|
2765
2795
|
* Constants for the Bitfab SDK.
|
|
@@ -2862,4 +2892,4 @@ type ReplayRegistry = Record<string, ReplayRegistration>;
|
|
|
2862
2892
|
*/
|
|
2863
2893
|
declare function defineReplayRegistry<TRegistry extends ReplayRegistry>(registry: TRegistry): TRegistry;
|
|
2864
2894
|
|
|
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 };
|
|
2895
|
+
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 MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
|
package/dist/index.js
CHANGED
|
@@ -12,20 +12,21 @@ import {
|
|
|
12
12
|
getCurrentReplayBranch,
|
|
13
13
|
getCurrentSpan,
|
|
14
14
|
getCurrentTrace
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-P2MYK27A.js";
|
|
16
|
+
import "./chunk-ZUD7OFYB.js";
|
|
17
17
|
import {
|
|
18
18
|
BITFAB_PROGRESS_PREFIX,
|
|
19
19
|
BitfabError,
|
|
20
20
|
DEFAULT_SERVICE_URL,
|
|
21
21
|
DbBranchReplayError,
|
|
22
22
|
HttpClient,
|
|
23
|
+
NO_MOCK_OVERRIDE,
|
|
23
24
|
ReplayError,
|
|
24
25
|
__version__,
|
|
25
26
|
flushTraces,
|
|
26
27
|
reportReplayProgress,
|
|
27
28
|
serializeReplayResult
|
|
28
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-QTTKZMHM.js";
|
|
29
30
|
import "./chunk-H6LZRFMN.js";
|
|
30
31
|
export {
|
|
31
32
|
BITFAB_PROGRESS_PREFIX,
|
|
@@ -41,6 +42,7 @@ export {
|
|
|
41
42
|
DEFAULT_SERVICE_URL,
|
|
42
43
|
DbBranchReplayError,
|
|
43
44
|
HttpClient,
|
|
45
|
+
NO_MOCK_OVERRIDE,
|
|
44
46
|
ReplayError,
|
|
45
47
|
SUPPORTED_PROVIDERS,
|
|
46
48
|
__version__,
|
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.6";
|
|
92
92
|
__packageName__ = "@bitfab/sdk";
|
|
93
93
|
}
|
|
94
94
|
});
|
|
@@ -2194,11 +2194,16 @@ function normalizeMockOverrides(mockOverride) {
|
|
|
2194
2194
|
if (mockOverride === void 0) {
|
|
2195
2195
|
return [];
|
|
2196
2196
|
}
|
|
2197
|
-
|
|
2197
|
+
const overrides = Array.isArray(mockOverride) ? mockOverride : [mockOverride];
|
|
2198
|
+
return overrides.map(
|
|
2199
|
+
(override) => typeof override === "function" ? { match: () => true, value: override } : override
|
|
2200
|
+
);
|
|
2198
2201
|
}
|
|
2202
|
+
var NO_MOCK_OVERRIDE;
|
|
2199
2203
|
var init_mockOverride = __esm({
|
|
2200
2204
|
"src/mockOverride.ts"() {
|
|
2201
2205
|
"use strict";
|
|
2206
|
+
NO_MOCK_OVERRIDE = /* @__PURE__ */ Symbol("bitfab.noMockOverride");
|
|
2202
2207
|
}
|
|
2203
2208
|
});
|
|
2204
2209
|
|
|
@@ -3140,6 +3145,7 @@ __export(node_exports, {
|
|
|
3140
3145
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
3141
3146
|
DbBranchReplayError: () => DbBranchReplayError,
|
|
3142
3147
|
HttpClient: () => HttpClient,
|
|
3148
|
+
NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
|
|
3143
3149
|
ReplayError: () => ReplayError,
|
|
3144
3150
|
SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
|
|
3145
3151
|
__version__: () => __version__,
|
|
@@ -3888,11 +3894,18 @@ function currentAutoTraceScope() {
|
|
|
3888
3894
|
}
|
|
3889
3895
|
function __setBitfabAutoTraceCapturePolicy(client, traceFunctionKey, functionIds) {
|
|
3890
3896
|
const policies = autoTraceState.capturePolicies.get(client) ?? /* @__PURE__ */ new Map();
|
|
3897
|
+
if (functionIds === void 0) {
|
|
3898
|
+
policies.delete(traceFunctionKey);
|
|
3899
|
+
if (policies.size === 0) {
|
|
3900
|
+
autoTraceState.capturePolicies.delete(client);
|
|
3901
|
+
}
|
|
3902
|
+
return;
|
|
3903
|
+
}
|
|
3891
3904
|
policies.set(traceFunctionKey, new Set(functionIds));
|
|
3892
3905
|
autoTraceState.capturePolicies.set(client, policies);
|
|
3893
3906
|
}
|
|
3894
3907
|
function getAutoTraceCapturePolicy(client, traceFunctionKey) {
|
|
3895
|
-
return autoTraceState.capturePolicies.get(client)?.get(traceFunctionKey)
|
|
3908
|
+
return autoTraceState.capturePolicies.get(client)?.get(traceFunctionKey);
|
|
3896
3909
|
}
|
|
3897
3910
|
|
|
3898
3911
|
// src/optionalPeer.ts
|
|
@@ -5681,8 +5694,9 @@ var Bitfab = class {
|
|
|
5681
5694
|
* Decorate a class method as an automatically expanded trace root.
|
|
5682
5695
|
*
|
|
5683
5696
|
* Build instrumentation turns repository functions called beneath this
|
|
5684
|
-
* method into nested spans
|
|
5685
|
-
*
|
|
5697
|
+
* method into nested spans that capture inputs, outputs, and errors by
|
|
5698
|
+
* default. A confirmed capture policy can narrow rich capture to selected
|
|
5699
|
+
* function IDs.
|
|
5686
5700
|
* Without a compatible build transform, this still records the decorated
|
|
5687
5701
|
* method as a normal rich root span but cannot discover child calls.
|
|
5688
5702
|
*
|
|
@@ -5892,7 +5906,7 @@ var Bitfab = class {
|
|
|
5892
5906
|
type: nodeConfiguration?.type ?? "function",
|
|
5893
5907
|
captureWhen: "nested",
|
|
5894
5908
|
functionId: definition.id,
|
|
5895
|
-
captureContent: nodeConfiguration !== void 0 || capturePolicy.has(definition.id),
|
|
5909
|
+
captureContent: nodeConfiguration !== void 0 || capturePolicy === void 0 || capturePolicy.has(definition.id),
|
|
5896
5910
|
autoTraceDefinition: definition,
|
|
5897
5911
|
...nodeConfiguration?.testRunId !== void 0 && {
|
|
5898
5912
|
testRunId: nodeConfiguration.testRunId
|
|
@@ -5957,7 +5971,11 @@ var Bitfab = class {
|
|
|
5957
5971
|
const functionIds = Array.isArray(policy.functionIds) ? policy.functionIds.filter(
|
|
5958
5972
|
(id) => typeof id === "string" && id.startsWith(`${AUTO_TRACE_PROTOCOL}:`)
|
|
5959
5973
|
).slice(0, DEFAULT_AUTO_TRACE_MAX_SPANS) : [];
|
|
5960
|
-
__setBitfabAutoTraceCapturePolicy(
|
|
5974
|
+
__setBitfabAutoTraceCapturePolicy(
|
|
5975
|
+
this,
|
|
5976
|
+
traceFunctionKey,
|
|
5977
|
+
policy.revision === null ? void 0 : functionIds
|
|
5978
|
+
);
|
|
5961
5979
|
state.refreshAfter = Date.now() + AUTO_TRACE_POLICY_REFRESH_MS;
|
|
5962
5980
|
}).catch(() => {
|
|
5963
5981
|
state.refreshAfter = Date.now() + AUTO_TRACE_POLICY_RETRY_MS;
|
|
@@ -6569,6 +6587,49 @@ var Bitfab = class {
|
|
|
6569
6587
|
} catch {
|
|
6570
6588
|
}
|
|
6571
6589
|
};
|
|
6590
|
+
const recordSpan = (result) => {
|
|
6591
|
+
if (options.finalize) {
|
|
6592
|
+
void self.httpClient.trackDeferred(
|
|
6593
|
+
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6594
|
+
(error) => sendSpan({
|
|
6595
|
+
result: void 0,
|
|
6596
|
+
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6597
|
+
})
|
|
6598
|
+
)
|
|
6599
|
+
);
|
|
6600
|
+
} else {
|
|
6601
|
+
void sendSpan({ result });
|
|
6602
|
+
}
|
|
6603
|
+
};
|
|
6604
|
+
executeWithContext = () => {
|
|
6605
|
+
let result;
|
|
6606
|
+
try {
|
|
6607
|
+
result = fn.apply(this, args);
|
|
6608
|
+
} catch (error) {
|
|
6609
|
+
void sendSpan({
|
|
6610
|
+
result: void 0,
|
|
6611
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6612
|
+
});
|
|
6613
|
+
throw error;
|
|
6614
|
+
}
|
|
6615
|
+
if (result instanceof Promise) {
|
|
6616
|
+
return result.then((resolvedResult) => {
|
|
6617
|
+
recordSpan(resolvedResult);
|
|
6618
|
+
return resolvedResult;
|
|
6619
|
+
}).catch((error) => {
|
|
6620
|
+
void sendSpan({
|
|
6621
|
+
result: void 0,
|
|
6622
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6623
|
+
});
|
|
6624
|
+
throw error;
|
|
6625
|
+
});
|
|
6626
|
+
}
|
|
6627
|
+
if (isAsyncGenerator(result)) {
|
|
6628
|
+
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6629
|
+
}
|
|
6630
|
+
recordSpan(result);
|
|
6631
|
+
return result;
|
|
6632
|
+
};
|
|
6572
6633
|
const replayCtxForMock = getReplayContext();
|
|
6573
6634
|
if (replayCtxForMock?.mockTree && !isRootSpan) {
|
|
6574
6635
|
const counters = replayCtxForMock.callCounters;
|
|
@@ -6627,6 +6688,7 @@ var Bitfab = class {
|
|
|
6627
6688
|
}
|
|
6628
6689
|
return output;
|
|
6629
6690
|
};
|
|
6691
|
+
const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
|
|
6630
6692
|
if (replayCtxForMock.mockOverrides?.length) {
|
|
6631
6693
|
const nodeMeta = {
|
|
6632
6694
|
traceFunctionKey,
|
|
@@ -6634,28 +6696,75 @@ var Bitfab = class {
|
|
|
6634
6696
|
type: options.type ?? "custom",
|
|
6635
6697
|
originalSpanId: mockSpan?.sourceSpanId
|
|
6636
6698
|
};
|
|
6637
|
-
const
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6699
|
+
const overrideCtx = {
|
|
6700
|
+
node: nodeMeta,
|
|
6701
|
+
inputs: args,
|
|
6702
|
+
getOriginalOutput: () => Promise.resolve(resolveRecordedOutput())
|
|
6703
|
+
};
|
|
6704
|
+
const resolveOverrideFrom = (startIndex) => {
|
|
6705
|
+
for (let index = startIndex; index < replayCtxForMock.mockOverrides.length; index += 1) {
|
|
6706
|
+
const override = replayCtxForMock.mockOverrides[index];
|
|
6707
|
+
if (!override?.match(nodeMeta)) {
|
|
6708
|
+
continue;
|
|
6709
|
+
}
|
|
6710
|
+
const injected = resolveMockValue(override.value, overrideCtx);
|
|
6711
|
+
if (injected instanceof Promise) {
|
|
6712
|
+
return injected.then(
|
|
6713
|
+
(output) => output === NO_MOCK_OVERRIDE ? resolveOverrideFrom(index + 1) : { matched: true, output }
|
|
6714
|
+
);
|
|
6715
|
+
}
|
|
6716
|
+
if (injected !== NO_MOCK_OVERRIDE) {
|
|
6717
|
+
return { matched: true, output: injected };
|
|
6718
|
+
}
|
|
6648
6719
|
}
|
|
6649
|
-
return
|
|
6720
|
+
return { matched: false };
|
|
6721
|
+
};
|
|
6722
|
+
const resolution = resolveOverrideFrom(0);
|
|
6723
|
+
if (resolution instanceof Promise) {
|
|
6724
|
+
if (!fnReturnsPromise) {
|
|
6725
|
+
throw new BitfabError(
|
|
6726
|
+
`Cannot resolve an asynchronous mock override for synchronous span "${traceFunctionKey}". Make the wrapped function async or return NO_MOCK_OVERRIDE synchronously.`
|
|
6727
|
+
);
|
|
6728
|
+
}
|
|
6729
|
+
return runWithSpanStack(newStack, async () => {
|
|
6730
|
+
const resolved = await resolution;
|
|
6731
|
+
if (resolved.matched) {
|
|
6732
|
+
void sendSpan({
|
|
6733
|
+
result: resolved.output,
|
|
6734
|
+
mocked: true,
|
|
6735
|
+
mockTarget: "output",
|
|
6736
|
+
mockSource: "override"
|
|
6737
|
+
});
|
|
6738
|
+
return resolved.output;
|
|
6739
|
+
}
|
|
6740
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6741
|
+
throw new BitfabError(
|
|
6742
|
+
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6743
|
+
);
|
|
6744
|
+
}
|
|
6745
|
+
if (shouldMockWithBaseStrategy) {
|
|
6746
|
+
const output = await resolveRecordedOutput();
|
|
6747
|
+
void sendSpan({
|
|
6748
|
+
result: output,
|
|
6749
|
+
mocked: true,
|
|
6750
|
+
mockTarget: "output",
|
|
6751
|
+
mockSource: "recorded"
|
|
6752
|
+
});
|
|
6753
|
+
return output;
|
|
6754
|
+
}
|
|
6755
|
+
return executeWithContext();
|
|
6756
|
+
});
|
|
6757
|
+
}
|
|
6758
|
+
if (resolution.matched) {
|
|
6759
|
+
return emitMock(resolution.output, "override");
|
|
6650
6760
|
}
|
|
6651
6761
|
}
|
|
6652
|
-
|
|
6653
|
-
if (shouldMock && !mockSpan) {
|
|
6762
|
+
if (shouldMockWithBaseStrategy && !mockSpan) {
|
|
6654
6763
|
throw new BitfabError(
|
|
6655
6764
|
`Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
|
|
6656
6765
|
);
|
|
6657
6766
|
}
|
|
6658
|
-
if (
|
|
6767
|
+
if (shouldMockWithBaseStrategy) {
|
|
6659
6768
|
const recorded = resolveRecordedOutput();
|
|
6660
6769
|
if (recorded instanceof Promise) {
|
|
6661
6770
|
return emitMockAsync(recorded, "recorded");
|
|
@@ -6663,49 +6772,6 @@ var Bitfab = class {
|
|
|
6663
6772
|
return emitMock(recorded, "recorded");
|
|
6664
6773
|
}
|
|
6665
6774
|
}
|
|
6666
|
-
const recordSpan = (result) => {
|
|
6667
|
-
if (options.finalize) {
|
|
6668
|
-
void self.httpClient.trackDeferred(
|
|
6669
|
-
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
6670
|
-
(error) => sendSpan({
|
|
6671
|
-
result: void 0,
|
|
6672
|
-
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
6673
|
-
})
|
|
6674
|
-
)
|
|
6675
|
-
);
|
|
6676
|
-
} else {
|
|
6677
|
-
void sendSpan({ result });
|
|
6678
|
-
}
|
|
6679
|
-
};
|
|
6680
|
-
executeWithContext = () => {
|
|
6681
|
-
let result;
|
|
6682
|
-
try {
|
|
6683
|
-
result = fn.apply(this, args);
|
|
6684
|
-
} catch (error) {
|
|
6685
|
-
void sendSpan({
|
|
6686
|
-
result: void 0,
|
|
6687
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6688
|
-
});
|
|
6689
|
-
throw error;
|
|
6690
|
-
}
|
|
6691
|
-
if (result instanceof Promise) {
|
|
6692
|
-
return result.then((resolvedResult) => {
|
|
6693
|
-
recordSpan(resolvedResult);
|
|
6694
|
-
return resolvedResult;
|
|
6695
|
-
}).catch((error) => {
|
|
6696
|
-
void sendSpan({
|
|
6697
|
-
result: void 0,
|
|
6698
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6699
|
-
});
|
|
6700
|
-
throw error;
|
|
6701
|
-
});
|
|
6702
|
-
}
|
|
6703
|
-
if (isAsyncGenerator(result)) {
|
|
6704
|
-
return wrapAsyncGenerator(result, newStack, sendSpan);
|
|
6705
|
-
}
|
|
6706
|
-
recordSpan(result);
|
|
6707
|
-
return result;
|
|
6708
|
-
};
|
|
6709
6775
|
} catch (setupError) {
|
|
6710
6776
|
if (registeredTraceId) {
|
|
6711
6777
|
activeTraceStates.delete(registeredTraceId);
|
|
@@ -6992,8 +7058,40 @@ var Bitfab = class {
|
|
|
6992
7058
|
...params.mockSource && { mockSource: params.mockSource }
|
|
6993
7059
|
});
|
|
6994
7060
|
}
|
|
6995
|
-
registerMockOverride(
|
|
6996
|
-
|
|
7061
|
+
registerMockOverride(overrideOrResolverOrMatch, ...values) {
|
|
7062
|
+
let override;
|
|
7063
|
+
if (typeof overrideOrResolverOrMatch === "string") {
|
|
7064
|
+
const keyedOverride = values[0];
|
|
7065
|
+
if (values.length !== 1 || keyedOverride === void 0) {
|
|
7066
|
+
throw new BitfabError(
|
|
7067
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7068
|
+
);
|
|
7069
|
+
}
|
|
7070
|
+
if (typeof keyedOverride === "function") {
|
|
7071
|
+
override = {
|
|
7072
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch,
|
|
7073
|
+
value: keyedOverride
|
|
7074
|
+
};
|
|
7075
|
+
} else if (typeof keyedOverride === "object" && keyedOverride !== null && "match" in keyedOverride && "value" in keyedOverride) {
|
|
7076
|
+
override = {
|
|
7077
|
+
match: (node) => node.traceFunctionKey === overrideOrResolverOrMatch && keyedOverride.match(node),
|
|
7078
|
+
value: keyedOverride.value
|
|
7079
|
+
};
|
|
7080
|
+
} else {
|
|
7081
|
+
throw new BitfabError(
|
|
7082
|
+
"registerMockOverride(traceFunctionKey, override) requires a resolver function or { match, value } override."
|
|
7083
|
+
);
|
|
7084
|
+
}
|
|
7085
|
+
} else if (typeof overrideOrResolverOrMatch !== "function") {
|
|
7086
|
+
override = overrideOrResolverOrMatch;
|
|
7087
|
+
} else if (values.length === 0) {
|
|
7088
|
+
override = { match: () => true, value: overrideOrResolverOrMatch };
|
|
7089
|
+
} else {
|
|
7090
|
+
override = {
|
|
7091
|
+
match: overrideOrResolverOrMatch,
|
|
7092
|
+
value: values[0]
|
|
7093
|
+
};
|
|
7094
|
+
}
|
|
6997
7095
|
this.mockOverrides.push(override);
|
|
6998
7096
|
}
|
|
6999
7097
|
/** Remove all overrides registered via {@link registerMockOverride}. */
|
|
@@ -7243,6 +7341,7 @@ var finalizers = {
|
|
|
7243
7341
|
|
|
7244
7342
|
// src/index.ts
|
|
7245
7343
|
init_http();
|
|
7344
|
+
init_mockOverride();
|
|
7246
7345
|
init_replay();
|
|
7247
7346
|
|
|
7248
7347
|
// src/replayRegistry.ts
|
|
@@ -7270,6 +7369,7 @@ assertAsyncStorageRegistered();
|
|
|
7270
7369
|
DEFAULT_SERVICE_URL,
|
|
7271
7370
|
DbBranchReplayError,
|
|
7272
7371
|
HttpClient,
|
|
7372
|
+
NO_MOCK_OVERRIDE,
|
|
7273
7373
|
ReplayError,
|
|
7274
7374
|
SUPPORTED_PROVIDERS,
|
|
7275
7375
|
__version__,
|