@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
package/src/plugins/README.md
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
# Plugin Architecture
|
|
2
|
-
|
|
3
|
-
This directory contains a flexible plugin architecture that allows for both platform-specific and platform-agnostic plugins. The goal is to maintain type safety while promoting code reuse across different platforms.
|
|
4
|
-
|
|
5
|
-
## Core Components
|
|
6
|
-
|
|
7
|
-
### Plugin Interfaces
|
|
8
|
-
|
|
9
|
-
- **BasePluginContext**: The foundation for all plugin contexts, includes logging and configuration.
|
|
10
|
-
- **IPluginClient**: A minimal client interface that all platforms should implement.
|
|
11
|
-
- **IPluginStateManager**: A minimal state manager interface for plugin operations.
|
|
12
|
-
- **GenericPluginContext**: Context for platform-agnostic plugins.
|
|
13
|
-
- **PluginContext**: Context specifically for HCS10-based plugins.
|
|
14
|
-
|
|
15
|
-
### Plugin Implementations
|
|
16
|
-
|
|
17
|
-
- **BasePlugin**: Abstract base class that implements the core plugin functionality.
|
|
18
|
-
- **GenericPlugin**: For platform-agnostic plugins that work across implementations.
|
|
19
|
-
- **HCS10Plugin**: For plugins that require HCS10-specific functionality.
|
|
20
|
-
|
|
21
|
-
## Creating Plugins
|
|
22
|
-
|
|
23
|
-
### Generic Plugin Example
|
|
24
|
-
|
|
25
|
-
Generic plugins can be used across different platforms as long as the platform implements the required interfaces:
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { GenericPlugin } from '../src/plugins/GenericPlugin';
|
|
29
|
-
import { GenericPluginContext } from '../src/plugins/PluginInterface';
|
|
30
|
-
import { StructuredTool } from '@langchain/core/tools';
|
|
31
|
-
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
32
|
-
import { z } from 'zod';
|
|
33
|
-
|
|
34
|
-
export class MyGenericPlugin extends GenericPlugin {
|
|
35
|
-
id = 'my-generic-plugin';
|
|
36
|
-
name = 'My Plugin';
|
|
37
|
-
description = 'A cross-platform plugin';
|
|
38
|
-
version = '1.0.0';
|
|
39
|
-
author = 'Your Name';
|
|
40
|
-
|
|
41
|
-
async initialize(context: GenericPluginContext): Promise<void> {
|
|
42
|
-
await super.initialize(context);
|
|
43
|
-
// Your initialization code
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
getTools(): StructuredTool[] {
|
|
47
|
-
return [
|
|
48
|
-
new DynamicStructuredTool({
|
|
49
|
-
name: 'my_tool',
|
|
50
|
-
description: 'Does something useful',
|
|
51
|
-
schema: z.object({
|
|
52
|
-
param: z.string().describe('Parameter description'),
|
|
53
|
-
}),
|
|
54
|
-
func: async ({ param }: { param: string }): Promise<string> => {
|
|
55
|
-
// Tool implementation
|
|
56
|
-
return `Result: ${param}, Network: ${this.context.client.getNetwork()}`;
|
|
57
|
-
},
|
|
58
|
-
}),
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### HCS10-Specific Plugin Example
|
|
65
|
-
|
|
66
|
-
For plugins that need the full HCS10 functionality:
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
import { HCS10Plugin } from '../src/plugins/HCS10Plugin';
|
|
70
|
-
import { PluginContext } from '../src/plugins/PluginInterface';
|
|
71
|
-
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
72
|
-
import { z } from 'zod';
|
|
73
|
-
|
|
74
|
-
export class MyHCS10Plugin extends HCS10Plugin {
|
|
75
|
-
id = 'my-hcs10-plugin';
|
|
76
|
-
name = 'HCS10 Plugin';
|
|
77
|
-
description = 'An HCS10-specific plugin';
|
|
78
|
-
version = '1.0.0';
|
|
79
|
-
author = 'Your Name';
|
|
80
|
-
|
|
81
|
-
async initialize(context: PluginContext): Promise<void> {
|
|
82
|
-
await super.initialize(context);
|
|
83
|
-
// Your HCS10-specific initialization
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
getTools(): StructuredTool[] {
|
|
87
|
-
return [
|
|
88
|
-
new DynamicStructuredTool({
|
|
89
|
-
name: 'hcs10_specific_tool',
|
|
90
|
-
description: 'Uses HCS10-specific functionality',
|
|
91
|
-
schema: z.object({
|
|
92
|
-
param: z.string().describe('Parameter description'),
|
|
93
|
-
}),
|
|
94
|
-
func: async ({ param }: { param: string }): Promise<string> => {
|
|
95
|
-
// HCS10-specific implementation
|
|
96
|
-
return `HCS10 Result for ${param}`;
|
|
97
|
-
},
|
|
98
|
-
}),
|
|
99
|
-
];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## Using in Different Platforms
|
|
105
|
-
|
|
106
|
-
To integrate this plugin system with other platforms:
|
|
107
|
-
|
|
108
|
-
1. Implement the `IPluginClient` interface in your platform's client
|
|
109
|
-
2. Optionally implement `IPluginStateManager` for state management
|
|
110
|
-
3. Create a context factory that provides the appropriate context type
|
|
111
|
-
4. Load plugins using the same loading mechanism
|
|
112
|
-
|
|
113
|
-
This architecture allows reusing generic plugins across platforms while maintaining the ability to create platform-specific plugins when needed.
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { GenericPlugin } from '../GenericPlugin';
|
|
2
|
-
import { GenericPluginContext } from '../PluginInterface';
|
|
3
|
-
import { StructuredTool } from '@langchain/core/tools';
|
|
4
|
-
import { HCS10Client } from '../../hcs10/HCS10Client';
|
|
5
|
-
import { IStateManager } from '../../state/state-types';
|
|
6
|
-
import { OpenConvaiState } from '../../state/open-convai-state';
|
|
7
|
-
|
|
8
|
-
import { RegisterAgentTool } from '../../tools/RegisterAgentTool';
|
|
9
|
-
import { SendMessageTool } from '../../tools/SendMessageTool';
|
|
10
|
-
import { ConnectionTool } from '../../tools/ConnectionTool';
|
|
11
|
-
import { FindRegistrationsTool } from '../../tools/FindRegistrationsTool';
|
|
12
|
-
import { InitiateConnectionTool } from '../../tools/InitiateConnectionTool';
|
|
13
|
-
import { ListConnectionsTool } from '../../tools/ListConnectionsTool';
|
|
14
|
-
import { SendMessageToConnectionTool } from '../../tools/SendMessageToConnectionTool';
|
|
15
|
-
import { CheckMessagesTool } from '../../tools/CheckMessagesTool';
|
|
16
|
-
import { ConnectionMonitorTool } from '../../tools/ConnectionMonitorTool';
|
|
17
|
-
import { ManageConnectionRequestsTool } from '../../tools/ManageConnectionRequestsTool';
|
|
18
|
-
import { AcceptConnectionRequestTool } from '../../tools/AcceptConnectionRequestTool';
|
|
19
|
-
import { RetrieveProfileTool } from '../../tools/RetrieveProfileTool';
|
|
20
|
-
import { ListUnapprovedConnectionRequestsTool } from '../../tools/ListUnapprovedConnectionRequestsTool';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* OpenConvAI Plugin that provides all the tools from standards-agent-kit
|
|
24
|
-
* This plugin enables full HCS-10 agent functionality including registration,
|
|
25
|
-
* connection management, and messaging capabilities.
|
|
26
|
-
*/
|
|
27
|
-
export class OpenConvAIPlugin extends GenericPlugin {
|
|
28
|
-
id = 'openconvai-standards-agent-kit';
|
|
29
|
-
name = 'OpenConvAI Standards Agent Kit Plugin';
|
|
30
|
-
description =
|
|
31
|
-
'Comprehensive plugin providing all HCS-10 agent tools for registration, connections, and messaging';
|
|
32
|
-
version = '1.0.0';
|
|
33
|
-
author = 'Hashgraph Online';
|
|
34
|
-
namespace = 'openconvai';
|
|
35
|
-
|
|
36
|
-
private hcs10Client?: HCS10Client;
|
|
37
|
-
private stateManager?: IStateManager;
|
|
38
|
-
private tools: StructuredTool[] = [];
|
|
39
|
-
|
|
40
|
-
override async initialize(context: GenericPluginContext): Promise<void> {
|
|
41
|
-
await super.initialize(context);
|
|
42
|
-
|
|
43
|
-
if (!(context.client instanceof HCS10Client)) {
|
|
44
|
-
throw new Error('OpenConvAIPlugin requires an HCS10Client instance');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
this.hcs10Client = context.client as HCS10Client;
|
|
48
|
-
|
|
49
|
-
this.stateManager =
|
|
50
|
-
(context.stateManager as IStateManager) || new OpenConvaiState();
|
|
51
|
-
|
|
52
|
-
this.initializeTools();
|
|
53
|
-
|
|
54
|
-
this.context.logger.info(
|
|
55
|
-
'OpenConvAI Standards Agent Kit Plugin initialized successfully'
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private initializeTools(): void {
|
|
60
|
-
if (!this.hcs10Client || !this.stateManager) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
'HCS10Client and StateManager must be initialized before creating tools'
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.tools = [
|
|
67
|
-
new RegisterAgentTool(this.hcs10Client, this.stateManager),
|
|
68
|
-
new SendMessageTool(this.hcs10Client),
|
|
69
|
-
new ConnectionTool({
|
|
70
|
-
client: this.hcs10Client,
|
|
71
|
-
stateManager: this.stateManager,
|
|
72
|
-
}),
|
|
73
|
-
new FindRegistrationsTool({
|
|
74
|
-
hcsClient: this.hcs10Client,
|
|
75
|
-
}),
|
|
76
|
-
new RetrieveProfileTool(this.hcs10Client),
|
|
77
|
-
new InitiateConnectionTool({
|
|
78
|
-
hcsClient: this.hcs10Client,
|
|
79
|
-
stateManager: this.stateManager,
|
|
80
|
-
}),
|
|
81
|
-
new ListConnectionsTool({
|
|
82
|
-
hcsClient: this.hcs10Client,
|
|
83
|
-
stateManager: this.stateManager,
|
|
84
|
-
}),
|
|
85
|
-
new SendMessageToConnectionTool({
|
|
86
|
-
hcsClient: this.hcs10Client,
|
|
87
|
-
stateManager: this.stateManager,
|
|
88
|
-
}),
|
|
89
|
-
new CheckMessagesTool({
|
|
90
|
-
hcsClient: this.hcs10Client,
|
|
91
|
-
stateManager: this.stateManager,
|
|
92
|
-
}),
|
|
93
|
-
new ConnectionMonitorTool({
|
|
94
|
-
hcsClient: this.hcs10Client,
|
|
95
|
-
stateManager: this.stateManager,
|
|
96
|
-
}),
|
|
97
|
-
new ManageConnectionRequestsTool({
|
|
98
|
-
hcsClient: this.hcs10Client,
|
|
99
|
-
stateManager: this.stateManager,
|
|
100
|
-
}),
|
|
101
|
-
new AcceptConnectionRequestTool({
|
|
102
|
-
hcsClient: this.hcs10Client,
|
|
103
|
-
stateManager: this.stateManager,
|
|
104
|
-
}),
|
|
105
|
-
new ListUnapprovedConnectionRequestsTool({
|
|
106
|
-
stateManager: this.stateManager,
|
|
107
|
-
hcsClient: this.hcs10Client,
|
|
108
|
-
}),
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
getTools(): StructuredTool[] {
|
|
113
|
-
return this.tools;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
override async cleanup(): Promise<void> {
|
|
117
|
-
this.tools = [];
|
|
118
|
-
this.hcs10Client = undefined;
|
|
119
|
-
this.stateManager = undefined;
|
|
120
|
-
this.context.logger.info(
|
|
121
|
-
'OpenConvAI Standards Agent Kit Plugin cleaned up'
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './OpenConvAIPlugin';
|
|
@@ -1,196 +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, FeeConfigBuilder } from '@hashgraphonline/standards-sdk';
|
|
6
|
-
|
|
7
|
-
export interface AcceptConnectionRequestToolParams extends ToolParams {
|
|
8
|
-
hcsClient: HCS10Client;
|
|
9
|
-
stateManager: IStateManager;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A tool specifically for accepting incoming connection requests.
|
|
14
|
-
*/
|
|
15
|
-
export class AcceptConnectionRequestTool extends StructuredTool {
|
|
16
|
-
name = 'accept_connection_request';
|
|
17
|
-
description =
|
|
18
|
-
'Accepts a specific pending connection request from another agent, establishing a communication channel.';
|
|
19
|
-
schema = z.object({
|
|
20
|
-
requestKey: z
|
|
21
|
-
.string()
|
|
22
|
-
.describe(
|
|
23
|
-
'The unique request key of the specific request to accept. Use the "manage_connection_requests" tool with action="list" first to get valid keys.'
|
|
24
|
-
),
|
|
25
|
-
hbarFee: z
|
|
26
|
-
.number()
|
|
27
|
-
.optional()
|
|
28
|
-
.describe(
|
|
29
|
-
'Optional HBAR fee amount to charge the connecting agent per message on the new connection topic.'
|
|
30
|
-
),
|
|
31
|
-
exemptAccountIds: z
|
|
32
|
-
.array(z.string())
|
|
33
|
-
.optional()
|
|
34
|
-
.describe(
|
|
35
|
-
'Optional list of account IDs to exempt from any configured fees on the new connection topic.'
|
|
36
|
-
),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
private hcsClient: HCS10Client;
|
|
40
|
-
private stateManager: IStateManager;
|
|
41
|
-
private logger: Logger;
|
|
42
|
-
|
|
43
|
-
constructor({
|
|
44
|
-
hcsClient,
|
|
45
|
-
stateManager,
|
|
46
|
-
...rest
|
|
47
|
-
}: AcceptConnectionRequestToolParams) {
|
|
48
|
-
super(rest);
|
|
49
|
-
this.hcsClient = hcsClient;
|
|
50
|
-
this.stateManager = stateManager;
|
|
51
|
-
this.logger = Logger.getInstance({
|
|
52
|
-
module: 'AcceptConnectionRequestTool',
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected async _call({
|
|
57
|
-
requestKey,
|
|
58
|
-
hbarFee,
|
|
59
|
-
exemptAccountIds,
|
|
60
|
-
}: z.infer<this['schema']>): Promise<string> {
|
|
61
|
-
const currentAgent = this.stateManager.getCurrentAgent();
|
|
62
|
-
if (!currentAgent) {
|
|
63
|
-
return 'Error: Cannot accept connection request. No agent is currently active. Please register or select an agent first.';
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const connectionsManager = this.stateManager.getConnectionsManager();
|
|
67
|
-
if (!connectionsManager) {
|
|
68
|
-
return 'Error: ConnectionsManager not initialized';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
await connectionsManager.fetchConnectionData(currentAgent.accountId);
|
|
72
|
-
|
|
73
|
-
// Find the request with the matching unique key or fallback to sequence number
|
|
74
|
-
const allRequests = [
|
|
75
|
-
...connectionsManager.getPendingRequests(),
|
|
76
|
-
...connectionsManager.getConnectionsNeedingConfirmation()
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
const request = allRequests.find(
|
|
80
|
-
(r) => (r.uniqueRequestKey === requestKey) ||
|
|
81
|
-
(r.connectionRequestId?.toString() === requestKey) ||
|
|
82
|
-
(r.inboundRequestId?.toString() === requestKey)
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
if (!request) {
|
|
86
|
-
return `Error: Request with key ${requestKey} not found or no longer pending. Use the manage_connection_requests tool with action="list" to verify.`;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Get the numeric request ID from the request for the SDK call
|
|
90
|
-
const numericRequestId = request.connectionRequestId || request.inboundRequestId;
|
|
91
|
-
if (!numericRequestId) {
|
|
92
|
-
return `Error: Could not determine a valid request ID for the request with key ${requestKey}.`;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
const inboundTopicId = await this.hcsClient.getInboundTopicId();
|
|
97
|
-
let feeConfigBuilder = undefined;
|
|
98
|
-
|
|
99
|
-
if (hbarFee && hbarFee > 0) {
|
|
100
|
-
const collectorId = this.hcsClient.getAccountAndSigner().accountId;
|
|
101
|
-
try {
|
|
102
|
-
feeConfigBuilder = new FeeConfigBuilder({
|
|
103
|
-
network: this.hcsClient.getNetwork(),
|
|
104
|
-
logger: this.logger,
|
|
105
|
-
defaultCollectorAccountId: collectorId,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const finalExemptions = [
|
|
109
|
-
...(exemptAccountIds || []),
|
|
110
|
-
currentAgent.accountId,
|
|
111
|
-
];
|
|
112
|
-
feeConfigBuilder.addHbarFee(hbarFee, collectorId, finalExemptions);
|
|
113
|
-
this.logger.info(
|
|
114
|
-
`Setting HBAR fee: ${hbarFee} HBAR to be collected by ${collectorId}`
|
|
115
|
-
);
|
|
116
|
-
} catch (feeConfigError) {
|
|
117
|
-
this.logger.error(
|
|
118
|
-
`Error creating fee configuration: ${feeConfigError}`
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
feeConfigBuilder = undefined;
|
|
122
|
-
this.logger.warn(
|
|
123
|
-
'Proceeding to accept request without fees due to configuration error.'
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
this.logger.info(
|
|
129
|
-
`Attempting to accept request Key: ${requestKey} (ID: ${numericRequestId}) from ${request.targetAccountId}`
|
|
130
|
-
);
|
|
131
|
-
const result = await this.hcsClient.handleConnectionRequest(
|
|
132
|
-
inboundTopicId,
|
|
133
|
-
request.targetAccountId,
|
|
134
|
-
numericRequestId,
|
|
135
|
-
feeConfigBuilder
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
if (!result?.connectionTopicId) {
|
|
139
|
-
return `Error: Failed to accept connection request with key ${requestKey}. The SDK did not return a connection topic ID.`;
|
|
140
|
-
}
|
|
141
|
-
this.logger.info(
|
|
142
|
-
`Successfully created connection topic: ${result.connectionTopicId}`
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const connectionTopicId = result.connectionTopicId;
|
|
146
|
-
|
|
147
|
-
let targetInboundTopic = '';
|
|
148
|
-
try {
|
|
149
|
-
const targetProfileData = await this.hcsClient.standardClient.retrieveProfile(request.targetAccountId);
|
|
150
|
-
targetInboundTopic =
|
|
151
|
-
targetProfileData?.topicInfo?.inboundTopic || '';
|
|
152
|
-
if (!targetInboundTopic) {
|
|
153
|
-
this.logger.warn(
|
|
154
|
-
`Could not resolve target inbound topic for ${request.targetAccountId}`
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
} catch (e) {
|
|
158
|
-
this.logger.warn(
|
|
159
|
-
`Error fetching target profile/topic for ${request.targetAccountId}: ${e}`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const name = request.profileInfo?.display_name || request.profileInfo?.alias || `Agent ${request.targetAccountId}`;
|
|
164
|
-
const newConnection: ActiveConnection = {
|
|
165
|
-
targetAccountId: request.targetAccountId,
|
|
166
|
-
targetAgentName: name,
|
|
167
|
-
targetInboundTopicId: targetInboundTopic,
|
|
168
|
-
connectionTopicId,
|
|
169
|
-
profileInfo: request.profileInfo,
|
|
170
|
-
created: new Date(),
|
|
171
|
-
status: 'established',
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
this.stateManager.addActiveConnection(newConnection);
|
|
175
|
-
connectionsManager.fetchConnectionData(request.targetAccountId);
|
|
176
|
-
|
|
177
|
-
this.logger.info(`Removed request ${requestKey} from pending requests`);
|
|
178
|
-
|
|
179
|
-
let feeMessage = '';
|
|
180
|
-
if (hbarFee && hbarFee > 0 && feeConfigBuilder) {
|
|
181
|
-
feeMessage = ` with a ${hbarFee} HBAR fee per message`;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const displayKey = request.uniqueRequestKey || requestKey;
|
|
185
|
-
return `Successfully accepted connection request ${displayKey} from ${name} ${feeMessage}. Connection established on topic: ${connectionTopicId}.`;
|
|
186
|
-
} catch (error) {
|
|
187
|
-
this.logger.error(
|
|
188
|
-
`Error accepting connection request ${requestKey}: ${error}`
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
return `Error accepting connection request ${requestKey}: ${
|
|
192
|
-
error instanceof Error ? error.message : String(error)
|
|
193
|
-
}`;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { StructuredTool, ToolParams } from '@langchain/core/tools';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { HCS10Client, HCSMessageWithTimestamp } from '../hcs10/HCS10Client';
|
|
4
|
-
import { IStateManager } from '../state/state-types';
|
|
5
|
-
import { Logger } from '@hashgraphonline/standards-sdk'; // Assuming logger utility
|
|
6
|
-
|
|
7
|
-
export interface CheckMessagesToolParams extends ToolParams {
|
|
8
|
-
hcsClient: HCS10Client;
|
|
9
|
-
stateManager: IStateManager;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A tool to check for new messages on an active HCS-10 connection topic,
|
|
14
|
-
* or optionally fetch the latest messages regardless of timestamp.
|
|
15
|
-
*/
|
|
16
|
-
export class CheckMessagesTool extends StructuredTool {
|
|
17
|
-
name = 'check_messages';
|
|
18
|
-
description = `Checks for and retrieves messages from an active connection.
|
|
19
|
-
Identify the target agent using their account ID (e.g., 0.0.12345) or the connection number shown in 'list_connections'.
|
|
20
|
-
By default, it only retrieves messages newer than the last check.
|
|
21
|
-
Use 'fetchLatest: true' to get the most recent messages regardless of when they arrived.
|
|
22
|
-
Use 'lastMessagesCount' to specify how many latest messages to retrieve (default 1 when fetchLatest is true).`;
|
|
23
|
-
schema = z.object({
|
|
24
|
-
targetIdentifier: z
|
|
25
|
-
.string()
|
|
26
|
-
.describe(
|
|
27
|
-
"The account ID (e.g., 0.0.12345) of the target agent OR the connection number (e.g., '1', '2') from the 'list_connections' tool to check messages for."
|
|
28
|
-
),
|
|
29
|
-
fetchLatest: z
|
|
30
|
-
.boolean()
|
|
31
|
-
.optional()
|
|
32
|
-
.default(false)
|
|
33
|
-
.describe(
|
|
34
|
-
'Set to true to fetch the latest messages even if they have been seen before, ignoring the last checked timestamp. Defaults to false (fetching only new messages).'
|
|
35
|
-
),
|
|
36
|
-
lastMessagesCount: z
|
|
37
|
-
.number()
|
|
38
|
-
.int()
|
|
39
|
-
.positive()
|
|
40
|
-
.optional()
|
|
41
|
-
.describe(
|
|
42
|
-
'When fetchLatest is true, specifies how many of the most recent messages to retrieve. Defaults to 1.'
|
|
43
|
-
),
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
public hcsClient: HCS10Client;
|
|
47
|
-
private stateManager: IStateManager;
|
|
48
|
-
private logger: Logger;
|
|
49
|
-
|
|
50
|
-
constructor({ hcsClient, stateManager, ...rest }: CheckMessagesToolParams) {
|
|
51
|
-
super(rest);
|
|
52
|
-
this.hcsClient = hcsClient;
|
|
53
|
-
this.stateManager = stateManager;
|
|
54
|
-
this.logger = Logger.getInstance({ module: 'CheckMessagesTool' });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
protected async _call({
|
|
58
|
-
targetIdentifier,
|
|
59
|
-
fetchLatest,
|
|
60
|
-
lastMessagesCount,
|
|
61
|
-
}: z.infer<this['schema']>): Promise<string> {
|
|
62
|
-
const connection =
|
|
63
|
-
this.stateManager.getConnectionByIdentifier(targetIdentifier);
|
|
64
|
-
|
|
65
|
-
if (!connection) {
|
|
66
|
-
return `Error: Could not find an active connection matching identifier "${targetIdentifier}". Use 'list_connections' to see active connections.`;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const connectionTopicId = connection.connectionTopicId;
|
|
70
|
-
const targetAgentName = connection.targetAgentName;
|
|
71
|
-
const lastProcessedTimestamp =
|
|
72
|
-
this.stateManager.getLastTimestamp(connectionTopicId);
|
|
73
|
-
|
|
74
|
-
this.logger.info(
|
|
75
|
-
`Checking messages for connection with ${targetAgentName} (${connection.targetAccountId}) on topic ${connectionTopicId} (fetchLatest: ${fetchLatest}, lastCount: ${lastMessagesCount}, since: ${lastProcessedTimestamp})`
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
// 1. Get messages from the topic
|
|
80
|
-
const result = await this.hcsClient.getMessages(connectionTopicId);
|
|
81
|
-
const allMessages = result.messages;
|
|
82
|
-
|
|
83
|
-
if (!allMessages || allMessages.length === 0) {
|
|
84
|
-
return `No messages found on connection topic ${connectionTopicId}.`;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let messagesToProcess: HCSMessageWithTimestamp[] = [];
|
|
88
|
-
let latestTimestampNanos = lastProcessedTimestamp;
|
|
89
|
-
const isFetchingLatest = fetchLatest === true;
|
|
90
|
-
|
|
91
|
-
if (isFetchingLatest) {
|
|
92
|
-
this.logger.info('Fetching latest messages regardless of timestamp.');
|
|
93
|
-
const count = lastMessagesCount ?? 1;
|
|
94
|
-
messagesToProcess = allMessages.slice(-count);
|
|
95
|
-
} else {
|
|
96
|
-
this.logger.info(
|
|
97
|
-
`Filtering for messages newer than ${lastProcessedTimestamp}`
|
|
98
|
-
);
|
|
99
|
-
messagesToProcess = allMessages.filter((msg) => {
|
|
100
|
-
const msgTimestampNanos = msg.timestamp * 1_000_000;
|
|
101
|
-
return msgTimestampNanos > lastProcessedTimestamp;
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
if (messagesToProcess.length > 0) {
|
|
105
|
-
latestTimestampNanos = messagesToProcess.reduce(
|
|
106
|
-
(maxTs, msg) => Math.max(maxTs, msg.timestamp * 1_000_000),
|
|
107
|
-
lastProcessedTimestamp
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (messagesToProcess.length === 0) {
|
|
113
|
-
return isFetchingLatest
|
|
114
|
-
? `Could not retrieve the latest message(s). No messages found on topic ${connectionTopicId}.`
|
|
115
|
-
: `No new messages found for connection with ${targetAgentName} since last check.`;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
this.logger.info(`Processing ${messagesToProcess.length} message(s).`);
|
|
119
|
-
|
|
120
|
-
// 3. Process messages (resolve inscriptions, format)
|
|
121
|
-
let outputString = isFetchingLatest
|
|
122
|
-
? `Latest message(s) from ${targetAgentName}:
|
|
123
|
-
`
|
|
124
|
-
: `New messages from ${targetAgentName}:
|
|
125
|
-
`;
|
|
126
|
-
|
|
127
|
-
for (const msg of messagesToProcess) {
|
|
128
|
-
let content = msg.data;
|
|
129
|
-
try {
|
|
130
|
-
// Check for inscription HRL
|
|
131
|
-
if (typeof content === 'string' && content.startsWith('hcs://')) {
|
|
132
|
-
this.logger.debug(`Resolving inscribed message: ${content}`);
|
|
133
|
-
content = await this.hcsClient.getMessageContent(content);
|
|
134
|
-
this.logger.debug(`Resolved content length: ${content?.length}`);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Attempt to parse the content as the HCS-10 structure
|
|
138
|
-
let displayContent = content; // Default to raw content
|
|
139
|
-
try {
|
|
140
|
-
const parsed = JSON.parse(content || '{}');
|
|
141
|
-
if (
|
|
142
|
-
parsed.p === 'hcs-10' &&
|
|
143
|
-
parsed.op === 'message' &&
|
|
144
|
-
parsed.data
|
|
145
|
-
) {
|
|
146
|
-
// Extract sender and actual data from standard message format
|
|
147
|
-
const senderOpId = parsed.operator_id || 'unknown_sender';
|
|
148
|
-
displayContent = `[${senderOpId}]: ${parsed.data}`;
|
|
149
|
-
} else {
|
|
150
|
-
// If not standard format, maybe just show raw stringified version
|
|
151
|
-
displayContent = content; // Keep raw if parsing worked but not expected format
|
|
152
|
-
}
|
|
153
|
-
} catch (parseError) {
|
|
154
|
-
// Content wasn't JSON, keep raw content
|
|
155
|
-
displayContent = content;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const messageDate = new Date(msg.timestamp);
|
|
159
|
-
outputString += `\n[${messageDate.toLocaleString()}] (Seq: ${
|
|
160
|
-
msg.sequence_number
|
|
161
|
-
})
|
|
162
|
-
${displayContent}
|
|
163
|
-
`;
|
|
164
|
-
} catch (error) {
|
|
165
|
-
const errorMsg = `Error processing message (Seq: ${
|
|
166
|
-
msg.sequence_number
|
|
167
|
-
}): ${error instanceof Error ? error.message : String(error)}`;
|
|
168
|
-
this.logger.error(errorMsg);
|
|
169
|
-
outputString += `\n[Error processing message Seq: ${msg.sequence_number}]\n`;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// 4. Update the timestamp in demo state ONLY if fetching NEW messages
|
|
174
|
-
if (!isFetchingLatest && latestTimestampNanos > lastProcessedTimestamp) {
|
|
175
|
-
this.logger.debug(
|
|
176
|
-
`Updating timestamp for topic ${connectionTopicId} to ${latestTimestampNanos}`
|
|
177
|
-
);
|
|
178
|
-
this.stateManager.updateTimestamp(
|
|
179
|
-
connectionTopicId,
|
|
180
|
-
latestTimestampNanos
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return outputString.trim();
|
|
185
|
-
} catch (error) {
|
|
186
|
-
this.logger.error(
|
|
187
|
-
`Failed to check messages for topic ${connectionTopicId}: ${error}`
|
|
188
|
-
);
|
|
189
|
-
return `Error checking messages for ${targetAgentName}: ${
|
|
190
|
-
error instanceof Error ? error.message : String(error)
|
|
191
|
-
}`;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|