bitfab 0.15.0 → 0.16.0
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-53G5GR7B.js} +3 -3
- package/dist/{chunk-YPG3XIG4.js.map → chunk-53G5GR7B.js.map} +1 -1
- package/dist/index.cjs +10 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -2
- package/dist/index.d.ts +41 -2
- package/dist/index.js +1 -1
- package/dist/node.cjs +10 -3
- 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-WIBKB3BK.js} +10 -3
- package/dist/replay-WIBKB3BK.js.map +1 -0
- package/package.json +1 -1
- package/dist/replay-3MQS22GS.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -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;
|
|
@@ -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.0";
|
|
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
|
@@ -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;
|
|
@@ -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.0";
|
|
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(
|
|
@@ -357,7 +363,8 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
|
|
|
357
363
|
fn,
|
|
358
364
|
testRunId,
|
|
359
365
|
mockStrategy,
|
|
360
|
-
options?.environment
|
|
366
|
+
options?.environment,
|
|
367
|
+
options?.adaptInputs
|
|
361
368
|
)
|
|
362
369
|
);
|
|
363
370
|
const resultItems = await mapWithConcurrency(tasks, maxConcurrency);
|
|
@@ -445,7 +452,7 @@ registerAsyncLocalStorageClass(
|
|
|
445
452
|
);
|
|
446
453
|
|
|
447
454
|
// src/version.generated.ts
|
|
448
|
-
var __version__ = "0.
|
|
455
|
+
var __version__ = "0.16.0";
|
|
449
456
|
|
|
450
457
|
// src/constants.ts
|
|
451
458
|
var DEFAULT_SERVICE_URL = "https://bitfab.ai";
|