bitfab 0.19.0 → 0.19.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
@@ -1063,7 +1063,7 @@ declare class BitfabFunction {
1063
1063
  /**
1064
1064
  * SDK version from package.json (injected at build time)
1065
1065
  */
1066
- declare const __version__ = "0.19.0";
1066
+ declare const __version__ = "0.19.1";
1067
1067
 
1068
1068
  /**
1069
1069
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -1063,7 +1063,7 @@ declare class BitfabFunction {
1063
1063
  /**
1064
1064
  * SDK version from package.json (injected at build time)
1065
1065
  */
1066
- declare const __version__ = "0.19.0";
1066
+ declare const __version__ = "0.19.1";
1067
1067
 
1068
1068
  /**
1069
1069
  * 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-WZ72P5SX.js";
24
24
  import {
25
25
  BitfabError
26
26
  } from "./chunk-EQI6ZJC3.js";
package/dist/node.cjs CHANGED
@@ -511,7 +511,7 @@ registerAsyncLocalStorageClass(
511
511
  );
512
512
 
513
513
  // src/version.generated.ts
514
- var __version__ = "0.19.0";
514
+ var __version__ = "0.19.1";
515
515
 
516
516
  // src/constants.ts
517
517
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -932,23 +932,30 @@ function extractContentBlocks(content) {
932
932
  }
933
933
  return content.map((block) => safeSerialize(block));
934
934
  }
935
+ function asTokenCount(val) {
936
+ return typeof val === "number" && Number.isFinite(val) ? val : null;
937
+ }
935
938
  function extractUsage(message) {
936
939
  const usageInfo = {};
937
940
  const usage = message.usage;
938
941
  if (!usage) {
939
942
  return usageInfo;
940
943
  }
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
- }
944
+ const baseInput = asTokenCount(usage.input_tokens);
945
+ const cacheRead = asTokenCount(usage.cache_read_input_tokens);
946
+ const cacheCreation = asTokenCount(usage.cache_creation_input_tokens);
947
+ if (baseInput !== null || cacheRead !== null || cacheCreation !== null) {
948
+ usageInfo.inputTokens = (baseInput ?? 0) + (cacheRead ?? 0) + (cacheCreation ?? 0);
949
+ }
950
+ const output = asTokenCount(usage.output_tokens);
951
+ if (output !== null) {
952
+ usageInfo.outputTokens = output;
953
+ }
954
+ if (cacheRead !== null) {
955
+ usageInfo.cacheReadTokens = cacheRead;
956
+ }
957
+ if (cacheCreation !== null) {
958
+ usageInfo.cacheCreationTokens = cacheCreation;
952
959
  }
953
960
  return usageInfo;
954
961
  }
@@ -1742,7 +1749,7 @@ function extractModelName(serialized, metadata) {
1742
1749
  }
1743
1750
  return void 0;
1744
1751
  }
1745
- function asTokenCount(value) {
1752
+ function asTokenCount2(value) {
1746
1753
  return typeof value === "number" && Number.isFinite(value) ? value : null;
1747
1754
  }
1748
1755
  function normalizeTokenUsage(raw) {
@@ -1751,10 +1758,10 @@ function normalizeTokenUsage(raw) {
1751
1758
  }
1752
1759
  const u = raw;
1753
1760
  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);
1761
+ const cacheRead = asTokenCount2(u.cache_read_input_tokens);
1762
+ const cacheCreation = asTokenCount2(u.cache_creation_input_tokens);
1763
+ const baseInput = asTokenCount2(u.input_tokens);
1764
+ const outputTokens = asTokenCount2(u.output_tokens);
1758
1765
  if (cacheRead === null && cacheCreation === null && baseInput === null && outputTokens === null) {
1759
1766
  return null;
1760
1767
  }
@@ -1769,25 +1776,25 @@ function normalizeTokenUsage(raw) {
1769
1776
  if ("prompt_tokens" in u || "completion_tokens" in u || "promptTokens" in u || "completionTokens" in u) {
1770
1777
  const promptDetails = u.prompt_tokens_details ?? {};
1771
1778
  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)
1779
+ inputTokens: asTokenCount2(u.prompt_tokens) ?? asTokenCount2(u.promptTokens),
1780
+ outputTokens: asTokenCount2(u.completion_tokens) ?? asTokenCount2(u.completionTokens),
1781
+ totalTokens: asTokenCount2(u.total_tokens) ?? asTokenCount2(u.totalTokens),
1782
+ cachedInputTokens: asTokenCount2(promptDetails.cached_tokens)
1776
1783
  });
1777
1784
  }
1778
1785
  if ("prompt_token_count" in u || "candidates_token_count" in u) {
1779
1786
  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)
1787
+ inputTokens: asTokenCount2(u.prompt_token_count),
1788
+ outputTokens: asTokenCount2(u.candidates_token_count),
1789
+ totalTokens: asTokenCount2(u.total_token_count),
1790
+ cachedInputTokens: asTokenCount2(u.cached_content_token_count)
1784
1791
  });
1785
1792
  }
1786
1793
  if ("input_tokens" in u || "output_tokens" in u) {
1787
1794
  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);
1795
+ const inputTokens = asTokenCount2(u.input_tokens);
1796
+ const outputTokens = asTokenCount2(u.output_tokens);
1797
+ let totalTokens = asTokenCount2(u.total_tokens);
1791
1798
  if (totalTokens === null && inputTokens !== null && outputTokens !== null) {
1792
1799
  totalTokens = inputTokens + outputTokens;
1793
1800
  }
@@ -1795,7 +1802,7 @@ function normalizeTokenUsage(raw) {
1795
1802
  inputTokens,
1796
1803
  outputTokens,
1797
1804
  totalTokens,
1798
- cachedInputTokens: asTokenCount(inputDetails.cache_read)
1805
+ cachedInputTokens: asTokenCount2(inputDetails.cache_read)
1799
1806
  });
1800
1807
  }
1801
1808
  return null;