/**
 * LoopContext — reactLoop 单次执行的完整状态
 *
 * 封装原 reactLoop 内散落的 10+ 局部变量:
 *   - 注入依赖 (messages, tracker, trace, memoryCoordinator, sharedState)
 *   - 循环状态 (iteration, lastReply, toolCalls, tokenUsage)
 *   - 错误恢复 (consecutiveAiErrors, consecutiveEmptyResponses)
 *   - 配置 (source, budget, capabilities, baseSystemPrompt, toolSchemas, prompt)
 *
 * 使 reactLoop 的提取方法只需接收一个 ctx 参数。
 *
 * @module core/LoopContext
 */
import type { Capability } from '../capabilities.js';
import type { ContextWindow } from '../context/ContextWindow.js';
import type { ExplorationTracker } from '../context/ExplorationTracker.js';
import type { ActiveContext } from '../memory/ActiveContext.js';
import type { MemoryCoordinator } from '../memory/MemoryCoordinator.js';
import type { MessageAdapter } from './MessageAdapter.js';
/** Tool call hook type */
type ToolCallHook = (name: string, params: Record<string, unknown>, result: unknown) => void;
type ToolCallHookLike = (...args: any[]) => void;
/** Token usage returned by AI providers */
interface TokenUsage {
    inputTokens?: number;
    outputTokens?: number;
}
/** Shared state between pipeline stages */
interface SharedState {
    submittedTitles?: Set<string>;
    submittedPatterns?: Set<string>;
    submittedTriggers?: Set<string>;
    submitToolName?: string;
    _dimensionMeta?: {
        id?: string;
        [key: string]: unknown;
    };
    [key: string]: unknown;
}
/** Budget configuration */
interface BudgetConfig {
    maxIterations?: number;
    timeoutMs?: number;
    maxTokens?: number;
    temperature?: number;
    [key: string]: unknown;
}
/** LoopContext configuration — accepts both concrete and duck-typed inputs from callers */
interface LoopContextConfig {
    messages: MessageAdapter;
    tracker?: ExplorationTracker | Record<string, unknown> | null;
    trace?: ActiveContext | Record<string, unknown> | null;
    memoryCoordinator?: MemoryCoordinator | Record<string, unknown> | null;
    sharedState?: SharedState | Record<string, unknown> | null;
    source?: string;
    budget: BudgetConfig;
    capabilities: Capability[];
    baseSystemPrompt: string;
    toolSchemas: Array<Record<string, unknown>>;
    prompt: string;
    onToolCall?: ToolCallHook | ToolCallHookLike | null;
    context?: Record<string, unknown>;
    contextWindow?: ContextWindow | null;
    toolChoiceOverride?: string | null;
    abortSignal?: AbortSignal | null;
}
export declare class LoopContext {
    /** 统一消息适配器 */
    messages: MessageAdapter;
    /** ExplorationTracker 实例 */
    tracker: ExplorationTracker | null;
    /** ActiveContext 实例 */
    trace: ActiveContext | null;
    /** MemoryCoordinator 实例 */
    memoryCoordinator: MemoryCoordinator | null;
    /** 共享状态 */
    sharedState: SharedState | null;
    /** 当前迭代次数 */
    iteration: number;
    /** 最终回复文本 */
    lastReply: string;
    /** 本轮工具调用记录 */
    toolCalls: any[];
    /** } 本轮 token 用量 */
    tokenUsage: {
        input: number;
        output: number;
    };
    /** 循环开始时间戳 */
    loopStartTime: number;
    /** 连续 AI 错误计数 (2-strike 策略) */
    consecutiveAiErrors: number;
    /** 连续空响应计数 */
    consecutiveEmptyResponses: number;
    /** 来源 'user' | 'system' */
    source: string;
    /** 预算配置 */
    budget: BudgetConfig;
    capabilities: Capability[];
    /** 基础系统提示词 */
    baseSystemPrompt: string;
    /** 工具 schemas */
    toolSchemas: Array<Record<string, unknown>>;
    /** 原始用户提示 */
    prompt: string;
    /** 工具调用钩子 */
    onToolCall: ToolCallHook | null;
    /** 额外上下文 */
    context: Record<string, unknown>;
    /** 原始 ContextWindow 引用 */
    contextWindow: ContextWindow | null;
    /** 首轮 toolChoice 覆盖 ('required'/'auto'/'none') */
    toolChoiceOverride: string | null;
    /** 外部中止信号 — hard timeout 时取消进行中的 LLM 调用 */
    abortSignal: AbortSignal | null;
    constructor(config: LoopContextConfig);
    /** 是否为 system 场景 */
    get isSystem(): boolean;
    /** 最大迭代数 */
    get maxIterations(): number;
    /**
     * 累加 token 用量到循环级统计
     * @param usage { inputTokens, outputTokens }
     */
    addTokenUsage(usage: TokenUsage | null | undefined): void;
    /**
     * 构建循环返回值
     * @returns }
     */
    buildResult(): {
        reply: string;
        toolCalls: any[];
        tokenUsage: {
            input: number;
            output: number;
        };
        iterations: number;
    };
}
export {};
