/**
 * Memory Context Builder Module
 *
 * Manages memory integration and context building for the agent.
 * Handles:
 * - Memory retrieval and relevance filtering
 * - Context window management
 * - Memory persistence and project context
 * - Cross-session context building
 *
 * @module agent/context
 */
import { EventEmitter } from "events";
import { type MemoryType, type MemoryConfig } from "../../memory/index.js";
/**
 * Configuration for the MemoryContextBuilder
 */
export interface MemoryContextConfig {
    /** Whether memory system is enabled. Default: true */
    enabled: boolean;
    /** Maximum memories to include in context. Default: 10 */
    maxContextMemories: number;
    /** Minimum importance score for inclusion. Default: 0.5 */
    minImportanceScore: number;
    /** Whether to auto-save conversation to memory. Default: true */
    autoSave: boolean;
    /** Types of memories to include in context */
    includedTypes: MemoryType[];
    /** Project context path */
    projectPath?: string;
    /** Enhanced memory configuration */
    memoryConfig?: Partial<MemoryConfig>;
}
/**
 * Default configuration
 */
export declare const DEFAULT_MEMORY_CONTEXT_CONFIG: MemoryContextConfig;
/**
 * Context item built from memory
 */
export interface ContextItem {
    /** Unique identifier */
    id: string;
    /** Memory type */
    type: MemoryType;
    /** Content of the memory */
    content: string;
    /** Importance score (0-1) */
    importance: number;
    /** When the memory was created */
    createdAt: Date;
    /** Optional metadata */
    metadata?: Record<string, unknown>;
}
/**
 * Built context result
 */
export interface BuiltContext {
    /** Context items to include */
    items: ContextItem[];
    /** Total token estimate for the context */
    estimatedTokens: number;
    /** Summary of context sources */
    sources: {
        type: MemoryType;
        count: number;
    }[];
    /** Whether context was truncated due to limits */
    truncated: boolean;
}
/**
 * Events emitted by MemoryContextBuilder
 */
export interface MemoryContextEvents {
    "context:built": {
        itemCount: number;
        estimatedTokens: number;
    };
    "memory:saved": {
        type: MemoryType;
        id: string;
    };
    "memory:retrieved": {
        count: number;
        query: string;
    };
    "project:set": {
        path: string;
    };
    "error": {
        operation: string;
        error: string;
    };
}
/**
 * MemoryContextBuilder - Manages memory integration for agent context
 *
 * This class builds relevant context from the memory system for
 * inclusion in agent conversations. It handles:
 * - Semantic search across memories
 * - Importance filtering and ranking
 * - Token budget management
 * - Project-specific context
 *
 * @example
 * ```typescript
 * const builder = new MemoryContextBuilder({
 *   enabled: true,
 *   maxContextMemories: 10
 * });
 *
 * await builder.setProjectContext("/path/to/project");
 *
 * const context = await builder.buildContext("How do I fix authentication?");
 * console.log(context.items);
 * ```
 */
