@bitfab/sdk 0.36.13 → 0.38.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/index.d.cts CHANGED
@@ -223,6 +223,39 @@ interface DbBranchLease {
223
223
  */
224
224
  region?: string;
225
225
  }
226
+ /**
227
+ * How long each phase of provisioning one replay branch took, measured
228
+ * server-side. A runner in another region sees these plus its own round trip.
229
+ *
230
+ * Durations, not instants: an instant is approximately `startedAt` plus the
231
+ * running sum, and per-phase wall-clock stamps would make clock skew between
232
+ * the server and your runner look like latency. Approximately, because
233
+ * `totalMs` is the resolve's true wall time and covers a little work no phase
234
+ * owns, so the phases account for it without summing to it exactly.
235
+ *
236
+ * `startedAt` and `totalMs` are always present. The phases are optional
237
+ * because a failed resolve reports only the ones it reached, and `totalMs` is
238
+ * then time-to-failure. On success every phase is present except `warmupMs`,
239
+ * which is absent when no warm-up SQL was supplied.
240
+ */
241
+ interface DbBranchTimings {
242
+ /** When the resolve began, ISO. */
243
+ startedAt: string;
244
+ /** Resolving the project, plus its retention and region reads. */
245
+ projectResolveMs?: number;
246
+ /** Creating the branch, through its provider operations reaching terminal. */
247
+ branchCreateMs?: number;
248
+ /** Resolving the connection URI. 0 when the provider returns one inline. */
249
+ connectionUriMs?: number;
250
+ /** The compute accepting a connection. */
251
+ computeConnectMs?: number;
252
+ /** The branch answering a readiness query. */
253
+ baseProbeMs?: number;
254
+ /** Your warm-up SQL. Absent when you supplied none. */
255
+ warmupMs?: number;
256
+ /** The whole resolve, or time-to-failure when it threw. */
257
+ totalMs: number;
258
+ }
226
259
  /**
227
260
  * Wire shape of the caller's `ReplayOptions.dbBranch`, sent to
228
261
  * `/api/sdk/replay/start` and applied per lease.
@@ -275,6 +308,14 @@ interface ReplayContext {
275
308
  */
276
309
  fetchSpanOutput?: (externalSpanId: string) => Promise<unknown>;
277
310
  dbBranchLease?: DbBranchLease;
311
+ /**
312
+ * Server-measured provisioning timings for this item's branch, echoed back
313
+ * on the trace completion so the trace records what it cost to set up. Kept
314
+ * off `ReplayBranch`: customer code reads that mid-replay to reach the
315
+ * branch, and provisioning latency is a property of the run, not of the
316
+ * connection.
317
+ */
318
+ dbBranchTimings?: DbBranchTimings;
278
319
  /**
279
320
  * Set to true by `ReplayBranch` the first time customer code actually
280
321
  * obtains `databaseUrl` for this item. Reported on the trace completion inside
@@ -570,6 +611,7 @@ declare class HttpClient {
570
611
  code: string;
571
612
  message: string;
572
613
  } | null;
614
+ timings: DbBranchTimings | null;
573
615
  }>;
574
616
  /** Release a previously-resolved DB branch by deleting its Neon branch. Idempotent server-side. */
575
617
  releaseDbBranchLease(neonBranchId: string): Promise<void>;
@@ -628,6 +670,13 @@ interface StartReplayResponse {
628
670
  code: string;
629
671
  message: string;
630
672
  };
673
+ /**
674
+ * How long provisioning took, per phase. Sits beside the two fields above
675
+ * rather than inside either: it is reported on both outcomes, complete on
676
+ * success and partial up to the failing phase on error. Absent from
677
+ * servers that predate it.
678
+ */
679
+ dbBranchTimings?: DbBranchTimings;
631
680
  }>;
632
681
  }
