Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(ts): reject a null score level, as the Python agent does

Rishit Sharma8aee9906676d
diff --git a/laya-ts/src/agent.ts b/laya-ts/src/agent.ts
index 294b7ad7..bd4b79d0 100644
--- a/laya-ts/src/agent.ts
+++ b/laya-ts/src/agent.ts
@@ -142,6 +142,12 @@ export function checkQuestion(qid: string, qdef: unknown): void {
if (crit.length === 0) {
throw new Error(`question ${qidStr(qid)}: a score question needs at least one level`);
}
+ const nullAt = crit.findIndex((c) => c === null || c === undefined);
+ if (nullAt >= 0) {
+ throw new Error(
+ `question ${qidStr(qid)}: score level ${nullAt} is null; give every level a description, index 0 first`,
+ );
+ }
} else if (crit !== undefined && crit !== null && (typeof crit !== "object" || Array.isArray(crit))) {
throw new Error(
`question ${qidStr(qid)}: a noul question takes 'criteria' as a dict with optional 'true'/'false' descriptions, or omits it`,
diff --git a/laya-ts/tests/audit-regressions.test.ts b/laya-ts/tests/audit-regressions.test.ts
index fb3120c6..041cf7cb 100644
--- a/laya-ts/tests/audit-regressions.test.ts
+++ b/laya-ts/tests/audit-regressions.test.ts
@@ -53,6 +53,11 @@ describe("audit regressions", () => {
expect(() => checkQuestion("q", { type: "choice", instructions: "?", criteria: ["yes"], labels: { false: "No", true: "Yes" } })).toThrow("labels");
});
+ it("rejects a null score level, as Python does (#302)", () => {
+ expect(() => checkQuestion("q", { type: "score", instructions: "?", criteria: ["low", null, "high"] })).toThrow("level 1");
+ expect(() => checkQuestion("q", { type: "score", instructions: "?", criteria: ["low", "mid", undefined] })).toThrow("level 2");
+ });
+
it("rejects malformed provider output", async () => {
const agent = new Agent({ provider: {
async runEncoder(_batch: any) { return { lastHidden: [[[0, 0]]] }; },