UNPKG

crewai-ts

Version:

TypeScript port of crewAI for agent-based workflows

125 lines 3.91 kB
/** * StorageAdapter Interface * * Defines the contract for all memory storage implementations * Optimized for efficient data persistence across different backends */ /** * Base interface for all storage adapters * Provides a consistent API for persisting memory items */ export interface StorageAdapter { /** * Save data with the specified key * @param key Unique identifier for the data * @param value Data to store * @returns Promise resolving when save is complete */ save(key: string, value: any): Promise<void>; /** * Load data with the specified key * @param key Unique identifier for the data * @returns Promise resolving to the data or null if not found */ load(key: string): Promise<any | null>; /** * Delete data with the specified key * @param key Unique identifier for the data to delete * @returns Promise resolving to true if data was deleted, false otherwise */ delete(key: string): Promise<boolean>; /** * Clear all data from storage * @returns Promise resolving when clear is complete */ clear(): Promise<void>; /** * Get all keys in storage * @returns Promise resolving to an array of keys */ keys(): Promise<string[]>; } /** * Options for storage adapter configuration */ export interface StorageAdapterOptions { /** * Namespace for this storage adapter, used to isolate data */ namespace?: string; /** * Whether to compress stored data */ compression?: boolean; /** * Compression level (if compression is enabled) */ compressionLevel?: number; /** * Custom serializer function for converting objects to strings */ serializer?: (value: any) => string; /** * Custom deserializer function for converting strings to objects */ deserializer?: (value: string) => any; /** * Maximum time in milliseconds that items should be stored * Items older than this will be eligible for automatic cleanup */ ttlMs?: number; /** * Debug mode flag */ debug?: boolean; } /** * Base class for storage adapters with common functionality * Provides optimized serialization, compression, and error handling */ export declare abstract class BaseStorageAdapter implements StorageAdapter { protected options: Required<StorageAdapterOptions>; constructor(options?: StorageAdapterOptions); /** * Get the full storage key with namespace * @param key The base key * @returns Namespaced key */ protected getNamespacedKey(key: string): string; /** * Serialize a value for storage with optimized handling * @param value The value to serialize * @returns Serialized value */ protected serialize(value: any): string; /** * Deserialize a value from storage with optimized handling * @param serialized The serialized value * @returns Deserialized value */ protected deserialize(serialized: string): any; /** * Compress a string * @param data The string to compress * @returns Compressed string */ protected compress(data: string): string; /** * Decompress a compressed string * @param compressed The compressed string * @returns Decompressed string */ protected decompress(compressed: string): string; /** * Check if a value has expired * @param timestamp The timestamp when the value was stored * @returns Whether the value has expired */ protected isExpired(timestamp: number): boolean; abstract save(key: string, value: any): Promise<void>; abstract load(key: string): Promise<any | null>; abstract delete(key: string): Promise<boolean>; abstract clear(): Promise<void>; abstract keys(): Promise<string[]>; } //# sourceMappingURL=StorageAdapter.d.ts.map