import type { Client } from '@botpress/client';
import { type Credentials } from '../auth/index.js';
import { AgentProject } from '../agent-project/agent-project.js';
import { LocalKnowledgeBase, KBSyncPlan, KBSyncResult, KBSyncOptions, OrphanedSource } from './types.js';
type RemoteKnowledgeBase = Pick<Awaited<ReturnType<Client['listKnowledgeBases']>>['knowledgeBases'][number], 'id' | 'name' | 'tags'>;
export interface KnowledgeManagerOptions {
    project: AgentProject;
    botId?: string;
    credentials?: Credentials;
}
/**
 * Manages knowledge base synchronization for ADK projects
 */
export declare class KnowledgeManager {
    private client?;
    private botId?;
    private project;
    private credentials?;
    /** Cache of file hashes by directory path to avoid recalculating */
    private fileHashCache;
    private remoteKbsPromise;
    constructor(options: KnowledgeManagerOptions);
    /**
     * Clear the file hash cache (call before a new sync operation)
     */
    clearHashCache(): void;
    private getClient;
    private assertBotId;
    /**
     * Format an error for display, including API response data if available
     */
    private formatError;
    /**
     * Get all knowledge bases from the project
     */
    getLocalKnowledgeBases(): LocalKnowledgeBase[];
    /**
     * Calculate content hash from individual file hashes
     * This creates a deterministic hash of all file contents
     */
    private computeContentHash;
    /**
     * List all remote knowledge bases
     */
    private listRemoteKnowledgeBases;
    private invalidateRemoteKbsCache;
    /**
     * Find remote KB by name
     */
    private findRemoteKB;
    /**
     * Create a new knowledge base
     */
    createKnowledgeBase(name: string): Promise<RemoteKnowledgeBase>;
    /**
     * Get remote KBs that don't exist locally (orphaned)
     */
    getOrphanedKBs(): Promise<RemoteKnowledgeBase[]>;
    /**
     * Get orphaned sources for a KB by listing files and extracting unique dsIds from tags
     * Returns sources that exist in remote files but not in local definition
     */
    getOrphanedSources(kbName: string, localDsIds: string[]): Promise<OrphanedSource[]>;
    /**
     * Delete all files belonging to an orphaned source using direct dsId tag query
     */
    deleteOrphanedSource(kbName: string, dsId: string): Promise<{
        deletedFiles: number;
        errors: string[];
    }>;
    /**
     * Clean up source tags from KB after deleting orphaned source
     * Note: Botpress API merges tags, so we set to empty string to "delete" them
     */
    private cleanupSourceTags;
    /**
     * Delete a KB and all its associated files
     */
    deleteKnowledgeBase(kbId: string, kbName: string): Promise<{
        deletedFiles: number;
    }>;
    /**
     * Get stored hash for a specific source from KB tags
     */
    private getRemoteSourceHash;
    /**
     * Update source hash in KB tags after sync
     */
    private updateSourceHash;
    /**
     * Compute config hash for a data source (used for website sources)
     */
    private computeConfigHash;
    /**
     * Trigger website source sync by creating the builtin_knowledge_indexing workflow.
     * For dev bots, this requires adk dev to be running. For prod bots, runs in Botpress Cloud.
     */
    syncWebsiteSource(kbName: string, kbId: string, force: boolean): Promise<{
        workflowId: string;
    }>;
    /**
     * Detect legacy website source files (old tag format)
     * Legacy files have: knowledge: 'true' (old format)
     * Returns count of legacy files found
     */
    detectLegacyWebsiteFiles(kbName: string, sourceId: string): Promise<number>;
    /**
     * Delete legacy website source files (old tag format)
     * Called during executeSync when legacy files were detected
     */
    deleteLegacyWebsiteFiles(kbName: string, sourceId: string): Promise<{
        deletedFiles: number;
    }>;
    /**
     * Check if a KB has any website sources
     */
    hasWebsiteSources(kbName: string): boolean;
    /**
     * Get list of KB names that have website sources
     */
    getKBsWithWebsiteSources(): string[];
    /**
     * Compute content hash for a single directory source
     */
    private computeDirectorySourceHash;
    /**
     * Create a sync plan comparing local sources vs remote KB tags
     * Uses per-source hashes stored in KB tags
     */
    createSyncPlan(): Promise<KBSyncPlan>;
    /**
     * Detect file changes for a single directory source
     */
    private detectDirectorySourceChanges;
    /**
     * Scan local files for a directory source and return their hashes
     */
    private scanLocalFileHashes;
    /**
     * Execute KB sync based on plan
     * Directly uploads files to Botpress without requiring a running bot.
     * For website sources that need sync, triggers the builtin_knowledge_indexing workflow.
     */
    executeSync(plan: KBSyncPlan, options?: KBSyncOptions): Promise<KBSyncResult>;
    /**
     * Sync a directory data source by uploading files directly
     */
    private syncDirectorySource;
    /**
     * List existing files in Botpress with given tags
     */
    private listExistingFiles;
    /**
     * Upload or update a file
     */
    private upsertFile;
}
export {};
//# sourceMappingURL=manager.d.ts.map