@agentv/core 2.5.4 → 2.5.5

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/dist/index.cjs CHANGED
@@ -1068,12 +1068,13 @@ function parseRubricItems(rawRubrics, evaluatorName, evalId) {
1068
1068
  let scoreRanges;
1069
1069
  const rawScoreRanges = rawRubric.score_ranges;
1070
1070
  if (rawScoreRanges !== void 0) {
1071
- if (!Array.isArray(rawScoreRanges)) {
1071
+ const normalized = normalizeScoreRangesShorthand(rawScoreRanges);
1072
+ if (!Array.isArray(normalized)) {
1072
1073
  throw new Error(
1073
- `Invalid score_ranges for rubric '${id}' in evaluator '${evaluatorName}' in '${evalId}': must be an array`
1074
+ `Invalid score_ranges for rubric '${id}' in evaluator '${evaluatorName}' in '${evalId}': must be an array or shorthand map`
1074
1075
  );
1075
1076
  }
1076
- scoreRanges = parseScoreRanges(rawScoreRanges, id, evaluatorName, evalId);
1077
+ scoreRanges = parseScoreRanges(normalized, id, evaluatorName, evalId);
1077
1078
  items.push({
1078
1079
  id,
1079
1080
  weight,
@@ -1101,6 +1102,37 @@ function parseRubricItems(rawRubrics, evaluatorName, evalId) {
1101
1102
  }
1102
1103
  return items.length > 0 ? items : void 0;
1103
1104
  }
1105
+ function normalizeScoreRangesShorthand(raw) {
1106
+ if (Array.isArray(raw)) return raw;
1107
+ if (!isJsonObject2(raw)) return raw;
1108
+ const keys = Object.keys(raw);
1109
+ if (keys.length === 0) return raw;
1110
+ const numericKeys = [];
1111
+ for (const key of keys) {
1112
+ const num = Number(key);
1113
+ if (!Number.isInteger(num) || num < 0 || num > 10) {
1114
+ return raw;
1115
+ }
1116
+ if (typeof raw[key] !== "string" || raw[key].length === 0) {
1117
+ return raw;
1118
+ }
1119
+ numericKeys.push(num);
1120
+ }
1121
+ numericKeys.sort((a, b) => a - b);
1122
+ if (numericKeys[0] !== 0) {
1123
+ throw new Error(`score_ranges shorthand map must start at 0 (got ${numericKeys[0]})`);
1124
+ }
1125
+ const result = [];
1126
+ for (let i = 0; i < numericKeys.length; i++) {
1127
+ const min = numericKeys[i];
1128
+ const max = i < numericKeys.length - 1 ? numericKeys[i + 1] - 1 : 10;
1129
+ result.push({
1130
+ score_range: [min, max],
1131
+ expected_outcome: raw[String(min)]
1132
+ });
1133
+ }
1134
+ return result;
1135
+ }
1104
1136
  function parseScoreRanges(rawRanges, rubricId, evaluatorName, evalId) {
1105
1137
  const ranges = [];
1106
1138
  for (const [index, rawRange] of rawRanges.entries()) {
@@ -1183,7 +1215,8 @@ function parseInlineRubrics(rawRubrics) {
1183
1215
  }
1184
1216
  const expectedOutcome = asString(rubric.expected_outcome) ?? asString(rubric.description) ?? "";
1185
1217
  const rawScoreRanges = rubric.score_ranges;
1186
- const scoreRanges = Array.isArray(rawScoreRanges) && rawScoreRanges.length > 0 ? rawScoreRanges.filter((r) => isJsonObject2(r)).map((range) => ({
1218
+ const normalizedScoreRanges = rawScoreRanges !== void 0 ? normalizeScoreRangesShorthand(rawScoreRanges) : void 0;
1219
+ const scoreRanges = Array.isArray(normalizedScoreRanges) && normalizedScoreRanges.length > 0 ? normalizedScoreRanges.filter((r) => isJsonObject2(r)).map((range) => ({
1187
1220
  score_range: Array.isArray(range.score_range) ? range.score_range : [0, 10],
1188
1221
  expected_outcome: asString(range.expected_outcome) ?? asString(range.description) ?? ""
1189
1222
  })).filter((r) => r.expected_outcome.length > 0) : void 0;