import { ContainerRepository, ImageRepository, SessionRepository, LLMProviderRepository, PrototypeRepository, ContainerRecord, ImageRecord, ImageMetadata, LLMProviderRecord, PrototypeRecord, SessionRecord } from '@agentxjs/core/persistence'; import { Storage } from 'unstorage'; import { Message } from '@agentxjs/core/agent'; /** * Persistence Types for Node Provider */ /** * Persistence driver interface * * Each driver must implement this interface. * The createStorage() method is called once during initialization. */ interface PersistenceDriver { /** * Create the underlying storage instance */ createStorage(): Promise; } /** * Persistence - Aggregated repositories */ interface Persistence { readonly containers: ContainerRepository; readonly images: ImageRepository; readonly sessions: SessionRepository; readonly llmProviders: LLMProviderRepository; readonly prototypes: PrototypeRepository; } /** * Memory Driver - In-memory storage * * Useful for testing and development. * Data is lost when the process exits. * * @example * ```typescript * import { createPersistence, memoryDriver } from "@agentxjs/node-platform/persistence"; * * const persistence = await createPersistence(memoryDriver()); * ``` */ /** * Create a memory driver */ declare function memoryDriver(): PersistenceDriver; /** * Persistence - Core persistence implementation * * Creates a Persistence instance from a driver. * Each driver provides a createStorage() method that returns an unstorage Storage instance. */ /** * Create a Persistence instance from a driver * * @param driver - The persistence driver to use * @returns Promise instance * * @example * ```typescript * import { createPersistence, memoryDriver } from "@agentxjs/node-platform/persistence"; * * const persistence = await createPersistence(memoryDriver()); * ``` */ declare function createPersistence(driver: PersistenceDriver): Promise; /** * StorageContainerRepository - unstorage-based ContainerRepository * * Uses unstorage for backend-agnostic storage (Memory, Redis, SQLite, etc.) */ /** * StorageContainerRepository - unstorage implementation */ declare class StorageContainerRepository implements ContainerRepository { private readonly storage; constructor(storage: Storage); private key; saveContainer(record: ContainerRecord): Promise; findContainerById(containerId: string): Promise; findAllContainers(): Promise; deleteContainer(containerId: string): Promise; containerExists(containerId: string): Promise; } /** * StorageImageRepository - unstorage-based ImageRepository * * Uses unstorage for backend-agnostic storage (Memory, Redis, SQLite, etc.) */ /** * StorageImageRepository - unstorage implementation */ declare class StorageImageRepository implements ImageRepository { private readonly storage; constructor(storage: Storage); private key; private nameIndexKey; private containerIndexKey; saveImage(record: ImageRecord): Promise; findImageById(imageId: string): Promise; findAllImages(): Promise; findImagesByName(name: string): Promise; findImagesByContainerId(containerId: string): Promise; deleteImage(imageId: string): Promise; imageExists(imageId: string): Promise; updateMetadata(imageId: string, metadata: Partial): Promise; } /** * StorageLLMProviderRepository - unstorage-based LLMProviderRepository * * Uses unstorage for backend-agnostic storage (Memory, Redis, SQLite, etc.) */ /** * StorageLLMProviderRepository - unstorage implementation */ declare class StorageLLMProviderRepository implements LLMProviderRepository { private readonly storage; constructor(storage: Storage); private key; private containerIndexKey; saveLLMProvider(record: LLMProviderRecord): Promise; findLLMProviderById(id: string): Promise; findLLMProvidersByContainerId(containerId: string): Promise; deleteLLMProvider(id: string): Promise; llmProviderExists(id: string): Promise; findDefaultLLMProvider(containerId: string): Promise; setDefaultLLMProvider(id: string): Promise; } /** * StoragePrototypeRepository - unstorage-based PrototypeRepository * * Uses unstorage for backend-agnostic storage (Memory, Redis, SQLite, etc.) */ /** * StoragePrototypeRepository - unstorage implementation */ declare class StoragePrototypeRepository implements PrototypeRepository { private readonly storage; constructor(storage: Storage); private key; private containerIndexKey; savePrototype(record: PrototypeRecord): Promise; findPrototypeById(prototypeId: string): Promise; findAllPrototypes(): Promise; findPrototypesByContainerId(containerId: string): Promise; deletePrototype(prototypeId: string): Promise; prototypeExists(prototypeId: string): Promise; } /** * StorageSessionRepository - unstorage-based SessionRepository * * Uses unstorage for backend-agnostic storage (Memory, Redis, SQLite, etc.) */ /** * StorageSessionRepository - unstorage implementation */ declare class StorageSessionRepository implements SessionRepository { private readonly storage; /** Per-session write lock to prevent concurrent addMessage race conditions */ private writeLocks; constructor(storage: Storage); private key; private messagesKey; private imageIndexKey; private containerIndexKey; saveSession(record: SessionRecord): Promise; findSessionById(sessionId: string): Promise; findSessionByImageId(imageId: string): Promise; findSessionsByContainerId(containerId: string): Promise; findAllSessions(): Promise; deleteSession(sessionId: string): Promise; sessionExists(sessionId: string): Promise; addMessage(sessionId: string, message: Message): Promise; getMessages(sessionId: string): Promise; clearMessages(sessionId: string): Promise; } /** * SQLite Driver - SQLite database storage * * Uses commonxjs SQLite abstraction with automatic runtime detection: * - Bun: uses bun:sqlite (built-in) * - Node.js 22+: uses node:sqlite (built-in) * * @example * ```typescript * import { createPersistence, sqliteDriver } from "@agentxjs/node-platform/persistence"; * * const persistence = await createPersistence( * sqliteDriver({ path: "./data/agentx.db" }) * ); * ``` */ interface SqliteDriverOptions { /** * Path to SQLite database file * @example "./data/agentx.db" */ path: string; } /** * Create a SQLite driver * * @param options - Driver options */ declare function sqliteDriver(options: SqliteDriverOptions): PersistenceDriver; export { type Persistence, type PersistenceDriver, type SqliteDriverOptions, StorageContainerRepository, StorageImageRepository, StorageLLMProviderRepository, StoragePrototypeRepository, StorageSessionRepository, createPersistence, memoryDriver, sqliteDriver };