bitfab 0.15.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-YPG3XIG4.js → chunk-P4WFJ5O3.js} +6 -6
- package/dist/{chunk-YPG3XIG4.js.map → chunk-P4WFJ5O3.js.map} +1 -1
- package/dist/index.cjs +19 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -8
- package/dist/index.d.ts +47 -8
- package/dist/index.js +1 -1
- package/dist/node.cjs +19 -9
- 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 +1 -1
- package/dist/{replay-3MQS22GS.js → replay-BIPIDXX6.js} +16 -6
- package/dist/replay-BIPIDXX6.js.map +1 -0
- package/package.json +1 -1
- package/dist/replay-3MQS22GS.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -343,9 +343,9 @@ declare class ReplayEnvironment {
|
|
|
343
343
|
type MockStrategy = "none" | "all" | "marked";
|
|
344
344
|
interface ReplayOptions {
|
|
345
345
|
/**
|
|
346
|
-
* Maximum number of traces to replay (1
|
|
347
|
-
*
|
|
348
|
-
* many traces replay
|
|
346
|
+
* Maximum number of traces to replay (1-100, default 5). Ignored when
|
|
347
|
+
* `traceIds` is passed (with a warning): an explicit ID list already
|
|
348
|
+
* determines how many traces replay.
|
|
349
349
|
*/
|
|
350
350
|
limit?: number;
|
|
351
351
|
/** Optional list of specific trace IDs to replay (max 100). */
|
|
@@ -380,7 +380,46 @@ interface ReplayOptions {
|
|
|
380
380
|
environment?: ReplayEnvironment;
|
|
381
381
|
/** Group ID to associate this replay with an experiment group for live streaming in Studio. */
|
|
382
382
|
experimentGroupId?: string;
|
|
383
|
+
/**
|
|
384
|
+
* Reshape recorded inputs before they are spread into `fn`.
|
|
385
|
+
*
|
|
386
|
+
* Replay pulls each trace's inputs exactly as they were captured against the
|
|
387
|
+
* function's signature AT TRACE TIME. When the function's shape has since
|
|
388
|
+
* changed (params renamed, reordered, collapsed into an options object, etc.),
|
|
389
|
+
* the recorded inputs no longer line up and `fn(...inputs)` throws. This hook
|
|
390
|
+
* lets a caller map the recorded inputs onto the current signature so replay
|
|
391
|
+
* can still run.
|
|
392
|
+
*
|
|
393
|
+
* Receives the deserialized recorded inputs and a per-trace {@link AdaptContext}
|
|
394
|
+
* (so a table-driven adapter can look up the adapted inputs by `traceId`), and
|
|
395
|
+
* returns the array actually spread into `fn`. The returned array is also what
|
|
396
|
+
* `ReplayItem.input` reports, so the experiment shows what was really run.
|
|
397
|
+
*
|
|
398
|
+
* Runs per item, inside the same try/catch as `fn`: if the adapter throws, the
|
|
399
|
+
* failure is surfaced on that item's `error` rather than crashing the run.
|
|
400
|
+
* Omit it to spread the recorded inputs unchanged.
|
|
401
|
+
*/
|
|
402
|
+
adaptInputs?: (inputs: unknown[], ctx: AdaptContext) => unknown[];
|
|
403
|
+
}
|
|
404
|
+
/** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
|
|
405
|
+
interface AdaptContext {
|
|
406
|
+
/** Bitfab trace ID of the historical trace being replayed. */
|
|
407
|
+
traceId: string;
|
|
408
|
+
/** External span ID the recorded inputs were read from. */
|
|
409
|
+
sourceSpanId: string;
|
|
383
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* The shape an adapter module must export as `adaptInputs`.
|
|
413
|
+
*
|
|
414
|
+
* Author an adapter in its own file (e.g. `scripts/replay-adapters/<name>.ts`),
|
|
415
|
+
* import it in your replay script, and pass it to `replay({ adaptInputs })`:
|
|
416
|
+
*
|
|
417
|
+
* ```ts
|
|
418
|
+
* import type { AdaptInputsFn } from "@bitfab/sdk"
|
|
419
|
+
* export const adaptInputs: AdaptInputsFn = (inputs, ctx) => [reshape(inputs)]
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
type AdaptInputsFn = (inputs: unknown[], ctx: AdaptContext) => unknown[];
|
|
384
423
|
interface ReplayItem<T> {
|
|
385
424
|
/** Trace ID of the new trace created during replay. */
|
|
386
425
|
traceId: string | null;
|
|
@@ -920,9 +959,9 @@ declare class Bitfab {
|
|
|
920
959
|
*
|
|
921
960
|
* @param traceFunctionKey - The trace function key to replay
|
|
922
961
|
* @param fn - The function to replay (must be the return value of `withSpan`)
|
|
923
|
-
* @param options - Optional replay options.
|
|
924
|
-
*
|
|
925
|
-
*
|
|
962
|
+
* @param options - Optional replay options. When `traceIds` is passed,
|
|
963
|
+
* `limit` is ignored (with a warning): an explicit ID list already
|
|
964
|
+
* determines how many traces replay.
|
|
926
965
|
* @returns ReplayResult with items, testRunId, and testRunUrl
|
|
927
966
|
*/
|
|
928
967
|
replay<TReturn>(traceFunctionKey: string, fn: (...args: any[]) => TReturn | Promise<TReturn>, options?: ReplayOptions): Promise<ReplayResult<TReturn>>;
|
|
@@ -988,7 +1027,7 @@ declare class BitfabFunction {
|
|
|
988
1027
|
/**
|
|
989
1028
|
* SDK version from package.json (injected at build time)
|
|
990
1029
|
*/
|
|
991
|
-
declare const __version__ = "0.
|
|
1030
|
+
declare const __version__ = "0.16.1";
|
|
992
1031
|
|
|
993
1032
|
/**
|
|
994
1033
|
* Constants for the Bitfab SDK.
|
|
@@ -998,4 +1037,4 @@ declare const __version__ = "0.15.0";
|
|
|
998
1037
|
*/
|
|
999
1038
|
declare const DEFAULT_SERVICE_URL = "https://bitfab.ai";
|
|
1000
1039
|
|
|
1001
|
-
export { type ActiveSpanContext, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace };
|
|
1040
|
+
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace };
|
package/dist/index.d.ts
CHANGED
|
@@ -343,9 +343,9 @@ declare class ReplayEnvironment {
|
|
|
343
343
|
type MockStrategy = "none" | "all" | "marked";
|
|
344
344
|
interface ReplayOptions {
|
|
345
345
|
/**
|
|
346
|
-
* Maximum number of traces to replay (1
|
|
347
|
-
*
|
|
348
|
-
* many traces replay
|
|
346
|
+
* Maximum number of traces to replay (1-100, default 5). Ignored when
|
|
347
|
+
* `traceIds` is passed (with a warning): an explicit ID list already
|
|
348
|
+
* determines how many traces replay.
|
|
349
349
|
*/
|
|
350
350
|
limit?: number;
|
|
351
351
|
/** Optional list of specific trace IDs to replay (max 100). */
|
|
@@ -380,7 +380,46 @@ interface ReplayOptions {
|
|
|
380
380
|
environment?: ReplayEnvironment;
|
|
381
381
|
/** Group ID to associate this replay with an experiment group for live streaming in Studio. */
|
|
382
382
|
experimentGroupId?: string;
|
|
383
|
+
/**
|
|
384
|
+
* Reshape recorded inputs before they are spread into `fn`.
|
|
385
|
+
*
|
|
386
|
+
* Replay pulls each trace's inputs exactly as they were captured against the
|
|
387
|
+
* function's signature AT TRACE TIME. When the function's shape has since
|
|
388
|
+
* changed (params renamed, reordered, collapsed into an options object, etc.),
|
|
389
|
+
* the recorded inputs no longer line up and `fn(...inputs)` throws. This hook
|
|
390
|
+
* lets a caller map the recorded inputs onto the current signature so replay
|
|
391
|
+
* can still run.
|
|
392
|
+
*
|
|
393
|
+
* Receives the deserialized recorded inputs and a per-trace {@link AdaptContext}
|
|
394
|
+
* (so a table-driven adapter can look up the adapted inputs by `traceId`), and
|
|
395
|
+
* returns the array actually spread into `fn`. The returned array is also what
|
|
396
|
+
* `ReplayItem.input` reports, so the experiment shows what was really run.
|
|
397
|
+
*
|
|
398
|
+
* Runs per item, inside the same try/catch as `fn`: if the adapter throws, the
|
|
399
|
+
* failure is surfaced on that item's `error` rather than crashing the run.
|
|
400
|
+
* Omit it to spread the recorded inputs unchanged.
|
|
401
|
+
*/
|
|
402
|
+
adaptInputs?: (inputs: unknown[], ctx: AdaptContext) => unknown[];
|
|
403
|
+
}
|
|
404
|
+
/** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
|
|
405
|
+
interface AdaptContext {
|
|
406
|
+
/** Bitfab trace ID of the historical trace being replayed. */
|
|
407
|
+
traceId: string;
|
|
408
|
+
/** External span ID the recorded inputs were read from. */
|
|
409
|
+
sourceSpanId: string;
|
|
383
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* The shape an adapter module must export as `adaptInputs`.
|
|
413
|
+
*
|
|
414
|
+
* Author an adapter in its own file (e.g. `scripts/replay-adapters/<name>.ts`),
|
|
415
|
+
* import it in your replay script, and pass it to `replay({ adaptInputs })`:
|
|
416
|
+
*
|
|
417
|
+
* ```ts
|
|
418
|
+
* import type { AdaptInputsFn } from "@bitfab/sdk"
|
|
419
|
+
* export const adaptInputs: AdaptInputsFn = (inputs, ctx) => [reshape(inputs)]
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
type AdaptInputsFn = (inputs: unknown[], ctx: AdaptContext) => unknown[];
|
|
384
423
|
interface ReplayItem<T> {
|
|
385
424
|
/** Trace ID of the new trace created during replay. */
|
|
386
425
|
traceId: string | null;
|
|
@@ -920,9 +959,9 @@ declare class Bitfab {
|
|
|
920
959
|
*
|
|
921
960
|
* @param traceFunctionKey - The trace function key to replay
|
|
922
961
|
* @param fn - The function to replay (must be the return value of `withSpan`)
|
|
923
|
-
* @param options - Optional replay options.
|
|
924
|
-
*
|
|
925
|
-
*
|
|
962
|
+
* @param options - Optional replay options. When `traceIds` is passed,
|
|
963
|
+
* `limit` is ignored (with a warning): an explicit ID list already
|
|
964
|
+
* determines how many traces replay.
|
|
926
965
|
* @returns ReplayResult with items, testRunId, and testRunUrl
|
|
927
966
|
*/
|
|
928
967
|
replay<TReturn>(traceFunctionKey: string, fn: (...args: any[]) => TReturn | Promise<TReturn>, options?: ReplayOptions): Promise<ReplayResult<TReturn>>;
|
|
@@ -988,7 +1027,7 @@ declare class BitfabFunction {
|
|
|
988
1027
|
/**
|
|
989
1028
|
* SDK version from package.json (injected at build time)
|
|
990
1029
|
*/
|
|
991
|
-
declare const __version__ = "0.
|
|
1030
|
+
declare const __version__ = "0.16.1";
|
|
992
1031
|
|
|
993
1032
|
/**
|
|
994
1033
|
* Constants for the Bitfab SDK.
|
|
@@ -998,4 +1037,4 @@ declare const __version__ = "0.15.0";
|
|
|
998
1037
|
*/
|
|
999
1038
|
declare const DEFAULT_SERVICE_URL = "https://bitfab.ai";
|
|
1000
1039
|
|
|
1001
|
-
export { type ActiveSpanContext, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace };
|
|
1040
|
+
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace };
|
package/dist/index.js
CHANGED
package/dist/node.cjs
CHANGED
|
@@ -234,7 +234,7 @@ function buildMockTree(rootNode) {
|
|
|
234
234
|
}
|
|
235
235
|
return { spans };
|
|
236
236
|
}
|
|
237
|
-
async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, environment) {
|
|
237
|
+
async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, environment, adaptInputs) {
|
|
238
238
|
const lease = environment ? serverItem.dbBranchLease : void 0;
|
|
239
239
|
let inputs = [];
|
|
240
240
|
let originalOutput;
|
|
@@ -247,6 +247,12 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
|
|
|
247
247
|
const spanData = span.rawData?.span_data ?? {};
|
|
248
248
|
inputs = deserializeInputs(spanData);
|
|
249
249
|
originalOutput = deserializeOutput(spanData);
|
|
250
|
+
if (adaptInputs) {
|
|
251
|
+
inputs = adaptInputs(inputs, {
|
|
252
|
+
traceId: serverItem.traceId,
|
|
253
|
+
sourceSpanId: serverItem.externalSpanId
|
|
254
|
+
});
|
|
255
|
+
}
|
|
250
256
|
let mockTree;
|
|
251
257
|
if (mockStrategy === "all" || mockStrategy === "marked") {
|
|
252
258
|
const treeResponse = await httpClient.getSpanTree(
|
|
@@ -327,9 +333,12 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
|
|
|
327
333
|
}
|
|
328
334
|
}
|
|
329
335
|
if (options?.limit !== void 0 && options?.traceIds !== void 0) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
336
|
+
try {
|
|
337
|
+
console.warn(
|
|
338
|
+
"Bitfab: limit is ignored when traceIds is passed: the explicit trace ID list already determines how many traces replay."
|
|
339
|
+
);
|
|
340
|
+
} catch {
|
|
341
|
+
}
|
|
333
342
|
}
|
|
334
343
|
await replayContextReady;
|
|
335
344
|
const {
|
|
@@ -357,7 +366,8 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
|
|
|
357
366
|
fn,
|
|
358
367
|
testRunId,
|
|
359
368
|
mockStrategy,
|
|
360
|
-
options?.environment
|
|
369
|
+
options?.environment,
|
|
370
|
+
options?.adaptInputs
|
|
361
371
|
)
|
|
362
372
|
);
|
|
363
373
|
const resultItems = await mapWithConcurrency(tasks, maxConcurrency);
|
|
@@ -445,7 +455,7 @@ registerAsyncLocalStorageClass(
|
|
|
445
455
|
);
|
|
446
456
|
|
|
447
457
|
// src/version.generated.ts
|
|
448
|
-
var __version__ = "0.
|
|
458
|
+
var __version__ = "0.16.1";
|
|
449
459
|
|
|
450
460
|
// src/constants.ts
|
|
451
461
|
var DEFAULT_SERVICE_URL = "https://bitfab.ai";
|
|
@@ -3235,9 +3245,9 @@ var Bitfab = class {
|
|
|
3235
3245
|
*
|
|
3236
3246
|
* @param traceFunctionKey - The trace function key to replay
|
|
3237
3247
|
* @param fn - The function to replay (must be the return value of `withSpan`)
|
|
3238
|
-
* @param options - Optional replay options.
|
|
3239
|
-
*
|
|
3240
|
-
*
|
|
3248
|
+
* @param options - Optional replay options. When `traceIds` is passed,
|
|
3249
|
+
* `limit` is ignored (with a warning): an explicit ID list already
|
|
3250
|
+
* determines how many traces replay.
|
|
3241
3251
|
* @returns ReplayResult with items, testRunId, and testRunUrl
|
|
3242
3252
|
*/
|
|
3243
3253
|
async replay(traceFunctionKey, fn, options) {
|