@hashgraphonline/conversational-agent 0.2.1 → 0.2.101

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 (63) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/conversational-agent.d.ts +11 -1
  3. package/dist/cjs/index.cjs +1 -1
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/services/attachment-processor.d.ts +41 -0
  6. package/dist/cjs/services/index.d.ts +2 -0
  7. package/dist/cjs/services/parameter-service.d.ts +43 -0
  8. package/dist/cjs/tools/entity-resolver-tool.d.ts +5 -3
  9. package/dist/esm/index.js +9 -5
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/index10.js +2 -2
  12. package/dist/esm/index21.js +1 -1
  13. package/dist/esm/index23.js +3 -3
  14. package/dist/esm/index24.js +20 -4
  15. package/dist/esm/index24.js.map +1 -1
  16. package/dist/esm/index29.js +248 -903
  17. package/dist/esm/index29.js.map +1 -1
  18. package/dist/esm/index30.js +98 -219
  19. package/dist/esm/index30.js.map +1 -1
  20. package/dist/esm/index31.js +834 -1085
  21. package/dist/esm/index31.js.map +1 -1
  22. package/dist/esm/index32.js +228 -115
  23. package/dist/esm/index32.js.map +1 -1
  24. package/dist/esm/index33.js +1185 -79
  25. package/dist/esm/index33.js.map +1 -1
  26. package/dist/esm/index34.js +119 -39
  27. package/dist/esm/index34.js.map +1 -1
  28. package/dist/esm/index35.js +103 -96
  29. package/dist/esm/index35.js.map +1 -1
  30. package/dist/esm/index36.js +46 -21
  31. package/dist/esm/index36.js.map +1 -1
  32. package/dist/esm/index37.js +107 -12
  33. package/dist/esm/index37.js.map +1 -1
  34. package/dist/esm/index38.js +21 -7
  35. package/dist/esm/index38.js.map +1 -1
  36. package/dist/esm/index39.js +4 -26
  37. package/dist/esm/index39.js.map +1 -1
  38. package/dist/esm/index40.js +11 -4
  39. package/dist/esm/index40.js.map +1 -1
  40. package/dist/esm/index41.js +1 -1
  41. package/dist/esm/index43.js +24 -89
  42. package/dist/esm/index43.js.map +1 -1
  43. package/dist/esm/index44.js +10 -0
  44. package/dist/esm/index44.js.map +1 -0
  45. package/dist/esm/index45.js +95 -0
  46. package/dist/esm/index45.js.map +1 -0
  47. package/dist/esm/index5.js +2 -2
  48. package/dist/esm/index6.js +76 -6
  49. package/dist/esm/index6.js.map +1 -1
  50. package/dist/esm/index8.js +1 -1
  51. package/dist/types/conversational-agent.d.ts +11 -1
  52. package/dist/types/services/attachment-processor.d.ts +41 -0
  53. package/dist/types/services/index.d.ts +2 -0
  54. package/dist/types/services/parameter-service.d.ts +43 -0
  55. package/dist/types/tools/entity-resolver-tool.d.ts +5 -3
  56. package/package.json +2 -1
  57. package/src/conversational-agent.ts +97 -5
  58. package/src/langchain/langchain-agent.ts +9 -1
  59. package/src/services/attachment-processor.ts +163 -0
  60. package/src/services/content-store-manager.ts +32 -4
  61. package/src/services/index.ts +2 -0
  62. package/src/services/parameter-service.ts +430 -0
  63. package/src/tools/entity-resolver-tool.ts +12 -18
@@ -0,0 +1,41 @@
1
+ import { ContentStoreManager as PackageContentStoreManager } from './content-store-manager';
2
+
3
+ export interface AttachmentData {
4
+ name: string;
5
+ data: string;
6
+ type: string;
7
+ size: number;
8
+ }
9
+ type ContentStoreManager = PackageContentStoreManager;
10
+ /**
11
+ * Utility for processing file attachments and content references
12
+ */
13
+ export declare class AttachmentProcessor {
14
+ private logger;
15
+ constructor();
16
+ /**
17
+ * Process attachments and create content references
18
+ */
19
+ processAttachments(content: string, attachments: AttachmentData[], contentStoreManager?: ContentStoreManager): Promise<string>;
20
+ /**
21
+ * Process attachments using content store manager
22
+ */
23
+ private processWithContentStore;
24
+ /**
25
+ * Process attachments with simple file references
26
+ */
27
+ private processWithSimpleReferences;
28
+ /**
29
+ * Create inline reference for small files
30
+ */
31
+ private createInlineReference;
32
+ /**
33
+ * Create formatted file list
34
+ */
35
+ private createFileList;
36
+ /**
37
+ * Format file size for display
38
+ */
39
+ private formatFileSize;
40
+ }
41
+ export {};
@@ -1,3 +1,5 @@
1
1
  export * from './entity-resolver';
