import { NoteKnowledgeSource, KnowledgeSearchOptions, BaseSearchResult, KnowledgeSearchSource, NoteKnowledgeConfigWithModels } from '@easbot/types';
export { BaseSearchResult, DatabaseConfig, GRAPH_ENTITY_TYPE_DEFINITIONS, GRAPH_RELATION_TYPE_DEFINITIONS, IndexerConfig, KnowledgeSearchOptions, KnowledgeSearchSource, NoteKnowledgeConfigWithModels, NoteKnowledgeSource, SearchConfig } from '@easbot/types';
import { LanguageModelV3Message } from '@ai-sdk/provider';
import { EmbeddingModel, LanguageModel, RerankingModel } from 'ai';
export { EmbeddingModel, LanguageModel, RerankingModel } from 'ai';

interface ScannedFile {
    absolutePath: string;
    relativePath: string;
    source: NoteKnowledgeSource;
    contentHash: string;
    lastModified: number;
    size: number;
}
interface ScannerOptions {
    workspaceDir: string;
    extraPaths?: string[];
    sources?: NoteKnowledgeSource[];
    ignorePatterns?: string[];
}
declare class FileScanner {
    private readonly workspaceDir;
    private readonly extraPaths;
    private readonly sources;
    private readonly ignorePatterns;
    constructor(options: ScannerOptions);
    scanAll(progress?: (current: number, total: number, file: ScannedFile) => void): Promise<ScannedFile[]>;
    scanDirectory(dir: string, source: NoteKnowledgeSource): Promise<ScannedFile[]>;
    scanFile(filePath: string, source?: NoteKnowledgeSource): Promise<ScannedFile | null>;
    private getFileInfo;
    private shouldIgnore;
    private isMarkdownFile;
}

