@wix/evalforge-evaluator 0.221.0 → 0.223.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.js CHANGED
@@ -6941,6 +6941,12 @@ function rethrowWithRequestId(err, action) {
6941
6941
  }
6942
6942
  throw err;
6943
6943
  }
6944
+ function requireEntity(entity, notFound) {
6945
+ if (!entity) {
6946
+ throw new Error(notFound);
6947
+ }
6948
+ return entity;
6949
+ }
6944
6950
  function resolveAmbassadorBaseUrl(serverUrl) {
6945
6951
  try {
6946
6952
  return new URL(serverUrl).origin;
@@ -6991,52 +6997,50 @@ function createApiClient(serverUrl, options = "") {
6991
6997
  const res = await httpClient.request(
6992
6998
  getEvalRun({ projectId: projectId2, evalRunId: id })
6993
6999
  );
6994
- const evalRun = res.data.evalRun;
6995
- if (!evalRun) {
6996
- throw new Error(`Eval run ${id} not found in project ${projectId2}`);
6997
- }
7000
+ const evalRun = requireEntity(
7001
+ res.data.evalRun,
7002
+ `Eval run ${id} not found in project ${projectId2}`
7003
+ );
6998
7004
  return evalRunFromProto(evalRun);
6999
7005
  },
7000
7006
  async getScenario(projectId2, id) {
7001
7007
  const res = await httpClient.request(
7002
7008
  getTestScenario({ projectId: projectId2, testScenarioId: id })
7003
7009
  );
7004
- const scenario = res.data.testScenario;
7005
- if (!scenario) {
7006
- throw new Error(
7007
- `Test scenario ${id} not found in project ${projectId2}`
7008
- );
7009
- }
7010
+ const scenario = requireEntity(
7011
+ res.data.testScenario,
7012
+ `Test scenario ${id} not found in project ${projectId2}`
7013
+ );
7010
7014
  return testScenarioFromProto(scenario);
7011
7015
  },
7012
7016
  async getAgent(projectId2, id) {
7013
7017
  const res = await httpClient.request(
7014
7018
  getAgent({ projectId: projectId2, agentId: id })
7015
7019
  );
7016
- const agent = res.data.agent;
7017
- if (!agent) {
7018
- throw new Error(`Agent ${id} not found in project ${projectId2}`);
7019
- }
7020
+ const agent = requireEntity(
7021
+ res.data.agent,
7022
+ `Agent ${id} not found in project ${projectId2}`
7023
+ );
7020
7024
  return agentFromProto(agent);
7021
7025
  },
7022
7026
  async getTemplate(projectId2, id) {
7023
7027
  const res = await httpClient.request(
7024
7028
  getTemplate({ projectId: projectId2, templateId: id })
7025
7029
  );
7026
- const template = res.data.template;
7027
- if (!template) {
7028
- throw new Error(`Template ${id} not found in project ${projectId2}`);
7029
- }
7030
+ const template = requireEntity(
7031
+ res.data.template,
7032
+ `Template ${id} not found in project ${projectId2}`
7033
+ );
7030
7034
  return templateFromProto(template);
7031
7035
  },
7032
7036
  async getPreset(projectId2, id) {
7033
7037
  const res = await httpClient.request(
7034
7038
  getPreset({ projectId: projectId2, presetId: id })
7035
7039
  );
7036
- const preset = res.data.preset;
7037
- if (!preset) {
7038
- throw new Error(`Preset ${id} not found in project ${projectId2}`);
7039
- }
7040
+ const preset = requireEntity(
7041
+ res.data.preset,
7042
+ `Preset ${id} not found in project ${projectId2}`
7043
+ );
7040
7044
  return presetFromProto(preset);
7041
7045
  },
7042
7046
  // The legacy REST endpoint enriched the capability with its latest version
@@ -7057,10 +7061,10 @@ function createApiClient(serverUrl, options = "") {
7057
7061
  if (capResult.status === "rejected") {
7058
7062
  throw capResult.reason;
7059
7063
  }
7060
- const capability = capResult.value.data.capability;
7061
- if (!capability) {
7062
- throw new Error(`Capability ${id} not found in project ${projectId2}`);
7063
- }
7064
+ const capability = requireEntity(
7065
+ capResult.value.data.capability,
7066
+ `Capability ${id} not found in project ${projectId2}`
7067
+ );
7064
7068
  let latestVersion;
7065
7069
  if (versionResult.status === "fulfilled" && versionResult.value.data.capabilityVersion) {
7066
7070
  latestVersion = capabilityVersionFromProto(
@@ -7083,12 +7087,10 @@ function createApiClient(serverUrl, options = "") {
7083
7087
  capabilityVersionId: versionId
7084
7088
  })
7085
7089
  );
7086
- const version = res.data.capabilityVersion;
7087
- if (!version) {
7088
- throw new Error(
7089
- `Capability version ${versionId} not found for capability ${capabilityId}`
7090
- );
7091
- }
7090
+ const version = requireEntity(
7091
+ res.data.capabilityVersion,
7092
+ `Capability version ${versionId} not found for capability ${capabilityId}`
7093
+ );
7092
7094
  return capabilityVersionFromProto(version, projectId2);
7093
7095
  },
7094
7096
  async addResult(projectId2, evalRunId2, result) {
@@ -7415,7 +7417,6 @@ async function writeFilesToDirectory(targetDir, files) {
7415
7417
 
7416
7418
  // src/run-scenario/install-dependencies.ts
7417
7419
  var import_fs = require("fs");
7418
- var import_crypto = require("crypto");
7419
7420
  var import_path2 = __toESM(require("path"));
7420
7421
  var import_child_process = require("child_process");
7421
7422
  var INSTALL_TIMEOUT_MS = 18e4;
@@ -7514,18 +7515,16 @@ function detectPackageManager(workDir) {
7514
7515
  if ((0, import_fs.existsSync)(import_path2.default.join(workDir, "pnpm-lock.yaml"))) {
7515
7516
  return {
7516
7517
  cmd: "pnpm",
7517
- args: ["install", "--frozen-lockfile"],
7518
- cacheSourceFile: "pnpm-lock.yaml"
7518
+ args: ["install", "--frozen-lockfile"]
7519
7519
  };
7520
7520
  }
7521
7521
  if ((0, import_fs.existsSync)(import_path2.default.join(workDir, "package-lock.json"))) {
7522
- return { cmd: "npm", args: ["ci"], cacheSourceFile: "package-lock.json" };
7522
+ return { cmd: "npm", args: ["ci"] };
7523
7523
  }
7524
7524
  if ((0, import_fs.existsSync)(import_path2.default.join(workDir, "yarn.lock"))) {
7525
7525
  return {
7526
7526
  cmd: "yarn",
7527
- args: ["install", "--frozen-lockfile"],
7528
- cacheSourceFile: "yarn.lock"
7527
+ args: ["install", "--frozen-lockfile"]
7529
7528
  };
7530
7529
  }
7531
7530
  return {
@@ -7536,17 +7535,9 @@ function detectPackageManager(workDir) {
7536
7535
  "--prefer-offline",
7537
7536
  "--no-fund",
7538
7537
  "--no-audit"
7539
- ],
7540
- cacheSourceFile: "package.json"
7538
+ ]
7541
7539
  };
7542
7540
  }
7543
- function cloneDirectory(src, dest) {
7544
- if (process.platform === "darwin") {
7545
- (0, import_child_process.execFileSync)("cp", ["-rc", src, dest]);
7546
- } else {
7547
- (0, import_fs.cpSync)(src, dest, { recursive: true });
7548
- }
7549
- }
7550
7541
  async function runInstall(exec, pm, workDir, onProgress) {
7551
7542
  reportRegistry(workDir, onProgress);
7552
7543
  onProgress(`[diag] npm install starting: ${pm.cmd} ${pm.args.join(" ")}`);
@@ -7577,64 +7568,13 @@ async function runInstall(exec, pm, workDir, onProgress) {
7577
7568
  clearInterval(heartbeat);
7578
7569
  }
7579
7570
  }
7580
- async function installWithCache(workDir, exec, cacheBase, pm, onProgress) {
7581
- const sourceContent = (0, import_fs.readFileSync)(
7582
- import_path2.default.join(workDir, pm.cacheSourceFile),
7583
- "utf-8"
7584
- );
7585
- const cacheKey = (0, import_crypto.createHash)("sha256").update(sourceContent).digest("hex").slice(0, 16);
7586
- const cachedNodeModules = import_path2.default.join(cacheBase, cacheKey, "node_modules");
7587
- const targetNodeModules = import_path2.default.join(workDir, "node_modules");
7588
- const cacheDir = import_path2.default.dirname(cachedNodeModules);
7589
- const cachedYarnLock = import_path2.default.join(cacheDir, "yarn.lock");
7590
- if ((0, import_fs.existsSync)(cachedNodeModules)) {
7591
- console.log(
7592
- `[environment] Restoring node_modules from cache (key: ${cacheKey})`
7593
- );
7594
- onProgress(`[diag] node_modules cache HIT (key: ${cacheKey}) \u2014 restoring`);
7595
- if (!(0, import_fs.existsSync)(targetNodeModules)) {
7596
- cloneDirectory(cachedNodeModules, targetNodeModules);
7597
- }
7598
- if ((0, import_fs.existsSync)(cachedYarnLock)) {
7599
- (0, import_fs.copyFileSync)(cachedYarnLock, import_path2.default.join(workDir, "yarn.lock"));
7600
- }
7601
- onProgress("[diag] node_modules cache restore complete");
7602
- return;
7603
- }
7604
- onProgress(`[diag] node_modules cache MISS (key: ${cacheKey})`);
7605
- const ok = await runInstall(exec, pm, workDir, onProgress);
7606
- if (!ok) {
7607
- return;
7608
- }
7609
- console.log(
7610
- "[environment] Dependency installation complete \u2014 saving to cache"
7611
- );
7612
- try {
7613
- (0, import_fs.mkdirSync)(cacheDir, { recursive: true });
7614
- const yarnLockPath = import_path2.default.join(workDir, "yarn.lock");
7615
- if ((0, import_fs.existsSync)(yarnLockPath)) {
7616
- (0, import_fs.copyFileSync)(yarnLockPath, cachedYarnLock);
7617
- }
7618
- cloneDirectory(targetNodeModules, cachedNodeModules);
7619
- } catch (err) {
7620
- console.error(
7621
- "[environment] Failed to save to cache (installation still succeeded):",
7622
- err instanceof Error ? err.message : String(err)
7623
- );
7624
- }
7625
- }
7626
7571
  async function installDependencies(workDir, onProgress, options = {}) {
7627
7572
  if (!(0, import_fs.existsSync)(import_path2.default.join(workDir, "package.json"))) {
7628
7573
  return;
7629
7574
  }
7630
7575
  const exec = options.exec ?? defaultExec;
7631
- const cacheBase = options.cacheBase;
7632
7576
  onProgress("Installing dependencies...");
7633
7577
  const pm = detectPackageManager(workDir);
7634
- if (cacheBase) {
7635
- await installWithCache(workDir, exec, cacheBase, pm, onProgress);
7636
- return;
7637
- }
7638
7578
  await runInstall(exec, pm, workDir, onProgress);
7639
7579
  }
7640
7580
 
@@ -7779,7 +7719,6 @@ function writeWixEnvFile(workDir) {
7779
7719
  async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId, onProgress, options = {}) {
7780
7720
  const template = options.template;
7781
7721
  const baseDir = config.evaluationsDir ?? import_path3.default.join((0, import_os.tmpdir)(), "evalforge-evaluations");
7782
- const nodeModulesCacheDir = import_path3.default.join(baseDir, "_node_modules_cache");
7783
7722
  if (template) {
7784
7723
  if (!config.evaluationsDir) {
7785
7724
  console.warn(
@@ -7798,7 +7737,6 @@ async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId,
7798
7737
  writeWixEnvFile(workDir2);
7799
7738
  onProgress("[diag] entering installDependencies");
7800
7739
  await installDependencies(workDir2, onProgress, {
7801
- cacheBase: nodeModulesCacheDir,
7802
7740
  exec: createLoggingInstallExec(onProgress)
7803
7741
  });
7804
7742
  onProgress("[diag] installDependencies returned");
@@ -7822,7 +7760,7 @@ function emitTraceEvent(event, pushEvent) {
7822
7760
  }
7823
7761
 
7824
7762
  // src/run-scenario/run-agent-with-context.ts
7825
- var import_crypto5 = require("crypto");
7763
+ var import_crypto4 = require("crypto");
7826
7764
 
7827
7765
  // src/run-scenario/agents/registry.ts
7828
7766
  var AgentAdapterRegistry = class {
@@ -7980,7 +7918,7 @@ function resolveTimeoutMs(maxTurns, maxDurationMs) {
7980
7918
  }
7981
7919
 
7982
7920
  // src/run-scenario/agents/claude-code/execute.ts
7983
- var import_crypto2 = require("crypto");
7921
+ var import_crypto = require("crypto");
7984
7922
 
7985
7923
  // src/run-scenario/agents/claude-code/write-mcp.ts
7986
7924
  var import_promises5 = require("fs/promises");
@@ -9177,7 +9115,7 @@ function buildLLMTraceFromSteps(steps, totalDurationMs, usage, model) {
9177
9115
  const totalSubSteps = thinkingSubSteps + toolSubSteps + textSubSteps || 1;
9178
9116
  if (hasThinking && (hasText || toolCallCount > 0)) {
9179
9117
  subSteps.push({
9180
- id: (0, import_crypto2.randomUUID)(),
9118
+ id: (0, import_crypto.randomUUID)(),
9181
9119
  stepNumber: 0,
9182
9120
  // renumbered below
9183
9121
  turnIndex,
@@ -9209,7 +9147,7 @@ function buildLLMTraceFromSteps(steps, totalDurationMs, usage, model) {
9209
9147
  const toolSuccess = !tc.isError;
9210
9148
  const toolError = tc.isError ? tc.errorContent ?? "Tool call failed" : void 0;
9211
9149
  subSteps.push({
9212
- id: (0, import_crypto2.randomUUID)(),
9150
+ id: (0, import_crypto.randomUUID)(),
9213
9151
  stepNumber: 0,
9214
9152
  turnIndex,
9215
9153
  type: import_evalforge_types4.LLMStepType.TOOL_USE,
@@ -9239,7 +9177,7 @@ function buildLLMTraceFromSteps(steps, totalDurationMs, usage, model) {
9239
9177
  }
9240
9178
  if (hasText && toolCallCount > 0) {
9241
9179
  subSteps.push({
9242
- id: (0, import_crypto2.randomUUID)(),
9180
+ id: (0, import_crypto.randomUUID)(),
9243
9181
  stepNumber: 0,
9244
9182
  turnIndex,
9245
9183
  type: import_evalforge_types4.LLMStepType.COMPLETION,
@@ -9261,7 +9199,7 @@ function buildLLMTraceFromSteps(steps, totalDurationMs, usage, model) {
9261
9199
  if (subSteps.length === 0) {
9262
9200
  const stepType = hasThinking && !hasText ? import_evalforge_types4.LLMStepType.THINKING : import_evalforge_types4.LLMStepType.COMPLETION;
9263
9201
  subSteps.push({
9264
- id: (0, import_crypto2.randomUUID)(),
9202
+ id: (0, import_crypto.randomUUID)(),
9265
9203
  stepNumber: 0,
9266
9204
  turnIndex,
9267
9205
  type: stepType,
@@ -9319,7 +9257,7 @@ function buildLLMTraceFromSteps(steps, totalDurationMs, usage, model) {
9319
9257
  stepTypeBreakdown
9320
9258
  };
9321
9259
  return {
9322
- id: (0, import_crypto2.randomUUID)(),
9260
+ id: (0, import_crypto.randomUUID)(),
9323
9261
  steps: traceSteps,
9324
9262
  summary
9325
9263
  };
@@ -9686,7 +9624,7 @@ async function buildOpenCodeEnv(options) {
9686
9624
 
9687
9625
  // src/run-scenario/agents/opencode/build-trace.ts
9688
9626
  var import_evalforge_types7 = require("@wix/evalforge-types");
9689
- var import_crypto3 = require("crypto");
9627
+ var import_crypto2 = require("crypto");
9690
9628
  function toCanonicalModelId(modelId) {
9691
9629
  const slashIndex = modelId.indexOf("/");
9692
9630
  return slashIndex > 0 ? modelId.slice(slashIndex + 1) : modelId;
@@ -9798,7 +9736,7 @@ function buildTurnSteps(turn, turnIndex, ctx) {
9798
9736
  const totalSubSteps = thinkingSubSteps + toolSubSteps + textSubSteps || 1;
9799
9737
  if (hasThinking && (hasText || toolCallCount > 0)) {
9800
9738
  subSteps.push({
9801
- id: (0, import_crypto3.randomUUID)(),
9739
+ id: (0, import_crypto2.randomUUID)(),
9802
9740
  stepNumber: 0,
9803
9741
  turnIndex,
9804
9742
  type: import_evalforge_types7.LLMStepType.THINKING,
@@ -9825,7 +9763,7 @@ function buildTurnSteps(turn, turnIndex, ctx) {
9825
9763
  const toolFraction = toolBudgetSteps > 0 ? 1 / toolBudgetSteps : 1;
9826
9764
  const remainingFraction = (totalSubSteps - thinkingSubSteps) / totalSubSteps;
9827
9765
  subSteps.push({
9828
- id: (0, import_crypto3.randomUUID)(),
9766
+ id: (0, import_crypto2.randomUUID)(),
9829
9767
  stepNumber: 0,
9830
9768
  turnIndex,
9831
9769
  type: import_evalforge_types7.LLMStepType.TOOL_USE,
@@ -9855,7 +9793,7 @@ function buildTurnSteps(turn, turnIndex, ctx) {
9855
9793
  }
9856
9794
  if (hasText && toolCallCount > 0) {
9857
9795
  subSteps.push({
9858
- id: (0, import_crypto3.randomUUID)(),
9796
+ id: (0, import_crypto2.randomUUID)(),
9859
9797
  stepNumber: 0,
9860
9798
  turnIndex,
9861
9799
  type: import_evalforge_types7.LLMStepType.COMPLETION,
@@ -9877,7 +9815,7 @@ function buildTurnSteps(turn, turnIndex, ctx) {
9877
9815
  if (subSteps.length === 0) {
9878
9816
  const stepType = hasThinking && !hasText ? import_evalforge_types7.LLMStepType.THINKING : import_evalforge_types7.LLMStepType.COMPLETION;
9879
9817
  subSteps.push({
9880
- id: (0, import_crypto3.randomUUID)(),
9818
+ id: (0, import_crypto2.randomUUID)(),
9881
9819
  stepNumber: 0,
9882
9820
  turnIndex,
9883
9821
  type: stepType,
@@ -9967,7 +9905,7 @@ function buildLLMTrace(timestampedEvents, totalDurationMs, model, provider, exec
9967
9905
  totalDurationMs,
9968
9906
  canonicalModel
9969
9907
  );
9970
- return { id: (0, import_crypto3.randomUUID)(), steps: allSteps, summary };
9908
+ return { id: (0, import_crypto2.randomUUID)(), steps: allSteps, summary };
9971
9909
  }
9972
9910
 
9973
9911
  // src/run-scenario/agents/opencode/gateway-cost-interceptor.ts
@@ -10836,7 +10774,7 @@ var import_anthropic = require("@ai-sdk/anthropic");
10836
10774
  var import_google = require("@ai-sdk/google");
10837
10775
  var import_openai = require("@ai-sdk/openai");
10838
10776
  var import_evalforge_types11 = require("@wix/evalforge-types");
10839
- var import_crypto4 = require("crypto");
10777
+ var import_crypto3 = require("crypto");
10840
10778
 
10841
10779
  // src/run-scenario/agents/simple-agent/mcp-tools.ts
10842
10780
  var import_mcp = require("@ai-sdk/mcp");
@@ -11473,7 +11411,7 @@ function buildLLMTrace2(steps, totalDurationMs, modelId, provider, executionStar
11473
11411
  const costUsd = calculateStepCost(step, modelId, provider, tokenUsage);
11474
11412
  const toolResultError = findToolResultError(step);
11475
11413
  return {
11476
- id: (0, import_crypto4.randomUUID)(),
11414
+ id: (0, import_crypto3.randomUUID)(),
11477
11415
  stepNumber: i + 1,
11478
11416
  turnIndex: i,
11479
11417
  type: step.toolCalls.length > 0 ? import_evalforge_types11.LLMStepType.TOOL_USE : import_evalforge_types11.LLMStepType.COMPLETION,
@@ -11500,7 +11438,7 @@ function buildLLMTrace2(steps, totalDurationMs, modelId, provider, executionStar
11500
11438
  { prompt: 0, completion: 0, total: 0 }
11501
11439
  );
11502
11440
  return {
11503
- id: (0, import_crypto4.randomUUID)(),
11441
+ id: (0, import_crypto3.randomUUID)(),
11504
11442
  steps: traceSteps,
11505
11443
  summary: {
11506
11444
  totalSteps: traceSteps.length,
@@ -12383,7 +12321,7 @@ async function runAgentWithContext(config, evalRunId2, scenario, evalData, workD
12383
12321
  }
12384
12322
  } : agent?.modelConfig ?? (llmTrace?.summary.modelsUsed?.[0] ? { model: llmTrace.summary.modelsUsed[0] } : void 0);
12385
12323
  return {
12386
- id: (0, import_crypto5.randomUUID)(),
12324
+ id: (0, import_crypto4.randomUUID)(),
12387
12325
  targetId,
12388
12326
  targetName,
12389
12327
  scenarioId: scenario.id,
@@ -12529,7 +12467,7 @@ Site ID: ${provisionedSite.id}` : void 0;
12529
12467
  }
12530
12468
 
12531
12469
  // src/evaluation-loop.ts
12532
- var import_crypto6 = require("crypto");
12470
+ var import_crypto5 = require("crypto");
12533
12471
  async function runEvaluationLoop(scenarioItems, evalData, callbacks) {
12534
12472
  const runsPerScenario = evalData.evalRun.runsPerScenario ?? 1;
12535
12473
  let completedExecutions = 0;
@@ -12555,7 +12493,7 @@ async function runEvaluationLoop(scenarioItems, evalData, callbacks) {
12555
12493
  `[Evaluator] Scenario iteration failed, recording as error result: "${scenario.name}"${iterLabel} \u2014 ${errorMsg}`
12556
12494
  );
12557
12495
  const errorResult = {
12558
- id: (0, import_crypto6.randomUUID)(),
12496
+ id: (0, import_crypto5.randomUUID)(),
12559
12497
  targetId,
12560
12498
  targetName,
12561
12499
  scenarioId: scenario.id,