@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,200 +1,32 @@
|
|
|
1
|
-
import { StructuredTool } from "@langchain/core/tools";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { BaseHCS10QueryTool } from "./standards-agent-kit.es4.js";
|
|
3
|
+
const ManageConnectionRequestsZodSchema = z.object({
|
|
4
|
+
action: z.enum(["list", "view", "reject"]).describe(
|
|
5
|
+
"The action to perform: list all requests, view details of a specific request, or reject a request"
|
|
6
|
+
),
|
|
7
|
+
requestKey: z.string().optional().describe(
|
|
8
|
+
"The unique request key to view or reject (required for view and reject actions)"
|
|
9
|
+
)
|
|
10
|
+
});
|
|
11
|
+
class ManageConnectionRequestsTool extends BaseHCS10QueryTool {
|
|
12
|
+
constructor(params) {
|
|
13
|
+
super(params);
|
|
11
14
|
this.name = "manage_connection_requests";
|
|
12
15
|
this.description = 'Manage incoming connection requests. List pending requests, view details about requesting agents, and reject connection requests. Use the separate "accept_connection_request" tool to accept.';
|
|
13
|
-
this.
|
|
14
|
-
action: z.enum(["list", "view", "reject"]).describe(
|
|
15
|
-
"The action to perform: list all requests, view details of a specific request, or reject a request"
|
|
16
|
-
),
|
|
17
|
-
requestKey: z.string().optional().describe(
|
|
18
|
-
"The unique request key to view or reject (required for view and reject actions)"
|
|
19
|
-
)
|
|
20
|
-
});
|
|
21
|
-
this.lastRefreshTime = 0;
|
|
22
|
-
this.refreshIntervalMs = 3e4;
|
|
23
|
-
this.hcsClient = hcsClient;
|
|
24
|
-
this.stateManager = stateManager;
|
|
25
|
-
this.logger = Logger.getInstance({
|
|
26
|
-
module: "ManageConnectionRequestsTool",
|
|
27
|
-
level: "debug"
|
|
28
|
-
});
|
|
16
|
+
this.specificInputSchema = ManageConnectionRequestsZodSchema;
|
|
29
17
|
}
|
|
30
|
-
async
|
|
18
|
+
async executeQuery({
|
|
31
19
|
action,
|
|
32
20
|
requestKey
|
|
33
21
|
}) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await this.refreshRequestsIfNeeded();
|
|
43
|
-
switch (action) {
|
|
44
|
-
case "list":
|
|
45
|
-
return this.listRequests();
|
|
46
|
-
case "view":
|
|
47
|
-
return this.viewRequest(requestKey);
|
|
48
|
-
case "reject":
|
|
49
|
-
return this.rejectRequest(requestKey);
|
|
50
|
-
default:
|
|
51
|
-
return `Error: Unsupported action: ${action}`;
|
|
52
|
-
}
|
|
53
|
-
} catch (error) {
|
|
54
|
-
this.logger.error(`Error in ManageConnectionRequestsTool: ${error}`);
|
|
55
|
-
return `Error managing connection requests: ${error instanceof Error ? error.message : String(error)}`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async refreshRequestsIfNeeded() {
|
|
59
|
-
const now = Date.now();
|
|
60
|
-
if (now - this.lastRefreshTime > this.refreshIntervalMs) {
|
|
61
|
-
await this.refreshRequests();
|
|
62
|
-
this.lastRefreshTime = now;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async refreshRequests() {
|
|
66
|
-
try {
|
|
67
|
-
const { accountId } = this.hcsClient.getAccountAndSigner();
|
|
68
|
-
if (!accountId) {
|
|
69
|
-
throw new Error("Could not determine account ID for current agent");
|
|
70
|
-
}
|
|
71
|
-
const connectionManager = this.stateManager.getConnectionsManager();
|
|
72
|
-
if (!connectionManager) {
|
|
73
|
-
throw new Error("ConnectionsManager not initialized");
|
|
74
|
-
}
|
|
75
|
-
await connectionManager.fetchConnectionData(accountId);
|
|
76
|
-
} catch (error) {
|
|
77
|
-
this.logger.error(`Error refreshing connection requests: ${error}`);
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
listRequests() {
|
|
82
|
-
const connectionsManager = this.stateManager.getConnectionsManager();
|
|
83
|
-
if (!connectionsManager) {
|
|
84
|
-
return "Error: ConnectionsManager not initialized";
|
|
85
|
-
}
|
|
86
|
-
const pendingRequests = connectionsManager.getPendingRequests();
|
|
87
|
-
const needsConfirmation = connectionsManager.getConnectionsNeedingConfirmation();
|
|
88
|
-
const allRequests = [...pendingRequests, ...needsConfirmation];
|
|
89
|
-
if (allRequests.length === 0) {
|
|
90
|
-
console.log("No pending connection requests found.", allRequests);
|
|
91
|
-
return "No pending connection requests found.";
|
|
92
|
-
}
|
|
93
|
-
let output = `Found ${allRequests.length} pending connection request(s):
|
|
94
|
-
|
|
95
|
-
`;
|
|
96
|
-
const sortedRequests = [...allRequests].sort(
|
|
97
|
-
(a, b) => b.created.getTime() - a.created.getTime()
|
|
98
|
-
);
|
|
99
|
-
sortedRequests.forEach((request, index) => {
|
|
100
|
-
const requestType = request.needsConfirmation ? "🟠 Incoming" : "⚪️ Outgoing";
|
|
101
|
-
const requestIdDisplay = request.uniqueRequestKey || `${request.connectionRequestId || request.inboundRequestId || "unknown"}`;
|
|
102
|
-
output += `${index + 1}. ${requestType} - Key: ${requestIdDisplay}
|
|
103
|
-
`;
|
|
104
|
-
output += ` ${request.needsConfirmation ? "From" : "To"}: ${request.targetAgentName || `Agent ${request.targetAccountId}`} (${request.targetAccountId})
|
|
105
|
-
`;
|
|
106
|
-
output += ` Sent/Rcvd: ${request.created.toLocaleString()}
|
|
107
|
-
`;
|
|
108
|
-
if (request.memo) {
|
|
109
|
-
output += ` Memo: ${request.memo}
|
|
110
|
-
`;
|
|
111
|
-
}
|
|
112
|
-
if (request.profileInfo && request.profileInfo.bio) {
|
|
113
|
-
output += ` Bio: ${request.profileInfo.bio}
|
|
114
|
-
`;
|
|
115
|
-
}
|
|
116
|
-
output += "\n";
|
|
117
|
-
});
|
|
118
|
-
output += 'To view more details about a request, use action="view" with the specific requestKey.\n';
|
|
119
|
-
output += 'To reject a request, use action="reject" with the specific requestKey.';
|
|
120
|
-
return output;
|
|
121
|
-
}
|
|
122
|
-
viewRequest(requestKey) {
|
|
123
|
-
const connectionsManager = this.stateManager.getConnectionsManager();
|
|
124
|
-
if (!connectionsManager) {
|
|
125
|
-
return "Error: ConnectionsManager not initialized";
|
|
126
|
-
}
|
|
127
|
-
const pendingRequests = connectionsManager.getPendingRequests();
|
|
128
|
-
const needsConfirmation = connectionsManager.getConnectionsNeedingConfirmation();
|
|
129
|
-
const allRequests = [...pendingRequests, ...needsConfirmation];
|
|
130
|
-
const request = allRequests.find(
|
|
131
|
-
(r) => r.uniqueRequestKey === requestKey || r.connectionRequestId?.toString() === requestKey || r.inboundRequestId?.toString() === requestKey
|
|
132
|
-
);
|
|
133
|
-
if (!request) {
|
|
134
|
-
return `Error: Request with key ${requestKey} not found or no longer pending.`;
|
|
135
|
-
}
|
|
136
|
-
const requestType = request.needsConfirmation ? "Incoming" : "Outgoing";
|
|
137
|
-
const uniqueKey = request.uniqueRequestKey || `${request.connectionRequestId || request.inboundRequestId || "unknown"}`;
|
|
138
|
-
let output = `Details for ${requestType} connection request: ${uniqueKey}
|
|
139
|
-
|
|
140
|
-
`;
|
|
141
|
-
output += `${request.needsConfirmation ? "Requestor" : "Target"} ID: ${request.targetAccountId}
|
|
142
|
-
`;
|
|
143
|
-
output += `${request.needsConfirmation ? "Requestor" : "Target"} Name: ${request.targetAgentName || `Agent ${request.targetAccountId}`}
|
|
144
|
-
`;
|
|
145
|
-
output += `Received: ${request.created.toLocaleString()}
|
|
146
|
-
`;
|
|
147
|
-
if (request.memo) {
|
|
148
|
-
output += `Memo: ${request.memo}
|
|
149
|
-
`;
|
|
150
|
-
}
|
|
151
|
-
if (request.profileInfo) {
|
|
152
|
-
output += "\nAgent Profile Information:\n";
|
|
153
|
-
if (request.profileInfo.display_name || request.profileInfo.alias) {
|
|
154
|
-
output += `Name: ${request.profileInfo.display_name || request.profileInfo.alias}
|
|
155
|
-
`;
|
|
156
|
-
}
|
|
157
|
-
if (request.profileInfo.type !== void 0) {
|
|
158
|
-
output += `Type: ${request.profileInfo.type}
|
|
159
|
-
`;
|
|
160
|
-
}
|
|
161
|
-
if (request.profileInfo.bio) {
|
|
162
|
-
output += `Bio: ${request.profileInfo.bio}
|
|
163
|
-
`;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
output += "\nActions:\n";
|
|
167
|
-
output += `- To reject this request: action="reject", requestKey="${uniqueKey}"
|
|
168
|
-
`;
|
|
169
|
-
output += 'Use the separate "accept_connection_request" tool to accept requests.';
|
|
170
|
-
return output;
|
|
171
|
-
}
|
|
172
|
-
async rejectRequest(requestKey) {
|
|
173
|
-
const connectionsManager = this.stateManager.getConnectionsManager();
|
|
174
|
-
if (!connectionsManager) {
|
|
175
|
-
return "Error: ConnectionsManager not initialized";
|
|
176
|
-
}
|
|
177
|
-
const pendingRequests = connectionsManager.getPendingRequests();
|
|
178
|
-
const needsConfirmation = connectionsManager.getConnectionsNeedingConfirmation();
|
|
179
|
-
const allRequests = [...pendingRequests, ...needsConfirmation];
|
|
180
|
-
const request = allRequests.find(
|
|
181
|
-
(r) => r.uniqueRequestKey === requestKey || r.connectionRequestId?.toString() === requestKey || r.inboundRequestId?.toString() === requestKey
|
|
182
|
-
);
|
|
183
|
-
if (!request) {
|
|
184
|
-
return `Error: Request with key ${requestKey} not found or no longer pending.`;
|
|
185
|
-
}
|
|
186
|
-
if (request.inboundRequestId) {
|
|
187
|
-
connectionsManager.markConnectionRequestProcessed(
|
|
188
|
-
request.targetInboundTopicId || "",
|
|
189
|
-
request.inboundRequestId
|
|
190
|
-
);
|
|
191
|
-
} else if (request.connectionRequestId) {
|
|
192
|
-
connectionsManager.markConnectionRequestProcessed(
|
|
193
|
-
request.originTopicId || "",
|
|
194
|
-
request.connectionRequestId
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
return `Connection request from ${request.targetAgentName || `Agent ${request.targetAccountId}`} was rejected.`;
|
|
22
|
+
const hcs10Builder = this.hcs10Builder;
|
|
23
|
+
const params = { action };
|
|
24
|
+
if (requestKey !== void 0) {
|
|
25
|
+
params.requestKey = requestKey;
|
|
26
|
+
}
|
|
27
|
+
await hcs10Builder.manageConnectionRequests(params);
|
|
28
|
+
const result = await hcs10Builder.execute();
|
|
29
|
+
return "rawResult" in result ? result.rawResult : result;
|
|
198
30
|
}
|
|
199
31
|
}
|
|
200
32
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es12.js","sources":["../../src/tools/ManageConnectionRequestsTool.ts"],"sourcesContent":["import { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { HCS10Client } from '../hcs10/HCS10Client';\nimport { IStateManager } from '../state/state-types';\nimport { Logger } from '@hashgraphonline/standards-sdk';\n\nexport interface ManageConnectionRequestsToolParams extends ToolParams {\n hcsClient: HCS10Client;\n stateManager: IStateManager;\n}\n\n/**\n * A tool for managing incoming connection requests in a LangChain-compatible way.\n * This tool allows an agent to list, view details of, and accept/reject incoming connection requests.\n */\nexport class ManageConnectionRequestsTool extends StructuredTool {\n name = 'manage_connection_requests';\n description =\n 'Manage incoming connection requests. List pending requests, view details about requesting agents, and reject connection requests. Use the separate \"accept_connection_request\" tool to accept.';\n schema = z.object({\n action: z\n .enum(['list', 'view', 'reject'])\n .describe(\n 'The action to perform: list all requests, view details of a specific request, or reject a request'\n ),\n requestKey: z\n .string()\n .optional()\n .describe(\n 'The unique request key to view or reject (required for view and reject actions)'\n ),\n });\n\n private hcsClient: HCS10Client;\n private stateManager: IStateManager;\n private logger: Logger;\n private lastRefreshTime: number = 0;\n private refreshIntervalMs = 30000;\n\n constructor({\n hcsClient,\n stateManager,\n ...rest\n }: ManageConnectionRequestsToolParams) {\n super(rest);\n this.hcsClient = hcsClient;\n this.stateManager = stateManager;\n this.logger = Logger.getInstance({\n module: 'ManageConnectionRequestsTool',\n level: 'debug',\n });\n }\n\n protected async _call({\n action,\n requestKey,\n }: z.infer<this['schema']>): Promise<string> {\n const currentAgent = this.stateManager.getCurrentAgent();\n if (!currentAgent) {\n return 'Error: Cannot manage connection requests. No agent is currently active. Please register or select an agent first.';\n }\n\n if ((action === 'view' || action === 'reject') && requestKey === undefined) {\n return `Error: Request key is required for the \"${action}\" action. Use the \"list\" action first to see available requests.`;\n }\n\n try {\n await this.refreshRequestsIfNeeded();\n\n switch (action) {\n case 'list':\n return this.listRequests();\n case 'view':\n return this.viewRequest(requestKey!);\n case 'reject':\n return this.rejectRequest(requestKey!);\n default:\n return `Error: Unsupported action: ${action}`;\n }\n } catch (error) {\n this.logger.error(`Error in ManageConnectionRequestsTool: ${error}`);\n return `Error managing connection requests: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n\n private async refreshRequestsIfNeeded(): Promise<void> {\n const now = Date.now();\n if (now - this.lastRefreshTime > this.refreshIntervalMs) {\n await this.refreshRequests();\n this.lastRefreshTime = now;\n }\n }\n\n private async refreshRequests(): Promise<void> {\n try {\n const { accountId } = this.hcsClient.getAccountAndSigner();\n if (!accountId) {\n throw new Error('Could not determine account ID for current agent');\n }\n\n const connectionManager = this.stateManager.getConnectionsManager();\n if (!connectionManager) {\n throw new Error('ConnectionsManager not initialized');\n }\n\n await connectionManager.fetchConnectionData(accountId);\n } catch (error) {\n this.logger.error(`Error refreshing connection requests: ${error}`);\n throw error;\n }\n }\n\n private listRequests(): string {\n const connectionsManager = this.stateManager.getConnectionsManager();\n if (!connectionsManager) {\n return 'Error: ConnectionsManager not initialized';\n }\n\n const pendingRequests = connectionsManager.getPendingRequests();\n const needsConfirmation =\n connectionsManager.getConnectionsNeedingConfirmation();\n\n const allRequests = [...pendingRequests, ...needsConfirmation];\n\n if (allRequests.length === 0) {\n console.log('No pending connection requests found.', allRequests);\n return 'No pending connection requests found.';\n }\n\n let output = `Found ${allRequests.length} pending connection request(s):\\n\\n`;\n const sortedRequests = [...allRequests].sort(\n (a, b) => b.created.getTime() - a.created.getTime()\n );\n\n sortedRequests.forEach((request, index) => {\n // Create a display ID for the connection request\n const requestType = request.needsConfirmation ? '🟠 Incoming' : '⚪️ Outgoing';\n const requestIdDisplay = request.uniqueRequestKey ||\n `${request.connectionRequestId || request.inboundRequestId || 'unknown'}`;\n\n output += `${index + 1}. ${requestType} - Key: ${requestIdDisplay}\\n`;\n output += ` ${request.needsConfirmation ? 'From' : 'To'}: ${\n request.targetAgentName || `Agent ${request.targetAccountId}`\n } (${request.targetAccountId})\\n`;\n output += ` Sent/Rcvd: ${request.created.toLocaleString()}\\n`;\n\n if (request.memo) {\n output += ` Memo: ${request.memo}\\n`;\n }\n\n if (request.profileInfo && request.profileInfo.bio) {\n output += ` Bio: ${request.profileInfo.bio}\\n`;\n }\n\n output += '\\n';\n });\n\n output +=\n 'To view more details about a request, use action=\"view\" with the specific requestKey.\\n';\n output +=\n 'To reject a request, use action=\"reject\" with the specific requestKey.';\n return output;\n }\n\n private viewRequest(requestKey: string): string {\n const connectionsManager = this.stateManager.getConnectionsManager();\n if (!connectionsManager) {\n return 'Error: ConnectionsManager not initialized';\n }\n\n const pendingRequests = connectionsManager.getPendingRequests();\n const needsConfirmation =\n connectionsManager.getConnectionsNeedingConfirmation();\n\n const allRequests = [...pendingRequests, ...needsConfirmation];\n\n // Find the request with the matching unique key or fallback to sequence number\n const request = allRequests.find(\n (r) =>\n (r.uniqueRequestKey === requestKey) ||\n (r.connectionRequestId?.toString() === requestKey) ||\n (r.inboundRequestId?.toString() === requestKey)\n );\n\n if (!request) {\n return `Error: Request with key ${requestKey} not found or no longer pending.`;\n }\n\n // Create a display ID for the connection request\n const requestType = request.needsConfirmation ? 'Incoming' : 'Outgoing';\n const uniqueKey = request.uniqueRequestKey ||\n `${request.connectionRequestId || request.inboundRequestId || 'unknown'}`;\n\n let output = `Details for ${requestType} connection request: ${uniqueKey}\\n\\n`;\n output += `${request.needsConfirmation ? 'Requestor' : 'Target'} ID: ${request.targetAccountId}\\n`;\n output += `${request.needsConfirmation ? 'Requestor' : 'Target'} Name: ${\n request.targetAgentName || `Agent ${request.targetAccountId}`\n }\\n`;\n output += `Received: ${request.created.toLocaleString()}\\n`;\n\n if (request.memo) {\n output += `Memo: ${request.memo}\\n`;\n }\n\n if (request.profileInfo) {\n output += '\\nAgent Profile Information:\\n';\n\n if (request.profileInfo.display_name || request.profileInfo.alias) {\n output += `Name: ${\n request.profileInfo.display_name || request.profileInfo.alias\n }\\n`;\n }\n\n if (request.profileInfo.type !== undefined) {\n output += `Type: ${request.profileInfo.type}\\n`;\n }\n\n if (request.profileInfo.bio) {\n output += `Bio: ${request.profileInfo.bio}\\n`;\n }\n }\n\n output += '\\nActions:\\n';\n output += `- To reject this request: action=\"reject\", requestKey=\"${uniqueKey}\"\\n`;\n output +=\n 'Use the separate \"accept_connection_request\" tool to accept requests.';\n return output;\n }\n\n private async rejectRequest(requestKey: string): Promise<string> {\n const connectionsManager = this.stateManager.getConnectionsManager();\n if (!connectionsManager) {\n return 'Error: ConnectionsManager not initialized';\n }\n\n const pendingRequests = connectionsManager.getPendingRequests();\n const needsConfirmation =\n connectionsManager.getConnectionsNeedingConfirmation();\n\n const allRequests = [...pendingRequests, ...needsConfirmation];\n\n // Find the request with the matching unique key or fallback to sequence number\n const request = allRequests.find(\n (r) =>\n (r.uniqueRequestKey === requestKey) ||\n (r.connectionRequestId?.toString() === requestKey) ||\n (r.inboundRequestId?.toString() === requestKey)\n );\n\n if (!request) {\n return `Error: Request with key ${requestKey} not found or no longer pending.`;\n }\n\n // Mark as processed in ConnectionsManager based on the appropriate ID\n if (request.inboundRequestId) {\n // For needs_confirmation requests\n connectionsManager.markConnectionRequestProcessed(\n request.targetInboundTopicId || '',\n request.inboundRequestId\n );\n } else if (request.connectionRequestId) {\n // For pending requests\n connectionsManager.markConnectionRequestProcessed(\n request.originTopicId || '',\n request.connectionRequestId\n );\n }\n\n return `Connection request from ${\n request.targetAgentName || `Agent ${request.targetAccountId}`\n } was rejected.`;\n }\n}\n"],"names":[],"mappings":";;;AAeO,MAAM,qCAAqC,eAAe;AAAA,EAwB/D,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GACkC;AACrC,UAAM,IAAI;AA5BL,SAAA,OAAA;AAEL,SAAA,cAAA;AACF,SAAA,SAAS,EAAE,OAAO;AAAA,MAChB,QAAQ,EACL,KAAK,CAAC,QAAQ,QAAQ,QAAQ,CAAC,EAC/B;AAAA,QACC;AAAA,MACF;AAAA,MACF,YAAY,EACT,SACA,SACA,EAAA;AAAA,QACC;AAAA,MAAA;AAAA,IACF,CACH;AAKD,SAAQ,kBAA0B;AAClC,SAAQ,oBAAoB;AAQ1B,SAAK,YAAY;AACjB,SAAK,eAAe;AACf,SAAA,SAAS,OAAO,YAAY;AAAA,MAC/B,QAAQ;AAAA,MACR,OAAO;AAAA,IAAA,CACR;AAAA,EAAA;AAAA,EAGH,MAAgB,MAAM;AAAA,IACpB;AAAA,IACA;AAAA,EAAA,GAC2C;AACrC,UAAA,eAAe,KAAK,aA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BAAqB,KAAK,aAAa,sBAAsB;AACnE,QAAI,CAAC,oBAAoB;AAChB,aAAA;AAAA,IAAA;AAGH,UAAA,kBAAkB,mBAAmB,mBAAmB;AACxD,UAAA,oBACJ,mBAAmB,kCAAkC;AAEvD,UAAM,cAAc,CAAC,GAAG,iBAAiB,GAAG,iBAAiB;AAG7D,UAAM,UAAU,YAAY;AAAA,MAC1B,CAAC,MACE,EAAE,qBAAqB,cACvB,EAAE,qBAAqB,SAAA,MAAe,cACtC,EAAE,kBAAkB,eAAe;AAAA,IACxC;AAEA,QAAI,CAAC,SAAS;AACZ,aAAO,2BAA2B,UAAU;AAAA,IAAA;AAI9C,QAAI,QAAQ,kBAAkB;AAET,yBAAA;AAAA,QACjB,QAAQ,wBAAwB;AAAA,QAChC,QAAQ;AAAA,MACV;AAAA,IAAA,WACS,QAAQ,qBAAqB;AAEnB,yBAAA;AAAA,QACjB,QAAQ,iBAAiB;AAAA,QACzB,QAAQ;AAAA,MACV;AAAA,IAAA;AAGF,WAAO,2BACL,QAAQ,mBAAmB,SAAS,QAAQ,eAAe,EAC7D;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es12.js","sources":["../../src/tools/hcs10/ManageConnectionRequestsTool.ts"],"sourcesContent":["import { z } from 'zod';\nimport { BaseHCS10QueryTool } from './base-hcs10-tools';\nimport { HCS10QueryToolParams } from './hcs10-tool-params';\n\nconst ManageConnectionRequestsZodSchema = z.object({\n action: z\n .enum(['list', 'view', 'reject'])\n .describe(\n 'The action to perform: list all requests, view details of a specific request, or reject a request'\n ),\n requestKey: z\n .string()\n .optional()\n .describe(\n 'The unique request key to view or reject (required for view and reject actions)'\n ),\n});\n\n/**\n * A tool for managing incoming connection requests in a LangChain-compatible way.\n * This tool allows an agent to list, view details of, and reject incoming connection requests.\n */\nexport class ManageConnectionRequestsTool extends BaseHCS10QueryTool<\n typeof ManageConnectionRequestsZodSchema\n> {\n name = 'manage_connection_requests';\n description =\n 'Manage incoming connection requests. List pending requests, view details about requesting agents, and reject connection requests. Use the separate \"accept_connection_request\" tool to accept.';\n specificInputSchema = ManageConnectionRequestsZodSchema;\n constructor(params: HCS10QueryToolParams) {\n super(params);\n }\n\n protected async executeQuery({\n action,\n requestKey,\n }: z.infer<typeof ManageConnectionRequestsZodSchema>): Promise<unknown> {\n const hcs10Builder = this.hcs10Builder;\n const params: { action: 'list' | 'view' | 'reject'; requestKey?: string } =\n { action };\n if (requestKey !== undefined) {\n params.requestKey = requestKey;\n }\n await hcs10Builder.manageConnectionRequests(params);\n const result = await hcs10Builder.execute();\n return 'rawResult' in result ? result.rawResult : result;\n }\n}\n"],"names":[],"mappings":";;AAIA,MAAM,oCAAoC,EAAE,OAAO;AAAA,EACjD,QAAQ,EACL,KAAK,CAAC,QAAQ,QAAQ,QAAQ,CAAC,EAC/B;AAAA,IACC;AAAA,EAAA;AAAA,EAEJ,YAAY,EACT,SACA,WACA;AAAA,IACC;AAAA,EAAA;AAEN,CAAC;AAMM,MAAM,qCAAqC,mBAEhD;AAAA,EAKA,YAAY,QAA8B;AACxC,UAAM,MAAM;AALd,SAAA,OAAO;AACP,SAAA,cACE;AACF,SAAA,sBAAsB;AAAA,EAGtB;AAAA,EAEA,MAAgB,aAAa;AAAA,IAC3B;AAAA,IACA;AAAA,EAAA,GACsE;AACtE,UAAM,eAAe,KAAK;AAC1B,UAAM,SACJ,EAAE,OAAA;AACJ,QAAI,eAAe,QAAW;AAC5B,aAAO,aAAa;AAAA,IACtB;AACA,UAAM,aAAa,yBAAyB,MAAM;AAClD,UAAM,SAAS,MAAM,aAAa,QAAA;AAClC,WAAO,eAAe,SAAS,OAAO,YAAY;AAAA,EACpD;AACF;"}
|
|
@@ -1,144 +1,32 @@
|
|
|
1
|
-
import { StructuredTool } from "@langchain/core/tools";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { BaseHCS10TransactionTool } from "./standards-agent-kit.es4.js";
|
|
3
|
+
const AcceptConnectionRequestZodSchema = z.object({
|
|
4
|
+
requestKey: z.string().describe(
|
|
5
|
+
'The unique request key of the specific request to accept. Use the "manage_connection_requests" tool with action="list" first to get valid keys.'
|
|
6
|
+
),
|
|
7
|
+
hbarFee: z.number().optional().describe(
|
|
8
|
+
"Optional HBAR fee amount to charge the connecting agent per message on the new connection topic."
|
|
9
|
+
),
|
|
10
|
+
exemptAccountIds: z.array(z.string()).optional().describe(
|
|
11
|
+
"Optional list of account IDs to exempt from any configured fees on the new connection topic."
|
|
12
|
+
)
|
|
13
|
+
});
|
|
14
|
+
class AcceptConnectionRequestTool extends BaseHCS10TransactionTool {
|
|
15
|
+
constructor(params) {
|
|
16
|
+
super(params);
|
|
11
17
|
this.name = "accept_connection_request";
|
|
12
|
-
this.description = "Accepts a
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
),
|
|
17
|
-
hbarFee: z.number().optional().describe(
|
|
18
|
-
"Optional HBAR fee amount to charge the connecting agent per message on the new connection topic."
|
|
19
|
-
),
|
|
20
|
-
exemptAccountIds: z.array(z.string()).optional().describe(
|
|
21
|
-
"Optional list of account IDs to exempt from any configured fees on the new connection topic."
|
|
22
|
-
)
|
|
23
|
-
});
|
|
24
|
-
this.hcsClient = hcsClient;
|
|
25
|
-
this.stateManager = stateManager;
|
|
26
|
-
this.logger = Logger.getInstance({
|
|
27
|
-
module: "AcceptConnectionRequestTool"
|
|
28
|
-
});
|
|
18
|
+
this.description = "Accepts a pending HCS-10 connection request from another agent. Use list_unapproved_connection_requests to see pending requests.";
|
|
19
|
+
this.specificInputSchema = AcceptConnectionRequestZodSchema;
|
|
20
|
+
this.neverScheduleThisTool = true;
|
|
21
|
+
this.requiresMultipleTransactions = true;
|
|
29
22
|
}
|
|
30
|
-
async
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return "Error: Cannot accept connection request. No agent is currently active. Please register or select an agent first.";
|
|
38
|
-
}
|
|
39
|
-
const connectionsManager = this.stateManager.getConnectionsManager();
|
|
40
|
-
if (!connectionsManager) {
|
|
41
|
-
return "Error: ConnectionsManager not initialized";
|
|
42
|
-
}
|
|
43
|
-
await connectionsManager.fetchConnectionData(currentAgent.accountId);
|
|
44
|
-
const allRequests = [
|
|
45
|
-
...connectionsManager.getPendingRequests(),
|
|
46
|
-
...connectionsManager.getConnectionsNeedingConfirmation()
|
|
47
|
-
];
|
|
48
|
-
const request = allRequests.find(
|
|
49
|
-
(r) => r.uniqueRequestKey === requestKey || r.connectionRequestId?.toString() === requestKey || r.inboundRequestId?.toString() === requestKey
|
|
50
|
-
);
|
|
51
|
-
if (!request) {
|
|
52
|
-
return `Error: Request with key ${requestKey} not found or no longer pending. Use the manage_connection_requests tool with action="list" to verify.`;
|
|
53
|
-
}
|
|
54
|
-
const numericRequestId = request.connectionRequestId || request.inboundRequestId;
|
|
55
|
-
if (!numericRequestId) {
|
|
56
|
-
return `Error: Could not determine a valid request ID for the request with key ${requestKey}.`;
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const inboundTopicId = await this.hcsClient.getInboundTopicId();
|
|
60
|
-
let feeConfigBuilder = void 0;
|
|
61
|
-
if (hbarFee && hbarFee > 0) {
|
|
62
|
-
const collectorId = this.hcsClient.getAccountAndSigner().accountId;
|
|
63
|
-
try {
|
|
64
|
-
feeConfigBuilder = new FeeConfigBuilder({
|
|
65
|
-
network: this.hcsClient.getNetwork(),
|
|
66
|
-
logger: this.logger,
|
|
67
|
-
defaultCollectorAccountId: collectorId
|
|
68
|
-
});
|
|
69
|
-
const finalExemptions = [
|
|
70
|
-
...exemptAccountIds || [],
|
|
71
|
-
currentAgent.accountId
|
|
72
|
-
];
|
|
73
|
-
feeConfigBuilder.addHbarFee(hbarFee, collectorId, finalExemptions);
|
|
74
|
-
this.logger.info(
|
|
75
|
-
`Setting HBAR fee: ${hbarFee} HBAR to be collected by ${collectorId}`
|
|
76
|
-
);
|
|
77
|
-
} catch (feeConfigError) {
|
|
78
|
-
this.logger.error(
|
|
79
|
-
`Error creating fee configuration: ${feeConfigError}`
|
|
80
|
-
);
|
|
81
|
-
feeConfigBuilder = void 0;
|
|
82
|
-
this.logger.warn(
|
|
83
|
-
"Proceeding to accept request without fees due to configuration error."
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
this.logger.info(
|
|
88
|
-
`Attempting to accept request Key: ${requestKey} (ID: ${numericRequestId}) from ${request.targetAccountId}`
|
|
89
|
-
);
|
|
90
|
-
const result = await this.hcsClient.handleConnectionRequest(
|
|
91
|
-
inboundTopicId,
|
|
92
|
-
request.targetAccountId,
|
|
93
|
-
numericRequestId,
|
|
94
|
-
feeConfigBuilder
|
|
95
|
-
);
|
|
96
|
-
if (!result?.connectionTopicId) {
|
|
97
|
-
return `Error: Failed to accept connection request with key ${requestKey}. The SDK did not return a connection topic ID.`;
|
|
98
|
-
}
|
|
99
|
-
this.logger.info(
|
|
100
|
-
`Successfully created connection topic: ${result.connectionTopicId}`
|
|
101
|
-
);
|
|
102
|
-
const connectionTopicId = result.connectionTopicId;
|
|
103
|
-
let targetInboundTopic = "";
|
|
104
|
-
try {
|
|
105
|
-
const targetProfileData = await this.hcsClient.standardClient.retrieveProfile(request.targetAccountId);
|
|
106
|
-
targetInboundTopic = targetProfileData?.topicInfo?.inboundTopic || "";
|
|
107
|
-
if (!targetInboundTopic) {
|
|
108
|
-
this.logger.warn(
|
|
109
|
-
`Could not resolve target inbound topic for ${request.targetAccountId}`
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
} catch (e) {
|
|
113
|
-
this.logger.warn(
|
|
114
|
-
`Error fetching target profile/topic for ${request.targetAccountId}: ${e}`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
const name = request.profileInfo?.display_name || request.profileInfo?.alias || `Agent ${request.targetAccountId}`;
|
|
118
|
-
const newConnection = {
|
|
119
|
-
targetAccountId: request.targetAccountId,
|
|
120
|
-
targetAgentName: name,
|
|
121
|
-
targetInboundTopicId: targetInboundTopic,
|
|
122
|
-
connectionTopicId,
|
|
123
|
-
profileInfo: request.profileInfo,
|
|
124
|
-
created: /* @__PURE__ */ new Date(),
|
|
125
|
-
status: "established"
|
|
126
|
-
};
|
|
127
|
-
this.stateManager.addActiveConnection(newConnection);
|
|
128
|
-
connectionsManager.fetchConnectionData(request.targetAccountId);
|
|
129
|
-
this.logger.info(`Removed request ${requestKey} from pending requests`);
|
|
130
|
-
let feeMessage = "";
|
|
131
|
-
if (hbarFee && hbarFee > 0 && feeConfigBuilder) {
|
|
132
|
-
feeMessage = ` with a ${hbarFee} HBAR fee per message`;
|
|
133
|
-
}
|
|
134
|
-
const displayKey = request.uniqueRequestKey || requestKey;
|
|
135
|
-
return `Successfully accepted connection request ${displayKey} from ${name} ${feeMessage}. Connection established on topic: ${connectionTopicId}.`;
|
|
136
|
-
} catch (error) {
|
|
137
|
-
this.logger.error(
|
|
138
|
-
`Error accepting connection request ${requestKey}: ${error}`
|
|
139
|
-
);
|
|
140
|
-
return `Error accepting connection request ${requestKey}: ${error instanceof Error ? error.message : String(error)}`;
|
|
141
|
-
}
|
|
23
|
+
async callBuilderMethod(builder, specificArgs) {
|
|
24
|
+
const hcs10Builder = builder;
|
|
25
|
+
await hcs10Builder.acceptConnection({
|
|
26
|
+
requestKey: specificArgs.requestKey,
|
|
27
|
+
hbarFee: specificArgs.hbarFee,
|
|
28
|
+
exemptAccountIds: specificArgs.exemptAccountIds
|
|
29
|
+
});
|
|
142
30
|
}
|
|
143
31
|
}
|
|
144
32
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es13.js","sources":["../../src/tools/AcceptConnectionRequestTool.ts"],"sourcesContent":["import { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { HCS10Client } from '../hcs10/HCS10Client';\nimport { IStateManager, ActiveConnection } from '../state/state-types';\nimport { Logger, FeeConfigBuilder } from '@hashgraphonline/standards-sdk';\n\nexport interface AcceptConnectionRequestToolParams extends ToolParams {\n hcsClient: HCS10Client;\n stateManager: IStateManager;\n}\n\n/**\n * A tool specifically for accepting incoming connection requests.\n */\nexport class AcceptConnectionRequestTool extends StructuredTool {\n name = 'accept_connection_request';\n description =\n 'Accepts a specific pending connection request from another agent, establishing a communication channel.';\n schema = z.object({\n requestKey: z\n .string()\n .describe(\n 'The unique request key of the specific request to accept. Use the \"manage_connection_requests\" tool with action=\"list\" first to get valid keys.'\n ),\n hbarFee: z\n .number()\n .optional()\n .describe(\n 'Optional HBAR fee amount to charge the connecting agent per message on the new connection topic.'\n ),\n exemptAccountIds: z\n .array(z.string())\n .optional()\n .describe(\n 'Optional list of account IDs to exempt from any configured fees on the new connection topic.'\n ),\n });\n\n private hcsClient: HCS10Client;\n private stateManager: IStateManager;\n private logger: Logger;\n\n constructor({\n hcsClient,\n stateManager,\n ...rest\n }: AcceptConnectionRequestToolParams) {\n super(rest);\n this.hcsClient = hcsClient;\n this.stateManager = stateManager;\n this.logger = Logger.getInstance({\n module: 'AcceptConnectionRequestTool',\n });\n }\n\n protected async _call({\n requestKey,\n hbarFee,\n exemptAccountIds,\n }: z.infer<this['schema']>): Promise<string> {\n const currentAgent = this.stateManager.getCurrentAgent();\n if (!currentAgent) {\n return 'Error: Cannot accept connection request. No agent is currently active. Please register or select an agent first.';\n }\n\n const connectionsManager = this.stateManager.getConnectionsManager();\n if (!connectionsManager) {\n return 'Error: ConnectionsManager not initialized';\n }\n\n await connectionsManager.fetchConnectionData(currentAgent.accountId);\n\n // Find the request with the matching unique key or fallback to sequence number\n const allRequests = [\n ...connectionsManager.getPendingRequests(),\n ...connectionsManager.getConnectionsNeedingConfirmation()\n ];\n\n const request = allRequests.find(\n (r) => (r.uniqueRequestKey === requestKey) ||\n (r.connectionRequestId?.toString() === requestKey) ||\n (r.inboundRequestId?.toString() === requestKey)\n );\n\n if (!request) {\n return `Error: Request with key ${requestKey} not found or no longer pending. Use the manage_connection_requests tool with action=\"list\" to verify.`;\n }\n\n // Get the numeric request ID from the request for the SDK call\n const numericRequestId = request.connectionRequestId || request.inboundRequestId;\n if (!numericRequestId) {\n return `Error: Could not determine a valid request ID for the request with key ${requestKey}.`;\n }\n\n try {\n const inboundTopicId = await this.hcsClient.getInboundTopicId();\n let feeConfigBuilder = undefined;\n\n if (hbarFee && hbarFee > 0) {\n const collectorId = this.hcsClient.getAccountAndSigner().accountId;\n try {\n feeConfigBuilder = new FeeConfigBuilder({\n network: this.hcsClient.getNetwork(),\n logger: this.logger,\n defaultCollectorAccountId: collectorId,\n });\n\n const finalExemptions = [\n ...(exemptAccountIds || []),\n currentAgent.accountId,\n ];\n feeConfigBuilder.addHbarFee(hbarFee, collectorId, finalExemptions);\n this.logger.info(\n `Setting HBAR fee: ${hbarFee} HBAR to be collected by ${collectorId}`\n );\n } catch (feeConfigError) {\n this.logger.error(\n `Error creating fee configuration: ${feeConfigError}`\n );\n\n feeConfigBuilder = undefined;\n this.logger.warn(\n 'Proceeding to accept request without fees due to configuration error.'\n );\n }\n }\n\n this.logger.info(\n `Attempting to accept request Key: ${requestKey} (ID: ${numericRequestId}) from ${request.targetAccountId}`\n );\n const result = await this.hcsClient.handleConnectionRequest(\n inboundTopicId,\n request.targetAccountId,\n numericRequestId,\n feeConfigBuilder\n );\n\n if (!result?.connectionTopicId) {\n return `Error: Failed to accept connection request with key ${requestKey}. The SDK did not return a connection topic ID.`;\n }\n this.logger.info(\n `Successfully created connection topic: ${result.connectionTopicId}`\n );\n\n const connectionTopicId = result.connectionTopicId;\n\n let targetInboundTopic = '';\n try {\n const targetProfileData = await this.hcsClient.standardClient.retrieveProfile(request.targetAccountId);\n targetInboundTopic =\n targetProfileData?.topicInfo?.inboundTopic || '';\n if (!targetInboundTopic) {\n this.logger.warn(\n `Could not resolve target inbound topic for ${request.targetAccountId}`\n );\n }\n } catch (e) {\n this.logger.warn(\n `Error fetching target profile/topic for ${request.targetAccountId}: ${e}`\n );\n }\n\n const name = request.profileInfo?.display_name || request.profileInfo?.alias || `Agent ${request.targetAccountId}`;\n const newConnection: ActiveConnection = {\n targetAccountId: request.targetAccountId,\n targetAgentName: name,\n targetInboundTopicId: targetInboundTopic,\n connectionTopicId,\n profileInfo: request.profileInfo,\n created: new Date(),\n status: 'established',\n };\n\n this.stateManager.addActiveConnection(newConnection);\n connectionsManager.fetchConnectionData(request.targetAccountId);\n\n this.logger.info(`Removed request ${requestKey} from pending requests`);\n\n let feeMessage = '';\n if (hbarFee && hbarFee > 0 && feeConfigBuilder) {\n feeMessage = ` with a ${hbarFee} HBAR fee per message`;\n }\n\n const displayKey = request.uniqueRequestKey || requestKey;\n return `Successfully accepted connection request ${displayKey} from ${name} ${feeMessage}. Connection established on topic: ${connectionTopicId}.`;\n } catch (error) {\n this.logger.error(\n `Error accepting connection request ${requestKey}: ${error}`\n );\n\n return `Error accepting connection request ${requestKey}: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n}\n"],"names":[],"mappings":";;;AAcO,MAAM,oCAAoC,eAAe;AAAA,EA4B9D,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GACiC;AACpC,UAAM,IAAI;AAhCL,SAAA,OAAA;AAEL,SAAA,cAAA;AACF,SAAA,SAAS,EAAE,OAAO;AAAA,MAChB,YAAY,EACT,OAAA,EACA;AAAA,QACC;AAAA,MACF;AAAA,MACF,SAAS,EACN,SACA,SACA,EAAA;AAAA,QACC;AAAA,MACF;AAAA,MACF,kBAAkB,EACf,MAAM,EAAE,QAAQ,EAChB,WACA;AAAA,QACC;AAAA,MAAA;AAAA,IACF,CACH;AAYC,SAAK,YAAY;AACjB,SAAK,eAAe;AACf,SAAA,SAAS,OAAO,YAAY;AAAA,MAC/B,QAAQ;AAAA,IAAA,CACT;AAAA,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AK,kBAAkB;AAC9C,qBAAa,WAAW,OAAO;AAAA,MAAA;AAG3B,YAAA,aAAa,QAAQ,oBAAoB;AAC/C,aAAO,4CAA4C,UAAU,SAAS,IAAI,IAAI,UAAU,sCAAsC,iBAAiB;AAAA,aACxI,OAAO;AACd,WAAK,OAAO;AAAA,QACV,sCAAsC,UAAU,KAAK,KAAK;AAAA,MAC5D;AAEO,aAAA,sCAAsC,UAAU,KACrD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es13.js","sources":["../../src/tools/hcs10/AcceptConnectionRequestTool.ts"],"sourcesContent":["import { z } from 'zod';\nimport { BaseHCS10TransactionTool } from './base-hcs10-tools';\nimport { HCS10Builder } from '../../builders/hcs10/hcs10-builder';\nimport { HCS10TransactionToolParams } from './hcs10-tool-params';\nimport { BaseServiceBuilder } from 'hedera-agent-kit';\n\nconst AcceptConnectionRequestZodSchema = z.object({\n requestKey: z\n .string()\n .describe(\n 'The unique request key of the specific request to accept. Use the \"manage_connection_requests\" tool with action=\"list\" first to get valid keys.'\n ),\n hbarFee: z\n .number()\n .optional()\n .describe(\n 'Optional HBAR fee amount to charge the connecting agent per message on the new connection topic.'\n ),\n exemptAccountIds: z\n .array(z.string())\n .optional()\n .describe(\n 'Optional list of account IDs to exempt from any configured fees on the new connection topic.'\n ),\n});\n\n/**\n * Tool for accepting incoming HCS-10 connection requests\n */\nexport class AcceptConnectionRequestTool extends BaseHCS10TransactionTool<\n typeof AcceptConnectionRequestZodSchema\n> {\n name = 'accept_connection_request';\n description =\n 'Accepts a pending HCS-10 connection request from another agent. Use list_unapproved_connection_requests to see pending requests.';\n specificInputSchema = AcceptConnectionRequestZodSchema;\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 AcceptConnectionRequestZodSchema>\n ): Promise<void> {\n const hcs10Builder = builder as HCS10Builder;\n\n await hcs10Builder.acceptConnection({\n requestKey: specificArgs.requestKey,\n hbarFee: specificArgs.hbarFee,\n exemptAccountIds: specificArgs.exemptAccountIds,\n });\n }\n}"],"names":[],"mappings":";;AAMA,MAAM,mCAAmC,EAAE,OAAO;AAAA,EAChD,YAAY,EACT,OAAA,EACA;AAAA,IACC;AAAA,EAAA;AAAA,EAEJ,SAAS,EACN,SACA,WACA;AAAA,IACC;AAAA,EAAA;AAAA,EAEJ,kBAAkB,EACf,MAAM,EAAE,QAAQ,EAChB,WACA;AAAA,IACC;AAAA,EAAA;AAEN,CAAC;AAKM,MAAM,oCAAoC,yBAE/C;AAAA,EAMA,YAAY,QAAoC;AAC9C,UAAM,MAAM;AANd,SAAA,OAAO;AACP,SAAA,cACE;AACF,SAAA,sBAAsB;AAIpB,SAAK,wBAAwB;AAC7B,SAAK,+BAA+B;AAAA,EACtC;AAAA,EAEA,MAAgB,kBACd,SACA,cACe;AACf,UAAM,eAAe;AAErB,UAAM,aAAa,iBAAiB;AAAA,MAClC,YAAY,aAAa;AAAA,MACzB,SAAS,aAAa;AAAA,MACtB,kBAAkB,aAAa;AAAA,IAAA,CAChC;AAAA,EACH;AACF;"}
|
|
@@ -1,66 +1,42 @@
|
|
|
1
|
-
import { StructuredTool } from "@langchain/core/tools";
|
|
2
1
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { BaseHCS10QueryTool } from "./standards-agent-kit.es4.js";
|
|
3
|
+
const RetrieveProfileZodSchema = z.object({
|
|
4
|
+
accountId: z.string().describe(
|
|
5
|
+
"The Hedera account ID of the agent whose profile you want to retrieve (e.g., 0.0.12345)."
|
|
6
|
+
),
|
|
7
|
+
disableCache: z.boolean().optional().describe(
|
|
8
|
+
"Optional: Force refresh from the network instead of using cache."
|
|
9
|
+
)
|
|
10
|
+
});
|
|
11
|
+
class RetrieveProfileTool extends BaseHCS10QueryTool {
|
|
12
|
+
constructor(params) {
|
|
13
|
+
super(params);
|
|
11
14
|
this.name = "retrieve_profile";
|
|
12
|
-
this.description = "
|
|
13
|
-
this.
|
|
14
|
-
accountId: z.string().optional().describe(
|
|
15
|
-
"The Hedera account ID (e.g., 0.0.12345) to retrieve the profile for. If omitted, defaults to the current operator account ID."
|
|
16
|
-
),
|
|
17
|
-
disableCache: z.boolean().optional().describe(
|
|
18
|
-
"Optional: Set to true to bypass the cache and fetch fresh profile data."
|
|
19
|
-
)
|
|
20
|
-
});
|
|
21
|
-
this.client = client;
|
|
22
|
-
this.logger = Logger.getInstance({ module: this.name });
|
|
15
|
+
this.description = "Gets the detailed profile information for a specific HCS-10 agent by their account ID. Returns name, bio, capabilities, topics, and other metadata.";
|
|
16
|
+
this.specificInputSchema = RetrieveProfileZodSchema;
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} else {
|
|
35
|
-
this.logger.info("accountId not provided, defaulting to operator ID.");
|
|
36
|
-
targetAccountId = this.client.getOperatorId();
|
|
37
|
-
}
|
|
38
|
-
if (!targetAccountId) {
|
|
39
|
-
throw new Error("Could not determine target account ID.");
|
|
40
|
-
}
|
|
41
|
-
this.logger.info(
|
|
42
|
-
`Attempting to retrieve profile for account: ${targetAccountId}, Disable Cache: ${!!input.disableCache}`
|
|
43
|
-
);
|
|
44
|
-
const result = await this.client.standardClient.retrieveProfile(
|
|
45
|
-
targetAccountId,
|
|
46
|
-
input.disableCache
|
|
47
|
-
);
|
|
48
|
-
if (result.success && result.profile) {
|
|
49
|
-
this.logger.info(
|
|
50
|
-
`Successfully retrieved profile for ${targetAccountId}.`
|
|
51
|
-
);
|
|
52
|
-
return JSON.stringify(result.profile, null, 2);
|
|
53
|
-
} else {
|
|
54
|
-
const errorMessage = `Error retrieving profile for ${targetAccountId}: ${result.error || "Profile not found or invalid."}`;
|
|
55
|
-
this.logger.error(errorMessage);
|
|
56
|
-
return errorMessage;
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
const idForError = input.accountId || "operator default";
|
|
60
|
-
const errorMessage = `Unexpected error retrieving profile for ${idForError}: ${error instanceof Error ? error.message : String(error)}`;
|
|
61
|
-
this.logger.error(errorMessage, error);
|
|
62
|
-
return errorMessage;
|
|
18
|
+
async executeQuery({
|
|
19
|
+
accountId,
|
|
20
|
+
disableCache
|
|
21
|
+
}) {
|
|
22
|
+
const hcs10Builder = this.hcs10Builder;
|
|
23
|
+
const params = {
|
|
24
|
+
accountId
|
|
25
|
+
};
|
|
26
|
+
if (disableCache !== void 0) {
|
|
27
|
+
params.disableCache = disableCache;
|
|
63
28
|
}
|
|
29
|
+
await hcs10Builder.retrieveProfile(params);
|
|
30
|
+
const result = await hcs10Builder.execute();
|
|
31
|
+
if (result.success && "rawResult" in result && result.rawResult) {
|
|
32
|
+
const raw = result.rawResult;
|
|
33
|
+
return {
|
|
34
|
+
success: true,
|
|
35
|
+
data: raw.profileDetails || "Profile retrieved",
|
|
36
|
+
rawProfile: raw.rawProfile
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
64
40
|
}
|
|
65
41
|
}
|
|
66
42
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es14.js","sources":["../../src/tools/RetrieveProfileTool.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es14.js","sources":["../../src/tools/hcs10/RetrieveProfileTool.ts"],"sourcesContent":["import { z } from 'zod';\nimport { BaseHCS10QueryTool } from './base-hcs10-tools';\nimport { HCS10QueryToolParams } from './hcs10-tool-params';\nconst RetrieveProfileZodSchema = z.object({\n accountId: z\n .string()\n .describe(\n 'The Hedera account ID of the agent whose profile you want to retrieve (e.g., 0.0.12345).'\n ),\n disableCache: z\n .boolean()\n .optional()\n .describe(\n 'Optional: Force refresh from the network instead of using cache.'\n ),\n});\n\n/**\n * Tool to retrieve detailed profile information for a specific HCS-10 agent\n */\nexport class RetrieveProfileTool extends BaseHCS10QueryTool<\n typeof RetrieveProfileZodSchema\n> {\n name = 'retrieve_profile';\n description =\n 'Gets the detailed profile information for a specific HCS-10 agent by their account ID. Returns name, bio, capabilities, topics, and other metadata.';\n specificInputSchema = RetrieveProfileZodSchema;\n constructor(params: HCS10QueryToolParams) {\n super(params);\n }\n\n protected async executeQuery({\n accountId,\n disableCache,\n }: z.infer<typeof RetrieveProfileZodSchema>): Promise<unknown> {\n const hcs10Builder = this.hcs10Builder;\n const params: { accountId: string; disableCache?: boolean } = {\n accountId,\n };\n if (disableCache !== undefined) {\n params.disableCache = disableCache;\n }\n await hcs10Builder.retrieveProfile(params);\n\n const result = await hcs10Builder.execute();\n\n if (result.success && 'rawResult' in result && result.rawResult) {\n const raw = result.rawResult as {\n profileDetails?: string;\n rawProfile?: unknown;\n };\n return {\n success: true,\n data: raw.profileDetails || 'Profile retrieved',\n rawProfile: raw.rawProfile,\n };\n }\n\n return result;\n }\n}"],"names":[],"mappings":";;AAGA,MAAM,2BAA2B,EAAE,OAAO;AAAA,EACxC,WAAW,EACR,OAAA,EACA;AAAA,IACC;AAAA,EAAA;AAAA,EAEJ,cAAc,EACX,UACA,WACA;AAAA,IACC;AAAA,EAAA;AAEN,CAAC;AAKM,MAAM,4BAA4B,mBAEvC;AAAA,EAKA,YAAY,QAA8B;AACxC,UAAM,MAAM;AALd,SAAA,OAAO;AACP,SAAA,cACE;AACF,SAAA,sBAAsB;AAAA,EAGtB;AAAA,EAEA,MAAgB,aAAa;AAAA,IAC3B;AAAA,IACA;AAAA,EAAA,GAC6D;AAC7D,UAAM,eAAe,KAAK;AAC1B,UAAM,SAAwD;AAAA,MAC5D;AAAA,IAAA;AAEF,QAAI,iBAAiB,QAAW;AAC9B,aAAO,eAAe;AAAA,IACxB;AACA,UAAM,aAAa,gBAAgB,MAAM;AAEzC,UAAM,SAAS,MAAM,aAAa,QAAA;AAElC,QAAI,OAAO,WAAW,eAAe,UAAU,OAAO,WAAW;AAC/D,YAAM,MAAM,OAAO;AAInB,aAAO;AAAA,QACL,SAAS;AAAA,QACT,MAAM,IAAI,kBAAkB;AAAA,QAC5B,YAAY,IAAI;AAAA,MAAA;AAAA,IAEpB;AAEA,WAAO;AAAA,EACT;AACF;"}
|