import { KnowledgeSearchOptions, MemoryKnowledgeConfigWithModels } from '@easbot/types';
export { GRAPH_ENTITY_TYPE_DEFINITIONS, GRAPH_RELATION_TYPE_DEFINITIONS } from '@easbot/types';
import Database, { Database as Database$1 } from 'better-sqlite3';
export { EmbeddingModel, LanguageModel } from 'ai';

type MemoryCategory = 'user_preference' | 'task_context' | 'technical_fact' | 'decision' | 'relationship' | 'reminder' | 'error_pattern' | 'workflow' | 'exploration_finding' | 'experience_summary' | 'tool_usage' | 'skill_creation' | 'test' | 'other';
declare const MEMORY_CATEGORIES: MemoryCategory[];
type MemorySource = 'session_self_write' | 'historical';
interface MemoryFact {
    id: string;
    agentId: string;
    sessionId?: string;
    msgId?: string;
    parentMsgId?: string;
    content: string;
    category: MemoryCategory;
    importance: number;
    source: MemorySource;
    tags?: string[];
    nodeIds?: number[];
    filePath?: string;
    createdAt: string;
    updatedAt: string;
}
interface MemoryVector {
    factId: string;
    embedding: Float32Array;
}
interface MemoryQuery extends KnowledgeSearchOptions {
    agentId: string;
    sessionId?: string;
    category?: MemoryCategory;
    minImportance?: number;
    source?: MemorySource;
    fromTime?: string;
    toTime?: string;
    candidateFactIds?: string[];
}
interface MemoryRecallResult {
    memoryId: string;
    category: MemoryCategory;
    importance: number;
    agentId: string;
    snippet: string;
    score: number;
    createdAt: string;
    source: MemorySource;
    filePath?: string;
    nodes?: Array<{
        id: number;
        name: string;
        type: string;
        edges?: Array<MemoryEdge & {
            direction?: 'in' | 'out';
        }>;
    }>;
}
type MemorySystemConfig = MemoryKnowledgeConfigWithModels;
interface IMemorySystem {
    remember(fact: Omit<MemoryFact, 'id' | 'createdAt' | 'updatedAt'>): Promise<MemoryFact>;
    query(query: string, options?: MemoryQuery): Promise<MemoryRecallResult[]>;
    queryEdgesByNodeId(nodeId: number, options?: {
        maxDepth?: number;
    }): Promise<{
        node?: {
            id: number;
            name: string;
            type: string;
        };
        nodes: MemoryNode[];
        edges: MemoryEdge[];
    }>;
    forget(agentId: string, memoryId: string): Promise<void>;
    update(agentId: string, memoryId: string, patch: {
        content?: string;
        importance?: number;
        tags?: string[];
    }): Promise<MemoryFact>;
    listAgentIds(): Promise<string[]>;
    queryForSummary(agentId: string, options?: {
        limit?: number;
        category?: string;
        fromTime?: string;
        toTime?: string;
    }): Promise<MemoryFact[]>;
    archive(): Promise<void>;
    clear(): Promise<void>;
    close(): Promise<void>;
    sync(): Promise<{
        synced: number;
        created: number;
        updated: number;
        errors: string[];
    }>;
    getStatus(): Promise<{
        dbPath: string;
        workspaceDir: string;
        factsCount: number;
        nodesCount: number;
        edgesCount: number;
        embeddingLlmAvailable: boolean;
        graphLlmAvailable: boolean;
        healthy: boolean;
        meta: Record<string, string>;
    }>;
}
declare class MemoryError extends Error {
    readonly code: string;
    cause?: Error | undefined;
    constructor(message: string, code: string, cause?: Error | undefined);
}
declare class MemoryValidationError extends MemoryError {
    constructor(message: string, cause?: Error);
}
declare class MemoryNotFoundError extends MemoryError {
    constructor(memoryId: string);
}
declare class MemoryPermissionError extends MemoryError {
    constructor(message: string);
}
declare class MemoryDatabaseError extends MemoryError {
    constructor(message: string, cause?: Error);
}
declare class MemoryFileError extends MemoryError {
    constructor(message: string, cause?: Error);
}
declare class MemorySearchError extends MemoryError {
    constructor(message: string, cause?: Error);
}
declare class MemoryEmbeddingError extends MemoryError {
    constructor(message: string, cause?: Error);
}
declare enum MemoryErrorCode {
    VALIDATION_ERROR = "MEMORY_VALIDATION_ERROR",
    NOT_FOUND = "MEMORY_NOT_FOUND",
    PERMISSION_ERROR = "MEMORY_PERMISSION_ERROR",
    DATABASE_ERROR = "MEMORY_DATABASE_ERROR",
    FILE_ERROR = "MEMORY_FILE_ERROR",
    SEARCH_ERROR = "MEMORY_SEARCH_ERROR",
    EMBEDDING_ERROR = "MEMORY_EMBEDDING_ERROR"
}
interface MemoryNode {
    id: number;
    name: string;
    type: string;
    properties?: Record<string, unknown>;
    createdAt: string;
    updatedAt: string;
}
interface MemoryEdge {
    id: number;
    source: number;
    target: number;
    relation: string;
    properties?: Record<string, unknown>;
    createdAt: string;
    targetNode?: MemoryNode;
}
interface MemoryNodeWithEdges extends MemoryNode {
    edges?: MemoryEdge[];
}
interface NodeQueryFilter {
    ids?: number[];
    name?: string;
    type?: string;
    limit?: number;
}
interface EdgeQueryFilter {
    ids?: number[];
    source?: number;
    target?: number;
    sourceOrTarget?: number[];
    relation?: string;
    limit?: number;
}
interface ArchiveRecord {
    source: string;
    target: string;
    timestamp: number;
}
interface ArchiveResult {
    archivedCount: number;
    records: ArchiveRecord[];
}

