@memberjunction/testing-engine 6.2.0-edge.1 → 6.2.0-edge.2

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.
Files changed (142) hide show
  1. package/README.md +4 -1
  2. package/dist/decision-eval/corpus.d.ts +94 -0
  3. package/dist/decision-eval/corpus.d.ts.map +1 -0
  4. package/dist/decision-eval/corpus.js +144 -0
  5. package/dist/decision-eval/corpus.js.map +1 -0
  6. package/dist/decision-eval/discovery-baseline.d.ts +62 -0
  7. package/dist/decision-eval/discovery-baseline.d.ts.map +1 -0
  8. package/dist/decision-eval/discovery-baseline.js +90 -0
  9. package/dist/decision-eval/discovery-baseline.js.map +1 -0
  10. package/dist/decision-eval/discovery-corpus.d.ts +75 -0
  11. package/dist/decision-eval/discovery-corpus.d.ts.map +1 -0
  12. package/dist/decision-eval/discovery-corpus.js +110 -0
  13. package/dist/decision-eval/discovery-corpus.js.map +1 -0
  14. package/dist/decision-eval/discovery-mapping.d.ts +18 -0
  15. package/dist/decision-eval/discovery-mapping.d.ts.map +1 -0
  16. package/dist/decision-eval/discovery-mapping.js +21 -0
  17. package/dist/decision-eval/discovery-mapping.js.map +1 -0
  18. package/dist/decision-eval/discovery-metrics.d.ts +339 -0
  19. package/dist/decision-eval/discovery-metrics.d.ts.map +1 -0
  20. package/dist/decision-eval/discovery-metrics.js +401 -0
  21. package/dist/decision-eval/discovery-metrics.js.map +1 -0
  22. package/dist/decision-eval/discovery-scorecard.d.ts +96 -0
  23. package/dist/decision-eval/discovery-scorecard.d.ts.map +1 -0
  24. package/dist/decision-eval/discovery-scorecard.js +351 -0
  25. package/dist/decision-eval/discovery-scorecard.js.map +1 -0
  26. package/dist/decision-eval/discovery-suite.d.ts +201 -0
  27. package/dist/decision-eval/discovery-suite.d.ts.map +1 -0
  28. package/dist/decision-eval/discovery-suite.js +180 -0
  29. package/dist/decision-eval/discovery-suite.js.map +1 -0
  30. package/dist/decision-eval/discovery-types.d.ts +896 -0
  31. package/dist/decision-eval/discovery-types.d.ts.map +1 -0
  32. package/dist/decision-eval/discovery-types.js +211 -0
  33. package/dist/decision-eval/discovery-types.js.map +1 -0
  34. package/dist/decision-eval/index.d.ts +18 -0
  35. package/dist/decision-eval/index.d.ts.map +1 -0
  36. package/dist/decision-eval/index.js +18 -0
  37. package/dist/decision-eval/index.js.map +1 -0
  38. package/dist/decision-eval/metrics.d.ts +330 -0
  39. package/dist/decision-eval/metrics.d.ts.map +1 -0
  40. package/dist/decision-eval/metrics.js +574 -0
  41. package/dist/decision-eval/metrics.js.map +1 -0
  42. package/dist/decision-eval/output-paths.d.ts +119 -0
  43. package/dist/decision-eval/output-paths.d.ts.map +1 -0
  44. package/dist/decision-eval/output-paths.js +258 -0
  45. package/dist/decision-eval/output-paths.js.map +1 -0
  46. package/dist/decision-eval/point-mapping.d.ts +50 -0
  47. package/dist/decision-eval/point-mapping.d.ts.map +1 -0
  48. package/dist/decision-eval/point-mapping.js +83 -0
  49. package/dist/decision-eval/point-mapping.js.map +1 -0
  50. package/dist/decision-eval/scorecard.d.ts +190 -0
  51. package/dist/decision-eval/scorecard.d.ts.map +1 -0
  52. package/dist/decision-eval/scorecard.js +384 -0
  53. package/dist/decision-eval/scorecard.js.map +1 -0
  54. package/dist/decision-eval/suite.d.ts +244 -0
  55. package/dist/decision-eval/suite.d.ts.map +1 -0
  56. package/dist/decision-eval/suite.js +238 -0
  57. package/dist/decision-eval/suite.js.map +1 -0
  58. package/dist/decision-eval/types.d.ts +993 -0
  59. package/dist/decision-eval/types.d.ts.map +1 -0
  60. package/dist/decision-eval/types.js +227 -0
  61. package/dist/decision-eval/types.js.map +1 -0
  62. package/dist/drivers/AgentEvalDriver.d.ts +30 -1
  63. package/dist/drivers/AgentEvalDriver.d.ts.map +1 -1
  64. package/dist/drivers/AgentEvalDriver.js +145 -16
  65. package/dist/drivers/AgentEvalDriver.js.map +1 -1
  66. package/dist/drivers/DecisionEvalDriver.d.ts +297 -0
  67. package/dist/drivers/DecisionEvalDriver.d.ts.map +1 -0
  68. package/dist/drivers/DecisionEvalDriver.js +716 -0
  69. package/dist/drivers/DecisionEvalDriver.js.map +1 -0
  70. package/dist/drivers/PinnedDecisionRunner.d.ts +24 -0
  71. package/dist/drivers/PinnedDecisionRunner.d.ts.map +1 -0
  72. package/dist/drivers/PinnedDecisionRunner.js +24 -0
  73. package/dist/drivers/PinnedDecisionRunner.js.map +1 -0
  74. package/dist/drivers/PromptEvalDriver.d.ts.map +1 -1
  75. package/dist/drivers/PromptEvalDriver.js +8 -1
  76. package/dist/drivers/PromptEvalDriver.js.map +1 -1
  77. package/dist/drivers/RubricCalibrationTestDriver.d.ts +34 -0
  78. package/dist/drivers/RubricCalibrationTestDriver.d.ts.map +1 -0
  79. package/dist/drivers/RubricCalibrationTestDriver.js +193 -0
  80. package/dist/drivers/RubricCalibrationTestDriver.js.map +1 -0
  81. package/dist/drivers/calibration.d.ts +85 -0
  82. package/dist/drivers/calibration.d.ts.map +1 -0
  83. package/dist/drivers/calibration.js +191 -0
  84. package/dist/drivers/calibration.js.map +1 -0
  85. package/dist/drivers/index.d.ts +2 -0
  86. package/dist/drivers/index.d.ts.map +1 -1
  87. package/dist/drivers/index.js +2 -0
  88. package/dist/drivers/index.js.map +1 -1
  89. package/dist/engine/TestEngine.d.ts.map +1 -1
  90. package/dist/engine/TestEngine.js +14 -4
  91. package/dist/engine/TestEngine.js.map +1 -1
  92. package/dist/index.d.ts +12 -0
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +12 -0
  95. package/dist/index.js.map +1 -1
  96. package/dist/oracles/DecisionJudgeOracle.d.ts +97 -0
  97. package/dist/oracles/DecisionJudgeOracle.d.ts.map +1 -0
  98. package/dist/oracles/DecisionJudgeOracle.js +230 -0
  99. package/dist/oracles/DecisionJudgeOracle.js.map +1 -0
  100. package/dist/oracles/DecisionLabelMatchOracle.d.ts +38 -0
  101. package/dist/oracles/DecisionLabelMatchOracle.d.ts.map +1 -0
  102. package/dist/oracles/DecisionLabelMatchOracle.js +96 -0
  103. package/dist/oracles/DecisionLabelMatchOracle.js.map +1 -0
  104. package/dist/oracles/DiscoveryLabelMatchOracle.d.ts +39 -0
  105. package/dist/oracles/DiscoveryLabelMatchOracle.d.ts.map +1 -0
  106. package/dist/oracles/DiscoveryLabelMatchOracle.js +88 -0
  107. package/dist/oracles/DiscoveryLabelMatchOracle.js.map +1 -0
  108. package/dist/oracles/LLMJudgeOracle.d.ts +2 -47
  109. package/dist/oracles/LLMJudgeOracle.d.ts.map +1 -1
  110. package/dist/oracles/LLMJudgeOracle.js +80 -149
  111. package/dist/oracles/LLMJudgeOracle.js.map +1 -1
  112. package/dist/oracles/RubricOracle.d.ts +51 -0
  113. package/dist/oracles/RubricOracle.d.ts.map +1 -0
  114. package/dist/oracles/RubricOracle.js +66 -0
  115. package/dist/oracles/RubricOracle.js.map +1 -0
  116. package/dist/oracles/index.d.ts +5 -0
  117. package/dist/oracles/index.d.ts.map +1 -1
  118. package/dist/oracles/index.js +5 -0
  119. package/dist/oracles/index.js.map +1 -1
  120. package/dist/oracles/inline-rubric.d.ts +25 -0
  121. package/dist/oracles/inline-rubric.d.ts.map +1 -0
  122. package/dist/oracles/inline-rubric.js +82 -0
  123. package/dist/oracles/inline-rubric.js.map +1 -0
  124. package/dist/oracles/judge-trace.d.ts +76 -0
  125. package/dist/oracles/judge-trace.d.ts.map +1 -0
  126. package/dist/oracles/judge-trace.js +125 -0
  127. package/dist/oracles/judge-trace.js.map +1 -0
  128. package/dist/oracles/promote-criteria.d.ts +57 -0
  129. package/dist/oracles/promote-criteria.d.ts.map +1 -0
  130. package/dist/oracles/promote-criteria.js +104 -0
  131. package/dist/oracles/promote-criteria.js.map +1 -0
  132. package/dist/oracles/rubric-resolution.d.ts +69 -0
  133. package/dist/oracles/rubric-resolution.d.ts.map +1 -0
  134. package/dist/oracles/rubric-resolution.js +110 -0
  135. package/dist/oracles/rubric-resolution.js.map +1 -0
  136. package/dist/types.d.ts +4 -0
  137. package/dist/types.d.ts.map +1 -1
  138. package/dist/utils/result-formatter.d.ts +5 -0
  139. package/dist/utils/result-formatter.d.ts.map +1 -1
  140. package/dist/utils/result-formatter.js +8 -2
  141. package/dist/utils/result-formatter.js.map +1 -1
  142. package/package.json +12 -10
