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

Function declaredPrimitiveCheck

src/compiled/cognition/validate.ts:46–63  ·  view source on GitHub ↗

True when the declared type is a recognised primitive.

(declared: string, value: unknown)

Source from the content-addressed store, hash-verified

44
45/** True when the declared type is a recognised primitive. */
46function declaredPrimitiveCheck(declared: string, value: unknown): string | null {
47 switch (declared) {
48 case "string":
49 if (typeof value !== "string") return `expected string, got ${typeof value}`;
50 return value.length === 0 ? "empty string" : null;
51 case "int": case "uint": case "float":
52 if (typeof value !== "number" || !Number.isFinite(value)) return `expected number, got ${typeof value}`;
53 if (declared === "uint" && value < 0) return "expected uint, got negative";
54 if (declared === "int" && !Number.isInteger(value)) return "expected int, got non-integer";
55 return null;
56 case "bool":
57 return typeof value === "boolean" ? null : `expected bool, got ${typeof value}`;
58 case "json":
59 return null;
60 default:
61 return null;
62 }
63}
64
65/**
66 * Validate a parsed model output against the prompt's declared return type.

Callers 1

validateSchemaOnlyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected