@hashgraphonline/conversational-agent
Version:
Hashgraph Online conversational AI agent implementing HCS-10 communication, HCS-2 registries, and content inscription on Hedera
152 lines (151 loc) • 4.32 kB
JavaScript
import { ContentStorage } from "./index14.js";
import { ContentStoreService, ContentResolverRegistry, shouldUseReference, extractReferenceId } from "@hashgraphonline/standards-sdk";
class ContentStorageAdapter {
constructor(storage) {
this.storage = storage;
}
async storeContent(content, metadata) {
const contentRef = await this.storage.storeContent(content, metadata);
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) {
return await this.storage.updateConfig(config);
}
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 || {
info: console.log,
debug: console.log,
warn: console.warn,
error: console.error
};
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 {
await ContentStoreService.setInstance(this.adapter);
ContentResolverRegistry.register(this.resolver);
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) {
return await this.contentStorage.storeContentIfLarge(content, metadata);
}
/**
* Cleanup and unregister
*/
async dispose() {
if (this.isRegistered) {
this.contentStorage.dispose();
ContentStoreService.dispose();
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=index17.js.map