@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,394 +1,332 @@
|
|
|
1
|
-
import { Logger, AIAgentCapability,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @param client - Instance of HCS10Client (already configured with operator/network)
|
|
12
|
-
* @param stateManager - Optional state manager to store agent details
|
|
13
|
-
*/
|
|
14
|
-
constructor(client, stateManager) {
|
|
15
|
-
super();
|
|
16
|
-
this.name = "register_agent";
|
|
17
|
-
this.description = "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.";
|
|
18
|
-
this.schema = z.object({
|
|
19
|
-
name: z.string().describe("The name of the agent to register"),
|
|
20
|
-
description: z.string().optional().describe("Optional description of the agent"),
|
|
21
|
-
type: z.enum(["autonomous", "manual"]).optional().describe("Optional agent type (default: autonomous)"),
|
|
22
|
-
model: z.string().optional().describe("Optional model identifier for the agent"),
|
|
23
|
-
capabilities: z.array(z.number()).optional().describe(
|
|
24
|
-
"Optional array of AIAgentCapability enum values (0-18). If not provided, defaults to just TEXT_GENERATION (0)"
|
|
25
|
-
),
|
|
26
|
-
profilePicture: z.union([
|
|
27
|
-
z.string().describe("Path to a local image file or URL to an image"),
|
|
28
|
-
z.object({
|
|
29
|
-
url: z.string().describe("URL to an image file"),
|
|
30
|
-
filename: z.string().describe("Filename to use for the image")
|
|
31
|
-
}),
|
|
32
|
-
z.object({
|
|
33
|
-
path: z.string().describe("Path to a local image file"),
|
|
34
|
-
filename: z.string().optional().describe("Optional custom filename")
|
|
35
|
-
})
|
|
36
|
-
]).optional().describe(
|
|
37
|
-
"Optional profile picture for the agent (local file path or URL)"
|
|
38
|
-
),
|
|
39
|
-
feeCollectorAccountId: z.string().optional().describe(
|
|
40
|
-
"The account ID to collect fees. If not specified, the new agent's account ID will be used. Required if any fee is specified."
|
|
41
|
-
),
|
|
42
|
-
hbarFee: z.number().optional().describe(
|
|
43
|
-
"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."
|
|
44
|
-
),
|
|
45
|
-
tokenFee: z.object({
|
|
46
|
-
amount: z.number(),
|
|
47
|
-
tokenId: z.string()
|
|
48
|
-
}).optional().describe(
|
|
49
|
-
'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.'
|
|
50
|
-
),
|
|
51
|
-
hbarFees: z.array(
|
|
52
|
-
z.object({
|
|
53
|
-
amount: z.number(),
|
|
54
|
-
collectorAccount: z.string().optional()
|
|
55
|
-
})
|
|
56
|
-
).optional().describe(
|
|
57
|
-
"Optional: Array of HBAR fees with different collectors. If specified, inboundTopicType will be set to FEE_BASED."
|
|
58
|
-
),
|
|
59
|
-
tokenFees: z.array(
|
|
60
|
-
z.object({
|
|
61
|
-
amount: z.number(),
|
|
62
|
-
tokenId: z.string(),
|
|
63
|
-
collectorAccount: z.string().optional()
|
|
64
|
-
})
|
|
65
|
-
).optional().describe(
|
|
66
|
-
"Optional: Array of token fees with different collectors. If specified, inboundTopicType will be set to FEE_BASED."
|
|
67
|
-
),
|
|
68
|
-
exemptAccountIds: z.array(z.string()).optional().describe(
|
|
69
|
-
"Optional: Array of account IDs to exempt from ALL fees set for this agent."
|
|
70
|
-
),
|
|
71
|
-
setAsCurrent: z.boolean().optional().describe(
|
|
72
|
-
"Optional: Whether to set the newly registered agent as the current active agent in the state manager. Default: true"
|
|
73
|
-
),
|
|
74
|
-
persistence: z.object({
|
|
75
|
-
prefix: z.string().optional()
|
|
76
|
-
}).optional().describe(
|
|
77
|
-
"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."
|
|
78
|
-
)
|
|
1
|
+
import { HCS10Client as HCS10Client$1, Logger, AgentBuilder, AIAgentCapability, InboundTopicType } from "@hashgraphonline/standards-sdk";
|
|
2
|
+
import { encryptMessage } from "./standards-agent-kit.es20.js";
|
|
3
|
+
class HCS10Client {
|
|
4
|
+
constructor(operatorId, operatorPrivateKey, network, options) {
|
|
5
|
+
this.standardClient = new HCS10Client$1({
|
|
6
|
+
network,
|
|
7
|
+
operatorId,
|
|
8
|
+
operatorPrivateKey,
|
|
9
|
+
guardedRegistryBaseUrl: options?.registryUrl,
|
|
10
|
+
logLevel: options?.logLevel
|
|
79
11
|
});
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
* @returns Object containing buffer and filename
|
|
87
|
-
*/
|
|
88
|
-
async loadProfilePicture(profilePicture) {
|
|
89
|
-
const logger = Logger.getInstance({
|
|
90
|
-
level: "debug"
|
|
12
|
+
this.guardedRegistryBaseUrl = options?.registryUrl || "";
|
|
13
|
+
this.useEncryption = options?.useEncryption || false;
|
|
14
|
+
const shouldSilence = process.env.DISABLE_LOGGING === "true";
|
|
15
|
+
this.logger = new Logger({
|
|
16
|
+
level: options?.logLevel || "info",
|
|
17
|
+
silent: shouldSilence
|
|
91
18
|
});
|
|
19
|
+
}
|
|
20
|
+
getOperatorId() {
|
|
21
|
+
const operator = this.standardClient.getClient().operatorAccountId;
|
|
22
|
+
if (!operator) {
|
|
23
|
+
throw new Error("Operator Account ID not configured in standard client.");
|
|
24
|
+
}
|
|
25
|
+
return operator.toString();
|
|
26
|
+
}
|
|
27
|
+
getNetwork() {
|
|
28
|
+
return this.standardClient.getNetwork();
|
|
29
|
+
}
|
|
30
|
+
async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionRequestId, feeConfig) {
|
|
92
31
|
try {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const response = await axios.get(profilePicture, {
|
|
101
|
-
responseType: "arraybuffer"
|
|
102
|
-
});
|
|
103
|
-
const buffer = Buffer.from(response.data);
|
|
104
|
-
const urlPathname = new URL(profilePicture).pathname;
|
|
105
|
-
const filename = path__default.basename(urlPathname) || "profile.png";
|
|
106
|
-
return { buffer, filename };
|
|
107
|
-
} else {
|
|
108
|
-
if (!fs__default.existsSync(profilePicture)) {
|
|
109
|
-
logger.warn(`Profile picture file not found: ${profilePicture}`);
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
logger.info(`Loading profile picture from file: ${profilePicture}`);
|
|
113
|
-
const buffer = fs__default.readFileSync(profilePicture);
|
|
114
|
-
const filename = path__default.basename(profilePicture);
|
|
115
|
-
return { buffer, filename };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if ("url" in profilePicture) {
|
|
119
|
-
logger.info(`Loading profile picture from URL: ${profilePicture.url}`);
|
|
120
|
-
const response = await axios.get(profilePicture.url, {
|
|
121
|
-
responseType: "arraybuffer"
|
|
122
|
-
});
|
|
123
|
-
const buffer = Buffer.from(response.data);
|
|
124
|
-
const filename = profilePicture.filename || "profile.png";
|
|
125
|
-
return { buffer, filename };
|
|
126
|
-
}
|
|
127
|
-
if ("path" in profilePicture) {
|
|
128
|
-
if (!fs__default.existsSync(profilePicture.path)) {
|
|
129
|
-
logger.warn(`Profile picture file not found: ${profilePicture.path}`);
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
logger.info(
|
|
133
|
-
`Loading profile picture from file: ${profilePicture.path}`
|
|
134
|
-
);
|
|
135
|
-
const buffer = fs__default.readFileSync(profilePicture.path);
|
|
136
|
-
const filename = profilePicture.filename || path__default.basename(profilePicture.path);
|
|
137
|
-
return { buffer, filename };
|
|
138
|
-
}
|
|
139
|
-
return null;
|
|
32
|
+
const result = await this.standardClient.handleConnectionRequest(
|
|
33
|
+
inboundTopicId,
|
|
34
|
+
requestingAccountId,
|
|
35
|
+
connectionRequestId,
|
|
36
|
+
feeConfig
|
|
37
|
+
);
|
|
38
|
+
return result;
|
|
140
39
|
} catch (error) {
|
|
141
|
-
logger.error(
|
|
142
|
-
|
|
40
|
+
this.logger.error(
|
|
41
|
+
`Error handling connection request #${connectionRequestId} for topic ${inboundTopicId}:`,
|
|
42
|
+
error
|
|
43
|
+
);
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Failed to handle connection request: ${error instanceof Error ? error.message : String(error)}`
|
|
46
|
+
);
|
|
143
47
|
}
|
|
144
48
|
}
|
|
145
49
|
/**
|
|
146
|
-
*
|
|
147
|
-
* Returns a JSON string with agent details on success, or an error string.
|
|
50
|
+
* Retrieves the profile for a given account ID using the standard SDK.
|
|
148
51
|
*/
|
|
149
|
-
async
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
52
|
+
async getAgentProfile(accountId) {
|
|
53
|
+
return this.standardClient.retrieveProfile(accountId);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Exposes the standard SDK's submitConnectionRequest method.
|
|
57
|
+
*/
|
|
58
|
+
async submitConnectionRequest(inboundTopicId, memo) {
|
|
59
|
+
return this.standardClient.submitConnectionRequest(
|
|
60
|
+
inboundTopicId,
|
|
61
|
+
memo
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Exposes the standard SDK's waitForConnectionConfirmation method.
|
|
66
|
+
*/
|
|
67
|
+
async waitForConnectionConfirmation(outboundTopicId, connectionRequestId, maxAttempts = 60, delayMs = 2e3) {
|
|
68
|
+
return this.standardClient.waitForConnectionConfirmation(
|
|
69
|
+
outboundTopicId,
|
|
70
|
+
connectionRequestId,
|
|
71
|
+
maxAttempts,
|
|
72
|
+
delayMs
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates and registers an agent using the standard SDK's HCS10Client.
|
|
77
|
+
* This handles account creation, key generation, topic setup, and registration.
|
|
78
|
+
*
|
|
79
|
+
* When metadata includes fee configuration:
|
|
80
|
+
* 1. The properties.feeConfig will be passed to the AgentBuilder
|
|
81
|
+
* 2. The properties.inboundTopicType will be set to FEE_BASED
|
|
82
|
+
* 3. The SDK's createAndRegisterAgent will apply the fees to the agent's inbound topic
|
|
83
|
+
*
|
|
84
|
+
* @param metadata - The agent's metadata, potentially including pfpBuffer, pfpFileName,
|
|
85
|
+
* and fee configuration in properties.feeConfig
|
|
86
|
+
* @returns The registration result from the standard SDK, containing accountId, keys, topics etc.
|
|
87
|
+
*/
|
|
88
|
+
async createAndRegisterAgent(metadata) {
|
|
89
|
+
const builder = new AgentBuilder().setName(metadata.name).setBio(metadata.description || "").setCapabilities(
|
|
90
|
+
metadata.capabilities ? metadata.capabilities : [AIAgentCapability.TEXT_GENERATION]
|
|
91
|
+
).setType(metadata.type || "autonomous").setModel(metadata.model || "agent-model-2024").setNetwork(this.getNetwork()).setInboundTopicType(InboundTopicType.PUBLIC);
|
|
92
|
+
if (metadata?.feeConfig) {
|
|
93
|
+
builder.setInboundTopicType(InboundTopicType.FEE_BASED);
|
|
94
|
+
builder.setFeeConfig(metadata.feeConfig);
|
|
178
95
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
96
|
+
if (metadata.pfpBuffer && metadata.pfpFileName) {
|
|
97
|
+
if (metadata.pfpBuffer.byteLength === 0) {
|
|
98
|
+
this.logger.warn(
|
|
99
|
+
"Provided PFP buffer is empty. Skipping profile picture."
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
this.logger.info(
|
|
103
|
+
`Setting profile picture: ${metadata.pfpFileName} (${metadata.pfpBuffer.byteLength} bytes)`
|
|
104
|
+
);
|
|
105
|
+
builder.setProfilePicture(metadata.pfpBuffer, metadata.pfpFileName);
|
|
188
106
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
107
|
+
} else {
|
|
108
|
+
this.logger.warn(
|
|
109
|
+
"Profile picture not provided in metadata. Agent creation might fail if required by the underlying SDK builder."
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (metadata.social) {
|
|
113
|
+
Object.entries(metadata.social).forEach(([platform, handle]) => {
|
|
114
|
+
builder.addSocial(platform, handle);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (metadata.properties) {
|
|
118
|
+
Object.entries(metadata.properties).forEach(([key, value]) => {
|
|
119
|
+
builder.addProperty(key, value);
|
|
192
120
|
});
|
|
193
|
-
try {
|
|
194
|
-
const exemptAccountIds = input.exemptAccountIds?.filter(
|
|
195
|
-
(id) => id !== collectorId && id.startsWith("0.0")
|
|
196
|
-
) || [];
|
|
197
|
-
let updatedFeeConfig = feeConfigBuilder;
|
|
198
|
-
if (hasHbarFee) {
|
|
199
|
-
logger.info(
|
|
200
|
-
`Adding HBAR fee: ${input.hbarFee} HBAR to be collected by ${collectorId}`
|
|
201
|
-
);
|
|
202
|
-
updatedFeeConfig = updatedFeeConfig.addHbarFee(
|
|
203
|
-
input.hbarFee,
|
|
204
|
-
collectorId,
|
|
205
|
-
exemptAccountIds
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
if (hasHbarFees) {
|
|
209
|
-
for (const fee of input.hbarFees) {
|
|
210
|
-
const feeCollector = fee.collectorAccount || collectorId;
|
|
211
|
-
logger.info(
|
|
212
|
-
`Adding HBAR fee: ${fee.amount} HBAR to be collected by ${feeCollector}`
|
|
213
|
-
);
|
|
214
|
-
updatedFeeConfig = updatedFeeConfig.addHbarFee(
|
|
215
|
-
fee.amount,
|
|
216
|
-
feeCollector,
|
|
217
|
-
exemptAccountIds
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (hasTokenFee) {
|
|
222
|
-
logger.info(
|
|
223
|
-
`Adding token fee: ${input.tokenFee.amount} of token ${input.tokenFee.tokenId} to be collected by ${collectorId}`
|
|
224
|
-
);
|
|
225
|
-
updatedFeeConfig = await updatedFeeConfig.addTokenFee(
|
|
226
|
-
input.tokenFee.amount,
|
|
227
|
-
input.tokenFee.tokenId,
|
|
228
|
-
collectorId,
|
|
229
|
-
void 0,
|
|
230
|
-
exemptAccountIds
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
if (hasTokenFees) {
|
|
234
|
-
for (const fee of input.tokenFees) {
|
|
235
|
-
const feeCollector = fee.collectorAccount || collectorId;
|
|
236
|
-
logger.info(
|
|
237
|
-
`Adding token fee: ${fee.amount} of token ${fee.tokenId} to be collected by ${feeCollector}`
|
|
238
|
-
);
|
|
239
|
-
updatedFeeConfig = await updatedFeeConfig.addTokenFee(
|
|
240
|
-
fee.amount,
|
|
241
|
-
fee.tokenId,
|
|
242
|
-
feeCollector,
|
|
243
|
-
void 0,
|
|
244
|
-
exemptAccountIds
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
metadata.feeConfig = updatedFeeConfig;
|
|
249
|
-
logger.info("FeeConfigBuilder created successfully");
|
|
250
|
-
} catch (error) {
|
|
251
|
-
return `Error: Failed to configure fees. Reason: ${error instanceof Error ? error.message : String(error)}`;
|
|
252
|
-
}
|
|
253
121
|
}
|
|
254
122
|
try {
|
|
255
|
-
|
|
256
|
-
const result = await this.
|
|
257
|
-
|
|
123
|
+
const hasFees = Boolean(metadata?.feeConfig);
|
|
124
|
+
const result = await this.standardClient.createAndRegisterAgent(builder, {
|
|
125
|
+
initialBalance: hasFees ? 50 : void 0
|
|
126
|
+
});
|
|
127
|
+
if (result?.metadata?.inboundTopicId && result?.metadata?.outboundTopicId) {
|
|
128
|
+
this.agentChannels = {
|
|
129
|
+
inboundTopicId: result.metadata.inboundTopicId,
|
|
130
|
+
outboundTopicId: result.metadata.outboundTopicId
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
this.logger.error("Error during agent creation/registration:", error);
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Failed to create/register agent: ${error instanceof Error ? error.message : String(error)}`
|
|
258
138
|
);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Sends a structured HCS-10 message to the specified topic using the standard SDK client.
|
|
143
|
+
* Handles potential inscription for large messages.
|
|
144
|
+
*
|
|
145
|
+
* @param topicId - The target topic ID (likely a connection topic).
|
|
146
|
+
* @param operatorId - The operator ID string (e.g., "inboundTopic@accountId").
|
|
147
|
+
* @param data - The actual message content/data.
|
|
148
|
+
* @param memo - Optional memo for the message.
|
|
149
|
+
* @param submitKey - Optional private key for topics requiring specific submit keys.
|
|
150
|
+
* @returns A confirmation status string from the transaction receipt.
|
|
151
|
+
*/
|
|
152
|
+
async sendMessage(topicId, data, memo, submitKey) {
|
|
153
|
+
if (this.useEncryption) {
|
|
154
|
+
data = encryptMessage(data);
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const messageResponse = await this.standardClient.sendMessage(
|
|
158
|
+
topicId,
|
|
159
|
+
data,
|
|
160
|
+
memo,
|
|
161
|
+
submitKey
|
|
263
162
|
);
|
|
163
|
+
return messageResponse.topicSequenceNumber?.toNumber();
|
|
264
164
|
} catch (error) {
|
|
265
|
-
|
|
165
|
+
this.logger.error(`Error sending message to topic ${topicId}:`, error);
|
|
166
|
+
throw new Error(
|
|
167
|
+
`Failed to send message: ${error instanceof Error ? error.message : String(error)}`
|
|
168
|
+
);
|
|
266
169
|
}
|
|
267
170
|
}
|
|
268
171
|
/**
|
|
269
|
-
*
|
|
172
|
+
* Retrieves messages from a topic using the standard SDK client.
|
|
173
|
+
*
|
|
174
|
+
* @param topicId - The topic ID to get messages from.
|
|
175
|
+
* @returns Messages from the topic, mapped to the expected format.
|
|
270
176
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
177
|
+
async getMessages(topicId) {
|
|
178
|
+
try {
|
|
179
|
+
const result = await this.standardClient.getMessages(topicId);
|
|
180
|
+
const mappedMessages = result.messages.map((sdkMessage) => {
|
|
181
|
+
const timestamp = sdkMessage?.created?.getTime() || 0;
|
|
182
|
+
return {
|
|
183
|
+
...sdkMessage,
|
|
184
|
+
timestamp,
|
|
185
|
+
data: sdkMessage.data,
|
|
186
|
+
sequence_number: sdkMessage.sequence_number
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
mappedMessages.sort(
|
|
190
|
+
(a, b) => a.timestamp - b.timestamp
|
|
191
|
+
);
|
|
192
|
+
return { messages: mappedMessages };
|
|
193
|
+
} catch (error) {
|
|
194
|
+
this.logger.error(`Error getting messages from topic ${topicId}:`, error);
|
|
195
|
+
return { messages: [] };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async getMessageStream(topicId) {
|
|
199
|
+
const result = this.standardClient.getMessageStream(topicId);
|
|
200
|
+
return result;
|
|
273
201
|
}
|
|
274
202
|
/**
|
|
275
|
-
*
|
|
203
|
+
* Retrieves content from an inscribed message using the standard SDK client.
|
|
204
|
+
* @param inscriptionIdOrData - The inscription ID (hcs://...) or potentially raw data string.
|
|
205
|
+
* @returns The resolved message content.
|
|
276
206
|
*/
|
|
277
|
-
async
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const agent = {
|
|
292
|
-
name: input.name,
|
|
293
|
-
accountId: newAgentAccountId,
|
|
294
|
-
inboundTopicId,
|
|
295
|
-
outboundTopicId,
|
|
296
|
-
profileTopicId,
|
|
297
|
-
privateKey,
|
|
298
|
-
pfpTopicId
|
|
299
|
-
};
|
|
300
|
-
this.stateManager.setCurrentAgent(agent);
|
|
301
|
-
if (this.stateManager.persistAgentData && input.persistence) {
|
|
302
|
-
try {
|
|
303
|
-
const persistenceOptions = {
|
|
304
|
-
type: "env-file",
|
|
305
|
-
prefix: input.persistence.prefix
|
|
306
|
-
};
|
|
307
|
-
await this.stateManager.persistAgentData(agent, persistenceOptions);
|
|
308
|
-
} catch (error) {
|
|
309
|
-
Logger.getInstance().warn("Failed to persist agent data", error);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
await this.ensureAgentHasFunds(newAgentAccountId, input.name);
|
|
314
|
-
const feeDescription = this.createFeeDescription(input);
|
|
315
|
-
const feeMessage = feeDescription ? ` with ${feeDescription} fee on inbound topic` : "";
|
|
316
|
-
const registrationDetails = {
|
|
317
|
-
success: true,
|
|
318
|
-
message: `Successfully registered agent '${input.name}'${feeMessage}.`,
|
|
319
|
-
name: input.name,
|
|
320
|
-
accountId: newAgentAccountId,
|
|
321
|
-
privateKey,
|
|
322
|
-
inboundTopicId,
|
|
323
|
-
outboundTopicId,
|
|
324
|
-
profileTopicId: profileTopicId || "N/A",
|
|
325
|
-
capabilities: input.capabilities || [AIAgentCapability.TEXT_GENERATION],
|
|
326
|
-
hasFees: !!(input.hbarFee || this.hasValidTokenFee(input.tokenFee)),
|
|
327
|
-
hbarFee: input.hbarFee || 0,
|
|
328
|
-
tokenFee: input.tokenFee || null
|
|
329
|
-
};
|
|
330
|
-
if (pfpTopicId || profilePictureSource) {
|
|
331
|
-
registrationDetails.profilePicture = {
|
|
332
|
-
source: profilePictureSource,
|
|
333
|
-
topicId: pfpTopicId
|
|
334
|
-
};
|
|
207
|
+
async getMessageContent(inscriptionIdOrData) {
|
|
208
|
+
try {
|
|
209
|
+
const content = await this.standardClient.getMessageContent(
|
|
210
|
+
inscriptionIdOrData
|
|
211
|
+
);
|
|
212
|
+
return content;
|
|
213
|
+
} catch (error) {
|
|
214
|
+
this.logger.error(
|
|
215
|
+
`Error retrieving message content for: ${inscriptionIdOrData}`,
|
|
216
|
+
error
|
|
217
|
+
);
|
|
218
|
+
throw new Error(
|
|
219
|
+
`Failed to retrieve message content: ${error instanceof Error ? error.message : String(error)}`
|
|
220
|
+
);
|
|
335
221
|
}
|
|
336
|
-
return JSON.stringify(registrationDetails);
|
|
337
222
|
}
|
|
338
223
|
/**
|
|
339
|
-
*
|
|
224
|
+
* Retrieves the inbound topic ID associated with the current operator.
|
|
225
|
+
* This typically involves fetching the operator's own HCS-10 profile.
|
|
226
|
+
* @returns A promise that resolves to the operator's inbound topic ID.
|
|
227
|
+
* @throws {Error} If the operator ID cannot be determined or the profile/topic cannot be retrieved.
|
|
340
228
|
*/
|
|
341
|
-
async
|
|
229
|
+
async getInboundTopicId() {
|
|
342
230
|
try {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}),
|
|
347
|
-
this.client.standardClient,
|
|
348
|
-
accountId,
|
|
349
|
-
agentName
|
|
231
|
+
const operatorId = this.getOperatorId();
|
|
232
|
+
this.logger.info(
|
|
233
|
+
`[HCS10Client] Retrieving profile for operator ${operatorId} to find inbound topic...`
|
|
350
234
|
);
|
|
235
|
+
const profileResponse = await this.getAgentProfile(operatorId);
|
|
236
|
+
if (profileResponse.success && profileResponse.topicInfo?.inboundTopic) {
|
|
237
|
+
this.logger.info(
|
|
238
|
+
`[HCS10Client] Found inbound topic for operator ${operatorId}: ${profileResponse.topicInfo.inboundTopic}`
|
|
239
|
+
);
|
|
240
|
+
return profileResponse.topicInfo.inboundTopic;
|
|
241
|
+
} else {
|
|
242
|
+
throw new Error(
|
|
243
|
+
`Could not retrieve inbound topic from profile for ${operatorId}. Profile success: ${profileResponse.success}, Error: ${profileResponse.error}`
|
|
244
|
+
);
|
|
245
|
+
}
|
|
351
246
|
} catch (error) {
|
|
352
|
-
|
|
247
|
+
this.logger.error(
|
|
248
|
+
`[HCS10Client] Error fetching operator's inbound topic ID (${this.getOperatorId()}):`,
|
|
249
|
+
error
|
|
250
|
+
);
|
|
251
|
+
const operatorId = this.getOperatorId();
|
|
252
|
+
let detailedMessage = `Failed to get inbound topic ID for operator ${operatorId}.`;
|
|
253
|
+
if (error instanceof Error && error.message.includes("does not have a valid HCS-11 memo")) {
|
|
254
|
+
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).`;
|
|
255
|
+
} else if (error instanceof Error) {
|
|
256
|
+
detailedMessage += ` Reason: ${error.message}`;
|
|
257
|
+
} else {
|
|
258
|
+
detailedMessage += ` Unexpected error: ${String(error)}`;
|
|
259
|
+
}
|
|
260
|
+
throw new Error(detailedMessage);
|
|
353
261
|
}
|
|
354
262
|
}
|
|
355
263
|
/**
|
|
356
|
-
*
|
|
264
|
+
* Retrieves the configured operator account ID and private key.
|
|
265
|
+
* Required by tools needing to identify the current agent instance.
|
|
266
|
+
*/
|
|
267
|
+
getAccountAndSigner() {
|
|
268
|
+
const result = this.standardClient.getAccountAndSigner();
|
|
269
|
+
return {
|
|
270
|
+
accountId: result.accountId,
|
|
271
|
+
signer: result.signer
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Retrieves the outbound topic ID for the current operator.
|
|
276
|
+
* Fetches the operator's profile if necessary.
|
|
277
|
+
* @returns The outbound topic ID string.
|
|
278
|
+
* @throws If the outbound topic cannot be determined.
|
|
357
279
|
*/
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
!privateKey && "privateKey"
|
|
365
|
-
].filter(Boolean).join(", ");
|
|
280
|
+
async getOutboundTopicId() {
|
|
281
|
+
const operatorId = this.getOperatorId();
|
|
282
|
+
const profile = await this.getAgentProfile(operatorId);
|
|
283
|
+
if (profile.success && profile.topicInfo?.outboundTopic) {
|
|
284
|
+
return profile.topicInfo.outboundTopic;
|
|
285
|
+
} else {
|
|
366
286
|
throw new Error(
|
|
367
|
-
`
|
|
287
|
+
`Could not retrieve outbound topic from profile for ${operatorId}. Profile success: ${profile.success}, Error: ${profile.error}`
|
|
368
288
|
);
|
|
369
289
|
}
|
|
370
290
|
}
|
|
291
|
+
setClient(accountId, privateKey) {
|
|
292
|
+
this.standardClient = new HCS10Client$1({
|
|
293
|
+
network: this.getNetwork(),
|
|
294
|
+
operatorId: accountId,
|
|
295
|
+
operatorPrivateKey: privateKey,
|
|
296
|
+
guardedRegistryBaseUrl: this.guardedRegistryBaseUrl
|
|
297
|
+
});
|
|
298
|
+
return this.standardClient;
|
|
299
|
+
}
|
|
371
300
|
/**
|
|
372
|
-
*
|
|
301
|
+
* Validates that the operator account exists and has proper access for agent operations
|
|
373
302
|
*/
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
return
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
303
|
+
async validateOperator(options) {
|
|
304
|
+
try {
|
|
305
|
+
this.setClient(options.accountId, options.privateKey);
|
|
306
|
+
const operatorId = this.getOperatorId();
|
|
307
|
+
return {
|
|
308
|
+
isValid: true,
|
|
309
|
+
operator: { accountId: operatorId }
|
|
310
|
+
};
|
|
311
|
+
} catch (error) {
|
|
312
|
+
this.logger.error(`Validation error: ${error}`);
|
|
313
|
+
return {
|
|
314
|
+
isValid: false,
|
|
315
|
+
error: error instanceof Error ? error.message : String(error)
|
|
316
|
+
};
|
|
383
317
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
318
|
+
}
|
|
319
|
+
async initializeWithValidation(options) {
|
|
320
|
+
const validationResult = await this.validateOperator(options);
|
|
321
|
+
if (validationResult.isValid) {
|
|
322
|
+
if (options.stateManager) {
|
|
323
|
+
options.stateManager.initializeConnectionsManager(this.standardClient);
|
|
324
|
+
}
|
|
387
325
|
}
|
|
388
|
-
return
|
|
326
|
+
return validationResult;
|
|
389
327
|
}
|
|
390
328
|
}
|
|
391
329
|
export {
|
|
392
|
-
|
|
330
|
+
HCS10Client
|
|
393
331
|
};
|
|
394
332
|
//# sourceMappingURL=standards-agent-kit.es3.js.map
|