@wix/evalforge-evaluator 0.221.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.mjs CHANGED
@@ -6946,6 +6946,12 @@ function rethrowWithRequestId(err, action) {
6946
6946
  }
6947
6947
  throw err;
6948
6948
  }
6949
+ function requireEntity(entity, notFound) {
6950
+ if (!entity) {
6951
+ throw new Error(notFound);
6952
+ }
6953
+ return entity;
6954
+ }
6949
6955
  function resolveAmbassadorBaseUrl(serverUrl) {
6950
6956
  try {
6951
6957
  return new URL(serverUrl).origin;
@@ -6996,52 +7002,50 @@ function createApiClient(serverUrl, options = "") {
6996
7002
  const res = await httpClient.request(
6997
7003
  getEvalRun({ projectId: projectId2, evalRunId: id })
6998
7004
  );
6999
- const evalRun = res.data.evalRun;
7000
- if (!evalRun) {
7001
- throw new Error(`Eval run ${id} not found in project ${projectId2}`);
7002
- }
7005
+ const evalRun = requireEntity(
7006
+ res.data.evalRun,
7007
+ `Eval run ${id} not found in project ${projectId2}`
7008
+ );
7003
7009
  return evalRunFromProto(evalRun);
7004
7010
  },
7005
7011
  async getScenario(projectId2, id) {
7006
7012
  const res = await httpClient.request(
7007
7013
  getTestScenario({ projectId: projectId2, testScenarioId: id })
7008
7014
  );
7009
- const scenario = res.data.testScenario;
7010
- if (!scenario) {
7011
- throw new Error(
7012
- `Test scenario ${id} not found in project ${projectId2}`
7013
- );
7014
- }
7015
+ const scenario = requireEntity(
7016
+ res.data.testScenario,
7017
+ `Test scenario ${id} not found in project ${projectId2}`
7018
+ );
7015
7019
  return testScenarioFromProto(scenario);
7016
7020
  },
7017
7021
  async getAgent(projectId2, id) {
7018
7022
  const res = await httpClient.request(
7019
7023
  getAgent({ projectId: projectId2, agentId: id })
7020
7024
  );
7021
- const agent = res.data.agent;
7022
- if (!agent) {
7023
- throw new Error(`Agent ${id} not found in project ${projectId2}`);
7024
- }
7025
+ const agent = requireEntity(
7026
+ res.data.agent,
7027
+ `Agent ${id} not found in project ${projectId2}`
7028
+ );
7025
7029
  return agentFromProto(agent);
7026
7030
  },
7027
7031
  async getTemplate(projectId2, id) {
7028
7032
  const res = await httpClient.request(
7029
7033
  getTemplate({ projectId: projectId2, templateId: id })
7030
7034
  );
7031
- const template = res.data.template;
7032
- if (!template) {
7033
- throw new Error(`Template ${id} not found in project ${projectId2}`);
7034
- }
7035
+ const template = requireEntity(
7036
+ res.data.template,
7037
+ `Template ${id} not found in project ${projectId2}`
7038
+ );
7035
7039
  return templateFromProto(template);
7036
7040
  },
7037
7041
  async getPreset(projectId2, id) {
7038
7042
  const res = await httpClient.request(
7039
7043
  getPreset({ projectId: projectId2, presetId: id })
7040
7044
  );
7041
- const preset = res.data.preset;
7042
- if (!preset) {
7043
- throw new Error(`Preset ${id} not found in project ${projectId2}`);
7044
- }
7045
+ const preset = requireEntity(
7046
+ res.data.preset,
7047
+ `Preset ${id} not found in project ${projectId2}`
7048
+ );
7045
7049
  return presetFromProto(preset);
7046
7050
  },
7047
7051
  // The legacy REST endpoint enriched the capability with its latest version
@@ -7062,10 +7066,10 @@ function createApiClient(serverUrl, options = "") {
7062
7066
  if (capResult.status === "rejected") {
7063
7067
  throw capResult.reason;
7064
7068
  }
7065
- const capability = capResult.value.data.capability;
7066
- if (!capability) {
7067
- throw new Error(`Capability ${id} not found in project ${projectId2}`);
7068
- }
7069
+ const capability = requireEntity(
7070
+ capResult.value.data.capability,
7071
+ `Capability ${id} not found in project ${projectId2}`
7072
+ );
7069
7073
  let latestVersion;
7070
7074
  if (versionResult.status === "fulfilled" && versionResult.value.data.capabilityVersion) {
7071
7075
  latestVersion = capabilityVersionFromProto(
@@ -7088,12 +7092,10 @@ function createApiClient(serverUrl, options = "") {
7088
7092
  capabilityVersionId: versionId
7089
7093
  })
7090
7094
  );
7091
- const version = res.data.capabilityVersion;
7092
- if (!version) {
7093
- throw new Error(
7094
- `Capability version ${versionId} not found for capability ${capabilityId}`
7095
- );
7096
- }
7095
+ const version = requireEntity(
7096
+ res.data.capabilityVersion,
7097
+ `Capability version ${versionId} not found for capability ${capabilityId}`
7098
+ );
7097
7099
  return capabilityVersionFromProto(version, projectId2);
7098
7100
  },
7099
7101
  async addResult(projectId2, evalRunId2, result) {