@replayci/contracts-core
v0.1.2
Published
Shared contract and provider utilities for the ReplayCI SDK.
Maintainers
Readme
@replayci/contracts-core
Shared contract types, parsing, evaluation, and provider utilities for the ReplayCI SDK.
Installation
npm install @replayci/contracts-coreWhat's Inside
- Contract types —
Contract,ContractInvariant,ExpectedToolCall, and related types - YAML parsing —
loadContract()/loadContractSync()for loading contract YAML files - Invariant evaluation —
evaluateInvariants()with 18 operators (equals, contains, regex, exists, type, one_of, gte, lte, length_gte, length_lte, and more) - Tool call matching —
evaluateExpectedToolCalls()with consuming multiset matching, tool order enforcement, and pass thresholds - Argument validation —
validateToolArguments()with recursive schema validation (numeric range, string length, array size, regex pattern) - Provider normalization —
normalizeToolArray()/normalizeToolDefinition()for OpenAI and Anthropic tool schema formats - Fingerprinting —
computeResponseShapeHash()for structure-only response hashing - Hashing —
hashToolSchema()/hashMessages()for content-addressed deduplication
Usage
import {
loadContractSync,
evaluateInvariants,
evaluateExpectedToolCalls,
} from "@replayci/contracts-core";
const contract = loadContractSync("./contracts/weather.yaml");
const failures = evaluateInvariants(contract.output_invariants, response);
if (failures.length > 0) {
console.error("Contract violations:", failures);
}Docs
Full documentation at docs.replayci.com.
