@hashgraphonline/conversational-agent 0.1.208 → 0.1.209

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/cjs/conversational-agent.d.ts +67 -8
  2. package/dist/cjs/index.cjs +1 -1
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.ts +1 -0
  5. package/dist/cjs/langchain-agent.d.ts +8 -0
  6. package/dist/cjs/memory/SmartMemoryManager.d.ts +58 -21
  7. package/dist/cjs/memory/index.d.ts +1 -1
  8. package/dist/esm/index.js +8 -0
  9. package/dist/esm/index.js.map +1 -1
  10. package/dist/esm/index12.js +124 -46
  11. package/dist/esm/index12.js.map +1 -1
  12. package/dist/esm/index13.js +178 -13
  13. package/dist/esm/index13.js.map +1 -1
  14. package/dist/esm/index14.js +604 -100
  15. package/dist/esm/index14.js.map +1 -1
  16. package/dist/esm/index15.js +464 -9
  17. package/dist/esm/index15.js.map +1 -1
  18. package/dist/esm/index16.js +44 -172
  19. package/dist/esm/index16.js.map +1 -1
  20. package/dist/esm/index17.js +11 -156
  21. package/dist/esm/index17.js.map +1 -1
  22. package/dist/esm/index18.js +106 -191
  23. package/dist/esm/index18.js.map +1 -1
  24. package/dist/esm/index19.js +9 -660
  25. package/dist/esm/index19.js.map +1 -1
  26. package/dist/esm/index2.js +22 -13
  27. package/dist/esm/index2.js.map +1 -1
  28. package/dist/esm/index20.js +150 -206
  29. package/dist/esm/index20.js.map +1 -1
  30. package/dist/esm/index21.js +140 -166
  31. package/dist/esm/index21.js.map +1 -1
  32. package/dist/esm/index22.js +47 -105
  33. package/dist/esm/index22.js.map +1 -1
  34. package/dist/esm/index23.js +24 -89
  35. package/dist/esm/index23.js.map +1 -1
  36. package/dist/esm/index24.js +83 -56
  37. package/dist/esm/index24.js.map +1 -1
  38. package/dist/esm/index25.js +236 -32
  39. package/dist/esm/index25.js.map +1 -1
  40. package/dist/esm/index5.js +1 -1
  41. package/dist/esm/index6.js +295 -17
  42. package/dist/esm/index6.js.map +1 -1
  43. package/dist/esm/index8.js +82 -8
  44. package/dist/esm/index8.js.map +1 -1
  45. package/dist/types/conversational-agent.d.ts +67 -8
  46. package/dist/types/index.d.ts +1 -0
  47. package/dist/types/langchain-agent.d.ts +8 -0
  48. package/dist/types/memory/SmartMemoryManager.d.ts +58 -21
  49. package/dist/types/memory/index.d.ts +1 -1
  50. package/package.json +3 -3
  51. package/src/context/ReferenceContextManager.ts +9 -4
  52. package/src/context/ReferenceResponseProcessor.ts +3 -4
  53. package/src/conversational-agent.ts +379 -31
  54. package/src/index.ts +2 -0
  55. package/src/langchain/ContentAwareAgentExecutor.ts +0 -1
  56. package/src/langchain-agent.ts +94 -11
  57. package/src/mcp/ContentProcessor.ts +13 -3
  58. package/src/mcp/adapters/langchain.ts +1 -9
  59. package/src/memory/ContentStorage.ts +3 -51
  60. package/src/memory/MemoryWindow.ts +4 -16
  61. package/src/memory/ReferenceIdGenerator.ts +0 -4
  62. package/src/memory/SmartMemoryManager.ts +400 -33
  63. package/src/memory/TokenCounter.ts +12 -16
  64. package/src/memory/index.ts +1 -1
  65. package/src/plugins/hcs-10/HCS10Plugin.ts +44 -14
  66. package/src/services/ContentStoreManager.ts +0 -3
  67. package/src/types/content-reference.ts +8 -8
  68. package/src/types/index.ts +0 -1
