UNPKG

crewai-ts

Version:

TypeScript port of crewAI for agent-based workflows

126 lines 3.5 kB
/** * FileStorageAdapter * * A file-based implementation of the StorageAdapter interface * Optimized for persistence in Node.js environments */ import { BaseStorageAdapter, StorageAdapterOptions } from './StorageAdapter.js'; /** * FileStorageAdapter Options */ export interface FileStorageOptions extends StorageAdapterOptions { /** * Directory path where files will be stored */ directory: string; /** * Whether to use a single file for all data or separate files per key * Single file mode is faster for small datasets, separate files for large datasets */ singleFile?: boolean; /** * How often to sync data to disk (in milliseconds) * Only used in single file mode */ syncIntervalMs?: number; /** * Whether to create a backup before writing */ createBackups?: boolean; /** * Maximum backup files to keep */ maxBackups?: number; } /** * FileStorageAdapter implements the StorageAdapter interface * using the filesystem for persistent storage with optimizations * for both small and large datasets */ export declare class FileStorageAdapter extends BaseStorageAdapter { private directory; private singleFile; private singleFileData; private syncInterval; private syncTimeout; private dirtyKeys; private initialized; private createBackups; private maxBackups; constructor(options: FileStorageOptions); /** * Initialize the storage adapter */ private init; /** * Ensure initialization is complete */ private ensureInitialized; /** * Save a value with efficient file handling */ save(key: string, value: any): Promise<void>; /** * Load a value with efficient file handling */ load(key: string): Promise<any | null>; /** * Delete a value with cleanup */ delete(key: string): Promise<boolean>; /** * Clear all values with efficient cleanup */ clear(): Promise<void>; /** * Get all keys with namespace handling */ keys(): Promise<string[]>; /** * Force an immediate sync to disk */ sync(): Promise<void>; /** * Close the storage adapter and release resources */ close(): Promise<void>; /** * Helper: Schedule a sync to file */ private scheduleSyncToFile; /** * Helper: Sync changes to file */ private syncToFile; /** * Helper: Load data from single file */ private loadSingleFileData; /** * Helper: Create a backup of a file */ private createBackup; /** * Helper: Clean up old backups with memory optimized implementation * @param filePath Path to the file for which to clean up backups */ private cleanupBackups; /** * Helper: Get the file path for a single file storage with memory optimization * @returns A guaranteed string path to the storage file */ private getSingleFilePath; /** * Helper: Get the file path for a multi-file key with type safety * @param key The key to generate a file path for * @returns A guaranteed string path to the key's file */ private getFilePath; /** * Helper: Check if a file exists with memory-optimized implementation * @param filePath Path to check for existence * @returns boolean indicating if file exists */ private fileExists; } //# sourceMappingURL=FileStorageAdapter.d.ts.map