2
2
  export * from './content-store-manager';
3
3
  export * from './formatters';
4
+ export * from './parameter-service';
5
+ export * from './attachment-processor';
@@ -0,0 +1,43 @@
1
+ import { NetworkType } from '@hashgraphonline/standards-sdk';
2
+ import { FormatConverterRegistry } from './formatters';
3
+ import { EntityAssociation } from '../memory/smart-memory-manager';
4
+
5
+ /**
6
+ * Service for processing tool parameters and applying entity format conversions
7
+ */
8
+ export declare class ParameterService {
9
+ private logger;
10
+ private formatConverterRegistry;
11
+ private networkType;
12
+ constructor(formatConverterRegistry: FormatConverterRegistry, networkType: NetworkType);
13
+ /**
14
+ * Unified preprocessing entrypoint (DRY):
15
+ * - Optional AI-driven resolution via provided entityResolver
16
+ * - Deterministic post-pass for safe format enforcement
17
+ */
18
+ preprocessParameters(toolName: string, parameters: Record<string, unknown>, entities?: EntityAssociation[], options?: {
19
+ entityResolver?: {
20
+ resolveReferences: (message: string, entities: EntityAssociation[]) => Promise<string>;
21
+ };
22
+ sessionId?: string;
23
+ preferences?: Record<string, string>;
24
+ }): Promise<Record<string, unknown>>;
25
+ /**
26
+ * Attach unified preprocessing callback directly to the agent.
27
+ */
28
+ attachToAgent(agent: unknown, deps?: {
29
+ getSessionId?: () => string | null;
30
+ getEntities?: (sessionId: string | null) => Promise<EntityAssociation[]>;
31
+ entityResolver?: {
32
+ resolveReferences: (message: string, entities: EntityAssociation[]) => Promise<string>;
33
+ };
34
+ }): void;
35
+ /**
36
+ * Preprocess tool parameters by applying format conversions based on tool's entity resolution preferences
37
+ */
38
+ preprocessToolParameters(toolName: string, parameters: Record<string, unknown>, entities?: EntityAssociation[], sessionId?: string): Promise<Record<string, unknown>>;
39
+ /**
40
+ * Convert entity references in a parameter value based on tool preferences
41
+ */
42
+ convertParameterEntities(parameterValue: string, entities: EntityAssociation[], preferences?: Record<string, string>): Promise<string>;
43
+ }
@@ -1,5 +1,7 @@
1
1
  import { StructuredTool } from '@langchain/core/tools';
2
2
  import { z } from 'zod';
3
+ import { ChatOpenAI } from '@langchain/openai';
4
+ import { ChatAnthropic } from '@langchain/anthropic';
3
5
 
4
6
  declare const ResolveEntitiesSchema: z.ZodObject<{
5
7
  message: z.ZodString;
@@ -75,7 +77,7 @@ export declare class ResolveEntitiesTool extends StructuredTool {
75
77
  }[];
76
78
  }>;
77
79
  private llm;
78
- constructor(apiKey: string, modelName?: string);
80
+ constructor(llm: ChatOpenAI | ChatAnthropic);
79
81
  _call(input: z.infer<typeof ResolveEntitiesSchema>): Promise<string>;
80
82
  private groupEntitiesByType;
81
83
  private buildEntityContext;
@@ -94,10 +96,10 @@ export declare class ExtractEntitiesTool extends StructuredTool {
94
96
  userMessage: string;
95
97
  }>;
96
98
  private llm;
97
- constructor(apiKey: string, modelName?: string);
99
+ constructor(llm: ChatOpenAI | ChatAnthropic);
98
100
  _call(input: z.infer<typeof ExtractEntitiesSchema>): Promise<string>;
99
101
  }
100
- export declare function createEntityTools(apiKey: string, modelName?: string): {
102
+ export declare function createEntityTools(llm: ChatOpenAI | ChatAnthropic): {
101
103
  resolveEntities: ResolveEntitiesTool;
102
104
  extractEntities: ExtractEntitiesTool;
103
105
  };
package/dist/esm/index.js CHANGED
@@ -26,12 +26,15 @@ import { FormatConverterRegistry } from "./index25.js";
26
26
  import { EntityFormat } from "./index26.js";
27
27
  import { TopicIdToHrlConverter } from "./index27.js";
28
28
  import { StringNormalizationConverter } from "./index28.js";
29
- import { FormAwareAgentExecutor } from "./index29.js";
30
- import { FormValidatingToolWrapper, wrapToolWithFormValidation } from "./index30.js";
31
- import { LangChainAgent } from "./index31.js";
32
- import { ExtractEntitiesTool, ResolveEntitiesTool, createEntityTools } from "./index32.js";
33
- import { ResponseFormatter } from "./index33.js";
29
+ import { ParameterService } from "./index29.js";
30
+ import { AttachmentProcessor } from "./index30.js";
31
+ import { FormAwareAgentExecutor } from "./index31.js";
32
+ import { FormValidatingToolWrapper, wrapToolWithFormValidation } from "./index32.js";
33
+ import { LangChainAgent } from "./index33.js";
34
+ import { ExtractEntitiesTool, ResolveEntitiesTool, createEntityTools } from "./index34.js";
35
+ import { ResponseFormatter } from "./index35.js";
34
36
  export {
37
+ AttachmentProcessor,
35
38
  BaseAgent,
36
39
  ContentStorage,
37
40
  ContentStoreManager,
@@ -56,6 +59,7 @@ export {
56
59
  MCPServers,
57
60
  MemoryWindow,
58
61
  HCS10Plugin2 as OpenConvAIPlugin,
62
+ ParameterService,
59
63
  ReferenceIdGenerator,
60
64
  ResolveEntitiesTool,
61
65
  ResponseFormatter,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -3,8 +3,8 @@ import { extractRenderConfigs, generateFieldOrdering } from "@hashgraphonline/st
3
3
  import { Logger } from "@hashgraphonline/standards-sdk";
4
4
  import { fieldTypeRegistry } from "./index12.js";
5
5
  import { fieldGuidanceRegistry } from "./index13.js";
6
- import "./index37.js";
7
- import { FIELD_PRIORITIES } from "./index38.js";
6
+ import "./index40.js";
7
+ import { FIELD_PRIORITIES } from "./index44.js";
8
8
  function isZodObjectSchema(schema) {
9
9
  return typeof schema === "object" && schema !== null && "shape" in schema;
10
10
  }
@@ -1,5 +1,5 @@
1
1
  import { ReferenceIdGenerator } from "./index22.js";
2
- import { DEFAULT_CONTENT_REFERENCE_CONFIG, ContentReferenceError } from "./index39.js";
2
+ import { DEFAULT_CONTENT_REFERENCE_CONFIG, ContentReferenceError } from "./index43.js";
3
3
  const _ContentStorage = class _ContentStorage {
4
4
  constructor(maxStorage = _ContentStorage.DEFAULT_MAX_STORAGE, referenceConfig) {
5
5
  this.messages = [];
@@ -1,9 +1,9 @@
1
1
  import { ChatOpenAI } from "@langchain/openai";
2
2
  import { Logger } from "@hashgraphonline/standards-sdk";
3
- import { ENTITY_PATTERNS } from "./index37.js";
3
+ import { ENTITY_PATTERNS } from "./index40.js";
4
4
  import "hedera-agent-kit";
5
5
  import "@hashgraphonline/standards-agent-kit";
6
- import "./index34.js";
6
+ import "./index36.js";
7
7
  import "@langchain/core/tools";
8
8
  import "zod";
9
9
  import "./index6.js";
@@ -22,7 +22,7 @@ import "./index21.js";
22
22
  import "crypto";
23
23
  import { EntityFormat } from "./index26.js";
24
24
  import "./index28.js";
25
- import "./index32.js";
25
+ import "./index34.js";
26
26
  class EntityResolver {
27
27
  constructor(config) {
28
28
  this.llm = new ChatOpenAI({
@@ -94,8 +94,20 @@ class ContentStoreManager {
94
94
  return;
95
95
  }
96
96
  try {
97
- await ContentStoreService.setInstance(this.adapter);
98
- ContentResolverRegistry.register(this.resolver);
97
+ if (ContentStoreService && typeof ContentStoreService.setInstance === "function") {
98
+ await ContentStoreService.setInstance(
99
+ this.adapter
100
+ );
101
+ } else {
102
+ this.logger.warn("ContentStoreService.setInstance is unavailable; skipping registration");
103
+ }
104
+ if (ContentResolverRegistry && typeof ContentResolverRegistry.register === "function") {
105
+ ContentResolverRegistry.register(
106
+ this.resolver
107
+ );
108
+ } else {
109
+ this.logger.warn("ContentResolverRegistry.register is unavailable; skipping registration");
110
+ }
99
111
  this.isRegistered = true;
100
112
  this.logger.info(
101
113
  "ContentStoreManager initialized and registered for cross-package access"
@@ -155,8 +167,12 @@ class ContentStoreManager {
155
167
  async dispose() {
156
168
  if (this.isRegistered) {
157
169
  this.contentStorage.dispose();
158
- ContentStoreService.dispose();
159
- ContentResolverRegistry.unregister();
170
+ if (ContentStoreService && typeof ContentStoreService.dispose === "function") {
171
+ ContentStoreService.dispose();
172
+ }
173
+ if (ContentResolverRegistry && typeof ContentResolverRegistry.unregister === "function") {
174
+ ContentResolverRegistry.unregister();
175
+ }
160
176
  this.isRegistered = false;
161
177
  this.logger.info("ContentStoreManager disposed and unregistered");
162
178
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index24.js","sources":["../../src/services/content-store-manager.ts"],"sourcesContent":["import { ContentStorage } from '../memory/content-storage';\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 {\n ContentReference,\n ContentReferenceConfig,\n ContentReferenceStats,\n} from '../types/content-reference';\nimport { Logger } from '@hashgraphonline/standards-sdk';\n\n/**\n * Content metadata interface for adapter compatibility\n */\ninterface AdapterContentMetadata {\n mimeType?: string;\n fileName?: string;\n sizeBytes?: number;\n [key: string]: unknown;\n}\n\n/**\n * Configuration interface for content storage\n */\ninterface ContentStoreConfig {\n maxSize?: number;\n enableCompression?: boolean;\n [key: string]: unknown;\n}\n\n/**\n * Adapter to make ContentStorage compatible with ContentStoreInterface\n */\nclass ContentStorageAdapter implements ContentStoreInterface {\n constructor(private storage: ContentStorage) {}\n\n async storeContent(\n content: Buffer,\n metadata: AdapterContentMetadata\n ): Promise<string> {\n const storeMetadata = {\n contentType: 'binary' as const,\n sizeBytes: content.length,\n source: 'system' as const,\n ...metadata,\n };\n const contentRef = await this.storage.storeContent(content, storeMetadata);\n return contentRef.referenceId;\n }\n\n async resolveReference(\n referenceId: string\n ): 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 && {\n mimeType: result.metadata.mimeType,\n }),\n ...(result.metadata.fileName !== undefined && {\n fileName: result.metadata.fileName,\n }),\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): Promise<boolean> {\n return await this.storage.hasReference(referenceId);\n }\n\n async cleanupReference(referenceId: string): Promise<void> {\n await this.storage.cleanupReference(referenceId);\n }\n\n async getStats(): Promise<unknown> {\n return await this.storage.getStats();\n }\n\n async updateConfig(config: ContentStoreConfig): Promise<void> {\n const referenceConfig = {\n sizeThresholdBytes: config.maxSize || 10240,\n enableAutoCleanup: config.enableCompression || true,\n ...config,\n };\n return await this.storage.updateConfig(referenceConfig);\n }\n\n async performCleanup(): Promise<void> {\n await this.storage.performCleanup();\n }\n\n async dispose(): Promise<void> {\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(\n referenceId: string\n ): 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 || new Logger({ module: 'ContentStoreManager' });\n\n this.contentStorage = new ContentStorage(\n maxMessageStorage,\n referenceConfig\n );\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(\n 'ContentStoreManager initialized and registered for cross-package access'\n );\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(): Promise<ContentReferenceStats> {\n return await this.contentStorage.getStats();\n }\n\n /**\n * Update configuration\n */\n async updateConfig(config: Partial<ContentReferenceConfig>): Promise<void> {\n return await this.contentStorage.updateConfig(config);\n }\n\n /**\n * Perform manual cleanup\n */\n async performCleanup(): Promise<{ cleanedUp: number; errors: string[] }> {\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(\n content: Buffer | string,\n metadata: AdapterContentMetadata\n ): Promise<ContentReference | null> {\n const storeMetadata = {\n source: 'system' as const,\n contentType: 'binary' as const,\n ...metadata,\n };\n return await this.contentStorage.storeContentIfLarge(\n content,\n storeMetadata\n );\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}\n"],"names":[],"mappings":";;AAuCA,MAAM,sBAAuD;AAAA,EAC3D,YAAoB,SAAyB;AAAzB,SAAA,UAAA;AAAA,EAA0B;AAAA,EAE9C,MAAM,aACJ,SACA,UACiB;AACjB,UAAM,gBAAgB;AAAA,MACpB,aAAa;AAAA,MACb,WAAW,QAAQ;AAAA,MACnB,QAAQ;AAAA,MACR,GAAG;AAAA,IAAA;AAEL,UAAM,aAAa,MAAM,KAAK,QAAQ,aAAa,SAAS,aAAa;AACzE,WAAO,WAAW;AAAA,EACpB;AAAA,EAEA,MAAM,iBACJ,aACoC;AACpC,UAAM,SAAS,MAAM,KAAK,QAAQ,iBAAiB,WAAW;AAC9D,QAAI,OAA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AO;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,oBACJ,SACA,UACkC;AAClC,UAAM,gBAAgB;AAAA,MACpB,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,GAAG;AAAA,IAAA;AAEL,WAAO,MAAM,KAAK,eAAe;AAAA,MAC/B;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAAyB;AAC7B,QAAI,KAAK,cAAc;AACrB,WAAK,eAAe,QAAA;AACpB,0BAAoB,QAAA;AACpB,8BAAwB,WAAA;AACxB,WAAK,eAAe;AACpB,WAAK,OAAO,KAAK,+CAA+C;AAAA,IAClE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AACF;"}
1
+ {"version":3,"file":"index24.js","sources":["../../src/services/content-store-manager.ts"],"sourcesContent":["import { ContentStorage } from '../memory/content-storage';\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 {\n ContentReference,\n ContentReferenceConfig,\n ContentReferenceStats,\n} from '../types/content-reference';\nimport { Logger } from '@hashgraphonline/standards-sdk';\n\n/**\n * Content metadata interface for adapter compatibility\n */\ninterface AdapterContentMetadata {\n mimeType?: string;\n fileName?: string;\n sizeBytes?: number;\n [key: string]: unknown;\n}\n\n/**\n * Configuration interface for content storage\n */\ninterface ContentStoreConfig {\n maxSize?: number;\n enableCompression?: boolean;\n [key: string]: unknown;\n}\n\n/**\n * Adapter to make ContentStorage compatible with ContentStoreInterface\n */\nclass ContentStorageAdapter implements ContentStoreInterface {\n constructor(private storage: ContentStorage) {}\n\n async storeContent(\n content: Buffer,\n metadata: AdapterContentMetadata\n ): Promise<string> {\n const storeMetadata = {\n contentType: 'binary' as const,\n sizeBytes: content.length,\n source: 'system' as const,\n ...metadata,\n };\n const contentRef = await this.storage.storeContent(content, storeMetadata);\n return contentRef.referenceId;\n }\n\n async resolveReference(\n referenceId: string\n ): 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 && {\n mimeType: result.metadata.mimeType,\n }),\n ...(result.metadata.fileName !== undefined && {\n fileName: result.metadata.fileName,\n }),\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): Promise<boolean> {\n return await this.storage.hasReference(referenceId);\n }\n\n async cleanupReference(referenceId: string): Promise<void> {\n await this.storage.cleanupReference(referenceId);\n }\n\n async getStats(): Promise<unknown> {\n return await this.storage.getStats();\n }\n\n async updateConfig(config: ContentStoreConfig): Promise<void> {\n const referenceConfig = {\n sizeThresholdBytes: config.maxSize || 10240,\n enableAutoCleanup: config.enableCompression || true,\n ...config,\n };\n return await this.storage.updateConfig(referenceConfig);\n }\n\n async performCleanup(): Promise<void> {\n await this.storage.performCleanup();\n }\n\n async dispose(): Promise<void> {\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(\n referenceId: string\n ): 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 || new Logger({ module: 'ContentStoreManager' });\n\n this.contentStorage = new ContentStorage(\n maxMessageStorage,\n referenceConfig\n );\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 if (\n ContentStoreService &&\n typeof (ContentStoreService as unknown as { setInstance?: Function }).setInstance === 'function'\n ) {\n await (ContentStoreService as unknown as { setInstance: (adapter: unknown) => Promise<void> }).setInstance(\n this.adapter\n );\n } else {\n this.logger.warn('ContentStoreService.setInstance is unavailable; skipping registration');\n }\n if (\n ContentResolverRegistry &&\n typeof (ContentResolverRegistry as unknown as { register?: Function }).register === 'function'\n ) {\n (ContentResolverRegistry as unknown as { register: (resolver: unknown) => void }).register(\n this.resolver\n );\n } else {\n this.logger.warn('ContentResolverRegistry.register is unavailable; skipping registration');\n }\n this.isRegistered = true;\n this.logger.info(\n 'ContentStoreManager initialized and registered for cross-package access'\n );\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(): Promise<ContentReferenceStats> {\n return await this.contentStorage.getStats();\n }\n\n /**\n * Update configuration\n */\n async updateConfig(config: Partial<ContentReferenceConfig>): Promise<void> {\n return await this.contentStorage.updateConfig(config);\n }\n\n /**\n * Perform manual cleanup\n */\n async performCleanup(): Promise<{ cleanedUp: number; errors: string[] }> {\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(\n content: Buffer | string,\n metadata: AdapterContentMetadata\n ): Promise<ContentReference | null> {\n const storeMetadata = {\n source: 'system' as const,\n contentType: 'binary' as const,\n ...metadata,\n };\n return await this.contentStorage.storeContentIfLarge(\n content,\n storeMetadata\n );\n }\n\n /**\n * Cleanup and unregister\n */\n async dispose(): Promise<void> {\n if (this.isRegistered) {\n this.contentStorage.dispose();\n if (\n ContentStoreService &&\n typeof (ContentStoreService as unknown as { dispose?: Function }).dispose === 'function'\n ) {\n (ContentStoreService as unknown as { dispose: () => void }).dispose();\n }\n if (\n ContentResolverRegistry &&\n typeof (ContentResolverRegistry as unknown as { unregister?: Function }).unregister === 'function'\n ) {\n (ContentResolverRegistry as unknown as { unregister: () => void }).unregister();\n }\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}\n"],"names":[],"mappings":";;AAuCA,MAAM,sBAAuD;AAAA,EAC3D,YAAoB,SAAyB;AAAzB,SAAA,UAAA;AAAA,EAA0B;AAAA,EAE9C,MAAM,aACJ,SACA,UACiB;AACjB,UAAM,gBAAgB;AAAA,MACpB,aAAa;AAAA,MACb,WAAW,QAAQ;AAAA,MACnB,QAAQ;AAAA,MACR,GAAG;AAAA,IAAA;AAEL,UAAM,aAAa,MAAM,KAAK,QAAQ,aAAa,SAAS,aAAa;AACzE,WAAO,WAAW;AAAA,EACpB;AAAA,EAEA,MAAM,iBACJ,aACoC;AACpC,UAAM,SAAS,MAAM,KAAK,QAAQ,iBAAiB,WAAW;AAC9D,QAAI,OAAO,WAAW,OAAO,SAAS;AACpC,YAAM,WAAsC;AAAA,QAC1C,SAAS,OAAO;AAAA,MAAA;AAElB,UAAI,OAAO,UAAU;AACnB,iBAAS,WAAW;AAAA,UAClB,GAAI,OAAO,SAAS,aAAa,UAAa;AAAA,YAC5C,UAAU,OAAO,SAAS;AAAA,UAAA;AAAA,UAE5B,GAAI,OAAO,S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