@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.
@@ -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.20.0";
14
14
 
15
15
  // src/constants.ts
16
16
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -287,7 +287,7 @@ var HttpClient = class {
287
287
  * Start a replay session by fetching historical traces.
288
288
  * Blocking call — creates a test run and returns lightweight item references.
289
289
  */
290
- async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId) {
290
+ async startReplay(traceFunctionKey, limit, traceIds, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId) {
291
291
  const payload = { traceFunctionKey };
292
292
  if (limit !== void 0) {
293
293
  payload.limit = limit;
@@ -307,6 +307,9 @@ var HttpClient = class {
307
307
  if (experimentGroupId !== void 0) {
308
308
  payload.experimentGroupId = experimentGroupId;
309
309
  }
310
+ if (datasetId !== void 0) {
311
+ payload.datasetId = datasetId;
312
+ }
310
313
  const timeout = includeDbBranchLease ? 18e4 : 3e4;
311
314
  return this.request("/api/sdk/replay/start", payload, {
312
315
  timeout
@@ -429,23 +432,30 @@ function extractContentBlocks(content) {
429
432
  }
430
433
  return content.map((block) => safeSerialize(block));
431
434
  }
435
+ function asTokenCount(val) {
436
+ return typeof val === "number" && Number.isFinite(val) ? val : null;
437
+ }
432
438
  function extractUsage(message) {
433
439
  const usageInfo = {};
434
440
  const usage = message.usage;
435
441
  if (!usage) {
436
442
  return usageInfo;
437
443
  }
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
- }
444
+ const baseInput = asTokenCount(usage.input_tokens);
445
+ const cacheRead = asTokenCount(usage.cache_read_input_tokens);
446
+ const cacheCreation = asTokenCount(usage.cache_creation_input_tokens);
447
+ if (baseInput !== null || cacheRead !== null || cacheCreation !== null) {
448
+ usageInfo.inputTokens = (baseInput ?? 0) + (cacheRead ?? 0) + (cacheCreation ?? 0);
449
+ }
450
+ const output = asTokenCount(usage.output_tokens);
451
+ if (output !== null) {
452
+ usageInfo.outputTokens = output;
453
+ }
454
+ if (cacheRead !== null) {
455
+ usageInfo.cacheReadTokens = cacheRead;
456
+ }
457
+ if (cacheCreation !== null) {
458
+ usageInfo.cacheCreationTokens = cacheCreation;
449
459
  }
450
460
  return usageInfo;
451
461
  }
@@ -1234,7 +1244,7 @@ function extractModelName(serialized, metadata) {
1234
1244
  }
1235
1245
  return void 0;
1236
1246
  }
1237
- function asTokenCount(value) {
1247
+ function asTokenCount2(value) {
1238
1248
  return typeof value === "number" && Number.isFinite(value) ? value : null;
1239
1249
  }
1240
1250
  function normalizeTokenUsage(raw) {
@@ -1243,10 +1253,10 @@ function normalizeTokenUsage(raw) {
1243
1253
  }
1244
1254
  const u = raw;
1245
1255
  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);
1256
+ const cacheRead = asTokenCount2(u.cache_read_input_tokens);
1257
+ const cacheCreation = asTokenCount2(u.cache_creation_input_tokens);
1258
+ const baseInput = asTokenCount2(u.input_tokens);
1259
+ const outputTokens = asTokenCount2(u.output_tokens);
1250
1260
  if (cacheRead === null && cacheCreation === null && baseInput === null && outputTokens === null) {
1251
1261
  return null;
1252
1262
  }
@@ -1261,25 +1271,25 @@ function normalizeTokenUsage(raw) {
1261
1271
  if ("prompt_tokens" in u || "completion_tokens" in u || "promptTokens" in u || "completionTokens" in u) {
1262
1272
  const promptDetails = u.prompt_tokens_details ?? {};
1263
1273
  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)
1274
+ inputTokens: asTokenCount2(u.prompt_tokens) ?? asTokenCount2(u.promptTokens),
1275
+ outputTokens: asTokenCount2(u.completion_tokens) ?? asTokenCount2(u.completionTokens),
1276
+ totalTokens: asTokenCount2(u.total_tokens) ?? asTokenCount2(u.totalTokens),
1277
+ cachedInputTokens: asTokenCount2(promptDetails.cached_tokens)
1268
1278
  });
1269
1279
  }
1270
1280
  if ("prompt_token_count" in u || "candidates_token_count" in u) {
1271
1281
  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)
1282
+ inputTokens: asTokenCount2(u.prompt_token_count),
1283
+ outputTokens: asTokenCount2(u.candidates_token_count),
1284
+ totalTokens: asTokenCount2(u.total_token_count),
1285
+ cachedInputTokens: asTokenCount2(u.cached_content_token_count)
1276
1286
  });
1277
1287
  }
1278
1288
  if ("input_tokens" in u || "output_tokens" in u) {
1279
1289
  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);
1290
+ const inputTokens = asTokenCount2(u.input_tokens);
1291
+ const outputTokens = asTokenCount2(u.output_tokens);
1292
+ let totalTokens = asTokenCount2(u.total_tokens);
1283
1293
  if (totalTokens === null && inputTokens !== null && outputTokens !== null) {
1284
1294
  totalTokens = inputTokens + outputTokens;
1285
1295
  }
@@ -1287,7 +1297,7 @@ function normalizeTokenUsage(raw) {
1287
1297
  inputTokens,
1288
1298
  outputTokens,
1289
1299
  totalTokens,
1290
- cachedInputTokens: asTokenCount(inputDetails.cache_read)
1300
+ cachedInputTokens: asTokenCount2(inputDetails.cache_read)
1291
1301
  });
1292
1302
  }
1293
1303
  return null;
@@ -2984,7 +2994,7 @@ var Bitfab = class {
2984
2994
  `Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
2985
2995
  );
2986
2996
  }
2987
- const { replay: doReplay } = await import("./replay-QAWGVRCZ.js");
2997
+ const { replay: doReplay } = await import("./replay-V6RPJYXZ.js");
2988
2998
  return doReplay(
2989
2999
  this.httpClient,
2990
3000
  this.serviceUrl,
@@ -3063,4 +3073,4 @@ export {
3063
3073
  Bitfab,
3064
3074
  BitfabFunction
3065
3075
  };
3066
- //# sourceMappingURL=chunk-FA6DBCAT.js.map
3076
+ //# sourceMappingURL=chunk-IUZIGC6T.js.map