633
682
  interface ExternalSpanResponse {
@@ -1343,42 +1392,52 @@ interface ReplayItemFinishProgress {
1343
1392
  /** Of the completed items, how many have `item.error` set. */
1344
1393
  errored: number;
1345
1394
  /**
1346
- * The single item that just finished to produce this event. `traceId` is null
1347
- * at this stage (the server replay id isn't known until the run completes);
1348
- * `originalTraceId` is the original (historical) trace that was replayed (so
1349
- * a UI can identify or link it); `error` is its replay error, or null when it
1350
- * ran ok; `durationMs` is how long this one trace took to replay. Lets a
1351
- * progress UI show per-trace pass/fail and timing as the run streams, without
1352
- * waiting for the full {@link ReplayResult}.
1395
+ * The single item that just finished to produce this event. Field-for-field
1396
+ * the same shape and meaning as {@link ReplayItem}, so a progress UI and a
1397
+ * final-result UI read one contract. `traceId` is null at this stage (the
1398
+ * server replay id arrives at completion), and `tokens` is null for the same
1399
+ * reason: the replayed run's usage is aggregated server-side by
1400
+ * completeReplay. `durationMs` is how long this item took to replay; the
1401
+ * `original*` fields describe the trace it replayed.
1353
1402
  */
1354
- item: {
1355
- /** Trace ID of the new replay trace (null during the run; the server id arrives at completion). */
1356
- traceId?: string | null;
1357
- /** Bitfab trace ID of the original (historical) trace being replayed. */
1358
- originalTraceId: string | null;
1359
- /** External span ID the recorded inputs were read from (the original root span). */
1360
- originalSpanId?: string | null;
1361
- /** @deprecated alias for `originalTraceId`. */
1362
- sourceTraceId: string | null;
1363
- /** @deprecated alias for `originalSpanId`. */
1364
- sourceSpanId?: string | null;
1365
- /** Deserialized inputs from the original trace. */
1366
- input?: unknown[];
1367
- /** The result returned by the replayed function, or undefined on error. */
1368
- result?: unknown;
1369
- /** The original output from the historical trace. */
1370
- originalOutput?: unknown;
1371
- /** Backward-compatible message for either error kind. */
1372
- error: string | null;
1373
- /** The actual value thrown by the replayed customer function. */
1374
- traceError: unknown | null;
1375
- /** The actual value thrown while Bitfab prepared this replay item. */
1376
- replayError: unknown | null;
1377
- durationMs: number | null;
1378
- tokens?: TokenUsage | null;
1379
- model?: string | null;
1380
- dbSnapshotRef?: DbSnapshotRef | null;
1381
- };
1403
+ item: ReplayProgressItem;
1404
+ }
1405
+ /** See {@link ReplayItemFinishProgress.item}. Mirrors {@link ReplayItem}. */
1406
+ interface ReplayProgressItem {
1407
+ /** Trace ID of the new replay trace (null during the run; the server id arrives at completion). */
1408
+ traceId?: string | null;
1409
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
1410
+ originalTraceId: string | null;
1411
+ /** External span ID the recorded inputs were read from (the original root span). */
1412
+ originalSpanId?: string | null;
1413
+ /** @deprecated alias for `originalTraceId`. */
1414
+ sourceTraceId: string | null;
1415
+ /** @deprecated alias for `originalSpanId`. */
1416
+ sourceSpanId?: string | null;
1417
+ /** Deserialized inputs from the original trace. */
1418
+ input?: unknown[];
1419
+ /** The result returned by the replayed function, or undefined on error. */
1420
+ result?: unknown;
1421
+ /** The original output from the historical trace. */
1422
+ originalOutput?: unknown;
1423
+ /** Backward-compatible message for either error kind. */
1424
+ error: string | null;
1425
+ /** The actual value thrown by the replayed customer function. */
1426
+ traceError?: unknown | null;
1427
+ /** The actual value thrown while Bitfab prepared this replay item. */
1428
+ replayError?: unknown | null;
1429
+ /** How long the replayed function took on this run. */
1430
+ durationMs?: number | null;
1431
+ /** The original trace's duration, tokens, and model. */
1432
+ originalDurationMs?: number | null;
1433
+ originalTokens?: TokenUsage | null;
1434
+ originalModel?: string | null;
1435
+ /** Always null here: the replayed run's usage is only known at completion. */
1436
+ tokens?: TokenUsage | null;
1437
+ /** @deprecated renamed to `originalModel`. */
1438
+ model?: string | null;
1439
+ dbSnapshotRef?: DbSnapshotRef | null;
1440
+ dbBranchTimings?: DbBranchTimings | null;
1382
1441
  }
1383
1442
  /**
1384
1443
  * @deprecated Use {@link ReplayItemFinishProgress}. This legacy shape also
@@ -1482,17 +1541,32 @@ interface ReplayItem<T> {
1482
1541
  * such as database warmup, input hydration, or mock preparation.
1483
1542
  */
1484
1543
  replayError: unknown | null;
1485
- /** Original trace duration in milliseconds, or null if timestamps are missing. */
1544
+ /**
1545
+ * How long the replayed function took on this run, in ms. Null if the item
1546
+ * failed before it ran. Compare against
1547
+ * {@link ReplayItem.originalDurationMs} for the before/after.
1548
+ */
1486
1549
  durationMs: number | null;
1550
+ /** The original trace's duration in ms, or null if its timestamps are missing. */
1551
+ originalDurationMs: number | null;
1552
+ /**
1553
+ * Token usage recorded on the original trace, or null if it captured none.
1554
+ * The "old" side of a token delta; {@link ReplayItem.tokens} is the new one.
1555
+ */
1556
+ originalTokens: TokenUsage | null;
1557
+ /** Model name from the original trace, or null if not captured. */
1558
+ originalModel: string | null;
1487
1559
  /**
1488
1560
  * Token usage from the REPLAYED run (this item's new execution), aggregated
1489
1561
  * server-side from the spans it produced, or null if the run captured no
1490
- * token data. This is the "new" side of a token delta: compare it against
1491
- * the original trace's recorded usage to see how the code change moved cost.
1492
- * Matches what Studio's experiments view shows.
1562
+ * token data. Compare against {@link ReplayItem.originalTokens} to see how
1563
+ * the code change moved cost. Matches what Studio's experiments view shows.
1564
+ *
1565
+ * Unprefixed because the replay is this item's subject: anything describing
1566
+ * the trace being replayed carries `original`.
1493
1567
  */
1494
1568
  tokens: TokenUsage | null;
1495
- /** Model name from the original trace, or null if not captured. */
1569
+ /** @deprecated renamed to {@link ReplayItem.originalModel}. */
1496
1570
  model: string | null;
1497
1571
  /**
1498
1572
  * The DB snapshot ref the SDK captured at trace open. Useful for debugging
@@ -1501,6 +1575,14 @@ interface ReplayItem<T> {
1501
1575
  * without `dbSnapshot` configured.
1502
1576
  */
1503
1577
  dbSnapshotRef: DbSnapshotRef | null;
1578
+ /**
1579
+ * How long this item's DB branch took to provision, per phase, measured
1580
+ * server-side. Present whenever a branch was attempted, on both outcomes:
1581
+ * complete on success, partial up to the failing phase when the resolve
1582
+ * failed. Null when no branch was asked for, when the source trace carried
1583
+ * no snapshot ref, or against a server that predates timings.
1584
+ */
1585
+ dbBranchTimings: DbBranchTimings | null;
1504
1586
  }