@@ -1,236 +1,151 @@
1
- import { MemoryWindow } from "./index21.js";
2
- import { ContentStorage } from "./index19.js";
3
- import { TokenCounter } from "./index22.js";
4
- const _SmartMemoryManager = class _SmartMemoryManager {
5
- constructor(config = {}) {
6
- this.config = { ..._SmartMemoryManager.DEFAULT_CONFIG, ...config };
7
- this.tokenCounter = new TokenCounter(this.config.modelName);
8
- this.contentStorage = new ContentStorage(this.config.storageLimit);
9
- this.memoryWindow = new MemoryWindow(
10
- this.config.maxTokens,
11
- this.config.reserveTokens,
12
- this.tokenCounter
13
- );
14
- }
15
- /**
16
- * Add a message to the active memory window
17
- * Automatically handles pruning and storage of displaced messages
18
- * @param message - Message to add
19
- */
20
- addMessage(message) {
21
- const result = this.memoryWindow.addMessage(message);
22
- if (result.prunedMessages.length > 0) {
23
- this.contentStorage.storeMessages(result.prunedMessages);
1
+ import { ContentStorage } from "./index14.js";
2
+ import { ContentStoreService, ContentResolverRegistry, shouldUseReference, extractReferenceId } from "@hashgraphonline/standards-sdk";
3
+ class ContentStorageAdapter {
4
+ constructor(storage) {
5
+ this.storage = storage;
6
+ }
7
+ async storeContent(content, metadata) {
8
+ const contentRef = await this.storage.storeContent(content, metadata);
9
+ return contentRef.referenceId;
10
+ }
11
+ async resolveReference(referenceId) {
12
+ const result = await this.storage.resolveReference(referenceId);
13
+ if (result.success && result.content) {
14
+ const response = {
15
+ content: result.content
16
+ };
17
+ if (result.metadata) {
18
+ response.metadata = {
19
+ ...result.metadata.mimeType !== void 0 && { mimeType: result.metadata.mimeType },
20
+ ...result.metadata.fileName !== void 0 && { fileName: result.metadata.fileName },
21
+ originalSize: result.metadata.sizeBytes
22
+ };
23
+ }
24
+ return response;
25
+ } else {
26
+ throw new Error(result.error || "Reference not found");
24
27
  }
25
28
  }
26
- /**
27
- * Get all active messages from the memory window
28
- * @returns Array of active messages in chronological order
29
- */
30
- getMessages() {
31
- return this.memoryWindow.getMessages();
29
+ async hasReference(referenceId) {
30
+ return await this.storage.hasReference(referenceId);
32
31
  }
33
- /**
34
- * Clear active memory window
35
- * @param clearStorage - Whether to also clear the content storage (default: false)
36
- */
37
- clear(clearStorage = false) {
38
- this.memoryWindow.clear();
39
- if (clearStorage) {
40
- this.contentStorage.clear();
41
- }
32
+ async cleanupReference(referenceId) {
33
+ await this.storage.cleanupReference(referenceId);
42
34
  }
43
- /**
44
- * Set the system prompt for the memory window
45
- * @param systemPrompt - System prompt text
46
- */
47
- setSystemPrompt(systemPrompt) {
48
- this.memoryWindow.setSystemPrompt(systemPrompt);
35
+ async getStats() {
36
+ return await this.storage.getStats();
49
37
  }
50
- /**
51
- * Get the current system prompt
52
- * @returns Current system prompt text
53
- */
54
- getSystemPrompt() {
55
- return this.memoryWindow.getSystemPrompt();
38
+ async updateConfig(config) {
39
+ return await this.storage.updateConfig(config);
56
40
  }
57
- /**
58
- * Search through stored message history
59
- * @param query - Search term or pattern
60
- * @param options - Search configuration
61
- * @returns Array of matching messages from history
62
- */
63
- searchHistory(query, options = {}) {
64
- return this.contentStorage.searchMessages(query, options);
41
+ async performCleanup() {
42
+ await this.storage.performCleanup();
65
43
  }
66
- /**
67
- * Get recent messages from storage history
68
- * @param count - Number of recent messages to retrieve
69
- * @returns Array of recent messages from storage
70
- */
71
- getRecentHistory(count) {
72
- return this.contentStorage.getRecentMessages(count);
44
+ async dispose() {
45
+ return Promise.resolve(this.storage.dispose());
73
46
  }
74
- /**
75
- * Check if a message can be added without exceeding limits
76
- * @param message - Message to test
77
- * @returns True if message can be added
78
- */
79
- canAddMessage(message) {
80
- return this.memoryWindow.canAddMessage(message);
47
+ }
48
+ class ContentResolver {
49
+ constructor(adapter) {
50
+ this.adapter = adapter;
81
51
  }
82
- /**
83
- * Get statistics about the active memory window
84
- * @returns Memory usage statistics
85
- */
86
- getMemoryStats() {
87
- const windowStats = this.memoryWindow.getStats();
88
- return {
89
- totalActiveMessages: windowStats.totalMessages,
90
- currentTokenCount: windowStats.currentTokens,
91
- maxTokens: windowStats.maxTokens,
92
- remainingCapacity: windowStats.remainingCapacity,
93
- systemPromptTokens: windowStats.systemPromptTokens,
94
- usagePercentage: windowStats.usagePercentage
95
- };
52
+ async resolveReference(referenceId) {
53
+ return await this.adapter.resolveReference(referenceId);
96
54
  }
97
- /**
98
- * Get statistics about the content storage
99
- * @returns Storage usage statistics
100
- */
101
- getStorageStats() {
102
- return this.contentStorage.getStorageStats();
55
+ shouldUseReference(content) {
56
+ return shouldUseReference(content);
103
57
  }
104
- /**
105
- * Get combined statistics for both active memory and storage
106
- * @returns Combined memory and storage statistics
107
- */
108
- getOverallStats() {
109
- const memoryStats = this.getMemoryStats();
110
- const storageStats = this.getStorageStats();
111
- return {
112
- activeMemory: memoryStats,
113
- storage: storageStats,
114
- totalMessagesManaged: memoryStats.totalActiveMessages + storageStats.totalMessages,
115
- activeMemoryUtilization: memoryStats.usagePercentage,
116
- storageUtilization: storageStats.usagePercentage
58
+ extractReferenceId(input) {
59
+ return extractReferenceId(input);
60
+ }
61
+ }
62
+ class ContentStoreManager {
63
+ constructor(maxMessageStorage = 1e3, referenceConfig, logger) {
64
+ this.isRegistered = false;
65
+ this.logger = logger || {
66
+ info: console.log,
67
+ debug: console.log,
68
+ warn: console.warn,
69
+ error: console.error
117
70
  };
71
+ this.contentStorage = new ContentStorage(maxMessageStorage, referenceConfig);
72
+ this.adapter = new ContentStorageAdapter(this.contentStorage);
73
+ this.resolver = new ContentResolver(this.adapter);
118
74
  }
119
75
  /**
120
- * Update the configuration and apply changes
121
- * @param newConfig - New configuration options
76
+ * Initialize and register content storage for cross-package access
122
77
  */
123
- updateConfig(newConfig) {
124
- this.config = { ...this.config, ...newConfig };
125
- if (newConfig.maxTokens !== void 0 || newConfig.reserveTokens !== void 0) {
126
- this.memoryWindow.updateLimits(
127
- this.config.maxTokens,
128
- this.config.reserveTokens
129
- );
78
+ async initialize() {
79
+ if (this.isRegistered) {
80
+ this.logger.warn("ContentStoreManager is already initialized");
81
+ return;
130
82
  }
131
- if (newConfig.storageLimit !== void 0) {
132
- this.contentStorage.updateStorageLimit(this.config.storageLimit);
83
+ try {
84
+ await ContentStoreService.setInstance(this.adapter);
85
+ ContentResolverRegistry.register(this.resolver);
86
+ this.isRegistered = true;
87
+ this.logger.info("ContentStoreManager initialized and registered for cross-package access");
88
+ } catch (error) {
89
+ this.logger.error("Failed to initialize ContentStoreManager:", error);
90
+ throw error;
133
91
  }
134
92
  }
135
93
  /**
136
- * Get current configuration
137
- * @returns Current configuration settings
94
+ * Get the underlying ContentStorage instance
138
95
  */
139
- getConfig() {
140
- return { ...this.config };
96
+ getContentStorage() {
97
+ return this.contentStorage;
141
98
  }
142
99
  /**
143
- * Get messages from storage within a time range
144
- * @param startTime - Start of time range
145
- * @param endTime - End of time range
146
- * @returns Messages within the specified time range
100
+ * Get storage statistics
147
101
  */
148
- getHistoryFromTimeRange(startTime, endTime) {
149
- return this.contentStorage.getMessagesFromTimeRange(startTime, endTime);
102
+ async getStats() {
103
+ return await this.contentStorage.getStats();
150
104
  }
151
105
  /**
152
- * Get messages from storage by message type
153
- * @param messageType - Type of messages to retrieve ('human', 'ai', 'system', etc.)
154
- * @param limit - Maximum number of messages to return
155
- * @returns Messages of the specified type
106
+ * Update configuration
156
107
  */
157
- getHistoryByType(messageType, limit) {
158
- return this.contentStorage.getMessagesByType(messageType, limit);
108
+ async updateConfig(config) {
109
+ return await this.contentStorage.updateConfig(config);
159
110
  }
160
111
  /**
161
- * Get recent messages from storage within the last N minutes
162
- * @param minutes - Number of minutes to look back
163
- * @returns Messages from the last N minutes
112
+ * Perform manual cleanup
164
113
  */
165
- getRecentHistoryByTime(minutes) {
166
- return this.contentStorage.getRecentMessagesByTime(minutes);
114
+ async performCleanup() {
115
+ return await this.contentStorage.performCleanup();
167
116
  }
168
117
  /**
169
- * Export the current state for persistence or analysis
170
- * @returns Serializable representation of memory state
118
+ * Check if content should be stored as reference
171
119
  */
172
- exportState() {
173
- return {
174
- config: this.config,
175
- activeMessages: this.memoryWindow.getMessages().map((msg) => ({
176
- content: msg.content,
177
- type: msg._getType()
178
- })),
179
- systemPrompt: this.memoryWindow.getSystemPrompt(),
180
- memoryStats: this.getMemoryStats(),
181
- storageStats: this.getStorageStats(),
182
- storedMessages: this.contentStorage.exportMessages()
183
- };
120
+ shouldUseReference(content) {
121
+ return this.contentStorage.shouldUseReference(content);
184
122
  }
185
123
  /**
186
- * Get a summary of conversation context for external use
187
- * Useful for providing context to other systems or for logging
188
- * @param includeStoredContext - Whether to include recent stored messages
189
- * @returns Context summary object
124
+ * Store content if it's large enough
190
125
  */
191
- getContextSummary(includeStoredContext = false) {
192
- const activeMessages = this.getMessages();
193
- const summary = {
194
- activeMessageCount: activeMessages.length,
195
- systemPrompt: this.getSystemPrompt(),
196
- recentMessages: activeMessages.slice(-5),
197
- // Last 5 active messages
198
- memoryUtilization: this.getMemoryStats().usagePercentage,
199
- hasStoredHistory: this.getStorageStats().totalMessages > 0
200
- };
201
- if (includeStoredContext) {
202
- return {
203
- ...summary,
204
- recentStoredMessages: this.getRecentHistory(10),
205
- // Last 10 stored messages
206
- storageStats: this.getStorageStats()
207
- };
208
- }
209
- return summary;
126
+ async storeContentIfLarge(content, metadata) {
127
+ return await this.contentStorage.storeContentIfLarge(content, metadata);
210
128
  }
211
129
  /**
212
- * Perform maintenance operations
213
- * Optimizes storage and cleans up resources
130
+ * Cleanup and unregister
214
131
  */
215
- performMaintenance() {
132
+ async dispose() {
133
+ if (this.isRegistered) {
134
+ this.contentStorage.dispose();
135
+ ContentStoreService.dispose();
136
+ ContentResolverRegistry.unregister();
137
+ this.isRegistered = false;
138
+ this.logger.info("ContentStoreManager disposed and unregistered");
139
+ }
216
140
  }
217
141
  /**
218
- * Clean up resources and dispose of components
142
+ * Check if the manager is initialized
219
143
  */
220
- dispose() {
221
- this.memoryWindow.dispose();
222
- this.contentStorage.dispose();
223
- this.tokenCounter.dispose();
144
+ isInitialized() {
145
+ return this.isRegistered;
224
146
  }
225
- };
226
- _SmartMemoryManager.DEFAULT_CONFIG = {
227
- maxTokens: 8e3,
228
- reserveTokens: 1e3,
229
- modelName: "gpt-4o",
230
- storageLimit: 1e3
231
- };
232
- let SmartMemoryManager = _SmartMemoryManager;
147
+ }
233
148
  export {
234
- SmartMemoryManager
149
+ ContentStoreManager
235
150
  };
236
151
  //# sourceMappingURL=index18.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index18.js","sources":["../../src/memory/SmartMemoryManager.ts"],"sourcesContent":["import type { BaseMessage } from '@langchain/core/messages';\nimport { MemoryWindow } from './MemoryWindow';\nimport { ContentStorage } from './ContentStorage';\nimport { TokenCounter } from './TokenCounter';\n\n/**\n * Configuration for SmartMemoryManager\n */\nexport interface SmartMemoryConfig {\n /** Maximum tokens for active memory window */\n maxTokens?: number;\n /** Reserve tokens for response generation */\n reserveTokens?: number;\n /** Model name for token counting */\n modelName?: string;\n /** Maximum messages to store in content storage */\n storageLimit?: number;\n}\n\n/**\n * Search options for history search\n */\nexport interface SearchOptions {\n /** Whether to perform case-sensitive search */\n caseSensitive?: boolean;\n /** Maximum number of results to return */\n limit?: number;\n /** Whether to use regex pattern matching */\n useRegex?: boolean;\n}\n\n/**\n * Memory statistics for active memory window\n */\nexport interface MemoryStats {\n /** Total active messages in memory window */\n totalActiveMessages: number;\n /** Current token count including system prompt */\n currentTokenCount: number;\n /** Maximum token capacity */\n maxTokens: number;\n /** Remaining token capacity */\n remainingCapacity: number;\n /** System prompt token count */\n systemPromptTokens: number;\n /** Memory usage percentage */\n usagePercentage: number;\n}\n\n/**\n * Smart memory manager that combines active memory window with long-term storage\n * Provides context-aware memory management with automatic pruning and searchable history\n */\nexport class SmartMemoryManager {\n private memoryWindow: MemoryWindow;\n private contentStorage: ContentStorage;\n private tokenCounter: TokenCounter;\n private config: Required<SmartMemoryConfig>;\n\n // Default configuration values\n private static readonly DEFAULT_CONFIG: Required<SmartMemoryConfig> = {\n maxTokens: 8000,\n reserveTokens: 1000,\n modelName: 'gpt-4o',\n storageLimit: 1000\n };\n\n constructor(config: SmartMemoryConfig = {}) {\n this.config = { ...SmartMemoryManager.DEFAULT_CONFIG, ...config };\n \n // Initialize components\n this.tokenCounter = new TokenCounter(this.config.modelName as any);\n this.contentStorage = new ContentStorage(this.config.storageLimit);\n this.memoryWindow = new MemoryWindow(\n this.config.maxTokens,\n this.config.reserveTokens,\n this.tokenCounter\n );\n }\n\n /**\n * Add a message to the active memory window\n * Automatically handles pruning and storage of displaced messages\n * @param message - Message to add\n */\n addMessage(message: BaseMessage): void {\n const result = this.memoryWindow.addMessage(message);\n \n // Store any pruned messages in content storage\n if (result.prunedMessages.length > 0) {\n this.contentStorage.storeMessages(result.prunedMessages);\n }\n }\n\n /**\n * Get all active messages from the memory window\n * @returns Array of active messages in chronological order\n */\n getMessages(): BaseMessage[] {\n return this.memoryWindow.getMessages();\n }\n\n /**\n * Clear active memory window\n * @param clearStorage - Whether to also clear the content storage (default: false)\n */\n clear(clearStorage: boolean = false): void {\n this.memoryWindow.clear();\n \n if (clearStorage) {\n this.contentStorage.clear();\n }\n }\n\n /**\n * Set the system prompt for the memory window\n * @param systemPrompt - System prompt text\n */\n setSystemPrompt(systemPrompt: string): void {\n this.memoryWindow.setSystemPrompt(systemPrompt);\n }\n\n /**\n * Get the current system prompt\n * @returns Current system prompt text\n */\n getSystemPrompt(): string {\n return this.memoryWindow.getSystemPrompt();\n }\n\n /**\n * Search through stored message history\n * @param query - Search term or pattern\n * @param options - Search configuration\n * @returns Array of matching messages from history\n */\n searchHistory(query: string, options: SearchOptions = {}): BaseMessage[] {\n return this.contentStorage.searchMessages(query, options);\n }\n\n /**\n * Get recent messages from storage history\n * @param count - Number of recent messages to retrieve\n * @returns Array of recent messages from storage\n */\n getRecentHistory(count: number): BaseMessage[] {\n return this.contentStorage.getRecentMessages(count);\n }\n\n /**\n * Check if a message can be added without exceeding limits\n * @param message - Message to test\n * @returns True if message can be added\n */\n canAddMessage(message: BaseMessage): boolean {\n return this.memoryWindow.canAddMessage(message);\n }\n\n /**\n * Get statistics about the active memory window\n * @returns Memory usage statistics\n */\n getMemoryStats(): MemoryStats {\n const windowStats = this.memoryWindow.getStats();\n \n return {\n totalActiveMessages: windowStats.totalMessages,\n currentTokenCount: windowStats.currentTokens,\n maxTokens: windowStats.maxTokens,\n remainingCapacity: windowStats.remainingCapacity,\n systemPromptTokens: windowStats.systemPromptTokens,\n usagePercentage: windowStats.usagePercentage\n };\n }\n\n /**\n * Get statistics about the content storage\n * @returns Storage usage statistics\n */\n getStorageStats() {\n return this.contentStorage.getStorageStats();\n }\n\n /**\n * Get combined statistics for both active memory and storage\n * @returns Combined memory and storage statistics\n */\n getOverallStats() {\n const memoryStats = this.getMemoryStats();\n const storageStats = this.getStorageStats();\n \n return {\n activeMemory: memoryStats,\n storage: storageStats,\n totalMessagesManaged: memoryStats.totalActiveMessages + storageStats.totalMessages,\n activeMemoryUtilization: memoryStats.usagePercentage,\n storageUtilization: storageStats.usagePercentage\n };\n }\n\n /**\n * Update the configuration and apply changes\n * @param newConfig - New configuration options\n */\n updateConfig(newConfig: Partial<SmartMemoryConfig>): void {\n this.config = { ...this.config, ...newConfig };\n \n // Update components with new configuration\n if (newConfig.maxTokens !== undefined || newConfig.reserveTokens !== undefined) {\n this.memoryWindow.updateLimits(\n this.config.maxTokens,\n this.config.reserveTokens\n );\n }\n \n if (newConfig.storageLimit !== undefined) {\n this.contentStorage.updateStorageLimit(this.config.storageLimit);\n }\n \n // Note: Model name changes would require recreating the token counter\n // This is not implemented to avoid disrupting ongoing operations\n }\n\n /**\n * Get current configuration\n * @returns Current configuration settings\n */\n getConfig(): Required<SmartMemoryConfig> {\n return { ...this.config };\n }\n\n /**\n * Get messages from storage within a time range\n * @param startTime - Start of time range\n * @param endTime - End of time range\n * @returns Messages within the specified time range\n */\n getHistoryFromTimeRange(startTime: Date, endTime: Date): BaseMessage[] {\n return this.contentStorage.getMessagesFromTimeRange(startTime, endTime);\n }\n\n /**\n * Get messages from storage by message type\n * @param messageType - Type of messages to retrieve ('human', 'ai', 'system', etc.)\n * @param limit - Maximum number of messages to return\n * @returns Messages of the specified type\n */\n getHistoryByType(messageType: string, limit?: number): BaseMessage[] {\n return this.contentStorage.getMessagesByType(messageType, limit);\n }\n\n /**\n * Get recent messages from storage within the last N minutes\n * @param minutes - Number of minutes to look back\n * @returns Messages from the last N minutes\n */\n getRecentHistoryByTime(minutes: number): BaseMessage[] {\n return this.contentStorage.getRecentMessagesByTime(minutes);\n }\n\n /**\n * Export the current state for persistence or analysis\n * @returns Serializable representation of memory state\n */\n exportState() {\n return {\n config: this.config,\n activeMessages: this.memoryWindow.getMessages().map(msg => ({\n content: msg.content,\n type: msg._getType()\n })),\n systemPrompt: this.memoryWindow.getSystemPrompt(),\n memoryStats: this.getMemoryStats(),\n storageStats: this.getStorageStats(),\n storedMessages: this.contentStorage.exportMessages()\n };\n }\n\n /**\n * Get a summary of conversation context for external use\n * Useful for providing context to other systems or for logging\n * @param includeStoredContext - Whether to include recent stored messages\n * @returns Context summary object\n */\n getContextSummary(includeStoredContext: boolean = false) {\n const activeMessages = this.getMessages();\n const summary = {\n activeMessageCount: activeMessages.length,\n systemPrompt: this.getSystemPrompt(),\n recentMessages: activeMessages.slice(-5), // Last 5 active messages\n memoryUtilization: this.getMemoryStats().usagePercentage,\n hasStoredHistory: this.getStorageStats().totalMessages > 0\n };\n\n if (includeStoredContext) {\n return {\n ...summary,\n recentStoredMessages: this.getRecentHistory(10), // Last 10 stored messages\n storageStats: this.getStorageStats()\n };\n }\n\n return summary;\n }\n\n /**\n * Perform maintenance operations\n * Optimizes storage and cleans up resources\n */\n performMaintenance(): void {\n // No specific maintenance needed currently\n // This method is reserved for future optimizations\n }\n\n /**\n * Clean up resources and dispose of components\n */\n dispose(): void {\n this.memoryWindow.dispose();\n this.contentStorage.dispose();\n this.tokenCounter.dispose();\n }\n}"],"names":[],"mappings":";;;AAqDO,MAAM,sBAAN,MAAM,oBAAmB;AAAA,EAc9B,YAAY,SAA4B,IAAI;AAC1C,SAAK,SAAS,EAAE,GAAG,oBAAmB,gBAAgB,GAAG,OAAA;AAGzD,SAAK,eAAe,IAAI,aAAa,KAAK,OAAO,SAAgB;AACjE,SAAK,iBAAiB,IAAI,eAAe,KAAK,OAAO,YAAY;AACjE,SAAK,eAAe,IAAI;AAAA,MACtB,KAAK,OAAO;AAAA,MACZ,KAAK,OAAO;AAAA,MACZ,KAAK;AAAA,IAAA;AAAA,EAET;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,SAA4B;AACrC,UAAM,SAAS,KAAK,aAAa,WAAW,OAAO;AAGnD,QAAI,OAAO,eAAe,SAAS,GAAG;AACpC,W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EACnB;AAAA,MACF,cAAc,KAAK,aAAa,gBAAA;AAAA,MAChC,aAAa,KAAK,eAAA;AAAA,MAClB,cAAc,KAAK,gBAAA;AAAA,MACnB,gBAAgB,KAAK,eAAe,eAAA;AAAA,IAAe;AAAA,EAEvD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,kBAAkB,uBAAgC,OAAO;AACvD,UAAM,iBAAiB,KAAK,YAAA;AAC5B,UAAM,UAAU;AAAA,MACd,oBAAoB,eAAe;AAAA,MACnC,cAAc,KAAK,gBAAA;AAAA,MACnB,gBAAgB,eAAe,MAAM,EAAE;AAAA;AAAA,MACvC,mBAAmB,KAAK,eAAA,EAAiB;AAAA,MACzC,kBAAkB,KAAK,gBAAA,EAAkB,gBAAgB;AAAA,IAAA;AAG3D,QAAI,sBAAsB;AACxB,aAAO;AAAA,QACL,GAAG;AAAA,QACH,sBAAsB,KAAK,iBAAiB,EAAE;AAAA;AAAA,QAC9C,cAAc,KAAK,gBAAA;AAAA,MAAgB;AAAA,IAEvC;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAA2B;AAAA,EAG3B;AAAA;AAAA;AAAA;AAAA,EAKA,UAAgB;AACd,SAAK,aAAa,QAAA;AAClB,SAAK,eAAe,QAAA;AACpB,SAAK,aAAa,QAAA;AAAA,EACpB;AACF;AAtQE,oBAAwB,iBAA8C;AAAA,EACpE,WAAW;AAAA,EACX,eAAe;AAAA,EACf,WAAW;AAAA,EACX,cAAc;AAAA;AAXX,IAAM,qBAAN;"}
1
+ {"version":3,"file":"index18.js","sources":["../../src/services/ContentStoreManager.ts"],"sourcesContent":["import { ContentStorage } from '../memory/ContentStorage';\nimport { \n ContentStoreService, \n extractReferenceId, \n shouldUseReference,\n ContentResolverRegistry,\n type ContentStoreInterface, \n type ContentResolverInterface, \n type ReferenceResolutionResult \n} from '@hashgraphonline/standards-sdk';\nimport type { ContentReferenceConfig } from '../types/content-reference';\nimport { Logger } from '@hashgraphonline/standards-sdk';\n\n/**\n * Adapter to make ContentStorage compatible with ContentStoreInterface\n */\nclass ContentStorageAdapter implements ContentStoreInterface {\n constructor(private storage: ContentStorage) {}\n\n async storeContent(content: Buffer, metadata: any) {\n const contentRef = await this.storage.storeContent(content, metadata);\n return contentRef.referenceId;\n }\n\n async resolveReference(referenceId: string): Promise<ReferenceResolutionResult> {\n const result = await this.storage.resolveReference(referenceId);\n if (result.success && result.content) {\n const response: ReferenceResolutionResult = {\n content: result.content\n };\n if (result.metadata) {\n response.metadata = {\n ...(result.metadata.mimeType !== undefined && { mimeType: result.metadata.mimeType }),\n ...(result.metadata.fileName !== undefined && { fileName: result.metadata.fileName }),\n originalSize: result.metadata.sizeBytes\n };\n }\n return response;\n } else {\n throw new Error(result.error || 'Reference not found');\n }\n }\n\n async hasReference(referenceId: string) {\n return await this.storage.hasReference(referenceId);\n }\n\n async cleanupReference(referenceId: string) {\n await this.storage.cleanupReference(referenceId);\n }\n\n async getStats() {\n return await this.storage.getStats();\n }\n\n async updateConfig(config: any) {\n return await this.storage.updateConfig(config);\n }\n\n async performCleanup() {\n await this.storage.performCleanup();\n }\n\n async dispose() {\n return Promise.resolve(this.storage.dispose());\n }\n}\n\n/**\n * Content resolver implementation for dependency injection\n */\nclass ContentResolver implements ContentResolverInterface {\n constructor(private adapter: ContentStorageAdapter) {}\n\n async resolveReference(referenceId: string): Promise<ReferenceResolutionResult> {\n return await this.adapter.resolveReference(referenceId);\n }\n\n shouldUseReference(content: string | Buffer): boolean {\n return shouldUseReference(content);\n }\n\n extractReferenceId(input: string): string | null {\n return extractReferenceId(input);\n }\n}\n\n/**\n * Manages content store lifecycle and cross-package registration\n */\nexport class ContentStoreManager {\n private contentStorage: ContentStorage;\n private adapter: ContentStorageAdapter;\n private resolver: ContentResolver;\n private logger: Logger;\n private isRegistered = false;\n\n constructor(\n maxMessageStorage: number = 1000,\n referenceConfig?: Partial<ContentReferenceConfig>,\n logger?: Logger\n ) {\n this.logger = logger || {\n info: console.log,\n debug: console.log,\n warn: console.warn,\n error: console.error\n } as Logger;\n\n this.contentStorage = new ContentStorage(maxMessageStorage, referenceConfig);\n this.adapter = new ContentStorageAdapter(this.contentStorage);\n this.resolver = new ContentResolver(this.adapter);\n }\n\n /**\n * Initialize and register content storage for cross-package access\n */\n async initialize(): Promise<void> {\n if (this.isRegistered) {\n this.logger.warn('ContentStoreManager is already initialized');\n return;\n }\n\n try {\n await ContentStoreService.setInstance(this.adapter);\n ContentResolverRegistry.register(this.resolver);\n this.isRegistered = true;\n this.logger.info('ContentStoreManager initialized and registered for cross-package access');\n } catch (error) {\n this.logger.error('Failed to initialize ContentStoreManager:', error);\n throw error;\n }\n }\n\n /**\n * Get the underlying ContentStorage instance\n */\n getContentStorage(): ContentStorage {\n return this.contentStorage;\n }\n\n /**\n * Get storage statistics\n */\n async getStats() {\n return await this.contentStorage.getStats();\n }\n\n /**\n * Update configuration\n */\n async updateConfig(config: Partial<ContentReferenceConfig>) {\n return await this.contentStorage.updateConfig(config);\n }\n\n /**\n * Perform manual cleanup\n */\n async performCleanup() {\n return await this.contentStorage.performCleanup();\n }\n\n /**\n * Check if content should be stored as reference\n */\n shouldUseReference(content: Buffer | string): boolean {\n return this.contentStorage.shouldUseReference(content);\n }\n\n /**\n * Store content if it's large enough\n */\n async storeContentIfLarge(content: Buffer | string, metadata: any) {\n return await this.contentStorage.storeContentIfLarge(content, metadata);\n }\n\n /**\n * Cleanup and unregister\n */\n async dispose(): Promise<void> {\n if (this.isRegistered) {\n this.contentStorage.dispose();\n ContentStoreService.dispose();\n ContentResolverRegistry.unregister();\n this.isRegistered = false;\n this.logger.info('ContentStoreManager disposed and unregistered');\n }\n }\n\n /**\n * Check if the manager is initialized\n */\n isInitialized(): boolean {\n return this.isRegistered;\n }\n}"],"names":[],"mappings":";;AAgBA,MAAM,sBAAuD;AAAA,EAC3D,YAAoB,SAAyB;AAAzB,SAAA,UAAA;AAAA,EAA0B;AAAA,EAE9C,MA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