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

ConceptPythonTypeScript
Trajectory modelsTrajectory, 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 trajectoriestrj.tool_calls(name=None), trj.model_calls(), trj.events_of(type), trj.summarize(); free functions tool_calls, model_calls, events_of, summarizetoolCalls(trj, name?), modelCalls(trj), eventsOf(trj, type), summarize(trj)
Budgets and rangescheck_budget(budget, actuals), BudgetCheck, in_range, format_range, range_issues, RangecheckBudget, BudgetCheck, inRange, formatRange, rangeIssues, Range
Matchermatch(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 outcomeMatchResult(status, failures), .passed, .message, truthy only on pass; MatchFailure(path, status, operator, message); MatchStatusMatchResult { status, passed, failures, message }, MatchFailure, MatchStatus
JudgesJudge, JudgeRequest, JudgeVerdictJudge, JudgeRequest, JudgeVerdict
JSONPath subsetquery_path, query_path_nodes, parse_path, format_path, join_path, PathNode, PathSegmentqueryPath, queryPathNodes, parsePath, formatPath, joinPath, PathNode, PathSegment
ErrorsViewportError(code, message, details=), SpecError(issues, code=, subject=), SpecIssue, format_issueViewportError, SpecError, SpecIssue, formatIssue
Durationsparse_duration("30s"), format_duration(ms)parseDuration, formatDuration
Ids and timenew_id(prefix), UlidIds(clock=, random=), IdGenerator, Clock (now(), async sleep(ms), cancelled with its task), SYSTEM_CLOCK, iso_timestamp, round_msnewId, UlidIds, IdGenerator, Clock (now(), sleep(ms, signal?)), systemClock, isoTimestamp
JSONstable_json(value, indent=), canonical_json, canonical_digest(value, prev), jcs, jcs_digest, deep_equal, format_number, format_value, parse_json, to_json_valuestableJson(value, { indent }), canonicalJson, canonicalDigest, jcs, jcsDigest, deepEqual, formatNumber, formatValue, parseJson
Textfold_case, code_point_length, did_you_mean, edit_distancefoldCase, codePointLength, didYouMean, editDistance
ToolsTool(...), @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
Sinkemit(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_idemit, withSink(sink, fn), span(event, fn), SpanHandle, Sink, SinkLike, hasSink, currentClock, currentIds, currentSpanId
Recordingtrace(input=, attributes=, clock=, ids=) -> Trace(events, output, trajectory), TrajectoryRecorder, to_error_info, TRAJECTORY_SCHEMA_URLtrace(fn, options) -> { result, events, trajectory }, TrajectoryRecorder, toErrorInfo, TRAJECTORY_SCHEMA_URL

Submodules

PythonTypeScriptContents
viewportai.core.schema@viewportai/core/schemavalidate(id, value, at=, source=, file=), parse(...), define_validator / defineValidator, VALIDATORS / validators, SCHEMAS / schemas, finish, SpecSource
viewportai.core.yaml@viewportai/core/yamlload_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/invariantsparse_invariants / parseInvariants, ParsedInvariant, APPROVAL_STATUSES, INVARIANT_SCOPES, INVARIANT_KINDS; schema invariant/v1
viewportai.core.testing@viewportai/core/testingFakeClock (advance, set, sleep, pending), SequentialIds, FAKE_EPOCH, collect, trajectory builder, normalize, fake_tool / fakeTool
(pytest: plain assert)@viewportai/core/vitestmatchers 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).

On this page