1505
1587
 
1506
1588
  interface ReplayResult<T> {
@@ -2581,7 +2663,7 @@ declare class BitfabFunction {
2581
2663
  /**
2582
2664
  * SDK version from package.json (injected at build time)
2583
2665
  */
2584
- declare const __version__ = "0.36.13";
2666
+ declare const __version__ = "0.38.0";
2585
2667
 
2586
2668
  /**
2587
2669
  * Constants for the Bitfab SDK.
@@ -2649,4 +2731,4 @@ declare const finalizers: {
2649
2731
  readableStream: typeof readableStream;
2650
2732
  };
2651
2733
 
2652
- 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 DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayProgress, 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__, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
2734
+ 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 ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayProgress, type ReplayProgressItem, 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__, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
package/dist/index.d.ts CHANGED
@@ -223,6 +223,39 @@ interface DbBranchLease {
223
223
  */
224
224
  region?: string;
225
225
  }
226
+ /**
227
+ * How long each phase of provisioning one replay branch took, measured
228
+ * server-side. A runner in another region sees these plus its own round trip.
229
+ *
230
+ * Durations, not instants: an instant is approximately `startedAt` plus the
231
+ * running sum, and per-phase wall-clock stamps would make clock skew between
232
+ * the server and your runner look like latency. Approximately, because
233
+ * `totalMs` is the resolve's true wall time and covers a little work no phase
234
+ * owns, so the phases account for it without summing to it exactly.
235
+ *
236
+ * `startedAt` and `totalMs` are always present. The phases are optional
237
+ * because a failed resolve reports only the ones it reached, and `totalMs` is
238
+ * then time-to-failure. On success every phase is present except `warmupMs`,
239
+ * which is absent when no warm-up SQL was supplied.
240
+ */
241
+ interface DbBranchTimings {
242
+ /** When the resolve began, ISO. */
243
+ startedAt: string;
244
+ /** Resolving the project, plus its retention and region reads. */
245
+ projectResolveMs?: number;
246
+ /** Creating the branch, through its provider operations reaching terminal. */
247
+ branchCreateMs?: number;
248
+ /** Resolving the connection URI. 0 when the provider returns one inline. */
249
+ connectionUriMs?: number;
250
+ /** The compute accepting a connection. */
251
+ computeConnectMs?: number;
252
+ /** The branch answering a readiness query. */
253
+ baseProbeMs?: number;
254
+ /** Your warm-up SQL. Absent when you supplied none. */
255
+ warmupMs?: number;
256
+ /** The whole resolve, or time-to-failure when it threw. */
257
+ totalMs: number;
258
+ }
226
259
  /**
227
260
  * Wire shape of the caller's `ReplayOptions.dbBranch`, sent to
228
261
  * `/api/sdk/replay/start` and applied per lease.
@@ -275,6 +308,14 @@ interface ReplayContext {
275
308
  */
276
309
  fetchSpanOutput?: (externalSpanId: string) => Promise<unknown>;
277
310
  dbBranchLease?: DbBranchLease;
311
+ /**
312
+ * Server-measured provisioning timings for this item's branch, echoed back
313
+ * on the trace completion so the trace records what it cost to set up. Kept
314
+ * off `ReplayBranch`: customer code reads that mid-replay to reach the
315
+ * branch, and provisioning latency is a property of the run, not of the
316
+ * connection.
317
+ */
318
+ dbBranchTimings?: DbBranchTimings;
278
319
  /**
279
320
  * Set to true by `ReplayBranch` the first time customer code actually
280
321
  * obtains `databaseUrl` for this item. Reported on the trace completion inside
@@ -570,6 +611,7 @@ declare class HttpClient {
570
611
  code: string;
571
612
  message: string;
572
613
  } | null;
614
+ timings: DbBranchTimings | null;
573
615
  }>;
574
616
  /** Release a previously-resolved DB branch by deleting its Neon branch. Idempotent server-side. */
575
617
  releaseDbBranchLease(neonBranchId: string): Promise<void>;
@@ -628,6 +670,13 @@ interface StartReplayResponse {
628
670
  code: string;
629
671
  message: string;
630
672
  };
673
+ /**
674
+ * How long provisioning took, per phase. Sits beside the two fields above
675
+ * rather than inside either: it is reported on both outcomes, complete on
676
+ * success and partial up to the failing phase on error. Absent from
677
+ * servers that predate it.
678
+ */
679
+ dbBranchTimings?: DbBranchTimings;
631
680
  }>;
