@bitfab/sdk 0.24.0 → 0.25.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-S3PN26RH.js → chunk-GQLNEYSU.js} +3 -3
- package/dist/chunk-GQLNEYSU.js.map +1 -0
- package/dist/index.cjs +33 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -3
- package/dist/index.d.ts +33 -3
- package/dist/index.js +1 -1
- package/dist/node.cjs +33 -5
- 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-CQIU2ITL.js → replay-KYGI6LJY.js} +33 -5
- package/dist/replay-KYGI6LJY.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-S3PN26RH.js.map +0 -1
- package/dist/replay-CQIU2ITL.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -651,6 +651,30 @@ interface ReplayOptions {
|
|
|
651
651
|
* Omit it to spread the recorded inputs unchanged.
|
|
652
652
|
*/
|
|
653
653
|
adaptInputs?: (inputs: unknown[], ctx: AdaptContext) => unknown[];
|
|
654
|
+
/**
|
|
655
|
+
* Called once per item as it finishes, in completion order (not input
|
|
656
|
+
* order), with running totals for the whole run. Use it to render replay
|
|
657
|
+
* progress, for example a terminal progress bar. Replay does not know
|
|
658
|
+
* pass/fail at this point (verdicts are assigned later), so the totals only
|
|
659
|
+
* distinguish items whose function ran (`succeeded`) from items that threw
|
|
660
|
+
* (`errored`).
|
|
661
|
+
*
|
|
662
|
+
* Invoked synchronously right after each item settles, so keep it cheap. A
|
|
663
|
+
* throwing callback never crashes the run: the error is swallowed so progress
|
|
664
|
+
* UI can't break replay.
|
|
665
|
+
*/
|
|
666
|
+
onProgress?: (progress: ReplayProgress) => void;
|
|
667
|
+
}
|
|
668
|
+
/** Running totals reported to {@link ReplayOptions.onProgress} as replay proceeds. */
|
|
669
|
+
interface ReplayProgress {
|
|
670
|
+
/** Items that have finished so far, whether they succeeded or errored. */
|
|
671
|
+
completed: number;
|
|
672
|
+
/** Total number of items in this replay run. */
|
|
673
|
+
total: number;
|
|
674
|
+
/** Of the completed items, how many ran the function without throwing. */
|
|
675
|
+
succeeded: number;
|
|
676
|
+
/** Of the completed items, how many threw (their `item.error` is set). */
|
|
677
|
+
errored: number;
|
|
654
678
|
}
|
|
655
679
|
/** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
|
|
656
680
|
interface AdaptContext {
|
|
@@ -684,7 +708,13 @@ interface ReplayItem<T> {
|
|
|
684
708
|
error: string | null;
|
|
685
709
|
/** Original trace duration in milliseconds, or null if timestamps are missing. */
|
|
686
710
|
durationMs: number | null;
|
|
687
|
-
/**
|
|
711
|
+
/**
|
|
712
|
+
* Token usage from the REPLAYED run (this item's new execution), aggregated
|
|
713
|
+
* server-side from the spans it produced, or null if the run captured no
|
|
714
|
+
* token data. This is the "new" side of a token delta: compare it against
|
|
715
|
+
* the original trace's recorded usage to see how the code change moved cost.
|
|
716
|
+
* Matches what Studio's experiments view shows.
|
|
717
|
+
*/
|
|
688
718
|
tokens: TokenUsage | null;
|
|
689
719
|
/** Model name from the original trace, or null if not captured. */
|
|
690
720
|
model: string | null;
|
|
@@ -1374,7 +1404,7 @@ declare class BitfabFunction {
|
|
|
1374
1404
|
/**
|
|
1375
1405
|
* SDK version from package.json (injected at build time)
|
|
1376
1406
|
*/
|
|
1377
|
-
declare const __version__ = "0.
|
|
1407
|
+
declare const __version__ = "0.25.0";
|
|
1378
1408
|
|
|
1379
1409
|
/**
|
|
1380
1410
|
* Constants for the Bitfab SDK.
|
|
@@ -1442,4 +1472,4 @@ declare const finalizers: {
|
|
|
1442
1472
|
readableStream: typeof readableStream;
|
|
1443
1473
|
};
|
|
1444
1474
|
|
|
1445
|
-
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, 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 VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace };
|
|
1475
|
+
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, 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 ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace };
|
package/dist/index.d.ts
CHANGED
|
@@ -651,6 +651,30 @@ interface ReplayOptions {
|
|
|
651
651
|
* Omit it to spread the recorded inputs unchanged.
|
|
652
652
|
*/
|
|
653
653
|
adaptInputs?: (inputs: unknown[], ctx: AdaptContext) => unknown[];
|
|
654
|
+
/**
|
|
655
|
+
* Called once per item as it finishes, in completion order (not input
|
|
656
|
+
* order), with running totals for the whole run. Use it to render replay
|
|
657
|
+
* progress, for example a terminal progress bar. Replay does not know
|
|
658
|
+
* pass/fail at this point (verdicts are assigned later), so the totals only
|
|
659
|
+
* distinguish items whose function ran (`succeeded`) from items that threw
|
|
660
|
+
* (`errored`).
|
|
661
|
+
*
|
|
662
|
+
* Invoked synchronously right after each item settles, so keep it cheap. A
|
|
663
|
+
* throwing callback never crashes the run: the error is swallowed so progress
|
|
664
|
+
* UI can't break replay.
|
|
665
|
+
*/
|
|
666
|
+
onProgress?: (progress: ReplayProgress) => void;
|
|
667
|
+
}
|
|
668
|
+
/** Running totals reported to {@link ReplayOptions.onProgress} as replay proceeds. */
|
|
669
|
+
interface ReplayProgress {
|
|
670
|
+
/** Items that have finished so far, whether they succeeded or errored. */
|
|
671
|
+
completed: number;
|
|
672
|
+
/** Total number of items in this replay run. */
|
|
673
|
+
total: number;
|
|
674
|
+
/** Of the completed items, how many ran the function without throwing. */
|
|
675
|
+
succeeded: number;
|
|
676
|
+
/** Of the completed items, how many threw (their `item.error` is set). */
|
|
677
|
+
errored: number;
|
|
654
678
|
}
|
|
655
679
|
/** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
|
|
656
680
|
interface AdaptContext {
|
|
@@ -684,7 +708,13 @@ interface ReplayItem<T> {
|
|
|
684
708
|
error: string | null;
|
|
685
709
|
/** Original trace duration in milliseconds, or null if timestamps are missing. */
|
|
686
710
|
durationMs: number | null;
|
|
687
|
-
/**
|
|
711
|
+
/**
|
|
712
|
+
* Token usage from the REPLAYED run (this item's new execution), aggregated
|
|
713
|
+
* server-side from the spans it produced, or null if the run captured no
|
|
714
|
+
* token data. This is the "new" side of a token delta: compare it against
|
|
715
|
+
* the original trace's recorded usage to see how the code change moved cost.
|
|
716
|
+
* Matches what Studio's experiments view shows.
|
|
717
|
+
*/
|
|
688
718
|
tokens: TokenUsage | null;
|
|
689
719
|
/** Model name from the original trace, or null if not captured. */
|
|
690
720
|
model: string | null;
|
|
@@ -1374,7 +1404,7 @@ declare class BitfabFunction {
|
|
|
1374
1404
|
/**
|
|
1375
1405
|
* SDK version from package.json (injected at build time)
|
|
1376
1406
|
*/
|
|
1377
|
-
declare const __version__ = "0.
|
|
1407
|
+
declare const __version__ = "0.25.0";
|
|
1378
1408
|
|
|
1379
1409
|
/**
|
|
1380
1410
|
* Constants for the Bitfab SDK.
|
|
@@ -1442,4 +1472,4 @@ declare const finalizers: {
|
|
|
1442
1472
|
readableStream: typeof readableStream;
|
|
1443
1473
|
};
|
|
1444
1474
|
|
|
1445
|
-
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, 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 VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace };
|
|
1475
|
+
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, 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 ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace };
|
package/dist/index.js
CHANGED
package/dist/node.cjs
CHANGED
|
@@ -412,18 +412,23 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
|
|
|
412
412
|
originalOutput,
|
|
413
413
|
error,
|
|
414
414
|
durationMs: serverItem.durationMs ?? null,
|
|
415
|
-
|
|
415
|
+
// Filled in by replay() from the complete-replay response once the
|
|
416
|
+
// replay traces are persisted and their spans aggregated server-side.
|
|
417
|
+
// Null here (and on older servers) means "replay tokens not known".
|
|
418
|
+
tokens: null,
|
|
416
419
|
model: serverItem.model ?? null,
|
|
417
420
|
dbSnapshotRef: serverItem.dbSnapshotRef ?? null
|
|
418
421
|
};
|
|
419
422
|
}
|
|
420
|
-
async function mapWithConcurrency(tasks, maxConcurrency) {
|
|
423
|
+
async function mapWithConcurrency(tasks, maxConcurrency, onSettled) {
|
|
421
424
|
const results = new Array(tasks.length);
|
|
422
425
|
let nextIndex = 0;
|
|
423
426
|
async function worker() {
|
|
424
427
|
while (nextIndex < tasks.length) {
|
|
425
428
|
const index = nextIndex++;
|
|
426
|
-
|
|
429
|
+
const result = await tasks[index]();
|
|
430
|
+
results[index] = result;
|
|
431
|
+
onSettled?.(result, index);
|
|
427
432
|
}
|
|
428
433
|
}
|
|
429
434
|
const workers = Array.from(
|
|
@@ -483,9 +488,29 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
|
|
|
483
488
|
options?.adaptInputs
|
|
484
489
|
)
|
|
485
490
|
);
|
|
486
|
-
const
|
|
491
|
+
const total = tasks.length;
|
|
492
|
+
let completed = 0;
|
|
493
|
+
let succeeded = 0;
|
|
494
|
+
let errored = 0;
|
|
495
|
+
const resultItems = await mapWithConcurrency(
|
|
496
|
+
tasks,
|
|
497
|
+
maxConcurrency,
|
|
498
|
+
options?.onProgress ? (item) => {
|
|
499
|
+
completed += 1;
|
|
500
|
+
if (item.error === null) {
|
|
501
|
+
succeeded += 1;
|
|
502
|
+
} else {
|
|
503
|
+
errored += 1;
|
|
504
|
+
}
|
|
505
|
+
try {
|
|
506
|
+
options?.onProgress?.({ completed, total, succeeded, errored });
|
|
507
|
+
} catch {
|
|
508
|
+
}
|
|
509
|
+
} : void 0
|
|
510
|
+
);
|
|
487
511
|
const completeResult = await httpClient.completeReplay(testRunId);
|
|
488
512
|
const serverTraceIds = completeResult.traceIds;
|
|
513
|
+
const replayTokens = completeResult.tokens;
|
|
489
514
|
if (serverTraceIds === void 0) {
|
|
490
515
|
try {
|
|
491
516
|
console.warn(
|
|
@@ -508,6 +533,9 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
|
|
|
508
533
|
missing.push(item.traceId);
|
|
509
534
|
}
|
|
510
535
|
}
|
|
536
|
+
if (mapped !== void 0) {
|
|
537
|
+
item.tokens = replayTokens?.[mapped] ?? null;
|
|
538
|
+
}
|
|
511
539
|
item.traceId = mapped ?? null;
|
|
512
540
|
}
|
|
513
541
|
}
|
|
@@ -573,7 +601,7 @@ registerAsyncLocalStorageClass(
|
|
|
573
601
|
);
|
|
574
602
|
|
|
575
603
|
// src/version.generated.ts
|
|
576
|
-
var __version__ = "0.
|
|
604
|
+
var __version__ = "0.25.0";
|
|
577
605
|
|
|
578
606
|
// src/constants.ts
|
|
579
607
|
var DEFAULT_SERVICE_URL = "https://bitfab.ai";
|