declare function initTokenizer(params?: {
    dictPath?: string[];
}): Promise<void>;
declare function loadCustomDict(dictPath: string): Promise<void>;
declare function tokenize(text: string): string[];
declare function tokenizeForSearch(text: string): string[];
declare function addWord(word: string, freq?: number, tag?: string): void;
declare function isInitialized(): boolean;
declare function closeTokenizer(): Promise<void>;
declare function toFtsTokens(text: string): string;
declare function toFtsTokensForSearch(text: string): string;

declare class MemoryDatabaseManager {
    private db;
    private readonly storagePath;
    private initialized;
    private initPromise;
    constructor(storagePath: string);
    initialize(): Promise<void>;
    private doInitialize;
    private openDatabaseAsync;
    private createTables;
    query<T>(sql: string, params?: unknown[]): T[];
    run(sql: string, params?: unknown[]): {
        lastID: number;
        changes: number;
    };
    transaction<T>(fn: () => T): T;
    prepare(sql: string): Database.Statement;
    exec(sql: string): void;
    getDb(): Database.Database;
    getPath(): string;
    close(): void;
    healthCheck(): boolean;
    getMeta(key: string): string | null;
    setMeta(key: string, value: string): void;
}

declare class MemoryFormatter {
    static generateId(): string;
    static serialize(fact: MemoryFact): string;
    static serializeFile(facts: MemoryFact[]): string;
    static parse(content: string): MemoryFact[];
    private static parseFrontmatter;
    private static validateFrontmatter;
    private static parseArrayField;
}

declare class MemoryFileManager {
    static getMemoryMdPath(workspaceDir: string): string;
    static getActiveFilePath(workspaceDir: string, category: MemoryCategory, date?: Date): string;
    static getArchiveFilePath(workspaceDir: string, category: MemoryCategory, createdAt: number, filename: string): string;
    static readMemoryMd(workspaceDir: string): Promise<string | null>;
    static write(workspaceDir: string, fact: MemoryFact): Promise<string>;
    static read(filePath: string): Promise<MemoryFact[]>;
    static delete(filePath: string, memoryId: string): Promise<void>;
    static update(filePath: string, memoryId: string, patch: {
        content?: string;
        importance?: number;
        tags?: string[];
    }): Promise<void>;
    static listActiveFiles(workspaceDir: string): Promise<string[]>;
    private static scanDir;
}

declare class MemoryArchiver {
    private db;
    private config;
    constructor(db: Database$1, config: MemorySystemConfig);
    archive(): Promise<ArchiveResult>;
}

