@bitfab/sdk 0.26.2 → 0.27.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/index.d.cts CHANGED
@@ -579,9 +579,9 @@ declare class ReplayEnvironment {
579
579
  * Replay historical traces through a function and create a test run.
580
580
  *
581
581
  * The replay flow has three phases:
582
- * 1. Start fetches historical traces from the server and creates a test run
583
- * 2. Execute re-runs each trace's inputs through the provided function locally
584
- * 3. Complete marks the test run as completed on the server
582
+ * 1. Start: fetches historical traces from the server and creates a test run
583
+ * 2. Execute: re-runs each trace's inputs through the provided function locally
584
+ * 3. Complete: marks the test run as completed on the server
585
585
  */
586
586
 
587
587
  type MockStrategy = "none" | "all" | "marked";
@@ -594,6 +594,8 @@ interface ReplayOptions {
594
594
  limit?: number;
595
595
  /** Optional list of specific trace IDs to replay (max 100). */
596
596
  traceIds?: string[];
597
+ /** Optional display name for the resulting experiment/test run. */
598
+ name?: string;
597
599
  /** Maximum number of items to process in parallel. Set to 1 for sequential. Default 10. */
598
600
  maxConcurrency?: number;
599
601
  /**
@@ -603,7 +605,7 @@ interface ReplayOptions {
603
605
  codeChangeDescription?: string;
604
606
  /**
605
607
  * Files edited as part of this code change. Each entry holds the file path
606
- * and the full `before`/`after` contents the agent reads each file before
608
+ * and the full `before`/`after` contents. The agent reads each file before
607
609
  * and after editing and passes the two strings. Use `""` for newly created
608
610
  * files (`before`) or deleted files (`after`).
609
611
  */
@@ -675,7 +677,44 @@ interface ReplayProgress {
675
677
  succeeded: number;
676
678
  /** Of the completed items, how many threw (their `item.error` is set). */
677
679
  errored: number;
680
+ /**
681
+ * The single item that just settled to produce this event. `traceId` is the
682
+ * source (historical) trace that was replayed (so a UI can identify or link
683
+ * it); `error` is its replay error, or null when it ran ok; `durationMs` is how
684
+ * long this one trace took to replay. Lets a progress UI show per-trace
685
+ * pass/fail and timing as the run streams, without waiting for the full
686
+ * {@link ReplayResult}.
687
+ */
688
+ item?: {
689
+ traceId: string | null;
690
+ error: string | null;
691
+ durationMs: number | null;
692
+ };
678
693
  }
694
+ /**
695
+ * Wire prefix the Bitfab plugin scans for. Each line {@link reportReplayProgress}
696
+ * writes is this prefix followed by the JSON of the running totals (plus the
697
+ * settled `item`). The plugin polls these lines to report live progress while a
698
+ * replay runs in the background; keep the SDK emitter and the plugin parser in
699
+ * sync.
700
+ */
701
+ declare const BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
702
+ /**
703
+ * A ready-made {@link ReplayOptions.onProgress} callback for replay scripts.
704
+ * Pass it straight in:
705
+ *
706
+ * ```ts
707
+ * await bitfab.replay("my-fn", fn, { limit, onProgress: reportReplayProgress })
708
+ * ```
709
+ *
710
+ * It writes one `@@bitfab:progress` line per trace to stderr, which the Bitfab
711
+ * plugin polls to report live progress while the replay runs in the background,
712
+ * so scripts never hand-format the wire protocol.
713
+ * stdout is left untouched for the ReplayResult JSON. Outside Node (no
714
+ * `process.stderr`, e.g. a browser) it is a no-op, and a write failure is
715
+ * swallowed so progress can never crash a run.
716
+ */
717
+ declare function reportReplayProgress(progress: ReplayProgress): void;
679
718
  /** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
680
719
  interface AdaptContext {
681
720
  /** Bitfab trace ID of the historical trace being replayed. */
@@ -1491,7 +1530,7 @@ declare class BitfabFunction {
1491
1530
  /**
1492
1531
  * SDK version from package.json (injected at build time)
1493
1532
  */
1494
- declare const __version__ = "0.26.2";
1533
+ declare const __version__ = "0.27.1";
1495
1534
 
1496
1535
  /**
1497
1536
  * Constants for the Bitfab SDK.
@@ -1559,4 +1598,4 @@ declare const finalizers: {
1559
1598
  readableStream: typeof readableStream;
1560
1599
  };
1561
1600
 
1562
- 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 };
1601
+ 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 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, reportReplayProgress };
package/dist/index.d.ts CHANGED
@@ -579,9 +579,9 @@ declare class ReplayEnvironment {
579
579
  * Replay historical traces through a function and create a test run.
580
580
  *
581
581
  * The replay flow has three phases:
582
- * 1. Start fetches historical traces from the server and creates a test run
583
- * 2. Execute re-runs each trace's inputs through the provided function locally
584
- * 3. Complete marks the test run as completed on the server
582
+ * 1. Start: fetches historical traces from the server and creates a test run
583
+ * 2. Execute: re-runs each trace's inputs through the provided function locally
584
+ * 3. Complete: marks the test run as completed on the server
585
585
  */
586
586
 
587
587
  type MockStrategy = "none" | "all" | "marked";
@@ -594,6 +594,8 @@ interface ReplayOptions {
594
594
  limit?: number;
595
595
  /** Optional list of specific trace IDs to replay (max 100). */
596
596
  traceIds?: string[];
597
+ /** Optional display name for the resulting experiment/test run. */
598
+ name?: string;
597
599
  /** Maximum number of items to process in parallel. Set to 1 for sequential. Default 10. */
598
600
  maxConcurrency?: number;
599
601
  /**
@@ -603,7 +605,7 @@ interface ReplayOptions {
603
605
  codeChangeDescription?: string;
604
606
  /**
605
607
  * Files edited as part of this code change. Each entry holds the file path
606
- * and the full `before`/`after` contents the agent reads each file before
608
+ * and the full `before`/`after` contents. The agent reads each file before
607
609
  * and after editing and passes the two strings. Use `""` for newly created
608
610
  * files (`before`) or deleted files (`after`).
609
611
  */
@@ -675,7 +677,44 @@ interface ReplayProgress {
675
677
  succeeded: number;
676
678
  /** Of the completed items, how many threw (their `item.error` is set). */
677
679
  errored: number;
680
+ /**
681
+ * The single item that just settled to produce this event. `traceId` is the
682
+ * source (historical) trace that was replayed (so a UI can identify or link
683
+ * it); `error` is its replay error, or null when it ran ok; `durationMs` is how
684
+ * long this one trace took to replay. Lets a progress UI show per-trace
685
+ * pass/fail and timing as the run streams, without waiting for the full
686
+ * {@link ReplayResult}.
687
+ */
688
+ item?: {
689
+ traceId: string | null;
690
+ error: string | null;
691
+ durationMs: number | null;
692
+ };
678
693
  }
694
+ /**
695
+ * Wire prefix the Bitfab plugin scans for. Each line {@link reportReplayProgress}
696
+ * writes is this prefix followed by the JSON of the running totals (plus the
697
+ * settled `item`). The plugin polls these lines to report live progress while a
698
+ * replay runs in the background; keep the SDK emitter and the plugin parser in
699
+ * sync.
700
+ */
701
+ declare const BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
702
+ /**
703
+ * A ready-made {@link ReplayOptions.onProgress} callback for replay scripts.
704
+ * Pass it straight in:
705
+ *
706
+ * ```ts
707
+ * await bitfab.replay("my-fn", fn, { limit, onProgress: reportReplayProgress })
708
+ * ```
709
+ *
710
+ * It writes one `@@bitfab:progress` line per trace to stderr, which the Bitfab
711
+ * plugin polls to report live progress while the replay runs in the background,
712
+ * so scripts never hand-format the wire protocol.
713
+ * stdout is left untouched for the ReplayResult JSON. Outside Node (no
714
+ * `process.stderr`, e.g. a browser) it is a no-op, and a write failure is
715
+ * swallowed so progress can never crash a run.
716
+ */
717
+ declare function reportReplayProgress(progress: ReplayProgress): void;
679
718
  /** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
680
719
  interface AdaptContext {
681
720
  /** Bitfab trace ID of the historical trace being replayed. */
@@ -1491,7 +1530,7 @@ declare class BitfabFunction {
1491
1530
  /**
1492
1531
  * SDK version from package.json (injected at build time)
1493
1532
  */
1494
- declare const __version__ = "0.26.2";
1533
+ declare const __version__ = "0.27.1";
1495
1534
 
1496
1535
  /**
1497
1536
  * Constants for the Bitfab SDK.
@@ -1559,4 +1598,4 @@ declare const finalizers: {
1559
1598
  readableStream: typeof readableStream;
1560
1599
  };
1561
1600
 
1562
- 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 };
1601
+ 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 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, reportReplayProgress };
package/dist/index.js CHANGED
@@ -14,11 +14,14 @@ import {
14
14
  flushTraces,
15
15
  getCurrentSpan,
16
16
  getCurrentTrace
17
- } from "./chunk-DW7VTEO2.js";
17
+ } from "./chunk-H5QQ54UI.js";
18
18
  import {
19
- BitfabError
20
- } from "./chunk-IDGR2OIX.js";
19
+ BITFAB_PROGRESS_PREFIX,
20
+ BitfabError,
21
+ reportReplayProgress
22
+ } from "./chunk-MD4XQGAF.js";
21
23
  export {
24
+ BITFAB_PROGRESS_PREFIX,
22
25
  Bitfab,
23
26
  BitfabClaudeAgentHandler,
24
27
  BitfabError,
@@ -35,6 +38,7 @@ export {
35
38
  finalizers,
36
39
  flushTraces,
37
40
  getCurrentSpan,
38
- getCurrentTrace
41
+ getCurrentTrace,
42
+ reportReplayProgress
39
43
  };
40
44
  //# sourceMappingURL=index.js.map
package/dist/node.cjs CHANGED
@@ -314,8 +314,21 @@ var init_replayContext = __esm({
314
314
  // src/replay.ts
315
315
  var replay_exports = {};
316
316
  __export(replay_exports, {
317
- replay: () => replay
317
+ BITFAB_PROGRESS_PREFIX: () => BITFAB_PROGRESS_PREFIX,
318
+ replay: () => replay,
319
+ reportReplayProgress: () => reportReplayProgress
318
320
  });
321
+ function reportReplayProgress(progress) {
322
+ const stderr = typeof process !== "undefined" ? process.stderr : void 0;
323
+ if (!stderr) {
324
+ return;
325
+ }
326
+ try {
327
+ stderr.write(`${BITFAB_PROGRESS_PREFIX}${JSON.stringify(progress)}
328
+ `);
329
+ } catch {
330
+ }
331
+ }
319
332
  function deserializeInputs(spanData) {
320
333
  const inputMeta = spanData.input_meta;
321
334
  const rawInput = spanData.input;
@@ -486,6 +499,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
486
499
  // the count), so it's omitted from the request entirely.
487
500
  options?.traceIds ? void 0 : options?.limit ?? 5,
488
501
  options?.traceIds,
502
+ options?.name,
489
503
  options?.codeChangeDescription,
490
504
  options?.codeChangeFiles,
491
505
  options?.environment !== void 0,
@@ -513,7 +527,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
513
527
  const resultItems = await mapWithConcurrency(
514
528
  tasks,
515
529
  maxConcurrency,
516
- options?.onProgress ? (item) => {
530
+ options?.onProgress ? (item, index) => {
517
531
  completed += 1;
518
532
  if (item.error === null) {
519
533
  succeeded += 1;
@@ -521,7 +535,20 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
521
535
  errored += 1;
522
536
  }
523
537
  try {
524
- options?.onProgress?.({ completed, total, succeeded, errored });
538
+ options?.onProgress?.({
539
+ completed,
540
+ total,
541
+ succeeded,
542
+ errored,
543
+ item: {
544
+ // Source (historical) trace id, so a UI can identify the trace
545
+ // that just settled. The item's own traceId is the new replay
546
+ // trace and is assigned later (below), so use the server item.
547
+ traceId: serverItems[index]?.traceId ?? null,
548
+ error: item.error,
549
+ durationMs: item.durationMs
550
+ }
551
+ });
525
552
  } catch {
526
553
  }
527
554
  } : void 0
@@ -578,6 +605,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
578
605
  testRunUrl: `${serviceUrl}${testRunUrl}`
579
606
  };
580
607
  }
608
+ var BITFAB_PROGRESS_PREFIX;
581
609
  var init_replay = __esm({
582
610
  "src/replay.ts"() {
583
611
  "use strict";
@@ -585,12 +613,14 @@ var init_replay = __esm({
585
613
  init_randomUuid();
586
614
  init_replayContext();
587
615
  init_serialize();
616
+ BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
588
617
  }
589
618
  });
590
619
 
591
620
  // src/node.ts
592
621
  var node_exports = {};
593
622
  __export(node_exports, {
623
+ BITFAB_PROGRESS_PREFIX: () => BITFAB_PROGRESS_PREFIX,
594
624
  Bitfab: () => Bitfab,
595
625
  BitfabClaudeAgentHandler: () => BitfabClaudeAgentHandler,
596
626
  BitfabError: () => BitfabError,
@@ -607,7 +637,8 @@ __export(node_exports, {
607
637
  finalizers: () => finalizers,
608
638
  flushTraces: () => flushTraces,
609
639
  getCurrentSpan: () => getCurrentSpan,
610
- getCurrentTrace: () => getCurrentTrace
640
+ getCurrentTrace: () => getCurrentTrace,
641
+ reportReplayProgress: () => reportReplayProgress
611
642
  });
612
643
  module.exports = __toCommonJS(node_exports);
613
644
 
@@ -619,7 +650,7 @@ registerAsyncLocalStorageClass(
619
650
  );
620
651
 
621
652
  // src/version.generated.ts
622
- var __version__ = "0.26.2";
653
+ var __version__ = "0.27.1";
623
654
 
624
655
  // src/constants.ts
625
656
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -927,7 +958,7 @@ var HttpClient = class {
927
958
  * Start a replay session by fetching historical traces.
928
959
  * Blocking call — creates a test run and returns lightweight item references.
929
960
  */
930
- async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId) {
961
+ async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId) {
931
962
  const payload = { traceFunctionKey };
932
963
  if (limit !== void 0) {
933
964
  payload.limit = limit;
@@ -935,6 +966,9 @@ var HttpClient = class {
935
966
  if (traceIds) {
936
967
  payload.traceIds = traceIds;
937
968
  }
969
+ if (name !== void 0) {
970
+ payload.name = name;
971
+ }
938
972
  if (codeChangeDescription !== void 0) {
939
973
  payload.codeChangeDescription = codeChangeDescription;
940
974
  }
@@ -4361,11 +4395,15 @@ var finalizers = {
4361
4395
  readableStream
4362
4396
  };
4363
4397
 
4398
+ // src/index.ts
4399
+ init_replay();
4400
+
4364
4401
  // src/node.ts
4365
4402
  init_asyncStorage();
4366
4403
  assertAsyncStorageRegistered();
4367
4404
  // Annotate the CommonJS export names for ESM import in node:
4368
4405
  0 && (module.exports = {
4406
+ BITFAB_PROGRESS_PREFIX,
4369
4407
  Bitfab,
4370
4408
  BitfabClaudeAgentHandler,
4371
4409
  BitfabError,
@@ -4382,6 +4420,7 @@ assertAsyncStorageRegistered();
4382
4420
  finalizers,
4383
4421
  flushTraces,
4384
4422
  getCurrentSpan,
4385
- getCurrentTrace
4423
+ getCurrentTrace,
4424
+ reportReplayProgress
4386
4425
  });
4387
4426
  //# sourceMappingURL=node.cjs.map