/** * @octomil/browser — Built-in output quality gate evaluators * * Each evaluator implements the `OutputQualityEvaluator` interface defined in * `attempt-runner.ts` and returns an `EvaluatorResult`. Evaluators run * **in the browser process** — no prompt/output content is uploaded. * * Built-in evaluators: * - `JsonParseableEvaluator` — checks that output parses as JSON * - `JsonSchemaEvaluator` — validates output against a JSON Schema (lightweight structural check) * - `ToolCallValidEvaluator` — validates tool-call structure * - `RegexPredicateEvaluator` — matches output against a regex pattern * - `SafetyPassedEvaluator` — adapter stub for app-provided safety check */ import type { CandidateGate, OutputQualityEvaluator } from "./attempt-runner.js"; /** * Privacy-safe result from an output quality evaluator. * * `safe_metadata` is sanitized by the forbidden-key filter before * inclusion in telemetry — no prompt, output, or content fields may survive. */ export interface EvaluatorResult { passed: boolean; score?: number; reason_code?: string; safe_metadata?: Record; } /** * Extract text content from a response object. * * Supports: string, object with `text`/`content`/`output` key. */ export declare function extractText(response: unknown): string | null; /** * Extract tool_calls array from a response object. * * Supports: object with `tool_calls` key. * Returns null if no tool calls are present. */ export declare function extractToolCalls(response: unknown): Array> | null; /** * Checks that the response text is valid JSON. * * Maps to gate code `json_parseable`. */ export declare class JsonParseableEvaluator implements OutputQualityEvaluator { readonly name = "json_parseable"; evaluate(input: { request: unknown; response: unknown; gate: CandidateGate; }): Promise; } /** * Validates the response text against a JSON Schema. * * The schema is taken from `gate.config.schema` (if present) or from the * `defaultSchema` provided at construction time. * * Uses a lightweight structural validator by default (type, required, * properties, items, enum). For full JSON Schema validation, register * an Ajv-backed evaluator instead. * * Maps to gate code `schema_valid`. */ export declare class JsonSchemaEvaluator implements OutputQualityEvaluator { readonly name = "json_schema"; private readonly _defaultSchema; private readonly _validate; constructor(opts?: { defaultSchema?: Record | null; validate?: (data: unknown, schema: Record) => { valid: boolean; errorPath?: string; errorMessage?: string; }; }); evaluate(input: { request: unknown; response: unknown; gate: CandidateGate; }): Promise; } /** * Validates that tool calls in the response have the required structure. * * Checks that each tool call has `name` and `arguments` fields and * that `arguments` is valid JSON (if it is a string). * * Maps to gate code `tool_call_valid`. */ export declare class ToolCallValidEvaluator implements OutputQualityEvaluator { readonly name = "tool_call_valid"; evaluate(input: { request: unknown; response: unknown; gate: CandidateGate; }): Promise; } /** * Matches the response text against a regex pattern. * * The pattern is taken from `gate.config.pattern` or `gate.threshold_string`, * or provided at construction time. A match anywhere in the text passes. * * Maps to gate code `evaluator_score_min` or custom codes. */ export declare class RegexPredicateEvaluator implements OutputQualityEvaluator { readonly name = "regex_predicate"; private readonly _defaultPattern; constructor(opts?: { defaultPattern?: string | null; }); evaluate(input: { request: unknown; response: unknown; gate: CandidateGate; }): Promise; } /** Callback type for safety checks. */ export type SafetyCheckFn = (response: unknown) => boolean | EvaluatorResult | Promise; /** * Adapter stub for app-provided safety evaluation. * * This evaluator does NOT implement a classifier itself. It delegates to * an app-provided `check` callback. If no callback is provided, it fails * closed so required `safety_passed` gates cannot accidentally pass. * * Maps to gate code `safety_passed`. */ export declare class SafetyPassedEvaluator implements OutputQualityEvaluator { readonly name = "safety_passed"; private readonly _check; constructor(opts?: { check?: SafetyCheckFn | null; }); evaluate(input: { request: unknown; response: unknown; gate: CandidateGate; }): Promise; } /** Interface for individual gate evaluators stored in the registry. */ export interface GateEvaluator { readonly name: string; evaluate(input: { gate: CandidateGate; response: unknown; }): EvaluatorResult | Promise; } /** * Maps gate codes to evaluator instances. * * Default built-in evaluators are registered automatically via * `EvaluatorRegistry.withDefaults()`. Apps can override or extend * by calling `register()` after construction. */ export declare class EvaluatorRegistry { private readonly _evaluators; /** Register an evaluator for a gate code. */ register(gateCode: string, evaluator: GateEvaluator): void; /** Get the evaluator for a gate code, or undefined. */ get(gateCode: string): GateEvaluator | undefined; /** Create a registry with built-in evaluators pre-registered. */ static withDefaults(opts?: { jsonSchema?: Record | null; safetyCheck?: SafetyCheckFn | null; regexPattern?: string | null; extra?: Record; }): EvaluatorRegistry; } /** * Bridges an `EvaluatorRegistry` into the single `OutputQualityEvaluator` * interface expected by `BrowserAttemptRunner`. * * When `evaluateOutputQualityGates` calls this evaluator, it dispatches * to the registry by `gate.code`. */ export declare class RegistryBackedEvaluator implements OutputQualityEvaluator { readonly name = "registry"; private readonly _registry; constructor(registry: EvaluatorRegistry); evaluate(input: { request: unknown; response: unknown; gate: CandidateGate; }): Promise; } //# sourceMappingURL=evaluators.d.ts.map