bitfab 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
@@ -23,11 +23,14 @@ import {
23
23
  flushTraces,
24
24
  getCurrentSpan,
25
25
  getCurrentTrace
26
- } from "./chunk-DW7VTEO2.js";
26
+ } from "./chunk-H5QQ54UI.js";
27
27
  import {
28
- BitfabError
29
- } from "./chunk-IDGR2OIX.js";
28
+ BITFAB_PROGRESS_PREFIX,
29
+ BitfabError,
30
+ reportReplayProgress
31
+ } from "./chunk-MD4XQGAF.js";
30
32
  export {
33
+ BITFAB_PROGRESS_PREFIX,
31
34
  Bitfab,
32
35
  BitfabClaudeAgentHandler,
33
36
  BitfabError,
@@ -44,6 +47,7 @@ export {
44
47
  finalizers,
45
48
  flushTraces,
46
49
  getCurrentSpan,
47
- getCurrentTrace
50
+ getCurrentTrace,
51
+ reportReplayProgress
48
52
  };
49
53
  //# sourceMappingURL=index.js.map
package/dist/node.cjs CHANGED
@@ -323,8 +323,21 @@ var init_replayContext = __esm({
323
323
  // src/replay.ts
324
324
  var replay_exports = {};
325
325
  __export(replay_exports, {
326
- replay: () => replay
326
+ BITFAB_PROGRESS_PREFIX: () => BITFAB_PROGRESS_PREFIX,
327
+ replay: () => replay,
328
+ reportReplayProgress: () => reportReplayProgress
327
329
  });
330
+ function reportReplayProgress(progress) {
331
+ const stderr = typeof process !== "undefined" ? process.stderr : void 0;
332
+ if (!stderr) {
333
+ return;
334
+ }
335
+ try {
336
+ stderr.write(`${BITFAB_PROGRESS_PREFIX}${JSON.stringify(progress)}
337
+ `);
338
+ } catch {
339
+ }
340
+ }
328
341
  function deserializeInputs(spanData) {
329
342
  const inputMeta = spanData.input_meta;
330
343
  const rawInput = spanData.input;
@@ -495,6 +508,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
495
508
  // the count), so it's omitted from the request entirely.
496
509
  options?.traceIds ? void 0 : options?.limit ?? 5,
497
510
  options?.traceIds,
511
+ options?.name,
498
512
  options?.codeChangeDescription,
499
513
  options?.codeChangeFiles,
500
514
  options?.environment !== void 0,
@@ -522,7 +536,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
522
536
  const resultItems = await mapWithConcurrency(
523
537
  tasks,
524
538
  maxConcurrency,
525
- options?.onProgress ? (item) => {
539
+ options?.onProgress ? (item, index) => {
526
540
  completed += 1;
527
541
  if (item.error === null) {
528
542
  succeeded += 1;
@@ -530,7 +544,20 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
530
544
  errored += 1;
531
545
  }
532
546
  try {
533
- options?.onProgress?.({ completed, total, succeeded, errored });
547
+ options?.onProgress?.({
548
+ completed,
549
+ total,
550
+ succeeded,
551
+ errored,
552
+ item: {
553
+ // Source (historical) trace id, so a UI can identify the trace
554
+ // that just settled. The item's own traceId is the new replay
555
+ // trace and is assigned later (below), so use the server item.
556
+ traceId: serverItems[index]?.traceId ?? null,
557
+ error: item.error,
558
+ durationMs: item.durationMs
559
+ }
560
+ });
534
561
  } catch {
535
562
  }
536
563
  } : void 0
@@ -587,6 +614,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
587
614
  testRunUrl: `${serviceUrl}${testRunUrl}`
588
615
  };
589
616
  }
617
+ var BITFAB_PROGRESS_PREFIX;
590
618
  var init_replay = __esm({
591
619
  "src/replay.ts"() {
592
620
  "use strict";
@@ -594,12 +622,14 @@ var init_replay = __esm({
594
622
  init_randomUuid();
595
623
  init_replayContext();
596
624
  init_serialize();
625
+ BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
597
626
  }
598
627
  });
599
628
 
600
629
  // src/node.ts
601
630
  var node_exports = {};
602
631
  __export(node_exports, {
632
+ BITFAB_PROGRESS_PREFIX: () => BITFAB_PROGRESS_PREFIX,
603
633
  Bitfab: () => Bitfab,
604
634
  BitfabClaudeAgentHandler: () => BitfabClaudeAgentHandler,
605
635
  BitfabError: () => BitfabError,
@@ -616,7 +646,8 @@ __export(node_exports, {
616
646
  finalizers: () => finalizers,
617
647
  flushTraces: () => flushTraces,
618
648
  getCurrentSpan: () => getCurrentSpan,
619
- getCurrentTrace: () => getCurrentTrace
649
+ getCurrentTrace: () => getCurrentTrace,
650
+ reportReplayProgress: () => reportReplayProgress
620
651
  });
621
652
  module.exports = __toCommonJS(node_exports);
622
653
 
@@ -628,7 +659,7 @@ registerAsyncLocalStorageClass(
628
659
  );
629
660
 
630
661
  // src/version.generated.ts
631
- var __version__ = "0.26.2";
662
+ var __version__ = "0.27.1";
632
663
 
633
664
  // src/constants.ts
634
665
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -936,7 +967,7 @@ var HttpClient = class {
936
967
  * Start a replay session by fetching historical traces.
937
968
  * Blocking call — creates a test run and returns lightweight item references.
938
969
  */
939
- async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId) {
970
+ async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId) {
940
971
  const payload = { traceFunctionKey };
941
972
  if (limit !== void 0) {
942
973
  payload.limit = limit;
@@ -944,6 +975,9 @@ var HttpClient = class {
944
975
  if (traceIds) {
945
976
  payload.traceIds = traceIds;
946
977
  }
978
+ if (name !== void 0) {
979
+ payload.name = name;
980
+ }
947
981
  if (codeChangeDescription !== void 0) {
948
982
  payload.codeChangeDescription = codeChangeDescription;
949
983
  }
@@ -4370,11 +4404,15 @@ var finalizers = {
4370
4404
  readableStream
4371
4405
  };
4372
4406
 
4407
+ // src/index.ts
4408
+ init_replay();
4409
+
4373
4410
  // src/node.ts
4374
4411
  init_asyncStorage();
4375
4412
  assertAsyncStorageRegistered();
4376
4413
  // Annotate the CommonJS export names for ESM import in node:
4377
4414
  0 && (module.exports = {
4415
+ BITFAB_PROGRESS_PREFIX,
4378
4416
  Bitfab,
4379
4417
  BitfabClaudeAgentHandler,
4380
4418
  BitfabError,
@@ -4391,6 +4429,7 @@ assertAsyncStorageRegistered();
4391
4429
  finalizers,
4392
4430
  flushTraces,
4393
4431
  getCurrentSpan,
4394
- getCurrentTrace
4432
+ getCurrentTrace,
4433
+ reportReplayProgress
4395
4434
  });
4396
4435
  //# sourceMappingURL=node.cjs.map