@hashgraphonline/conversational-agent 0.2.200 → 0.2.201
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/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index10.js +1 -1
- package/dist/esm/index21.js +1 -1
- package/dist/esm/index33.js +3 -3
- package/dist/esm/index37.js +1 -1
- package/dist/esm/index42.js +95 -5
- package/dist/esm/index42.js.map +1 -1
- package/dist/esm/index43.js +7 -322
- package/dist/esm/index43.js.map +1 -1
- package/dist/esm/index44.js +24 -181
- package/dist/esm/index44.js.map +1 -1
- package/dist/esm/index45.js +4 -6
- package/dist/esm/index45.js.map +1 -1
- package/dist/esm/index46.js +319 -24
- package/dist/esm/index46.js.map +1 -1
- package/dist/esm/index47.js +174 -85
- package/dist/esm/index47.js.map +1 -1
- package/package.json +2 -3
- package/src/plugins/hbar/AccountBuilder.ts +1 -1
package/dist/esm/index44.js
CHANGED
|
@@ -1,187 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const DEFAULT_CONTENT_REFERENCE_CONFIG = {
|
|
2
|
+
sizeThresholdBytes: 10 * 1024,
|
|
3
|
+
maxAgeMs: 60 * 60 * 1e3,
|
|
4
|
+
maxReferences: 100,
|
|
5
|
+
maxTotalStorageBytes: 100 * 1024 * 1024,
|
|
6
|
+
enableAutoCleanup: true,
|
|
7
|
+
cleanupIntervalMs: 5 * 60 * 1e3,
|
|
8
|
+
enablePersistence: false,
|
|
9
|
+
storageBackend: "memory",
|
|
10
|
+
cleanupPolicies: {
|
|
11
|
+
recent: { maxAgeMs: 30 * 60 * 1e3, priority: 1 },
|
|
12
|
+
userContent: { maxAgeMs: 2 * 60 * 60 * 1e3, priority: 2 },
|
|
13
|
+
agentGenerated: { maxAgeMs: 60 * 60 * 1e3, priority: 3 },
|
|
14
|
+
default: { maxAgeMs: 60 * 60 * 1e3, priority: 4 }
|
|
9
15
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw new Error(`Tool not found in registry: ${toolName}`);
|
|
19
|
-
}
|
|
20
|
-
const context = {
|
|
21
|
-
toolName,
|
|
22
|
-
input,
|
|
23
|
-
session: sessionContext || this.buildDefaultSession(),
|
|
24
|
-
memory: this.memory,
|
|
25
|
-
traceId,
|
|
26
|
-
toolEntry
|
|
27
|
-
};
|
|
28
|
-
try {
|
|
29
|
-
const shouldGenerateForm = await this.checkFormGeneration(context);
|
|
30
|
-
if (shouldGenerateForm.requiresForm && shouldGenerateForm.formMessage) {
|
|
31
|
-
return {
|
|
32
|
-
success: false,
|
|
33
|
-
output: "Form generation required",
|
|
34
|
-
requiresForm: true,
|
|
35
|
-
formMessage: shouldGenerateForm.formMessage,
|
|
36
|
-
traceId,
|
|
37
|
-
executionTime: Date.now() - startTime
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
const result = await this.executeToolDirect(context);
|
|
41
|
-
return {
|
|
42
|
-
success: true,
|
|
43
|
-
output: result,
|
|
44
|
-
traceId,
|
|
45
|
-
executionTime: Date.now() - startTime
|
|
46
|
-
};
|
|
47
|
-
} catch (error) {
|
|
48
|
-
return this.handleExecutionError(
|
|
49
|
-
error,
|
|
50
|
-
context,
|
|
51
|
-
traceId,
|
|
52
|
-
Date.now() - startTime
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Execute tool with validation
|
|
58
|
-
*/
|
|
59
|
-
async executeWithValidation(toolName, input, sessionContext) {
|
|
60
|
-
return this.execute(toolName, input, sessionContext);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Process form submission
|
|
64
|
-
*/
|
|
65
|
-
async processFormSubmission(toolName, formId, parameters, sessionContext) {
|
|
66
|
-
const traceId = `form-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
67
|
-
const startTime = Date.now();
|
|
68
|
-
try {
|
|
69
|
-
const formSubmission = {
|
|
70
|
-
formId,
|
|
71
|
-
toolName,
|
|
72
|
-
parameters,
|
|
73
|
-
timestamp: Date.now()
|
|
74
|
-
};
|
|
75
|
-
const processedInput = await this.formEngine.processSubmission(
|
|
76
|
-
formSubmission
|
|
77
|
-
);
|
|
78
|
-
return this.execute(toolName, processedInput, sessionContext);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
return {
|
|
81
|
-
success: false,
|
|
82
|
-
output: "Form submission processing failed",
|
|
83
|
-
error: error instanceof Error ? error.message : String(error),
|
|
84
|
-
traceId,
|
|
85
|
-
executionTime: Date.now() - startTime
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Check if form generation is required
|
|
91
|
-
*/
|
|
92
|
-
async checkFormGeneration(context) {
|
|
93
|
-
const inputRecord = context.input;
|
|
94
|
-
if (inputRecord?.__fromForm === true || inputRecord?.renderForm === false) {
|
|
95
|
-
return { requiresForm: false };
|
|
96
|
-
}
|
|
97
|
-
if (!this.formEngine.shouldGenerateForm(context.toolEntry.tool, context.input)) {
|
|
98
|
-
return { requiresForm: false };
|
|
99
|
-
}
|
|
100
|
-
const formMessage = await this.formEngine.generateForm(
|
|
101
|
-
context.toolName,
|
|
102
|
-
context.toolEntry.tool,
|
|
103
|
-
context.input
|
|
104
|
-
);
|
|
105
|
-
if (formMessage) {
|
|
106
|
-
return { requiresForm: true, formMessage };
|
|
107
|
-
}
|
|
108
|
-
return { requiresForm: false };
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Execute tool directly
|
|
112
|
-
*/
|
|
113
|
-
async executeToolDirect(context) {
|
|
114
|
-
const { toolEntry, input } = context;
|
|
115
|
-
const parameters = input || {};
|
|
116
|
-
const mergedArgs = { ...parameters, renderForm: false };
|
|
117
|
-
if (toolEntry.wrapper) {
|
|
118
|
-
return this.executeWrappedTool(toolEntry, mergedArgs);
|
|
119
|
-
}
|
|
120
|
-
return await toolEntry.tool.call(mergedArgs);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Execute wrapped tool
|
|
124
|
-
*/
|
|
125
|
-
async executeWrappedTool(toolEntry, mergedArgs) {
|
|
126
|
-
const wrapper = toolEntry.wrapper;
|
|
127
|
-
if (!wrapper) {
|
|
128
|
-
throw new Error("Tool wrapper not found");
|
|
129
|
-
}
|
|
130
|
-
const wrapperAsAny = wrapper;
|
|
131
|
-
if (wrapperAsAny.executeOriginal) {
|
|
132
|
-
return await wrapperAsAny.executeOriginal(mergedArgs);
|
|
133
|
-
}
|
|
134
|
-
if (wrapperAsAny.originalTool?.call) {
|
|
135
|
-
return await wrapperAsAny.originalTool.call(mergedArgs);
|
|
136
|
-
}
|
|
137
|
-
return await toolEntry.originalTool.call(mergedArgs);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Handle execution error
|
|
141
|
-
*/
|
|
142
|
-
handleExecutionError(error, context, traceId, executionTime) {
|
|
143
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
144
|
-
if (error instanceof ZodError) {
|
|
145
|
-
return {
|
|
146
|
-
success: false,
|
|
147
|
-
output: "Validation error occurred",
|
|
148
|
-
error: errorMessage,
|
|
149
|
-
traceId,
|
|
150
|
-
executionTime
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
this.logger.error(`Tool execution failed: ${context.toolName}`, {
|
|
154
|
-
traceId,
|
|
155
|
-
error: errorMessage
|
|
156
|
-
});
|
|
157
|
-
return {
|
|
158
|
-
success: false,
|
|
159
|
-
output: "Tool execution failed",
|
|
160
|
-
error: errorMessage,
|
|
161
|
-
traceId,
|
|
162
|
-
executionTime
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Build default session context
|
|
167
|
-
*/
|
|
168
|
-
buildDefaultSession() {
|
|
169
|
-
return {
|
|
170
|
-
sessionId: `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
171
|
-
timestamp: Date.now()
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Get statistics about the pipeline
|
|
176
|
-
*/
|
|
177
|
-
getStatistics() {
|
|
178
|
-
return {
|
|
179
|
-
totalMiddleware: 0,
|
|
180
|
-
registeredMiddleware: []
|
|
181
|
-
};
|
|
16
|
+
};
|
|
17
|
+
class ContentReferenceError extends Error {
|
|
18
|
+
constructor(message, type, referenceId, suggestedActions) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.type = type;
|
|
21
|
+
this.referenceId = referenceId;
|
|
22
|
+
this.suggestedActions = suggestedActions;
|
|
23
|
+
this.name = "ContentReferenceError";
|
|
182
24
|
}
|
|
183
25
|
}
|
|
184
26
|
export {
|
|
185
|
-
|
|
27
|
+
ContentReferenceError,
|
|
28
|
+
DEFAULT_CONTENT_REFERENCE_CONFIG
|
|
186
29
|
};
|
|
187
30
|
//# sourceMappingURL=index44.js.map
|
package/dist/esm/index44.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index44.js","sources":["../../src/execution/execution-pipeline.ts"],"sourcesContent":["import { ZodError } from 'zod';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport { SmartMemoryManager } from '../memory/smart-memory-manager';\nimport { FormEngine, ToolExecutionResult } from '../forms/form-engine';\nimport type { FormMessage, FormSubmission } from '../forms/types';\nimport type { ToolRegistry, ToolRegistryEntry } from '../core/tool-registry';\n\n/**\n * Session context for tool execution\n */\nexport interface SessionContext {\n sessionId: string;\n userId?: string;\n timestamp: number;\n conversationId?: string;\n}\n\n/**\n * Context passed through execution pipeline\n */\nexport interface ExecutionContext {\n toolName: string;\n input: unknown;\n session: SessionContext;\n memory: SmartMemoryManager;\n traceId: string;\n toolEntry: ToolRegistryEntry;\n}\n\n/**\n * Result of tool execution with metadata\n */\nexport interface ExecutionResult extends ToolExecutionResult {\n traceId: string;\n executionTime: number;\n}\n\n/**\n * ExecutionPipeline handles tool execution coordination\n */\nexport class ExecutionPipeline {\n private logger: Logger;\n private toolRegistry: ToolRegistry;\n private formEngine: FormEngine;\n private memory: SmartMemoryManager;\n\n constructor(\n toolRegistry: ToolRegistry,\n formEngine: FormEngine,\n memory: SmartMemoryManager,\n logger?: Logger\n ) {\n this.toolRegistry = toolRegistry;\n this.formEngine = formEngine;\n this.memory = memory;\n this.logger = logger || new Logger({ module: 'ExecutionPipeline' });\n }\n\n /**\n * Execute a tool through the pipeline\n */\n async execute(\n toolName: string,\n input: unknown,\n sessionContext?: SessionContext\n ): Promise<ExecutionResult> {\n const traceId = `trace-${Date.now()}-${Math.random()\n .toString(36)\n .substr(2, 9)}`;\n const startTime = Date.now();\n\n const toolEntry = this.toolRegistry.getTool(toolName);\n if (!toolEntry) {\n throw new Error(`Tool not found in registry: ${toolName}`);\n }\n\n const context: ExecutionContext = {\n toolName,\n input,\n session: sessionContext || this.buildDefaultSession(),\n memory: this.memory,\n traceId,\n toolEntry,\n };\n\n try {\n const shouldGenerateForm = await this.checkFormGeneration(context);\n if (shouldGenerateForm.requiresForm && shouldGenerateForm.formMessage) {\n return {\n success: false,\n output: 'Form generation required',\n requiresForm: true,\n formMessage: shouldGenerateForm.formMessage,\n traceId,\n executionTime: Date.now() - startTime,\n };\n }\n\n const result = await this.executeToolDirect(context);\n\n return {\n success: true,\n output: result,\n traceId,\n executionTime: Date.now() - startTime,\n };\n } catch (error) {\n return this.handleExecutionError(\n error,\n context,\n traceId,\n Date.now() - startTime\n );\n }\n }\n\n /**\n * Execute tool with validation\n */\n async executeWithValidation(\n toolName: string,\n input: unknown,\n sessionContext?: SessionContext\n ): Promise<ExecutionResult> {\n return this.execute(toolName, input, sessionContext);\n }\n\n /**\n * Process form submission\n */\n async processFormSubmission(\n toolName: string,\n formId: string,\n parameters: Record<string, unknown>,\n sessionContext?: SessionContext\n ): Promise<ExecutionResult> {\n const traceId = `form-${Date.now()}-${Math.random()\n .toString(36)\n .substr(2, 9)}`;\n const startTime = Date.now();\n\n try {\n const formSubmission: FormSubmission = {\n formId,\n toolName,\n parameters,\n timestamp: Date.now(),\n };\n\n const processedInput = await this.formEngine.processSubmission(\n formSubmission\n );\n\n return this.execute(toolName, processedInput, sessionContext);\n } catch (error) {\n return {\n success: false,\n output: 'Form submission processing failed',\n error: error instanceof Error ? error.message : String(error),\n traceId,\n executionTime: Date.now() - startTime,\n };\n }\n }\n\n /**\n * Check if form generation is required\n */\n private async checkFormGeneration(context: ExecutionContext): Promise<{\n requiresForm: boolean;\n formMessage?: FormMessage;\n }> {\n const inputRecord = context.input as Record<string, unknown>;\n if (inputRecord?.__fromForm === true || inputRecord?.renderForm === false) {\n return { requiresForm: false };\n }\n\n if (\n !this.formEngine.shouldGenerateForm(context.toolEntry.tool, context.input)\n ) {\n return { requiresForm: false };\n }\n\n const formMessage = await this.formEngine.generateForm(\n context.toolName,\n context.toolEntry.tool,\n context.input\n );\n\n if (formMessage) {\n return { requiresForm: true, formMessage };\n }\n\n return { requiresForm: false };\n }\n\n /**\n * Execute tool directly\n */\n private async executeToolDirect(context: ExecutionContext): Promise<string> {\n const { toolEntry, input } = context;\n const parameters = (input as Record<string, unknown>) || {};\n const mergedArgs = { ...parameters, renderForm: false };\n\n if (toolEntry.wrapper) {\n return this.executeWrappedTool(toolEntry, mergedArgs);\n }\n\n return await toolEntry.tool.call(mergedArgs);\n }\n\n /**\n * Execute wrapped tool\n */\n private async executeWrappedTool(\n toolEntry: ToolRegistryEntry,\n mergedArgs: Record<string, unknown>\n ): Promise<string> {\n const wrapper = toolEntry.wrapper;\n if (!wrapper) {\n throw new Error('Tool wrapper not found');\n }\n\n const wrapperAsAny = wrapper as unknown as {\n executeOriginal?: (args: Record<string, unknown>) => Promise<string>;\n originalTool?: {\n call?: (args: Record<string, unknown>) => Promise<string>;\n };\n };\n\n if (wrapperAsAny.executeOriginal) {\n return await wrapperAsAny.executeOriginal(mergedArgs);\n }\n\n if (wrapperAsAny.originalTool?.call) {\n return await wrapperAsAny.originalTool.call(mergedArgs);\n }\n\n return await toolEntry.originalTool.call(mergedArgs);\n }\n\n /**\n * Handle execution error\n */\n private handleExecutionError(\n error: unknown,\n context: ExecutionContext,\n traceId: string,\n executionTime: number\n ): ExecutionResult {\n const errorMessage = error instanceof Error ? error.message : String(error);\n\n if (error instanceof ZodError) {\n return {\n success: false,\n output: 'Validation error occurred',\n error: errorMessage,\n traceId,\n executionTime,\n };\n }\n\n this.logger.error(`Tool execution failed: ${context.toolName}`, {\n traceId,\n error: errorMessage,\n });\n\n return {\n success: false,\n output: 'Tool execution failed',\n error: errorMessage,\n traceId,\n executionTime,\n };\n }\n\n /**\n * Build default session context\n */\n private buildDefaultSession(): SessionContext {\n return {\n sessionId: `session-${Date.now()}-${Math.random()\n .toString(36)\n .substr(2, 9)}`,\n timestamp: Date.now(),\n };\n }\n\n /**\n * Get statistics about the pipeline\n */\n getStatistics(): {\n totalMiddleware: number;\n registeredMiddleware: string[];\n } {\n return {\n totalMiddleware: 0,\n registeredMiddleware: [],\n };\n }\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index44.js","sources":["../../src/types/content-reference.ts"],"sourcesContent":["/**\n * Content Reference System Types\n *\n * Shared interfaces for the Reference-Based Content System that handles\n * large content storage with unique reference IDs to optimize context window usage.\n */\n\n/**\n * Unique identifier for stored content references\n * Format: Cryptographically secure 32-byte identifier with base64url encoding\n */\nexport type ReferenceId = string;\n\n/**\n * Lifecycle state of a content reference\n */\nexport type ReferenceLifecycleState =\n | 'active'\n | 'expired'\n | 'cleanup_pending'\n | 'invalid';\n\n/**\n * Content types supported by the reference system\n */\nexport type ContentType =\n | 'text'\n | 'json'\n | 'html'\n | 'markdown'\n | 'binary'\n | 'unknown';\n\n/**\n * Sources that created the content reference\n */\nexport type ContentSource =\n | 'mcp_tool'\n | 'user_upload'\n | 'agent_generated'\n | 'system';\n\n/**\n * Metadata associated with stored content\n */\nexport interface ContentMetadata {\n /** Content type classification */\n contentType: ContentType;\n\n /** MIME type of the original content */\n mimeType?: string;\n\n /** Size in bytes of the stored content */\n sizeBytes: number;\n\n /** When the content was originally stored */\n createdAt: Date;\n\n /** Last time the content was accessed via reference resolution */\n lastAccessedAt: Date;\n\n /** Source that created this content reference */\n source: ContentSource;\n\n /** Name of the MCP tool that generated the content (if applicable) */\n mcpToolName?: string;\n\n /** Original filename or suggested name for the content */\n fileName?: string;\n\n /** Number of times this reference has been resolved */\n accessCount: number;\n\n /** Tags for categorization and cleanup policies */\n tags?: string[];\n\n /** Custom metadata from the source */\n customMetadata?: Record<string, unknown>;\n}\n\n/**\n * Core content reference object passed through agent context\n * Designed to be lightweight (<100 tokens) while providing enough\n * information for agent decision-making\n */\nexport interface ContentReference {\n /** Unique identifier for resolving the content */\n referenceId: ReferenceId;\n\n /** Current lifecycle state */\n state: ReferenceLifecycleState;\n\n /** Brief description or preview of the content (max 200 chars) */\n preview: string;\n\n /** Essential metadata for agent decision-making */\n metadata: Pick<\n ContentMetadata,\n 'contentType' | 'sizeBytes' | 'source' | 'fileName' | 'mimeType'\n >;\n\n /** When this reference was created */\n createdAt: Date;\n\n /** Special format indicator for reference IDs in content */\n readonly format: 'ref://{id}';\n}\n\n/**\n * Result of attempting to resolve a content reference\n */\nexport interface ReferenceResolutionResult {\n /** Whether the resolution was successful */\n success: boolean;\n\n /** The resolved content if successful */\n content?: Buffer;\n\n /** Complete metadata if successful */\n metadata?: ContentMetadata;\n\n /** Error message if resolution failed */\n error?: string;\n\n /** Specific error type for targeted error handling */\n errorType?:\n | 'not_found'\n | 'expired'\n | 'corrupted'\n | 'access_denied'\n | 'system_error';\n\n /** Suggested actions for recovery */\n suggestedActions?: string[];\n}\n\n/**\n * Configuration for content reference storage and lifecycle\n */\nexport interface ContentReferenceConfig {\n /** Size threshold above which content should be stored as references (default: 10KB) */\n sizeThresholdBytes: number;\n\n /** Maximum age for unused references before cleanup (default: 1 hour) */\n maxAgeMs: number;\n\n /** Maximum number of references to store simultaneously */\n maxReferences: number;\n\n /** Maximum total storage size for all references */\n maxTotalStorageBytes: number;\n\n /** Whether to enable automatic cleanup */\n enableAutoCleanup: boolean;\n\n /** Interval for cleanup checks in milliseconds */\n cleanupIntervalMs: number;\n\n /** Whether to persist references across restarts */\n enablePersistence: boolean;\n\n /** Storage backend configuration */\n storageBackend: 'memory' | 'filesystem' | 'hybrid';\n\n /** Cleanup policies for different content types */\n cleanupPolicies: {\n /** Policy for content marked as \"recent\" from MCP tools */\n recent: { maxAgeMs: number; priority: number };\n\n /** Policy for user-uploaded content */\n userContent: { maxAgeMs: number; priority: number };\n\n /** Policy for agent-generated content */\n agentGenerated: { maxAgeMs: number; priority: number };\n\n /** Default policy for other content */\n default: { maxAgeMs: number; priority: number };\n };\n}\n\n/**\n * Default configuration values\n */\nexport const DEFAULT_CONTENT_REFERENCE_CONFIG: ContentReferenceConfig = {\n sizeThresholdBytes: 10 * 1024,\n maxAgeMs: 60 * 60 * 1000,\n maxReferences: 100,\n maxTotalStorageBytes: 100 * 1024 * 1024,\n enableAutoCleanup: true,\n cleanupIntervalMs: 5 * 60 * 1000,\n enablePersistence: false,\n storageBackend: 'memory',\n cleanupPolicies: {\n recent: { maxAgeMs: 30 * 60 * 1000, priority: 1 },\n userContent: { maxAgeMs: 2 * 60 * 60 * 1000, priority: 2 },\n agentGenerated: { maxAgeMs: 60 * 60 * 1000, priority: 3 },\n default: { maxAgeMs: 60 * 60 * 1000, priority: 4 },\n },\n};\n\n/**\n * Statistics about content reference usage and storage\n */\nexport interface ContentReferenceStats {\n /** Total number of active references */\n activeReferences: number;\n\n /** Total storage used by all references in bytes */\n totalStorageBytes: number;\n\n /** Number of references cleaned up in last cleanup cycle */\n recentlyCleanedUp: number;\n\n /** Number of successful reference resolutions since startup */\n totalResolutions: number;\n\n /** Number of failed resolution attempts */\n failedResolutions: number;\n\n /** Average content size in bytes */\n averageContentSize: number;\n\n /** Most frequently accessed reference ID */\n mostAccessedReferenceId?: ReferenceId;\n\n /** Storage utilization percentage */\n storageUtilization: number;\n\n /** Performance metrics */\n performanceMetrics: {\n /** Average time to create a reference in milliseconds */\n averageCreationTimeMs: number;\n\n /** Average time to resolve a reference in milliseconds */\n averageResolutionTimeMs: number;\n\n /** Average cleanup time in milliseconds */\n averageCleanupTimeMs: number;\n };\n}\n\n/**\n * Error types for content reference operations\n */\nexport class ContentReferenceError extends Error {\n constructor(\n message: string,\n public readonly type: ReferenceResolutionResult['errorType'],\n public readonly referenceId?: ReferenceId,\n public readonly suggestedActions?: string[]\n ) {\n super(message);\n this.name = 'ContentReferenceError';\n }\n}\n\n/**\n * Interface for content reference storage implementations\n */\nexport interface ContentReferenceStore {\n /**\n * Store content and return a reference\n */\n storeContent(\n content: Buffer,\n metadata: Omit<\n ContentMetadata,\n 'createdAt' | 'lastAccessedAt' | 'accessCount'\n >\n ): Promise<ContentReference>;\n\n /**\n * Resolve a reference to its content\n */\n resolveReference(\n referenceId: ReferenceId\n ): Promise<ReferenceResolutionResult>;\n\n /**\n * Check if a reference exists and is valid\n */\n hasReference(referenceId: ReferenceId): Promise<boolean>;\n\n /**\n * Mark a reference for cleanup\n */\n cleanupReference(referenceId: ReferenceId): Promise<boolean>;\n\n /**\n * Get current storage statistics\n */\n getStats(): Promise<ContentReferenceStats>;\n\n /**\n * Update configuration\n */\n updateConfig(config: Partial<ContentReferenceConfig>): Promise<void>;\n\n /**\n * Perform cleanup based on current policies\n */\n performCleanup(): Promise<{ cleanedUp: number; errors: string[] }>;\n\n /**\n * Dispose of resources\n */\n dispose(): Promise<void>;\n}\n"],"names":[],"mappings":"AAuLO,MAAM,mCAA2D;AAAA,EACtE,oBAAoB,KAAK;AAAA,EACzB,UAAU,KAAK,KAAK;AAAA,EACpB,eAAe;AAAA,EACf,sBAAsB,MAAM,OAAO;AAAA,EACnC,mBAAmB;AAAA,EACnB,mBAAmB,IAAI,KAAK;AAAA,EAC5B,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,IACf,QAAQ,EAAE,UAAU,KAAK,KAAK,KAAM,UAAU,EAAA;AAAA,IAC9C,aAAa,EAAE,UAAU,IAAI,KAAK,KAAK,KAAM,UAAU,EAAA;AAAA,IACvD,gBAAgB,EAAE,UAAU,KAAK,KAAK,KAAM,UAAU,EAAA;AAAA,IACtD,SAAS,EAAE,UAAU,KAAK,KAAK,KAAM,UAAU,EAAA;AAAA,EAAE;AAErD;AA8CO,MAAM,8BAA8B,MAAM;AAAA,EAC/C,YACE,SACgB,MACA,aACA,kBAChB;AACA,UAAM,OAAO;AAJG,SAAA,OAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;"}
|
package/dist/esm/index45.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
ADVANCED: "advanced",
|
|
5
|
-
EXPERT: "expert"
|
|
1
|
+
const ERROR_MESSAGES = {
|
|
2
|
+
TOO_MANY_REQUESTS: "Too many requests. Please wait a moment and try again.",
|
|
3
|
+
RATE_LIMITED: "I'm receiving too many requests right now. Please wait a moment and try again."
|
|
6
4
|
};
|
|
7
5
|
export {
|
|
8
|
-
|
|
6
|
+
ERROR_MESSAGES
|
|
9
7
|
};
|
|
10
8
|
//# sourceMappingURL=index45.js.map
|
package/dist/esm/index45.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index45.js","sources":["../../src/constants/
|
|
1
|
+
{"version":3,"file":"index45.js","sources":["../../src/constants/messages.ts"],"sourcesContent":["/**\n * Common error messages and user feedback strings\n */\nexport const ERROR_MESSAGES = {\n TOO_MANY_REQUESTS: 'Too many requests. Please wait a moment and try again.',\n RATE_LIMITED: \"I'm receiving too many requests right now. Please wait a moment and try again.\",\n SYSTEM_ERROR: 'System error occurred',\n INVALID_INPUT: 'Invalid input provided',\n NETWORK_ERROR: 'Network error occurred',\n} as const;\n\n/**\n * Common success and status messages\n */\nexport const STATUS_MESSAGES = {\n OPERATION_SUCCESSFUL: 'Operation completed successfully',\n PROCESSING: 'Processing your request...',\n READY: 'Ready to process requests',\n INITIALIZING: 'Initializing...',\n} as const;"],"names":[],"mappings":"AAGO,MAAM,iBAAiB;AAAA,EAC5B,mBAAmB;AAAA,EACnB,cAAc;AAIhB;"}
|
package/dist/esm/index46.js
CHANGED
|
@@ -1,30 +1,325 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
userContent: { maxAgeMs: 2 * 60 * 60 * 1e3, priority: 2 },
|
|
13
|
-
agentGenerated: { maxAgeMs: 60 * 60 * 1e3, priority: 3 },
|
|
14
|
-
default: { maxAgeMs: 60 * 60 * 1e3, priority: 4 }
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Logger } from "@hashgraphonline/standards-sdk";
|
|
3
|
+
import { wrapToolWithFormValidation } from "./index32.js";
|
|
4
|
+
import { FormGenerator } from "./index10.js";
|
|
5
|
+
import { fieldGuidanceRegistry } from "./index13.js";
|
|
6
|
+
import { isFormValidatable } from "@hashgraphonline/standards-agent-kit";
|
|
7
|
+
class ToolRegistry {
|
|
8
|
+
constructor(logger) {
|
|
9
|
+
this.tools = /* @__PURE__ */ new Map();
|
|
10
|
+
this.formGenerator = new FormGenerator();
|
|
11
|
+
this.logger = logger || new Logger({ module: "ToolRegistry" });
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Register a tool with the registry
|
|
15
|
+
*/
|
|
16
|
+
registerTool(tool, options = {}) {
|
|
17
|
+
const capabilities = this.analyzeToolCapabilities(tool);
|
|
18
|
+
const metadata = {
|
|
19
|
+
name: tool.name,
|
|
20
|
+
version: "1.0.0",
|
|
21
|
+
category: options.metadata?.category || "core",
|
|
22
|
+
description: tool.description,
|
|
23
|
+
capabilities,
|
|
24
|
+
dependencies: [],
|
|
25
|
+
schema: tool.schema,
|
|
26
|
+
...options.metadata
|
|
27
|
+
};
|
|
28
|
+
try {
|
|
29
|
+
if (!metadata.entityResolutionPreferences) {
|
|
30
|
+
const schemaRecord = tool.schema;
|
|
31
|
+
const rawPrefs = schemaRecord && typeof schemaRecord === "object" && schemaRecord["_entityResolutionPreferences"];
|
|
32
|
+
if (rawPrefs && typeof rawPrefs === "object") {
|
|
33
|
+
metadata.entityResolutionPreferences = rawPrefs;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const schemaRecord = tool.schema;
|
|
40
|
+
const schemaDef = schemaRecord && schemaRecord._def;
|
|
41
|
+
if (schemaDef?.typeName === "ZodObject") {
|
|
42
|
+
const shape = typeof schemaDef.shape === "function" ? schemaDef.shape?.() || {} : schemaDef.shape || {};
|
|
43
|
+
const metadataField = shape["metadata"];
|
|
44
|
+
const isStringArray = !!metadataField && metadataField._def?.typeName === "ZodArray" && metadataField._def?.type?._def?.typeName === "ZodString";
|
|
45
|
+
if (isStringArray && typeof tool.description === "string") {
|
|
46
|
+
if (!metadata.entityResolutionPreferences) {
|
|
47
|
+
metadata.entityResolutionPreferences = {
|
|
48
|
+
inscription: "hrl"
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const note = " NOTE: When referencing inscriptions or media, provide canonical Hashlink Resource Locators (e.g., hcs://<standard>/<topicId>) rather than external URLs or embedded JSON.";
|
|
52
|
+
if (!tool.description.includes("Hashlink Resource Locators")) {
|
|
53
|
+
tool.description = `${tool.description}${note}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
let finalTool = tool;
|
|
60
|
+
let wrapper;
|
|
61
|
+
if (this.shouldWrapTool(tool, capabilities, options)) {
|
|
62
|
+
wrapper = wrapToolWithFormValidation(
|
|
63
|
+
tool,
|
|
64
|
+
this.formGenerator,
|
|
65
|
+
{
|
|
66
|
+
requireAllFields: false,
|
|
67
|
+
skipFields: ["metaOptions"],
|
|
68
|
+
...options.wrapperConfig
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
finalTool = wrapper;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
if (metadata.entityResolutionPreferences) {
|
|
75
|
+
finalTool["entityResolutionPreferences"] = metadata.entityResolutionPreferences;
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
const entry = {
|
|
80
|
+
tool: finalTool,
|
|
81
|
+
metadata,
|
|
82
|
+
wrapper,
|
|
83
|
+
originalTool: tool,
|
|
84
|
+
options: {
|
|
85
|
+
priority: capabilities.priority,
|
|
86
|
+
capability: "basic",
|
|
87
|
+
// Default capability
|
|
88
|
+
enabled: true,
|
|
89
|
+
// All tools are enabled by default
|
|
90
|
+
namespace: metadata.category
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
this.tools.set(tool.name, entry);
|
|
94
|
+
try {
|
|
95
|
+
const metaFG = metadata.fieldGuidance;
|
|
96
|
+
if (metaFG) {
|
|
97
|
+
fieldGuidanceRegistry.registerToolConfiguration(metaFG);
|
|
98
|
+
}
|
|
99
|
+
const provider = metadata.fieldGuidanceProvider;
|
|
100
|
+
if (provider) {
|
|
101
|
+
const pattern = metaFG?.toolPattern ?? tool.name;
|
|
102
|
+
fieldGuidanceRegistry.registerToolProvider(pattern, provider, {
|
|
103
|
+
id: `${tool.name}:field-guidance-provider`,
|
|
104
|
+
priority: 0
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
} catch {
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get a tool by name
|
|
112
|
+
*/
|
|
113
|
+
getTool(name) {
|
|
114
|
+
return this.tools.get(name) || null;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get tools by capability
|
|
118
|
+
*/
|
|
119
|
+
getToolsByCapability(capability, value) {
|
|
120
|
+
const results = [];
|
|
121
|
+
for (const entry of this.tools.values()) {
|
|
122
|
+
if (value !== void 0) {
|
|
123
|
+
if (entry.metadata.capabilities[capability] === value) {
|
|
124
|
+
results.push(entry);
|
|
125
|
+
}
|
|
126
|
+
} else if (entry.metadata.capabilities[capability]) {
|
|
127
|
+
results.push(entry);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return results;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get tools by query
|
|
134
|
+
*/
|
|
135
|
+
getToolsByQuery(query) {
|
|
136
|
+
const results = [];
|
|
137
|
+
for (const entry of this.tools.values()) {
|
|
138
|
+
let matches = true;
|
|
139
|
+
if (query.name && entry.metadata.name !== query.name) {
|
|
140
|
+
matches = false;
|
|
141
|
+
}
|
|
142
|
+
if (query.category && entry.metadata.category !== query.category) {
|
|
143
|
+
matches = false;
|
|
144
|
+
}
|
|
145
|
+
if (query.capabilities) {
|
|
146
|
+
for (const [key, value] of Object.entries(query.capabilities)) {
|
|
147
|
+
if (entry.metadata.capabilities[key] !== value) {
|
|
148
|
+
matches = false;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (matches) {
|
|
154
|
+
results.push(entry);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return results;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get all registered tools
|
|
161
|
+
*/
|
|
162
|
+
getAllTools() {
|
|
163
|
+
return Array.from(this.tools.values()).map((entry) => entry.tool);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Get all registry entries
|
|
167
|
+
*/
|
|
168
|
+
getAllRegistryEntries() {
|
|
169
|
+
return Array.from(this.tools.values());
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get all tool names
|
|
173
|
+
*/
|
|
174
|
+
getToolNames() {
|
|
175
|
+
return Array.from(this.tools.keys());
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get tools by priority
|
|
179
|
+
*/
|
|
180
|
+
getToolsByPriority(priority) {
|
|
181
|
+
return this.getToolsByCapability("priority", priority);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get enabled tools (all tools are considered enabled by default)
|
|
185
|
+
*/
|
|
186
|
+
getEnabledTools() {
|
|
187
|
+
return this.getAllRegistryEntries();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get tools by namespace/category
|
|
191
|
+
*/
|
|
192
|
+
getToolsByNamespace(namespace) {
|
|
193
|
+
if (!namespace) {
|
|
194
|
+
return this.getAllRegistryEntries();
|
|
195
|
+
}
|
|
196
|
+
return this.getToolsByQuery({ category: namespace });
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Check if registry has capability
|
|
200
|
+
*/
|
|
201
|
+
hasCapability(capability) {
|
|
202
|
+
for (const entry of this.tools.values()) {
|
|
203
|
+
if (entry.metadata.capabilities[capability]) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Update tool options (metadata)
|
|
211
|
+
*/
|
|
212
|
+
updateToolOptions(name, options) {
|
|
213
|
+
const entry = this.tools.get(name);
|
|
214
|
+
if (!entry) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
entry.metadata = { ...entry.metadata, ...options };
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Check if a tool is registered
|
|
222
|
+
*/
|
|
223
|
+
hasTool(name) {
|
|
224
|
+
return this.tools.has(name);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Unregister a tool
|
|
228
|
+
*/
|
|
229
|
+
unregisterTool(name) {
|
|
230
|
+
return this.tools.delete(name);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Clear all tools
|
|
234
|
+
*/
|
|
235
|
+
clear() {
|
|
236
|
+
this.tools.clear();
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Analyze tool capabilities
|
|
240
|
+
*/
|
|
241
|
+
analyzeToolCapabilities(tool) {
|
|
242
|
+
const implementsFormValidatable = isFormValidatable(tool);
|
|
243
|
+
const hasRenderConfig = this.hasRenderConfig(tool);
|
|
244
|
+
const isZodObjectLike = this.isZodObjectLike(tool.schema);
|
|
245
|
+
const supportsFormValidation = implementsFormValidatable || hasRenderConfig;
|
|
246
|
+
const requiresWrapper = supportsFormValidation && isZodObjectLike;
|
|
247
|
+
let priority = "medium";
|
|
248
|
+
let category = "core";
|
|
249
|
+
if (supportsFormValidation && requiresWrapper) {
|
|
250
|
+
priority = "critical";
|
|
251
|
+
} else if (supportsFormValidation) {
|
|
252
|
+
priority = "high";
|
|
253
|
+
} else if (tool.description?.toLowerCase().includes("query") || tool.description?.toLowerCase().includes("search")) {
|
|
254
|
+
priority = "low";
|
|
255
|
+
}
|
|
256
|
+
const toolAsAny = tool;
|
|
257
|
+
if (tool.constructor.name.includes("MCP") || toolAsAny.isMCPTool) {
|
|
258
|
+
category = "mcp";
|
|
259
|
+
} else if (toolAsAny.isExtension || tool.constructor.name.includes("Extension")) {
|
|
260
|
+
category = "extension";
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
supportsFormValidation,
|
|
264
|
+
requiresWrapper,
|
|
265
|
+
priority,
|
|
266
|
+
category
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Check if tool has render configuration
|
|
271
|
+
*/
|
|
272
|
+
hasRenderConfig(tool) {
|
|
273
|
+
const schema = tool.schema;
|
|
274
|
+
return !!(schema && schema._renderConfig);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Determine if tool should be wrapped
|
|
278
|
+
*/
|
|
279
|
+
shouldWrapTool(tool, capabilities, options) {
|
|
280
|
+
if (options.skipWrapper) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
if (options.forceWrapper) {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
return capabilities.requiresWrapper;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Check if schema is ZodObject-like
|
|
290
|
+
*/
|
|
291
|
+
isZodObjectLike(schema) {
|
|
292
|
+
if (!schema || typeof schema !== "object") {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
const schemaRecord = schema;
|
|
296
|
+
const schemaDef = schemaRecord._def;
|
|
297
|
+
return schema instanceof z.ZodObject || schemaDef?.typeName === "ZodObject" || "shape" in schemaRecord && typeof schemaRecord.shape === "object";
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Get statistics about the registry
|
|
301
|
+
*/
|
|
302
|
+
getStatistics() {
|
|
303
|
+
const stats = {
|
|
304
|
+
totalTools: this.tools.size,
|
|
305
|
+
wrappedTools: 0,
|
|
306
|
+
unwrappedTools: 0,
|
|
307
|
+
categoryCounts: { core: 0, extension: 0, mcp: 0 },
|
|
308
|
+
priorityCounts: { low: 0, medium: 0, high: 0, critical: 0 }
|
|
309
|
+
};
|
|
310
|
+
for (const entry of this.tools.values()) {
|
|
311
|
+
if (entry.wrapper) {
|
|
312
|
+
stats.wrappedTools++;
|
|
313
|
+
} else {
|
|
314
|
+
stats.unwrappedTools++;
|
|
315
|
+
}
|
|
316
|
+
stats.categoryCounts[entry.metadata.category]++;
|
|
317
|
+
stats.priorityCounts[entry.metadata.capabilities.priority]++;
|
|
318
|
+
}
|
|
319
|
+
return stats;
|
|
24
320
|
}
|
|
25
321
|
}
|
|
26
322
|
export {
|
|
27
|
-
|
|
28
|
-
DEFAULT_CONTENT_REFERENCE_CONFIG
|
|
323
|
+
ToolRegistry
|
|
29
324
|
};
|
|
30
325
|
//# sourceMappingURL=index46.js.map
|