@valerypopoff/rivet2-cli 2.8.0 → 2.9.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.
@@ -1,5 +1,5 @@
1
1
  import { createProcessor, loadProjectAndAttachedDataFromFile, } from '@valerypopoff/rivet2-node';
2
- import { deserializeEvaluationProjectData, deserializeEvaluationSuiteBundleJson, EvaluationGraphExecutionError, runEvaluationSuite, validateEvaluationDataset, } from '@valerypopoff/rivet2-evaluations';
2
+ import { deserializeEvaluationProjectData, deserializeEvaluationSuiteBundleJson, createEvaluationEventCollector, EvaluationGraphExecutionError, runEvaluationSuite, validateEvaluationDataset, } from '@valerypopoff/rivet2-evaluations';
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import { resolve } from 'node:path';
5
5
  import { addDatasetOptions, addProviderOptions, createDatasetProvider, getProjectFile, resolveDatasetFilePath, withCliProcessorOptions, } from '../cliRuntime.js';
@@ -214,7 +214,8 @@ export async function runEvaluation(args) {
214
214
  if (args.baseline !== undefined && importedBundle) {
215
215
  throw new EvaluationCliError('Exported suite bundles do not include baselines; omit --baseline or use a legacy project attachment.', 3);
216
216
  }
217
- const dataset = importedBundle?.dataset ?? (await loadEvaluationDataset(projectPath, project.metadata.id, suite.datasetId, args.datasetFile));
217
+ const dataset = importedBundle?.dataset ??
218
+ (await loadEvaluationDataset(projectPath, project.metadata.id, suite.datasetId, args.datasetFile));
218
219
  const datasetProvider = await createDatasetProvider(projectPath, args);
219
220
  const effectiveData = args.trials === undefined && args.concurrency === undefined
220
221
  ? evaluationData
@@ -248,77 +249,30 @@ export async function runEvaluation(args) {
248
249
  executionMode: 'node-cli',
249
250
  runGraph: async ({ graphId, inputs, signal, metadata }) => {
250
251
  const startedAt = Date.now();
251
- const metrics = {
252
- durationMs: 0,
253
- modelCallCount: 0,
254
- toolCallCount: 0,
255
- toolFailureCount: 0,
256
- };
257
- const providerAttempts = [];
252
+ const captured = createEvaluationEventCollector('cli');
258
253
  const processorInfo = createProcessor(project, withCliProcessorOptions({ datasetProvider, projectPath }, args, {
259
254
  graph: graphId,
260
255
  inputs: graphInputsToOutputs(project, graphId, inputs),
261
256
  abortSignal: signal,
262
257
  evaluation: metadata,
263
258
  }));
264
- processorInfo.processor.on('llmCallFinished', (event) => {
265
- metrics.modelCallCount = (metrics.modelCallCount ?? 0) + 1;
266
- metrics.inputTokens = (metrics.inputTokens ?? 0) + (event.normalizedUsage?.promptTokens ?? 0);
267
- metrics.outputTokens = (metrics.outputTokens ?? 0) + (event.normalizedUsage?.completionTokens ?? 0);
268
- metrics.cachedInputTokens = (metrics.cachedInputTokens ?? 0) + (event.normalizedUsage?.cachedTokens ?? 0);
269
- metrics.reasoningTokens = (metrics.reasoningTokens ?? 0) + (event.normalizedUsage?.reasoningTokens ?? 0);
270
- if (event.pricing.status === 'known')
271
- metrics.costUsd = (metrics.costUsd ?? 0) + (event.pricing.costUsd ?? 0);
272
- else
273
- metrics.hasUnknownCost = true;
274
- providerAttempts.push({
275
- kind: 'provider-call',
276
- provider: event.provider,
277
- model: event.model,
278
- customProviderApi: event.customProviderApi ?? null,
279
- outcome: event.outcome,
280
- profileIndex: event.profileIndex ?? null,
281
- attemptIndex: event.attemptIndex,
282
- roundIndex: event.roundIndex ?? null,
283
- durationMs: event.durationMs ?? null,
284
- });
285
- });
286
- processorInfo.processor.on('llmProfileAttempt', (event) => {
287
- providerAttempts.push({
288
- kind: 'profile-decision',
289
- provider: event.provider,
290
- model: event.model,
291
- customProviderApi: event.customProviderApi ?? null,
292
- stage: event.stage,
293
- outcome: event.outcome,
294
- profileIndex: event.profileIndex ?? null,
295
- attemptIndex: event.attemptIndex ?? null,
296
- roundIndex: event.roundIndex,
297
- status: event.status ?? null,
298
- healthState: event.healthState ?? null,
299
- healthDisposition: event.healthDisposition ?? null,
300
- timeoutKind: event.timeoutKind ?? null,
301
- });
302
- });
303
- processorInfo.processor.on('toolCallFinished', (event) => {
304
- metrics.toolCallCount = (metrics.toolCallCount ?? 0) + 1;
305
- if (event.outcome !== 'success')
306
- metrics.toolFailureCount = (metrics.toolFailureCount ?? 0) + 1;
307
- });
259
+ processorInfo.processor.on('llmCallFinished', captured.llmCallFinished);
260
+ processorInfo.processor.on('llmProfileAttempt', captured.llmProfileAttempt);
261
+ processorInfo.processor.on('toolCallFinished', captured.toolCallFinished);
308
262
  try {
309
263
  const outputs = await processorInfo.run();
310
- metrics.durationMs = Date.now() - startedAt;
264
+ captured.metrics.durationMs = Date.now() - startedAt;
311
265
  return {
312
266
  outputs: Object.fromEntries(Object.entries(outputs).map(([key, value]) => [key, value.value])),
313
- metrics,
314
- ...(providerAttempts.length === 0 ? {} : { providerAttempts }),
267
+ metrics: captured.metrics,
268
+ ...(captured.providerAttempts.length === 0 ? {} : { providerAttempts: captured.providerAttempts }),
315
269
  };
316
270
  }
317
271
  catch (error) {
318
- metrics.durationMs = Math.max(metrics.durationMs, Date.now() - startedAt);
272
+ captured.metrics.durationMs = Math.max(captured.metrics.durationMs, Date.now() - startedAt);
319
273
  throw new EvaluationGraphExecutionError(error instanceof Error ? error.message : String(error), {
320
- metrics,
321
- ...(providerAttempts.length === 0 ? {} : { providerAttempts }),
274
+ metrics: captured.metrics,
275
+ ...(captured.providerAttempts.length === 0 ? {} : { providerAttempts: captured.providerAttempts }),
322
276
  });
323
277
  }
324
278
  finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerypopoff/rivet2-cli",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "license": "MIT",
5
5
  "types": "dist/types/cli.d.ts",
6
6
  "type": "module",
@@ -23,8 +23,8 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@hono/node-server": "^1.19.14",
26
- "@valerypopoff/rivet2-evaluations": "^2.8.0",
27
- "@valerypopoff/rivet2-node": "^2.8.0",
26
+ "@valerypopoff/rivet2-evaluations": "^2.9.0",
27
+ "@valerypopoff/rivet2-node": "^2.9.0",
28
28
  "chalk": "^5.4.1",
29
29
  "didyoumean2": "^7.0.4",
30
30
  "dotenv": "^16.4.7",