@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.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
@@ -11,7 +11,7 @@ import {
11
11
  flushTraces,
12
12
  getCurrentSpan,
13
13
  getCurrentTrace
14
- } from "./chunk-FA6DBCAT.js";
14
+ } from "./chunk-IUZIGC6T.js";
15
15
  import {
16
16
  BitfabError
17
17
  } from "./chunk-EQI6ZJC3.js";
package/dist/node.cjs CHANGED
@@ -401,7 +401,8 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options) {
401
401
  options?.codeChangeFiles,
402
402
  options?.environment !== void 0,
403
403
  // includeDbBranchLease
404
- options?.experimentGroupId
404
+ options?.experimentGroupId,
405
+ options?.datasetId
405
406
  );
406
407
  const mockStrategy = options?.mock ?? "none";
407
408
  const maxConcurrency = options?.maxConcurrency ?? 10;
@@ -502,7 +503,7 @@ registerAsyncLocalStorageClass(
502
503
  );
503
504
 
504
505
  // src/version.generated.ts
505
- var __version__ = "0.19.0";
506
+ var __version__ = "0.20.0";
506
507
 
507
508
  // src/constants.ts
508
509
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -780,7 +781,7 @@ var HttpClient = class {
780
781
  * Start a replay session by fetching historical traces.
781
782
  * Blocking call — creates a test run and returns lightweight item references.
782
783
  */
783
- async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId) {
784
+ async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId) {
784
785
  const payload = { traceFunctionKey };
785
786
  if (limit !== void 0) {
786
787
  payload.limit = limit;
@@ -800,6 +801,9 @@ var HttpClient = class {
800
801
  if (experimentGroupId !== void 0) {
801
802
  payload.experimentGroupId = experimentGroupId;
802
803
  }
804
+ if (datasetId !== void 0) {
805
+ payload.datasetId = datasetId;
806
+ }
803
807
  const timeout = includeDbBranchLease ? 18e4 : 3e4;
804
808
  return this.request("/api/sdk/replay/start", payload, {
805
809
  timeout
@@ -923,23 +927,30 @@ function extractContentBlocks(content) {
923
927
  }
924
928
  return content.map((block) => safeSerialize(block));
925
929
  }
930
+ function asTokenCount(val) {
931
+ return typeof val === "number" && Number.isFinite(val) ? val : null;
932
+ }
926
933
  function extractUsage(message) {
927
934
  const usageInfo = {};
928
935
  const usage = message.usage;
929
936
  if (!usage) {
930
937
  return usageInfo;
931
938
  }
932
- const mapping = {
933
- input_tokens: "inputTokens",
934
- output_tokens: "outputTokens",
935
- cache_read_input_tokens: "cacheReadTokens",
936
- cache_creation_input_tokens: "cacheCreationTokens"
937
- };
938
- for (const [srcKey, dstKey] of Object.entries(mapping)) {
939
- const val = usage[srcKey];
940
- if (val !== void 0 && val !== null) {
941
- usageInfo[dstKey] = val;
942
- }
939
+ const baseInput = asTokenCount(usage.input_tokens);
940
+ const cacheRead = asTokenCount(usage.cache_read_input_tokens);
941
+ const cacheCreation = asTokenCount(usage.cache_creation_input_tokens);
942
+ if (baseInput !== null || cacheRead !== null || cacheCreation !== null) {
943
+ usageInfo.inputTokens = (baseInput ?? 0) + (cacheRead ?? 0) + (cacheCreation ?? 0);
944
+ }
945
+ const output = asTokenCount(usage.output_tokens);
946
+ if (output !== null) {
947
+ usageInfo.outputTokens = output;
948
+ }
949
+ if (cacheRead !== null) {
950
+ usageInfo.cacheReadTokens = cacheRead;
951
+ }
952
+ if (cacheCreation !== null) {
953
+ usageInfo.cacheCreationTokens = cacheCreation;
943
954
  }
944
955
  return usageInfo;
945
956
  }
@@ -1733,7 +1744,7 @@ function extractModelName(serialized, metadata) {
1733
1744
  }
1734
1745
  return void 0;
1735
1746
  }
1736
- function asTokenCount(value) {
1747
+ function asTokenCount2(value) {
1737
1748
  return typeof value === "number" && Number.isFinite(value) ? value : null;
1738
1749
  }
1739
1750
  function normalizeTokenUsage(raw) {
@@ -1742,10 +1753,10 @@ function normalizeTokenUsage(raw) {
1742
1753
  }
1743
1754
  const u = raw;
1744
1755
  if ("cache_read_input_tokens" in u || "cache_creation_input_tokens" in u) {
1745
- const cacheRead = asTokenCount(u.cache_read_input_tokens);
1746
- const cacheCreation = asTokenCount(u.cache_creation_input_tokens);
1747
- const baseInput = asTokenCount(u.input_tokens);
1748
- const outputTokens = asTokenCount(u.output_tokens);
1756
+ const cacheRead = asTokenCount2(u.cache_read_input_tokens);
1757
+ const cacheCreation = asTokenCount2(u.cache_creation_input_tokens);
1758
+ const baseInput = asTokenCount2(u.input_tokens);
1759
+ const outputTokens = asTokenCount2(u.output_tokens);
1749
1760
  if (cacheRead === null && cacheCreation === null && baseInput === null && outputTokens === null) {
1750
1761
  return null;
1751
1762
  }
@@ -1760,25 +1771,25 @@ function normalizeTokenUsage(raw) {
1760
1771
  if ("prompt_tokens" in u || "completion_tokens" in u || "promptTokens" in u || "completionTokens" in u) {
1761
1772
  const promptDetails = u.prompt_tokens_details ?? {};
1762
1773
  return withAnyTokenCount({
1763
- inputTokens: asTokenCount(u.prompt_tokens) ?? asTokenCount(u.promptTokens),
1764
- outputTokens: asTokenCount(u.completion_tokens) ?? asTokenCount(u.completionTokens),
1765
- totalTokens: asTokenCount(u.total_tokens) ?? asTokenCount(u.totalTokens),
1766
- cachedInputTokens: asTokenCount(promptDetails.cached_tokens)
1774
+ inputTokens: asTokenCount2(u.prompt_tokens) ?? asTokenCount2(u.promptTokens),
1775
+ outputTokens: asTokenCount2(u.completion_tokens) ?? asTokenCount2(u.completionTokens),
1776
+ totalTokens: asTokenCount2(u.total_tokens) ?? asTokenCount2(u.totalTokens),
1777
+ cachedInputTokens: asTokenCount2(promptDetails.cached_tokens)
1767
1778
  });
1768
1779
  }
1769
1780
  if ("prompt_token_count" in u || "candidates_token_count" in u) {
1770
1781
  return withAnyTokenCount({
1771
- inputTokens: asTokenCount(u.prompt_token_count),
1772
- outputTokens: asTokenCount(u.candidates_token_count),
1773
- totalTokens: asTokenCount(u.total_token_count),
1774
- cachedInputTokens: asTokenCount(u.cached_content_token_count)
1782
+ inputTokens: asTokenCount2(u.prompt_token_count),
1783
+ outputTokens: asTokenCount2(u.candidates_token_count),
1784
+ totalTokens: asTokenCount2(u.total_token_count),
1785
+ cachedInputTokens: asTokenCount2(u.cached_content_token_count)
1775
1786
  });
1776
1787
  }
1777
1788
  if ("input_tokens" in u || "output_tokens" in u) {
1778
1789
  const inputDetails = u.input_token_details ?? {};
1779
- const inputTokens = asTokenCount(u.input_tokens);
1780
- const outputTokens = asTokenCount(u.output_tokens);
1781
- let totalTokens = asTokenCount(u.total_tokens);
1790
+ const inputTokens = asTokenCount2(u.input_tokens);
1791
+ const outputTokens = asTokenCount2(u.output_tokens);
1792
+ let totalTokens = asTokenCount2(u.total_tokens);
1782
1793
  if (totalTokens === null && inputTokens !== null && outputTokens !== null) {
1783
1794
  totalTokens = inputTokens + outputTokens;
1784
1795
  }
@@ -1786,7 +1797,7 @@ function normalizeTokenUsage(raw) {
1786
1797
  inputTokens,
1787
1798
  outputTokens,
1788
1799
  totalTokens,
1789
- cachedInputTokens: asTokenCount(inputDetails.cache_read)
1800
+ cachedInputTokens: asTokenCount2(inputDetails.cache_read)
1790
1801
  });
1791
1802
  }
1792
1803
  return null;