@lucentive-labs/loupe-schema
The Zod config contract a human or agent fills — Config, parseConfig, toJsonSchema, validateConfig.
The single source of truth for what a Loupe config is. Zod is canonical; TypeScript types are inferred from it, and toJsonSchema() emits the contract an agent fills. Everything downstream consumes these types — nothing redefines the shape.
Functions
parseConfig(input: unknown): Config
Structural parse. Runs the Zod schema and throws a ZodError on any structural problem — wrong version, missing required fields, a crop rect with zero area or out of bounds. Returns a fully-typed Config (with defaults like assets: {} applied) on success.
validateConfig(cfg: Config): string[]
Semantic validation beyond structure. Takes an already-parsed Config and returns an array of human-readable error strings — empty means valid. It catches what types cannot:
- duplicate group ids, and duplicate option ids within a group;
- options whose specimen references an
assetkey not present inconfig.assets; - preview bands (and
headlineFrom) that point at a missing group.
Use both, in order: parseConfig first (structure), then validateConfig (references). The generator runs exactly this pair before building, and the interactive tutorial runs it on every render.
toJsonSchema(): Record<string, unknown>
Emits the JSON Schema for the Config, pinned to input mode — the shape an author writes, before defaults are applied. This is the contract you hand an agent so it can fill a config without writing TypeScript.
See the agent method for the JSON-Schema-as-contract workflow.
The Config type
Inferred from the Zod schema. The full shape:
| Field | Type | Notes |
|---|---|---|
version | 1 | literal |
title | string? | shown in header + brief |
assets | Record<string, Asset> | defaults to {} |
theme | ThemeTokens? | --loupe-* tokens (no prefix) |
groups | Group[] | at least 1 |
preview | Preview? | band → slot mapping |
banned | string[]? | flows into the brief |
notes | string[]? | author notes |
workflow | string[]? | flows into the brief |
Nested shapes
Exported schemas + types
The package exports both the Zod schemas (for composition) and the inferred types:
| Export | Kind |
|---|---|
Config, Group, Option, Specimen, Asset, Rect, Preview | Zod schema and inferred type |
MotionPreset, LayoutPlan, ThemeTokens | Zod schema |
TGroup, TOption, TSpecimen, TSpecimenKind, TRect, TAsset, TPreview, TThemeTokens, TMotionPreset, TLayoutPlan | inferred types |
ThemeTokens is z.record(z.string(), z.string()) — any kebab key (without the --loupe- prefix) mapped to any CSS value. See Theming.