@bitfab/sdk 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
@@ -11,7 +11,7 @@ import {
11
11
  flushTraces,
12
12
  getCurrentSpan,
13
13
  getCurrentTrace
14
- } from "./chunk-FA6DBCAT.js";
14
+ } from "./chunk-WZ72P5SX.js";
15
15
  import {
16
16
  BitfabError
17
17
  } from "./chunk-EQI6ZJC3.js";
package/dist/node.cjs CHANGED
@@ -502,7 +502,7 @@ registerAsyncLocalStorageClass(
502
502
  );
503
503
 
504
504
  // src/version.generated.ts
505
- var __version__ = "0.19.0";
505
+ var __version__ = "0.19.1";
506
506
 
507
507
  // src/constants.ts
508
508
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -923,23 +923,30 @@ function extractContentBlocks(content) {
923
923
  }
924
924
  return content.map((block) => safeSerialize(block));
925
925
  }
926
+ function asTokenCount(val) {
927
+ return typeof val === "number" && Number.isFinite(val) ? val : null;
928
+ }
926
929
  function extractUsage(message) {
927
930
  const usageInfo = {};
928
931
  const usage = message.usage;
929
932
  if (!usage) {
930
933
  return usageInfo;
931
934
  }
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
- }
935
+ const baseInput = asTokenCount(usage.input_tokens);
936
+ const cacheRead = asTokenCount(usage.cache_read_input_tokens);
937
+ const cacheCreation = asTokenCount(usage.cache_creation_input_tokens);
938
+ if (baseInput !== null || cacheRead !== null || cacheCreation !== null) {
939
+ usageInfo.inputTokens = (baseInput ?? 0) + (cacheRead ?? 0) + (cacheCreation ?? 0);
940
+ }
941
+ const output = asTokenCount(usage.output_tokens);
942
+ if (output !== null) {
943
+ usageInfo.outputTokens = output;
944
+ }
945
+ if (cacheRead !== null) {
946
+ usageInfo.cacheReadTokens = cacheRead;
947
+ }
948
+ if (cacheCreation !== null) {
949
+ usageInfo.cacheCreationTokens = cacheCreation;
943
950
  }
944
951
  return usageInfo;
945
952
  }
@@ -1733,7 +1740,7 @@ function extractModelName(serialized, metadata) {
1733
1740
  }
1734
1741
  return void 0;
1735
1742
  }
1736
- function asTokenCount(value) {
1743
+ function asTokenCount2(value) {
1737
1744
  return typeof value === "number" && Number.isFinite(value) ? value : null;
1738
1745
  }
1739
1746
  function normalizeTokenUsage(raw) {
@@ -1742,10 +1749,10 @@ function normalizeTokenUsage(raw) {
1742
1749
  }
1743
1750
  const u = raw;
1744
1751
  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);
1752
+ const cacheRead = asTokenCount2(u.cache_read_input_tokens);
1753
+ const cacheCreation = asTokenCount2(u.cache_creation_input_tokens);
1754
+ const baseInput = asTokenCount2(u.input_tokens);
1755
+ const outputTokens = asTokenCount2(u.output_tokens);
1749
1756
  if (cacheRead === null && cacheCreation === null && baseInput === null && outputTokens === null) {
1750
1757
  return null;
1751
1758
  }
@@ -1760,25 +1767,25 @@ function normalizeTokenUsage(raw) {
1760
1767
  if ("prompt_tokens" in u || "completion_tokens" in u || "promptTokens" in u || "completionTokens" in u) {
1761
1768
  const promptDetails = u.prompt_tokens_details ?? {};
1762
1769
  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)
1770
+ inputTokens: asTokenCount2(u.prompt_tokens) ?? asTokenCount2(u.promptTokens),
1771
+ outputTokens: asTokenCount2(u.completion_tokens) ?? asTokenCount2(u.completionTokens),
1772
+ totalTokens: asTokenCount2(u.total_tokens) ?? asTokenCount2(u.totalTokens),
1773
+ cachedInputTokens: asTokenCount2(promptDetails.cached_tokens)
1767
1774
  });
1768
1775
  }
1769
1776
  if ("prompt_token_count" in u || "candidates_token_count" in u) {
1770
1777
  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)
1778
+ inputTokens: asTokenCount2(u.prompt_token_count),
1779
+ outputTokens: asTokenCount2(u.candidates_token_count),
1780
+ totalTokens: asTokenCount2(u.total_token_count),
1781
+ cachedInputTokens: asTokenCount2(u.cached_content_token_count)
1775
1782
  });
1776
1783
  }
1777
1784
  if ("input_tokens" in u || "output_tokens" in u) {
1778
1785
  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);
1786
+ const inputTokens = asTokenCount2(u.input_tokens);
1787
+ const outputTokens = asTokenCount2(u.output_tokens);
1788
+ let totalTokens = asTokenCount2(u.total_tokens);
1782
1789
  if (totalTokens === null && inputTokens !== null && outputTokens !== null) {
1783
1790
  totalTokens = inputTokens + outputTokens;
1784
1791
  }
@@ -1786,7 +1793,7 @@ function normalizeTokenUsage(raw) {
1786
1793
  inputTokens,
1787
1794
  outputTokens,
1788
1795
  totalTokens,
1789
- cachedInputTokens: asTokenCount(inputDetails.cache_read)
1796
+ cachedInputTokens: asTokenCount2(inputDetails.cache_read)
1790
1797
  });
1791
1798
  }
1792
1799
  return null;