@wix/evalforge-evaluator 0.220.0 → 0.222.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) {