@hashgraphonline/standards-agent-kit 0.0.37 → 0.2.0
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/builders/hcs10/hcs10-builder.d.ts +262 -0
- package/dist/cjs/builders/index.d.ts +2 -0
- package/dist/cjs/builders/types.d.ts +10 -0
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/init/init.d.ts +21 -22
- package/dist/cjs/plugins/PluginInterface.d.ts +4 -80
- package/dist/cjs/plugins/PluginRegistry.d.ts +1 -47
- package/dist/cjs/plugins/defi/index.d.ts +7 -4
- package/dist/cjs/plugins/hedera/HbarPricePlugin.d.ts +7 -35
- package/dist/cjs/plugins/index.d.ts +0 -5
- package/dist/cjs/plugins/weather/index.d.ts +6 -5
- package/dist/cjs/standards-agent-kit.cjs +1 -1
- package/dist/cjs/standards-agent-kit.cjs.map +1 -1
- package/dist/cjs/state/state-types.d.ts +8 -8
- package/dist/cjs/tools/hcs10/AcceptConnectionRequestTool.d.ts +40 -0
- package/dist/cjs/tools/hcs10/CheckMessagesTool.d.ts +40 -0
- package/dist/cjs/tools/hcs10/ConnectionMonitorTool.d.ts +134 -0
- package/dist/cjs/tools/hcs10/FindRegistrationsTool.d.ts +34 -0
- package/dist/cjs/tools/hcs10/InitiateConnectionTool.d.ts +43 -0
- package/dist/cjs/tools/hcs10/ListConnectionsTool.d.ts +34 -0
- package/dist/cjs/tools/hcs10/ListUnapprovedConnectionRequestsTool.d.ts +15 -0
- package/dist/cjs/tools/hcs10/ManageConnectionRequestsTool.d.ts +34 -0
- package/dist/cjs/tools/hcs10/RegisterAgentTool.d.ts +218 -0
- package/dist/cjs/tools/hcs10/RetrieveProfileTool.d.ts +33 -0
- package/dist/cjs/tools/hcs10/SendMessageToConnectionTool.d.ts +40 -0
- package/dist/cjs/tools/hcs10/base-hcs10-tools.d.ts +28 -0
- package/dist/cjs/tools/hcs10/hcs10-tool-params.d.ts +18 -0
- package/dist/cjs/tools/hcs10/index.d.ts +13 -0
- package/dist/cjs/tools/index.d.ts +1 -13
- package/dist/es/builders/hcs10/hcs10-builder.d.ts +262 -0
- package/dist/es/builders/index.d.ts +2 -0
- package/dist/es/builders/types.d.ts +10 -0
- package/dist/es/index.d.ts +3 -1
- package/dist/es/init/init.d.ts +21 -22
- package/dist/es/plugins/PluginInterface.d.ts +4 -80
- package/dist/es/plugins/PluginRegistry.d.ts +1 -47
- package/dist/es/plugins/defi/index.d.ts +7 -4
- package/dist/es/plugins/hedera/HbarPricePlugin.d.ts +7 -35
- package/dist/es/plugins/index.d.ts +0 -5
- package/dist/es/plugins/weather/index.d.ts +6 -5
- package/dist/es/standards-agent-kit.es.js +10 -18
- package/dist/es/standards-agent-kit.es.js.map +1 -1
- package/dist/es/standards-agent-kit.es10.js +29 -76
- package/dist/es/standards-agent-kit.es10.js.map +1 -1
- package/dist/es/standards-agent-kit.es11.js +61 -384
- package/dist/es/standards-agent-kit.es11.js.map +1 -1
- package/dist/es/standards-agent-kit.es12.js +22 -190
- package/dist/es/standards-agent-kit.es12.js.map +1 -1
- package/dist/es/standards-agent-kit.es13.js +26 -138
- package/dist/es/standards-agent-kit.es13.js.map +1 -1
- package/dist/es/standards-agent-kit.es14.js +35 -59
- package/dist/es/standards-agent-kit.es14.js.map +1 -1
- package/dist/es/standards-agent-kit.es15.js +11 -117
- package/dist/es/standards-agent-kit.es15.js.map +1 -1
- package/dist/es/standards-agent-kit.es16.js +1 -1
- package/dist/es/standards-agent-kit.es16.js.map +1 -1
- package/dist/es/standards-agent-kit.es17.js +63 -46
- package/dist/es/standards-agent-kit.es17.js.map +1 -1
- package/dist/es/standards-agent-kit.es18.js +25 -74
- package/dist/es/standards-agent-kit.es18.js.map +1 -1
- package/dist/es/standards-agent-kit.es19.js +22 -13
- package/dist/es/standards-agent-kit.es19.js.map +1 -1
- package/dist/es/standards-agent-kit.es2.js +1381 -188
- package/dist/es/standards-agent-kit.es2.js.map +1 -1
- package/dist/es/standards-agent-kit.es20.js +3 -67
- package/dist/es/standards-agent-kit.es20.js.map +1 -1
- package/dist/es/standards-agent-kit.es3.js +285 -347
- package/dist/es/standards-agent-kit.es3.js.map +1 -1
- package/dist/es/standards-agent-kit.es4.js +22 -74
- package/dist/es/standards-agent-kit.es4.js.map +1 -1
- package/dist/es/standards-agent-kit.es5.js +127 -154
- package/dist/es/standards-agent-kit.es5.js.map +1 -1
- package/dist/es/standards-agent-kit.es6.js +21 -88
- package/dist/es/standards-agent-kit.es6.js.map +1 -1
- package/dist/es/standards-agent-kit.es7.js +28 -86
- package/dist/es/standards-agent-kit.es7.js.map +1 -1
- package/dist/es/standards-agent-kit.es8.js +27 -100
- package/dist/es/standards-agent-kit.es8.js.map +1 -1
- package/dist/es/standards-agent-kit.es9.js +35 -117
- package/dist/es/standards-agent-kit.es9.js.map +1 -1
- package/dist/es/state/state-types.d.ts +8 -8
- package/dist/es/tools/hcs10/AcceptConnectionRequestTool.d.ts +40 -0
- package/dist/es/tools/hcs10/CheckMessagesTool.d.ts +40 -0
- package/dist/es/tools/hcs10/ConnectionMonitorTool.d.ts +134 -0
- package/dist/es/tools/hcs10/FindRegistrationsTool.d.ts +34 -0
- package/dist/es/tools/hcs10/InitiateConnectionTool.d.ts +43 -0
- package/dist/es/tools/hcs10/ListConnectionsTool.d.ts +34 -0
- package/dist/es/tools/hcs10/ListUnapprovedConnectionRequestsTool.d.ts +15 -0
- package/dist/es/tools/hcs10/ManageConnectionRequestsTool.d.ts +34 -0
- package/dist/es/tools/hcs10/RegisterAgentTool.d.ts +218 -0
- package/dist/es/tools/hcs10/RetrieveProfileTool.d.ts +33 -0
- package/dist/es/tools/hcs10/SendMessageToConnectionTool.d.ts +40 -0
- package/dist/es/tools/hcs10/base-hcs10-tools.d.ts +28 -0
- package/dist/es/tools/hcs10/hcs10-tool-params.d.ts +18 -0
- package/dist/es/tools/hcs10/index.d.ts +13 -0
- package/dist/es/tools/index.d.ts +1 -13
- package/dist/umd/builders/hcs10/hcs10-builder.d.ts +262 -0
- package/dist/umd/builders/index.d.ts +2 -0
- package/dist/umd/builders/types.d.ts +10 -0
- package/dist/umd/index.d.ts +3 -1
- package/dist/umd/init/init.d.ts +21 -22
- package/dist/umd/plugins/PluginInterface.d.ts +4 -80
- package/dist/umd/plugins/PluginRegistry.d.ts +1 -47
- package/dist/umd/plugins/defi/index.d.ts +7 -4
- package/dist/umd/plugins/hedera/HbarPricePlugin.d.ts +7 -35
- package/dist/umd/plugins/index.d.ts +0 -5
- package/dist/umd/plugins/weather/index.d.ts +6 -5
- package/dist/umd/standards-agent-kit.umd.js +1 -164
- package/dist/umd/standards-agent-kit.umd.js.map +1 -1
- package/dist/umd/state/state-types.d.ts +8 -8
- package/dist/umd/tools/hcs10/AcceptConnectionRequestTool.d.ts +40 -0
- package/dist/umd/tools/hcs10/CheckMessagesTool.d.ts +40 -0
- package/dist/umd/tools/hcs10/ConnectionMonitorTool.d.ts +134 -0
- package/dist/umd/tools/hcs10/FindRegistrationsTool.d.ts +34 -0
- package/dist/umd/tools/hcs10/InitiateConnectionTool.d.ts +43 -0
- package/dist/umd/tools/hcs10/ListConnectionsTool.d.ts +34 -0
- package/dist/umd/tools/hcs10/ListUnapprovedConnectionRequestsTool.d.ts +15 -0
- package/dist/umd/tools/hcs10/ManageConnectionRequestsTool.d.ts +34 -0
- package/dist/umd/tools/hcs10/RegisterAgentTool.d.ts +218 -0
- package/dist/umd/tools/hcs10/RetrieveProfileTool.d.ts +33 -0
- package/dist/umd/tools/hcs10/SendMessageToConnectionTool.d.ts +40 -0
- package/dist/umd/tools/hcs10/base-hcs10-tools.d.ts +28 -0
- package/dist/umd/tools/hcs10/hcs10-tool-params.d.ts +18 -0
- package/dist/umd/tools/hcs10/index.d.ts +13 -0
- package/dist/umd/tools/index.d.ts +1 -13
- package/package.json +41 -41
- package/src/builders/hcs10/hcs10-builder.ts +2108 -0
- package/src/builders/index.ts +2 -0
- package/src/builders/types.ts +11 -0
- package/src/hcs10/HCS10Client.ts +3 -2
- package/src/index.ts +4 -2
- package/src/init/init.ts +85 -63
- package/src/plugins/PluginInterface.ts +15 -94
- package/src/plugins/PluginRegistry.ts +2 -98
- package/src/plugins/defi/index.ts +31 -118
- package/src/plugins/hedera/HbarPricePlugin.ts +19 -100
- package/src/plugins/index.ts +0 -5
- package/src/plugins/weather/index.ts +56 -40
- package/src/state/state-types.ts +9 -11
- package/src/tools/hcs10/AcceptConnectionRequestTool.ts +56 -0
- package/src/tools/hcs10/CheckMessagesTool.ts +73 -0
- package/src/tools/hcs10/ConnectionMonitorTool.ts +111 -0
- package/src/tools/hcs10/FindRegistrationsTool.ts +64 -0
- package/src/tools/hcs10/InitiateConnectionTool.ts +66 -0
- package/src/tools/hcs10/ListConnectionsTool.ts +58 -0
- package/src/tools/hcs10/ListUnapprovedConnectionRequestsTool.ts +26 -0
- package/src/tools/hcs10/ManageConnectionRequestsTool.ts +48 -0
- package/src/tools/hcs10/RegisterAgentTool.ts +213 -0
- package/src/tools/hcs10/RetrieveProfileTool.ts +61 -0
- package/src/tools/hcs10/SendMessageToConnectionTool.ts +45 -0
- package/src/tools/hcs10/base-hcs10-tools.ts +65 -0
- package/src/tools/hcs10/hcs10-tool-params.ts +21 -0
- package/src/tools/hcs10/index.ts +13 -0
- package/src/tools/index.ts +2 -13
- package/src/utils/HederaClient.ts +2 -2
- package/src/utils/ensure-agent-has-hbar.ts +3 -4
- package/dist/cjs/agents/index.d.ts +0 -0
- package/dist/cjs/plugins/BasePlugin.d.ts +0 -28
- package/dist/cjs/plugins/GenericPlugin.d.ts +0 -17
- package/dist/cjs/plugins/HCS10Plugin.d.ts +0 -13
- package/dist/cjs/plugins/PluginLoader.d.ts +0 -38
- package/dist/cjs/plugins/openconvai/OpenConvAIPlugin.d.ts +0 -23
- package/dist/cjs/plugins/openconvai/index.d.ts +0 -1
- package/dist/cjs/tools/AcceptConnectionRequestTool.d.ts +0 -33
- package/dist/cjs/tools/CheckMessagesTool.d.ts +0 -34
- package/dist/cjs/tools/ConnectionMonitorTool.d.ts +0 -100
- package/dist/cjs/tools/ConnectionTool.d.ts +0 -40
- package/dist/cjs/tools/FindRegistrationsTool.d.ts +0 -28
- package/dist/cjs/tools/InitiateConnectionTool.d.ts +0 -30
- package/dist/cjs/tools/ListConnectionsTool.d.ts +0 -33
- package/dist/cjs/tools/ListUnapprovedConnectionRequestsTool.d.ts +0 -41
- package/dist/cjs/tools/ManageConnectionRequestsTool.d.ts +0 -38
- package/dist/cjs/tools/RegisterAgentTool.d.ts +0 -188
- package/dist/cjs/tools/RetrieveProfileTool.d.ts +0 -34
- package/dist/cjs/tools/SendMessageToConnectionTool.d.ts +0 -34
- package/dist/cjs/tools/SendMessageTool.d.ts +0 -40
- package/dist/es/agents/index.d.ts +0 -0
- package/dist/es/plugins/BasePlugin.d.ts +0 -28
- package/dist/es/plugins/GenericPlugin.d.ts +0 -17
- package/dist/es/plugins/HCS10Plugin.d.ts +0 -13
- package/dist/es/plugins/PluginLoader.d.ts +0 -38
- package/dist/es/plugins/openconvai/OpenConvAIPlugin.d.ts +0 -23
- package/dist/es/plugins/openconvai/index.d.ts +0 -1
- package/dist/es/standards-agent-kit.es21.js +0 -92
- package/dist/es/standards-agent-kit.es21.js.map +0 -1
- package/dist/es/standards-agent-kit.es22.js +0 -7
- package/dist/es/standards-agent-kit.es22.js.map +0 -1
- package/dist/es/standards-agent-kit.es23.js +0 -106
- package/dist/es/standards-agent-kit.es23.js.map +0 -1
- package/dist/es/standards-agent-kit.es24.js +0 -7
- package/dist/es/standards-agent-kit.es24.js.map +0 -1
- package/dist/es/standards-agent-kit.es25.js +0 -7
- package/dist/es/standards-agent-kit.es25.js.map +0 -1
- package/dist/es/standards-agent-kit.es26.js +0 -85
- package/dist/es/standards-agent-kit.es26.js.map +0 -1
- package/dist/es/standards-agent-kit.es27.js +0 -28
- package/dist/es/standards-agent-kit.es27.js.map +0 -1
- package/dist/es/tools/AcceptConnectionRequestTool.d.ts +0 -33
- package/dist/es/tools/CheckMessagesTool.d.ts +0 -34
- package/dist/es/tools/ConnectionMonitorTool.d.ts +0 -100
- package/dist/es/tools/ConnectionTool.d.ts +0 -40
- package/dist/es/tools/FindRegistrationsTool.d.ts +0 -28
- package/dist/es/tools/InitiateConnectionTool.d.ts +0 -30
- package/dist/es/tools/ListConnectionsTool.d.ts +0 -33
- package/dist/es/tools/ListUnapprovedConnectionRequestsTool.d.ts +0 -41
- package/dist/es/tools/ManageConnectionRequestsTool.d.ts +0 -38
- package/dist/es/tools/RegisterAgentTool.d.ts +0 -188
- package/dist/es/tools/RetrieveProfileTool.d.ts +0 -34
- package/dist/es/tools/SendMessageToConnectionTool.d.ts +0 -34
- package/dist/es/tools/SendMessageTool.d.ts +0 -40
- package/dist/umd/agents/index.d.ts +0 -0
- package/dist/umd/plugins/BasePlugin.d.ts +0 -28
- package/dist/umd/plugins/GenericPlugin.d.ts +0 -17
- package/dist/umd/plugins/HCS10Plugin.d.ts +0 -13
- package/dist/umd/plugins/PluginLoader.d.ts +0 -38
- package/dist/umd/plugins/openconvai/OpenConvAIPlugin.d.ts +0 -23
- package/dist/umd/plugins/openconvai/index.d.ts +0 -1
- package/dist/umd/tools/AcceptConnectionRequestTool.d.ts +0 -33
- package/dist/umd/tools/CheckMessagesTool.d.ts +0 -34
- package/dist/umd/tools/ConnectionMonitorTool.d.ts +0 -100
- package/dist/umd/tools/ConnectionTool.d.ts +0 -40
- package/dist/umd/tools/FindRegistrationsTool.d.ts +0 -28
- package/dist/umd/tools/InitiateConnectionTool.d.ts +0 -30
- package/dist/umd/tools/ListConnectionsTool.d.ts +0 -33
- package/dist/umd/tools/ListUnapprovedConnectionRequestsTool.d.ts +0 -41
- package/dist/umd/tools/ManageConnectionRequestsTool.d.ts +0 -38
- package/dist/umd/tools/RegisterAgentTool.d.ts +0 -188
- package/dist/umd/tools/RetrieveProfileTool.d.ts +0 -34
- package/dist/umd/tools/SendMessageToConnectionTool.d.ts +0 -34
- package/dist/umd/tools/SendMessageTool.d.ts +0 -40
- package/src/agents/index.ts +0 -1
- package/src/plugins/BasePlugin.ts +0 -37
- package/src/plugins/GenericPlugin.ts +0 -19
- package/src/plugins/HCS10Plugin.ts +0 -14
- package/src/plugins/PluginLoader.ts +0 -121
- package/src/plugins/README.md +0 -113
- package/src/plugins/openconvai/OpenConvAIPlugin.ts +0 -124
- package/src/plugins/openconvai/index.ts +0 -1
- package/src/tools/AcceptConnectionRequestTool.ts +0 -196
- package/src/tools/CheckMessagesTool.ts +0 -194
- package/src/tools/ConnectionMonitorTool.ts +0 -550
- package/src/tools/ConnectionTool.ts +0 -231
- package/src/tools/FindRegistrationsTool.ts +0 -114
- package/src/tools/InitiateConnectionTool.ts +0 -137
- package/src/tools/ListConnectionsTool.ts +0 -158
- package/src/tools/ListUnapprovedConnectionRequestsTool.ts +0 -173
- package/src/tools/ManageConnectionRequestsTool.ts +0 -275
- package/src/tools/RegisterAgentTool.ts +0 -590
- package/src/tools/RetrieveProfileTool.ts +0 -94
- package/src/tools/SendMessageToConnectionTool.ts +0 -142
- package/src/tools/SendMessageTool.ts +0 -116
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es3.js","sources":["../../src/tools/RegisterAgentTool.ts"],"sourcesContent":["import {\n AIAgentCapability,\n Logger,\n FeeConfigBuilder,\n} from '@hashgraphonline/standards-sdk';\nimport { ensureAgentHasEnoughHbar } from '../utils/ensure-agent-has-hbar';\nimport { HCS10Client, ExtendedAgentMetadata } from '../hcs10/HCS10Client';\nimport { StructuredTool } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { IStateManager } from '../state/state-types';\nimport { AgentPersistenceOptions } from '../state/state-types';\nimport fs from 'fs';\nimport path from 'path';\nimport axios from 'axios';\n\n/**\n * Interface for HCS10 registration result\n */\ninterface HCS10RegistrationResult {\n metadata?: {\n accountId?: string;\n inboundTopicId?: string;\n outboundTopicId?: string;\n profileTopicId?: string;\n privateKey?: string;\n capabilities?: number[];\n [key: string]: string | number | boolean | number[] | object | undefined;\n };\n}\n\n/**\n * Agent registration details returned when successful\n */\ninterface AgentRegistrationDetails {\n success: boolean;\n message: string;\n name: string;\n accountId: string;\n privateKey: string;\n inboundTopicId: string;\n outboundTopicId: string;\n profileTopicId: string;\n capabilities: number[];\n hasFees: boolean;\n hbarFee: number;\n tokenFee: { amount: number; tokenId: string } | null;\n profilePicture?: {\n source: string;\n topicId?: string;\n };\n}\n\n/**\n * Profile picture input types supported by the tool\n */\ntype ProfilePictureInput =\n | string\n | {\n url: string;\n filename: string;\n }\n | {\n path: string;\n filename?: string;\n };\n\n/**\n * RegisterAgentTool wraps the createAndRegisterAgent() function of HCS10Client.\n * It creates and registers an agent on Hedera using the HCS-10 standard SDK flow.\n * On success, returns a JSON string containing the new agent's details (including private key).\n */\nexport class RegisterAgentTool extends StructuredTool {\n name = 'register_agent';\n description =\n \"Creates and registers the AI agent on the Hedera network. Returns JSON string with agent details (accountId, privateKey, topics) on success. Optionally supports fee configuration for the agent's inbound topic using HBAR or specific tokens.\";\n private client: HCS10Client;\n private stateManager?: IStateManager;\n\n schema = z.object({\n name: z.string().describe('The name of the agent to register'),\n description: z\n .string()\n .optional()\n .describe('Optional description of the agent'),\n type: z\n .enum(['autonomous', 'manual'])\n .optional()\n .describe('Optional agent type (default: autonomous)'),\n model: z\n .string()\n .optional()\n .describe('Optional model identifier for the agent'),\n capabilities: z\n .array(z.number())\n .optional()\n .describe(\n 'Optional array of AIAgentCapability enum values (0-18). If not provided, defaults to just TEXT_GENERATION (0)'\n ),\n profilePicture: z\n .union([\n z.string().describe('Path to a local image file or URL to an image'),\n z.object({\n url: z.string().describe('URL to an image file'),\n filename: z.string().describe('Filename to use for the image'),\n }),\n z.object({\n path: z.string().describe('Path to a local image file'),\n filename: z.string().optional().describe('Optional custom filename'),\n }),\n ])\n .optional()\n .describe(\n 'Optional profile picture for the agent (local file path or URL)'\n ),\n feeCollectorAccountId: z\n .string()\n .optional()\n .describe(\n \"The account ID to collect fees. If not specified, the new agent's account ID will be used. Required if any fee is specified.\"\n ),\n hbarFee: z\n .number()\n .optional()\n .describe(\n 'Optional: The fee amount in HBAR to charge per message on the inbound topic (e.g., 0.5). If specified, inboundTopicType will be set to FEE_BASED.'\n ),\n tokenFee: z\n .object({\n amount: z.number(),\n tokenId: z.string(),\n })\n .optional()\n .describe(\n 'Optional: The fee amount and token ID to charge per message on the inbound topic (e.g., { amount: 10, tokenId: \"0.0.12345\" }). If specified, inboundTopicType will be set to FEE_BASED.'\n ),\n hbarFees: z\n .array(\n z.object({\n amount: z.number(),\n collectorAccount: z.string().optional(),\n })\n )\n .optional()\n .describe(\n 'Optional: Array of HBAR fees with different collectors. If specified, inboundTopicType will be set to FEE_BASED.'\n ),\n tokenFees: z\n .array(\n z.object({\n amount: z.number(),\n tokenId: z.string(),\n collectorAccount: z.string().optional(),\n })\n )\n .optional()\n .describe(\n 'Optional: Array of token fees with different collectors. If specified, inboundTopicType will be set to FEE_BASED.'\n ),\n exemptAccountIds: z\n .array(z.string())\n .optional()\n .describe(\n 'Optional: Array of account IDs to exempt from ALL fees set for this agent.'\n ),\n setAsCurrent: z\n .boolean()\n .optional()\n .describe(\n 'Optional: Whether to set the newly registered agent as the current active agent in the state manager. Default: true'\n ),\n persistence: z\n .object({\n prefix: z.string().optional(),\n })\n .optional()\n .describe(\n 'Optional: Configuration for persisting agent data to environment variables. The prefix will determine the environment variable names (e.g., PREFIX_ACCOUNT_ID). Defaults to TODD if not specified.'\n ),\n });\n\n /**\n * Creates a new RegisterAgentTool instance\n * @param client - Instance of HCS10Client (already configured with operator/network)\n * @param stateManager - Optional state manager to store agent details\n */\n constructor(client: HCS10Client, stateManager?: IStateManager) {\n super();\n this.client = client;\n this.stateManager = stateManager;\n }\n\n /**\n * Loads a profile picture from a local file or URL and returns a buffer\n * @param profilePicture - Local file path or URL\n * @returns Object containing buffer and filename\n */\n private async loadProfilePicture(\n profilePicture: ProfilePictureInput\n ): Promise<{ buffer: Buffer; filename: string } | null> {\n const logger = Logger.getInstance({\n level: 'debug',\n });\n\n try {\n if (!profilePicture) {\n return null;\n }\n\n if (typeof profilePicture === 'string') {\n const isUrl =\n profilePicture.startsWith('http://') ||\n profilePicture.startsWith('https://');\n\n if (isUrl) {\n logger.info(`Loading profile picture from URL: ${profilePicture}`);\n const response = await axios.get(profilePicture, {\n responseType: 'arraybuffer',\n });\n const buffer = Buffer.from(response.data);\n\n const urlPathname = new URL(profilePicture).pathname;\n const filename = path.basename(urlPathname) || 'profile.png';\n\n return { buffer, filename };\n } else {\n if (!fs.existsSync(profilePicture)) {\n logger.warn(`Profile picture file not found: ${profilePicture}`);\n return null;\n }\n\n logger.info(`Loading profile picture from file: ${profilePicture}`);\n const buffer = fs.readFileSync(profilePicture);\n const filename = path.basename(profilePicture);\n\n return { buffer, filename };\n }\n }\n\n if ('url' in profilePicture) {\n logger.info(`Loading profile picture from URL: ${profilePicture.url}`);\n const response = await axios.get(profilePicture.url, {\n responseType: 'arraybuffer',\n });\n const buffer = Buffer.from(response.data);\n const filename = profilePicture.filename || 'profile.png';\n\n return { buffer, filename };\n }\n\n if ('path' in profilePicture) {\n if (!fs.existsSync(profilePicture.path)) {\n logger.warn(`Profile picture file not found: ${profilePicture.path}`);\n return null;\n }\n\n logger.info(\n `Loading profile picture from file: ${profilePicture.path}`\n );\n const buffer = fs.readFileSync(profilePicture.path);\n const filename =\n profilePicture.filename || path.basename(profilePicture.path);\n\n return { buffer, filename };\n }\n\n return null;\n } catch (error) {\n logger.error('Failed to load profile picture:', error);\n return null;\n }\n }\n\n /**\n * Calls createAndRegisterAgent() with the provided metadata.\n * Returns a JSON string with agent details on success, or an error string.\n */\n async _call(input: z.infer<typeof this.schema>): Promise<string> {\n const logger = Logger.getInstance({\n level: 'debug',\n });\n\n const metadata: ExtendedAgentMetadata = {\n name: input.name,\n description: input.description,\n type: input.type,\n model: input.model,\n capabilities: input.capabilities || [AIAgentCapability.TEXT_GENERATION],\n properties: {},\n };\n\n let profilePictureSource = '';\n if (input.profilePicture) {\n const profilePictureData = await this.loadProfilePicture(\n input.profilePicture\n );\n if (profilePictureData) {\n const { buffer, filename } = profilePictureData;\n metadata.pfpBuffer = buffer;\n metadata.pfpFileName = filename;\n\n if (typeof input.profilePicture === 'string') {\n profilePictureSource = input.profilePicture;\n } else if ('url' in input.profilePicture) {\n profilePictureSource = input.profilePicture.url;\n } else if ('path' in input.profilePicture) {\n profilePictureSource = input.profilePicture.path;\n }\n }\n }\n\n const hasHbarFee = input.hbarFee !== undefined && input.hbarFee > 0;\n const hasTokenFee = this.hasValidTokenFee(input.tokenFee);\n const hasHbarFees = input.hbarFees && input.hbarFees.length > 0;\n const hasTokenFees = input.tokenFees && input.tokenFees.length > 0;\n\n if (hasHbarFee || hasTokenFee || hasHbarFees || hasTokenFees) {\n const { accountId: operatorAccountId } =\n this.client.getAccountAndSigner();\n const collectorId = input.feeCollectorAccountId || operatorAccountId;\n\n if (!collectorId) {\n return 'Error: Fee collector account ID is required when specifying fees and could not be determined.';\n }\n\n const feeConfigBuilder = new FeeConfigBuilder({\n network: this.client.getNetwork(),\n logger,\n });\n\n try {\n const exemptAccountIds =\n input.exemptAccountIds?.filter(\n (id) => id !== collectorId && id.startsWith('0.0')\n ) || [];\n\n let updatedFeeConfig = feeConfigBuilder;\n\n if (hasHbarFee) {\n logger.info(\n `Adding HBAR fee: ${input.hbarFee} HBAR to be collected by ${collectorId}`\n );\n updatedFeeConfig = updatedFeeConfig.addHbarFee(\n input.hbarFee!,\n collectorId,\n exemptAccountIds\n );\n }\n\n if (hasHbarFees) {\n for (const fee of input.hbarFees!) {\n const feeCollector = fee.collectorAccount || collectorId;\n logger.info(\n `Adding HBAR fee: ${fee.amount} HBAR to be collected by ${feeCollector}`\n );\n updatedFeeConfig = updatedFeeConfig.addHbarFee(\n fee.amount,\n feeCollector,\n exemptAccountIds\n );\n }\n }\n\n if (hasTokenFee) {\n logger.info(\n `Adding token fee: ${input.tokenFee!.amount} of token ${\n input.tokenFee!.tokenId\n } to be collected by ${collectorId}`\n );\n updatedFeeConfig = await updatedFeeConfig.addTokenFee(\n input.tokenFee!.amount,\n input.tokenFee!.tokenId,\n collectorId,\n undefined,\n exemptAccountIds\n );\n }\n\n if (hasTokenFees) {\n for (const fee of input.tokenFees!) {\n const feeCollector = fee.collectorAccount || collectorId;\n logger.info(\n `Adding token fee: ${fee.amount} of token ${fee.tokenId} to be collected by ${feeCollector}`\n );\n updatedFeeConfig = await updatedFeeConfig.addTokenFee(\n fee.amount,\n fee.tokenId,\n feeCollector,\n undefined,\n exemptAccountIds\n );\n }\n }\n\n metadata.feeConfig = updatedFeeConfig;\n logger.info('FeeConfigBuilder created successfully');\n } catch (error) {\n return `Error: Failed to configure fees. Reason: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n\n try {\n logger.info('Registering agent with metadata');\n\n const result = (await this.client.createAndRegisterAgent(\n metadata\n )) as unknown as HCS10RegistrationResult;\n\n return this.processRegistrationResult(\n result,\n input,\n profilePictureSource\n );\n } catch (error) {\n return `Error: Failed to create/register agent \"${input.name}\". Reason: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n\n /**\n * Checks if the token fee configuration is valid\n */\n private hasValidTokenFee(tokenFee?: {\n amount: number;\n tokenId: string;\n }): boolean {\n return !!(\n tokenFee &&\n tokenFee.amount > 0 &&\n tokenFee.tokenId &&\n tokenFee.tokenId.trim() !== ''\n );\n }\n\n /**\n * Processes the registration result and returns formatted output\n */\n private async processRegistrationResult(\n result: HCS10RegistrationResult,\n input: z.infer<typeof this.schema>,\n profilePictureSource: string = ''\n ): Promise<string> {\n const newAgentAccountId = result?.metadata?.accountId || '';\n const inboundTopicId = result?.metadata?.inboundTopicId || '';\n const outboundTopicId = result?.metadata?.outboundTopicId || '';\n const profileTopicId = result?.metadata?.profileTopicId || '';\n const privateKey = result?.metadata?.privateKey || '';\n const pfpTopicId = result?.metadata?.pfpTopicId;\n\n this.validateRegistrationResult(\n newAgentAccountId,\n inboundTopicId,\n outboundTopicId,\n privateKey\n );\n\n if (\n this.stateManager &&\n privateKey &&\n newAgentAccountId &&\n inboundTopicId &&\n outboundTopicId &&\n (input.setAsCurrent === undefined || input.setAsCurrent)\n ) {\n const agent = {\n name: input.name,\n accountId: newAgentAccountId,\n inboundTopicId,\n outboundTopicId,\n profileTopicId,\n privateKey,\n pfpTopicId: pfpTopicId as string,\n };\n\n this.stateManager.setCurrentAgent(agent);\n\n if (this.stateManager.persistAgentData && input.persistence) {\n try {\n const persistenceOptions: AgentPersistenceOptions = {\n type: 'env-file',\n prefix: input.persistence.prefix,\n };\n\n await this.stateManager.persistAgentData(agent, persistenceOptions);\n } catch (error) {\n Logger.getInstance().warn('Failed to persist agent data', error);\n }\n }\n }\n\n await this.ensureAgentHasFunds(newAgentAccountId, input.name);\n\n const feeDescription = this.createFeeDescription(input);\n const feeMessage = feeDescription\n ? ` with ${feeDescription} fee on inbound topic`\n : '';\n\n const registrationDetails: AgentRegistrationDetails = {\n success: true,\n message: `Successfully registered agent '${input.name}'${feeMessage}.`,\n name: input.name,\n accountId: newAgentAccountId,\n privateKey: privateKey,\n inboundTopicId: inboundTopicId,\n outboundTopicId: outboundTopicId,\n profileTopicId: profileTopicId || 'N/A',\n capabilities: input.capabilities || [AIAgentCapability.TEXT_GENERATION],\n hasFees: !!(input.hbarFee || this.hasValidTokenFee(input.tokenFee)),\n hbarFee: input.hbarFee || 0,\n tokenFee: input.tokenFee || null,\n };\n\n if (pfpTopicId || profilePictureSource) {\n registrationDetails.profilePicture = {\n source: profilePictureSource,\n topicId: pfpTopicId as string,\n };\n }\n\n return JSON.stringify(registrationDetails);\n }\n\n /**\n * Ensures the agent has enough HBAR for operations\n */\n private async ensureAgentHasFunds(\n accountId: string,\n agentName: string\n ): Promise<void> {\n try {\n await ensureAgentHasEnoughHbar(\n Logger.getInstance({\n module: 'RegisterAgentTool',\n }),\n this.client.standardClient,\n accountId,\n agentName\n );\n } catch (error) {\n Logger.getInstance().error('Failed to auto fund agent', error);\n }\n }\n\n /**\n * Validates that all required fields are present in the registration result\n */\n private validateRegistrationResult(\n accountId?: string,\n inboundTopicId?: string,\n outboundTopicId?: string,\n privateKey?: string\n ): void {\n if (!accountId || !inboundTopicId || !outboundTopicId || !privateKey) {\n const missingFields = [\n !accountId && 'accountId',\n !inboundTopicId && 'inboundTopicId',\n !outboundTopicId && 'outboundTopicId',\n !privateKey && 'privateKey',\n ]\n .filter(Boolean)\n .join(', ');\n throw new Error(\n `Registration failed. The HCS client returned incomplete details (Missing: ${missingFields}).`\n );\n }\n }\n\n /**\n * Creates a description of the fees configured for the agent\n */\n private createFeeDescription(input: z.infer<typeof this.schema>): string {\n const hasHbarFee = input.hbarFee && input.hbarFee > 0;\n const hasTokenFee = this.hasValidTokenFee(input.tokenFee);\n if (!hasHbarFee && !hasTokenFee) {\n return '';\n }\n\n let description = '';\n if (hasHbarFee) {\n description += `${input.hbarFee} HBAR`;\n }\n if (hasTokenFee && input.tokenFee) {\n const tokenFeeText = `${input.tokenFee.amount} of token ${input.tokenFee.tokenId}`;\n description += description ? ` and ${tokenFeeText}` : tokenFeeText;\n }\n return description;\n }\n}\n"],"names":["path","fs"],"mappings":";;;;;;;AAuEO,MAAM,0BAA0B,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkHpD,YAAY,QAAqB,cAA8B;AACvD,UAAA;AAlHD,SAAA,OAAA;AAEL,SAAA,cAAA;AAIF,SAAA,SAAS,EAAE,OAAO;AAAA,MAChB,MAAM,EAAE,SAAS,SAAS,mCAAmC;AAAA,MAC7D,aAAa,EACV,OAAA,EACA,SAAS,EACT,SAAS,mCAAmC;AAAA,MAC/C,MAAM,EACH,KAAK,CAAC,cAAc,QAAQ,CAAC,EAC7B,SAAA,EACA,SAAS,2CAA2C;AAAA,MACvD,OAAO,EACJ,OAAA,EACA,SAAS,EACT,SAAS,yCAAyC;AAAA,MACrD,cAAc,EACX,MAAM,EAAE,QAAQ,EAChB,WACA;AAAA,QACC;AAAA,M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standards-agent-kit.es3.js","sources":["../../src/hcs10/HCS10Client.ts"],"sourcesContent":["import { TransactionReceipt, PrivateKey } from '@hashgraph/sdk';\nimport {\n HCS10Client as StandardSDKClient,\n AgentBuilder,\n InboundTopicType as StandardInboundTopicType,\n AIAgentCapability as StandardAIAgentCapability,\n AgentRegistrationResult,\n WaitForConnectionConfirmationResponse,\n ProfileResponse as SDKProfileResponse,\n HCSMessage,\n LogLevel,\n Logger,\n FeeConfigBuilderInterface,\n SocialPlatform,\n} from '@hashgraphonline/standards-sdk';\nimport { AgentMetadata, AgentChannels } from './types';\nimport { encryptMessage } from '../utils/Encryption';\nimport { IStateManager } from '../state/state-types';\n\n// Keep type alias as they were removed accidentally\ntype StandardHandleConnectionRequest = InstanceType<\n typeof StandardSDKClient\n>['handleConnectionRequest'];\ntype HandleConnectionRequestResponse = Awaited<\n ReturnType<StandardHandleConnectionRequest>\n>;\nexport type StandardNetworkType = 'mainnet' | 'testnet';\n\nexport interface ClientValidationOptions {\n accountId: string;\n privateKey: string;\n network?: StandardNetworkType;\n stateManager?: IStateManager;\n}\n\nexport interface HCSMessageWithTimestamp extends HCSMessage {\n timestamp: number;\n data?: string;\n sequence_number: number;\n}\n\nexport interface ExtendedAgentMetadata extends AgentMetadata {\n pfpBuffer?: Buffer;\n pfpFileName?: string;\n feeConfig?: FeeConfigBuilderInterface;\n}\n\n/**\n * HCS10Client wraps the HCS-10 functionalities using the @hashgraphonline/standards-sdk.\n * - Creates and registers agents using the standard SDK flow.\n * - Manages agent communication channels (handled by standard SDK).\n * - Sends messages on Hedera topics (currently manual, potential for standard SDK integration).\n */\nexport class HCS10Client {\n public standardClient: StandardSDKClient;\n private useEncryption: boolean;\n public agentChannels?: AgentChannels;\n public guardedRegistryBaseUrl: string;\n public logger: Logger;\n\n constructor(\n operatorId: string,\n operatorPrivateKey: string,\n network: StandardNetworkType,\n options?: {\n useEncryption?: boolean;\n registryUrl?: string;\n logLevel?: LogLevel;\n }\n ) {\n this.standardClient = new StandardSDKClient({\n network: network,\n operatorId: operatorId,\n operatorPrivateKey: operatorPrivateKey,\n guardedRegistryBaseUrl: options?.registryUrl,\n logLevel: options?.logLevel,\n });\n this.guardedRegistryBaseUrl = options?.registryUrl || '';\n this.useEncryption = options?.useEncryption || false;\n const shouldSilence = process.env.DISABLE_LOGGING === 'true';\n this.logger = new Logger({\n level: options?.logLevel || 'info',\n silent: shouldSilence,\n });\n }\n\n public getOperatorId(): string {\n const operator = this.standardClient.getClient().operatorAccountId;\n if (!operator) {\n throw new Error('Operator Account ID not configured in standard client.');\n }\n return operator.toString();\n }\n\n public getNetwork(): StandardNetworkType {\n return this.standardClient.getNetwork() as StandardNetworkType;\n }\n\n public async handleConnectionRequest(\n inboundTopicId: string,\n requestingAccountId: string,\n connectionRequestId: number,\n feeConfig?: FeeConfigBuilderInterface\n ): Promise<HandleConnectionRequestResponse> {\n try {\n const result = await this.standardClient.handleConnectionRequest(\n inboundTopicId,\n requestingAccountId,\n connectionRequestId,\n feeConfig\n );\n return result;\n } catch (error) {\n this.logger.error(\n `Error handling connection request #${connectionRequestId} for topic ${inboundTopicId}:`,\n error\n );\n throw new Error(\n `Failed to handle connection request: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n\n /**\n * Retrieves the profile for a given account ID using the standard SDK.\n */\n public async getAgentProfile(accountId: string): Promise<SDKProfileResponse> {\n return this.standardClient.retrieveProfile(accountId);\n }\n\n /**\n * Exposes the standard SDK's submitConnectionRequest method.\n */\n public async submitConnectionRequest(\n inboundTopicId: string,\n memo: string\n ): Promise<TransactionReceipt> {\n return this.standardClient.submitConnectionRequest(\n inboundTopicId,\n memo\n ) as Promise<TransactionReceipt>;\n }\n\n /**\n * Exposes the standard SDK's waitForConnectionConfirmation method.\n */\n public async waitForConnectionConfirmation(\n outboundTopicId: string,\n connectionRequestId: number,\n maxAttempts = 60,\n delayMs = 2000\n ): Promise<WaitForConnectionConfirmationResponse> {\n return this.standardClient.waitForConnectionConfirmation(\n outboundTopicId,\n connectionRequestId,\n maxAttempts,\n delayMs\n );\n }\n\n /**\n * Creates and registers an agent using the standard SDK's HCS10Client.\n * This handles account creation, key generation, topic setup, and registration.\n *\n * When metadata includes fee configuration:\n * 1. The properties.feeConfig will be passed to the AgentBuilder\n * 2. The properties.inboundTopicType will be set to FEE_BASED\n * 3. The SDK's createAndRegisterAgent will apply the fees to the agent's inbound topic\n *\n * @param metadata - The agent's metadata, potentially including pfpBuffer, pfpFileName,\n * and fee configuration in properties.feeConfig\n * @returns The registration result from the standard SDK, containing accountId, keys, topics etc.\n */\n public async createAndRegisterAgent(\n metadata: ExtendedAgentMetadata\n ): Promise<AgentRegistrationResult> {\n const builder = new AgentBuilder()\n .setName(metadata.name)\n .setBio(metadata.description || '')\n .setCapabilities(\n metadata.capabilities\n ? metadata.capabilities\n : [StandardAIAgentCapability.TEXT_GENERATION]\n )\n .setType((metadata.type || 'autonomous') as 'autonomous' | 'manual')\n .setModel(metadata.model || 'agent-model-2024')\n .setNetwork(this.getNetwork())\n .setInboundTopicType(StandardInboundTopicType.PUBLIC);\n\n if (metadata?.feeConfig) {\n builder.setInboundTopicType(StandardInboundTopicType.FEE_BASED);\n builder.setFeeConfig(metadata.feeConfig);\n }\n\n if (metadata.pfpBuffer && metadata.pfpFileName) {\n if (metadata.pfpBuffer.byteLength === 0) {\n this.logger.warn(\n 'Provided PFP buffer is empty. Skipping profile picture.'\n );\n } else {\n this.logger.info(\n `Setting profile picture: ${metadata.pfpFileName} (${metadata.pfpBuffer.byteLength} bytes)`\n );\n builder.setProfilePicture(metadata.pfpBuffer, metadata.pfpFileName);\n }\n } else {\n this.logger.warn(\n 'Profile picture not provided in metadata. Agent creation might fail if required by the underlying SDK builder.'\n );\n }\n\n if (metadata.social) {\n Object.entries(metadata.social).forEach(([platform, handle]) => {\n builder.addSocial(platform as SocialPlatform, handle);\n });\n }\n\n if (metadata.properties) {\n Object.entries(metadata.properties).forEach(([key, value]) => {\n builder.addProperty(key, value);\n });\n }\n\n try {\n const hasFees = Boolean(metadata?.feeConfig);\n const result = await this.standardClient.createAndRegisterAgent(builder, {\n initialBalance: hasFees ? 50 : undefined,\n });\n if (\n result?.metadata?.inboundTopicId &&\n result?.metadata?.outboundTopicId\n ) {\n this.agentChannels = {\n inboundTopicId: result.metadata.inboundTopicId,\n outboundTopicId: result.metadata.outboundTopicId,\n };\n }\n return result;\n } catch (error) {\n this.logger.error('Error during agent creation/registration:', error);\n throw new Error(\n `Failed to create/register agent: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n\n /**\n * Sends a structured HCS-10 message to the specified topic using the standard SDK client.\n * Handles potential inscription for large messages.\n *\n * @param topicId - The target topic ID (likely a connection topic).\n * @param operatorId - The operator ID string (e.g., \"inboundTopic@accountId\").\n * @param data - The actual message content/data.\n * @param memo - Optional memo for the message.\n * @param submitKey - Optional private key for topics requiring specific submit keys.\n * @returns A confirmation status string from the transaction receipt.\n */\n public async sendMessage(\n topicId: string,\n data: string,\n memo?: string,\n submitKey?: PrivateKey\n ): Promise<number | undefined> {\n if (this.useEncryption) {\n data = encryptMessage(data);\n }\n\n try {\n const messageResponse = await this.standardClient.sendMessage(\n topicId,\n data,\n memo,\n submitKey\n );\n return messageResponse.topicSequenceNumber?.toNumber();\n } catch (error) {\n this.logger.error(`Error sending message to topic ${topicId}:`, error);\n throw new Error(\n `Failed to send message: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n\n /**\n * Retrieves messages from a topic using the standard SDK client.\n *\n * @param topicId - The topic ID to get messages from.\n * @returns Messages from the topic, mapped to the expected format.\n */\n public async getMessages(topicId: string): Promise<{\n messages: HCSMessageWithTimestamp[];\n }> {\n try {\n const result = await this.standardClient.getMessages(topicId);\n\n const mappedMessages = result.messages.map((sdkMessage) => {\n const timestamp = sdkMessage?.created?.getTime() || 0;\n\n return {\n ...sdkMessage,\n timestamp: timestamp,\n data: sdkMessage.data,\n sequence_number: sdkMessage.sequence_number,\n };\n });\n mappedMessages.sort(\n (a: { timestamp: number }, b: { timestamp: number }) =>\n a.timestamp - b.timestamp\n );\n return { messages: mappedMessages as HCSMessageWithTimestamp[] };\n } catch (error) {\n this.logger.error(`Error getting messages from topic ${topicId}:`, error);\n return { messages: [] };\n }\n }\n\n public async getMessageStream(topicId: string): Promise<{\n messages: HCSMessage[];\n }> {\n const result = this.standardClient.getMessageStream(topicId);\n return result as Promise<{ messages: HCSMessage[] }>;\n }\n\n /**\n * Retrieves content from an inscribed message using the standard SDK client.\n * @param inscriptionIdOrData - The inscription ID (hcs://...) or potentially raw data string.\n * @returns The resolved message content.\n */\n public async getMessageContent(inscriptionIdOrData: string): Promise<string> {\n try {\n const content = await this.standardClient.getMessageContent(\n inscriptionIdOrData\n );\n return content as string;\n } catch (error) {\n this.logger.error(\n `Error retrieving message content for: ${inscriptionIdOrData}`,\n error\n );\n throw new Error(\n `Failed to retrieve message content: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n\n /**\n * Retrieves the inbound topic ID associated with the current operator.\n * This typically involves fetching the operator's own HCS-10 profile.\n * @returns A promise that resolves to the operator's inbound topic ID.\n * @throws {Error} If the operator ID cannot be determined or the profile/topic cannot be retrieved.\n */\n public async getInboundTopicId(): Promise<string> {\n try {\n const operatorId = this.getOperatorId();\n this.logger.info(\n `[HCS10Client] Retrieving profile for operator ${operatorId} to find inbound topic...`\n );\n const profileResponse = await this.getAgentProfile(operatorId);\n if (profileResponse.success && profileResponse.topicInfo?.inboundTopic) {\n this.logger.info(\n `[HCS10Client] Found inbound topic for operator ${operatorId}: ${profileResponse.topicInfo.inboundTopic}`\n );\n return profileResponse.topicInfo.inboundTopic;\n } else {\n throw new Error(\n `Could not retrieve inbound topic from profile for ${operatorId}. Profile success: ${profileResponse.success}, Error: ${profileResponse.error}`\n );\n }\n } catch (error) {\n this.logger.error(\n `[HCS10Client] Error fetching operator's inbound topic ID (${this.getOperatorId()}):`,\n error\n );\n const operatorId = this.getOperatorId();\n let detailedMessage = `Failed to get inbound topic ID for operator ${operatorId}.`;\n if (\n error instanceof Error &&\n error.message.includes('does not have a valid HCS-11 memo')\n ) {\n detailedMessage += ` The account profile may not exist or is invalid. Please ensure this operator account (${operatorId}) is registered as an HCS-10 agent. You might need to register it first (e.g., using the 'register_agent' tool or SDK function).`;\n } else if (error instanceof Error) {\n detailedMessage += ` Reason: ${error.message}`;\n } else {\n detailedMessage += ` Unexpected error: ${String(error)}`;\n }\n throw new Error(detailedMessage);\n }\n }\n\n /**\n * Retrieves the configured operator account ID and private key.\n * Required by tools needing to identify the current agent instance.\n */\n public getAccountAndSigner(): { accountId: string; signer: PrivateKey } {\n const result = this.standardClient.getAccountAndSigner();\n return {\n accountId: result.accountId,\n signer: result.signer as unknown as PrivateKey,\n };\n }\n\n /**\n * Retrieves the outbound topic ID for the current operator.\n * Fetches the operator's profile if necessary.\n * @returns The outbound topic ID string.\n * @throws If the outbound topic cannot be determined.\n */\n public async getOutboundTopicId(): Promise<string> {\n const operatorId = this.getOperatorId();\n const profile = await this.getAgentProfile(operatorId);\n if (profile.success && profile.topicInfo?.outboundTopic) {\n return profile.topicInfo.outboundTopic;\n } else {\n throw new Error(\n `Could not retrieve outbound topic from profile for ${operatorId}. Profile success: ${profile.success}, Error: ${profile.error}`\n );\n }\n }\n\n public setClient(accountId: string, privateKey: string): StandardSDKClient {\n this.standardClient = new StandardSDKClient({\n network: this.getNetwork(),\n operatorId: accountId,\n operatorPrivateKey: privateKey,\n guardedRegistryBaseUrl: this.guardedRegistryBaseUrl,\n });\n return this.standardClient;\n }\n\n /**\n * Validates that the operator account exists and has proper access for agent operations\n */\n private async validateOperator(options: ClientValidationOptions): Promise<{\n isValid: boolean;\n operator?: { accountId: string };\n error?: string;\n }> {\n try {\n // Set up client with provided operator details\n this.setClient(options.accountId, options.privateKey);\n\n // Check if we can retrieve the operator ID\n const operatorId = this.getOperatorId();\n\n // If we got this far, basic validation passed\n return {\n isValid: true,\n operator: { accountId: operatorId },\n };\n } catch (error) {\n this.logger.error(`Validation error: ${error}`);\n return {\n isValid: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n async initializeWithValidation(options: ClientValidationOptions): Promise<{\n isValid: boolean;\n operator?: { accountId: string };\n error?: string;\n }> {\n const validationResult = await this.validateOperator(options);\n\n if (validationResult.isValid) {\n // If we have access to the state manager, initialize its connections manager\n if (options.stateManager) {\n options.stateManager.initializeConnectionsManager(this.standardClient);\n }\n }\n\n return validationResult;\n }\n}\n"],"names":["StandardSDKClient","StandardAIAgentCapability","StandardInboundTopicType"],"mappings":";;AAqDO,MAAM,YAAY;AAAA,EAOvB,YACE,YACA,oBACA,SACA,SAKA;AACA,SAAK,iBAAiB,IAAIA,cAAkB;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,MACA,wBAAwB,SAAS;AAAA,MACjC,UAAU,SAAS;AAAA,IAAA,CACpB;AACD,SAAK,yBAAyB,SAAS,eAAe;AACtD,SAAK,gBAAgB,SAAS,iBAAiB;AAC/C,UAAM,gBAAgB,QAAQ,IAAI,oBAAoB;AACtD,SAAK,SAAS,IAAI,OAAO;AAAA,MACvB,OAAO,SAAS,YAAY;AAAA,MAC5B,QAAQ;AAAA,IAAA,CACT;AAAA,EACH;AAAA,EAEO,gBAAwB;AAC7B,UAAM,WAAW,KAAK,eAAe,UAAA,EAAY;AACjD,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AACA,WAAO,SAAS,SAAA;AAAA,EAClB;AAAA,EAEO,aAAkC;AACvC,WAAO,KAAK,eAAe,WAAA;AAAA,EAC7B;AAAA,EAEA,MAAa,wBACX,gBACA,qBACA,qBACA,WAC0C;AAC1C,QAAI;AACF,YAAM,SAAS,MAAM,KAAK,eAAe;AAAA,QACvC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAEF,aAAO;AAAA,IACT,SAAS,OAAO;AACd,WAAK,OAAO;AAAA,QACV,sCAAsC,mBAAmB,cAA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aseHederaQueryTool } from "hedera-agent-kit";
|
|
2
|
+
class BaseHCS10TransactionTool extends BaseHederaTransactionTool {
|
|
3
|
+
constructor(params) {
|
|
4
|
+
super(params);
|
|
5
|
+
this.namespace = "hcs10";
|
|
6
|
+
this.hcs10Builder = params.hcs10Builder;
|
|
7
|
+
}
|
|
5
8
|
/**
|
|
6
|
-
*
|
|
9
|
+
* Override to return the HCS10Builder
|
|
7
10
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
this.client = client;
|
|
19
|
-
this.logger = Logger.getInstance({ module: "SendMessageTool" });
|
|
11
|
+
getServiceBuilder() {
|
|
12
|
+
return this.hcs10Builder;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class BaseHCS10QueryTool extends BaseHederaQueryTool {
|
|
16
|
+
constructor(params) {
|
|
17
|
+
super(params);
|
|
18
|
+
this.namespace = "hcs10";
|
|
19
|
+
this.hcs10Builder = params.hcs10Builder;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Override to return the HCS10Builder
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const result = await this.client.sendMessage(
|
|
27
|
-
input.topicId,
|
|
28
|
-
input.message
|
|
29
|
-
);
|
|
30
|
-
if (!result) {
|
|
31
|
-
throw new Error("Failed to send message");
|
|
32
|
-
}
|
|
33
|
-
this.logger.info(`Message sent with sequence number ${result}`);
|
|
34
|
-
if (!input.disableMonitoring) {
|
|
35
|
-
const response = await this.monitorResponses(input.topicId, result);
|
|
36
|
-
return `Successfully sent message to topic ${input.topicId}${response ? `
|
|
37
|
-
Response: ${response}` : ""}`;
|
|
38
|
-
} else {
|
|
39
|
-
return `Successfully sent message to topic ${input.topicId}`;
|
|
40
|
-
}
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
`Failed to send message: ${error instanceof Error ? error.message : String(error)}`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
async monitorResponses(topicId, sequenceNumber) {
|
|
48
|
-
const maxAttempts = 10;
|
|
49
|
-
let attempts = 0;
|
|
50
|
-
while (attempts < maxAttempts) {
|
|
51
|
-
try {
|
|
52
|
-
const messages = await this.client.getMessageStream(topicId);
|
|
53
|
-
for (const message of messages.messages) {
|
|
54
|
-
if (message.created && message.created.getTime() > this.lastProcessedTimestamp) {
|
|
55
|
-
this.lastProcessedTimestamp = message.created.getTime();
|
|
56
|
-
const content = await this.client.getMessageContent(message.data || "");
|
|
57
|
-
let parsedContent;
|
|
58
|
-
try {
|
|
59
|
-
parsedContent = JSON.parse(content);
|
|
60
|
-
} catch (error) {
|
|
61
|
-
this.logger.error(`Error parsing message content: ${error}`);
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (message.sequence_number > sequenceNumber) {
|
|
65
|
-
if (parsedContent && typeof parsedContent.data === "string") {
|
|
66
|
-
return parsedContent.data;
|
|
67
|
-
}
|
|
68
|
-
return JSON.stringify(parsedContent);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
} catch (error) {
|
|
73
|
-
this.logger.error(`Error monitoring responses: ${error}`);
|
|
74
|
-
}
|
|
75
|
-
attempts++;
|
|
76
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
24
|
+
getServiceBuilder() {
|
|
25
|
+
return this.hcs10Builder;
|
|
79
26
|
}
|
|
80
27
|
}
|
|
81
28
|
export {
|
|
82
|
-
|
|
29
|
+
BaseHCS10QueryTool,
|
|
30
|
+
BaseHCS10TransactionTool
|
|
83
31
|
};
|
|
84
32
|
//# sourceMappingURL=standards-agent-kit.es4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es4.js","sources":["../../src/tools/
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es4.js","sources":["../../src/tools/hcs10/base-hcs10-tools.ts"],"sourcesContent":["import {\n BaseHederaTransactionTool,\n BaseHederaQueryTool,\n BaseServiceBuilder,\n} from 'hedera-agent-kit';\nimport { HCS10Builder } from '../../builders/hcs10/hcs10-builder';\nimport {\n HCS10TransactionToolParams,\n HCS10QueryToolParams,\n} from './hcs10-tool-params';\nimport { z } from 'zod';\n\n/**\n * Base class for HCS10 transaction tools\n */\nexport abstract class BaseHCS10TransactionTool<\n T extends z.ZodObject<\n z.ZodRawShape,\n z.UnknownKeysParam,\n z.ZodTypeAny\n > = z.ZodObject<z.ZodRawShape>\n> extends BaseHederaTransactionTool<T> {\n protected hcs10Builder: HCS10Builder;\n namespace = 'hcs10' as const;\n\n constructor(params: HCS10TransactionToolParams) {\n super(params);\n this.hcs10Builder = params.hcs10Builder;\n }\n\n /**\n * Override to return the HCS10Builder\n */\n protected getServiceBuilder(): BaseServiceBuilder {\n return this.hcs10Builder;\n }\n}\n\n/**\n * Base class for HCS10 query tools\n */\nexport abstract class BaseHCS10QueryTool<\n T extends z.ZodObject<\n z.ZodRawShape,\n z.UnknownKeysParam,\n z.ZodTypeAny,\n Record<string, unknown>,\n Record<string, unknown>\n > = z.ZodObject<z.ZodRawShape>\n> extends BaseHederaQueryTool<T> {\n protected hcs10Builder: HCS10Builder;\n namespace = 'hcs10' as const;\n\n constructor(params: HCS10QueryToolParams) {\n super(params);\n this.hcs10Builder = params.hcs10Builder;\n }\n\n /**\n * Override to return the HCS10Builder\n */\n protected getServiceBuilder(): BaseServiceBuilder {\n return this.hcs10Builder;\n }\n}\n"],"names":[],"mappings":";AAeO,MAAe,iCAMZ,0BAA6B;AAAA,EAIrC,YAAY,QAAoC;AAC9C,UAAM,MAAM;AAHd,SAAA,YAAY;AAIV,SAAK,eAAe,OAAO;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKU,oBAAwC;AAChD,WAAO,KAAK;AAAA,EACd;AACF;AAKO,MAAe,2BAQZ,oBAAuB;AAAA,EAI/B,YAAY,QAA8B;AACxC,UAAM,MAAM;AAHd,SAAA,YAAY;AAIV,SAAK,eAAe,OAAO;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKU,oBAAwC;AAChD,WAAO,KAAK;AAAA,EACd;AACF;"}
|
|
@@ -1,168 +1,141 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AIAgentCapability } from "@hashgraphonline/standards-sdk";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
import { BaseHCS10TransactionTool } from "./standards-agent-kit.es4.js";
|
|
4
|
+
const RegisterAgentZodSchema = z.object({
|
|
5
|
+
name: z.string().min(1).max(50).describe("A unique name for the agent (1-50 characters)"),
|
|
6
|
+
description: z.string().max(500).optional().describe("Optional bio description for the agent (max 500 characters)"),
|
|
7
|
+
alias: z.string().optional().describe("Optional custom username/alias for the agent"),
|
|
8
|
+
type: z.enum(["autonomous", "manual"]).optional().describe("Agent type (default: autonomous)"),
|
|
9
|
+
model: z.string().optional().describe("AI model identifier (default: agent-model-2024)"),
|
|
10
|
+
capabilities: z.array(z.nativeEnum(AIAgentCapability)).optional().describe("Array of agent capabilities (default: [TEXT_GENERATION])"),
|
|
11
|
+
creator: z.string().optional().describe("Creator attribution for the agent"),
|
|
12
|
+
socials: z.record(
|
|
13
|
+
z.enum([
|
|
14
|
+
"twitter",
|
|
15
|
+
"github",
|
|
16
|
+
"discord",
|
|
17
|
+
"telegram",
|
|
18
|
+
"linkedin",
|
|
19
|
+
"youtube",
|
|
20
|
+
"website",
|
|
21
|
+
"x"
|
|
22
|
+
]),
|
|
23
|
+
z.string()
|
|
24
|
+
).optional().describe(
|
|
25
|
+
'Social media links (e.g., {"twitter": "@handle", "discord": "username"})'
|
|
26
|
+
),
|
|
27
|
+
properties: z.record(z.unknown()).optional().describe("Custom metadata properties for the agent"),
|
|
28
|
+
profilePicture: z.union([
|
|
29
|
+
z.string().describe("URL or local file path to profile picture"),
|
|
30
|
+
z.object({
|
|
31
|
+
url: z.string().optional(),
|
|
32
|
+
path: z.string().optional(),
|
|
33
|
+
filename: z.string().optional()
|
|
34
|
+
})
|
|
35
|
+
]).optional().describe(
|
|
36
|
+
"Optional profile picture as URL, file path, or object with url/path/filename"
|
|
37
|
+
),
|
|
38
|
+
existingProfilePictureTopicId: z.string().optional().describe(
|
|
39
|
+
"Topic ID of an existing profile picture to reuse (e.g., 0.0.12345)"
|
|
40
|
+
),
|
|
41
|
+
initialBalance: z.number().positive().optional().describe(
|
|
42
|
+
"Optional initial HBAR balance for the new agent account (will create new account if provided)"
|
|
43
|
+
),
|
|
44
|
+
userAccountId: z.string().optional().describe(
|
|
45
|
+
"Optional account ID (e.g., 0.0.12345) to use as the agent account instead of creating a new one"
|
|
46
|
+
),
|
|
47
|
+
hbarFee: z.number().positive().optional().describe(
|
|
48
|
+
"Optional HBAR fee amount to charge per message on the inbound topic"
|
|
49
|
+
),
|
|
50
|
+
tokenFees: z.array(
|
|
51
|
+
z.object({
|
|
52
|
+
amount: z.number().positive(),
|
|
53
|
+
tokenId: z.string()
|
|
54
|
+
})
|
|
55
|
+
).optional().describe("Optional token fees to charge per message"),
|
|
56
|
+
exemptAccountIds: z.array(z.string()).optional().describe("Optional account IDs to exempt from fees"),
|
|
57
|
+
setAsCurrent: z.boolean().optional().describe("Whether to set as current agent (default: true)"),
|
|
58
|
+
persistence: z.object({
|
|
59
|
+
prefix: z.string().optional()
|
|
60
|
+
}).optional().describe("Optional persistence configuration")
|
|
61
|
+
});
|
|
62
|
+
class RegisterAgentTool extends BaseHCS10TransactionTool {
|
|
63
|
+
constructor(params) {
|
|
64
|
+
super(params);
|
|
65
|
+
this.name = "register_agent";
|
|
66
|
+
this.description = "Creates and registers the AI agent on the Hedera network. Returns JSON string with agent details (accountId, privateKey, topics) on success. Note: This tool requires multiple transactions and cannot be used in returnBytes mode.";
|
|
67
|
+
this.specificInputSchema = RegisterAgentZodSchema;
|
|
68
|
+
this.neverScheduleThisTool = true;
|
|
69
|
+
this.requiresMultipleTransactions = true;
|
|
22
70
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
inboundTopicId = await this.client.getInboundTopicId();
|
|
31
|
-
} catch (error) {
|
|
32
|
-
const errorMsg = `Error getting inbound topic ID for monitoring: ${error instanceof Error ? error.message : String(error)}`;
|
|
33
|
-
this.logger.error(errorMsg);
|
|
34
|
-
return errorMsg;
|
|
71
|
+
async callBuilderMethod(builder, specificArgs) {
|
|
72
|
+
const hcs10Builder = builder;
|
|
73
|
+
const params = {
|
|
74
|
+
name: specificArgs.name
|
|
75
|
+
};
|
|
76
|
+
if (specificArgs.description !== void 0) {
|
|
77
|
+
params.bio = specificArgs.description;
|
|
35
78
|
}
|
|
36
|
-
if (
|
|
37
|
-
|
|
79
|
+
if (specificArgs.alias !== void 0) {
|
|
80
|
+
params.alias = specificArgs.alias;
|
|
38
81
|
}
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
return `Already monitoring topic ${inboundTopicId}.`;
|
|
42
|
-
} else {
|
|
43
|
-
return `Error: Already monitoring a different topic (${this.monitoringTopic}). Stop the current monitor first.`;
|
|
44
|
-
}
|
|
82
|
+
if (specificArgs.type !== void 0) {
|
|
83
|
+
params.type = specificArgs.type;
|
|
45
84
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
while (this.isMonitoring && this.monitoringTopic === inboundTopicId) {
|
|
69
|
-
try {
|
|
70
|
-
const messagesResult = await this.client.getMessages(inboundTopicId);
|
|
71
|
-
const allMessages = messagesResult.messages;
|
|
72
|
-
const connectionRequests = allMessages.filter(
|
|
73
|
-
(msg) => msg.op === "connection_request" && typeof msg.sequence_number === "number"
|
|
74
|
-
// Keep filtering by sequence number if needed, or remove if checking existing confirmations is sufficient
|
|
75
|
-
// msg.sequence_number > lastProcessedMessageSequence // Temporarily remove or adjust this if checking confirmations is the primary method
|
|
76
|
-
);
|
|
77
|
-
for (const message of connectionRequests) {
|
|
78
|
-
lastProcessedMessageSequence = Math.max(
|
|
79
|
-
lastProcessedMessageSequence,
|
|
80
|
-
message.sequence_number || 0
|
|
81
|
-
// Use 0 if sequence_number is undefined (though filter should prevent this)
|
|
82
|
-
);
|
|
83
|
-
const connectionRequestId = message.sequence_number;
|
|
84
|
-
if (!connectionRequestId) {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
const alreadyHandled = allMessages.some(
|
|
88
|
-
(m) => m.op === "connection_created" && m.connection_id === connectionRequestId
|
|
89
|
-
);
|
|
90
|
-
if (alreadyHandled) {
|
|
91
|
-
this.logger.debug(
|
|
92
|
-
`Connection request #${connectionRequestId} already handled (found connection_created). Skipping.`
|
|
93
|
-
);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const senderOperatorId = message.operator_id || "";
|
|
97
|
-
const requestingAccountId = senderOperatorId.split("@")[1] || null;
|
|
98
|
-
if (!requestingAccountId) {
|
|
99
|
-
this.logger.warn(
|
|
100
|
-
`Could not determine requesting account ID from operator_id '${senderOperatorId}' for request #${connectionRequestId}. Skipping.`
|
|
101
|
-
);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (processedRequestIds.has(connectionRequestId)) {
|
|
105
|
-
this.logger.info(
|
|
106
|
-
`Connection request #${connectionRequestId} already processed in this session. Skipping.`
|
|
107
|
-
);
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
this.logger.info(
|
|
111
|
-
`Processing connection request #${connectionRequestId} from account ${requestingAccountId}...`
|
|
112
|
-
);
|
|
113
|
-
try {
|
|
114
|
-
const confirmation = await this.client.handleConnectionRequest(
|
|
115
|
-
inboundTopicId,
|
|
116
|
-
requestingAccountId,
|
|
117
|
-
connectionRequestId
|
|
118
|
-
);
|
|
119
|
-
processedRequestIds.add(connectionRequestId);
|
|
120
|
-
this.logger.info(
|
|
121
|
-
`Connection confirmed for request #${connectionRequestId}. New connection topic: ${confirmation.connectionTopicId}`
|
|
122
|
-
);
|
|
123
|
-
const newConnection = {
|
|
124
|
-
targetAccountId: requestingAccountId,
|
|
125
|
-
targetAgentName: `Agent ${requestingAccountId}`,
|
|
126
|
-
targetInboundTopicId: "N/A",
|
|
127
|
-
connectionTopicId: confirmation.connectionTopicId
|
|
128
|
-
};
|
|
129
|
-
this.stateManager.addActiveConnection(newConnection);
|
|
130
|
-
this.logger.info(
|
|
131
|
-
`Added new active connection to ${requestingAccountId} state.`
|
|
132
|
-
);
|
|
133
|
-
} catch (handleError) {
|
|
134
|
-
this.logger.error(
|
|
135
|
-
`Error handling connection request #${connectionRequestId} from ${requestingAccountId}:`,
|
|
136
|
-
handleError
|
|
137
|
-
);
|
|
138
|
-
}
|
|
85
|
+
if (specificArgs.model !== void 0) {
|
|
86
|
+
params.model = specificArgs.model;
|
|
87
|
+
}
|
|
88
|
+
if (specificArgs.capabilities !== void 0) {
|
|
89
|
+
params.capabilities = specificArgs.capabilities;
|
|
90
|
+
}
|
|
91
|
+
if (specificArgs.creator !== void 0) {
|
|
92
|
+
params.creator = specificArgs.creator;
|
|
93
|
+
}
|
|
94
|
+
if (specificArgs.socials !== void 0) {
|
|
95
|
+
params.socials = specificArgs.socials;
|
|
96
|
+
}
|
|
97
|
+
if (specificArgs.properties !== void 0) {
|
|
98
|
+
params.properties = specificArgs.properties;
|
|
99
|
+
}
|
|
100
|
+
if (specificArgs.profilePicture !== void 0) {
|
|
101
|
+
if (typeof specificArgs.profilePicture === "string") {
|
|
102
|
+
params.profilePicture = specificArgs.profilePicture;
|
|
103
|
+
} else {
|
|
104
|
+
const profilePicObj = {};
|
|
105
|
+
if (specificArgs.profilePicture.url !== void 0) {
|
|
106
|
+
profilePicObj.url = specificArgs.profilePicture.url;
|
|
139
107
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
108
|
+
if (specificArgs.profilePicture.path !== void 0) {
|
|
109
|
+
profilePicObj.path = specificArgs.profilePicture.path;
|
|
110
|
+
}
|
|
111
|
+
if (specificArgs.profilePicture.filename !== void 0) {
|
|
112
|
+
profilePicObj.filename = specificArgs.profilePicture.filename;
|
|
113
|
+
}
|
|
114
|
+
params.profilePicture = profilePicObj;
|
|
145
115
|
}
|
|
146
|
-
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
147
116
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
117
|
+
if (specificArgs.existingProfilePictureTopicId !== void 0) {
|
|
118
|
+
params.existingProfilePictureTopicId = specificArgs.existingProfilePictureTopicId;
|
|
119
|
+
}
|
|
120
|
+
if (specificArgs.userAccountId !== void 0) {
|
|
121
|
+
params.userAccountId = specificArgs.userAccountId;
|
|
122
|
+
}
|
|
123
|
+
if (specificArgs.hbarFee !== void 0) {
|
|
124
|
+
params.hbarFee = specificArgs.hbarFee;
|
|
125
|
+
}
|
|
126
|
+
if (specificArgs.tokenFees !== void 0) {
|
|
127
|
+
params.tokenFees = specificArgs.tokenFees;
|
|
128
|
+
}
|
|
129
|
+
if (specificArgs.exemptAccountIds !== void 0) {
|
|
130
|
+
params.exemptAccountIds = specificArgs.exemptAccountIds;
|
|
131
|
+
}
|
|
132
|
+
if (specificArgs.initialBalance !== void 0) {
|
|
133
|
+
params.initialBalance = specificArgs.initialBalance;
|
|
162
134
|
}
|
|
135
|
+
await hcs10Builder.registerAgent(params);
|
|
163
136
|
}
|
|
164
137
|
}
|
|
165
138
|
export {
|
|
166
|
-
|
|
139
|
+
RegisterAgentTool
|
|
167
140
|
};
|
|
168
141
|
//# sourceMappingURL=standards-agent-kit.es5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es5.js","sources":["../../src/tools/ConnectionTool.ts"],"sourcesContent":["import { HCS10Client } from '../hcs10/HCS10Client';\nimport { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\n// Import FeeConfigBuilder if needed for explicit fee handling\n// import { FeeConfigBuilder } from '@hashgraphonline/standards-sdk';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport {\n IStateManager,\n ActiveConnection,\n} from '../state/state-types'; // Corrected import path/name\n\nexport interface ConnectionToolParams extends ToolParams {\n client: HCS10Client;\n stateManager: IStateManager;\n}\n\n/**\n * ConnectionTool monitors the *current* agent's inbound topic for connection requests\n * and automatically handles them using the HCS-10 standard SDK flow.\n * Use this ONLY to passively LISTEN for other agents trying to connect TO YOU.\n * This tool takes NO arguments and does NOT start outgoing connections.\n */\nexport class ConnectionTool extends StructuredTool {\n name = 'monitor_connections';\n description =\n \"Starts passively LISTENING on the current agent's own inbound topic for INCOMING HCS-10 connection requests. Handles received requests automatically. Takes NO arguments. DO NOT use this to start a new connection TO someone else.\";\n public client: HCS10Client;\n public logger: Logger;\n private stateManager: IStateManager; // Renamed property\n private isMonitoring: boolean = false; // Flag to prevent multiple monitors\n private monitoringTopic: string | null = null;\n\n // Schema now takes NO arguments\n schema = z.object({});\n\n /**\n * @param client - Instance of HCS10Client.\n * @param stateManager - Instance of StateManager for shared state management.\n */\n constructor({ client, stateManager, ...rest }: ConnectionToolParams) {\n super(rest);\n this.client = client;\n this.stateManager = stateManager; // Renamed assignment\n this.logger = Logger.getInstance({\n module: 'ConnectionTool',\n level: 'info',\n });\n }\n\n /**\n * Initiates the connection request monitoring process in the background.\n * Gets the inbound topic ID from the configured client.\n */\n async _call(/* _input: z.infer<typeof this.schema> */): Promise<string> {\n // Get inboundTopicId from the client\n let inboundTopicId: string;\n try {\n // Assuming getInboundTopicId() is implemented and available\n inboundTopicId = await this.client.getInboundTopicId();\n } catch (error) {\n const errorMsg = `Error getting inbound topic ID for monitoring: ${\n error instanceof Error ? error.message : String(error)\n }`;\n this.logger.error(errorMsg);\n return errorMsg;\n }\n\n if (!inboundTopicId) {\n return 'Error: Could not determine the inbound topic ID for the current agent.';\n }\n\n if (this.isMonitoring) {\n if (this.monitoringTopic === inboundTopicId) {\n return `Already monitoring topic ${inboundTopicId}.`;\n } else {\n return `Error: Already monitoring a different topic (${this.monitoringTopic}). Stop the current monitor first.`;\n // TODO: Add a mechanism to stop the monitor if needed.\n }\n }\n\n this.isMonitoring = true;\n this.monitoringTopic = inboundTopicId;\n this.logger.info(\n `Initiating connection request monitoring for topic ${inboundTopicId}...`\n );\n\n // Start the monitoring process asynchronously without awaiting it\n // This allows the tool call to return quickly.\n this.monitorIncomingRequests(inboundTopicId).catch((error) => {\n this.logger.error(\n `Monitoring loop for ${inboundTopicId} encountered an unrecoverable error:`,\n error\n );\n this.isMonitoring = false; // Reset flag on loop failure\n this.monitoringTopic = null;\n });\n\n return `Started monitoring inbound topic ${inboundTopicId} for connection requests in the background.`;\n }\n\n /**\n * The core monitoring loop.\n */\n private async monitorIncomingRequests(inboundTopicId: string): Promise<void> {\n this.logger.info(`Monitoring inbound topic ${inboundTopicId}...`);\n\n let lastProcessedMessageSequence = 0;\n const processedRequestIds = new Set<number>(); // Track processed requests within this monitoring session\n\n // Main monitoring loop\n while (this.isMonitoring && this.monitoringTopic === inboundTopicId) {\n try {\n const messagesResult = await this.client.getMessages(inboundTopicId);\n\n const allMessages = messagesResult.messages;\n\n const connectionRequests = allMessages.filter(\n (msg) =>\n msg.op === 'connection_request' &&\n typeof msg.sequence_number === 'number' // Keep filtering by sequence number if needed, or remove if checking existing confirmations is sufficient\n // msg.sequence_number > lastProcessedMessageSequence // Temporarily remove or adjust this if checking confirmations is the primary method\n );\n\n for (const message of connectionRequests) {\n // Update lastProcessedMessageSequence regardless of handling outcome to avoid re-checking handled/skipped messages in future loops\n lastProcessedMessageSequence = Math.max(\n lastProcessedMessageSequence,\n message.sequence_number || 0 // Use 0 if sequence_number is undefined (though filter should prevent this)\n );\n\n const connectionRequestId = message.sequence_number;\n if (!connectionRequestId) {\n continue; // Skip if sequence number is missing\n }\n\n // --- Check if already handled ---\n const alreadyHandled = allMessages.some(\n (m) => m.op === 'connection_created' && m.connection_id === connectionRequestId\n );\n\n if (alreadyHandled) {\n this.logger.debug(\n `Connection request #${connectionRequestId} already handled (found connection_created). Skipping.`\n );\n continue; // Skip to the next request\n }\n // --- End Check ---\n\n // Extract requesting account ID from the message's operator_id field (topic@account)\n const senderOperatorId = message.operator_id || '';\n const requestingAccountId = senderOperatorId.split('@')[1] || null;\n\n if (!requestingAccountId) {\n this.logger.warn(\n `Could not determine requesting account ID from operator_id '${senderOperatorId}' for request #${connectionRequestId}. Skipping.`\n );\n continue;\n }\n\n if (processedRequestIds.has(connectionRequestId)) {\n this.logger.info(\n `Connection request #${connectionRequestId} already processed in this session. Skipping.`\n );\n continue;\n }\n\n this.logger.info(\n `Processing connection request #${connectionRequestId} from account ${requestingAccountId}...`\n );\n\n try {\n // Handle the connection request using the HCS10Client wrapper\n const confirmation = await this.client.handleConnectionRequest(\n inboundTopicId,\n requestingAccountId,\n connectionRequestId\n );\n\n processedRequestIds.add(connectionRequestId);\n this.logger.info(\n `Connection confirmed for request #${connectionRequestId}. New connection topic: ${confirmation.connectionTopicId}`\n );\n\n // Use stateManager to add connection\n const newConnection: ActiveConnection = {\n targetAccountId: requestingAccountId,\n targetAgentName: `Agent ${requestingAccountId}`,\n targetInboundTopicId: 'N/A',\n connectionTopicId: confirmation.connectionTopicId,\n };\n this.stateManager.addActiveConnection(newConnection);\n this.logger.info(\n `Added new active connection to ${requestingAccountId} state.`\n );\n } catch (handleError) {\n this.logger.error(\n `Error handling connection request #${connectionRequestId} from ${requestingAccountId}:`,\n handleError\n );\n }\n }\n } catch (error) {\n this.logger.error(\n `Error fetching or processing messages for topic ${inboundTopicId}:`,\n error\n );\n // Implement backoff or error threshold if needed\n }\n\n // Wait before the next poll\n await new Promise((resolve) => setTimeout(resolve, 5000)); // Poll every 5 seconds (adjust as needed)\n }\n\n this.logger.info(`Monitoring loop stopped for topic ${inboundTopicId}.`);\n this.isMonitoring = false; // Ensure flag is reset when loop exits\n this.monitoringTopic = null;\n }\n\n // Optional: Method to explicitly stop monitoring\n public stopMonitoring(): void {\n if (this.isMonitoring) {\n this.logger.info(\n `Stopping monitoring for topic ${this.monitoringTopic}...`\n );\n this.isMonitoring = false;\n this.monitoringTopic = null;\n } else {\n this.logger.info('Monitor is not currently running.');\n }\n }\n}\n"],"names":[],"mappings":";;;AAsBO,MAAM,uBAAuB,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBjD,YAAY,EAAE,QAAQ,cAAc,GAAG,QAA8B;AACnE,UAAM,IAAI;AAjBL,SAAA,OAAA;AAEL,SAAA,cAAA;AAIF,SAAQ,eAAwB;AAChC,SAAQ,kBAAiC;AAGhC,SAAA,SAAA,EAAE,OAAO,CAAA,CAAE;AAQlB,SAAK,SAAS;AACd,SAAK,eAAe;AACf,SAAA,SAAS,OAAO,YAAY;AAAA,MAC/B,QAAQ;AAAA,MACR,OAAO;AAAA,IAAA,CACR;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO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AA,UAAA;AAAA,QACF;AAAA,eAEK,OAAO;AACd,aAAK,OAAO;AAAA,UACV,mDAAmD,cAAc;AAAA,UACjE;AAAA,QACF;AAAA,MAAA;AAKF,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC;AAAA,IAAA;AAG1D,SAAK,OAAO,KAAK,qCAAqC,cAAc,GAAG;AACvE,SAAK,eAAe;AACpB,SAAK,kBAAkB;AAAA,EAAA;AAAA;AAAA,EAIlB,iBAAuB;AAC5B,QAAI,KAAK,cAAc;AACrB,WAAK,OAAO;AAAA,QACV,iCAAiC,KAAK,eAAe;AAAA,MACvD;AACA,WAAK,eAAe;AACpB,WAAK,kBAAkB;AAAA,IAAA,OAClB;AACA,WAAA,OAAO,KAAK,mCAAmC;AAAA,IAAA;AAAA,EACtD;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es5.js","sources":["../../src/tools/hcs10/RegisterAgentTool.ts"],"sourcesContent":["import { AIAgentCapability } from '@hashgraphonline/standards-sdk';\nimport { z } from 'zod';\nimport { BaseServiceBuilder } from 'hedera-agent-kit';\nimport { HCS10Builder, RegisterAgentParams } from '../../builders/hcs10/hcs10-builder';\nimport { BaseHCS10TransactionTool } from './base-hcs10-tools';\nimport { HCS10TransactionToolParams } from './hcs10-tool-params';\n\nconst RegisterAgentZodSchema = z.object({\n name: z\n .string()\n .min(1)\n .max(50)\n .describe('A unique name for the agent (1-50 characters)'),\n description: z\n .string()\n .max(500)\n .optional()\n .describe('Optional bio description for the agent (max 500 characters)'),\n alias: z\n .string()\n .optional()\n .describe('Optional custom username/alias for the agent'),\n type: z\n .enum(['autonomous', 'manual'])\n .optional()\n .describe('Agent type (default: autonomous)'),\n model: z\n .string()\n .optional()\n .describe('AI model identifier (default: agent-model-2024)'),\n capabilities: z\n .array(z.nativeEnum(AIAgentCapability))\n .optional()\n .describe('Array of agent capabilities (default: [TEXT_GENERATION])'),\n creator: z.string().optional().describe('Creator attribution for the agent'),\n socials: z\n .record(\n z.enum([\n 'twitter',\n 'github',\n 'discord',\n 'telegram',\n 'linkedin',\n 'youtube',\n 'website',\n 'x',\n ] as const),\n z.string()\n )\n .optional()\n .describe(\n 'Social media links (e.g., {\"twitter\": \"@handle\", \"discord\": \"username\"})'\n ),\n properties: z\n .record(z.unknown())\n .optional()\n .describe('Custom metadata properties for the agent'),\n profilePicture: z\n .union([\n z.string().describe('URL or local file path to profile picture'),\n z.object({\n url: z.string().optional(),\n path: z.string().optional(),\n filename: z.string().optional(),\n }),\n ])\n .optional()\n .describe(\n 'Optional profile picture as URL, file path, or object with url/path/filename'\n ),\n existingProfilePictureTopicId: z\n .string()\n .optional()\n .describe(\n 'Topic ID of an existing profile picture to reuse (e.g., 0.0.12345)'\n ),\n initialBalance: z\n .number()\n .positive()\n .optional()\n .describe(\n 'Optional initial HBAR balance for the new agent account (will create new account if provided)'\n ),\n userAccountId: z\n .string()\n .optional()\n .describe(\n 'Optional account ID (e.g., 0.0.12345) to use as the agent account instead of creating a new one'\n ),\n hbarFee: z\n .number()\n .positive()\n .optional()\n .describe(\n 'Optional HBAR fee amount to charge per message on the inbound topic'\n ),\n tokenFees: z\n .array(\n z.object({\n amount: z.number().positive(),\n tokenId: z.string(),\n })\n )\n .optional()\n .describe('Optional token fees to charge per message'),\n exemptAccountIds: z\n .array(z.string())\n .optional()\n .describe('Optional account IDs to exempt from fees'),\n setAsCurrent: z\n .boolean()\n .optional()\n .describe('Whether to set as current agent (default: true)'),\n persistence: z\n .object({\n prefix: z.string().optional(),\n })\n .optional()\n .describe('Optional persistence configuration'),\n});\n\nexport class RegisterAgentTool extends BaseHCS10TransactionTool<\n typeof RegisterAgentZodSchema\n> {\n name = 'register_agent';\n description =\n 'Creates and registers the AI agent on the Hedera network. Returns JSON string with agent details (accountId, privateKey, topics) on success. Note: This tool requires multiple transactions and cannot be used in returnBytes mode.';\n specificInputSchema = RegisterAgentZodSchema;\n\n constructor(params: HCS10TransactionToolParams) {\n super(params);\n this.neverScheduleThisTool = true;\n this.requiresMultipleTransactions = true;\n }\n\n protected async callBuilderMethod(\n builder: BaseServiceBuilder,\n specificArgs: z.infer<typeof RegisterAgentZodSchema>\n ): Promise<void> {\n const hcs10Builder = builder as HCS10Builder;\n\n const params: RegisterAgentParams = {\n name: specificArgs.name,\n };\n\n if (specificArgs.description !== undefined) {\n params.bio = specificArgs.description;\n }\n if (specificArgs.alias !== undefined) {\n params.alias = specificArgs.alias;\n }\n if (specificArgs.type !== undefined) {\n params.type = specificArgs.type;\n }\n if (specificArgs.model !== undefined) {\n params.model = specificArgs.model;\n }\n if (specificArgs.capabilities !== undefined) {\n params.capabilities = specificArgs.capabilities;\n }\n if (specificArgs.creator !== undefined) {\n params.creator = specificArgs.creator;\n }\n if (specificArgs.socials !== undefined) {\n params.socials = specificArgs.socials;\n }\n if (specificArgs.properties !== undefined) {\n params.properties = specificArgs.properties;\n }\n if (specificArgs.profilePicture !== undefined) {\n if (typeof specificArgs.profilePicture === 'string') {\n params.profilePicture = specificArgs.profilePicture;\n } else {\n const profilePicObj: {\n url?: string;\n path?: string;\n filename?: string;\n } = {};\n if (specificArgs.profilePicture.url !== undefined) {\n profilePicObj.url = specificArgs.profilePicture.url;\n }\n if (specificArgs.profilePicture.path !== undefined) {\n profilePicObj.path = specificArgs.profilePicture.path;\n }\n if (specificArgs.profilePicture.filename !== undefined) {\n profilePicObj.filename = specificArgs.profilePicture.filename;\n }\n params.profilePicture = profilePicObj;\n }\n }\n if (specificArgs.existingProfilePictureTopicId !== undefined) {\n params.existingProfilePictureTopicId =\n specificArgs.existingProfilePictureTopicId;\n }\n if (specificArgs.userAccountId !== undefined) {\n params.userAccountId = specificArgs.userAccountId;\n }\n if (specificArgs.hbarFee !== undefined) {\n params.hbarFee = specificArgs.hbarFee;\n }\n if (specificArgs.tokenFees !== undefined) {\n params.tokenFees = specificArgs.tokenFees;\n }\n if (specificArgs.exemptAccountIds !== undefined) {\n params.exemptAccountIds = specificArgs.exemptAccountIds;\n }\n if (specificArgs.initialBalance !== undefined) {\n params.initialBalance = specificArgs.initialBalance;\n }\n\n await hcs10Builder.registerAgent(params);\n }\n}"],"names":[],"mappings":";;;AAOA,MAAM,yBAAyB,EAAE,OAAO;AAAA,EACtC,MAAM,EACH,OAAA,EACA,IAAI,CAAC,EACL,IAAI,EAAE,EACN,SAAS,+CAA+C;AAAA,EAC3D,aAAa,EACV,OAAA,EACA,IAAI,GAAG,EACP,SAAA,EACA,SAAS,6DAA6D;AAAA,EACzE,OAAO,EACJ,OAAA,EACA,SAAA,EACA,SAAS,8CAA8C;AAAA,EAC1D,MAAM,EACH,KAAK,CAAC,cAAc,QAAQ,CAAC,EAC7B,SAAA,EACA,SAAS,kCAAkC;AAAA,EAC9C,OAAO,EACJ,OAAA,EACA,SAAA,EACA,SAAS,iDAAiD;AAAA,EAC7D,cAAc,EACX,MAAM,EAAE,WAAW,iBAAiB,CAAC,EACrC,SAAA,EACA,SAAS,0DAA0D;AAAA,EACtE,SAAS,EAAE,OAAA,EAAS,SAAA,EAAW,SAAS,mCAAmC;AAAA,EAC3E,SAAS,EACN;AAAA,IACC,EAAE,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACQ;AAAA,IACV,EAAE,OAAA;AAAA,EAAO,EAEV,WACA;AAAA,IACC;AAAA,EAAA;AAAA,EAEJ,YAAY,EACT,OAAO,EAAE,QAAA,CAAS,EAClB,SAAA,EACA,SAAS,0CAA0C;AAAA,EACtD,gBAAgB,EACb,MAAM;AAAA,IACL,EAAE,OAAA,EAAS,SAAS,2CAA2C;AAAA,IAC/D,EAAE,OAAO;AAAA,MACP,KAAK,EAAE,OAAA,EAAS,SAAA;AAAA,MAChB,MAAM,EAAE,OAAA,EAAS,SAAA;AAAA,MACjB,UAAU,EAAE,OAAA,EAAS,SAAA;AAAA,IAAS,CAC/B;AAAA,EAAA,CACF,EACA,SA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