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.
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-EQI6ZJC3.js";
11
11
 
12
12
  // src/version.generated.ts
13
- var __version__ = "0.19.0";
13
+ var __version__ = "0.19.1";
14
14
 
15
15
  // src/constants.ts
16
16
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -429,23 +429,30 @@ function extractContentBlocks(content) {
429
429
  }
430
430
  return content.map((block) => safeSerialize(block));
431
431
  }
432
+ function asTokenCount(val) {
433
+ return typeof val === "number" && Number.isFinite(val) ? val : null;
434
+ }
432
435
  function extractUsage(message) {
433
436
  const usageInfo = {};
434
437
  const usage = message.usage;
435
438
  if (!usage) {
436
439
  return usageInfo;
437
440
  }
438
- const mapping = {
439
- input_tokens: "inputTokens",
440
- output_tokens: "outputTokens",
441
- cache_read_input_tokens: "cacheReadTokens",
442
- cache_creation_input_tokens: "cacheCreationTokens"
443
- };
444
- for (const [srcKey, dstKey] of Object.entries(mapping)) {
445
- const val = usage[srcKey];
446
- if (val !== void 0 && val !== null) {
447
- usageInfo[dstKey] = val;
448
- }
441
+ const baseInput = asTokenCount(usage.input_tokens);
442
+ const cacheRead = asTokenCount(usage.cache_read_input_tokens);
443
+ const cacheCreation = asTokenCount(usage.cache_creation_input_tokens);
444
+ if (baseInput !== null || cacheRead !== null || cacheCreation !== null) {
445
+ usageInfo.inputTokens = (baseInput ?? 0) + (cacheRead ?? 0) + (cacheCreation ?? 0);
446
+ }
447
+ const output = asTokenCount(usage.output_tokens);
448
+ if (output !== null) {
449
+ usageInfo.outputTokens = output;
450
+ }
451
+ if (cacheRead !== null) {
452
+ usageInfo.cacheReadTokens = cacheRead;
453
+ }
454
+ if (cacheCreation !== null) {
455
+ usageInfo.cacheCreationTokens = cacheCreation;
449
456
  }
450
457
  return usageInfo;
451
458
  }
@@ -1234,7 +1241,7 @@ function extractModelName(serialized, metadata) {
1234
1241
  }
1235
1242
  return void 0;
1236
1243
  }
1237
- function asTokenCount(value) {
1244
+ function asTokenCount2(value) {
1238
1245
  return typeof value === "number" && Number.isFinite(value) ? value : null;
1239
1246
  }
1240
1247
  function normalizeTokenUsage(raw) {
@@ -1243,10 +1250,10 @@ function normalizeTokenUsage(raw) {
1243
1250
  }
1244
1251
  const u = raw;
1245
1252
  if ("cache_read_input_tokens" in u || "cache_creation_input_tokens" in u) {
1246
- const cacheRead = asTokenCount(u.cache_read_input_tokens);
1247
- const cacheCreation = asTokenCount(u.cache_creation_input_tokens);
1248
- const baseInput = asTokenCount(u.input_tokens);
1249
- const outputTokens = asTokenCount(u.output_tokens);
1253
+ const cacheRead = asTokenCount2(u.cache_read_input_tokens);
1254
+ const cacheCreation = asTokenCount2(u.cache_creation_input_tokens);
1255
+ const baseInput = asTokenCount2(u.input_tokens);
1256
+ const outputTokens = asTokenCount2(u.output_tokens);
1250
1257
  if (cacheRead === null && cacheCreation === null && baseInput === null && outputTokens === null) {
1251
1258
  return null;
1252
1259
  }
@@ -1261,25 +1268,25 @@ function normalizeTokenUsage(raw) {
1261
1268
  if ("prompt_tokens" in u || "completion_tokens" in u || "promptTokens" in u || "completionTokens" in u) {
1262
1269
  const promptDetails = u.prompt_tokens_details ?? {};
1263
1270
  return withAnyTokenCount({
1264
- inputTokens: asTokenCount(u.prompt_tokens) ?? asTokenCount(u.promptTokens),
1265
- outputTokens: asTokenCount(u.completion_tokens) ?? asTokenCount(u.completionTokens),
1266
- totalTokens: asTokenCount(u.total_tokens) ?? asTokenCount(u.totalTokens),
1267
- cachedInputTokens: asTokenCount(promptDetails.cached_tokens)
1271
+ inputTokens: asTokenCount2(u.prompt_tokens) ?? asTokenCount2(u.promptTokens),
1272
+ outputTokens: asTokenCount2(u.completion_tokens) ?? asTokenCount2(u.completionTokens),
1273
+ totalTokens: asTokenCount2(u.total_tokens) ?? asTokenCount2(u.totalTokens),
1274
+ cachedInputTokens: asTokenCount2(promptDetails.cached_tokens)
1268
1275
  });
1269
1276
  }
1270
1277
  if ("prompt_token_count" in u || "candidates_token_count" in u) {
1271
1278
  return withAnyTokenCount({
1272
- inputTokens: asTokenCount(u.prompt_token_count),
1273
- outputTokens: asTokenCount(u.candidates_token_count),
1274
- totalTokens: asTokenCount(u.total_token_count),
1275
- cachedInputTokens: asTokenCount(u.cached_content_token_count)
1279
+ inputTokens: asTokenCount2(u.prompt_token_count),
1280
+ outputTokens: asTokenCount2(u.candidates_token_count),
1281
+ totalTokens: asTokenCount2(u.total_token_count),
1282
+ cachedInputTokens: asTokenCount2(u.cached_content_token_count)
1276
1283
  });
1277
1284
  }
1278
1285
  if ("input_tokens" in u || "output_tokens" in u) {
1279
1286
  const inputDetails = u.input_token_details ?? {};
1280
- const inputTokens = asTokenCount(u.input_tokens);
1281
- const outputTokens = asTokenCount(u.output_tokens);
1282
- let totalTokens = asTokenCount(u.total_tokens);
1287
+ const inputTokens = asTokenCount2(u.input_tokens);
1288
+ const outputTokens = asTokenCount2(u.output_tokens);
1289
+ let totalTokens = asTokenCount2(u.total_tokens);
1283
1290
  if (totalTokens === null && inputTokens !== null && outputTokens !== null) {
1284
1291
  totalTokens = inputTokens + outputTokens;
1285
1292
  }
@@ -1287,7 +1294,7 @@ function normalizeTokenUsage(raw) {
1287
1294
  inputTokens,
1288
1295
  outputTokens,
1289
1296
  totalTokens,
1290
- cachedInputTokens: asTokenCount(inputDetails.cache_read)
1297
+ cachedInputTokens: asTokenCount2(inputDetails.cache_read)
1291
1298
  });
1292
1299
  }
1293
1300
  return null;
@@ -3063,4 +3070,4 @@ export {
3063
3070
  Bitfab,
3064
3071
  BitfabFunction
3065
3072
  };
3066
- //# sourceMappingURL=chunk-FA6DBCAT.js.map
3073
+ //# sourceMappingURL=chunk-WZ72P5SX.js.map