type NoteKnowledgeConfig = NoteKnowledgeConfigWithModels;
interface DocumentMetadata {
    title?: string;
    author?: string;
    date?: string;
    [key: string]: unknown;
}
interface Document {
    id: number;
    path: string;
    title?: string;
    contentHash: string;
    summary?: string;
    metadata?: DocumentMetadata;
    lastModified?: number;
    createdAt: number;
    updatedAt: number;
}
interface Node {
    id: number;
    name: string;
    type: string;
    properties?: Record<string, unknown>;
    createdAt: string;
    updatedAt: string;
}
interface Edge {
    id: number;
    source: number;
    target: number;
    relation: string;
    properties?: Record<string, unknown>;
    createdAt: string;
    targetNode?: Node;
}
interface NodeWithEdges extends Node {
    edges?: Edge[];
}
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 RelationQueryOptions {
    maxDepth?: number;
    relationTypes?: string[];
    direction?: 'incoming' | 'outgoing' | 'both';
    limit?: number;
}
interface CallGraphNode {
    callers: number[];
    callees: number[];
}
interface InheritanceQueryResult {
    ancestors: Node[];
    descendants: Node[];
}
interface Chunk {
    id: number;
    documentId: number;
    startLine: number;
    endLine: number;
    startChar: number;
    endChar: number;
    content: string;
    contentHash: string;
    nodeIds?: number[];
    createdAt: number;
}
interface VectorRecord {
    chunkId: number;
    embedding: Float32Array;
}
type SearchResultSource = KnowledgeSearchSource;
interface SearchResult extends BaseSearchResult {
    chunk: Chunk & {
        path: string;
    };
    document: Document;
    nodes?: NodeWithEdges[];
    source: SearchResultSource;
}
type SearchOptions = KnowledgeSearchOptions;
interface IngestResult {
    documentId: number;
    chunksCreated: number;
    vectorsCreated: number;
    entitiesExtracted?: number;
    relationsExtracted?: number;
    summary?: string;
}
interface NoteSyncResult {
    success: boolean;
    filesAdded: number;
    filesUpdated: number;
    filesDeleted: number;
    filesSkipped: number;
    chunksCreated: number;
    vectorsCreated: number;
    entitiesExtracted: number;
    relationsExtracted: number;
    errors: Array<{
        filePath: string;
        error: string;
    }>;
    duration: number;
}
interface LastSyncResult {
    timestamp: string;
    success: boolean;
    filesAdded: number;
    filesUpdated: number;
    filesDeleted: number;
    filesSkipped: number;
    chunksCreated: number;
    vectorsCreated: number;
    entitiesExtracted: number;
    relationsExtracted: number;
    errorCount: number;
    duration: number;
}
interface KnowledgeBaseStatus {
    dbPath: string;
    workspaceDir: string;
    documentsCount: number;
    chunksCount: number;
    nodesCount: number;
    edgesCount: number;
    embeddingLlmAvailable: boolean;
    graphLlmAvailable: boolean;
    rerankLlmAvailable: boolean;
    healthy: boolean;
    meta: Record<string, string>;
}
declare enum KnowledgeBaseErrorCode {
    DATABASE_INIT_FAILED = "DATABASE_INIT_FAILED",
    DATABASE_NOT_INITIALIZED = "DATABASE_NOT_INITIALIZED",
    DATABASE_QUERY_FAILED = "DATABASE_QUERY_FAILED",
    DOCUMENT_PARSE_FAILED = "DOCUMENT_PARSE_FAILED",
    EMBEDDING_FAILED = "EMBEDDING_FAILED",
    ENTITY_EXTRACTION_FAILED = "ENTITY_EXTRACTION_FAILED",
    SEARCH_FAILED = "SEARCH_FAILED",
    NODE_NOT_FOUND = "NODE_NOT_FOUND",
    EDGE_NOT_FOUND = "EDGE_NOT_FOUND",
    INVALID_CONFIG = "INVALID_CONFIG",
    MODEL_INJECTION_FAILED = "MODEL_INJECTION_FAILED"
}
declare class KnowledgeBaseError extends Error {
    code: KnowledgeBaseErrorCode;
    cause?: Error | undefined;
    constructor(message: string, code: KnowledgeBaseErrorCode, cause?: Error | undefined);
    toString(): string;
}
type LanguageModelPrompt = LanguageModelV3Message[];
interface INoteKnowledge {
    initialize(): Promise<void>;
    ingestDocument(filePath: string): Promise<IngestResult>;
    scanAndIngest(progress?: (current: number, total: number, file: ScannedFile) => void): Promise<IngestResult[]>;
    sync(progress?: (current: number, total: number, file: ScannedFile) => void): Promise<NoteSyncResult>;
    markDirty(): void;
    search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
    queryNodes(filter: NodeQueryFilter): Promise<Node[]>;
    queryEdges(filter: EdgeQueryFilter): Promise<Edge[]>;
    findPath(startNode: string, endNode: string, maxDepth?: number): Promise<Node[][]>;
    queryNeighbors(nodeId: number, options?: RelationQueryOptions): Promise<{
        nodes: Node[];
        edges: Edge[];
    }>;
    queryCallGraph(nodeId: number, depth?: number): Promise<Map<number, CallGraphNode>>;
    queryInheritance(nodeId: number): Promise<InheritanceQueryResult>;
    getStatus(): KnowledgeBaseStatus;
    healthCheck(): Promise<boolean>;
    clear(): Promise<void>;
    close(): Promise<void>;
}