export declare class MemoryContextBuilder extends EventEmitter {
    private config;
    private memory;
    private initialized;
    constructor(config?: Partial<MemoryContextConfig>);
    /**
     * Initialize the memory system lazily
     */
    private getMemory;
    /**
     * Set the project context for memory operations
     */
    setProjectContext(projectPath: string): Promise<void>;
    /**
     * Build context from memory for a given query
     *
     * @param query - The user's query or message
     * @param tokenBudget - Optional token budget to respect
     * @returns Built context with relevant memories
     */
    buildContext(query: string, tokenBudget?: number): Promise<BuiltContext>;
    /**
     * Format context items for inclusion in system prompt
     */
    formatContextForPrompt(context: BuiltContext): string;
    /**
     * Get emoji for memory type
     */
    private getTypeEmoji;
    /**
     * Save a memory entry
     */
    saveMemory(content: string, type: MemoryType, metadata?: Record<string, unknown>): Promise<string | null>;
    /**
     * Save a conversation exchange to memory
     */
    saveConversation(userMessage: string, assistantResponse: string): Promise<string | null>;
    /**
     * Save a code pattern to memory
     */
    saveCodePattern(code: string, language: string, description?: string): Promise<string | null>;
    /**
     * Save an error solution to memory
     */
    saveErrorSolution(error: string, solution: string, context?: string): Promise<string | null>;
    /**
     * Save a decision to memory
     */
    saveDecision(decision: string, reasoning?: string): Promise<string | null>;
    /**
     * Get memory statistics
     */
    getStatistics(): {
        totalMemories: number;
        byType: Record<string, number>;
        projects: number;
        summaries: number;
    } | null;
    /**
     * Clear all memories
     */
    clearMemories(): Promise<boolean>;
    /**
     * Get configuration
     */
    getConfig(): MemoryContextConfig;
    /**
     * Update configuration
     */
    updateConfig(config: Partial<MemoryContextConfig>): void;
    /**
     * Check if memory is enabled
     */
    isEnabled(): boolean;
    /**
     * Enable or disable memory
     */
    setEnabled(enabled: boolean): void;
    /**
     * Check if initialized
     */
    isInitialized(): boolean;
    /**
     * Dispose and cleanup
     */
    dispose(): void;
}
/**
 * Create a MemoryContextBuilder instance
 */
export declare function createMemoryContextBuilder(config?: Partial<MemoryContextConfig>): MemoryContextBuilder;
/**
 * Get global MemoryContextBuilder instance
 */
export declare function getMemoryContextBuilder(config?: Partial<MemoryContextConfig>): MemoryContextBuilder;
/**
 * Reset global MemoryContextBuilder
 */
export declare function resetMemoryContextBuilder(): void;
/**
 * User input pattern for suggestion learning
 */
export interface InputPattern {
    keywords: string[];
    suggestedTools: string[];
    frequency: number;
    successRate: number;
    lastUsed: Date;
}
/**
 * Tool suggestion based on input analysis
 */
export interface SmartSuggestion {
    toolName: string;
    confidence: number;
    reason: string;
    basedOn: 'keyword' | 'pattern' | 'history' | 'context';
}
/**
 * Smart Suggestions Manager
 *
 * Learns from user input patterns and successful tool chains
 * to provide intelligent tool suggestions.
 */
export declare class SmartSuggestionsManager extends EventEmitter {
    private patterns;
    private toolChainHistory;
    private maxHistory;
    private keywordToolMap;
    constructor();
    /**
     * Get tool suggestions based on user input
     */
    suggestTools(input: string): SmartSuggestion[];
    /**
     * Get suggestions from keyword mappings
     */
    private suggestFromKeywords;
    /**
     * Get suggestions from learned patterns
     */
    private suggestFromPatterns;
    /**
     * Get suggestions from recent successful tool chains
     */
    private suggestFromHistory;
    /**
     * Learn from a successful tool chain
     */
    learnFromSuccess(input: string, tools: string[]): void;
    /**
     * Learn from a failed tool chain
     */
    learnFromFailure(input: string, tools: string[]): void;
    /**
     * Add a custom keyword -> tool mapping
     */
    addKeywordMapping(keyword: string, tools: string[]): void;
    /**
     * Get learned patterns
     */
    getLearnedPatterns(): InputPattern[];
    /**
     * Format suggestions for display
     */
    formatSuggestions(suggestions: SmartSuggestion[]): string;
    /**
     * Clear learned data
     */
    clear(): void;
    /**
     * Dispose and cleanup
     */
    dispose(): void;
}
/**
 * Get global SmartSuggestionsManager instance
 */
export declare function getSmartSuggestionsManager(): SmartSuggestionsManager;
/**
 * Reset global SmartSuggestionsManager
 */
export declare function resetSmartSuggestionsManager(): void;
