bitfab 0.19.0 → 0.20.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
@@ -396,6 +396,13 @@ interface ReplayOptions {
396
396
  environment?: ReplayEnvironment;
397
397
  /** Group ID to associate this replay with an experiment group for live streaming in Studio. */
398
398
  experimentGroupId?: string;
399
+ /**
400
+ * Dataset this replay runs against. When set, the resulting experiment is
401
+ * durably attributed to the dataset (stored on the test run), so it appears
402
+ * under the dataset's experiments even if the trace lineage can't be
403
+ * reconstructed. Validated server-side against the org.
404
+ */
405
+ datasetId?: string;
399
406
  /**
400
407
  * Reshape recorded inputs before they are spread into `fn`.
401
408
  *
@@ -1063,7 +1070,7 @@ declare class BitfabFunction {
1063
1070
  /**
1064
1071
  * SDK version from package.json (injected at build time)
1065
1072
  */
1066
- declare const __version__ = "0.19.0";
1073
+ declare const __version__ = "0.20.0";
1067
1074
 
1068
1075
  /**
1069
1076
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -396,6 +396,13 @@ interface ReplayOptions {
396
396
  environment?: ReplayEnvironment;
397
397
  /** Group ID to associate this replay with an experiment group for live streaming in Studio. */
398
398
  experimentGroupId?: string;
399
+ /**
400
+ * Dataset this replay runs against. When set, the resulting experiment is
401
+ * durably attributed to the dataset (stored on the test run), so it appears
402
+ * under the dataset's experiments even if the trace lineage can't be
403
+ * reconstructed. Validated server-side against the org.
404
+ */
405
+ datasetId?: string;
399
406
  /**
400
407
  * Reshape recorded inputs before they are spread into `fn`.
401
408
  *
@@ -1063,7 +1070,7 @@ declare class BitfabFunction {
1063
1070
  /**
1064
1071
  * SDK version from package.json (injected at build time)
1065
1072
  */
1066
- declare const __version__ = "0.19.0";
1073
+ declare const __version__ = "0.20.0";
1067
1074
 
1068
1075
  /**
1069
1076
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  flushTraces,
21
21
  getCurrentSpan,
22
22
  getCurrentTrace
23
- } from "./chunk-FA6DBCAT.js";
23
+ } from "./chunk-IUZIGC6T.js";
24
24
  import {
25
25
  BitfabError
26
26
  } from "./chunk-EQI6ZJC3.js";
package/dist/node.cjs CHANGED
@@ -410,7 +410,8 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
410
410
  options?.codeChangeFiles,
411
411
  options?.environment !== void 0,
412
412
  // includeDbBranchLease
413
- options?.experimentGroupId
413
+ options?.experimentGroupId,
414
+ options?.datasetId
414
415
  );
415
416
  const mockStrategy = options?.mock ?? "none";
416
417
  const maxConcurrency = options?.maxConcurrency ?? 10;
@@ -511,7 +512,7 @@ registerAsyncLocalStorageClass(
511
512
  );
512
513
 
513
514
  // src/version.generated.ts
514
- var __version__ = "0.19.0";
515
+ var __version__ = "0.20.0";
515
516
 
516
517
  // src/constants.ts
517
518
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -789,7 +790,7 @@ var HttpClient = class {
789
790
  * Start a replay session by fetching historical traces.
790
791
  * Blocking call — creates a test run and returns lightweight item references.
791
792
  */
792
- async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId) {
793
+ async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId) {
793
794
  const payload = { traceFunctionKey };
794
795
  if (limit !== void 0) {
795
796
  payload.limit = limit;
@@ -809,6 +810,9 @@ var HttpClient = class {
809
810
  if (experimentGroupId !== void 0) {
810
811
  payload.experimentGroupId = experimentGroupId;
811
812
  }
813
+ if (datasetId !== void 0) {
814
+ payload.datasetId = datasetId;
815
+ }
812
816
  const timeout = includeDbBranchLease ? 18e4 : 3e4;
813
817
  return this.request("/api/sdk/replay/start", payload, {
814
818
  timeout
@@ -932,23 +936,30 @@ function extractContentBlocks(content) {
932
936
  }
933
937
  return content.map((block) => safeSerialize(block));
934
938
  }
939
+ function asTokenCount(val) {
940
+ return typeof val === "number" && Number.isFinite(val) ? val : null;
941
+ }
935
942
  function extractUsage(message) {
936
943
  const usageInfo = {};
937
944
  const usage = message.usage;
938
945
  if (!usage) {
939
946
  return usageInfo;
940
947
  }
941
- const mapping = {
942
- input_tokens: "inputTokens",
943
- output_tokens: "outputTokens",
944
- cache_read_input_tokens: "cacheReadTokens",
945
- cache_creation_input_tokens: "cacheCreationTokens"
946
- };
947
- for (const [srcKey, dstKey] of Object.entries(mapping)) {
948
- const val = usage[srcKey];
949
- if (val !== void 0 && val !== null) {
950
- usageInfo[dstKey] = val;
951
- }
948
+ const baseInput = asTokenCount(usage.input_tokens);
949
+ const cacheRead = asTokenCount(usage.cache_read_input_tokens);
950
+ const cacheCreation = asTokenCount(usage.cache_creation_input_tokens);
951
+ if (baseInput !== null || cacheRead !== null || cacheCreation !== null) {
952
+ usageInfo.inputTokens = (baseInput ?? 0) + (cacheRead ?? 0) + (cacheCreation ?? 0);
953
+ }
954
+ const output = asTokenCount(usage.output_tokens);
955
+ if (output !== null) {
956
+ usageInfo.outputTokens = output;
957
+ }
958
+ if (cacheRead !== null) {
959
+ usageInfo.cacheReadTokens = cacheRead;
960
+ }
961
+ if (cacheCreation !== null) {
962
+ usageInfo.cacheCreationTokens = cacheCreation;
952
963
  }
953
964
  return usageInfo;
954
965
  }
@@ -1742,7 +1753,7 @@ function extractModelName(serialized, metadata) {
1742
1753
  }
1743
1754
  return void 0;
1744
1755
  }
1745
- function asTokenCount(value) {
1756
+ function asTokenCount2(value) {
1746
1757
  return typeof value === "number" && Number.isFinite(value) ? value : null;
1747
1758
  }
1748
1759
  function normalizeTokenUsage(raw) {
@@ -1751,10 +1762,10 @@ function normalizeTokenUsage(raw) {
1751
1762
  }
1752
1763
  const u = raw;
1753
1764
  if ("cache_read_input_tokens" in u || "cache_creation_input_tokens" in u) {
1754
- const cacheRead = asTokenCount(u.cache_read_input_tokens);
1755
- const cacheCreation = asTokenCount(u.cache_creation_input_tokens);
1756
- const baseInput = asTokenCount(u.input_tokens);
1757
- const outputTokens = asTokenCount(u.output_tokens);
1765
+ const cacheRead = asTokenCount2(u.cache_read_input_tokens);
1766
+ const cacheCreation = asTokenCount2(u.cache_creation_input_tokens);
1767
+ const baseInput = asTokenCount2(u.input_tokens);
1768
+ const outputTokens = asTokenCount2(u.output_tokens);
1758
1769
  if (cacheRead === null && cacheCreation === null && baseInput === null && outputTokens === null) {
1759
1770
  return null;
1760
1771
  }
@@ -1769,25 +1780,25 @@ function normalizeTokenUsage(raw) {
1769
1780
  if ("prompt_tokens" in u || "completion_tokens" in u || "promptTokens" in u || "completionTokens" in u) {
1770
1781
  const promptDetails = u.prompt_tokens_details ?? {};
1771
1782
  return withAnyTokenCount({
1772
- inputTokens: asTokenCount(u.prompt_tokens) ?? asTokenCount(u.promptTokens),
1773
- outputTokens: asTokenCount(u.completion_tokens) ?? asTokenCount(u.completionTokens),
1774
- totalTokens: asTokenCount(u.total_tokens) ?? asTokenCount(u.totalTokens),
1775
- cachedInputTokens: asTokenCount(promptDetails.cached_tokens)
1783
+ inputTokens: asTokenCount2(u.prompt_tokens) ?? asTokenCount2(u.promptTokens),
1784
+ outputTokens: asTokenCount2(u.completion_tokens) ?? asTokenCount2(u.completionTokens),
1785
+ totalTokens: asTokenCount2(u.total_tokens) ?? asTokenCount2(u.totalTokens),
1786
+ cachedInputTokens: asTokenCount2(promptDetails.cached_tokens)
1776
1787
  });
1777
1788
  }
1778
1789
  if ("prompt_token_count" in u || "candidates_token_count" in u) {
1779
1790
  return withAnyTokenCount({
1780
- inputTokens: asTokenCount(u.prompt_token_count),
1781
- outputTokens: asTokenCount(u.candidates_token_count),
1782
- totalTokens: asTokenCount(u.total_token_count),
1783
- cachedInputTokens: asTokenCount(u.cached_content_token_count)
1791
+ inputTokens: asTokenCount2(u.prompt_token_count),
1792
+ outputTokens: asTokenCount2(u.candidates_token_count),
1793
+ totalTokens: asTokenCount2(u.total_token_count),
1794
+ cachedInputTokens: asTokenCount2(u.cached_content_token_count)
1784
1795
  });
1785
1796
  }
1786
1797
  if ("input_tokens" in u || "output_tokens" in u) {
1787
1798
  const inputDetails = u.input_token_details ?? {};
1788
- const inputTokens = asTokenCount(u.input_tokens);
1789
- const outputTokens = asTokenCount(u.output_tokens);
1790
- let totalTokens = asTokenCount(u.total_tokens);
1799
+ const inputTokens = asTokenCount2(u.input_tokens);
1800
+ const outputTokens = asTokenCount2(u.output_tokens);
1801
+ let totalTokens = asTokenCount2(u.total_tokens);
1791
1802
  if (totalTokens === null && inputTokens !== null && outputTokens !== null) {
1792
1803
  totalTokens = inputTokens + outputTokens;
1793
1804
  }
@@ -1795,7 +1806,7 @@ function normalizeTokenUsage(raw) {
1795
1806
  inputTokens,
1796
1807
  outputTokens,
1797
1808
  totalTokens,
1798
- cachedInputTokens: asTokenCount(inputDetails.cache_read)
1809
+ cachedInputTokens: asTokenCount2(inputDetails.cache_read)
1799
1810
  });
1800
1811
  }
1801
1812
  return null;