import type { AgentHeartbeatEvent } from '../core/heartbeat/index.js';
import type { AgentLoopEvent } from '../core/runtime/loop/index.js';
export type CyberLoopMetadataChannels = Record<string, unknown>;
export type CyberLoopStepContext<S = unknown> = {
    step: number;
    state: S;
    prevState?: S;
    budget: {
        used: number;
        remaining: number;
    };
    metadata: CyberLoopMetadataChannels;
};
export type CyberLoopStepResult<S = unknown> = {
    state: S;
    action?: unknown;
    feedback?: unknown;
    cost?: number;
};
/**
 * Structural subset of CyberLoop's middleware contract.
 *
 * Heddle does not import CyberLoop directly. Callers can pass middleware from
 * CyberLoop because TypeScript's structural typing makes the contracts match.
 */
export type CyberLoopCompatibleMiddleware<S = unknown> = {
    name: string;
    setup?: (ctx: {
        input: unknown;
    }) => Promise<void>;
    beforeStep?: (ctx: CyberLoopStepContext<S>) => Promise<CyberLoopStepContext<S> | 'halt'>;
    afterStep?: (ctx: CyberLoopStepContext<S>, result: CyberLoopStepResult<S>) => Promise<void>;
    teardown?: (ctx: {
        reason: string;
    }) => Promise<void>;
};
/**
 * Structural subset of CyberLoop's StateEmbedder contract.
 */
export type CyberLoopCompatibleStateEmbedder<S = unknown> = {
    embed: (state: S) => Promise<number[]>;
};
export type HeddleRuntimeFrameKind = 'assistant' | 'tool' | 'checkpoint' | 'heartbeat' | 'final';
export type HeddleRuntimeFrame = {
    runId: string;
    step: number;
    kind: HeddleRuntimeFrameKind;
    goal: string;
    text: string;
    timestamp: string;
    tool?: string;
    toolCallId?: string;
    ok?: boolean;
    rawEvent: AgentHeartbeatEvent;
};
export type CyberLoopDriftLevel = 'unknown' | 'low' | 'medium' | 'high';
export type CyberLoopObserverAnnotation = {
    runId: string;
    step: number;
    frame: HeddleRuntimeFrame;
    metadata: CyberLoopMetadataChannels;
    driftLevel: CyberLoopDriftLevel;
    requestedHalt: boolean;
    timestamp: string;
};
export type CreateCyberLoopObserverOptions = {
    middleware: CyberLoopCompatibleMiddleware<HeddleRuntimeFrame>[];
    baselineFrame?: (event: Extract<AgentLoopEvent, {
        type: 'loop.started';
    }>) => HeddleRuntimeFrame | undefined;
    shouldObserveFrame?: (frame: HeddleRuntimeFrame) => boolean;
    onAnnotation?: (annotation: CyberLoopObserverAnnotation) => void;
    onError?: (error: unknown) => void;
};
export type RuntimeFrameEmbedText = (text: string, frame: HeddleRuntimeFrame) => Promise<number[]>;
export type CreateRuntimeFrameEmbedderOptions = {
    embedText: RuntimeFrameEmbedText;
    includeGoal?: boolean;
    maxTextLength?: number;
};
export type CyberLoopObserver = {
    handleEvent: (event: AgentHeartbeatEvent) => void;
    flush: () => Promise<void>;
};
export declare function createRuntimeFrameEmbedder(options: CreateRuntimeFrameEmbedderOptions): CyberLoopCompatibleStateEmbedder<HeddleRuntimeFrame>;
export declare function formatRuntimeFrameForEmbedding(frame: HeddleRuntimeFrame, options?: Pick<CreateRuntimeFrameEmbedderOptions, 'includeGoal' | 'maxTextLength'>): string;
export declare function createCyberLoopObserver(options: CreateCyberLoopObserverOptions): CyberLoopObserver;
export declare function eventToRuntimeFrame(event: AgentHeartbeatEvent, context?: {
    runId?: string;
    goal?: string;
}): HeddleRuntimeFrame | undefined;
export declare function inferDriftLevel(metadata: CyberLoopMetadataChannels): CyberLoopDriftLevel;
//# sourceMappingURL=cyberloop.d.ts.map