import type { GraderResult, Trajectory } from "../index.js"; import type { ToolCallEvent, TrajectoryEvent } from "../trajectory/types.js"; /** * Every assistant message in trajectory order. * * The `transcript-*` graders use this to assert against the whole conversation. */ export declare function getAssistantMessages(trajectory: Trajectory): string[]; /** * Failure returned when a negated `transcript-*` grader runs against a * trajectory with no assistant messages. Without this guard an empty transcript * would vacuously satisfy "not contains"/"not matches" checks, even though the * agent never produced any output to inspect. */ export declare function noAssistantMessagesResult(name: string, metadata?: Record): GraderResult; /** * True if any of `texts` contains `substring`. Case-insensitive unless * `caseSensitive` is set. Shared by the `*-contains` graders. */ export declare function anyContains(texts: string[], substring: string, caseSensitive?: boolean): boolean; /** * Compile `pattern` and test it against `texts`. Returns `ok: false` with the * compilation error message when the pattern is invalid. Shared by the * `*-matches` graders. */ export declare function anyMatches(texts: string[], pattern: string): { ok: true; found: boolean; } | { ok: false; error: string; }; /** Exact tool-name match, or a `name.`-prefixed (namespaced) variant. */ export declare function toolNameMatches(toolName: string, targets: readonly string[]): boolean; /** Render a tool result as the string a capture pattern runs against. */ export declare function toolResultText(result: unknown): string; /** A value captured from a tool output, tagged with the event index it came from. */ export interface CapturedToolOutput { value: string; index: number; } /** * Capture values from `tool_result` outputs selected by `matchTool` and matched * by `pattern`. When the pattern has a capture group, group 1 is used; otherwise * the full match. Empty captures (e.g. an unmatched optional group) are skipped. * The event index is retained so callers can require an echo to come *after* the * capture. */ export declare function captureToolOutputs(events: readonly TrajectoryEvent[], matchTool: (toolName: string) => boolean, pattern: RegExp): CapturedToolOutput[]; /** * True if some `assistant_message` after `afterIndex` contains `value` as a * case-sensitive substring. Non-string assistant content is ignored. */ export declare function assistantEchoesAfter(events: readonly TrajectoryEvent[], afterIndex: number, value: string): boolean; /** Repeated-pattern result, including the legacy consecutive-repeat result. */ export interface RepeatedStepsResult { /** Longest run of consecutive identical, non-empty step fingerprints. */ maxConsecutive: number; /** Comma-joined tool name(s) of the repeated consecutive step. */ repeatedTool: string; /** The repeated consecutive step fingerprint. */ repeatedKey: string; /** Greatest number of complete occurrences of any action/pattern (0 when no watched steps). */ maxOccurrences: number; /** Period of the repeated pattern, or null when no pattern repeats. */ detectedPeriod: number | null; /** Ordered fingerprints forming one occurrence of the repeated pattern. */ repeatedPattern: string[]; /** Comma-joined tool name(s) in the repeated pattern. */ repeatedPatternTools: string; } /** Default preview length cap for repeated-step fingerprints surfaced in evidence/metadata. */ export declare const FINGERPRINT_PREVIEW_MAX = 120; /** Truncate `s` to `max` chars, appending an ellipsis when it overflows. */ export declare function truncateFingerprint(s: string, max?: number): string; /** * Validate a required, finite integer `>= min` config value. Error messages are * prefixed with `grader` and `field` so each call site reports its own name. * Shared by graders that take a mandatory integer threshold — authors must opt * in rather than inherit a silent default that quietly decides pass/fail. */ export declare function resolveRequiredInteger(raw: unknown, grader: string, field: string, min: number): number; /** Largest pattern period accepted by the built-in loop graders. */ export declare const MAX_CYCLE_PERIOD = 10; /** Resolve an optional bounded pattern period, defaulting to consecutive-only detection. */ export declare function resolveMaxCyclePeriod(raw: unknown, grader: string): number; /** How two calls are compared to decide whether they are "the same" repeated action. */ export type MatchMode = "observation" | "name" | "name-args"; /** * Validate a `match` config value, falling back to `defaultMode` when omitted. * `grader` prefixes the error message so each grader reports its own name. */ export declare function resolveMatchMode(raw: unknown, grader: string, defaultMode: MatchMode): MatchMode; /** Map (agentId, toolCallId) -> result for the most recent matching tool_result. */ export declare function buildResultIndex(events: TrajectoryEvent[]): Map; /** * Fingerprint component for a single watched tool_call under `match`. An empty * string means "included in the step but contributes no fingerprint" (see * {@link longestRepeatedStepPatterns}); `observation` mode returns it when * the call has no usable result. `observation` mode requires `resultsById` * (build it with {@link buildResultIndex}). */ export declare function fingerprintComponent(match: MatchMode, event: ToolCallEvent, resultsById: Map): string; /** * Detect complete repeated patterns over the `watch`-selected tools, compared * under `match`. The default period of one preserves consecutive-repeat * detection for existing callers. */ export declare function detectRepeatedPatterns(events: TrajectoryEvent[], match: MatchMode, watch: (toolName: string) => boolean, maxCyclePeriod?: number): RepeatedStepsResult; /** * Render one step fingerprint in a readable form. A step can contain multiple * parallel calls, joined internally with NUL, so callers that render a cycle * must retain the outer array of step fingerprints. */ export declare function formatRepeatedAction(key: string, match: MatchMode): string; /** Render the ordered steps of one repeated pattern without losing step boundaries. */ export declare function formatRepeatedPattern(pattern: string[], match: MatchMode): string; /** * Build a predicate selecting which entries are watched. When `tools` is * omitted, all entries are watched. An empty array or an empty/`(?:)` pattern is a * config mistake (it would silently watch nothing / everything) and is rejected. * `grader` prefixes error messages so each grader reports its own name; `noun` * names what a pattern matches against (defaults to `"tool"` — `step-count` * passes `"step"` since its patterns match step names, not just tool names). */ export declare function resolveWatchedTools(tools: unknown, grader: string, noun?: string): (toolName: string) => boolean; /** * Deterministic JSON serialization with recursively sorted object keys and a * circular-reference guard. Tool arguments/results may be any JSON-like or loosely * typed value, so this stays defensive against odd values. */ export declare function stableStringify(value: unknown): string; //# sourceMappingURL=helpers.d.ts.map