632
681
  }
633
682
  interface ExternalSpanResponse {
@@ -1343,42 +1392,52 @@ interface ReplayItemFinishProgress {
1343
1392
  /** Of the completed items, how many have `item.error` set. */
1344
1393
  errored: number;
1345
1394
  /**
1346
- * The single item that just finished to produce this event. `traceId` is null
1347
- * at this stage (the server replay id isn't known until the run completes);
1348
- * `originalTraceId` is the original (historical) trace that was replayed (so
1349
- * a UI can identify or link it); `error` is its replay error, or null when it
1350
- * ran ok; `durationMs` is how long this one trace took to replay. Lets a
1351
- * progress UI show per-trace pass/fail and timing as the run streams, without
1352
- * waiting for the full {@link ReplayResult}.
1395
+ * The single item that just finished to produce this event. Field-for-field
1396
+ * the same shape and meaning as {@link ReplayItem}, so a progress UI and a
1397
+ * final-result UI read one contract. `traceId` is null at this stage (the
1398
+ * server replay id arrives at completion), and `tokens` is null for the same
1399
+ * reason: the replayed run's usage is aggregated server-side by
1400
+ * completeReplay. `durationMs` is how long this item took to replay; the
1401
+ * `original*` fields describe the trace it replayed.
1353
1402
  */
1354
- item: {
1355
- /** Trace ID of the new replay trace (null during the run; the server id arrives at completion). */
1356
- traceId?: string | null;
1357
- /** Bitfab trace ID of the original (historical) trace being replayed. */
1358
- originalTraceId: string | null;
1359
- /** External span ID the recorded inputs were read from (the original root span). */
1360
- originalSpanId?: string | null;
1361
- /** @deprecated alias for `originalTraceId`. */
1362
- sourceTraceId: string | null;
1363
- /** @deprecated alias for `originalSpanId`. */
1364
- sourceSpanId?: string | null;
1365
- /** Deserialized inputs from the original trace. */
1366
- input?: unknown[];
1367
- /** The result returned by the replayed function, or undefined on error. */
1368
- result?: unknown;
1369
- /** The original output from the historical trace. */
1370
- originalOutput?: unknown;
1371
- /** Backward-compatible message for either error kind. */
1372
- error: string | null;
1373
- /** The actual value thrown by the replayed customer function. */
1374
- traceError: unknown | null;
1375
- /** The actual value thrown while Bitfab prepared this replay item. */
1376
- replayError: unknown | null;
1377
- durationMs: number | null;
1378
- tokens?: TokenUsage | null;
1379
- model?: string | null;
1380
- dbSnapshotRef?: DbSnapshotRef | null;
1381
- };
1403
+ item: ReplayProgressItem;
1404
+ }
1405
+ /** See {@link ReplayItemFinishProgress.item}. Mirrors {@link ReplayItem}. */
1406
+ interface ReplayProgressItem {
1407
+ /** Trace ID of the new replay trace (null during the run; the server id arrives at completion). */
1408
+ traceId?: string | null;
1409
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
1410
+ originalTraceId: string | null;
1411
+ /** External span ID the recorded inputs were read from (the original root span). */
1412
+ originalSpanId?: string | null;
1413
+ /** @deprecated alias for `originalTraceId`. */
1414
+ sourceTraceId: string | null;
1415
+ /** @deprecated alias for `originalSpanId`. */
1416
+ sourceSpanId?: string | null;
1417
+ /** Deserialized inputs from the original trace. */
1418
+ input?: unknown[];
1419
+ /** The result returned by the replayed function, or undefined on error. */
1420
+ result?: unknown;
1421
+ /** The original output from the historical trace. */
1422
+ originalOutput?: unknown;
1423
+ /** Backward-compatible message for either error kind. */
1424
+ error: string | null;
1425
+ /** The actual value thrown by the replayed customer function. */
1426
+ traceError?: unknown | null;
1427
+ /** The actual value thrown while Bitfab prepared this replay item. */
1428
+ replayError?: unknown | null;
1429
+ /** How long the replayed function took on this run. */
1430
+ durationMs?: number | null;
1431
+ /** The original trace's duration, tokens, and model. */
1432
+ originalDurationMs?: number | null;
1433
+ originalTokens?: TokenUsage | null;
1434
+ originalModel?: string | null;
1435
+ /** Always null here: the replayed run's usage is only known at completion. */
1436
+ tokens?: TokenUsage | null;
1437
+ /** @deprecated renamed to `originalModel`. */
1438
+ model?: string | null;
1439
+ dbSnapshotRef?: DbSnapshotRef | null;
1440
+ dbBranchTimings?: DbBranchTimings | null;
1382
1441
  }
1383
1442
  /**
1384
1443
  * @deprecated Use {@link ReplayItemFinishProgress}. This legacy shape also
@@ -1482,17 +1541,32 @@ interface ReplayItem<T> {
1482
1541
  * such as database warmup, input hydration, or mock preparation.
1483
1542
  */
1484
1543
  replayError: unknown | null;
1485
- /** Original trace duration in milliseconds, or null if timestamps are missing. */
1544
+ /**
1545
+ * How long the replayed function took on this run, in ms. Null if the item
1546
+ * failed before it ran. Compare against
1547
+ * {@link ReplayItem.originalDurationMs} for the before/after.
1548
+ */
1486
1549
  durationMs: number | null;
1550
+ /** The original trace's duration in ms, or null if its timestamps are missing. */
1551
+ originalDurationMs: number | null;
1552
+ /**
1553
+ * Token usage recorded on the original trace, or null if it captured none.
1554
+ * The "old" side of a token delta; {@link ReplayItem.tokens} is the new one.
1555
+ */
1556
+ originalTokens: TokenUsage | null;
1557
+ /** Model name from the original trace, or null if not captured. */
1558
+ originalModel: string | null;
1487
1559
  /**
1488
1560
  * Token usage from the REPLAYED run (this item's new execution), aggregated
1489
1561
  * server-side from the spans it produced, or null if the run captured no
1490
- * token data. This is the "new" side of a token delta: compare it against
1491
- * the original trace's recorded usage to see how the code change moved cost.
1492
- * Matches what Studio's experiments view shows.
1562
+ * token data. Compare against {@link ReplayItem.originalTokens} to see how
1563
+ * the code change moved cost. Matches what Studio's experiments view shows.
1564
+ *
1565
+ * Unprefixed because the replay is this item's subject: anything describing
1566
+ * the trace being replayed carries `original`.
1493
1567
  */
1494
1568
  tokens: TokenUsage | null;
1495
- /** Model name from the original trace, or null if not captured. */
1569
+ /** @deprecated renamed to {@link ReplayItem.originalModel}. */
1496
1570
  model: string | null;
1497
1571
  /**
1498
1572
  * The DB snapshot ref the SDK captured at trace open. Useful for debugging
@@ -1501,6 +1575,14 @@ interface ReplayItem<T> {
1501
1575
  * without `dbSnapshot` configured.
1502
1576
  */
1503
1577
  dbSnapshotRef: DbSnapshotRef | null;
1578
+ /**
1579
+ * How long this item's DB branch took to provision, per phase, measured
1580
+ * server-side. Present whenever a branch was attempted, on both outcomes:
1581
+ * complete on success, partial up to the failing phase when the resolve
1582
+ * failed. Null when no branch was asked for, when the source trace carried
1583
+ * no snapshot ref, or against a server that predates timings.
1584
+ */
1585
+ dbBranchTimings: DbBranchTimings | null;
1504
1586
  }
