True when the declared type is a recognised primitive.
(declared, value)
| 52 | } |
| 53 | /** True when the declared type is a recognised primitive. */ |
| 54 | function 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", |
no outgoing calls
no test coverage detected