import { ToolRegistration } from '../tools/tool-manager.js';
import { SlashCommand } from '../commands/slash-commands.js';
import { Logger } from '../utils/logger.js';
import type { LLMMessage } from '../providers/types.js';
/**
 * Plugin Provider Type
 * Defines the category of capability a provider offers
 */
export type PluginProviderType = 'llm' | 'embedding' | 'search';
/**
 * Plugin Provider Interface
 * Allows plugins to provide additional capabilities (e.g., LLM providers, embedding services)
 */
export interface PluginProvider {
    /** Unique identifier for this provider */
    id: string;
    /** Human-readable name */
    name: string;
    /** Type of provider capability */
    type: PluginProviderType;
    /** Priority for provider selection (higher = preferred, default: 0) */
    priority?: number;
    /** Provider-specific configuration */
    config?: Record<string, unknown>;
    /** Initialize the provider (called once during registration) */
    initialize(): Promise<void>;
    /** Shutdown the provider (called during cleanup) */
    shutdown?(): Promise<void>;
    /** Chat completion with message history */
    chat?(messages: LLMMessage[]): Promise<string>;
    /** Simple text completion */
    complete?(prompt: string): Promise<string>;
    /** Generate embeddings for text */
    embed?(text: string | string[]): Promise<number[] | number[][]>;
    /** Search for documents matching a query */
    search?(query: string, options?: {
        limit?: number;
        filters?: Record<string, unknown>;
    }): Promise<SearchResult[]>;
}
/**
 * Search result from a search provider
 */
export interface SearchResult {
    /** Unique identifier for the result */
    id: string;
    /** Content or snippet of the result */
    content: string;
    /** Relevance score (0-1) */
    score: number;
    /** Additional metadata */
    metadata?: Record<string, unknown>;
}
/**
 * Plugin Configuration Schema
 * JSON Schema-like definition for validating plugin configuration
 */
export interface PluginConfigSchema {
    type: 'object';
    properties: Record<string, PluginConfigPropertySchema>;
    required?: string[];
}
export interface PluginConfigPropertySchema {
    type: 'string' | 'number' | 'boolean' | 'array' | 'object';
    description?: string;
    default?: unknown;
    enum?: (string | number | boolean)[];
    minimum?: number;
    maximum?: number;
    minLength?: number;
    maxLength?: number;
    pattern?: string;
    items?: PluginConfigPropertySchema;
}
/**
 * Plugin Manifest
 * Defines metadata for a plugin
 */
export interface PluginManifest {
    id: string;
    name: string;
    version: string;
    description: string;
    author?: string;
    license?: string;
    homepage?: string;
    repository?: string;
    minApiVersion?: string;
    permissions?: PluginPermissions;
    /** Whether the plugin should run in an isolated Worker Thread (default: true) */
    isolated?: boolean;
    /** Default configuration values for this plugin */
    defaultConfig?: Record<string, unknown>;
    /** JSON Schema for validating plugin configuration */
    configSchema?: PluginConfigSchema;
}
/**
 * Plugin Permissions
 * Defines what a plugin is allowed to do
 */
export interface PluginPermissions {
    filesystem?: boolean | string[];
    network?: boolean | string[];
    shell?: boolean;
    env?: boolean;
}
/**
 * Plugin Context
 * Passed to plugin lifecycle methods to interact with the host system
 */
export interface PluginContext {
    /** Logger scoped to this plugin */
    logger: Logger;
    /** Configuration for this plugin */
    config: Record<string, unknown>;
    /** Register a tool */
    registerTool(tool: ToolRegistration): void;
    /** Register a slash command */
    registerCommand(command: SlashCommand): void;
    /** Register a provider (e.g., for LLMs, embeddings, search) */
    registerProvider(provider: PluginProvider): void;
    /** Path to plugin's data directory */
    dataDir: string;
}
/**
 * Plugin Interface
 * The main entry point for a plugin
 */
export interface Plugin {
    /** Called when the plugin is loaded */
    activate(context: PluginContext): Promise<void> | void;
    /** Called when the plugin is unloaded or disabled */
    deactivate(): Promise<void> | void;
}
/**
 * Plugin Status
 */
export declare enum PluginStatus {
    LOADED = "loaded",
    ACTIVE = "active",
    DISABLED = "disabled",
    ERROR = "error"
}
/**
 * Plugin Metadata (internal use)
 */
export interface PluginMetadata {
    manifest: PluginManifest;
    status: PluginStatus;
    path: string;
    error?: Error;
    instance?: Plugin;
    /** Whether this plugin is running in isolation (Worker Thread) */
    isolated?: boolean;
}
/**
 * Plugin Isolation Configuration
 */
export interface PluginIsolationConfig {
    /** Execution timeout in milliseconds (default: 30000) */
    timeout?: number;
    /** Memory limit in MB (default: 128) */
    memoryLimit?: number;
    /** Stack size in MB (default: 4) */
    stackSize?: number;
}
/**
 * Plugin Execution Statistics (for monitoring isolated plugins)
 */
export interface PluginExecutionStats {
    pluginId: string;
    startTime: number;
    activationTime?: number;
    messageCount: number;
    errorCount: number;
    lastError?: string;
    isRunning: boolean;
}
/**
 * Manifest Validation Error
 */
export declare class ManifestValidationError extends Error {
    readonly field?: string | undefined;
    readonly value?: unknown | undefined;
    constructor(message: string, field?: string | undefined, value?: unknown | undefined);
}
/**
 * Validation result type
 */
export interface ValidationResult {
    valid: boolean;
    errors: string[];
}
/**
 * Validate a plugin manifest
 * Ensures all required fields are present and have valid formats
 */
export declare function validateManifest(manifest: unknown): ValidationResult;
/**
 * Validate plugin permissions object
 */
export declare function validatePermissions(permissions: unknown): ValidationResult;
/**
 * Check if a plugin has a specific permission
 */
export declare function hasPermission(permissions: PluginPermissions | undefined, type: keyof PluginPermissions, target?: string): boolean;
/**
 * Blocked module list for sandboxing
 * These modules should never be accessible to plugins without explicit permission
 */
export declare const BLOCKED_MODULES: {
    readonly always: readonly ["cluster", "dgram", "dns", "tls", "v8", "vm", "worker_threads", "repl"];
    readonly withoutShell: readonly ["child_process"];
    readonly withoutFilesystem: readonly ["fs", "fs/promises", "fs-extra"];
    readonly withoutNetwork: readonly ["net", "http", "https", "http2"];
};
/**
 * Get list of blocked modules based on permissions
 */
export declare function getBlockedModules(permissions: PluginPermissions): string[];
/**
 * Validate a plugin configuration schema
 */
export declare function validateConfigSchema(schema: unknown): ValidationResult;
/**
 * Validate a configuration value against a schema
 */
export declare function validateConfigValue(value: unknown, schema: PluginConfigPropertySchema, path?: string): ValidationResult;
/**
 * Validate a complete plugin configuration against its schema
 */
export declare function validatePluginConfig(config: Record<string, unknown>, schema: PluginConfigSchema): ValidationResult;