1505
1587
 
1506
1588
  interface ReplayResult<T> {
@@ -2581,7 +2663,7 @@ declare class BitfabFunction {
2581
2663
  /**
2582
2664
  * SDK version from package.json (injected at build time)
2583
2665
  */
2584
- declare const __version__ = "0.36.13";
2666
+ declare const __version__ = "0.38.0";
2585
2667
 
2586
2668
  /**
2587
2669
  * Constants for the Bitfab SDK.
@@ -2649,4 +2731,4 @@ declare const finalizers: {
2649
2731
  readableStream: typeof readableStream;
2650
2732
  };
2651
2733
 
2652
- 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 DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayProgress, 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__, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
2734
+ 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 ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayProgress, type ReplayProgressItem, 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__, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  getCurrentReplayBranch,
12
12
  getCurrentSpan,
13
13
  getCurrentTrace
14
- } from "./chunk-XAQJOZMJ.js";
14
+ } from "./chunk-LCGQUVKR.js";
15
15
  import {
16
16
  BITFAB_PROGRESS_PREFIX,
17
17
  BitfabError,
@@ -23,7 +23,7 @@ import {
23
23
  flushTraces,
24
24
  reportReplayProgress,
25
25
  serializeReplayResult
26
- } from "./chunk-VOUV7ZTS.js";
26
+ } from "./chunk-SSNTMROV.js";
27
27
  export {
28
28
  BITFAB_PROGRESS_PREFIX,
29
29
  Bitfab,
package/dist/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.36.13";
91
+ __version__ = "0.38.0";
92
92
  }
93
93
  });
94
94
 
@@ -2532,12 +2532,15 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2532
2532
  let lease = includeDbBranchLease ? serverItem.dbBranchLease : void 0;
2533
2533
  let leaseError = includeDbBranchLease ? serverItem.dbBranchLeaseError : void 0;
2534
2534
  let dbSnapshotRef = serverItem.dbSnapshotRef;
2535
+ let dbBranchTimings = includeDbBranchLease ? serverItem.dbBranchTimings : void 0;
2535
2536
  let inputs = [];
2536
2537
  let originalOutput;
2537
2538
  let result;
2538
2539
  let error = null;
2539
2540
  let traceError = null;
2540
2541
  let replayError = null;
2542
+ let replayDurationMs = null;
2543
+ let replayStarted = null;
2541
2544
  const originalTraceId = serverItem.originalTraceId ?? serverItem.sourceTraceId;
2542
2545
  const originalSpanId = serverItem.originalSpanId ?? serverItem.sourceSpanId;
2543
2546
  try {
@@ -2560,6 +2563,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2560
2563
  lease = resolved.lease ?? void 0;
2561
2564
  leaseError = resolved.leaseError ?? void 0;
2562
2565
  dbSnapshotRef = resolved.dbSnapshotRef ?? dbSnapshotRef;
2566
+ dbBranchTimings = resolved.timings ?? dbBranchTimings;
2563
2567
  }
2564
2568
  if (leaseError) {
2565
2569
  throw new DbBranchReplayError(
@@ -2620,6 +2624,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2620
2624
  return pending;
2621
2625
  } : void 0;
2622
2626
  try {
2627
+ replayStarted = performance.now();
2623
2628
  const maybePromise = runWithReplayContext(
2624
2629
  {
2625
2630
  testRunId,
@@ -2632,16 +2637,24 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2632
2637
  mockStrategy,
2633
2638
  mockOverrides: hasOverrides ? resolvedOverrides : void 0,
2634
2639
  fetchSpanOutput,
2635
- dbBranchLease: lease
2640
+ dbBranchLease: lease,
2641
+ dbBranchTimings
2636
2642
  },
2637
2643
  () => fn(...inputs)
2638
2644
  );
2639
2645
  result = maybePromise instanceof Promise ? await maybePromise : maybePromise;
2646
+ replayDurationMs = Math.round(performance.now() - replayStarted);
2640
2647
  } catch (e) {
2648
+ if (replayStarted !== null) {
2649
+ replayDurationMs = Math.round(performance.now() - replayStarted);
2650
+ }
2641
2651
  traceError = e;
2642
2652
  error = errorMessage(e);
2643
2653
  }
2644
2654
  } catch (e) {
2655
+ if (replayStarted !== null) {
2656
+ replayDurationMs = Math.round(performance.now() - replayStarted);
2657
+ }
2645
2658
  replayError = e;
2646
2659
  error = replayItemErrorMessage(e);
2647
2660
  } finally {
@@ -2658,6 +2671,8 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2658
2671
  }
2659
2672
  }
2660
2673
  }
2674
+ const originalDurationMs = serverItem.originalDurationMs ?? serverItem.durationMs ?? null;
2675
+ const originalModel = serverItem.originalModel ?? serverItem.model ?? null;
2661
2676
  return {
2662
2677
  // Written in by replay() from the complete-replay response once the server
2663
2678
  // has minted this replay trace's row. Null until then: the client-side
@@ -2674,13 +2689,17 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2674
2689
  error,
2675
2690
  traceError,
2676
2691
  replayError,
2677
- durationMs: serverItem.durationMs ?? null,
2692
+ durationMs: replayDurationMs,
2693
+ originalDurationMs,
2694
+ originalTokens: serverItem.originalTokens ?? serverItem.tokens ?? null,
2695
+ originalModel,
2678
2696
  // Filled in by replay() from the complete-replay response once the
2679
2697
  // replay traces are persisted and their spans aggregated server-side.
2680
2698
  // Null here (and on older servers) means "replay tokens not known".
2681
2699
  tokens: null,
2682
- model: serverItem.model ?? null,
2683
- dbSnapshotRef: dbSnapshotRef ?? null
2700
+ model: originalModel,
2701
+ dbSnapshotRef: dbSnapshotRef ?? null,
2702
+ dbBranchTimings: dbBranchTimings ?? null
2684
2703
  };
2685
2704
  }
2686
2705
  async function waitForReplayPersistence(httpClient, testRunId, replayedTraceIds) {
@@ -2907,9 +2926,13 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
2907
2926
  traceError: item.traceError,
2908
2927
  replayError: item.replayError,
2909
2928
  durationMs: item.durationMs,
2929
+ originalDurationMs: item.originalDurationMs,
2930
+ originalTokens: item.originalTokens,
2931
+ originalModel: item.originalModel,
2910
2932
  tokens: item.tokens,
2911
2933
  model: item.model,
2912
- dbSnapshotRef: item.dbSnapshotRef
2934
+ dbSnapshotRef: item.dbSnapshotRef,
2935
+ dbBranchTimings: item.dbBranchTimings
2913
2936
  }
2914
2937
  });
2915
2938
  } catch {
@@ -6095,7 +6118,8 @@ var Bitfab = class {
6095
6118
  snapshotTimestamp: replayCtx.dbBranchLease.snapshotTimestamp,
6096
6119
  region: replayCtx.dbBranchLease.region,
6097
6120
  originalTraceId: replayCtx.sourceBitfabTraceId,
6098
- accessed: replayCtx.dbSnapshotAccessed === true
6121
+ accessed: replayCtx.dbSnapshotAccessed === true,
6122
+ timings: replayCtx.dbBranchTimings
6099
6123
  }
6100
6124
  }
6101
6125
  });
@@ -6427,7 +6451,13 @@ var Bitfab = class {
6427
6451
  // against servers that predate the rename.
6428
6452
  source_trace_id: params.dbSnapshotUsage.originalTraceId
6429
6453
  },
6430
- accessed: params.dbSnapshotUsage.accessed
6454
+ accessed: params.dbSnapshotUsage.accessed,
6455
+ // Echoed verbatim (camelCase inside) rather than re-cased into this
6456
+ // record's snake_case: it is the server's own object coming back, and
6457
+ // a translation layer here is one more thing to drift.
6458
+ ...params.dbSnapshotUsage.timings && {
6459
+ timings: params.dbSnapshotUsage.timings
6460
+ }
6431
6461
  };
6432
6462
  }
6433
6463
  this.httpClient.sendExternalTrace({