declare class NoteKnowledge implements INoteKnowledge {
    private config;
    private db;
    private pipeline;
    private searchEngine;
    private graphInterface;
    private fileScanner;
    private initialized;
    private dirty;
    private syncTimer?;
    private syncConfig;
    private syncingInProgress;
    constructor(config: NoteKnowledgeConfig);
    initialize(): Promise<void>;
    private startSyncTimer;
    private ensureSynced;
    private stopSyncTimer;
    private syncAll;
    ingestDocument(filePath: string): Promise<IngestResult>;
    ingestDocuments(filePaths: string[], progress?: (p: number) => void): Promise<IngestResult[]>;
    scanAndIngest(progress?: (current: number, total: number, file: ScannedFile) => void): Promise<IngestResult[]>;
    ingestUploadedFile(filePath: string): Promise<IngestResult>;
    removeDocument(filePath: string): Promise<void>;
    markDirty(): void;
    sync(progress?: (current: number, total: number, file: ScannedFile) => void): Promise<NoteSyncResult>;
    search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
    queryNodes(sql: string, params?: unknown[]): Promise<Node[]>;
    queryNodes(filter: NodeQueryFilter): Promise<Node[]>;
    queryEdges(sql: string, params?: unknown[]): Promise<Edge[]>;
    queryEdges(filter: EdgeQueryFilter): Promise<Edge[]>;
    findPath(startNode: string, endNode: string, maxDepth?: number): Promise<Node[][]>;
    queryNeighbors(nodeId: number, options?: RelationQueryOptions): Promise<{
        nodes: Node[];
        edges: Edge[];
    }>;
    queryCallGraph(nodeId: number, depth?: number): Promise<Map<number, CallGraphNode>>;
    queryInheritance(nodeId: number): Promise<InheritanceQueryResult>;
    createNode(name: string, type: string, properties?: Record<string, unknown>): Promise<Node>;
    updateNode(id: number, properties: Record<string, unknown>): Promise<Node>;
    deleteNode(id: number): Promise<void>;
    createEdge(source: number, target: number, relation: string, properties?: Record<string, unknown>): Promise<Edge>;
    deleteEdge(id: number): Promise<void>;
    getStatus(): KnowledgeBaseStatus;
    private getMetaMap;
    healthCheck(): Promise<boolean>;
    clear(): Promise<void>;
    private ensureInitialized;
    close(): Promise<void>;
}
declare function createNoteKnowledge(config: NoteKnowledgeConfig): Promise<INoteKnowledge>;

interface LlmModels {
    embeddingLlm?: EmbeddingModel;
    graphLlm?: LanguageModel;
    rerankLlm?: RerankingModel;
}
interface LlmOptions {
    maxOutputTokens?: number;
    temperature?: number;
}
interface LlmInitConfig {
    models: LlmModels;
    options?: {
        graph?: LlmOptions;
        rerankTopN?: number;
    };
}
declare namespace Llm {
    function init(config: LlmInitConfig): void;
    function isInitialized(): boolean;
    function capabilities(): {
        embedding: boolean;
        graphLlm: boolean;
        rerankLlm: boolean;
    };
    function embedText(value: string): Promise<Float32Array>;
    function embedTexts(values: string[]): Promise<Float32Array[]>;
    function generateGraph(chunks: string[], options?: LlmOptions): Promise<string>;
    function rerank(query: string, documents: string[], topN?: number): Promise<Array<{
        index: number;
        score: number;
    }>>;
    const embed: typeof embedText;
    const embedMany: typeof embedTexts;
}

declare function initTokenizer(params?: {
    dictPath?: string[];
    hmm?: boolean;
}): 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 function initLog(options: {
    print: boolean;
    logDir: string;
    logFile?: string;
    dev?: boolean;
    level?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
}): Promise<void>;

export { type CallGraphNode, type Chunk, type Document, type DocumentMetadata, type Edge, type EdgeQueryFilter, FileScanner, type INoteKnowledge, type IngestResult, type InheritanceQueryResult, KnowledgeBaseError, KnowledgeBaseErrorCode, type KnowledgeBaseStatus, type LanguageModelPrompt, type LastSyncResult, Llm, type Node, type NodeQueryFilter, type NodeWithEdges, NoteKnowledge, type NoteKnowledgeConfig, type NoteSyncResult, type RelationQueryOptions, type ScannedFile, type ScannerOptions, type SearchOptions, type SearchResult, type SearchResultSource, type VectorRecord, addWord, closeTokenizer, createNoteKnowledge, initLog, initTokenizer, isInitialized, loadCustomDict, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch };
