@bitfab/sdk 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.cjs CHANGED
@@ -394,7 +394,8 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
394
394
  options?.codeChangeFiles,
395
395
  options?.environment !== void 0,
396
396
  // includeDbBranchLease
397
- options?.experimentGroupId
397
+ options?.experimentGroupId,
398
+ options?.datasetId
398
399
  );
399
400
  const mockStrategy = options?.mock ?? "none";
400
401
  const maxConcurrency = options?.maxConcurrency ?? 10;
@@ -488,7 +489,7 @@ __export(index_exports, {
488
489
  module.exports = __toCommonJS(index_exports);
489
490
 
490
491
  // src/version.generated.ts
491
- var __version__ = "0.19.0";
492
+ var __version__ = "0.20.0";
492
493
 
493
494
  // src/constants.ts
494
495
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -766,7 +767,7 @@ var HttpClient = class {
766
767
  * Start a replay session by fetching historical traces.
767
768
  * Blocking call — creates a test run and returns lightweight item references.
768
769
  */
769
- async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId) {
770
+ async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId) {
770
771
  const payload = { traceFunctionKey };
771
772
  if (limit !== void 0) {
772
773
  payload.limit = limit;
@@ -786,6 +787,9 @@ var HttpClient = class {
786
787
  if (experimentGroupId !== void 0) {
787
788
  payload.experimentGroupId = experimentGroupId;
788
789
  }
790
+ if (datasetId !== void 0) {
791
+ payload.datasetId = datasetId;
792
+ }
789
793
  const timeout = includeDbBranchLease ? 18e4 : 3e4;
790
794
  return this.request("/api/sdk/replay/start", payload, {
791
795
  timeout
@@ -909,23 +913,30 @@ function extractContentBlocks(content) {
909
913
  }
910
914
  return content.map((block) => safeSerialize(block));
911
915
  }
916
+ function asTokenCount(val) {
917
+ return typeof val === "number" && Number.isFinite(val) ? val : null;
918
+ }
912
919
  function extractUsage(message) {
913
920
  const usageInfo = {};
914
921
  const usage = message.usage;
915
922
  if (!usage) {
916
923
  return usageInfo;
917
924
  }
918
- const mapping = {
919
- input_tokens: "inputTokens",
920
- output_tokens: "outputTokens",
921
- cache_read_input_tokens: "cacheReadTokens",
922
- cache_creation_input_tokens: "cacheCreationTokens"
923
- };
924
- for (const [srcKey, dstKey] of Object.entries(mapping)) {
925
- const val = usage[srcKey];
926
- if (val !== void 0 && val !== null) {
927
- usageInfo[dstKey] = val;
928
- }
925
+ const baseInput = asTokenCount(usage.input_tokens);
926
+ const cacheRead = asTokenCount(usage.cache_read_input_tokens);
927
+ const cacheCreation = asTokenCount(usage.cache_creation_input_tokens);
928
+ if (baseInput !== null || cacheRead !== null || cacheCreation !== null) {
929
+ usageInfo.inputTokens = (baseInput ?? 0) + (cacheRead ?? 0) + (cacheCreation ?? 0);
930
+ }
931
+ const output = asTokenCount(usage.output_tokens);
932
+ if (output !== null) {
933
+ usageInfo.outputTokens = output;
934
+ }
935
+ if (cacheRead !== null) {
936
+ usageInfo.cacheReadTokens = cacheRead;
937
+ }
938
+ if (cacheCreation !== null) {
939
+ usageInfo.cacheCreationTokens = cacheCreation;
929
940
  }
930
941
  return usageInfo;
931
942
  }
@@ -1719,7 +1730,7 @@ function extractModelName(serialized, metadata) {
1719
1730
  }
1720
1731
  return void 0;
1721
1732
  }
1722
- function asTokenCount(value) {
1733
+ function asTokenCount2(value) {
1723
1734
  return typeof value === "number" && Number.isFinite(value) ? value : null;
1724
1735
  }
1725
1736
  function normalizeTokenUsage(raw) {
@@ -1728,10 +1739,10 @@ function normalizeTokenUsage(raw) {
1728
1739
  }
1729
1740
  const u = raw;
1730
1741
  if ("cache_read_input_tokens" in u || "cache_creation_input_tokens" in u) {
1731
- const cacheRead = asTokenCount(u.cache_read_input_tokens);
1732
- const cacheCreation = asTokenCount(u.cache_creation_input_tokens);
1733
- const baseInput = asTokenCount(u.input_tokens);
1734
- const outputTokens = asTokenCount(u.output_tokens);
1742
+ const cacheRead = asTokenCount2(u.cache_read_input_tokens);
1743
+ const cacheCreation = asTokenCount2(u.cache_creation_input_tokens);
1744
+ const baseInput = asTokenCount2(u.input_tokens);
1745
+ const outputTokens = asTokenCount2(u.output_tokens);
1735
1746
  if (cacheRead === null && cacheCreation === null && baseInput === null && outputTokens === null) {
1736
1747
  return null;
1737
1748
  }
@@ -1746,25 +1757,25 @@ function normalizeTokenUsage(raw) {
1746
1757
  if ("prompt_tokens" in u || "completion_tokens" in u || "promptTokens" in u || "completionTokens" in u) {
1747
1758
  const promptDetails = u.prompt_tokens_details ?? {};
1748
1759
  return withAnyTokenCount({
1749
- inputTokens: asTokenCount(u.prompt_tokens) ?? asTokenCount(u.promptTokens),
1750
- outputTokens: asTokenCount(u.completion_tokens) ?? asTokenCount(u.completionTokens),
1751
- totalTokens: asTokenCount(u.total_tokens) ?? asTokenCount(u.totalTokens),
1752
- cachedInputTokens: asTokenCount(promptDetails.cached_tokens)
1760
+ inputTokens: asTokenCount2(u.prompt_tokens) ?? asTokenCount2(u.promptTokens),
1761
+ outputTokens: asTokenCount2(u.completion_tokens) ?? asTokenCount2(u.completionTokens),
1762
+ totalTokens: asTokenCount2(u.total_tokens) ?? asTokenCount2(u.totalTokens),
1763
+ cachedInputTokens: asTokenCount2(promptDetails.cached_tokens)
1753
1764
  });
1754
1765
  }
1755
1766
  if ("prompt_token_count" in u || "candidates_token_count" in u) {
1756
1767
  return withAnyTokenCount({
1757
- inputTokens: asTokenCount(u.prompt_token_count),
1758
- outputTokens: asTokenCount(u.candidates_token_count),
1759
- totalTokens: asTokenCount(u.total_token_count),
1760
- cachedInputTokens: asTokenCount(u.cached_content_token_count)
1768
+ inputTokens: asTokenCount2(u.prompt_token_count),
1769
+ outputTokens: asTokenCount2(u.candidates_token_count),
1770
+ totalTokens: asTokenCount2(u.total_token_count),
1771
+ cachedInputTokens: asTokenCount2(u.cached_content_token_count)
1761
1772
  });
1762
1773
  }
1763
1774
  if ("input_tokens" in u || "output_tokens" in u) {
1764
1775
  const inputDetails = u.input_token_details ?? {};
1765
- const inputTokens = asTokenCount(u.input_tokens);
1766
- const outputTokens = asTokenCount(u.output_tokens);
1767
- let totalTokens = asTokenCount(u.total_tokens);
1776
+ const inputTokens = asTokenCount2(u.input_tokens);
1777
+ const outputTokens = asTokenCount2(u.output_tokens);
1778
+ let totalTokens = asTokenCount2(u.total_tokens);
1768
1779
  if (totalTokens === null && inputTokens !== null && outputTokens !== null) {
1769
1780
  totalTokens = inputTokens + outputTokens;
1770
1781
  }
@@ -1772,7 +1783,7 @@ function normalizeTokenUsage(raw) {
1772
1783
  inputTokens,
1773
1784
  outputTokens,
1774
1785
  totalTokens,
1775
- cachedInputTokens: asTokenCount(inputDetails.cache_read)
1786
+ cachedInputTokens: asTokenCount2(inputDetails.cache_read)
1776
1787
  });
1777
1788
  }
1778
1789
  return null;