UNPKG

@hashgraphonline/conversational-agent

Version:

Hashgraph Online conversational AI agent implementing HCS-10 communication, HCS-2 registries, and content inscription on Hedera. https://hol.org

191 lines (190 loc) 5.46 kB
import { ContentStorage } from "./index22.js"; import { Logger, ContentStoreService, ContentResolverRegistry, shouldUseReference, extractReferenceId } from "@hashgraphonline/standards-sdk"; class ContentStorageAdapter { constructor(storage) { this.storage = storage; } async storeContent(content, metadata) { const storeMetadata = { contentType: "binary", sizeBytes: content.length, source: "system", ...metadata }; const contentRef = await this.storage.storeContent(content, storeMetadata); return contentRef.referenceId; } async resolveReference(referenceId) { const result = await this.storage.resolveReference(referenceId); if (result.success && result.content) { const response = { content: result.content }; if (result.metadata) { response.metadata = { ...result.metadata.mimeType !== void 0 && { mimeType: result.metadata.mimeType }, ...result.metadata.fileName !== void 0 && { fileName: result.metadata.fileName }, originalSize: result.metadata.sizeBytes }; } return response; } else { throw new Error(result.error || "Reference not found"); } } async hasReference(referenceId) { return await this.storage.hasReference(referenceId); } async cleanupReference(referenceId) { await this.storage.cleanupReference(referenceId); } async getStats() { return await this.storage.getStats(); } async updateConfig(config) { const referenceConfig = { sizeThresholdBytes: config.maxSize || 10240, enableAutoCleanup: config.enableCompression || true, ...config }; return await this.storage.updateConfig(referenceConfig); } async performCleanup() { await this.storage.performCleanup(); } async dispose() { return Promise.resolve(this.storage.dispose()); } } class ContentResolver { constructor(adapter) { this.adapter = adapter; } async resolveReference(referenceId) { return await this.adapter.resolveReference(referenceId); } shouldUseReference(content) { return shouldUseReference(content); } extractReferenceId(input) { return extractReferenceId(input); } } class ContentStoreManager { constructor(maxMessageStorage = 1e3, referenceConfig, logger) { this.isRegistered = false; this.logger = logger || new Logger({ module: "ContentStoreManager" }); this.contentStorage = new ContentStorage( maxMessageStorage, referenceConfig ); this.adapter = new ContentStorageAdapter(this.contentStorage); this.resolver = new ContentResolver(this.adapter); } /** * Initialize and register content storage for cross-package access */ async initialize() { if (this.isRegistered) { this.logger.warn("ContentStoreManager is already initialized"); return; } try { if (ContentStoreService && typeof ContentStoreService.setInstance === "function") { await ContentStoreService.setInstance( this.adapter ); } else { this.logger.warn("ContentStoreService.setInstance is unavailable; skipping registration"); } if (ContentResolverRegistry && typeof ContentResolverRegistry.register === "function") { ContentResolverRegistry.register( this.resolver ); } else { this.logger.warn("ContentResolverRegistry.register is unavailable; skipping registration"); } this.isRegistered = true; this.logger.info( "ContentStoreManager initialized and registered for cross-package access" ); } catch (error) { this.logger.error("Failed to initialize ContentStoreManager:", error); throw error; } } /** * Get the underlying ContentStorage instance */ getContentStorage() { return this.contentStorage; } /** * Get storage statistics */ async getStats() { return await this.contentStorage.getStats(); } /** * Update configuration */ async updateConfig(config) { return await this.contentStorage.updateConfig(config); } /** * Perform manual cleanup */ async performCleanup() { return await this.contentStorage.performCleanup(); } /** * Check if content should be stored as reference */ shouldUseReference(content) { return this.contentStorage.shouldUseReference(content); } /** * Store content if it's large enough */ async storeContentIfLarge(content, metadata) { const storeMetadata = { source: "system", contentType: "binary", ...metadata }; return await this.contentStorage.storeContentIfLarge( content, storeMetadata ); } /** * Cleanup and unregister */ async dispose() { if (this.isRegistered) { this.contentStorage.dispose(); if (ContentStoreService && typeof ContentStoreService.dispose === "function") { ContentStoreService.dispose(); } if (ContentResolverRegistry && typeof ContentResolverRegistry.unregister === "function") { ContentResolverRegistry.unregister(); } this.isRegistered = false; this.logger.info("ContentStoreManager disposed and unregistered"); } } /** * Check if the manager is initialized */ isInitialized() { return this.isRegistered; } } export { ContentStoreManager }; //# sourceMappingURL=index25.js.map