@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 +37 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -987,12 +987,13 @@ function parseRubricItems(rawRubrics, evaluatorName, evalId) {
|
|
|
987
987
|
let scoreRanges;
|
|
988
988
|
const rawScoreRanges = rawRubric.score_ranges;
|
|
989
989
|
if (rawScoreRanges !== void 0) {
|
|
990
|
-
|
|
990
|
+
const normalized = normalizeScoreRangesShorthand(rawScoreRanges);
|
|
991
|
+
if (!Array.isArray(normalized)) {
|
|
991
992
|
throw new Error(
|
|
992
|
-
`Invalid score_ranges for rubric '${id}' in evaluator '${evaluatorName}' in '${evalId}': must be an array`
|
|
993
|
+
`Invalid score_ranges for rubric '${id}' in evaluator '${evaluatorName}' in '${evalId}': must be an array or shorthand map`
|
|
993
994
|
);
|
|
994
995
|
}
|
|
995
|
-
scoreRanges = parseScoreRanges(
|
|
996
|
+
scoreRanges = parseScoreRanges(normalized, id, evaluatorName, evalId);
|
|
996
997
|
items.push({
|
|
997
998
|
id,
|
|
998
999
|
weight,
|
|
@@ -1020,6 +1021,37 @@ function parseRubricItems(rawRubrics, evaluatorName, evalId) {
|
|
|
1020
1021
|
}
|
|
1021
1022
|
return items.length > 0 ? items : void 0;
|
|
1022
1023
|
}
|
|
1024
|
+
function normalizeScoreRangesShorthand(raw) {
|
|
1025
|
+
if (Array.isArray(raw)) return raw;
|
|
1026
|
+
if (!isJsonObject2(raw)) return raw;
|
|
1027
|
+
const keys = Object.keys(raw);
|
|
1028
|
+
if (keys.length === 0) return raw;
|
|
1029
|
+
const numericKeys = [];
|
|
1030
|
+
for (const key of keys) {
|
|
1031
|
+
const num = Number(key);
|
|
1032
|
+
if (!Number.isInteger(num) || num < 0 || num > 10) {
|
|
1033
|
+
return raw;
|
|
1034
|
+
}
|
|
1035
|
+
if (typeof raw[key] !== "string" || raw[key].length === 0) {
|
|
1036
|
+
return raw;
|
|
1037
|
+
}
|
|
1038
|
+
numericKeys.push(num);
|
|
1039
|
+
}
|
|
1040
|
+
numericKeys.sort((a, b) => a - b);
|
|
1041
|
+
if (numericKeys[0] !== 0) {
|
|
1042
|
+
throw new Error(`score_ranges shorthand map must start at 0 (got ${numericKeys[0]})`);
|
|
1043
|
+
}
|
|
1044
|
+
const result = [];
|
|
1045
|
+
for (let i = 0; i < numericKeys.length; i++) {
|
|
1046
|
+
const min = numericKeys[i];
|
|
1047
|
+
const max = i < numericKeys.length - 1 ? numericKeys[i + 1] - 1 : 10;
|
|
1048
|
+
result.push({
|
|
1049
|
+
score_range: [min, max],
|
|
1050
|
+
expected_outcome: raw[String(min)]
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
return result;
|
|
1054
|
+
}
|
|
1023
1055
|
function parseScoreRanges(rawRanges, rubricId, evaluatorName, evalId) {
|
|
1024
1056
|
const ranges = [];
|
|
1025
1057
|
for (const [index, rawRange] of rawRanges.entries()) {
|
|
@@ -1102,7 +1134,8 @@ function parseInlineRubrics(rawRubrics) {
|
|
|
1102
1134
|
}
|
|
1103
1135
|
const expectedOutcome = asString(rubric.expected_outcome) ?? asString(rubric.description) ?? "";
|
|
1104
1136
|
const rawScoreRanges = rubric.score_ranges;
|
|
1105
|
-
const
|
|
1137
|
+
const normalizedScoreRanges = rawScoreRanges !== void 0 ? normalizeScoreRangesShorthand(rawScoreRanges) : void 0;
|
|
1138
|
+
const scoreRanges = Array.isArray(normalizedScoreRanges) && normalizedScoreRanges.length > 0 ? normalizedScoreRanges.filter((r) => isJsonObject2(r)).map((range) => ({
|
|
1106
1139
|
score_range: Array.isArray(range.score_range) ? range.score_range : [0, 10],
|
|
1107
1140
|
expected_outcome: asString(range.expected_outcome) ?? asString(range.description) ?? ""
|
|
1108
1141
|
})).filter((r) => r.expected_outcome.length > 0) : void 0;
|