Schemas
The JSON Schemas core owns, where they live, and how authored and machine documents differ.
Schemas are JSON Schema draft 2020-12, hand-written in spec/schemas/<path>/v<N>.json, with $id
https://getviewport.com/schemas/<path>/v<N>.json. Within a major version they change additively only.
| Id | Kind | What it describes |
|---|---|---|
trajectory/v1 | machine record (open) | a run: input, output, error, attributes, events |
matcher/v1 | authored (strict) | the Matcher language |
range/v1 | authored (strict) | a count: N or { min, max } |
budget/v1 | authored (strict) | resource limits: tokens, input_tokens, output_tokens, cost_usd, latency_ms |
tool/v1 | authored (strict) | the serializable part of a Tool |
Authored documents are strict: an unknown key is an error with a did-you-mean. Machine records are open: a trajectory from a newer writer with extra fields or new event types validates, and the extras survive a round trip.
TypeScript types, ajv standalone validators (no runtime code generation, so they run on Cloudflare Workers and
Vercel Edge) and pydantic v2 models are generated from these files by scripts/codegen.mjs and committed. The schema
files ship in both packages: @viewportai/core/schemas/trajectory/v1.json and, in Python, viewportai.core.schema.SCHEMAS.
from viewportai.core import stable_json
from viewportai.core.schema import validate
issues = validate("budget/v1", {"tokns": 1000, "cost_usd": -1})
print(
stable_json([[i.path, i.code, i.suggestion] for i in issues])
) # [["cost_usd","minimum",null],["tokns","unknown_key","tokens"]]import { stableJson } from "@viewportai/core";
import { validate } from "@viewportai/core/schema";
const issues = validate("budget/v1", { tokns: 1000, cost_usd: -1 });
console.log(stableJson(issues.map((i) => [i.path, i.code, i.suggestion ?? null]))); // [["cost_usd","minimum",null],["tokns","unknown_key","tokens"]]