import { b as ChatId, g as ChatSession, c as ChatMessage, j as ChatSessionConfig } from '../types-ajANVzf7.js';
import { IStorageAdapter } from './storage.js';
export { StorageError } from './storage.js';
import '../agent-CW9XbmG_.js';
import 'zod';
import '../errors-C-so0M4t.js';
import '../types-BxggH0Yh.js';
import '../errors-CmVvczxZ.js';

/**
 * @witqq/agent-sdk/chat/sessions
 *
 * Session store layer wrapping generic storage adapters.
 * Provides session-specific operations: message management,
 * paginated retrieval, search, and session lifecycle.
 */

/** Options for creating a new session */
interface CreateSessionOptions<TCustom extends Record<string, unknown> = Record<string, unknown>> {
    /** Session title (defaults to "Untitled") */
    title?: string;
    /** Session configuration (optional — runtime defaults used when omitted) */
    config?: Partial<ChatSessionConfig>;
    /** Initial tags */
    tags?: string[];
    /** Custom metadata */
    custom?: TCustom;
}
/** Paginated result of messages */
interface PaginatedMessages {
    /** Messages in this page */
    messages: ChatMessage[];
    /** Total number of messages in session */
    total: number;
    /** Whether there are more messages after this page */
    hasMore: boolean;
}
/** Options for listing sessions */
interface SessionListOptions {
    /** Filter predicate */
    filter?: (session: ChatSession) => boolean;
    /** Sort comparator */
    sort?: (a: ChatSession, b: ChatSession) => number;
    /** Maximum number of sessions to return */
    limit?: number;
    /** Number of sessions to skip */
    offset?: number;
}
/** Search options for finding sessions */
interface SessionSearchOptions {
    /** Text query to match against title and message content */
    query: string;
    /** Maximum results (default: 20) */
    limit?: number;
}
/**
 * Read-only session operations.
 * Consumers needing read-only access (dashboards, analytics) implement only this.
 */
interface ISessionReader {
    getSession(id: ChatId): Promise<ChatSession | null>;
    listSessions(options?: SessionListOptions): Promise<ChatSession[]>;
    loadMessages(sessionId: ChatId, options?: {
        limit?: number;
        offset?: number;
    }): Promise<PaginatedMessages>;
    searchSessions(options: SessionSearchOptions): Promise<ChatSession[]>;
    count(): Promise<number>;
}
/**
 * Write/mutate session operations.
 * Consumers needing full access implement both ISessionReader & ISessionWriter.
 */
interface ISessionWriter {
    createSession(options: CreateSessionOptions): Promise<ChatSession>;
    updateTitle(id: ChatId, title: string): Promise<void>;
    updateConfig(id: ChatId, config: Partial<ChatSessionConfig>): Promise<void>;
    deleteSession(id: ChatId): Promise<void>;
    appendMessage(sessionId: ChatId, message: ChatMessage): Promise<void>;
    saveMessages(sessionId: ChatId, messages: ChatMessage[]): Promise<void>;
    clear(): Promise<void>;
    /** Release any resources held by this store (optional). */
    dispose?(): Promise<void>;
}
/**
 * Full session store interface — union of reader and writer.
 * Backward-compatible: all existing implementations continue to work.
 *
 * @example
 * ```typescript
 * const store = new InMemorySessionStore();
 * const session = await store.createSession({ config: { model: "gpt-4", backend: "vercel-ai" } });
 * await store.appendMessage(session.id, message);
 * const page = await store.loadMessages(session.id, { limit: 20, offset: 0 });
 * ```
 */
interface IChatSessionStore extends ISessionReader, ISessionWriter {
}
/**
 * Base session store implementation backed by any `IStorageAdapter<ChatSession>`.
 * Handles all session-specific logic; subclasses only need to provide the adapter.
 */
declare class BaseSessionStore implements IChatSessionStore {
    protected readonly adapter: IStorageAdapter<ChatSession>;
    constructor(adapter: IStorageAdapter<ChatSession>);
    createSession(options: CreateSessionOptions): Promise<ChatSession>;
    getSession(id: ChatId): Promise<ChatSession | null>;
    listSessions(options?: SessionListOptions): Promise<ChatSession[]>;
    updateTitle(id: ChatId, title: string): Promise<void>;
    updateConfig(id: ChatId, config: Partial<ChatSessionConfig>): Promise<void>;
    deleteSession(id: ChatId): Promise<void>;
    appendMessage(sessionId: ChatId, message: ChatMessage): Promise<void>;
    saveMessages(sessionId: ChatId, messages: ChatMessage[]): Promise<void>;
    loadMessages(sessionId: ChatId, options?: {
        limit?: number;
        offset?: number;
    }): Promise<PaginatedMessages>;
    searchSessions(options: SessionSearchOptions): Promise<ChatSession[]>;
    count(): Promise<number>;
    clear(): Promise<void>;
}
/**
 * In-memory session store. Data is lost when the process exits.
 * Uses `InMemoryStorage` internally.
 *
 * @example
 * ```typescript
 * const store = new InMemorySessionStore();
 * const session = await store.createSession({
 *   config: { model: "gpt-4", backend: "vercel-ai" },
 * });
 * ```
 */
declare class InMemorySessionStore extends BaseSessionStore {
    constructor();
}
/** Configuration for FileSessionStore */
interface FileSessionStoreOptions {
    /** Directory to store session JSON files */
    directory: string;
}
/**
 * File-based session store. Each session is a JSON file on disk.
 * Uses `FileStorage` internally.
 *
 * @example
 * ```typescript
 * const store = new FileSessionStore({ directory: "./data/sessions" });
 * const session = await store.createSession({
 *   config: { model: "claude-3", backend: "claude" },
 * });
 * ```
 */
declare class FileSessionStore extends BaseSessionStore {
    constructor(options: FileSessionStoreOptions);
}

export { type CreateSessionOptions, FileSessionStore, type FileSessionStoreOptions, type IChatSessionStore, type ISessionReader, type ISessionWriter, InMemorySessionStore, type PaginatedMessages, type SessionListOptions, type SessionSearchOptions };
