@bitfab/sdk 0.26.2 → 0.27.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
@@ -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";
@@ -603,7 +603,7 @@ interface ReplayOptions {
603
603
  codeChangeDescription?: string;
604
604
  /**
605
605
  * 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
606
+ * and the full `before`/`after` contents. The agent reads each file before
607
607
  * and after editing and passes the two strings. Use `""` for newly created
608
608
  * files (`before`) or deleted files (`after`).
609
609
  */
@@ -675,7 +675,44 @@ interface ReplayProgress {
675
675
  succeeded: number;
676
676
  /** Of the completed items, how many threw (their `item.error` is set). */
677
677
  errored: number;
678
+ /**
679
+ * The single item that just settled to produce this event. `traceId` is the
680
+ * source (historical) trace that was replayed (so a UI can identify or link
681
+ * it); `error` is its replay error, or null when it ran ok; `durationMs` is how
682
+ * long this one trace took to replay. Lets a progress UI show per-trace
683
+ * pass/fail and timing as the run streams, without waiting for the full
684
+ * {@link ReplayResult}.
685
+ */
686
+ item?: {
687
+ traceId: string | null;
688
+ error: string | null;
689
+ durationMs: number | null;
690
+ };
678
691
  }
692
+ /**
693
+ * Wire prefix the Bitfab plugin scans for. Each line {@link reportReplayProgress}
694
+ * writes is this prefix followed by the JSON of the running totals (plus the
695
+ * settled `item`). The plugin polls these lines to report live progress while a
696
+ * replay runs in the background; keep the SDK emitter and the plugin parser in
697
+ * sync.
698
+ */
699
+ declare const BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
700
+ /**
701
+ * A ready-made {@link ReplayOptions.onProgress} callback for replay scripts.
702
+ * Pass it straight in:
703
+ *
704
+ * ```ts
705
+ * await bitfab.replay("my-fn", fn, { limit, onProgress: reportReplayProgress })
706
+ * ```
707
+ *
708
+ * It writes one `@@bitfab:progress` line per trace to stderr, which the Bitfab
709
+ * plugin polls to report live progress while the replay runs in the background,
710
+ * so scripts never hand-format the wire protocol.
711
+ * stdout is left untouched for the ReplayResult JSON. Outside Node (no
712
+ * `process.stderr`, e.g. a browser) it is a no-op, and a write failure is
713
+ * swallowed so progress can never crash a run.
714
+ */
715
+ declare function reportReplayProgress(progress: ReplayProgress): void;
679
716
  /** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
680
717
  interface AdaptContext {
681
718
  /** Bitfab trace ID of the historical trace being replayed. */
@@ -1491,7 +1528,7 @@ declare class BitfabFunction {
1491
1528
  /**
1492
1529
  * SDK version from package.json (injected at build time)
1493
1530
  */
1494
- declare const __version__ = "0.26.2";
1531
+ declare const __version__ = "0.27.0";
1495
1532
 
1496
1533
  /**
1497
1534
  * Constants for the Bitfab SDK.
@@ -1559,4 +1596,4 @@ declare const finalizers: {
1559
1596
  readableStream: typeof readableStream;
1560
1597
  };
1561
1598
 
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 };
1599
+ 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";
@@ -603,7 +603,7 @@ interface ReplayOptions {
603
603
  codeChangeDescription?: string;
604
604
  /**
605
605
  * 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
606
+ * and the full `before`/`after` contents. The agent reads each file before
607
607
  * and after editing and passes the two strings. Use `""` for newly created
608
608
  * files (`before`) or deleted files (`after`).
609
609
  */
@@ -675,7 +675,44 @@ interface ReplayProgress {
675
675
  succeeded: number;
676
676
  /** Of the completed items, how many threw (their `item.error` is set). */
677
677
  errored: number;
678
+ /**
679
+ * The single item that just settled to produce this event. `traceId` is the
680
+ * source (historical) trace that was replayed (so a UI can identify or link
681
+ * it); `error` is its replay error, or null when it ran ok; `durationMs` is how
682
+ * long this one trace took to replay. Lets a progress UI show per-trace
683
+ * pass/fail and timing as the run streams, without waiting for the full
684
+ * {@link ReplayResult}.
685
+ */
686
+ item?: {
687
+ traceId: string | null;
688
+ error: string | null;
689
+ durationMs: number | null;
690
+ };
678
691
  }
692
+ /**
693
+ * Wire prefix the Bitfab plugin scans for. Each line {@link reportReplayProgress}
694
+ * writes is this prefix followed by the JSON of the running totals (plus the
695
+ * settled `item`). The plugin polls these lines to report live progress while a
696
+ * replay runs in the background; keep the SDK emitter and the plugin parser in
697
+ * sync.
698
+ */
699
+ declare const BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
700
+ /**
701
+ * A ready-made {@link ReplayOptions.onProgress} callback for replay scripts.
702
+ * Pass it straight in:
703
+ *
704
+ * ```ts
705
+ * await bitfab.replay("my-fn", fn, { limit, onProgress: reportReplayProgress })
706
+ * ```
707
+ *
708
+ * It writes one `@@bitfab:progress` line per trace to stderr, which the Bitfab
709
+ * plugin polls to report live progress while the replay runs in the background,
710
+ * so scripts never hand-format the wire protocol.
711
+ * stdout is left untouched for the ReplayResult JSON. Outside Node (no
712
+ * `process.stderr`, e.g. a browser) it is a no-op, and a write failure is
713
+ * swallowed so progress can never crash a run.
714
+ */
715
+ declare function reportReplayProgress(progress: ReplayProgress): void;
679
716
  /** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
680
717
  interface AdaptContext {
681
718
  /** Bitfab trace ID of the historical trace being replayed. */
@@ -1491,7 +1528,7 @@ declare class BitfabFunction {
1491
1528
  /**
1492
1529
  * SDK version from package.json (injected at build time)
1493
1530
  */
1494
- declare const __version__ = "0.26.2";
1531
+ declare const __version__ = "0.27.0";
1495
1532
 
1496
1533
  /**
1497
1534
  * Constants for the Bitfab SDK.
@@ -1559,4 +1596,4 @@ declare const finalizers: {
1559
1596
  readableStream: typeof readableStream;
1560
1597
  };
1561
1598
 
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 };
1599
+ 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-PFV4MPNS.js";
18
18
  import {
19
- BitfabError
20
- } from "./chunk-IDGR2OIX.js";
19
+ BITFAB_PROGRESS_PREFIX,
20
+ BitfabError,
21
+ reportReplayProgress
22
+ } from "./chunk-RNTDM6WM.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;
@@ -513,7 +526,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
513
526
  const resultItems = await mapWithConcurrency(
514
527
  tasks,
515
528
  maxConcurrency,
516
- options?.onProgress ? (item) => {
529
+ options?.onProgress ? (item, index) => {
517
530
  completed += 1;
518
531
  if (item.error === null) {
519
532
  succeeded += 1;
@@ -521,7 +534,20 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
521
534
  errored += 1;
522
535
  }
523
536
  try {
524
- options?.onProgress?.({ completed, total, succeeded, errored });
537
+ options?.onProgress?.({
538
+ completed,
539
+ total,
540
+ succeeded,
541
+ errored,
542
+ item: {
543
+ // Source (historical) trace id, so a UI can identify the trace
544
+ // that just settled. The item's own traceId is the new replay
545
+ // trace and is assigned later (below), so use the server item.
546
+ traceId: serverItems[index]?.traceId ?? null,
547
+ error: item.error,
548
+ durationMs: item.durationMs
549
+ }
550
+ });
525
551
  } catch {
526
552
  }
527
553
  } : void 0
@@ -578,6 +604,7 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
578
604
  testRunUrl: `${serviceUrl}${testRunUrl}`
579
605
  };
580
606
  }
607
+ var BITFAB_PROGRESS_PREFIX;
581
608
  var init_replay = __esm({
582
609
  "src/replay.ts"() {
583
610
  "use strict";
@@ -585,12 +612,14 @@ var init_replay = __esm({
585
612
  init_randomUuid();
586
613
  init_replayContext();
587
614
  init_serialize();
615
+ BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
588
616
  }
589
617
  });
590
618
 
591
619
  // src/node.ts
592
620
  var node_exports = {};
593
621
  __export(node_exports, {
622
+ BITFAB_PROGRESS_PREFIX: () => BITFAB_PROGRESS_PREFIX,
594
623
  Bitfab: () => Bitfab,
595
624
  BitfabClaudeAgentHandler: () => BitfabClaudeAgentHandler,
596
625
  BitfabError: () => BitfabError,
@@ -607,7 +636,8 @@ __export(node_exports, {
607
636
  finalizers: () => finalizers,
608
637
  flushTraces: () => flushTraces,
609
638
  getCurrentSpan: () => getCurrentSpan,
610
- getCurrentTrace: () => getCurrentTrace
639
+ getCurrentTrace: () => getCurrentTrace,
640
+ reportReplayProgress: () => reportReplayProgress
611
641
  });
612
642
  module.exports = __toCommonJS(node_exports);
613
643
 
@@ -619,7 +649,7 @@ registerAsyncLocalStorageClass(
619
649
  );
620
650
 
621
651
  // src/version.generated.ts
622
- var __version__ = "0.26.2";
652
+ var __version__ = "0.27.0";
623
653
 
624
654
  // src/constants.ts
625
655
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -4361,11 +4391,15 @@ var finalizers = {
4361
4391
  readableStream
4362
4392
  };
4363
4393
 
4394
+ // src/index.ts
4395
+ init_replay();
4396
+
4364
4397
  // src/node.ts
4365
4398
  init_asyncStorage();
4366
4399
  assertAsyncStorageRegistered();
4367
4400
  // Annotate the CommonJS export names for ESM import in node:
4368
4401
  0 && (module.exports = {
4402
+ BITFAB_PROGRESS_PREFIX,
4369
4403
  Bitfab,
4370
4404
  BitfabClaudeAgentHandler,
4371
4405
  BitfabError,
@@ -4382,6 +4416,7 @@ assertAsyncStorageRegistered();
4382
4416
  finalizers,
4383
4417
  flushTraces,
4384
4418
  getCurrentSpan,
4385
- getCurrentTrace
4419
+ getCurrentTrace,
4420
+ reportReplayProgress
4386
4421
  });
4387
4422
  //# sourceMappingURL=node.cjs.map