import type { MastraDBMessage, MessageList } from '@mastra/core/agent';
import type { MessageHistory } from '@mastra/core/processors';
import type { MemoryStorage } from '@mastra/core/storage';
import type { ObserverRunner } from '../observer-runner.js';
import type { ReflectorRunner } from '../reflector-runner.js';
import type { TokenCounter } from '../token-counter.js';
import type { ObservationDebugEvent, ObservationMarkerConfig, ResolvedObservationConfig, ResolvedReflectionConfig } from '../types.js';
import type { ObservationRunOpts, ObservationRunResult, ObserverOutput, ProcessedObservation } from './types.js';
/**
 * Dependencies injected into observation strategies.
 * Built by the factory in index.ts from the ObservationalMemory instance.
 */
export interface StrategyDeps {
    storage: MemoryStorage;
    messageHistory: MessageHistory;
    tokenCounter: TokenCounter;
    observationConfig: ResolvedObservationConfig;
    reflectionConfig: ResolvedReflectionConfig;
    scope: 'thread' | 'resource';
    retrieval: boolean;
    observer: ObserverRunner;
    reflector: ReflectorRunner;
    observedMessageIds: Set<string>;
    obscureThreadIds: boolean;
    onIndexObservations?: (observation: {
        text: string;
        groupId: string;
        range: string;
        threadId: string;
        resourceId: string;
        observedAt?: Date;
    }) => Promise<void>;
    emitDebugEvent: (event: ObservationDebugEvent) => void;
}
/**
 * Abstract base class for observation strategies.
 *
 * Each strategy implements the phases of the observation lifecycle
 * (prepare → observe → process → persist) while the base class handles
 * the shared orchestration (lock guard, marker emission, reflection, error handling).
 */
export declare abstract class ObservationStrategy {
    protected readonly deps: StrategyDeps;
    protected readonly opts: ObservationRunOpts;
    protected readonly storage: MemoryStorage;
    protected readonly messageHistory: MessageHistory;
    protected readonly tokenCounter: TokenCounter;
    protected readonly observationConfig: ResolvedObservationConfig;
    protected readonly reflectionConfig: ResolvedReflectionConfig;
    protected readonly scope: 'thread' | 'resource';
    protected readonly retrieval: boolean;
    /** Select the right strategy based on scope and mode. Wired up by index.ts. */
    static create: (om: unknown, opts: ObservationRunOpts) => ObservationStrategy;
    constructor(deps: StrategyDeps, opts: ObservationRunOpts);
    /**
     * Run the full observation lifecycle.
     * @returns Result with `observed` flag and optional `usage` from the observer LLM call.
     * @throws On sync/resource-scoped observer failure after failed markers (same as pre–Option-A contract).
     */
    run(): Promise<ObservationRunResult>;
    protected generateCycleId(): string;
    protected streamMarker(marker: {
        type: string;
        data: unknown;
    }): Promise<void>;
    protected getObservationMarkerConfig(): ObservationMarkerConfig;
    protected getMaxMessageTimestamp(messages: MastraDBMessage[]): Date;
    /**
     * Wrap observations in a thread attribution tag.
     * In resource scope, thread IDs can be obscured via xxhash.
     */
    protected wrapWithThreadTag(threadId: string, observations: string, messageRange?: string): Promise<string>;
    /**
     * Create a message boundary delimiter with an ISO 8601 date.
     * Used to separate observation chunks for cache stability.
     */
    protected static createMessageBoundary(date: Date): string;
    /**
     * Wrap raw observations — in resource scope, wraps with thread tag and merges;
     * in thread scope, simply appends with a message boundary delimiter.
     */
    protected wrapObservations(rawObservations: string, existingObservations: string, threadId: string, lastObservedAt?: Date, messageRange?: string): Promise<string> | string;
    protected replaceOrAppendThreadSection(existingObservations: string, _threadId: string, newThreadSection: string, lastObservedAt?: Date): string;
    protected indexObservationGroups(observations: string, threadId: string, resourceId?: string, observedAt?: Date): Promise<void>;
    /**
     * Persist a marker to the last assistant message in storage.
     * Fetches messages directly from the DB so it works even when
     * no MessageList is available (e.g. async buffering ops).
     */
    protected persistMarkerToStorage(marker: {
        type: string;
        data: unknown;
    }, threadId: string, resourceId?: string): Promise<void>;
    /**
     * Persist a marker part on the last assistant message in a MessageList
     * AND save the updated message to the DB.
     */
    protected persistMarkerToMessage(marker: {
        type: string;
        data: unknown;
    }, messageList: MessageList | undefined, threadId: string, resourceId?: string): Promise<void>;
    abstract get needsLock(): boolean;
    abstract get needsReflection(): boolean;
    abstract get rethrowOnFailure(): boolean;
    abstract prepare(): Promise<{
        messages: MastraDBMessage[];
        existingObservations: string;
    }>;
    abstract observe(existingObservations: string, messages: MastraDBMessage[]): Promise<ObserverOutput>;
    abstract process(output: ObserverOutput, existingObservations: string): Promise<ProcessedObservation>;
    abstract persist(processed: ProcessedObservation): Promise<void>;
    abstract emitStartMarkers(cycleId: string): Promise<void>;
    abstract emitEndMarkers(cycleId: string, processed: ProcessedObservation): Promise<void>;
    abstract emitFailedMarkers(cycleId: string, error: unknown): Promise<void>;
}
//# sourceMappingURL=base.d.ts.map