import { A as AgentSDKError } from '../errors-CmVvczxZ.js';
import { E as ErrorCode } from '../errors-C-so0M4t.js';

/**
 * @witqq/agent-sdk/chat/storage
 *
 * Generic storage adapter layer with pluggable backends.
 * Provides CRUD operations for any data type via `IStorageAdapter<T>`.
 * Implementations: `InMemoryStorage` (Map-based) and `FileStorage` (JSON files).
 */

/**
 * Error thrown by storage operations.
 *
 * @example
 * ```typescript
 * try {
 *   await store.get("missing-id");
 * } catch (e) {
 *   if (e instanceof StorageError && e.code === ErrorCode.STORAGE_NOT_FOUND) {
 *     // handle missing item
 *   }
 * }
 * ```
 */
declare class StorageError extends AgentSDKError {
    /** Machine-readable error code from the unified ErrorCode enum */
    readonly code: StorageErrorCode;
    constructor(message: string, code: StorageErrorCode);
}
/** Storage-specific subset of ErrorCode */
type StorageErrorCode = ErrorCode.STORAGE_NOT_FOUND | ErrorCode.STORAGE_DUPLICATE_KEY | ErrorCode.STORAGE_IO_ERROR | ErrorCode.STORAGE_SERIALIZATION_ERROR;
/**
 * Options for listing stored items.
 *
 * @typeParam T - The type of stored items
 */
interface ListOptions<T> {
    /** Filter predicate — return `true` to include the item */
    filter?: (item: T) => boolean;
    /** Sort comparator — standard Array.sort semantics */
    sort?: (a: T, b: T) => number;
    /** Maximum number of items to return */
    limit?: number;
    /** Number of items to skip (for pagination) */
    offset?: number;
}
/**
 * Generic storage adapter for CRUD operations on any data type.
 * Items are identified by a string key.
 *
 * @typeParam T - The type of stored items
 *
 * @example
 * ```typescript
 * const store: IStorageAdapter<{ name: string }> = new InMemoryStorage();
 * await store.create("key1", { name: "Alice" });
 * const item = await store.get("key1"); // { name: "Alice" }
 * ```
 */
interface IStorageAdapter<T> {
    /**
     * Retrieve an item by key.
     * @param key - Unique identifier
     * @returns The item, or `null` if not found
     */
    get(key: string): Promise<T | null>;
    /**
     * List items with optional filtering, sorting, and pagination.
     * @param options - Filter, sort, limit, offset options
     * @returns Array of matching items
     */
    list(options?: ListOptions<T>): Promise<T[]>;
    /**
     * Create a new item. Throws `StorageError` with code `DUPLICATE_KEY` if key exists.
     * @param key - Unique identifier
     * @param item - Data to store
     */
    create(key: string, item: T): Promise<void>;
    /**
     * Update an existing item. Throws `StorageError` with code `NOT_FOUND` if key missing.
     * @param key - Unique identifier
     * @param item - Updated data
     */
    update(key: string, item: T): Promise<void>;
    /**
     * Delete an item by key. Throws `StorageError` with code `NOT_FOUND` if key missing.
     * @param key - Unique identifier
     */
    delete(key: string): Promise<void>;
    /**
     * Check whether a key exists.
     * @param key - Unique identifier
     * @returns `true` if key exists
     */
    has(key: string): Promise<boolean>;
    /**
     * Return the number of stored items.
     * @returns Count of items
     */
    count(): Promise<number>;
    /**
     * Remove all items from storage.
     */
    clear(): Promise<void>;
    /**
     * Release any resources held by this adapter (DB connections, file handles).
     * Optional — adapters that don't hold resources need not implement this.
     */
    dispose?(): Promise<void>;
}
/**
 * In-memory storage adapter backed by a `Map`.
 * Suitable for development, testing, and short-lived processes.
 * Data is lost when the process exits.
 *
 * @typeParam T - The type of stored items
 *
 * @example
 * ```typescript
 * const store = new InMemoryStorage<{ name: string }>();
 * await store.create("k1", { name: "Alice" });
 * await store.create("k2", { name: "Bob" });
 * const items = await store.list({ filter: i => i.name.startsWith("A") });
 * // [{ name: "Alice" }]
 * ```
 */
declare class InMemoryStorage<T> implements IStorageAdapter<T> {
    private readonly data;
    /** @inheritdoc */
    get(key: string): Promise<T | null>;
    /** @inheritdoc */
    list(options?: ListOptions<T>): Promise<T[]>;
    /** @inheritdoc */
    create(key: string, item: T): Promise<void>;
    /** @inheritdoc */
    update(key: string, item: T): Promise<void>;
    /** @inheritdoc */
    delete(key: string): Promise<void>;
    /** @inheritdoc */
    has(key: string): Promise<boolean>;
    /** @inheritdoc */
    count(): Promise<number>;
    /** @inheritdoc */
    clear(): Promise<void>;
}
/**
 * Options for configuring `FileStorage`.
 */
interface FileStorageOptions {
    /** Directory path where JSON files are stored */
    directory: string;
    /** File extension (default: `.json`) */
    extension?: string;
}
/**
 * File-based storage adapter that persists each item as a JSON file.
 * Suitable for local applications, CLI tools, and development.
 * Creates the storage directory if it doesn't exist.
 *
 * @typeParam T - The type of stored items (must be JSON-serializable)
 *
 * @example
 * ```typescript
 * const store = new FileStorage<ChatSession>({
 *   directory: "./data/sessions",
 * });
 * await store.create("session-1", mySession);
 * ```
 */
declare class FileStorage<T> implements IStorageAdapter<T> {
    private readonly directory;
    private readonly extension;
    constructor(options: FileStorageOptions);
    /** @inheritdoc */
    get(key: string): Promise<T | null>;
    /** @inheritdoc */
    list(options?: ListOptions<T>): Promise<T[]>;
    /** @inheritdoc */
    create(key: string, item: T): Promise<void>;
    /** @inheritdoc */
    update(key: string, item: T): Promise<void>;
    /** @inheritdoc */
    delete(key: string): Promise<void>;
    /** @inheritdoc */
    has(key: string): Promise<boolean>;
    /** @inheritdoc */
    count(): Promise<number>;
    /** @inheritdoc */
    clear(): Promise<void>;
    private keyToPath;
    private ensureDirectory;
    private readFile;
    private writeFile;
}

export { FileStorage, type FileStorageOptions, type IStorageAdapter, InMemoryStorage, type ListOptions, StorageError, type StorageErrorCode };
