@hashgraphonline/conversational-agent 0.1.217 → 0.1.219
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/cli/readme.md +181 -0
- package/dist/cjs/constants/entity-references.d.ts +18 -0
- package/dist/cjs/constants/form-priorities.d.ts +24 -0
- package/dist/cjs/constants/index.d.ts +4 -0
- package/dist/cjs/constants/messages.d.ts +19 -0
- package/dist/cjs/constants/test-constants.d.ts +42 -0
- package/dist/cjs/conversational-agent.d.ts +3 -8
- package/dist/{types/core/ToolRegistry.d.ts → cjs/core/tool-registry.d.ts} +11 -1
- package/dist/{types/execution/ExecutionPipeline.d.ts → cjs/execution/execution-pipeline.d.ts} +3 -3
- package/dist/cjs/forms/field-guidance-registry.d.ts +108 -0
- package/dist/cjs/forms/form-generator.d.ts +2 -7
- package/dist/cjs/forms/index.d.ts +3 -0
- package/dist/cjs/forms/types.d.ts +9 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +7 -12
- package/dist/cjs/langchain/external-tool-wrapper.d.ts +101 -0
- package/dist/{types/langchain/FormAwareAgentExecutor.d.ts → cjs/langchain/form-aware-agent-executor.d.ts} +19 -4
- package/dist/cjs/langchain/index.d.ts +3 -0
- package/dist/{types → cjs/langchain}/langchain-agent.d.ts +15 -7
- package/dist/cjs/mcp/adapters/index.d.ts +1 -0
- package/dist/cjs/mcp/adapters/langchain.d.ts +1 -1
- package/dist/{types/mcp/ContentProcessor.d.ts → cjs/mcp/content-processor.d.ts} +1 -1
- package/dist/cjs/mcp/index.d.ts +5 -0
- package/dist/{types/mcp/MCPClientManager.d.ts → cjs/mcp/mcp-client-manager.d.ts} +1 -1
- package/dist/cjs/memory/{ContentStorage.d.ts → content-storage.d.ts} +4 -4
- package/dist/cjs/memory/index.d.ts +5 -7
- package/dist/{types/memory/MemoryWindow.d.ts → cjs/memory/memory-window.d.ts} +1 -1
- package/dist/{types/memory/SmartMemoryManager.d.ts → cjs/memory/smart-memory-manager.d.ts} +1 -1
- package/dist/cjs/services/{ContentStoreManager.d.ts → content-store-manager.d.ts} +6 -6
- package/dist/cjs/services/context/resolution-context.d.ts +49 -0
- package/dist/cjs/services/entity-resolver.d.ts +58 -0
- package/dist/cjs/services/formatters/converters/index.d.ts +2 -0
- package/dist/cjs/services/formatters/converters/string-normalization-converter.d.ts +13 -0
- package/dist/cjs/services/formatters/converters/topic-id-to-hrl-converter.d.ts +17 -0
- package/dist/cjs/services/formatters/format-converter-registry.d.ts +66 -0
- package/dist/cjs/services/formatters/index.d.ts +3 -0
- package/dist/cjs/services/formatters/types.d.ts +29 -0
- package/dist/cjs/services/index.d.ts +3 -0
- package/dist/cjs/services/resolution/resolution-pipeline.d.ts +44 -0
- package/dist/cjs/tools/index.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/esm/index.js +40 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index10.js +669 -13
- package/dist/esm/index10.js.map +1 -1
- package/dist/esm/index11.js +310 -95
- package/dist/esm/index11.js.map +1 -1
- package/dist/esm/index12.js +130 -95
- package/dist/esm/index12.js.map +1 -1
- package/dist/esm/index13.js +262 -153
- package/dist/esm/index13.js.map +1 -1
- package/dist/esm/index14.js +100 -664
- package/dist/esm/index14.js.map +1 -1
- package/dist/esm/index15.js +135 -408
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index16.js +240 -122
- package/dist/esm/index16.js.map +1 -1
- package/dist/esm/index17.js +147 -135
- package/dist/esm/index17.js.map +1 -1
- package/dist/esm/index18.js +376 -533
- package/dist/esm/index18.js.map +1 -1
- package/dist/esm/index19.js +87 -214
- package/dist/esm/index19.js.map +1 -1
- package/dist/esm/index2.js +21 -4
- package/dist/esm/index2.js.map +1 -1
- package/dist/esm/index20.js +158 -92
- package/dist/esm/index20.js.map +1 -1
- package/dist/esm/index21.js +717 -44
- package/dist/esm/index21.js.map +1 -1
- package/dist/esm/index22.js +58 -96
- package/dist/esm/index22.js.map +1 -1
- package/dist/esm/index23.js +324 -34
- package/dist/esm/index23.js.map +1 -1
- package/dist/esm/index24.js +125 -712
- package/dist/esm/index24.js.map +1 -1
- package/dist/esm/index25.js +113 -133
- package/dist/esm/index25.js.map +1 -1
- package/dist/esm/index26.js +18 -152
- package/dist/esm/index26.js.map +1 -1
- package/dist/esm/index27.js +14 -210
- package/dist/esm/index27.js.map +1 -1
- package/dist/esm/index28.js +70 -173
- package/dist/esm/index28.js.map +1 -1
- package/dist/esm/index29.js +882 -220
- package/dist/esm/index29.js.map +1 -1
- package/dist/esm/index30.js +218 -126
- package/dist/esm/index30.js.map +1 -1
- package/dist/esm/index31.js +1258 -44
- package/dist/esm/index31.js.map +1 -1
- package/dist/esm/index32.js +132 -24
- package/dist/esm/index32.js.map +1 -1
- package/dist/esm/index33.js +104 -82
- package/dist/esm/index33.js.map +1 -1
- package/dist/esm/index34.js +43 -239
- package/dist/esm/index34.js.map +1 -1
- package/dist/esm/index35.js +106 -0
- package/dist/esm/index35.js.map +1 -0
- package/dist/esm/index36.js +24 -0
- package/dist/esm/index36.js.map +1 -0
- package/dist/esm/index37.js +8 -0
- package/dist/esm/index37.js.map +1 -0
- package/dist/esm/index38.js +15 -0
- package/dist/esm/index38.js.map +1 -0
- package/dist/esm/index39.js +258 -0
- package/dist/esm/index39.js.map +1 -0
- package/dist/esm/index40.js +187 -0
- package/dist/esm/index40.js.map +1 -0
- package/dist/esm/index41.js +30 -0
- package/dist/esm/index41.js.map +1 -0
- package/dist/esm/index42.js +10 -0
- package/dist/esm/index42.js.map +1 -0
- package/dist/esm/index43.js +95 -0
- package/dist/esm/index43.js.map +1 -0
- package/dist/esm/index5.js +2 -2
- package/dist/esm/index5.js.map +1 -1
- package/dist/esm/index6.js +44 -67
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index7.js +9 -0
- package/dist/esm/index7.js.map +1 -1
- package/dist/esm/index8.js +13 -1095
- package/dist/esm/index8.js.map +1 -1
- package/dist/esm/index9.js +17 -13
- package/dist/esm/index9.js.map +1 -1
- package/dist/types/constants/entity-references.d.ts +18 -0
- package/dist/types/constants/form-priorities.d.ts +24 -0
- package/dist/types/constants/index.d.ts +4 -0
- package/dist/types/constants/messages.d.ts +19 -0
- package/dist/types/constants/test-constants.d.ts +42 -0
- package/dist/types/conversational-agent.d.ts +3 -8
- package/dist/{cjs/core/ToolRegistry.d.ts → types/core/tool-registry.d.ts} +11 -1
- package/dist/{cjs/execution/ExecutionPipeline.d.ts → types/execution/execution-pipeline.d.ts} +3 -3
- package/dist/types/forms/field-guidance-registry.d.ts +108 -0
- package/dist/types/forms/form-generator.d.ts +2 -7
- package/dist/types/forms/index.d.ts +3 -0
- package/dist/types/forms/types.d.ts +9 -1
- package/dist/types/index.d.ts +7 -12
- package/dist/types/langchain/external-tool-wrapper.d.ts +101 -0
- package/dist/{cjs/langchain/FormAwareAgentExecutor.d.ts → types/langchain/form-aware-agent-executor.d.ts} +19 -4
- package/dist/types/langchain/index.d.ts +3 -0
- package/dist/{cjs → types/langchain}/langchain-agent.d.ts +15 -7
- package/dist/types/mcp/adapters/index.d.ts +1 -0
- package/dist/types/mcp/adapters/langchain.d.ts +1 -1
- package/dist/{cjs/mcp/ContentProcessor.d.ts → types/mcp/content-processor.d.ts} +1 -1
- package/dist/types/mcp/index.d.ts +5 -0
- package/dist/{cjs/mcp/MCPClientManager.d.ts → types/mcp/mcp-client-manager.d.ts} +1 -1
- package/dist/types/memory/{ContentStorage.d.ts → content-storage.d.ts} +4 -4
- package/dist/types/memory/index.d.ts +5 -7
- package/dist/{cjs/memory/MemoryWindow.d.ts → types/memory/memory-window.d.ts} +1 -1
- package/dist/{cjs/memory/SmartMemoryManager.d.ts → types/memory/smart-memory-manager.d.ts} +1 -1
- package/dist/types/services/{ContentStoreManager.d.ts → content-store-manager.d.ts} +6 -6
- package/dist/types/services/context/resolution-context.d.ts +49 -0
- package/dist/types/services/entity-resolver.d.ts +58 -0
- package/dist/types/services/formatters/converters/index.d.ts +2 -0
- package/dist/types/services/formatters/converters/string-normalization-converter.d.ts +13 -0
- package/dist/types/services/formatters/converters/topic-id-to-hrl-converter.d.ts +17 -0
- package/dist/types/services/formatters/format-converter-registry.d.ts +66 -0
- package/dist/types/services/formatters/index.d.ts +3 -0
- package/dist/types/services/formatters/types.d.ts +29 -0
- package/dist/types/services/index.d.ts +3 -0
- package/dist/types/services/resolution/resolution-pipeline.d.ts +44 -0
- package/dist/types/tools/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +30 -27
- package/src/agent-factory.ts +1 -1
- package/src/base-agent.ts +9 -0
- package/src/config/system-message.ts +2 -15
- package/src/constants/entity-references.ts +23 -0
- package/src/constants/form-priorities.ts +25 -0
- package/src/constants/index.ts +4 -0
- package/src/constants/messages.ts +20 -0
- package/src/constants/test-constants.ts +49 -0
- package/src/conversational-agent.ts +42 -69
- package/src/core/{ToolRegistry.ts → tool-registry.ts} +71 -1
- package/src/examples/external-tool-wrapper-example.ts +56 -0
- package/src/execution/{ExecutionPipeline.ts → execution-pipeline.ts} +3 -3
- package/src/forms/field-guidance-registry.ts +415 -0
- package/src/forms/field-type-registry.ts +49 -48
- package/src/forms/{FormEngine.ts → form-engine.ts} +66 -43
- package/src/forms/form-generator.ts +91 -17
- package/src/forms/index.ts +4 -1
- package/src/forms/types.ts +9 -1
- package/src/index.ts +7 -37
- package/src/langchain/external-tool-wrapper.ts +90 -0
- package/src/langchain/{FormAwareAgentExecutor.ts → form-aware-agent-executor.ts} +615 -231
- package/src/langchain/{FormValidatingToolWrapper.ts → form-validating-tool-wrapper.ts} +2 -1
- package/src/langchain/index.ts +3 -0
- package/src/{langchain-agent.ts → langchain/langchain-agent.ts} +389 -113
- package/src/mcp/adapters/index.ts +1 -0
- package/src/mcp/adapters/langchain.ts +27 -18
- package/src/mcp/{ContentProcessor.ts → content-processor.ts} +71 -47
- package/src/mcp/index.ts +5 -0
- package/src/mcp/{MCPClientManager.ts → mcp-client-manager.ts} +2 -2
- package/src/memory/{ContentStorage.ts → content-storage.ts} +263 -167
- package/src/memory/index.ts +5 -8
- package/src/memory/{MemoryWindow.ts → memory-window.ts} +47 -24
- package/src/memory/{SmartMemoryManager.ts → smart-memory-manager.ts} +49 -22
- package/src/plugins/hbar/HbarPlugin.ts +1 -1
- package/src/plugins/hcs-10/HCS10Plugin.ts +46 -28
- package/src/scripts/test-external-tool-wrapper.ts +6 -6
- package/src/scripts/test-inscribe-form-generation.ts +22 -21
- package/src/scripts/test-inscribe-wrapper-verification.ts +5 -4
- package/src/services/{ContentStoreManager.ts → content-store-manager.ts} +75 -33
- package/src/services/context/resolution-context.ts +80 -0
- package/src/services/entity-resolver.ts +425 -0
- package/src/services/formatters/converters/index.ts +2 -0
- package/src/services/formatters/converters/string-normalization-converter.ts +106 -0
- package/src/services/formatters/converters/topic-id-to-hrl-converter.ts +25 -0
- package/src/services/formatters/format-converter-registry.ts +229 -0
- package/src/services/formatters/index.ts +3 -0
- package/src/services/formatters/types.ts +31 -0
- package/src/services/index.ts +3 -0
- package/src/services/resolution/resolution-pipeline.ts +106 -0
- package/src/tools/index.ts +1 -0
- package/src/types/content-reference.ts +87 -60
- package/src/utils/index.ts +1 -0
- package/cli/dist/CLIApp.d.ts +0 -9
- package/cli/dist/CLIApp.js +0 -127
- package/cli/dist/LocalConversationalAgent.d.ts +0 -37
- package/cli/dist/LocalConversationalAgent.js +0 -58
- package/cli/dist/app.d.ts +0 -16
- package/cli/dist/app.js +0 -13
- package/cli/dist/cli.d.ts +0 -2
- package/cli/dist/cli.js +0 -51
- package/cli/dist/components/AppContainer.d.ts +0 -16
- package/cli/dist/components/AppContainer.js +0 -24
- package/cli/dist/components/AppScreens.d.ts +0 -2
- package/cli/dist/components/AppScreens.js +0 -259
- package/cli/dist/components/ChatScreen.d.ts +0 -15
- package/cli/dist/components/ChatScreen.js +0 -39
- package/cli/dist/components/DebugLoadingScreen.d.ts +0 -5
- package/cli/dist/components/DebugLoadingScreen.js +0 -31
- package/cli/dist/components/LoadingScreen.d.ts +0 -2
- package/cli/dist/components/LoadingScreen.js +0 -16
- package/cli/dist/components/LoadingScreenDebug.d.ts +0 -5
- package/cli/dist/components/LoadingScreenDebug.js +0 -27
- package/cli/dist/components/MCPConfigScreen.d.ts +0 -28
- package/cli/dist/components/MCPConfigScreen.js +0 -168
- package/cli/dist/components/ScreenRouter.d.ts +0 -12
- package/cli/dist/components/ScreenRouter.js +0 -22
- package/cli/dist/components/SetupScreen.d.ts +0 -15
- package/cli/dist/components/SetupScreen.js +0 -65
- package/cli/dist/components/SingleLoadingScreen.d.ts +0 -5
- package/cli/dist/components/SingleLoadingScreen.js +0 -27
- package/cli/dist/components/StatusBadge.d.ts +0 -7
- package/cli/dist/components/StatusBadge.js +0 -28
- package/cli/dist/components/TerminalWindow.d.ts +0 -8
- package/cli/dist/components/TerminalWindow.js +0 -24
- package/cli/dist/components/WelcomeScreen.d.ts +0 -11
- package/cli/dist/components/WelcomeScreen.js +0 -47
- package/cli/dist/context/AppContext.d.ts +0 -68
- package/cli/dist/context/AppContext.js +0 -363
- package/cli/dist/hooks/useInitializeAgent.d.ts +0 -19
- package/cli/dist/hooks/useInitializeAgent.js +0 -28
- package/cli/dist/hooks/useStableState.d.ts +0 -38
- package/cli/dist/hooks/useStableState.js +0 -68
- package/cli/dist/managers/AgentManager.d.ts +0 -57
- package/cli/dist/managers/AgentManager.js +0 -119
- package/cli/dist/managers/ConfigManager.d.ts +0 -53
- package/cli/dist/managers/ConfigManager.js +0 -173
- package/cli/dist/types.d.ts +0 -31
- package/cli/dist/types.js +0 -19
- package/dist/cjs/context/ReferenceContextManager.d.ts +0 -84
- package/dist/cjs/context/ReferenceResponseProcessor.d.ts +0 -76
- package/dist/cjs/services/EntityResolver.d.ts +0 -26
- package/dist/types/context/ReferenceContextManager.d.ts +0 -84
- package/dist/types/context/ReferenceResponseProcessor.d.ts +0 -76
- package/dist/types/services/EntityResolver.d.ts +0 -26
- package/src/context/ReferenceContextManager.ts +0 -350
- package/src/context/ReferenceResponseProcessor.ts +0 -295
- package/src/scripts/test-hedera-kit-wrapper.ts +0 -265
- package/src/services/EntityResolver.ts +0 -128
- /package/dist/cjs/forms/{FormEngine.d.ts → form-engine.d.ts} +0 -0
- /package/dist/cjs/langchain/{FormValidatingToolWrapper.d.ts → form-validating-tool-wrapper.d.ts} +0 -0
- /package/dist/cjs/memory/{ReferenceIdGenerator.d.ts → reference-id-generator.d.ts} +0 -0
- /package/dist/cjs/memory/{TokenCounter.d.ts → token-counter.d.ts} +0 -0
- /package/dist/cjs/tools/{EntityResolverTool.d.ts → entity-resolver-tool.d.ts} +0 -0
- /package/dist/cjs/utils/{ResponseFormatter.d.ts → response-formatter.d.ts} +0 -0
- /package/dist/types/forms/{FormEngine.d.ts → form-engine.d.ts} +0 -0
- /package/dist/types/langchain/{FormValidatingToolWrapper.d.ts → form-validating-tool-wrapper.d.ts} +0 -0
- /package/dist/types/memory/{ReferenceIdGenerator.d.ts → reference-id-generator.d.ts} +0 -0
- /package/dist/types/memory/{TokenCounter.d.ts → token-counter.d.ts} +0 -0
- /package/dist/types/tools/{EntityResolverTool.d.ts → entity-resolver-tool.d.ts} +0 -0
- /package/dist/types/utils/{ResponseFormatter.d.ts → response-formatter.d.ts} +0 -0
- /package/src/memory/{ReferenceIdGenerator.ts → reference-id-generator.ts} +0 -0
- /package/src/memory/{TokenCounter.ts → token-counter.ts} +0 -0
- /package/src/tools/{EntityResolverTool.ts → entity-resolver-tool.ts} +0 -0
- /package/src/utils/{ResponseFormatter.ts → response-formatter.ts} +0 -0
package/dist/esm/index7.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index7.js","sources":["../../src/base-agent.ts"],"sourcesContent":["import type { BaseMessage } from '@langchain/core/messages';\nimport type { StructuredTool } from '@langchain/core/tools';\nimport type { TransactionReceipt } from '@hashgraph/sdk';\nimport {\n HederaAgentKit,\n ServerSigner,\n TokenUsageCallbackHandler,\n TokenUsage,\n BasePlugin,\n} from 'hedera-agent-kit';\nimport type { CostCalculation } from 'hedera-agent-kit';\nimport type { AIProvider, VercelAIProvider, BAMLProvider } from './providers';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport type { MCPServerConfig, MCPConnectionStatus } from './mcp/types';\n\nexport interface ToolFilterConfig {\n namespaceWhitelist?: string[];\n toolBlacklist?: string[];\n toolPredicate?: (tool: StructuredTool) => boolean;\n}\n\nexport type ExecutionMode = 'direct' | 'bytes';\nexport type OperationalMode = 'autonomous' | 'returnBytes';\n\nexport interface HederaAgentConfiguration {\n signer: ServerSigner;\n execution?: {\n mode?: ExecutionMode;\n operationalMode?: OperationalMode;\n userAccountId?: string;\n scheduleUserTransactions?: boolean;\n scheduleUserTransactionsInBytesMode?: boolean;\n };\n ai?: {\n provider?: AIProvider;\n llm?: unknown;\n apiKey?: string;\n modelName?: string;\n temperature?: number;\n };\n filtering?: ToolFilterConfig;\n messaging?: {\n systemPreamble?: string;\n systemPostamble?: string;\n conciseMode?: boolean;\n };\n extensions?: {\n plugins?: BasePlugin[];\n mirrorConfig?: Record<string, unknown>;\n modelCapability?: string;\n };\n mcp?: {\n servers?: MCPServerConfig[];\n autoConnect?: boolean;\n };\n debug?: {\n verbose?: boolean;\n silent?: boolean;\n };\n}\n\nexport interface ConversationContext {\n messages: BaseMessage[];\n metadata?: Record<string, unknown>;\n}\n\nexport interface ChatResponse {\n output: string;\n message?: string;\n transactionBytes?: string;\n receipt?: TransactionReceipt | object;\n scheduleId?: string;\n transactionId?: string;\n notes?: string[];\n error?: string;\n intermediateSteps?: unknown;\n rawToolOutput?: unknown;\n tokenUsage?: TokenUsage;\n cost?: CostCalculation;\n metadata?: Record<string, unknown>;\n tool_calls?: Array<{\n id: string;\n name: string;\n args: Record<string, unknown>;\n output?: string;\n }>;\n formMessage?: unknown;\n requiresForm?: boolean;\n [key: string]: unknown;\n}\n\nexport interface UsageStats extends TokenUsage {\n cost: CostCalculation;\n}\n\nexport abstract class BaseAgent {\n protected logger: Logger;\n protected agentKit: HederaAgentKit | undefined;\n protected tools: StructuredTool[] = [];\n protected initialized = false;\n protected tokenTracker: TokenUsageCallbackHandler | undefined;\n\n constructor(protected config: HederaAgentConfiguration) {\n this.logger = new Logger({\n module: 'BaseAgent',\n silent: config.debug?.silent || false,\n });\n }\n\n abstract boot(): Promise<void>;\n abstract chat(\n message: string,\n context?: ConversationContext\n ): Promise<ChatResponse>;\n abstract shutdown(): Promise<void>;\n abstract switchMode(mode: OperationalMode): void;\n abstract getUsageStats(): UsageStats;\n abstract getUsageLog(): UsageStats[];\n abstract clearUsageStats(): void;\n abstract connectMCPServers(): Promise<void>;\n abstract getMCPConnectionStatus(): Map<string, MCPConnectionStatus>;\n\n public getCore(): HederaAgentKit | undefined {\n return this.agentKit;\n }\n\n protected filterTools(tools: StructuredTool[]): StructuredTool[] {\n let filtered = [...tools];\n const filter = this.config.filtering;\n\n if (!filter) return filtered;\n\n if (filter.namespaceWhitelist?.length) {\n filtered = filtered.filter((tool) => {\n const namespace = (tool as StructuredTool & { namespace?: string })\n .namespace;\n return !namespace || filter.namespaceWhitelist!.includes(namespace);\n });\n }\n\n if (filter.toolBlacklist?.length) {\n filtered = filtered.filter(\n (tool) => !filter.toolBlacklist!.includes(tool.name)\n );\n }\n\n if (filter.toolPredicate) {\n filtered = filtered.filter(filter.toolPredicate);\n }\n\n this.logger.debug(`Filtered tools: ${tools.length} → ${filtered.length}`);\n return filtered;\n }\n\n protected buildSystemPrompt(): string {\n const parts: string[] = [];\n const operatorId = this.config.signer.getAccountId().toString();\n const userAccId = this.config.execution?.userAccountId;\n\n if (this.config.messaging?.systemPreamble) {\n parts.push(this.config.messaging.systemPreamble);\n }\n\n parts.push(\n `You are a helpful Hedera assistant. Your primary operator account is ${operatorId}. ` +\n `You have tools to interact with the Hedera Hashgraph. ` +\n `When using any tool, provide all necessary parameters as defined by that tool's schema and description.`\n );\n\n if (userAccId) {\n parts.push(\n `The user you are assisting has a personal Hedera account ID: ${userAccId}. ` +\n `IMPORTANT: When the user says things like \"I want to send HBAR\" or \"transfer my tokens\", you MUST use ${userAccId} as the sender/from account. ` +\n `For example, if user says \"I want to send 2 HBAR to 0.0.800\", you must set up a transfer where ${userAccId} sends the HBAR, not your operator account.`\n );\n }\n\n const operationalMode =\n this.config.execution?.operationalMode || 'returnBytes';\n if (operationalMode === 'autonomous') {\n parts.push(\n `\\nOPERATIONAL MODE: 'autonomous'. Your goal is to execute transactions directly using your tools. ` +\n `Your account ${operatorId} will be the payer for these transactions. ` +\n `Even if the user's account (${\n userAccId || 'a specified account'\n }) is the actor in the transaction body (e.g., sender of HBAR), ` +\n `you (the agent with operator ${operatorId}) are still executing and paying. For HBAR transfers, ensure the amounts in the 'transfers' array sum to zero (as per tool schema), balancing with your operator account if necessary.`\n );\n } else {\n if (\n this.config.execution?.scheduleUserTransactionsInBytesMode &&\n userAccId\n ) {\n parts.push(\n `\\nOPERATIONAL MODE: 'returnBytes' with scheduled transactions for user actions. ` +\n `When a user asks for a transaction to be prepared (e.g., creating a token, topic, transferring assets for them to sign, etc), ` +\n `you MUST default to creating a Scheduled Transaction using the appropriate tool with the metaOption 'schedule: true'. ` +\n `The user (with account ID ${userAccId}) will be the one to ultimately pay for and (if needed) sign the inner transaction. ` +\n `Your operator account (${operatorId}) will pay for creating the schedule entity itself. ` +\n `You MUST return the ScheduleId and details of the scheduled operation in a structured JSON format with these fields: success, op, schedule_id, description, payer_account_id_scheduled_tx, and scheduled_transaction_details.`\n );\n } else {\n parts.push(\n `\\nOPERATIONAL MODE: 'returnBytes'. Your goal is to provide transaction bytes when possible. ` +\n `When a user asks for a transaction to be prepared (e.g., for them to sign, or for scheduling without the default scheduling flow), ` +\n `you MUST call the appropriate tool. ` +\n `IMPORTANT: Only use metaOption 'returnBytes: true' for tools that explicitly support it (like HBAR transfers, token operations). ` +\n `Many tools (inscriptions, HCS-2, HCS-20, etc.) do NOT support returnBytes and will execute directly - this is expected behavior. ` +\n `For tools without returnBytes support, simply call them with their standard parameters. ` +\n `If you need raw bytes for the user to sign for their own account ${\n userAccId || 'if specified'\n }, ensure the tool constructs the transaction body accordingly when returnBytes IS supported.`\n );\n }\n }\n\n if (this.config.messaging?.conciseMode !== false) {\n parts.push(\n '\\nAlways be concise. If the tool provides a JSON string as its primary output (especially in returnBytes mode), make your accompanying text brief. If the tool does not provide JSON output or an error occurs, your narrative becomes primary; if notes were generated by the tool in such cases, append them to your textual response.'\n );\n }\n\n if (this.config.messaging?.systemPostamble) {\n parts.push(this.config.messaging.systemPostamble);\n }\n\n return parts.join('\\n');\n }\n\n isReady(): boolean {\n return this.initialized;\n }\n}\n\nexport type { AIProvider, VercelAIProvider, BAMLProvider };\n"],"names":[],"mappings":";AA+FO,MAAe,UAAU;AAAA,EAO9B,YAAsB,QAAkC;AAAlC,SAAA,SAAA;AAJtB,SAAU,QAA0B,CAAA;AACpC,SAAU,cAAc;AAItB,SAAK,SAAS,IAAI,OAAO;AAAA,MACvB,QAAQ;AAAA,MACR,QAAQ,OAAO,OAAO,UAAU;AAAA,IAAA,CACjC;AAAA,EACH;AAAA,EAeO,UAAsC;AAC3C,WAAO,KAAK;AAAA,EACd;AAAA,EAEU,YAAY,OAA2C;AAC/D,QAAI,WAAW,CAAC,GAAG,KAAK;AACxB,UAAM,SAAS,KAAK,OAAO;AAE3B,QAAI,CAAC,OAAQ,QAAO;AAEpB,QAAI,OAAO,oBAAoB,QAAQ;AACrC,iBAAW,SAAS,OAAO,CAAC,SAAS;AACnC,cAAM,YAAa,KAChB;AACH,eAAO,CAAC,aAAa,OAAO,mBAAoB,SAAS,SAAS;AAAA,MACpE,CAAC;AAAA,IACH;AAEA,QAAI,OAAO,eAAe,QAAQ;AAChC,iBAAW,SAAS;AAAA,QAClB,CAAC,SAAS,CAAC,OAAO,cAAe,SAAS,KAAK,IAAI;AAAA,MAAA;AAAA,IAEvD;AAEA,QAAI,OAAO,eAAe;AACxB,iBAAW,SAAS,O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ts"],"sourcesContent":["import type { BaseMessage } from '@langchain/core/messages';\nimport type { StructuredTool } from '@langchain/core/tools';\nimport type { TransactionReceipt } from '@hashgraph/sdk';\nimport {\n HederaAgentKit,\n ServerSigner,\n TokenUsageCallbackHandler,\n TokenUsage,\n BasePlugin,\n} from 'hedera-agent-kit';\nimport type { CostCalculation } from 'hedera-agent-kit';\nimport type { AIProvider, VercelAIProvider, BAMLProvider } from './providers';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport type { MCPServerConfig, MCPConnectionStatus } from './mcp/types';\n\nexport interface ToolFilterConfig {\n namespaceWhitelist?: string[];\n toolBlacklist?: string[];\n toolPredicate?: (tool: StructuredTool) => boolean;\n}\n\nexport type ExecutionMode = 'direct' | 'bytes';\nexport type OperationalMode = 'autonomous' | 'returnBytes';\n\nexport interface HederaAgentConfiguration {\n signer: ServerSigner;\n execution?: {\n mode?: ExecutionMode;\n operationalMode?: OperationalMode;\n userAccountId?: string;\n scheduleUserTransactions?: boolean;\n scheduleUserTransactionsInBytesMode?: boolean;\n };\n ai?: {\n provider?: AIProvider;\n llm?: unknown;\n apiKey?: string;\n modelName?: string;\n temperature?: number;\n };\n filtering?: ToolFilterConfig;\n messaging?: {\n systemPreamble?: string;\n systemPostamble?: string;\n conciseMode?: boolean;\n };\n extensions?: {\n plugins?: BasePlugin[];\n mirrorConfig?: Record<string, unknown>;\n modelCapability?: string;\n };\n mcp?: {\n servers?: MCPServerConfig[];\n autoConnect?: boolean;\n };\n debug?: {\n verbose?: boolean;\n silent?: boolean;\n };\n}\n\nexport interface ConversationContext {\n messages: BaseMessage[];\n metadata?: Record<string, unknown>;\n}\n\nexport interface ChatResponse {\n output: string;\n message?: string;\n transactionBytes?: string;\n receipt?: TransactionReceipt | object;\n scheduleId?: string;\n transactionId?: string;\n notes?: string[];\n error?: string;\n intermediateSteps?: unknown;\n rawToolOutput?: unknown;\n tokenUsage?: TokenUsage;\n cost?: CostCalculation;\n metadata?: Record<string, unknown>;\n tool_calls?: Array<{\n id: string;\n name: string;\n args: Record<string, unknown>;\n output?: string;\n }>;\n formMessage?: unknown;\n requiresForm?: boolean;\n [key: string]: unknown;\n}\n\nexport interface UsageStats extends TokenUsage {\n cost: CostCalculation;\n}\n\nexport abstract class BaseAgent {\n protected logger: Logger;\n protected agentKit: HederaAgentKit | undefined;\n protected tools: StructuredTool[] = [];\n protected initialized = false;\n protected tokenTracker: TokenUsageCallbackHandler | undefined;\n\n constructor(protected config: HederaAgentConfiguration) {\n this.logger = new Logger({\n module: 'BaseAgent',\n silent: config.debug?.silent || false,\n });\n }\n\n abstract boot(): Promise<void>;\n abstract chat(\n message: string,\n context?: ConversationContext\n ): Promise<ChatResponse>;\n abstract shutdown(): Promise<void>;\n abstract switchMode(mode: OperationalMode): void;\n abstract getUsageStats(): UsageStats;\n abstract getUsageLog(): UsageStats[];\n abstract clearUsageStats(): void;\n abstract connectMCPServers(): Promise<void>;\n abstract getMCPConnectionStatus(): Map<string, MCPConnectionStatus>;\n\n public getCore(): HederaAgentKit | undefined {\n return this.agentKit;\n }\n\n protected filterTools(tools: StructuredTool[]): StructuredTool[] {\n let filtered = [...tools];\n const filter = this.config.filtering;\n\n if (!filter) return filtered;\n\n if (filter.namespaceWhitelist?.length) {\n filtered = filtered.filter((tool) => {\n const namespace = (tool as StructuredTool & { namespace?: string })\n .namespace;\n return !namespace || filter.namespaceWhitelist!.includes(namespace);\n });\n }\n\n if (filter.toolBlacklist?.length) {\n filtered = filtered.filter(\n (tool) => !filter.toolBlacklist!.includes(tool.name)\n );\n }\n\n if (filter.toolPredicate) {\n filtered = filtered.filter(filter.toolPredicate);\n }\n\n this.logger.debug(`Filtered tools: ${tools.length} → ${filtered.length}`);\n return filtered;\n }\n\n protected buildSystemPrompt(): string {\n const parts: string[] = [];\n const operatorId = this.config.signer.getAccountId().toString();\n const userAccId = this.config.execution?.userAccountId;\n\n if (this.config.messaging?.systemPreamble) {\n parts.push(this.config.messaging.systemPreamble);\n }\n\n parts.push(\n `You are a helpful Hedera assistant. Your primary operator account is ${operatorId}. ` +\n `You have tools to interact with the Hedera Hashgraph. ` +\n `When using any tool, provide all necessary parameters as defined by that tool's schema and description.`\n );\n\n parts.push(\n `\\nMETADATA QUALITY PRINCIPLES: When collecting user input for metadata creation across any tool:` +\n `\\n• Prioritize meaningful, valuable content over technical file information` +\n `\\n• Focus on attributes that add value for end users and collectors` +\n `\\n• Avoid auto-generating meaningless technical attributes as user-facing metadata` +\n `\\n• When fields are missing or inadequate, use forms to collect quality metadata` +\n `\\n• Encourage descriptive names, collectible traits, and storytelling elements`\n );\n\n if (userAccId) {\n parts.push(\n `The user you are assisting has a personal Hedera account ID: ${userAccId}. ` +\n `IMPORTANT: When the user says things like \"I want to send HBAR\" or \"transfer my tokens\", you MUST use ${userAccId} as the sender/from account. ` +\n `For example, if user says \"I want to send 2 HBAR to 0.0.800\", you must set up a transfer where ${userAccId} sends the HBAR, not your operator account.`\n );\n }\n\n const operationalMode =\n this.config.execution?.operationalMode || 'returnBytes';\n if (operationalMode === 'autonomous') {\n parts.push(\n `\\nOPERATIONAL MODE: 'autonomous'. Your goal is to execute transactions directly using your tools. ` +\n `Your account ${operatorId} will be the payer for these transactions. ` +\n `Even if the user's account (${\n userAccId || 'a specified account'\n }) is the actor in the transaction body (e.g., sender of HBAR), ` +\n `you (the agent with operator ${operatorId}) are still executing and paying. For HBAR transfers, ensure the amounts in the 'transfers' array sum to zero (as per tool schema), balancing with your operator account if necessary.`\n );\n } else {\n if (\n this.config.execution?.scheduleUserTransactionsInBytesMode &&\n userAccId\n ) {\n parts.push(\n `\\nOPERATIONAL MODE: 'returnBytes' with scheduled transactions for user actions. ` +\n `When a user asks for a transaction to be prepared (e.g., creating a token, topic, transferring assets for them to sign, etc), ` +\n `you MUST default to creating a Scheduled Transaction using the appropriate tool with the metaOption 'schedule: true'. ` +\n `The user (with account ID ${userAccId}) will be the one to ultimately pay for and (if needed) sign the inner transaction. ` +\n `Your operator account (${operatorId}) will pay for creating the schedule entity itself. ` +\n `You MUST return the ScheduleId and details of the scheduled operation in a structured JSON format with these fields: success, op, schedule_id, description, payer_account_id_scheduled_tx, and scheduled_transaction_details.`\n );\n } else {\n parts.push(\n `\\nOPERATIONAL MODE: 'returnBytes'. Your goal is to provide transaction bytes when possible. ` +\n `When a user asks for a transaction to be prepared (e.g., for them to sign, or for scheduling without the default scheduling flow), ` +\n `you MUST call the appropriate tool. ` +\n `IMPORTANT: Only use metaOption 'returnBytes: true' for tools that explicitly support it (like HBAR transfers, token operations). ` +\n `Many tools (inscriptions, HCS-2, HCS-20, etc.) do NOT support returnBytes and will execute directly - this is expected behavior. ` +\n `For tools without returnBytes support, simply call them with their standard parameters. ` +\n `If you need raw bytes for the user to sign for their own account ${\n userAccId || 'if specified'\n }, ensure the tool constructs the transaction body accordingly when returnBytes IS supported.`\n );\n }\n }\n\n if (this.config.messaging?.conciseMode !== false) {\n parts.push(\n '\\nAlways be concise. If the tool provides a JSON string as its primary output (especially in returnBytes mode), make your accompanying text brief. If the tool does not provide JSON output or an error occurs, your narrative becomes primary; if notes were generated by the tool in such cases, append them to your textual response.'\n );\n }\n\n if (this.config.messaging?.systemPostamble) {\n parts.push(this.config.messaging.systemPostamble);\n }\n\n return parts.join('\\n');\n }\n\n isReady(): boolean {\n return this.initialized;\n }\n}\n\nexport type { AIProvider, VercelAIProvider, BAMLProvider };\n"],"names":[],"mappings":";AA+FO,MAAe,UAAU;AAAA,EAO9B,YAAsB,QAAkC;AAAlC,SAAA,SAAA;AAJtB,SAAU,QAA0B,CAAA;AACpC,SAAU,cAAc;AAItB,SAAK,SAAS,IAAI,OAAO;AAAA,MACvB,QAAQ;AAAA,MACR,QAAQ,OAAO,OAAO,UAAU;AAAA,IAAA,CACjC;AAAA,EACH;AAAA,EAeO,UAAsC;AAC3C,WAAO,KAAK;AAAA,EACd;AAAA,EAEU,YAAY,OAA2C;AAC/D,QAAI,WAAW,CAAC,GAAG,KAAK;AACxB,UAAM,SAAS,KAAK,OAA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