@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,231 +0,0 @@
|
|
|
1
|
-
import { HCS10Client } from '../hcs10/HCS10Client';
|
|
2
|
-
import { StructuredTool, ToolParams } from '@langchain/core/tools';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
// Import FeeConfigBuilder if needed for explicit fee handling
|
|
5
|
-
// import { FeeConfigBuilder } from '@hashgraphonline/standards-sdk';
|
|
6
|
-
import { Logger } from '@hashgraphonline/standards-sdk';
|
|
7
|
-
import {
|
|
8
|
-
IStateManager,
|
|
9
|
-
ActiveConnection,
|
|
10
|
-
} from '../state/state-types'; // Corrected import path/name
|
|
11
|
-
|
|
12
|
-
export interface ConnectionToolParams extends ToolParams {
|
|
13
|
-
client: HCS10Client;
|
|
14
|
-
stateManager: IStateManager;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* ConnectionTool monitors the *current* agent's inbound topic for connection requests
|
|
19
|
-
* and automatically handles them using the HCS-10 standard SDK flow.
|
|
20
|
-
* Use this ONLY to passively LISTEN for other agents trying to connect TO YOU.
|
|
21
|
-
* This tool takes NO arguments and does NOT start outgoing connections.
|
|
22
|
-
*/
|
|
23
|
-
export class ConnectionTool extends StructuredTool {
|
|
24
|
-
name = 'monitor_connections';
|
|
25
|
-
description =
|
|
26
|
-
"Starts passively LISTENING on the current agent's own inbound topic for INCOMING HCS-10 connection requests. Handles received requests automatically. Takes NO arguments. DO NOT use this to start a new connection TO someone else.";
|
|
27
|
-
public client: HCS10Client;
|
|
28
|
-
public logger: Logger;
|
|
29
|
-
private stateManager: IStateManager; // Renamed property
|
|
30
|
-
private isMonitoring: boolean = false; // Flag to prevent multiple monitors
|
|
31
|
-
private monitoringTopic: string | null = null;
|
|
32
|
-
|
|
33
|
-
// Schema now takes NO arguments
|
|
34
|
-
schema = z.object({});
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @param client - Instance of HCS10Client.
|
|
38
|
-
* @param stateManager - Instance of StateManager for shared state management.
|
|
39
|
-
*/
|
|
40
|
-
constructor({ client, stateManager, ...rest }: ConnectionToolParams) {
|
|
41
|
-
super(rest);
|
|
42
|
-
this.client = client;
|
|
43
|
-
this.stateManager = stateManager; // Renamed assignment
|
|
44
|
-
this.logger = Logger.getInstance({
|
|
45
|
-
module: 'ConnectionTool',
|
|
46
|
-
level: 'info',
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Initiates the connection request monitoring process in the background.
|
|
52
|
-
* Gets the inbound topic ID from the configured client.
|
|
53
|
-
*/
|
|
54
|
-
async _call(/* _input: z.infer<typeof this.schema> */): Promise<string> {
|
|
55
|
-
// Get inboundTopicId from the client
|
|
56
|
-
let inboundTopicId: string;
|
|
57
|
-
try {
|
|
58
|
-
// Assuming getInboundTopicId() is implemented and available
|
|
59
|
-
inboundTopicId = await this.client.getInboundTopicId();
|
|
60
|
-
} catch (error) {
|
|
61
|
-
const errorMsg = `Error getting inbound topic ID for monitoring: ${
|
|
62
|
-
error instanceof Error ? error.message : String(error)
|
|
63
|
-
}`;
|
|
64
|
-
this.logger.error(errorMsg);
|
|
65
|
-
return errorMsg;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (!inboundTopicId) {
|
|
69
|
-
return 'Error: Could not determine the inbound topic ID for the current agent.';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (this.isMonitoring) {
|
|
73
|
-
if (this.monitoringTopic === inboundTopicId) {
|
|
74
|
-
return `Already monitoring topic ${inboundTopicId}.`;
|
|
75
|
-
} else {
|
|
76
|
-
return `Error: Already monitoring a different topic (${this.monitoringTopic}). Stop the current monitor first.`;
|
|
77
|
-
// TODO: Add a mechanism to stop the monitor if needed.
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
this.isMonitoring = true;
|
|
82
|
-
this.monitoringTopic = inboundTopicId;
|
|
83
|
-
this.logger.info(
|
|
84
|
-
`Initiating connection request monitoring for topic ${inboundTopicId}...`
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
// Start the monitoring process asynchronously without awaiting it
|
|
88
|
-
// This allows the tool call to return quickly.
|
|
89
|
-
this.monitorIncomingRequests(inboundTopicId).catch((error) => {
|
|
90
|
-
this.logger.error(
|
|
91
|
-
`Monitoring loop for ${inboundTopicId} encountered an unrecoverable error:`,
|
|
92
|
-
error
|
|
93
|
-
);
|
|
94
|
-
this.isMonitoring = false; // Reset flag on loop failure
|
|
95
|
-
this.monitoringTopic = null;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return `Started monitoring inbound topic ${inboundTopicId} for connection requests in the background.`;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* The core monitoring loop.
|
|
103
|
-
*/
|
|
104
|
-
private async monitorIncomingRequests(inboundTopicId: string): Promise<void> {
|
|
105
|
-
this.logger.info(`Monitoring inbound topic ${inboundTopicId}...`);
|
|
106
|
-
|
|
107
|
-
let lastProcessedMessageSequence = 0;
|
|
108
|
-
const processedRequestIds = new Set<number>(); // Track processed requests within this monitoring session
|
|
109
|
-
|
|
110
|
-
// Main monitoring loop
|
|
111
|
-
while (this.isMonitoring && this.monitoringTopic === inboundTopicId) {
|
|
112
|
-
try {
|
|
113
|
-
const messagesResult = await this.client.getMessages(inboundTopicId);
|
|
114
|
-
|
|
115
|
-
const allMessages = messagesResult.messages;
|
|
116
|
-
|
|
117
|
-
const connectionRequests = allMessages.filter(
|
|
118
|
-
(msg) =>
|
|
119
|
-
msg.op === 'connection_request' &&
|
|
120
|
-
typeof msg.sequence_number === 'number' // Keep filtering by sequence number if needed, or remove if checking existing confirmations is sufficient
|
|
121
|
-
// msg.sequence_number > lastProcessedMessageSequence // Temporarily remove or adjust this if checking confirmations is the primary method
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
for (const message of connectionRequests) {
|
|
125
|
-
// Update lastProcessedMessageSequence regardless of handling outcome to avoid re-checking handled/skipped messages in future loops
|
|
126
|
-
lastProcessedMessageSequence = Math.max(
|
|
127
|
-
lastProcessedMessageSequence,
|
|
128
|
-
message.sequence_number || 0 // Use 0 if sequence_number is undefined (though filter should prevent this)
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const connectionRequestId = message.sequence_number;
|
|
132
|
-
if (!connectionRequestId) {
|
|
133
|
-
continue; // Skip if sequence number is missing
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// --- Check if already handled ---
|
|
137
|
-
const alreadyHandled = allMessages.some(
|
|
138
|
-
(m) => m.op === 'connection_created' && m.connection_id === connectionRequestId
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
if (alreadyHandled) {
|
|
142
|
-
this.logger.debug(
|
|
143
|
-
`Connection request #${connectionRequestId} already handled (found connection_created). Skipping.`
|
|
144
|
-
);
|
|
145
|
-
continue; // Skip to the next request
|
|
146
|
-
}
|
|
147
|
-
// --- End Check ---
|
|
148
|
-
|
|
149
|
-
// Extract requesting account ID from the message's operator_id field (topic@account)
|
|
150
|
-
const senderOperatorId = message.operator_id || '';
|
|
151
|
-
const requestingAccountId = senderOperatorId.split('@')[1] || null;
|
|
152
|
-
|
|
153
|
-
if (!requestingAccountId) {
|
|
154
|
-
this.logger.warn(
|
|
155
|
-
`Could not determine requesting account ID from operator_id '${senderOperatorId}' for request #${connectionRequestId}. Skipping.`
|
|
156
|
-
);
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (processedRequestIds.has(connectionRequestId)) {
|
|
161
|
-
this.logger.info(
|
|
162
|
-
`Connection request #${connectionRequestId} already processed in this session. Skipping.`
|
|
163
|
-
);
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
this.logger.info(
|
|
168
|
-
`Processing connection request #${connectionRequestId} from account ${requestingAccountId}...`
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
// Handle the connection request using the HCS10Client wrapper
|
|
173
|
-
const confirmation = await this.client.handleConnectionRequest(
|
|
174
|
-
inboundTopicId,
|
|
175
|
-
requestingAccountId,
|
|
176
|
-
connectionRequestId
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
processedRequestIds.add(connectionRequestId);
|
|
180
|
-
this.logger.info(
|
|
181
|
-
`Connection confirmed for request #${connectionRequestId}. New connection topic: ${confirmation.connectionTopicId}`
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
// Use stateManager to add connection
|
|
185
|
-
const newConnection: ActiveConnection = {
|
|
186
|
-
targetAccountId: requestingAccountId,
|
|
187
|
-
targetAgentName: `Agent ${requestingAccountId}`,
|
|
188
|
-
targetInboundTopicId: 'N/A',
|
|
189
|
-
connectionTopicId: confirmation.connectionTopicId,
|
|
190
|
-
};
|
|
191
|
-
this.stateManager.addActiveConnection(newConnection);
|
|
192
|
-
this.logger.info(
|
|
193
|
-
`Added new active connection to ${requestingAccountId} state.`
|
|
194
|
-
);
|
|
195
|
-
} catch (handleError) {
|
|
196
|
-
this.logger.error(
|
|
197
|
-
`Error handling connection request #${connectionRequestId} from ${requestingAccountId}:`,
|
|
198
|
-
handleError
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
} catch (error) {
|
|
203
|
-
this.logger.error(
|
|
204
|
-
`Error fetching or processing messages for topic ${inboundTopicId}:`,
|
|
205
|
-
error
|
|
206
|
-
);
|
|
207
|
-
// Implement backoff or error threshold if needed
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Wait before the next poll
|
|
211
|
-
await new Promise((resolve) => setTimeout(resolve, 5000)); // Poll every 5 seconds (adjust as needed)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
this.logger.info(`Monitoring loop stopped for topic ${inboundTopicId}.`);
|
|
215
|
-
this.isMonitoring = false; // Ensure flag is reset when loop exits
|
|
216
|
-
this.monitoringTopic = null;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Optional: Method to explicitly stop monitoring
|
|
220
|
-
public stopMonitoring(): void {
|
|
221
|
-
if (this.isMonitoring) {
|
|
222
|
-
this.logger.info(
|
|
223
|
-
`Stopping monitoring for topic ${this.monitoringTopic}...`
|
|
224
|
-
);
|
|
225
|
-
this.isMonitoring = false;
|
|
226
|
-
this.monitoringTopic = null;
|
|
227
|
-
} else {
|
|
228
|
-
this.logger.info('Monitor is not currently running.');
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { StructuredTool, ToolParams } from '@langchain/core/tools';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { HCS10Client } from '../hcs10/HCS10Client';
|
|
4
|
-
import {
|
|
5
|
-
AIAgentCapability,
|
|
6
|
-
Logger,
|
|
7
|
-
RegistrationSearchOptions,
|
|
8
|
-
} from '@hashgraphonline/standards-sdk';
|
|
9
|
-
|
|
10
|
-
export interface FindRegistrationsToolParams extends ToolParams {
|
|
11
|
-
hcsClient: HCS10Client;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A tool to search for registered HCS-10 agents using the configured registry.
|
|
16
|
-
*/
|
|
17
|
-
export class FindRegistrationsTool extends StructuredTool {
|
|
18
|
-
name = 'find_registrations';
|
|
19
|
-
description =
|
|
20
|
-
'Searches the configured agent registry for HCS-10 agents. You can filter by account ID or tags. Returns basic registration info.';
|
|
21
|
-
schema = z.object({
|
|
22
|
-
accountId: z
|
|
23
|
-
.string()
|
|
24
|
-
.optional()
|
|
25
|
-
.describe(
|
|
26
|
-
'Optional: Filter registrations by a specific Hedera account ID (e.g., 0.0.12345).'
|
|
27
|
-
),
|
|
28
|
-
tags: z
|
|
29
|
-
.array(z.nativeEnum(AIAgentCapability))
|
|
30
|
-
.optional()
|
|
31
|
-
.describe(
|
|
32
|
-
'Optional: Filter registrations by a list of tags (API filter only).'
|
|
33
|
-
),
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
private hcsClient: HCS10Client;
|
|
37
|
-
private logger: Logger;
|
|
38
|
-
|
|
39
|
-
constructor({ hcsClient, ...rest }: FindRegistrationsToolParams) {
|
|
40
|
-
super(rest);
|
|
41
|
-
this.hcsClient = hcsClient;
|
|
42
|
-
this.logger = Logger.getInstance({ module: 'FindRegistrationsTool' });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
protected async _call({
|
|
46
|
-
accountId,
|
|
47
|
-
tags,
|
|
48
|
-
}: z.infer<this['schema']>): Promise<string> {
|
|
49
|
-
this.logger.info(
|
|
50
|
-
'Searching registrations with filters - Account ID',
|
|
51
|
-
JSON.stringify({
|
|
52
|
-
accountId,
|
|
53
|
-
tags,
|
|
54
|
-
})
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const options: RegistrationSearchOptions = {};
|
|
58
|
-
if (accountId) {
|
|
59
|
-
options.accountId = accountId;
|
|
60
|
-
}
|
|
61
|
-
if (tags && tags.length > 0) {
|
|
62
|
-
options.tags = tags;
|
|
63
|
-
}
|
|
64
|
-
options.network = this.hcsClient.getNetwork();
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
if (!this.hcsClient.standardClient) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
'Standard SDK client instance is not available in HCS10Client wrapper.'
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
const result = await this.hcsClient.standardClient.findRegistrations(
|
|
73
|
-
options
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
if (!result.success || result.error) {
|
|
77
|
-
return `Error finding registrations: ${
|
|
78
|
-
result.error || 'Unknown error'
|
|
79
|
-
}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!result.registrations || result.registrations.length === 0) {
|
|
83
|
-
return 'No registrations found matching the criteria.';
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Format the results based on available data from RegistrationSearchResult
|
|
87
|
-
let output = `Found ${result.registrations.length} registration(s):\n`;
|
|
88
|
-
result.registrations.forEach((reg, index: number) => {
|
|
89
|
-
const metadata = reg.metadata;
|
|
90
|
-
output += `${index + 1}. Name: ${metadata.alias || 'N/A'}\n`;
|
|
91
|
-
output += `Description: ${metadata.bio || 'N/A'}\n`;
|
|
92
|
-
output += ` Account ID: ${reg.accountId}\n`;
|
|
93
|
-
output += ` Status: ${reg.status}\n`;
|
|
94
|
-
output += ` Model: ${metadata.properties?.model || 'N/A'}\n`;
|
|
95
|
-
if (metadata.properties?.capabilities && metadata.properties.capabilities.length > 0) {
|
|
96
|
-
output += ` Capabilities: ${metadata.properties.capabilities.join(', ')}\n`;
|
|
97
|
-
}
|
|
98
|
-
if (metadata.properties) {
|
|
99
|
-
output += ` Properties: ${JSON.stringify(metadata.properties)}\n`;
|
|
100
|
-
}
|
|
101
|
-
output += ` Inbound Topic: ${reg.inboundTopicId}\n`;
|
|
102
|
-
output += ` Outbound Topic: ${reg.outboundTopicId}\n`;
|
|
103
|
-
output += ` Created At: ${reg.createdAt}\n`;
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
return output.trim();
|
|
107
|
-
} catch (error) {
|
|
108
|
-
this.logger.error(`Failed to execute findRegistrations: ${error}`);
|
|
109
|
-
return `Error searching registrations: ${
|
|
110
|
-
error instanceof Error ? error.message : String(error)
|
|
111
|
-
}`;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { StructuredTool, ToolParams } from '@langchain/core/tools';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { HCS10Client } from '../hcs10/HCS10Client';
|
|
4
|
-
import { IStateManager, ActiveConnection } from '../state/state-types';
|
|
5
|
-
import { Logger } from '@hashgraphonline/standards-sdk';
|
|
6
|
-
|
|
7
|
-
export interface InitiateConnectionToolParams extends ToolParams {
|
|
8
|
-
hcsClient: HCS10Client;
|
|
9
|
-
stateManager: IStateManager;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A tool to actively START a NEW HCS-10 connection TO a target agent.
|
|
14
|
-
* Requires the target agent's account ID.
|
|
15
|
-
* It retrieves their profile, sends a connection request, waits for confirmation, and stores the connection using the provided stateManager.
|
|
16
|
-
* Use this tool ONLY to actively INITIATE an OUTGOING connection.
|
|
17
|
-
*/
|
|
18
|
-
export class InitiateConnectionTool extends StructuredTool {
|
|
19
|
-
name = 'initiate_connection';
|
|
20
|
-
description =
|
|
21
|
-
'Actively STARTS a NEW HCS-10 connection TO a specific target agent identified by their account ID. Requires the targetAccountId parameter. Use this ONLY to INITIATE an OUTGOING connection request.';
|
|
22
|
-
schema = z.object({
|
|
23
|
-
targetAccountId: z
|
|
24
|
-
.string()
|
|
25
|
-
.describe(
|
|
26
|
-
'The Hedera account ID (e.g., 0.0.12345) of the agent you want to connect with.'
|
|
27
|
-
)
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
private hcsClient: HCS10Client;
|
|
31
|
-
private stateManager: IStateManager;
|
|
32
|
-
private logger: Logger;
|
|
33
|
-
|
|
34
|
-
constructor({
|
|
35
|
-
hcsClient,
|
|
36
|
-
stateManager,
|
|
37
|
-
...rest
|
|
38
|
-
}: InitiateConnectionToolParams) {
|
|
39
|
-
super(rest);
|
|
40
|
-
this.hcsClient = hcsClient;
|
|
41
|
-
this.stateManager = stateManager;
|
|
42
|
-
this.logger = Logger.getInstance({ module: 'InitiateConnectionTool' });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
protected async _call({
|
|
46
|
-
targetAccountId
|
|
47
|
-
}: z.infer<this['schema']>): Promise<string> {
|
|
48
|
-
const currentAgent = this.stateManager.getCurrentAgent();
|
|
49
|
-
if (!currentAgent) {
|
|
50
|
-
return 'Error: Cannot initiate connection. No agent is currently active. Please register or select an agent first.';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.logger.info(
|
|
54
|
-
`Attempting connection from ${currentAgent.accountId} to ${targetAccountId}`
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
this.logger.debug(`Retrieving profile for ${targetAccountId}...`);
|
|
59
|
-
const targetProfile = await this.hcsClient.getAgentProfile(
|
|
60
|
-
targetAccountId
|
|
61
|
-
);
|
|
62
|
-
if (!targetProfile?.topicInfo?.inboundTopic) {
|
|
63
|
-
return `Error: Could not retrieve profile or find inbound topic ID for target agent ${targetAccountId}. They might not be registered or have a public profile.`;
|
|
64
|
-
}
|
|
65
|
-
const targetInboundTopicId = targetProfile.topicInfo.inboundTopic;
|
|
66
|
-
const targetAgentName =
|
|
67
|
-
targetProfile.profile.name || `Agent ${targetAccountId}`;
|
|
68
|
-
|
|
69
|
-
const requestResult = await this.hcsClient.submitConnectionRequest(
|
|
70
|
-
targetInboundTopicId,
|
|
71
|
-
currentAgent.name
|
|
72
|
-
);
|
|
73
|
-
const sequenceNumberLong = requestResult?.topicSequenceNumber;
|
|
74
|
-
if (!sequenceNumberLong) {
|
|
75
|
-
throw new Error('Connection request sequence number not found.');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let connectionRequestId: number;
|
|
79
|
-
try {
|
|
80
|
-
connectionRequestId = sequenceNumberLong.toNumber();
|
|
81
|
-
if (isNaN(connectionRequestId)) {
|
|
82
|
-
throw new Error('Converted sequence number is NaN.');
|
|
83
|
-
}
|
|
84
|
-
} catch (conversionError) {
|
|
85
|
-
throw new Error(
|
|
86
|
-
`Failed to convert connection request sequence number: ${conversionError}`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const confirmationTimeoutMs = 60000;
|
|
91
|
-
const delayMs = 2000;
|
|
92
|
-
const maxAttempts = Math.ceil(confirmationTimeoutMs / delayMs);
|
|
93
|
-
|
|
94
|
-
const confirmationResult =
|
|
95
|
-
await this.hcsClient.waitForConnectionConfirmation(
|
|
96
|
-
targetInboundTopicId,
|
|
97
|
-
connectionRequestId,
|
|
98
|
-
maxAttempts,
|
|
99
|
-
delayMs
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
if (!confirmationResult?.connectionTopicId) {
|
|
103
|
-
return `Error: Connection confirmation not received from ${targetAccountId} (for request ${connectionRequestId}) within ${
|
|
104
|
-
confirmationTimeoutMs / 1000
|
|
105
|
-
} seconds.`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const connectionTopicId = confirmationResult.connectionTopicId;
|
|
109
|
-
this.logger.info(`Connection confirmed! Topic ID: ${connectionTopicId}`);
|
|
110
|
-
|
|
111
|
-
const newConnection: ActiveConnection = {
|
|
112
|
-
targetAccountId: targetAccountId,
|
|
113
|
-
targetAgentName: targetAgentName,
|
|
114
|
-
targetInboundTopicId: targetInboundTopicId,
|
|
115
|
-
connectionTopicId: connectionTopicId,
|
|
116
|
-
};
|
|
117
|
-
this.stateManager.addActiveConnection(newConnection);
|
|
118
|
-
|
|
119
|
-
const connections = this.stateManager.listConnections();
|
|
120
|
-
const addedEntry = connections.find(
|
|
121
|
-
(c) => c.connectionTopicId === connectionTopicId
|
|
122
|
-
);
|
|
123
|
-
const localConnectionId = addedEntry
|
|
124
|
-
? connections.indexOf(addedEntry) + 1
|
|
125
|
-
: null;
|
|
126
|
-
|
|
127
|
-
const idString = localConnectionId ? `#${localConnectionId}` : '';
|
|
128
|
-
|
|
129
|
-
return `Successfully established connection ${idString} with ${targetAgentName} (${targetAccountId}). Connection Topic: ${connectionTopicId}. You can now send messages using this connection.`;
|
|
130
|
-
} catch (error) {
|
|
131
|
-
this.logger.error(`Connection initiation failed: ${error}`);
|
|
132
|
-
return `Error initiating connection with ${targetAccountId}: ${
|
|
133
|
-
error instanceof Error ? error.message : String(error)
|
|
134
|
-
}`;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { StructuredTool, ToolParams } from '@langchain/core/tools';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { IStateManager, ActiveConnection } from '../state/state-types';
|
|
4
|
-
import { HCS10Client } from '../hcs10/HCS10Client';
|
|
5
|
-
import { Connection, Logger } from '@hashgraphonline/standards-sdk';
|
|
6
|
-
|
|
7
|
-
export interface ListConnectionsToolParams extends ToolParams {
|
|
8
|
-
stateManager: IStateManager;
|
|
9
|
-
hcsClient?: HCS10Client;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A tool to list currently active HCS-10 connections stored in the state manager.
|
|
14
|
-
* Enhanced to show more details similar to moonscape's implementation.
|
|
15
|
-
*/
|
|
16
|
-
export class ListConnectionsTool extends StructuredTool {
|
|
17
|
-
name = 'list_connections';
|
|
18
|
-
description =
|
|
19
|
-
'Lists the currently active HCS-10 connections with detailed information. Shows connection status, agent details, and recent activity. Use this to get a comprehensive view of all active connections.';
|
|
20
|
-
schema = z.object({
|
|
21
|
-
includeDetails: z
|
|
22
|
-
.boolean()
|
|
23
|
-
.optional()
|
|
24
|
-
.describe(
|
|
25
|
-
'Whether to include detailed information about each connection'
|
|
26
|
-
),
|
|
27
|
-
showPending: z
|
|
28
|
-
.boolean()
|
|
29
|
-
.optional()
|
|
30
|
-
.describe('Whether to include pending connection requests'),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
private stateManager: IStateManager;
|
|
34
|
-
private hcsClient?: HCS10Client;
|
|
35
|
-
private logger: Logger;
|
|
36
|
-
|
|
37
|
-
constructor({ stateManager, hcsClient, ...rest }: ListConnectionsToolParams) {
|
|
38
|
-
super(rest);
|
|
39
|
-
this.stateManager = stateManager;
|
|
40
|
-
this.hcsClient = hcsClient;
|
|
41
|
-
this.logger = new Logger({ module: 'ListConnectionsTool' });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected async _call(args: z.infer<this['schema']>): Promise<string> {
|
|
45
|
-
const includeDetails = args.includeDetails ?? true;
|
|
46
|
-
const showPending = args.showPending ?? true;
|
|
47
|
-
|
|
48
|
-
const connections = await this.getEnhancedConnections();
|
|
49
|
-
|
|
50
|
-
if (connections.length === 0) {
|
|
51
|
-
return 'There are currently no active connections.';
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const activeConnections = connections.filter(
|
|
55
|
-
(c) => c.status === 'established'
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const pendingConnections = connections.filter((c) => c.isPending);
|
|
59
|
-
|
|
60
|
-
const needsConfirmation = connections.filter((c) => c.needsConfirmation);
|
|
61
|
-
|
|
62
|
-
let output = '';
|
|
63
|
-
|
|
64
|
-
if (activeConnections.length > 0) {
|
|
65
|
-
output += `🟢 Active Connections (${activeConnections.length}):\n`;
|
|
66
|
-
activeConnections.forEach((conn, index) => {
|
|
67
|
-
output += this.formatConnection(conn, index, includeDetails);
|
|
68
|
-
});
|
|
69
|
-
output += '\n';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (showPending && needsConfirmation.length > 0) {
|
|
73
|
-
output += `🟠 Connections Needing Confirmation (${needsConfirmation.length}):\n`;
|
|
74
|
-
needsConfirmation.forEach((conn, index) => {
|
|
75
|
-
output += this.formatConnection(conn, index, includeDetails);
|
|
76
|
-
});
|
|
77
|
-
output += '\n';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (showPending && pendingConnections.length > 0) {
|
|
81
|
-
output += `⚪ Pending Connection Requests (${pendingConnections.length}):\n`;
|
|
82
|
-
pendingConnections.forEach((conn, index) => {
|
|
83
|
-
output += this.formatConnection(conn, index, includeDetails);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return output.trim();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private formatConnection(
|
|
91
|
-
conn: Connection,
|
|
92
|
-
index: number,
|
|
93
|
-
includeDetails: boolean
|
|
94
|
-
): string {
|
|
95
|
-
let output = `${index + 1}. ${
|
|
96
|
-
conn.profileInfo?.display_name || conn.targetAgentName || 'Unknown Agent'
|
|
97
|
-
} (${conn.targetAccountId})\n`;
|
|
98
|
-
const displayTopicId = conn.isPending
|
|
99
|
-
? '(Pending Request)'
|
|
100
|
-
: conn.connectionTopicId;
|
|
101
|
-
output += ` Topic: ${displayTopicId}\n`;
|
|
102
|
-
const statusText = conn.status || 'unknown';
|
|
103
|
-
output += ` Status: ${statusText}\n`;
|
|
104
|
-
|
|
105
|
-
if (includeDetails) {
|
|
106
|
-
if (conn.profileInfo?.bio) {
|
|
107
|
-
output += ` Bio: ${conn.profileInfo.bio.substring(0, 100)}${
|
|
108
|
-
conn.profileInfo.bio.length > 100 ? '...' : ''
|
|
109
|
-
}\n`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (conn.created) {
|
|
113
|
-
const createdLabel = conn.isPending
|
|
114
|
-
? 'Request sent'
|
|
115
|
-
: 'Connection established';
|
|
116
|
-
output += ` ${createdLabel}: ${conn.created.toLocaleString()}\n`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (conn.lastActivity) {
|
|
120
|
-
output += ` Last activity: ${conn.lastActivity.toLocaleString()}\n`;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return output;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private async getEnhancedConnections(): Promise<Connection[]> {
|
|
128
|
-
if (!this.hcsClient) {
|
|
129
|
-
return this.stateManager.listConnections() as Connection[];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
const { accountId } = this.hcsClient.getAccountAndSigner();
|
|
134
|
-
if (!accountId) {
|
|
135
|
-
return this.stateManager.listConnections() as Connection[];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const connectionManager = this.stateManager.getConnectionsManager();
|
|
139
|
-
if (!connectionManager) {
|
|
140
|
-
this.logger.error('ConnectionsManager not initialized');
|
|
141
|
-
return this.stateManager.listConnections() as Connection[];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const connections = await connectionManager.fetchConnectionData(
|
|
145
|
-
accountId
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
for (const connection of connections) {
|
|
149
|
-
this.stateManager.updateOrAddConnection(connection as ActiveConnection);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return connections;
|
|
153
|
-
} catch (error) {
|
|
154
|
-
console.error('Error fetching connection data:', error);
|
|
155
|
-
return this.stateManager.listConnections() as Connection[];
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|