@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/{chunk-FA6DBCAT.js → chunk-WZ72P5SX.js} +37 -30
- package/dist/chunk-WZ72P5SX.js.map +1 -0
- package/dist/index.cjs +36 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/node.cjs +36 -29
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-FA6DBCAT.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -488,7 +488,7 @@ __export(index_exports, {
|
|
|
488
488
|
module.exports = __toCommonJS(index_exports);
|
|
489
489
|
|
|
490
490
|
// src/version.generated.ts
|
|
491
|
-
var __version__ = "0.19.
|
|
491
|
+
var __version__ = "0.19.1";
|
|
492
492
|
|
|
493
493
|
// src/constants.ts
|
|
494
494
|
var DEFAULT_SERVICE_URL = "https://bitfab.ai";
|
|
@@ -909,23 +909,30 @@ function extractContentBlocks(content) {
|
|
|
909
909
|
}
|
|
910
910
|
return content.map((block) => safeSerialize(block));
|
|
911
911
|
}
|
|
912
|
+
function asTokenCount(val) {
|
|
913
|
+
return typeof val === "number" && Number.isFinite(val) ? val : null;
|
|
914
|
+
}
|
|
912
915
|
function extractUsage(message) {
|
|
913
916
|
const usageInfo = {};
|
|
914
917
|
const usage = message.usage;
|
|
915
918
|
if (!usage) {
|
|
916
919
|
return usageInfo;
|
|
917
920
|
}
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
921
|
+
const baseInput = asTokenCount(usage.input_tokens);
|
|
922
|
+
const cacheRead = asTokenCount(usage.cache_read_input_tokens);
|
|
923
|
+
const cacheCreation = asTokenCount(usage.cache_creation_input_tokens);
|
|
924
|
+
if (baseInput !== null || cacheRead !== null || cacheCreation !== null) {
|
|
925
|
+
usageInfo.inputTokens = (baseInput ?? 0) + (cacheRead ?? 0) + (cacheCreation ?? 0);
|
|
926
|
+
}
|
|
927
|
+
const output = asTokenCount(usage.output_tokens);
|
|
928
|
+
if (output !== null) {
|
|
929
|
+
usageInfo.outputTokens = output;
|
|
930
|
+
}
|
|
931
|
+
if (cacheRead !== null) {
|
|
932
|
+
usageInfo.cacheReadTokens = cacheRead;
|
|
933
|
+
}
|
|
934
|
+
if (cacheCreation !== null) {
|
|
935
|
+
usageInfo.cacheCreationTokens = cacheCreation;
|
|
929
936
|
}
|
|
930
937
|
return usageInfo;
|
|
931
938
|
}
|
|
@@ -1719,7 +1726,7 @@ function extractModelName(serialized, metadata) {
|
|
|
1719
1726
|
}
|
|
1720
1727
|
return void 0;
|
|
1721
1728
|
}
|
|
1722
|
-
function
|
|
1729
|
+
function asTokenCount2(value) {
|
|
1723
1730
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1724
1731
|
}
|
|
1725
1732
|
function normalizeTokenUsage(raw) {
|
|
@@ -1728,10 +1735,10 @@ function normalizeTokenUsage(raw) {
|
|
|
1728
1735
|
}
|
|
1729
1736
|
const u = raw;
|
|
1730
1737
|
if ("cache_read_input_tokens" in u || "cache_creation_input_tokens" in u) {
|
|
1731
|
-
const cacheRead =
|
|
1732
|
-
const cacheCreation =
|
|
1733
|
-
const baseInput =
|
|
1734
|
-
const outputTokens =
|
|
1738
|
+
const cacheRead = asTokenCount2(u.cache_read_input_tokens);
|
|
1739
|
+
const cacheCreation = asTokenCount2(u.cache_creation_input_tokens);
|
|
1740
|
+
const baseInput = asTokenCount2(u.input_tokens);
|
|
1741
|
+
const outputTokens = asTokenCount2(u.output_tokens);
|
|
1735
1742
|
if (cacheRead === null && cacheCreation === null && baseInput === null && outputTokens === null) {
|
|
1736
1743
|
return null;
|
|
1737
1744
|
}
|
|
@@ -1746,25 +1753,25 @@ function normalizeTokenUsage(raw) {
|
|
|
1746
1753
|
if ("prompt_tokens" in u || "completion_tokens" in u || "promptTokens" in u || "completionTokens" in u) {
|
|
1747
1754
|
const promptDetails = u.prompt_tokens_details ?? {};
|
|
1748
1755
|
return withAnyTokenCount({
|
|
1749
|
-
inputTokens:
|
|
1750
|
-
outputTokens:
|
|
1751
|
-
totalTokens:
|
|
1752
|
-
cachedInputTokens:
|
|
1756
|
+
inputTokens: asTokenCount2(u.prompt_tokens) ?? asTokenCount2(u.promptTokens),
|
|
1757
|
+
outputTokens: asTokenCount2(u.completion_tokens) ?? asTokenCount2(u.completionTokens),
|
|
1758
|
+
totalTokens: asTokenCount2(u.total_tokens) ?? asTokenCount2(u.totalTokens),
|
|
1759
|
+
cachedInputTokens: asTokenCount2(promptDetails.cached_tokens)
|
|
1753
1760
|
});
|
|
1754
1761
|
}
|
|
1755
1762
|
if ("prompt_token_count" in u || "candidates_token_count" in u) {
|
|
1756
1763
|
return withAnyTokenCount({
|
|
1757
|
-
inputTokens:
|
|
1758
|
-
outputTokens:
|
|
1759
|
-
totalTokens:
|
|
1760
|
-
cachedInputTokens:
|
|
1764
|
+
inputTokens: asTokenCount2(u.prompt_token_count),
|
|
1765
|
+
outputTokens: asTokenCount2(u.candidates_token_count),
|
|
1766
|
+
totalTokens: asTokenCount2(u.total_token_count),
|
|
1767
|
+
cachedInputTokens: asTokenCount2(u.cached_content_token_count)
|
|
1761
1768
|
});
|
|
1762
1769
|
}
|
|
1763
1770
|
if ("input_tokens" in u || "output_tokens" in u) {
|
|
1764
1771
|
const inputDetails = u.input_token_details ?? {};
|
|
1765
|
-
const inputTokens =
|
|
1766
|
-
const outputTokens =
|
|
1767
|
-
let totalTokens =
|
|
1772
|
+
const inputTokens = asTokenCount2(u.input_tokens);
|
|
1773
|
+
const outputTokens = asTokenCount2(u.output_tokens);
|
|
1774
|
+
let totalTokens = asTokenCount2(u.total_tokens);
|
|
1768
1775
|
if (totalTokens === null && inputTokens !== null && outputTokens !== null) {
|
|
1769
1776
|
totalTokens = inputTokens + outputTokens;
|
|
1770
1777
|
}
|
|
@@ -1772,7 +1779,7 @@ function normalizeTokenUsage(raw) {
|
|
|
1772
1779
|
inputTokens,
|
|
1773
1780
|
outputTokens,
|
|
1774
1781
|
totalTokens,
|
|
1775
|
-
cachedInputTokens:
|
|
1782
|
+
cachedInputTokens: asTokenCount2(inputDetails.cache_read)
|
|
1776
1783
|
});
|
|
1777
1784
|
}
|
|
1778
1785
|
return null;
|