declare class GraphStore {
    private db;
    constructor(db: Database$1);
    upsertNode(name: string, type: string, properties?: Record<string, unknown>): Promise<number>;
    deleteNode(id: number): Promise<void>;
    upsertEdge(source: number, target: number, relation: string, properties?: Record<string, unknown>): Promise<number>;
    queryNodes(filter?: NodeQueryFilter): Promise<MemoryNode[]>;
    queryEdges(filter?: EdgeQueryFilter): Promise<MemoryEdge[]>;
    queryNeighbors(nodeId: number, depth?: number, options?: {
        maxEdgesPerNode?: number;
    }): Promise<MemoryNodeWithEdges[]>;
}

declare class MemorySystem implements IMemorySystem {
    private readonly config;
    private readonly db;
    private archiver;
    private searchEngine;
    private graphStore;
    private embeddingModel;
    private vectorDims;
    constructor(config: MemorySystemConfig);
    initialize(): Promise<void>;
    remember(fact: Omit<MemoryFact, 'id' | 'createdAt' | 'updatedAt'>): Promise<MemoryFact>;
    query(query: string, options?: MemoryQuery): Promise<MemoryRecallResult[]>;
    queryEdgesByNodeId(nodeId: number, options?: {
        maxDepth?: number;
        maxEdgesPerNode?: number;
    }): Promise<{
        node?: {
            id: number;
            name: string;
            type: string;
        };
        nodes: MemoryNode[];
        edges: MemoryEdge[];
    }>;
    forget(agentId: string, memoryId: string): Promise<void>;
    update(agentId: string, memoryId: string, patch: {
        content?: string;
        importance?: number;
        tags?: string[];
    }): Promise<MemoryFact>;
    listAgentIds(): Promise<string[]>;
    queryForSummary(agentId: string, options?: {
        limit?: number;
        category?: string;
        fromTime?: string;
        toTime?: string;
    }): Promise<MemoryFact[]>;
    archive(): Promise<void>;
    cleanupOrphanRecords(): Promise<void>;
    clear(): Promise<void>;
    close(): Promise<void>;
    getStatus(): Promise<{
        dbPath: string;
        workspaceDir: string;
        factsCount: number;
        nodesCount: number;
        edgesCount: number;
        embeddingLlmAvailable: boolean;
        graphLlmAvailable: boolean;
        healthy: boolean;
        meta: Record<string, string>;
    }>;
    sync(): Promise<{
        synced: number;
        created: number;
        updated: number;
        errors: string[];
    }>;
    private hasMemoryFiles;
    private clearFiles;
    private rowToFact;
    private extractEntities;
    private extractEntitiesWithLlm;
    private buildEntityExtractionPrompt;
    private storeEntitiesAndRelations;
    private mergeEntitiesAndRelations;
    private embed;
    private embedAndStore;
    private writeVector;
    private writeFts;
    private parseEntityExtractionResult;
    private normalizeExtractionResult;
    private sanitizeEntityToken;
    private inferEntityType;
    private getSearchEngine;
    private getGraphStore;
    private getArchiver;
}
declare function createMemorySystem(config: MemorySystemConfig): Promise<IMemorySystem>;

declare function initLog(options: {
    print: boolean;
    logDir: string;
    logFile?: string;
    dev?: boolean;
    level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
}): Promise<void>;

export { type ArchiveRecord, type ArchiveResult, type EdgeQueryFilter, GraphStore, type IMemorySystem, MEMORY_CATEGORIES, MemoryArchiver, type MemoryCategory, MemoryDatabaseError, MemoryDatabaseManager, type MemoryEdge, MemoryEmbeddingError, MemoryError, MemoryErrorCode, type MemoryFact, MemoryFileError, MemoryFileManager, MemoryFormatter, type MemoryNode, type MemoryNodeWithEdges, MemoryNotFoundError, MemoryPermissionError, type MemoryQuery, type MemoryRecallResult, MemorySearchError, type MemorySource, MemorySystem, type MemorySystemConfig, MemoryValidationError, type MemoryVector, type NodeQueryFilter, addWord, closeTokenizer, createMemorySystem, initLog, initTokenizer, isInitialized, loadCustomDict, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch };
