/**
 * Stream Monitor — callback-based early exit and repetition detection.
 *
 * Adapted from agent-zero's streaming callback pattern.  Instead of
 * relying solely on model stop tokens (which may be ignored or lost),
 * the monitor watches the streaming output in real-time and signals
 * when to stop.
 *
 * Two detection modes:
 * 1. Tool JSON detection — stops when a complete tool call JSON block
 *    is found in the accumulated stream (for models without native
 *    structured tool calls, like Gemma).
 * 2. Repetition detection — stops when the same block of text appears
 *    twice, indicating a looping cascade.
 *
 * @module
 */
import type { ModelProfile } from "../config/model-profiles.js";
export interface StreamMonitor {
    /** Process a new text delta.  Call on each streaming chunk. */
    onChunk(delta: string): void;
    /** Returns true if the monitor thinks generation should stop. */
    shouldStop(): boolean;
    /** Get the accumulated text so far. */
    getAccumulated(): string;
    /** Get the reason for stop signal (for logging). */
    getStopReason(): string | undefined;
    /** Reset state for a new generation turn. */
    reset(): void;
}
export interface StreamMonitorOptions {
    /** Enable tool JSON detection (for models without structured tool calls). */
    detectToolJson?: boolean;
    /** Enable repetition cascade detection. */
    detectRepetition?: boolean;
    /** Minimum block size (chars) for repetition detection. Default: 150. */
    repetitionMinBlockSize?: number;
}
/**
 * Create a stream monitor configured for the given model profile.
 *
 * - Claude (hasStructuredThinking: true): repetition detection only
 * - Gemma/vLLM (hasStructuredThinking: false): tool JSON + repetition detection
 */
export declare function createStreamMonitor(profile: ModelProfile, overrides?: StreamMonitorOptions): StreamMonitor;
/**
 * Detect if the accumulated text contains a syntactically complete JSON
 * object with tool_name and tool_args.  Used for models that output tool
 * calls as plain text JSON (not native structured tool calls).
 */
declare function hasCompleteToolJson(text: string): boolean;
/**
 * Detect if the accumulated text contains a repeated block, indicating
 * a looping cascade.  Returns true if a block of `minBlockSize` chars
 * from the first half appears again in the second half.
 */
declare function hasRepetition(text: string, minBlockSize: number): boolean;
export declare const __testing: {
    hasCompleteToolJson: typeof hasCompleteToolJson;
    hasRepetition: typeof hasRepetition;
};
export {};
