TheDocumentation Index
Fetch the complete documentation index at: https://docs.pecta.ai/llms.txt
Use this file to discover all available pages before exploring further.
@pecta/core SDK runs quality gates entirely inside your Node.js process. There is no network call on the hot path: gates execute in parallel, the engine returns a result object, and telemetry ships to Pecta cloud asynchronously in a background batch. This makes the SDK the right choice for latency-critical workloads such as RTB pipelines, where you need a gate decision in under 15 ms.
Create an engine
Call
createEngine once — typically at module initialisation — and reuse the engine for every request. Engines are stateless and safe to share across async calls.timeout is the wall-clock budget shared across all gates. If the budget is exhausted the engine aborts remaining work and marks those gates as failed.Evaluate an agent output
Call
engine.evaluate() with an EvaluationContext after your agent returns a result. The call is async and resolves in the time it takes all gates to run (bounded by timeout).Check the result
result.passed is true only when every gate passes (or is explicitly skipped). Inspect result.gates to see which gates blocked the output and why.EvaluationResult shape:Send telemetry
Instantiate Telemetry flushes automatically every 5 seconds or when 100 events accumulate. Call
PectaTelemetry with your publishable key and call telemetry.track(result) after every evaluation. The call is synchronous and non-blocking — it adds the result to an in-memory buffer and returns immediately.shutdown() before your process exits to drain any remaining buffer.sampleRate controls the fraction of evaluations that are POSTed to the cloud. It does not affect local gate execution or which evaluations feed into reputation scoring — all evaluations are counted locally regardless of sample rate.RTB / OpenRTB example
For programmatic advertising pipelines, use the RTB gate suite. Pass the originalopenRtbRequest as input and the bidder response as output, then add tmaxMs and startedAt so the tmaxGuard gate can skip downstream checks when the deadline is already exhausted.
Writing a custom gate
A gate is any object with aname string and a run function. The engine provides an AbortSignal — check it at the start of long operations to respect fail-fast and timeout behaviour.
run returns { passed: boolean, reason?: string, skipped?: boolean, details?: unknown }. The engine fills in name and latency_ms automatically.