Core
API reference
Every public name in Python and TypeScript, side by side. Same behavior and verdicts, names idiomatic to each language.
Python names are snake_case and keyword-only for options; TypeScript names are camelCase with an options object. Wire keys (event fields, schema fields, matcher operators) are snake_case in both.
Main entry: viewportai.core / @viewportai/core
| Concept | Python | TypeScript |
|---|---|---|
| Trajectory models | Trajectory, AgentEvent, ModelCallEvent, ToolCallEvent, ApprovalEvent, SkillLoadEvent, SkillUnloadEvent, ContextAssemblyEvent, HandoffEvent, MessageEvent, UnknownEvent, Event, Usage, ErrorInfo, Budget, ToolDescriptor (pydantic, to_dict(), to_json()) | same names as types |
| Reading trajectories | trj.tool_calls(name=None), trj.model_calls(), trj.events_of(type), trj.summarize(); free functions tool_calls, model_calls, events_of, summarize | toolCalls(trj, name?), modelCalls(trj), eventsOf(trj, type), summarize(trj) |
| Budgets and ranges | check_budget(budget, actuals), BudgetCheck, in_range, format_range, range_issues, Range | checkBudget, BudgetCheck, inRange, formatRange, rangeIssues, Range |
| Matcher | match(spec, value), amatch(spec, value, judge=), compile_matcher(spec, at=, operators=, file=) -> CompiledMatcher(match, amatch, uses_judge, spec), MATCHER_OPERATORS, glob_to_regex, MISSING (the value is absent; TS uses undefined) | match, matchAsync(spec, value, { judge, signal }), compileMatcher(spec, { at, operators, file }) -> CompiledMatcher { match, matchAsync, usesJudge, spec }, MATCHER_OPERATORS, globToRegex |
| Match outcome | MatchResult(status, failures), .passed, .message, truthy only on pass; MatchFailure(path, status, operator, message); MatchStatus | MatchResult { status, passed, failures, message }, MatchFailure, MatchStatus |
| Judges | Judge, JudgeRequest, JudgeVerdict | Judge, JudgeRequest, JudgeVerdict |
| JSONPath subset | query_path, query_path_nodes, parse_path, format_path, join_path, PathNode, PathSegment | queryPath, queryPathNodes, parsePath, formatPath, joinPath, PathNode, PathSegment |
| Errors | ViewportError(code, message, details=), SpecError(issues, code=, subject=), SpecIssue, format_issue | ViewportError, SpecError, SpecIssue, formatIssue |
| Durations | parse_duration("30s"), format_duration(ms) | parseDuration, formatDuration |
| Ids and time | new_id(prefix), UlidIds(clock=, random=), IdGenerator, Clock (now(), async sleep(ms), cancelled with its task), SYSTEM_CLOCK, iso_timestamp, round_ms | newId, UlidIds, IdGenerator, Clock (now(), sleep(ms, signal?)), systemClock, isoTimestamp |
| JSON | stable_json(value, indent=), canonical_json, canonical_digest(value, prev), jcs, jcs_digest, deep_equal, format_number, format_value, parse_json, to_json_value | stableJson(value, { indent }), canonicalJson, canonicalDigest, jcs, jcsDigest, deepEqual, formatNumber, formatValue, parseJson |
| Text | fold_case, code_point_length, did_you_mean, edit_distance | foldCase, codePointLength, didYouMean, editDistance |
| Tools | Tool(...), @tool (an async def gives an awaitable FunctionTool; a plain def gives a SyncFunctionTool that returns its value when called; on the main thread with no loop it runs on a fresh loop, anywhere else in place, and it raises core.tool_sync_in_loop only when a middleware declared loop_bound=True is on it), ToolContext(call_id, sink, attributes), ToolMiddleware, wrap_tool, compose, @tool_middleware (loop_bound=True for a middleware that waits on the event loop), ToolCall (args, context, await call.revalidate(args), call.mask(jsonpaths)), ToolNext, execute_sync(tool, args) | defineTool, Tool, ToolContext { callId, signal, sink, attributes }, ToolMiddleware, wrapTool, compose, toolMiddleware, ToolCall (args, context, await call.revalidate(args), call.mask(jsonpaths)), ToolNext |
| Sink | emit(event, sink=), with_sink(sink) (context manager), span(event, sink=) (sync or async context manager), SpanHandle, Sink, SinkLike, has_sink, current_clock, current_ids, current_span_id | emit, withSink(sink, fn), span(event, fn), SpanHandle, Sink, SinkLike, hasSink, currentClock, currentIds, currentSpanId |
| Recording | trace(input=, attributes=, clock=, ids=) -> Trace(events, output, trajectory), TrajectoryRecorder, to_error_info, TRAJECTORY_SCHEMA_URL | trace(fn, options) -> { result, events, trajectory }, TrajectoryRecorder, toErrorInfo, TRAJECTORY_SCHEMA_URL |
Submodules
| Python | TypeScript | Contents |
|---|---|---|
viewportai.core.schema | @viewportai/core/schema | validate(id, value, at=, source=, file=), parse(...), define_validator / defineValidator, VALIDATORS / validators, SCHEMAS / schemas, finish, SpecSource |
viewportai.core.yaml | @viewportai/core/yaml | load_yaml(text, file=) / loadYaml(text, { file }) -> YamlDocument(value, file, locate(path, part)), SourcePosition, MAX_ALIAS_NODES, MAX_DEPTH. Strict: no tabs (write \t in a double-quoted value), no bare CR, no control or line-separator characters, flow nesting at most 256 |
viewportai.core.invariants | @viewportai/core/invariants | parse_invariants / parseInvariants, ParsedInvariant, APPROVAL_STATUSES, INVARIANT_SCOPES, INVARIANT_KINDS; schema invariant/v1 |
viewportai.core.testing | @viewportai/core/testing | FakeClock (advance, set, sleep, pending), SequentialIds, FAKE_EPOCH, collect, trajectory builder, normalize, fake_tool / fakeTool |
(pytest: plain assert) | @viewportai/core/vitest | matchers with toMatchSpec |
Schema validation lives in a subpath in both languages so the main TypeScript bundle stays small (its budget, checked by make size, is 68 KB minified).