@@ -0,0 +1,82 @@
1
+ import { RubricScoring } from '@memberjunction/rubrics-base';
2
+ function inlineLeaves(criteria) {
3
+ return criteria.map(item => typeof item === 'string' ? { text: item, weight: 1 } : { text: item.text, weight: item.weight ?? 1 });
4
+ }
5
+ /** A binary inline rubric. Met = 1 and Not met = 0. There is no version row. */
6
+ export function InlineVersion(criteria, strict, passThreshold) {
7
+ const leaves = inlineLeaves(criteria);
8
+ return {
9
+ id: 'inline',
10
+ rubricId: 'inline',
11
+ notApplicablePolicy: 'NotAllowed',
12
+ minimumCompleteness: 1,
13
+ passThreshold,
14
+ scoreDisplayMin: 0,
15
+ scoreDisplayMax: 1,
16
+ nodes: leaves.map((leaf, index) => ({
17
+ id: `c${index}`,
18
+ key: `c${index}`,
19
+ name: leaf.text,
20
+ nodeType: 'Criterion',
21
+ scaleId: 'met',
22
+ weight: leaf.weight,
23
+ isAdvisory: false,
24
+ isGate: strict,
25
+ gateMinimumScore: strict ? 1 : null,
26
+ evidenceRequired: false,
27
+ rationaleRequired: false,
28
+ sequence: index,
29
+ })),
30
+ scales: [{
31
+ id: 'met',
32
+ scaleType: 'Levels',
33
+ higherIsBetter: true,
34
+ levels: [
35
+ { id: 'not-met', label: 'Not met', value: 0, normalizedValue: 0, sequence: 0 },
36
+ { id: 'met', label: 'Met', value: 1, normalizedValue: 1, sequence: 1 },
37
+ ],
38
+ }],
39
+ bands: [],
40
+ };
41
+ }
42
+ export function ScoreInline(criteria, answers, options) {
43
+ const version = InlineVersion(criteria, options.strict === true, options.passThreshold ?? 0.7);
44
+ return RubricScoring.Compute({
45
+ version,
46
+ answers: answers.map(answer => ({
47
+ criterionId: `c${answer.index}`,
48
+ scaleLevelId: answer.met ? 'met' : 'not-met',
49
+ rationale: answer.rationale,
50
+ })),
51
+ });
52
+ }
53
+ /** Computer Use verdicts, reported in the same inline details shape. Not stored as a RubricEvaluation. */
54
+ export function InlineOracleFromVerdicts(verdicts, passThreshold = 0.7) {
55
+ const scored = ScoreInline(verdicts.map(verdict => verdict.criterion), verdicts.map((verdict, index) => ({
56
+ index,
57
+ met: verdict.met,
58
+ rationale: verdict.evidence,
59
+ })), { passThreshold });
60
+ return InlineOracleResult(verdicts.map(verdict => verdict.criterion), scored, verdicts.map(verdict => verdict.evidence));
61
+ }
62
+ export function InlineOracleResult(criteria, scored, evidence = []) {
63
+ const passed = scored.outcome === 'Passed';
64
+ return {
65
+ oracleType: 'llm-judge',
66
+ passed,
67
+ score: scored.normalizedScore ?? 0,
68
+ message: `inline: ${scored.outcome} (${scored.normalizedScore ?? 0})`,
69
+ details: {
70
+ inline: true,
71
+ Outcome: scored.outcome,
72
+ Criteria: scored.nodes.map((node, index) => ({
73
+ Key: node.key,
74
+ Name: criteria[index] ?? node.key,
75
+ NormalizedScore: node.normalizedScore,
76
+ GateFailed: node.gateFailed,
77
+ Rationale: evidence[index],
78
+ })),
79
+ },
80
+ };
81
+ }
82
+ //# sourceMappingURL=inline-rubric.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-rubric.js","sourceRoot":"","sources":["../../src/oracles/inline-rubric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAsD,MAAM,8BAA8B,CAAC;AAMjH,SAAS,YAAY,CAAC,QAAyC;IAC3D,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC;A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EAAE,MAAyB,EAAE,WAAmC,EAAE;IACnH,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,KAAK,QAAQ,CAAC;IAC3C,OAAO;QACH,UAAU,EAAE,WAAW;QACvB,MAAM;QACN,KAAK,EAAE,MAAM,CAAC,eAAe,IAAI,CAAC;QAClC,OAAO,EAAE,WAAW,MAAM,CAAC,OAAO,KAAK,MAAM,CAAC,eAAe,IAAI,CAAC,GAAG;QACrE,OAAO,EAAE;YACL,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;gBACzC,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG;gBACjC,eAAe,EAAE,IAAI,CAAC,eAAe;gBACrC,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC;aAC7B,CAAC,CAAC;SACN;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @fileoverview The trace and criteria the judge oracles evaluate
3
+ * @module @memberjunction/testing-engine
4
+ *
5
+ * `LLMJudgeOracle` and `DecisionJudgeOracle` judge the same trace against the same criteria, so a
6
+ * test can run both side by side. Both read them, and their model-call timeout, through these
7
+ * helpers, so both accept, and reject, exactly the same criteria and settings.
8
+ */
9
+ import { OracleInput, OracleConfig } from '../types.js';
10
+ /**
11
+ * The trace a judge evaluates, as pretty-printed JSON. Each part is `JSON.stringify`'s output, so it
12
+ * is `undefined` when the value it renders is `undefined`.
13
+ */
14
+ export interface JudgeTrace {
15
+ /** The test's input definition, parsed first when it is stored as a JSON string; `{}` when it has none. */
16
+ Input: string | undefined;
17
+ /** The test's expected output. */
18
+ Expected: string | undefined;
19
+ /** The output the test produced. */
20
+ Actual: string | undefined;
21
+ }
22
+ /**
23
+ * One criterion a judge scores against. A test states it as a string, or as
24
+ * `{ "criterion": "...", "weight": 2 }`.
25
+ */
26
+ export interface JudgeCriterion {
27
+ /** What the output must satisfy, as the test states it. */
28
+ Criterion: string;
29
+ /** The criterion's weight in a weighted score: a finite number of 0 or more, 1 when the test sets none. */
30
+ Weight: number;
31
+ }
32
+ /** A value read from the test or the oracle config, or the reason it cannot be used. */
33
+ export type JudgeReadResult<T> = {
34
+ Success: true;
35
+ Value: T;
36
+ } | {
37
+ Success: false;
38
+ ErrorMessage: string;
39
+ };
40
+ /**
41
+ * How long a judge waits for each model call when the oracle config sets no `timeoutMS`: two minutes.
42
+ * A judge call is one prompt over one test's trace, so this is generous; it is there so a hung call
43
+ * fails the oracle instead of hanging the test run.
44
+ */
45
+ export declare const DEFAULT_JUDGE_TIMEOUT_MS = 120000;
46
+ /**
47
+ * Builds the trace a judge evaluates from the oracle input.
48
+ *
49
+ * @param input - The oracle input
50
+ * @returns The input definition, the expected output and the actual output, as JSON
51
+ * @throws SyntaxError when the test's input definition is a string that is not valid JSON
52
+ */
53
+ export declare function BuildJudgeTrace(input: OracleInput): JudgeTrace;
54
+ /**
55
+ * Reads the criteria a judge scores against: the expected output's `judgeValidationCriteria` when it
56
+ * is set, otherwise the oracle config's `criteria`. Each entry is a non-empty string (weight 1), or
57
+ * an object with a non-empty `criterion` and an optional `weight` that is a finite number of 0 or more.
58
+ * At least one criterion must weigh more than 0.
59
+ *
60
+ * @param input - The oracle input
61
+ * @param config - The oracle config
62
+ * @returns The criteria, in the order the test lists them, or the reason they cannot be read: there
63
+ * are none, the value is not an array, an entry is malformed, or every weight is 0
64
+ */
65
+ export declare function ReadJudgeCriteria(input: OracleInput, config: OracleConfig): JudgeReadResult<JudgeCriterion[]>;
66
+ /**
67
+ * Reads how long a judge waits for each model call from the oracle config's `timeoutMS`. The runner
68
+ * applies it to each model call as `AIPromptParams.timeoutMS`, so a failover to another model gets a
69
+ * fresh budget, and a call that runs over fails.
70
+ *
71
+ * @param config - The oracle config
72
+ * @returns The timeout in milliseconds, {@link DEFAULT_JUDGE_TIMEOUT_MS} when the config sets none, or
73
+ * the reason the config's value is not a positive, finite number
74
+ */
75
+ export declare function ReadJudgeTimeoutMS(config: OracleConfig): JudgeReadResult<number>;
76
+ //# sourceMappingURL=judge-trace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"judge-trace.d.ts","sourceRoot":"","sources":["../../src/oracles/judge-trace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,UAAU;IACvB,2GAA2G;IAC3G,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,oCAAoC;IACpC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC3B,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,2GAA2G;IAC3G,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,wFAAwF;AACxF,MAAM,MAAM,eAAe,CAAC,CAAC,IACvB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC3B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,SAAU,CAAC;AAEhD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAM9D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,eAAe,CAAC,cAAc,EAAE,CAAC,CAS7G;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,eAAe,CAAC,MAAM,CAAC,CAOhF"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @fileoverview The trace and criteria the judge oracles evaluate
3
+ * @module @memberjunction/testing-engine
4
+ *
5
+ * `LLMJudgeOracle` and `DecisionJudgeOracle` judge the same trace against the same criteria, so a
6
+ * test can run both side by side. Both read them, and their model-call timeout, through these
7
+ * helpers, so both accept, and reject, exactly the same criteria and settings.
8
+ */
9
+ /**
10
+ * How long a judge waits for each model call when the oracle config sets no `timeoutMS`: two minutes.
11
+ * A judge call is one prompt over one test's trace, so this is generous; it is there so a hung call
12
+ * fails the oracle instead of hanging the test run.
13
+ */
14
+ export const DEFAULT_JUDGE_TIMEOUT_MS = 120_000;
15
+ /**
16
+ * Builds the trace a judge evaluates from the oracle input.
17
+ *
18
+ * @param input - The oracle input
19
+ * @returns The input definition, the expected output and the actual output, as JSON
20
+ * @throws SyntaxError when the test's input definition is a string that is not valid JSON
21
+ */
22
+ export function BuildJudgeTrace(input) {
23
+ return {
24
+ Input: JSON.stringify(readInputDefinition(input), null, 2),
25
+ Expected: JSON.stringify(input.expectedOutput, null, 2),
26
+ Actual: JSON.stringify(input.actualOutput, null, 2),
27
+ };
28
+ }
29
+ /**
30
+ * Reads the criteria a judge scores against: the expected output's `judgeValidationCriteria` when it
31
+ * is set, otherwise the oracle config's `criteria`. Each entry is a non-empty string (weight 1), or
32
+ * an object with a non-empty `criterion` and an optional `weight` that is a finite number of 0 or more.
33
+ * At least one criterion must weigh more than 0.
34
+ *
35
+ * @param input - The oracle input
36
+ * @param config - The oracle config
37
+ * @returns The criteria, in the order the test lists them, or the reason they cannot be read: there
38
+ * are none, the value is not an array, an entry is malformed, or every weight is 0
39
+ */
40
+ export function ReadJudgeCriteria(input, config) {
41
+ const raw = readExpectedCriteria(input.expectedOutput) || config.criteria;
42
+ if (!raw || (Array.isArray(raw) && raw.length === 0)) {
43
+ return { Success: false, ErrorMessage: 'No validation criteria provided' };
44
+ }
45
+ if (!Array.isArray(raw)) {
46
+ return { Success: false, ErrorMessage: `Validation criteria must be an array of criteria, not a ${typeof raw}` };
47
+ }
48
+ return readCriteriaEntries(raw);
49
+ }
50
+ /**
51
+ * Reads how long a judge waits for each model call from the oracle config's `timeoutMS`. The runner
52
+ * applies it to each model call as `AIPromptParams.timeoutMS`, so a failover to another model gets a
53
+ * fresh budget, and a call that runs over fails.
54
+ *
55
+ * @param config - The oracle config
56
+ * @returns The timeout in milliseconds, {@link DEFAULT_JUDGE_TIMEOUT_MS} when the config sets none, or
57
+ * the reason the config's value is not a positive, finite number
58
+ */
59
+ export function ReadJudgeTimeoutMS(config) {
60
+ const timeoutMS = config.timeoutMS ?? DEFAULT_JUDGE_TIMEOUT_MS;
61
+ if (typeof timeoutMS !== 'number' || !Number.isFinite(timeoutMS) || timeoutMS <= 0) {
62
+ const shown = typeof timeoutMS === 'number' ? String(timeoutMS) : JSON.stringify(timeoutMS);
63
+ return { Success: false, ErrorMessage: `timeoutMS must be a positive number of milliseconds, not ${shown}` };
64
+ }
65
+ return { Success: true, Value: timeoutMS };
66
+ }
67
+ /** The test's input definition, parsed when it is a JSON string, or `{}` when it has none. */
68
+ function readInputDefinition(input) {
69
+ const definition = input.test.InputDefinition;
70
+ if (!definition) {
71
+ return {};
72
+ }
73
+ return typeof definition === 'string' ? JSON.parse(definition) : definition;
74
+ }
75
+ /** The expected output's `judgeValidationCriteria`, when the expected output is an object. */
76
+ function readExpectedCriteria(expectedOutput) {
77
+ if (typeof expectedOutput !== 'object' || expectedOutput === null || !('judgeValidationCriteria' in expectedOutput)) {
78
+ return undefined;
79
+ }
80
+ return expectedOutput.judgeValidationCriteria;
81
+ }
82
+ /**
83
+ * Every entry as a criterion, or the reason they cannot be read: the first malformed entry, or every
84
+ * weight being 0, which leaves a weighted score with nothing to weigh.
85
+ */
86
+ function readCriteriaEntries(entries) {
87
+ const criteria = [];
88
+ for (const [index, entry] of entries.entries()) {
89
+ const criterion = readCriterion(entry);
90
+ if (!criterion) {
91
+ return {
92
+ Success: false,
93
+ ErrorMessage: `Criterion ${index + 1} must be a non-empty string, or an object with a non-empty "criterion" ` +
94
+ 'and an optional "weight" that is a number of 0 or more',
95
+ };
96
+ }
97
+ criteria.push(criterion);
98
+ }
99
+ if (criteria.every(c => c.Weight === 0)) {
100
+ return {
101
+ Success: false,
102
+ ErrorMessage: 'Every criterion has weight 0, so none counts toward the score: give at least one a weight above 0',
103
+ };
104
+ }
105
+ return { Success: true, Value: criteria };
106
+ }
107
+ /** One criterion: a string (weight 1), or `{ criterion, weight? }`. Undefined when it is neither. */
108
+ function readCriterion(entry) {
109
+ if (typeof entry === 'string') {
110
+ return entry.trim() ? { Criterion: entry, Weight: 1 } : undefined;
111
+ }
112
+ if (typeof entry !== 'object' || entry === null || !('criterion' in entry)) {
113
+ return undefined;
114
+ }
115
+ const text = entry.criterion;
116
+ const weight = 'weight' in entry && entry.weight != null ? entry.weight : 1;
117
+ if (typeof text !== 'string' || !text.trim()) {
118
+ return undefined;
119
+ }
120
+ if (typeof weight !== 'number' || !Number.isFinite(weight) || weight < 0) {
121
+ return undefined;
122
+ }
123
+ return { Criterion: text, Weight: weight };
124
+ }
125
+ //# sourceMappingURL=judge-trace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"judge-trace.js","sourceRoot":"","sources":["../../src/oracles/judge-trace.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiCH;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAkB;IAC9C,OAAO;QACH,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,EA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O;YACH,OAAO,EAAE,KAAK;YACd,YAAY,EAAE,mGAAmG;SACpH,CAAC;IACN,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC9C,CAAC;AAED,qGAAqG;AACrG,SAAS,aAAa,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,EAAE,CAAC;QACzE,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC;IAC7B,MAAM,MAAM,GAAG,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3C,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACvE,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,57 @@
1
+ /** The reusable binary scale. Created once and shared by every promoted draft. */
2
+ export declare const BINARY_SCALE_NAME = "Binary (Met / Not met)";
3
+ export interface PromotedCriterion {
4
+ key: string;
5
+ name: string;
6
+ weight: number;
7
+ isGate: boolean;
8
+ gateMinimumScore: number | null;
9
+ sequence: number;
10
+ }
11
+ /** A draft rubric that copies the inline judge. The version stays Draft. */
12
+ export interface PromotedRubric {
13
+ name: string;
14
+ description: string;
15
+ passThreshold: number;
16
+ notApplicablePolicy: 'NotAllowed';
17
+ scoreDisplayMin: 0;
18
+ scoreDisplayMax: 1;
19
+ status: 'Draft';
20
+ criteria: PromotedCriterion[];
21
+ }
22
+ export type PromoteCriteriaPlan = {
23
+ ok: true;
24
+ rubric: PromotedRubric;
25
+ } | {
26
+ ok: false;
27
+ message: string;
28
+ };
29
+ export interface PromoteCriteriaStore {
30
+ saveRubric(input: {
31
+ name: string;
32
+ description: string;
33
+ }): Promise<string>;
34
+ ensureBinaryScale(): Promise<string>;
35
+ saveDraftVersion(input: PromotedRubric & {
36
+ rubricId: string;
37
+ scaleId: string;
38
+ }): Promise<string>;
39
+ setTestRubric(testId: string, rubricId: string): Promise<void>;
40
+ }
41
+ /**
42
+ * Plans a Draft rubric from a test's inline criteria. Does not publish and does not replace a rubric
43
+ * the test already has. Weights, the judge threshold, and strict mode are copied onto the leaves.
44
+ */
45
+ export declare function BuildPromotedRubric(input: {
46
+ testName: string;
47
+ testId: string;
48
+ existingRubricId?: string | null;
49
+ expectedOutcomes: unknown;
50
+ configuration: unknown;
51
+ }): PromoteCriteriaPlan;
52
+ /** Writes the draft and points the test at it. The version status is Draft. */
53
+ export declare function PromoteInlineCriteria(testId: string, rubric: PromotedRubric, store: PromoteCriteriaStore): Promise<{
54
+ rubricId: string;
55
+ versionId: string;
56
+ }>;
57
+ //# sourceMappingURL=promote-criteria.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promote-criteria.d.ts","sourceRoot":"","sources":["../../src/oracles/promote-criteria.ts"],"names":[],"mappings":"AAKA,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D,MAAM,WAAW,iBAAiB;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EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,aAAa,EAAE,OAAO,CAAC;CAC1B,GAAG,mBAAmB,CAuCtB;AAED,+EAA+E;AAC/E,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAMjK"}
@@ -0,0 +1,104 @@
1
+ import { ReadJudgeCriteria } from './judge-trace.js';
2
+ /** The reusable binary scale. Created once and shared by every promoted draft. */
3
+ export const BINARY_SCALE_NAME = 'Binary (Met / Not met)';
4
+ /**
5
+ * Plans a Draft rubric from a test's inline criteria. Does not publish and does not replace a rubric
6
+ * the test already has. Weights, the judge threshold, and strict mode are copied onto the leaves.
7
+ */
8
+ export function BuildPromotedRubric(input) {
9
+ if (input.existingRubricId) {
10
+ return { ok: false, message: 'This test already has a rubric. Promotion does not replace it.' };
11
+ }
12
+ let expected = input.expectedOutcomes;
13
+ let configuration = input.configuration;
14
+ try {
15
+ if (typeof expected === 'string')
16
+ expected = expected.trim() ? JSON.parse(expected) : {};
17
+ if (typeof configuration === 'string')
18
+ configuration = configuration.trim() ? JSON.parse(configuration) : {};
19
+ }
20
+ catch {
21
+ return { ok: false, message: 'Expected outcomes or configuration is not valid JSON.' };
22
+ }
23
+ const judge = judgeOracleConfig(configuration);
24
+ const read = ReadJudgeCriteria(oracleInput(expected), judge);
25
+ if (!read.Success)
26
+ return { ok: false, message: read.ErrorMessage };
27
+ const threshold = readThreshold(judge.passThreshold);
28
+ if (typeof threshold !== 'number')
29
+ return { ok: false, message: threshold };
30
+ const strict = judge.strictMode === true;
31
+ const used = new Set();
32
+ return {
33
+ ok: true,
34
+ rubric: {
35
+ name: rubricName(input.testName),
36
+ description: `Draft promoted from the inline criteria on ${input.testName}. Not published.`,
37
+ passThreshold: threshold,
38
+ notApplicablePolicy: 'NotAllowed',
39
+ scoreDisplayMin: 0,
40
+ scoreDisplayMax: 1,
41
+ status: 'Draft',
42
+ criteria: read.Value.map((criterion, index) => ({
43
+ key: criterionKey(criterion.Criterion, index, used),
44
+ name: criterion.Criterion.slice(0, 255),
45
+ weight: criterion.Weight,
46
+ isGate: strict,
47
+ gateMinimumScore: strict ? 1 : null,
48
+ sequence: index,
49
+ })),
50
+ },
51
+ };
52
+ }
53
+ /** Writes the draft and points the test at it. The version status is Draft. */
54
+ export async function PromoteInlineCriteria(testId, rubric, store) {
55
+ const rubricId = await store.saveRubric({ name: rubric.name, description: rubric.description });
56
+ const scaleId = await store.ensureBinaryScale();
57
+ const versionId = await store.saveDraftVersion({ ...rubric, rubricId, scaleId, status: 'Draft' });
58
+ await store.setTestRubric(testId, rubricId);
59
+ return { rubricId, versionId };
60
+ }
61
+ function oracleInput(expectedOutput) {
62
+ return {
63
+ test: { InputDefinition: null },
64
+ expectedOutput,
65
+ actualOutput: undefined,
66
+ contextUser: { ID: '' },
67
+ };
68
+ }
69
+ function judgeOracleConfig(configuration) {
70
+ if (!configuration || typeof configuration !== 'object' || !('oracles' in configuration))
71
+ return {};
72
+ const oracles = configuration.oracles;
73
+ if (!Array.isArray(oracles))
74
+ return {};
75
+ const judge = oracles.find(item => item && typeof item === 'object' && item.type === 'llm-judge');
76
+ return judge?.config ?? {};
77
+ }
78
+ function readThreshold(value) {
79
+ if (value === undefined || value === null)
80
+ return 0.7;
81
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > 1) {
82
+ return 'passThreshold must be a number from 0 to 1.';
83
+ }
84
+ return value;
85
+ }
86
+ function rubricName(testName) {
87
+ const base = testName.trim() || 'Inline criteria';
88
+ const name = `${base} rubric`;
89
+ return name.length <= 255 ? name : name.slice(0, 255);
90
+ }
91
+ function criterionKey(text, index, used) {
92
+ const slug = text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
93
+ let key = (slug || `c${index}`).slice(0, 100);
94
+ const base = key;
95
+ let n = 2;
96
+ while (used.has(key)) {
97
+ const suffix = `-${n}`;
98
+ key = `${base.slice(0, 100 - suffix.length)}${suffix}`;
99
+ n += 1;
100
+ }
101
+ used.add(key);
102
+ return key;
103
+ }
104
+ //# sourceMappingURL=promote-criteria.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promote-criteria.js","sourceRoot":"","sources":["../../src/oracles/promote-criteria.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,kFAAkF;AAClF,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAkC1D;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAMnC;IACG,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;QACzB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,gEAAgE,EAAE,CAAC;IACpG,CAAC;IACD,IAAI,QAAQ,GAAY,KAAK,CAAC,gBAAgB,CAAC;IAC/C,IAAI,aAAa,GAAY,KAAK,CAAC,aAAa,CAAC;IACjD,IAAI,CAAC;QACD,IAAI,OAAO,QAAQ,KAAK,QAAQ;YAAE,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACzF,IAAI,OAAO,aAAa,KAAK,QAAQ;YAAE,aAAa,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACjH,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,uDAAuD,EAAE,CAAC;IAC3F,CAAC;IACD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ACvB,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAAC;QACvD,CAAC,IAAI,CAAC,CAAC;IACX,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACd,OAAO,GAAG,CAAC;AACf,CAAC"}
@@ -0,0 +1,69 @@
1
+ /** Which rubric a test run uses. The first source that names one wins. */
2
+ export interface RubricChoice {
3
+ RubricId?: string;
4
+ VersionId?: string;
5
+ /** Set when the caller named a version. That version is not replaced by the suite pin. */
6
+ ExplicitVersion: boolean;
7
+ Source: 'run' | 'oracle' | 'test' | 'suite' | 'agent' | 'none';
8
+ }
9
+ export interface RubricSuiteRow {
10
+ Id: string;
11
+ ParentId?: string | null;
12
+ RubricId?: string | null;
13
+ }
14
+ /**
15
+ * Resolves the rubric for one test. First match wins:
16
+ * run override, the rubric oracle's own config, the test, the suite chain
17
+ * walking up ParentID, then the agent's default Evaluation rubric.
18
+ */
19
+ export declare function ResolveRubric(input: {
20
+ run?: {
21
+ rubricId?: string;
22
+ versionId?: string;
23
+ };
24
+ oracle?: {
25
+ rubricId?: string;
26
+ rubricVersionId?: string;
27
+ };
28
+ testRubricId?: string | null;
29
+ suites?: RubricSuiteRow[];
30
+ suiteId?: string;
31
+ agentRubricId?: string | null;
32
+ }): RubricChoice;
33
+ /**
34
+ * Remembers the published version chosen at the start of a suite run.
35
+ * A later publish does not change the version for that suite run.
36
+ * An explicitly named version is returned and does not replace the pin.
37
+ */
38
+ export declare class PublishedVersionPin {
39
+ private readonly pinned;
40
+ Remember(suiteRunId: string, rubricId: string, explicitVersionId: string | undefined, lookupLatest: () => Promise<string | undefined>): Promise<string | undefined>;
41
+ }
42
+ export interface OracleConfigLike {
43
+ /** Same field as IOracle.type. Test configuration stores it as `type`. */
44
+ type: string;
45
+ config?: Record<string, unknown>;
46
+ }
47
+ /**
48
+ * Pins the resolved rubric onto the oracle list.
49
+ * An llm-judge skips only the agent's own Evaluation rubric (`Source === 'agent'`).
50
+ * A run override, a test rubric, a suite rubric, or a promoted rubric is still pinned.
51
+ * A rubric with no published version is still named. The pin is written after the
52
+ * oracle config, so the config cannot replace the version.
53
+ */
54
+ export declare function EnsureImplicitRubricOracle(oracles: OracleConfigLike[] | undefined, choice: RubricChoice, versionId?: string, versionLabel?: string): OracleConfigLike[];
55
+ /**
56
+ * Adds the rubric named by `--rubric` or `Test.RubricID`, and pins an explicit
57
+ * rubric oracle already on the list. Weights on the existing oracles stay.
58
+ */
59
+ export declare function OraclesWithNamedRubric<T extends OracleConfigLike>(oracles: readonly T[] | undefined, input: {
60
+ runRubricId?: string;
61
+ runVersionId?: string;
62
+ testRubricId?: string | null;
63
+ }): T[];
64
+ /**
65
+ * The implicit rubric always gates status. It contributes to the score when
66
+ * weights are absent, or when the weights already name `rubric`.
67
+ */
68
+ export declare function WeightsForImplicitRubric(weights: Record<string, number> | undefined, addedImplicit: boolean): Record<string, number> | undefined;
69
+ //# sourceMappingURL=rubric-resolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rubric-resolution.d.ts","sourceRoot":"","sources":["../../src/oracles/rubric-resolution.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0FAA0F;IAC1F,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;CAClE;AAED,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,K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