MCPcopy
hub / github.com/Doorman11991/smallcode / declaredPrimitiveCheck

Function declaredPrimitiveCheck

src/compiled/cognition/validate.js:54–77  ·  view source on GitHub ↗

True when the declared type is a recognised primitive.

(declared, value)

Source from the content-addressed store, hash-verified

52}
53/** True when the declared type is a recognised primitive. */
54function declaredPrimitiveCheck(declared, value) {
55 switch (declared) {
56 case "string":
57 if (typeof value !== "string")
58 return `expected string, got ${typeof value}`;
59 return value.length === 0 ? "empty string" : null;
60 case "int":
61 case "uint":
62 case "float":
63 if (typeof value !== "number" || !Number.isFinite(value))
64 return `expected number, got ${typeof value}`;
65 if (declared === "uint" && value < 0)
66 return "expected uint, got negative";
67 if (declared === "int" && !Number.isInteger(value))
68 return "expected int, got non-integer";
69 return null;
70 case "bool":
71 return typeof value === "boolean" ? null : `expected bool, got ${typeof value}`;
72 case "json":
73 return null;
74 default:
75 return null;
76 }
77}
78/**
79 * Validate a parsed model output against the prompt's declared return type.
80 * `outputType` is the IR-serialised type expression, e.g. "string",

Callers 1

validateSchemaOnlyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected