@hashgraphonline/conversational-agent 0.1.204 → 0.1.206
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.
- package/dist/cjs/base-agent.d.ts +6 -0
- package/dist/cjs/context/ReferenceContextManager.d.ts +84 -0
- package/dist/cjs/context/ReferenceResponseProcessor.d.ts +76 -0
- package/dist/cjs/conversational-agent.d.ts +34 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/langchain-agent.d.ts +1 -0
- package/dist/cjs/mcp/ContentProcessor.d.ts +37 -0
- package/dist/cjs/mcp/MCPClientManager.d.ts +19 -1
- package/dist/cjs/memory/ContentStorage.d.ts +205 -0
- package/dist/cjs/memory/MemoryWindow.d.ts +114 -0
- package/dist/cjs/memory/ReferenceIdGenerator.d.ts +45 -0
- package/dist/cjs/memory/SmartMemoryManager.d.ts +201 -0
- package/dist/cjs/memory/TokenCounter.d.ts +61 -0
- package/dist/cjs/memory/index.d.ts +7 -0
- package/dist/cjs/plugins/hbar-transfer/TransferHbarTool.d.ts +18 -0
- package/dist/cjs/services/ContentStoreManager.d.ts +54 -0
- package/dist/cjs/types/content-reference.d.ts +213 -0
- package/dist/cjs/types/index.d.ts +4 -0
- package/dist/esm/index12.js +15 -2
- package/dist/esm/index12.js.map +1 -1
- package/dist/esm/index14.js +119 -95
- package/dist/esm/index14.js.map +1 -1
- package/dist/esm/index15.js +159 -114
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index16.js +122 -81
- package/dist/esm/index16.js.map +1 -1
- package/dist/esm/index17.js +236 -0
- package/dist/esm/index17.js.map +1 -0
- package/dist/esm/index18.js +95 -0
- package/dist/esm/index18.js.map +1 -0
- package/dist/esm/index19.js +663 -0
- package/dist/esm/index19.js.map +1 -0
- package/dist/esm/index2.js +3 -1
- package/dist/esm/index2.js.map +1 -1
- package/dist/esm/index20.js +233 -0
- package/dist/esm/index20.js.map +1 -0
- package/dist/esm/index21.js +182 -0
- package/dist/esm/index21.js.map +1 -0
- package/dist/esm/index22.js +126 -0
- package/dist/esm/index22.js.map +1 -0
- package/dist/esm/index23.js +68 -0
- package/dist/esm/index23.js.map +1 -0
- package/dist/esm/index24.js +38 -0
- package/dist/esm/index24.js.map +1 -0
- package/dist/esm/index6.js +143 -84
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index7.js.map +1 -1
- package/dist/esm/index8.js +69 -5
- package/dist/esm/index8.js.map +1 -1
- package/dist/types/base-agent.d.ts +6 -0
- package/dist/types/context/ReferenceContextManager.d.ts +84 -0
- package/dist/types/context/ReferenceResponseProcessor.d.ts +76 -0
- package/dist/types/conversational-agent.d.ts +34 -0
- package/dist/types/langchain-agent.d.ts +1 -0
- package/dist/types/mcp/ContentProcessor.d.ts +37 -0
- package/dist/types/mcp/MCPClientManager.d.ts +19 -1
- package/dist/types/memory/ContentStorage.d.ts +205 -0
- package/dist/types/memory/MemoryWindow.d.ts +114 -0
- package/dist/types/memory/ReferenceIdGenerator.d.ts +45 -0
- package/dist/types/memory/SmartMemoryManager.d.ts +201 -0
- package/dist/types/memory/TokenCounter.d.ts +61 -0
- package/dist/types/memory/index.d.ts +7 -0
- package/dist/types/plugins/hbar-transfer/TransferHbarTool.d.ts +18 -0
- package/dist/types/services/ContentStoreManager.d.ts +54 -0
- package/dist/types/types/content-reference.d.ts +213 -0
- package/dist/types/types/index.d.ts +4 -0
- package/package.json +30 -26
- package/src/base-agent.ts +6 -0
- package/src/context/ReferenceContextManager.ts +345 -0
- package/src/context/ReferenceResponseProcessor.ts +296 -0
- package/src/conversational-agent.ts +166 -92
- package/src/langchain-agent.ts +89 -2
- package/src/mcp/ContentProcessor.ts +317 -0
- package/src/mcp/MCPClientManager.ts +61 -1
- package/src/mcp/adapters/langchain.ts +9 -4
- package/src/memory/ContentStorage.ts +954 -0
- package/src/memory/MemoryWindow.ts +247 -0
- package/src/memory/ReferenceIdGenerator.ts +84 -0
- package/src/memory/SmartMemoryManager.ts +323 -0
- package/src/memory/TokenCounter.ts +152 -0
- package/src/memory/index.ts +8 -0
- package/src/plugins/hbar-transfer/TransferHbarTool.ts +19 -1
- package/src/plugins/hcs-10/HCS10Plugin.ts +5 -4
- package/src/services/ContentStoreManager.ts +199 -0
- package/src/types/content-reference.ts +281 -0
- package/src/types/index.ts +6 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { TiktokenModel } from 'tiktoken';
|
|
2
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Token counter utility for OpenAI models using tiktoken encoding
|
|
6
|
+
* Provides accurate token counting for text content and chat messages
|
|
7
|
+
*/
|
|
8
|
+
export declare class TokenCounter {
|
|
9
|
+
private encoding;
|
|
10
|
+
private modelName;
|
|
11
|
+
private static readonly MESSAGE_OVERHEAD;
|
|
12
|
+
private static readonly ROLE_OVERHEAD;
|
|
13
|
+
constructor(modelName?: TiktokenModel);
|
|
14
|
+
/**
|
|
15
|
+
* Count tokens in raw text content
|
|
16
|
+
* @param text - The text to count tokens for
|
|
17
|
+
* @returns Number of tokens
|
|
18
|
+
*/
|
|
19
|
+
countTokens(text: string): number;
|
|
20
|
+
/**
|
|
21
|
+
* Count tokens for a single chat message including role overhead
|
|
22
|
+
* @param message - The message to count tokens for
|
|
23
|
+
* @returns Number of tokens including message formatting overhead
|
|
24
|
+
*/
|
|
25
|
+
countMessageTokens(message: BaseMessage): number;
|
|
26
|
+
/**
|
|
27
|
+
* Count tokens for multiple messages
|
|
28
|
+
* @param messages - Array of messages to count
|
|
29
|
+
* @returns Total token count for all messages
|
|
30
|
+
*/
|
|
31
|
+
countMessagesTokens(messages: BaseMessage[]): number;
|
|
32
|
+
/**
|
|
33
|
+
* Estimate tokens for system prompt
|
|
34
|
+
* System prompts have slightly different overhead in chat completions
|
|
35
|
+
* @param systemPrompt - The system prompt text
|
|
36
|
+
* @returns Estimated token count
|
|
37
|
+
*/
|
|
38
|
+
estimateSystemPromptTokens(systemPrompt: string): number;
|
|
39
|
+
/**
|
|
40
|
+
* Get total context size estimate including system prompt and messages
|
|
41
|
+
* @param systemPrompt - System prompt text
|
|
42
|
+
* @param messages - Conversation messages
|
|
43
|
+
* @returns Total estimated token count
|
|
44
|
+
*/
|
|
45
|
+
estimateContextSize(systemPrompt: string, messages: BaseMessage[]): number;
|
|
46
|
+
/**
|
|
47
|
+
* Get the role string for a message
|
|
48
|
+
* @param message - The message to get the role for
|
|
49
|
+
* @returns Role string ('user', 'assistant', 'system', etc.)
|
|
50
|
+
*/
|
|
51
|
+
private getMessageRole;
|
|
52
|
+
/**
|
|
53
|
+
* Get the model name being used for token counting
|
|
54
|
+
* @returns The tiktoken model name
|
|
55
|
+
*/
|
|
56
|
+
getModelName(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Clean up encoding resources
|
|
59
|
+
*/
|
|
60
|
+
dispose(): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { TokenCounter } from './TokenCounter';
|
|
2
|
+
export { MemoryWindow } from './MemoryWindow';
|
|
3
|
+
export { ContentStorage } from './ContentStorage';
|
|
4
|
+
export { SmartMemoryManager } from './SmartMemoryManager';
|
|
5
|
+
export type { SmartMemoryConfig, SearchOptions, MemoryStats } from './SmartMemoryManager';
|
|
6
|
+
export type { AddMessageResult } from './MemoryWindow';
|
|
7
|
+
export type { StorageStats } from './ContentStorage';
|
|
@@ -26,6 +26,11 @@ declare const TransferHbarZodSchemaCore: z.ZodObject<{
|
|
|
26
26
|
}[];
|
|
27
27
|
memo?: string | undefined;
|
|
28
28
|
}>;
|
|
29
|
+
/**
|
|
30
|
+
* A Hedera transaction tool for transferring HBAR between accounts.
|
|
31
|
+
* Supports single and multi-party transfers with automatic balance validation.
|
|
32
|
+
* Extends BaseHederaTransactionTool to handle HBAR transfer transactions on the Hedera network.
|
|
33
|
+
*/
|
|
29
34
|
export declare class TransferHbarTool extends BaseHederaTransactionTool<typeof TransferHbarZodSchemaCore> {
|
|
30
35
|
name: string;
|
|
31
36
|
description: string;
|
|
@@ -55,7 +60,20 @@ export declare class TransferHbarTool extends BaseHederaTransactionTool<typeof T
|
|
|
55
60
|
memo?: string | undefined;
|
|
56
61
|
}>;
|
|
57
62
|
namespace: string;
|
|
63
|
+
/**
|
|
64
|
+
* Creates and returns the service builder for account operations.
|
|
65
|
+
*
|
|
66
|
+
* @returns BaseServiceBuilder instance configured for account operations
|
|
67
|
+
*/
|
|
58
68
|
protected getServiceBuilder(): BaseServiceBuilder;
|
|
69
|
+
/**
|
|
70
|
+
* Executes the HBAR transfer using the provided builder and arguments.
|
|
71
|
+
* Validates that all transfers sum to zero before execution.
|
|
72
|
+
*
|
|
73
|
+
* @param builder - The service builder instance for executing transactions
|
|
74
|
+
* @param specificArgs - The validated transfer parameters including transfers array and optional memo
|
|
75
|
+
* @returns Promise that resolves when the transfer is complete
|
|
76
|
+
*/
|
|
59
77
|
protected callBuilderMethod(builder: BaseServiceBuilder, specificArgs: z.infer<typeof TransferHbarZodSchemaCore>): Promise<void>;
|
|
60
78
|
}
|
|
61
79
|
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ContentStorage } from '../memory/ContentStorage';
|
|
2
|
+
import { ContentReferenceConfig } from '../types/content-reference';
|
|
3
|
+
import { Logger } from '@hashgraphonline/standards-sdk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Manages content store lifecycle and cross-package registration
|
|
7
|
+
*/
|
|
8
|
+
export declare class ContentStoreManager {
|
|
9
|
+
private contentStorage;
|
|
10
|
+
private adapter;
|
|
11
|
+
private resolver;
|
|
12
|
+
private logger;
|
|
13
|
+
private isRegistered;
|
|
14
|
+
constructor(maxMessageStorage?: number, referenceConfig?: Partial<ContentReferenceConfig>, logger?: Logger);
|
|
15
|
+
/**
|
|
16
|
+
* Initialize and register content storage for cross-package access
|
|
17
|
+
*/
|
|
18
|
+
initialize(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Get the underlying ContentStorage instance
|
|
21
|
+
*/
|
|
22
|
+
getContentStorage(): ContentStorage;
|
|
23
|
+
/**
|
|
24
|
+
* Get storage statistics
|
|
25
|
+
*/
|
|
26
|
+
getStats(): Promise<import('../types').ContentReferenceStats>;
|
|
27
|
+
/**
|
|
28
|
+
* Update configuration
|
|
29
|
+
*/
|
|
30
|
+
updateConfig(config: Partial<ContentReferenceConfig>): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Perform manual cleanup
|
|
33
|
+
*/
|
|
34
|
+
performCleanup(): Promise<{
|
|
35
|
+
cleanedUp: number;
|
|
36
|
+
errors: string[];
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Check if content should be stored as reference
|
|
40
|
+
*/
|
|
41
|
+
shouldUseReference(content: Buffer | string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Store content if it's large enough
|
|
44
|
+
*/
|
|
45
|
+
storeContentIfLarge(content: Buffer | string, metadata: any): Promise<import('../types').ContentReference | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Cleanup and unregister
|
|
48
|
+
*/
|
|
49
|
+
dispose(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Check if the manager is initialized
|
|
52
|
+
*/
|
|
53
|
+
isInitialized(): boolean;
|
|
54
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Reference System Types
|
|
3
|
+
*
|
|
4
|
+
* Shared interfaces for the Reference-Based Content System that handles
|
|
5
|
+
* large content storage with unique reference IDs to optimize context window usage.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Unique identifier for stored content references
|
|
9
|
+
* Format: Cryptographically secure 32-byte identifier with base64url encoding
|
|
10
|
+
*/
|
|
11
|
+
export type ReferenceId = string;
|
|
12
|
+
/**
|
|
13
|
+
* Lifecycle state of a content reference
|
|
14
|
+
*/
|
|
15
|
+
export type ReferenceLifecycleState = 'active' | 'expired' | 'cleanup_pending' | 'invalid';
|
|
16
|
+
/**
|
|
17
|
+
* Content types supported by the reference system
|
|
18
|
+
*/
|
|
19
|
+
export type ContentType = 'text' | 'json' | 'html' | 'markdown' | 'binary' | 'unknown';
|
|
20
|
+
/**
|
|
21
|
+
* Sources that created the content reference
|
|
22
|
+
*/
|
|
23
|
+
export type ContentSource = 'mcp_tool' | 'user_upload' | 'agent_generated' | 'system';
|
|
24
|
+
/**
|
|
25
|
+
* Metadata associated with stored content
|
|
26
|
+
*/
|
|
27
|
+
export interface ContentMetadata {
|
|
28
|
+
/** Content type classification */
|
|
29
|
+
contentType: ContentType;
|
|
30
|
+
/** MIME type of the original content */
|
|
31
|
+
mimeType?: string;
|
|
32
|
+
/** Size in bytes of the stored content */
|
|
33
|
+
sizeBytes: number;
|
|
34
|
+
/** When the content was originally stored */
|
|
35
|
+
createdAt: Date;
|
|
36
|
+
/** Last time the content was accessed via reference resolution */
|
|
37
|
+
lastAccessedAt: Date;
|
|
38
|
+
/** Source that created this content reference */
|
|
39
|
+
source: ContentSource;
|
|
40
|
+
/** Name of the MCP tool that generated the content (if applicable) */
|
|
41
|
+
mcpToolName?: string;
|
|
42
|
+
/** Original filename or suggested name for the content */
|
|
43
|
+
fileName?: string;
|
|
44
|
+
/** Number of times this reference has been resolved */
|
|
45
|
+
accessCount: number;
|
|
46
|
+
/** Tags for categorization and cleanup policies */
|
|
47
|
+
tags?: string[];
|
|
48
|
+
/** Custom metadata from the source */
|
|
49
|
+
customMetadata?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Core content reference object passed through agent context
|
|
53
|
+
* Designed to be lightweight (<100 tokens) while providing enough
|
|
54
|
+
* information for agent decision-making
|
|
55
|
+
*/
|
|
56
|
+
export interface ContentReference {
|
|
57
|
+
/** Unique identifier for resolving the content */
|
|
58
|
+
referenceId: ReferenceId;
|
|
59
|
+
/** Current lifecycle state */
|
|
60
|
+
state: ReferenceLifecycleState;
|
|
61
|
+
/** Brief description or preview of the content (max 200 chars) */
|
|
62
|
+
preview: string;
|
|
63
|
+
/** Essential metadata for agent decision-making */
|
|
64
|
+
metadata: Pick<ContentMetadata, 'contentType' | 'sizeBytes' | 'source' | 'fileName' | 'mimeType'>;
|
|
65
|
+
/** When this reference was created */
|
|
66
|
+
createdAt: Date;
|
|
67
|
+
/** Special format indicator for reference IDs in content */
|
|
68
|
+
readonly format: 'ref://{id}';
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Result of attempting to resolve a content reference
|
|
72
|
+
*/
|
|
73
|
+
export interface ReferenceResolutionResult {
|
|
74
|
+
/** Whether the resolution was successful */
|
|
75
|
+
success: boolean;
|
|
76
|
+
/** The resolved content if successful */
|
|
77
|
+
content?: Buffer;
|
|
78
|
+
/** Complete metadata if successful */
|
|
79
|
+
metadata?: ContentMetadata;
|
|
80
|
+
/** Error message if resolution failed */
|
|
81
|
+
error?: string;
|
|
82
|
+
/** Specific error type for targeted error handling */
|
|
83
|
+
errorType?: 'not_found' | 'expired' | 'corrupted' | 'access_denied' | 'system_error';
|
|
84
|
+
/** Suggested actions for recovery */
|
|
85
|
+
suggestedActions?: string[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Configuration for content reference storage and lifecycle
|
|
89
|
+
*/
|
|
90
|
+
export interface ContentReferenceConfig {
|
|
91
|
+
/** Size threshold above which content should be stored as references (default: 10KB) */
|
|
92
|
+
sizeThresholdBytes: number;
|
|
93
|
+
/** Maximum age for unused references before cleanup (default: 1 hour) */
|
|
94
|
+
maxAgeMs: number;
|
|
95
|
+
/** Maximum number of references to store simultaneously */
|
|
96
|
+
maxReferences: number;
|
|
97
|
+
/** Maximum total storage size for all references */
|
|
98
|
+
maxTotalStorageBytes: number;
|
|
99
|
+
/** Whether to enable automatic cleanup */
|
|
100
|
+
enableAutoCleanup: boolean;
|
|
101
|
+
/** Interval for cleanup checks in milliseconds */
|
|
102
|
+
cleanupIntervalMs: number;
|
|
103
|
+
/** Whether to persist references across restarts */
|
|
104
|
+
enablePersistence: boolean;
|
|
105
|
+
/** Storage backend configuration */
|
|
106
|
+
storageBackend: 'memory' | 'filesystem' | 'hybrid';
|
|
107
|
+
/** Cleanup policies for different content types */
|
|
108
|
+
cleanupPolicies: {
|
|
109
|
+
/** Policy for content marked as "recent" from MCP tools */
|
|
110
|
+
recent: {
|
|
111
|
+
maxAgeMs: number;
|
|
112
|
+
priority: number;
|
|
113
|
+
};
|
|
114
|
+
/** Policy for user-uploaded content */
|
|
115
|
+
userContent: {
|
|
116
|
+
maxAgeMs: number;
|
|
117
|
+
priority: number;
|
|
118
|
+
};
|
|
119
|
+
/** Policy for agent-generated content */
|
|
120
|
+
agentGenerated: {
|
|
121
|
+
maxAgeMs: number;
|
|
122
|
+
priority: number;
|
|
123
|
+
};
|
|
124
|
+
/** Default policy for other content */
|
|
125
|
+
default: {
|
|
126
|
+
maxAgeMs: number;
|
|
127
|
+
priority: number;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Default configuration values
|
|
133
|
+
*/
|
|
134
|
+
export declare const DEFAULT_CONTENT_REFERENCE_CONFIG: ContentReferenceConfig;
|
|
135
|
+
/**
|
|
136
|
+
* Statistics about content reference usage and storage
|
|
137
|
+
*/
|
|
138
|
+
export interface ContentReferenceStats {
|
|
139
|
+
/** Total number of active references */
|
|
140
|
+
activeReferences: number;
|
|
141
|
+
/** Total storage used by all references in bytes */
|
|
142
|
+
totalStorageBytes: number;
|
|
143
|
+
/** Number of references cleaned up in last cleanup cycle */
|
|
144
|
+
recentlyCleanedUp: number;
|
|
145
|
+
/** Number of successful reference resolutions since startup */
|
|
146
|
+
totalResolutions: number;
|
|
147
|
+
/** Number of failed resolution attempts */
|
|
148
|
+
failedResolutions: number;
|
|
149
|
+
/** Average content size in bytes */
|
|
150
|
+
averageContentSize: number;
|
|
151
|
+
/** Most frequently accessed reference ID */
|
|
152
|
+
mostAccessedReferenceId?: ReferenceId;
|
|
153
|
+
/** Storage utilization percentage */
|
|
154
|
+
storageUtilization: number;
|
|
155
|
+
/** Performance metrics */
|
|
156
|
+
performanceMetrics: {
|
|
157
|
+
/** Average time to create a reference in milliseconds */
|
|
158
|
+
averageCreationTimeMs: number;
|
|
159
|
+
/** Average time to resolve a reference in milliseconds */
|
|
160
|
+
averageResolutionTimeMs: number;
|
|
161
|
+
/** Average cleanup time in milliseconds */
|
|
162
|
+
averageCleanupTimeMs: number;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Error types for content reference operations
|
|
167
|
+
*/
|
|
168
|
+
export declare class ContentReferenceError extends Error {
|
|
169
|
+
readonly type: ReferenceResolutionResult['errorType'];
|
|
170
|
+
readonly referenceId?: ReferenceId | undefined;
|
|
171
|
+
readonly suggestedActions?: string[] | undefined;
|
|
172
|
+
constructor(message: string, type: ReferenceResolutionResult['errorType'], referenceId?: ReferenceId | undefined, suggestedActions?: string[] | undefined);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Interface for content reference storage implementations
|
|
176
|
+
*/
|
|
177
|
+
export interface ContentReferenceStore {
|
|
178
|
+
/**
|
|
179
|
+
* Store content and return a reference
|
|
180
|
+
*/
|
|
181
|
+
storeContent(content: Buffer, metadata: Omit<ContentMetadata, 'createdAt' | 'lastAccessedAt' | 'accessCount'>): Promise<ContentReference>;
|
|
182
|
+
/**
|
|
183
|
+
* Resolve a reference to its content
|
|
184
|
+
*/
|
|
185
|
+
resolveReference(referenceId: ReferenceId): Promise<ReferenceResolutionResult>;
|
|
186
|
+
/**
|
|
187
|
+
* Check if a reference exists and is valid
|
|
188
|
+
*/
|
|
189
|
+
hasReference(referenceId: ReferenceId): Promise<boolean>;
|
|
190
|
+
/**
|
|
191
|
+
* Mark a reference for cleanup
|
|
192
|
+
*/
|
|
193
|
+
cleanupReference(referenceId: ReferenceId): Promise<boolean>;
|
|
194
|
+
/**
|
|
195
|
+
* Get current storage statistics
|
|
196
|
+
*/
|
|
197
|
+
getStats(): Promise<ContentReferenceStats>;
|
|
198
|
+
/**
|
|
199
|
+
* Update configuration
|
|
200
|
+
*/
|
|
201
|
+
updateConfig(config: Partial<ContentReferenceConfig>): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Perform cleanup based on current policies
|
|
204
|
+
*/
|
|
205
|
+
performCleanup(): Promise<{
|
|
206
|
+
cleanedUp: number;
|
|
207
|
+
errors: string[];
|
|
208
|
+
}>;
|
|
209
|
+
/**
|
|
210
|
+
* Dispose of resources
|
|
211
|
+
*/
|
|
212
|
+
dispose(): Promise<void>;
|
|
213
|
+
}
|
package/dist/esm/index12.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { AccountBuilder } from "./
|
|
2
|
+
import { AccountBuilder } from "./index18.js";
|
|
3
3
|
import { BaseHederaTransactionTool } from "hedera-agent-kit";
|
|
4
4
|
const HbarTransferInputSchema = z.object({
|
|
5
5
|
accountId: z.string().describe('Account ID for the transfer (e.g., "0.0.xxxx").'),
|
|
6
6
|
amount: z.union([z.number(), z.string()]).describe(
|
|
7
|
-
"HBAR amount. Positive for credit, negative for debit.
|
|
7
|
+
"HBAR amount in decimal format (e.g., 1 for 1 HBAR, 0.5 for 0.5 HBAR). Positive for credit, negative for debit. DO NOT multiply by 10^8 for tinybars - just use the HBAR amount directly."
|
|
8
8
|
)
|
|
9
9
|
});
|
|
10
10
|
const TransferHbarZodSchemaCore = z.object({
|
|
@@ -21,9 +21,22 @@ class TransferHbarTool extends BaseHederaTransactionTool {
|
|
|
21
21
|
this.specificInputSchema = TransferHbarZodSchemaCore;
|
|
22
22
|
this.namespace = "account";
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates and returns the service builder for account operations.
|
|
26
|
+
*
|
|
27
|
+
* @returns BaseServiceBuilder instance configured for account operations
|
|
28
|
+
*/
|
|
24
29
|
getServiceBuilder() {
|
|
25
30
|
return new AccountBuilder(this.hederaKit);
|
|
26
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Executes the HBAR transfer using the provided builder and arguments.
|
|
34
|
+
* Validates that all transfers sum to zero before execution.
|
|
35
|
+
*
|
|
36
|
+
* @param builder - The service builder instance for executing transactions
|
|
37
|
+
* @param specificArgs - The validated transfer parameters including transfers array and optional memo
|
|
38
|
+
* @returns Promise that resolves when the transfer is complete
|
|
39
|
+
*/
|
|
27
40
|
async callBuilderMethod(builder, specificArgs) {
|
|
28
41
|
await builder.transferHbar(
|
|
29
42
|
specificArgs
|
package/dist/esm/index12.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index12.js","sources":["../../src/plugins/hbar-transfer/TransferHbarTool.ts"],"sourcesContent":["import { z } from 'zod';\nimport { HbarTransferParams } from './types';\nimport { AccountBuilder } from './AccountBuilder';\nimport { BaseHederaTransactionTool, BaseServiceBuilder } from 'hedera-agent-kit';\n\nconst HbarTransferInputSchema = z.object({\n accountId: z\n .string()\n .describe('Account ID for the transfer (e.g., \"0.0.xxxx\").'),\n amount: z\n .union([z.number(), z.string()])\n .describe(\n 'HBAR amount. Positive for credit, negative for debit.
|
|
1
|
+
{"version":3,"file":"index12.js","sources":["../../src/plugins/hbar-transfer/TransferHbarTool.ts"],"sourcesContent":["import { z } from 'zod';\nimport { HbarTransferParams } from './types';\nimport { AccountBuilder } from './AccountBuilder';\nimport { BaseHederaTransactionTool, BaseServiceBuilder } from 'hedera-agent-kit';\n\nconst HbarTransferInputSchema = z.object({\n accountId: z\n .string()\n .describe('Account ID for the transfer (e.g., \"0.0.xxxx\").'),\n amount: z\n .union([z.number(), z.string()])\n .describe(\n 'HBAR amount in decimal format (e.g., 1 for 1 HBAR, 0.5 for 0.5 HBAR). Positive for credit, negative for debit. DO NOT multiply by 10^8 for tinybars - just use the HBAR amount directly.'\n ),\n});\n\nconst TransferHbarZodSchemaCore = z.object({\n transfers: z\n .array(HbarTransferInputSchema)\n .min(1)\n .describe(\n 'Array of ALL transfers for this transaction. For multi-party transfers (e.g., \"A sends 5 to C and B sends 3 to C\"), include all transfers here: [{accountId: \"A\", amount: -5}, {accountId: \"B\", amount: -3}, {accountId: \"C\", amount: 8}]. Amounts must sum to zero.'\n ),\n memo: z.string().optional().describe('Optional. Memo for the transaction.'),\n});\n\n/**\n * A Hedera transaction tool for transferring HBAR between accounts.\n * Supports single and multi-party transfers with automatic balance validation.\n * Extends BaseHederaTransactionTool to handle HBAR transfer transactions on the Hedera network.\n */\nexport class TransferHbarTool extends BaseHederaTransactionTool<\n typeof TransferHbarZodSchemaCore\n> {\n name = 'hedera-account-transfer-hbar-v2';\n description =\n 'PRIMARY TOOL FOR HBAR TRANSFERS: Transfers HBAR between accounts. Supports multiple transfers in a single transaction - when multiple accounts need to send/receive HBAR (e.g., \"A sends 5 HBAR to C and B sends 3 HBAR to C\"), include ALL transfers in one transfers array. The sum of all transfers must equal zero. Use this for scheduled transactions and multi-signature scenarios.';\n specificInputSchema = TransferHbarZodSchemaCore;\n namespace = 'account';\n\n\n /**\n * Creates and returns the service builder for account operations.\n * \n * @returns BaseServiceBuilder instance configured for account operations\n */\n protected getServiceBuilder(): BaseServiceBuilder {\n return new AccountBuilder(this.hederaKit) as BaseServiceBuilder;\n }\n\n /**\n * Executes the HBAR transfer using the provided builder and arguments.\n * Validates that all transfers sum to zero before execution.\n * \n * @param builder - The service builder instance for executing transactions\n * @param specificArgs - The validated transfer parameters including transfers array and optional memo\n * @returns Promise that resolves when the transfer is complete\n */\n protected async callBuilderMethod(\n builder: BaseServiceBuilder,\n specificArgs: z.infer<typeof TransferHbarZodSchemaCore>\n ): Promise<void> {\n await (builder as AccountBuilder).transferHbar(\n specificArgs as unknown as HbarTransferParams\n );\n }\n}"],"names":[],"mappings":";;;AAKA,MAAM,0BAA0B,EAAE,OAAO;AAAA,EACvC,WAAW,EACR,SACA,SAAS,iDAAiD;AAAA,EAC7D,QAAQ,EACL,MAAM,CAAC,EAAE,OAAA,GAAU,EAAE,QAAQ,CAAC,EAC9B;AAAA,IACC;AAAA,EAAA;AAEN,CAAC;AAED,MAAM,4BAA4B,EAAE,OAAO;AAAA,EACzC,WAAW,EACR,MAAM,uBAAuB,EAC7B,IAAI,CAAC,EACL;AAAA,IACC;AAAA,EAAA;AAAA,EAEJ,MAAM,EAAE,OAAA,EAAS,SAAA,EAAW,SAAS,qCAAqC;AAC5E,CAAC;AAOM,MAAM,yBAAyB,0BAEpC;AAAA,EAFK,cAAA;AAAA,UAAA,GAAA,SAAA;AAGL,SAAA,OAAO;AACP,SAAA,cACE;AACF,SAAA,sBAAsB;AACtB,SAAA,YAAY;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQF,oBAAwC;AAChD,WAAO,IAAI,eAAe,KAAK,SAAS;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAgB,kBACd,SACA,cACe;AACf,UAAO,QAA2B;AAAA,MAChC;AAAA,IAAA;AAAA,EAEJ;AACF;"}
|
package/dist/esm/index14.js
CHANGED
|
@@ -1,127 +1,151 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
class
|
|
4
|
-
constructor(
|
|
5
|
-
this.
|
|
6
|
-
this.tools = /* @__PURE__ */ new Map();
|
|
7
|
-
this.logger = logger;
|
|
1
|
+
import { ContentStorage } from "./index19.js";
|
|
2
|
+
import { ContentStoreService, ContentResolverRegistry, shouldUseReference, extractReferenceId } from "@hashgraphonline/standards-sdk";
|
|
3
|
+
class ContentStorageAdapter {
|
|
4
|
+
constructor(storage) {
|
|
5
|
+
this.storage = storage;
|
|
8
6
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const transport = new StdioClientTransport({
|
|
26
|
-
command: config.command,
|
|
27
|
-
args: config.args,
|
|
28
|
-
...config.env && { env: config.env }
|
|
29
|
-
});
|
|
30
|
-
const client = new Client({
|
|
31
|
-
name: `conversational-agent-${config.name}`,
|
|
32
|
-
version: "1.0.0"
|
|
33
|
-
}, {
|
|
34
|
-
capabilities: {}
|
|
35
|
-
});
|
|
36
|
-
await client.connect(transport);
|
|
37
|
-
this.clients.set(config.name, client);
|
|
38
|
-
const toolsResponse = await client.listTools();
|
|
39
|
-
const toolsWithServer = toolsResponse.tools.map((tool) => ({
|
|
40
|
-
...tool,
|
|
41
|
-
serverName: config.name
|
|
42
|
-
}));
|
|
43
|
-
this.tools.set(config.name, toolsWithServer);
|
|
44
|
-
this.logger.info(`Connected to MCP server ${config.name} with ${toolsWithServer.length} tools`);
|
|
45
|
-
return {
|
|
46
|
-
serverName: config.name,
|
|
47
|
-
connected: true,
|
|
48
|
-
tools: toolsWithServer
|
|
49
|
-
};
|
|
50
|
-
} catch (error) {
|
|
51
|
-
this.logger.error(`Failed to connect to MCP server ${config.name}:`, error);
|
|
52
|
-
return {
|
|
53
|
-
serverName: config.name,
|
|
54
|
-
connected: false,
|
|
55
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
56
|
-
tools: []
|
|
57
|
-
};
|
|
24
|
+
return response;
|
|
25
|
+
} else {
|
|
26
|
+
throw new Error(result.error || "Reference not found");
|
|
58
27
|
}
|
|
59
28
|
}
|
|
29
|
+
async hasReference(referenceId) {
|
|
30
|
+
return await this.storage.hasReference(referenceId);
|
|
31
|
+
}
|
|
32
|
+
async cleanupReference(referenceId) {
|
|
33
|
+
await this.storage.cleanupReference(referenceId);
|
|
34
|
+
}
|
|
35
|
+
async getStats() {
|
|
36
|
+
return await this.storage.getStats();
|
|
37
|
+
}
|
|
38
|
+
async updateConfig(config) {
|
|
39
|
+
return await this.storage.updateConfig(config);
|
|
40
|
+
}
|
|
41
|
+
async performCleanup() {
|
|
42
|
+
await this.storage.performCleanup();
|
|
43
|
+
}
|
|
44
|
+
async dispose() {
|
|
45
|
+
return Promise.resolve(this.storage.dispose());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class ContentResolver {
|
|
49
|
+
constructor(adapter) {
|
|
50
|
+
this.adapter = adapter;
|
|
51
|
+
}
|
|
52
|
+
async resolveReference(referenceId) {
|
|
53
|
+
return await this.adapter.resolveReference(referenceId);
|
|
54
|
+
}
|
|
55
|
+
shouldUseReference(content) {
|
|
56
|
+
return shouldUseReference(content);
|
|
57
|
+
}
|
|
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
|
|
70
|
+
};
|
|
71
|
+
this.contentStorage = new ContentStorage(maxMessageStorage, referenceConfig);
|
|
72
|
+
this.adapter = new ContentStorageAdapter(this.contentStorage);
|
|
73
|
+
this.resolver = new ContentResolver(this.adapter);
|
|
74
|
+
}
|
|
60
75
|
/**
|
|
61
|
-
*
|
|
76
|
+
* Initialize and register content storage for cross-package access
|
|
62
77
|
*/
|
|
63
|
-
async
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
async initialize() {
|
|
79
|
+
if (this.isRegistered) {
|
|
80
|
+
this.logger.warn("ContentStoreManager is already initialized");
|
|
81
|
+
return;
|
|
67
82
|
}
|
|
68
|
-
this.logger.debug(`Executing MCP tool ${toolName} on server ${serverName}`, args);
|
|
69
83
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return result;
|
|
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");
|
|
75
88
|
} catch (error) {
|
|
76
|
-
this.logger.error(
|
|
89
|
+
this.logger.error("Failed to initialize ContentStoreManager:", error);
|
|
77
90
|
throw error;
|
|
78
91
|
}
|
|
79
92
|
}
|
|
80
93
|
/**
|
|
81
|
-
*
|
|
94
|
+
* Get the underlying ContentStorage instance
|
|
82
95
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
await client.close();
|
|
87
|
-
this.logger.info(`Disconnected from MCP server ${name}`);
|
|
88
|
-
} catch (error) {
|
|
89
|
-
this.logger.error(`Error disconnecting MCP server ${name}:`, error);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
this.clients.clear();
|
|
93
|
-
this.tools.clear();
|
|
96
|
+
getContentStorage() {
|
|
97
|
+
return this.contentStorage;
|
|
94
98
|
}
|
|
95
99
|
/**
|
|
96
|
-
* Get
|
|
100
|
+
* Get storage statistics
|
|
97
101
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
for (const tools of this.tools.values()) {
|
|
101
|
-
allTools.push(...tools);
|
|
102
|
-
}
|
|
103
|
-
return allTools;
|
|
102
|
+
async getStats() {
|
|
103
|
+
return await this.contentStorage.getStats();
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
106
|
+
* Update configuration
|
|
107
107
|
*/
|
|
108
|
-
|
|
109
|
-
return this.
|
|
108
|
+
async updateConfig(config) {
|
|
109
|
+
return await this.contentStorage.updateConfig(config);
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
112
|
+
* Perform manual cleanup
|
|
113
113
|
*/
|
|
114
|
-
|
|
115
|
-
return this.
|
|
114
|
+
async performCleanup() {
|
|
115
|
+
return await this.contentStorage.performCleanup();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if content should be stored as reference
|
|
119
|
+
*/
|
|
120
|
+
shouldUseReference(content) {
|
|
121
|
+
return this.contentStorage.shouldUseReference(content);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Store content if it's large enough
|
|
125
|
+
*/
|
|
126
|
+
async storeContentIfLarge(content, metadata) {
|
|
127
|
+
return await this.contentStorage.storeContentIfLarge(content, metadata);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Cleanup and unregister
|
|
131
|
+
*/
|
|
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
|
+
}
|
|
116
140
|
}
|
|
117
141
|
/**
|
|
118
|
-
*
|
|
142
|
+
* Check if the manager is initialized
|
|
119
143
|
*/
|
|
120
|
-
|
|
121
|
-
return
|
|
144
|
+
isInitialized() {
|
|
145
|
+
return this.isRegistered;
|
|
122
146
|
}
|
|
123
147
|
}
|
|
124
148
|
export {
|
|
125
|
-
|
|
149
|
+
ContentStoreManager
|
|
126
150
|
};
|
|
127
151
|
//# sourceMappingURL=index14.js.map
|