@wix/evalforge-evaluator 0.207.0 → 0.209.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.
package/build/index.mjs CHANGED
@@ -11025,7 +11025,14 @@ function calculateFromPricing(modelId, tokenUsage) {
11025
11025
  return tokenUsage.prompt / 1e6 * pricing.input + tokenUsage.completion / 1e6 * pricing.output;
11026
11026
  }
11027
11027
  function calculateStepCost(step, modelId, provider, tokenUsage) {
11028
- return extractGatewayCost(step, provider) ?? calculateFromPricing(modelId, tokenUsage);
11028
+ const gatewayCost = extractGatewayCost(step, provider);
11029
+ if (gatewayCost !== void 0) {
11030
+ return gatewayCost;
11031
+ }
11032
+ console.warn(
11033
+ `[cost-calculation] gateway cost missing; using list-price fallback (provider=${provider}, model=${modelId}, promptTokens=${tokenUsage.prompt}, completionTokens=${tokenUsage.completion})`
11034
+ );
11035
+ return calculateFromPricing(modelId, tokenUsage);
11029
11036
  }
11030
11037
 
11031
11038
  // src/run-scenario/agents/simple-agent/build-conversation.ts
@@ -11305,13 +11312,13 @@ async function executeWithAiSdk(context) {
11305
11312
  [text, steps, rawUsage] = await Promise.all([
11306
11313
  stream.text,
11307
11314
  stream.steps,
11308
- stream.usage
11315
+ stream.totalUsage
11309
11316
  ]);
11310
11317
  } else {
11311
11318
  const result = await generateText(sdkParams);
11312
11319
  text = result.text;
11313
11320
  steps = result.steps;
11314
- rawUsage = result.usage;
11321
+ rawUsage = result.totalUsage;
11315
11322
  }
11316
11323
  const durationMs = Date.now() - startTime;
11317
11324
  const usage = {
@@ -11322,7 +11329,6 @@ async function executeWithAiSdk(context) {
11322
11329
  const llmTrace = buildLLMTrace2(
11323
11330
  steps,
11324
11331
  durationMs,
11325
- usage,
11326
11332
  modelId,
11327
11333
  provider,
11328
11334
  startTime,
@@ -11471,7 +11477,7 @@ function findToolResultError(step) {
11471
11477
  }
11472
11478
  return null;
11473
11479
  }
11474
- function buildLLMTrace2(steps, totalDurationMs, totalUsage, modelId, provider, executionStartMs, stepTimestamps) {
11480
+ function buildLLMTrace2(steps, totalDurationMs, modelId, provider, executionStartMs, stepTimestamps) {
11475
11481
  const traceSteps = steps.map((step, i) => {
11476
11482
  const stepFinishedAt = stepTimestamps[i] ?? executionStartMs;
11477
11483
  const stepStartedAt = i === 0 ? executionStartMs : stepTimestamps[i - 1] ?? executionStartMs;
@@ -11503,11 +11509,14 @@ function buildLLMTrace2(steps, totalDurationMs, totalUsage, modelId, provider, e
11503
11509
  };
11504
11510
  });
11505
11511
  const totalCostUsd = traceSteps.reduce((sum, s) => sum + s.costUsd, 0);
11506
- const finalTokens = {
11507
- prompt: totalUsage.inputTokens,
11508
- completion: totalUsage.outputTokens,
11509
- total: totalUsage.totalTokens
11510
- };
11512
+ const finalTokens = traceSteps.reduce(
11513
+ (acc, s) => ({
11514
+ prompt: acc.prompt + s.tokenUsage.prompt,
11515
+ completion: acc.completion + s.tokenUsage.completion,
11516
+ total: acc.total + s.tokenUsage.total
11517
+ }),
11518
+ { prompt: 0, completion: 0, total: 0 }
11519
+ );
11511
11520
  return {
11512
11521
  id: randomUUID3(),
11513
11522
  steps: traceSteps,