@parcha/agentrun-dsl 0.1.0-beta.4 → 0.1.0-beta.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/README.md +1 -1
- package/dist/system-one.js +17 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Composable, typed workflows for agents. The core provides the v2 workflow types, validator, interpreter, events, schema, and an offline CLI. Supply agent, judgment, and effect functions only when a workflow needs them.
|
|
4
4
|
|
|
5
|
-
Beta: `0.1.0-beta.
|
|
5
|
+
Beta: `0.1.0-beta.4`. Requires Node 22.19+; TypeScript consumers require TypeScript 5.4+.
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
npm install @parcha/agentrun-dsl@beta
|
package/dist/system-one.js
CHANGED
|
@@ -150,6 +150,22 @@ export class SystemOneError extends Error {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
const unit = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 1;
|
|
153
|
+
// System One reports probabilities rounded to two places, so the reported sum drifts from 1 by up to
|
|
154
|
+
// half a step per option (3 × 0.33 = 0.99; 8 × 0.13 = 1.04). A distribution is accepted when it could
|
|
155
|
+
// be that rounding of one summing to 1: a value on the two-place grid may be off by ±0.005 (within
|
|
156
|
+
// [0, 1]); any other value is taken as exact. With no grid values this is |sum − 1| ≤ 1e-5, the
|
|
157
|
+
// check for full-precision distributions. Answers are accepted as reported, never rescaled.
|
|
158
|
+
const ROUNDING_HALF_STEP = 0.005;
|
|
159
|
+
const onTwoPlaceGrid = (p) => Math.abs(p * 100 - Math.round(p * 100)) < 1e-9;
|
|
160
|
+
function roundedFromUnitMass(probabilities) {
|
|
161
|
+
let low = 0, high = 0;
|
|
162
|
+
for (const p of probabilities) {
|
|
163
|
+
const step = onTwoPlaceGrid(p) ? ROUNDING_HALF_STEP : 0;
|
|
164
|
+
low += Math.max(0, p - step);
|
|
165
|
+
high += Math.min(1, p + step);
|
|
166
|
+
}
|
|
167
|
+
return low <= 1 + 1e-5 && high >= 1 - 1e-5;
|
|
168
|
+
}
|
|
153
169
|
export function validateAnswers(questions, answers) {
|
|
154
170
|
if (!answers || typeof answers !== "object" || Array.isArray(answers))
|
|
155
171
|
throw new SystemOneError("System One response carries no answers", null, undefined, "answers_shape");
|
|
@@ -175,8 +191,7 @@ export function validateAnswers(questions, answers) {
|
|
|
175
191
|
const probabilityKeys = Object.keys(a.probabilities);
|
|
176
192
|
if (Array.isArray(a.probabilities) || probabilityKeys.length !== expectedKeys.length || expectedKeys.some(key => !Object.hasOwn(a.probabilities, key)))
|
|
177
193
|
throw new SystemOneError("System One answer: probabilities must contain exactly the declared options", null, undefined, "probability_keys");
|
|
178
|
-
|
|
179
|
-
if (Math.abs(mass - 1) > 1e-5)
|
|
194
|
+
if (!roundedFromUnitMass(Object.values(a.probabilities)))
|
|
180
195
|
throw new SystemOneError("System One answer: probabilities must sum to 1", null, undefined, "probability_mass");
|
|
181
196
|
if (q.type === "score") {
|
|
182
197
|
if (!a.legend || typeof a.legend !== "object" || Array.isArray(a.legend) || Object.keys(a.legend).length !== expectedKeys.length || q.criteria.some((text, index) => a.legend[String(index)] !== text))
|