@hashgraphonline/conversational-agent 0.2.215 → 0.2.217
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/cli/readme.md +181 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/SwarmPlugin.d.ts +17 -0
- package/dist/cjs/plugins/community/swarm/__tests__/SwarmPlugin.mocks.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/SwarmPlugin.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.d.ts +14 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadDataTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadFileTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.d.ts +1 -0
- package/dist/cjs/plugins/community/swarm/config.d.ts +6 -0
- package/dist/cjs/plugins/community/swarm/constants.d.ts +8 -0
- package/dist/cjs/plugins/community/swarm/index.d.ts +2 -0
- package/dist/cjs/plugins/community/swarm/model.d.ts +23 -0
- package/dist/cjs/plugins/community/swarm/tools/CreatePostageStampTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/DownloadDataTool.d.ts +35 -0
- package/dist/cjs/plugins/community/swarm/tools/DownloadFilesTool.d.ts +41 -0
- package/dist/cjs/plugins/community/swarm/tools/ExtendPostageStampTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/GetPostageStampTool.d.ts +35 -0
- package/dist/cjs/plugins/community/swarm/tools/ListPostageStampsTool.d.ts +53 -0
- package/dist/cjs/plugins/community/swarm/tools/QueryUploadProgressTool.d.ts +35 -0
- package/dist/cjs/plugins/community/swarm/tools/ReadFeedTool.d.ts +41 -0
- package/dist/cjs/plugins/community/swarm/tools/UpdateFeedTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/UploadDataTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/tools/UploadFileTool.d.ts +53 -0
- package/dist/cjs/plugins/community/swarm/tools/UploadFolderTool.d.ts +47 -0
- package/dist/cjs/plugins/community/swarm/utils.d.ts +22 -0
- package/dist/cjs/plugins/index.d.ts +1 -0
- package/dist/esm/index.js +33 -31
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index10.js +13 -677
- package/dist/esm/index10.js.map +1 -1
- package/dist/esm/index11.js +601 -234
- package/dist/esm/index11.js.map +1 -1
- package/dist/esm/index12.js +296 -136
- package/dist/esm/index12.js.map +1 -1
- package/dist/esm/index13.js +127 -235
- package/dist/esm/index13.js.map +1 -1
- package/dist/esm/index14.js +247 -84
- package/dist/esm/index14.js.map +1 -1
- package/dist/esm/index15.js +81 -159
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index16.js +155 -229
- package/dist/esm/index16.js.map +1 -1
- package/dist/esm/index17.js +238 -140
- package/dist/esm/index17.js.map +1 -1
- package/dist/esm/index18.js +139 -493
- package/dist/esm/index18.js.map +1 -1
- package/dist/esm/index19.js +479 -91
- package/dist/esm/index19.js.map +1 -1
- package/dist/esm/index20.js +88 -147
- package/dist/esm/index20.js.map +1 -1
- package/dist/esm/index21.js +127 -666
- package/dist/esm/index21.js.map +1 -1
- package/dist/esm/index22.js +698 -44
- package/dist/esm/index22.js.map +1 -1
- package/dist/esm/index23.js +45 -304
- package/dist/esm/index23.js.map +1 -1
- package/dist/esm/index24.js +303 -153
- package/dist/esm/index24.js.map +1 -1
- package/dist/esm/index25.js +150 -117
- package/dist/esm/index25.js.map +1 -1
- package/dist/esm/index26.js +154 -18
- package/dist/esm/index26.js.map +1 -1
- package/dist/esm/index27.js +18 -22
- package/dist/esm/index27.js.map +1 -1
- package/dist/esm/index28.js +15 -74
- package/dist/esm/index28.js.map +1 -1
- package/dist/esm/index29.js +70 -295
- package/dist/esm/index29.js.map +1 -1
- package/dist/esm/index30.js +279 -100
- package/dist/esm/index30.js.map +1 -1
- package/dist/esm/index31.js +86 -922
- package/dist/esm/index31.js.map +1 -1
- package/dist/esm/index32.js +904 -189
- package/dist/esm/index32.js.map +1 -1
- package/dist/esm/index33.js +185 -1169
- package/dist/esm/index33.js.map +1 -1
- package/dist/esm/index34.js +1218 -112
- package/dist/esm/index34.js.map +1 -1
- package/dist/esm/index35.js +111 -99
- package/dist/esm/index35.js.map +1 -1
- package/dist/esm/index36.js +113 -8
- package/dist/esm/index36.js.map +1 -1
- package/dist/esm/index37.js +8 -45
- package/dist/esm/index37.js.map +1 -1
- package/dist/esm/index38.js +41 -102
- package/dist/esm/index38.js.map +1 -1
- package/dist/esm/index39.js +96 -55
- package/dist/esm/index39.js.map +1 -1
- package/dist/esm/index4.js +1 -1
- package/dist/esm/index40.js +58 -71
- package/dist/esm/index40.js.map +1 -1
- package/dist/esm/index41.js +79 -21
- package/dist/esm/index41.js.map +1 -1
- package/dist/esm/index42.js +21 -5
- package/dist/esm/index42.js.map +1 -1
- package/dist/esm/index43.js +4 -11
- package/dist/esm/index43.js.map +1 -1
- package/dist/esm/index44.js +12 -322
- package/dist/esm/index44.js.map +1 -1
- package/dist/esm/index45.js +280 -142
- package/dist/esm/index45.js.map +1 -1
- package/dist/esm/index46.js +181 -24
- package/dist/esm/index46.js.map +1 -1
- package/dist/esm/index48.js +67 -85
- package/dist/esm/index48.js.map +1 -1
- package/dist/esm/index49.js +75 -0
- package/dist/esm/index49.js.map +1 -0
- package/dist/esm/index5.js +2 -2
- package/dist/esm/index50.js +57 -0
- package/dist/esm/index50.js.map +1 -0
- package/dist/esm/index51.js +103 -0
- package/dist/esm/index51.js.map +1 -0
- package/dist/esm/index52.js +79 -0
- package/dist/esm/index52.js.map +1 -0
- package/dist/esm/index53.js +75 -0
- package/dist/esm/index53.js.map +1 -0
- package/dist/esm/index54.js +124 -0
- package/dist/esm/index54.js.map +1 -0
- package/dist/esm/index55.js +58 -0
- package/dist/esm/index55.js.map +1 -0
- package/dist/esm/index56.js +83 -0
- package/dist/esm/index56.js.map +1 -0
- package/dist/esm/index57.js +100 -0
- package/dist/esm/index57.js.map +1 -0
- package/dist/esm/index58.js +118 -0
- package/dist/esm/index58.js.map +1 -0
- package/dist/esm/index59.js +108 -0
- package/dist/esm/index59.js.map +1 -0
- package/dist/esm/index6.js +132 -833
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index60.js +30 -0
- package/dist/esm/index60.js.map +1 -0
- package/dist/esm/index61.js +98 -0
- package/dist/esm/index61.js.map +1 -0
- package/dist/esm/index62.js +131 -0
- package/dist/esm/index62.js.map +1 -0
- package/dist/esm/index63.js +19 -0
- package/dist/esm/index63.js.map +1 -0
- package/dist/esm/index7.js +826 -75
- package/dist/esm/index7.js.map +1 -1
- package/dist/esm/index8.js +91 -13
- package/dist/esm/index8.js.map +1 -1
- package/dist/esm/index9.js +13 -17
- package/dist/esm/index9.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugins/community/swarm/SwarmPlugin.d.ts +17 -0
- package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.mocks.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/SwarmPlugin.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.d.ts +14 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UploadDataTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UploadFileTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.d.ts +1 -0
- package/dist/types/plugins/community/swarm/config.d.ts +6 -0
- package/dist/types/plugins/community/swarm/constants.d.ts +8 -0
- package/dist/types/plugins/community/swarm/index.d.ts +2 -0
- package/dist/types/plugins/community/swarm/model.d.ts +23 -0
- package/dist/types/plugins/community/swarm/tools/CreatePostageStampTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/DownloadDataTool.d.ts +35 -0
- package/dist/types/plugins/community/swarm/tools/DownloadFilesTool.d.ts +41 -0
- package/dist/types/plugins/community/swarm/tools/ExtendPostageStampTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/GetPostageStampTool.d.ts +35 -0
- package/dist/types/plugins/community/swarm/tools/ListPostageStampsTool.d.ts +53 -0
- package/dist/types/plugins/community/swarm/tools/QueryUploadProgressTool.d.ts +35 -0
- package/dist/types/plugins/community/swarm/tools/ReadFeedTool.d.ts +41 -0
- package/dist/types/plugins/community/swarm/tools/UpdateFeedTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/UploadDataTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/tools/UploadFileTool.d.ts +53 -0
- package/dist/types/plugins/community/swarm/tools/UploadFolderTool.d.ts +47 -0
- package/dist/types/plugins/community/swarm/utils.d.ts +22 -0
- package/dist/types/plugins/index.d.ts +1 -0
- package/package.json +37 -27
- package/src/index.ts +1 -0
- package/src/plugins/community/swarm/README.md +279 -0
- package/src/plugins/community/swarm/SwarmPlugin.ts +178 -0
- package/src/plugins/community/swarm/__tests__/SwarmPlugin.mocks.ts +105 -0
- package/src/plugins/community/swarm/__tests__/SwarmPlugin.test.ts +93 -0
- package/src/plugins/community/swarm/__tests__/tools/CreatePostageStampTool.test.ts +152 -0
- package/src/plugins/community/swarm/__tests__/tools/DownloadDataTool.test.ts +93 -0
- package/src/plugins/community/swarm/__tests__/tools/DownloadFilesTool.test.ts +163 -0
- package/src/plugins/community/swarm/__tests__/tools/ExtendPostageStampTool.test.ts +132 -0
- package/src/plugins/community/swarm/__tests__/tools/GetPostageStampTool.test.ts +83 -0
- package/src/plugins/community/swarm/__tests__/tools/ListPostageStampsTool.test.ts +219 -0
- package/src/plugins/community/swarm/__tests__/tools/QueryUploadProgressTool.test.ts +169 -0
- package/src/plugins/community/swarm/__tests__/tools/ReadFeedTool.test.ts +133 -0
- package/src/plugins/community/swarm/__tests__/tools/SwarmTool.mocks.ts +67 -0
- package/src/plugins/community/swarm/__tests__/tools/UpdateFeedTool.test.ts +148 -0
- package/src/plugins/community/swarm/__tests__/tools/UploadDataTool.test.ts +125 -0
- package/src/plugins/community/swarm/__tests__/tools/UploadFileTool.test.ts +194 -0
- package/src/plugins/community/swarm/__tests__/tools/UploadFolderTool.test.ts +118 -0
- package/src/plugins/community/swarm/config.ts +6 -0
- package/src/plugins/community/swarm/constants.ts +12 -0
- package/src/plugins/community/swarm/index.ts +2 -0
- package/src/plugins/community/swarm/model.ts +23 -0
- package/src/plugins/community/swarm/tools/CreatePostageStampTool.ts +137 -0
- package/src/plugins/community/swarm/tools/DownloadDataTool.ts +79 -0
- package/src/plugins/community/swarm/tools/DownloadFilesTool.ts +155 -0
- package/src/plugins/community/swarm/tools/ExtendPostageStampTool.ts +112 -0
- package/src/plugins/community/swarm/tools/GetPostageStampTool.ts +92 -0
- package/src/plugins/community/swarm/tools/ListPostageStampsTool.ts +124 -0
- package/src/plugins/community/swarm/tools/QueryUploadProgressTool.ts +109 -0
- package/src/plugins/community/swarm/tools/ReadFeedTool.ts +110 -0
- package/src/plugins/community/swarm/tools/UpdateFeedTool.ts +149 -0
- package/src/plugins/community/swarm/tools/UploadDataTool.ts +109 -0
- package/src/plugins/community/swarm/tools/UploadFileTool.ts +163 -0
- package/src/plugins/community/swarm/tools/UploadFolderTool.ts +150 -0
- package/src/plugins/community/swarm/utils.ts +172 -0
- package/src/plugins/index.ts +1 -0
- package/cli/dist/CLIApp.d.ts +0 -11
- package/cli/dist/CLIApp.d.ts.map +0 -1
- package/cli/dist/CLIApp.js +0 -128
- package/cli/dist/CLIApp.js.map +0 -1
- package/cli/dist/LocalConversationalAgent.d.ts +0 -37
- package/cli/dist/LocalConversationalAgent.js +0 -58
- package/cli/dist/app.d.ts +0 -18
- package/cli/dist/app.d.ts.map +0 -1
- package/cli/dist/app.js +0 -14
- package/cli/dist/app.js.map +0 -1
- package/cli/dist/cli.d.ts +0 -3
- package/cli/dist/cli.d.ts.map +0 -1
- package/cli/dist/cli.js +0 -87
- package/cli/dist/cli.js.map +0 -1
- package/cli/dist/components/AppContainer.d.ts +0 -16
- package/cli/dist/components/AppContainer.js +0 -24
- package/cli/dist/components/AppScreens.d.ts +0 -2
- package/cli/dist/components/AppScreens.js +0 -259
- package/cli/dist/components/ChatScreen.d.ts +0 -21
- package/cli/dist/components/ChatScreen.d.ts.map +0 -1
- package/cli/dist/components/ChatScreen.js +0 -40
- package/cli/dist/components/ChatScreen.js.map +0 -1
- package/cli/dist/components/DebugLoadingScreen.d.ts +0 -5
- package/cli/dist/components/DebugLoadingScreen.js +0 -31
- package/cli/dist/components/LoadingScreen.d.ts +0 -3
- package/cli/dist/components/LoadingScreen.d.ts.map +0 -1
- package/cli/dist/components/LoadingScreen.js +0 -17
- package/cli/dist/components/LoadingScreen.js.map +0 -1
- package/cli/dist/components/LoadingScreenDebug.d.ts +0 -5
- package/cli/dist/components/LoadingScreenDebug.js +0 -27
- package/cli/dist/components/MCPConfigScreen.d.ts +0 -28
- package/cli/dist/components/MCPConfigScreen.d.ts.map +0 -1
- package/cli/dist/components/MCPConfigScreen.js +0 -186
- package/cli/dist/components/MCPConfigScreen.js.map +0 -1
- package/cli/dist/components/ScreenRouter.d.ts +0 -13
- package/cli/dist/components/ScreenRouter.d.ts.map +0 -1
- package/cli/dist/components/ScreenRouter.js +0 -23
- package/cli/dist/components/ScreenRouter.js.map +0 -1
- package/cli/dist/components/SetupScreen.d.ts +0 -16
- package/cli/dist/components/SetupScreen.d.ts.map +0 -1
- package/cli/dist/components/SetupScreen.js +0 -67
- package/cli/dist/components/SetupScreen.js.map +0 -1
- package/cli/dist/components/SingleLoadingScreen.d.ts +0 -5
- package/cli/dist/components/SingleLoadingScreen.js +0 -27
- package/cli/dist/components/StatusBadge.d.ts +0 -10
- package/cli/dist/components/StatusBadge.d.ts.map +0 -1
- package/cli/dist/components/StatusBadge.js +0 -24
- package/cli/dist/components/StatusBadge.js.map +0 -1
- package/cli/dist/components/TerminalWindow.d.ts +0 -9
- package/cli/dist/components/TerminalWindow.d.ts.map +0 -1
- package/cli/dist/components/TerminalWindow.js +0 -19
- package/cli/dist/components/TerminalWindow.js.map +0 -1
- package/cli/dist/components/WelcomeScreen.d.ts +0 -12
- package/cli/dist/components/WelcomeScreen.d.ts.map +0 -1
- package/cli/dist/components/WelcomeScreen.js +0 -47
- package/cli/dist/components/WelcomeScreen.js.map +0 -1
- package/cli/dist/context/AppContext.d.ts +0 -68
- package/cli/dist/context/AppContext.js +0 -363
- package/cli/dist/headless-runner.d.ts +0 -17
- package/cli/dist/headless-runner.d.ts.map +0 -1
- package/cli/dist/headless-runner.js +0 -128
- package/cli/dist/headless-runner.js.map +0 -1
- package/cli/dist/hooks/useInitializeAgent.d.ts +0 -19
- package/cli/dist/hooks/useInitializeAgent.d.ts.map +0 -1
- package/cli/dist/hooks/useInitializeAgent.js +0 -29
- package/cli/dist/hooks/useInitializeAgent.js.map +0 -1
- package/cli/dist/hooks/useStableState.d.ts +0 -38
- package/cli/dist/hooks/useStableState.d.ts.map +0 -1
- package/cli/dist/hooks/useStableState.js +0 -69
- package/cli/dist/hooks/useStableState.js.map +0 -1
- package/cli/dist/managers/AgentManager.d.ts +0 -58
- package/cli/dist/managers/AgentManager.d.ts.map +0 -1
- package/cli/dist/managers/AgentManager.js +0 -121
- package/cli/dist/managers/AgentManager.js.map +0 -1
- package/cli/dist/managers/ConfigManager.d.ts +0 -54
- package/cli/dist/managers/ConfigManager.d.ts.map +0 -1
- package/cli/dist/managers/ConfigManager.js +0 -188
- package/cli/dist/managers/ConfigManager.js.map +0 -1
- package/cli/dist/types.d.ts +0 -52
- package/cli/dist/types.d.ts.map +0 -1
- package/cli/dist/types.js +0 -34
- package/cli/dist/types.js.map +0 -1
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# Swarm Plugin
|
|
2
|
+
|
|
3
|
+
The Swarm Plugin provides tools for interacting with the Swarm decentralized storage.
|
|
4
|
+
|
|
5
|
+
To upload data to Swarm, you must first purchase storage capcity in the form of postage stamps. These stamps represent the right to store a certain amount of data for a specific duration. Swarm Gateways will use their underlying postage stamp batches for uploads.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Upload text data to Swarm.
|
|
10
|
+
- Download text data from Swarm.
|
|
11
|
+
- Upload files and folders to Swarm.
|
|
12
|
+
- Download files and folders from Swarm.
|
|
13
|
+
- Update data on a Swarm feed.
|
|
14
|
+
- Read latest data from a Swarm feed.
|
|
15
|
+
- Create postage stamp batches for storage.
|
|
16
|
+
- Get a postage stamp batch.
|
|
17
|
+
- List postage stamp batches.
|
|
18
|
+
- Extend storage and duration of a postage stamp batch.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Configuration Options
|
|
22
|
+
|
|
23
|
+
| Option | Type | Default | Description |
|
|
24
|
+
| -----------------------------------| --------------| --------------| --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `beeApiUrl` | string | **required** | The URL of the Bee node or of the Swarm Gateway. When using a gateway, its postage stamp will be used for uploads and postage stamp tools won't function. |
|
|
26
|
+
| `beeFeedPK` | string | **required** | The signer's private key used for updating the feed. |
|
|
27
|
+
| `autoAssignStamp` | boolean | undefined | If true, the batch with highest capacity is used for uploads. |
|
|
28
|
+
| `deferredUploadSizeThresholdMB` | number | undefined | The threshold above which file upload is deferred. Default is 5 MB. |
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { ConversationalAgent, SwarmPlugin, SwarmConfig } from "@hashgraphonline/conversational-agent";
|
|
35
|
+
|
|
36
|
+
const swarmConfig: SwarmConfig = {
|
|
37
|
+
beeApiUrl: process.env.SWARM_BEE_API_URL || "https://api.gateway.ethswarm.org",
|
|
38
|
+
beeFeedPK: process.env.SWARM_BEE_FEED_PK!,
|
|
39
|
+
autoAssignStamp: true,
|
|
40
|
+
deferredUploadSizeThresholdMB: Number(process.env.DEFERRED_UPLOAD_SIZE_THRESHOLD_MB!),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Initialize the agent
|
|
44
|
+
const agent = new ConversationalAgent({
|
|
45
|
+
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
46
|
+
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
47
|
+
network: 'testnet',
|
|
48
|
+
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
49
|
+
openAIModelName: 'gpt-4o',
|
|
50
|
+
verbose: true,
|
|
51
|
+
additionalPlugins: [new SwarmPlugin(swarmConfig)],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Initialize (automatically detects key type)
|
|
55
|
+
await agent.initialize();
|
|
56
|
+
|
|
57
|
+
// Process a message
|
|
58
|
+
const response = await agent.processMessage(
|
|
59
|
+
"List my stamps."
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Plugin Tools
|
|
66
|
+
|
|
67
|
+
The plugin provides the following tools:
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### `swarm-create-postage-stamp`
|
|
71
|
+
|
|
72
|
+
Buy postage stamp batch based on size in megabytes and duration.
|
|
73
|
+
|
|
74
|
+
**Parameters:**
|
|
75
|
+
|
|
76
|
+
- `size`: The storage size in MB (Megabytes). These other size units convert like this to MB: 1 byte = 0.000001 MB, 1 KB = 0.001 MB, 1GB= 1000MB.
|
|
77
|
+
- `duration`: Duration for which the data should be stored. Time to live of the postage stamp batch, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.
|
|
78
|
+
- `label`: (Optional) Sets label for the postage stamp batch.
|
|
79
|
+
|
|
80
|
+
**Sample prompt:**
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
Create new stamp with 4 days, 10 megabytes.
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### `swarm-get-postage-stamp`
|
|
87
|
+
|
|
88
|
+
Get a specific postage stamp batch based on batch id.
|
|
89
|
+
|
|
90
|
+
**Parameters:**
|
|
91
|
+
|
|
92
|
+
- `postageBatchId`: The id of the postage stamp batch which is requested.
|
|
93
|
+
|
|
94
|
+
**Sample prompt:**
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
Give me the details for batch 3b3881ac37f936a4023a4562c69f1f138df8c1c24994f7b047514fbcbe9388fa.
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
### `swarm-list-postage-stamps`
|
|
102
|
+
|
|
103
|
+
List the available postage stamp batches.
|
|
104
|
+
|
|
105
|
+
**Parameters:**
|
|
106
|
+
|
|
107
|
+
- `leastUsed`: (Optional) A boolean value that tells if postage stamp batches are sorted so least used comes first.
|
|
108
|
+
- `limit`: (Optional) Limit is the maximum number of returned postage stamp batches.
|
|
109
|
+
- `minUsage`: (Optional) Only list postage stamp batches with at least this usage percentage.
|
|
110
|
+
- `maxUsage`: (Optional) Only list postage stamp batches with at most this usage percentage.
|
|
111
|
+
|
|
112
|
+
**Sample prompt:**
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
List my stamps.
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
### `swarm-extend-postage-stamp`
|
|
120
|
+
|
|
121
|
+
Increase the duration (relative to current duration) or size (in megabytes) of a postage stamp batch.
|
|
122
|
+
|
|
123
|
+
**Parameters:**
|
|
124
|
+
|
|
125
|
+
- `postageBatchId`: The id of the postage stamp batch for which extend is performed.
|
|
126
|
+
- `size`: (Optional) The storage size in MB (Megabytes). These other size units convert like this to MB: 1 byte = 0.000001 MB, 1 KB = 0.001 MB, 1GB= 1000MB.
|
|
127
|
+
- `duration`: (Optional) Duration for which the data should be stored. Time to live of the postage stamp batch, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.
|
|
128
|
+
|
|
129
|
+
**Sample prompt:**
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
Extend 3b3881ac37f936a4023a4562c69f1f138df8c1c24994f7b047514fbcbe9388fa to 5 days.
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
### `swarm-upload-data`
|
|
137
|
+
|
|
138
|
+
Upload text data to Swarm.
|
|
139
|
+
|
|
140
|
+
**Parameters:**
|
|
141
|
+
|
|
142
|
+
- `data`: Arbitrary string to upload.
|
|
143
|
+
- `redundancyLevel`: (Optional) Redundancy level for fault tolerance: 0 - none, 1 - medium, 2 - strong, 3 - insane, 4 - paranoid (higher values provide better fault tolerance but increase storage overhead). Optional, value is 0 if not requested.
|
|
144
|
+
- `postageBatchId`: (Optional) The postage stamp batch ID which will be used to perform the upload, if it is provided.
|
|
145
|
+
|
|
146
|
+
**Sample prompt:**
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
Upload data to Swarm: Hello World!.
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
### `swarm-download-data`
|
|
154
|
+
|
|
155
|
+
Downloads immutable data from a Swarm content address hash.
|
|
156
|
+
|
|
157
|
+
**Parameters:**
|
|
158
|
+
|
|
159
|
+
- `reference`: Swarm reference hash.
|
|
160
|
+
|
|
161
|
+
**Sample prompt:**
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
Download data from Swarm: 76d133e2798d2b15db55b6c3de01303acd86e43998eab372e25c5a2115bf3f0b.
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
### `swarm-update-feed`
|
|
169
|
+
|
|
170
|
+
Update the feed of a given topic with new data.
|
|
171
|
+
|
|
172
|
+
**Parameters:**
|
|
173
|
+
|
|
174
|
+
- `data`: Arbitrary string to upload.
|
|
175
|
+
- `memoryTopic`: If provided, uploads the lastes data to a feed with this topic. It is the label of the memory that can be used later to retrieve the data instead of its content hash. If not a hex string, it will be hashed to create a feed topic.
|
|
176
|
+
- `postageBatchId`: (Optional) The postage stamp batch ID which will be used to perform the upload, if it is provided.
|
|
177
|
+
|
|
178
|
+
**Sample prompt:**
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
Update the Swarm feed of Topic1 with: Message1 using postage batch id 3b3881ac37f936a4023a4562c69f1f138df8c1c24994f7b047514fbcbe9388fa.
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
### `swarm-read-feed`
|
|
186
|
+
|
|
187
|
+
Retrieve the latest data from the feed of a given topic.
|
|
188
|
+
|
|
189
|
+
**Parameters:**
|
|
190
|
+
|
|
191
|
+
- `memoryTopic`: Feed topic.
|
|
192
|
+
- `owner`: (Optional) When accessing external memory or feed, ethereum address of the owner must be set..
|
|
193
|
+
|
|
194
|
+
**Sample prompt:**
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
Read the Swarm feed of Topic1.
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
### `swarm-upload-file`
|
|
202
|
+
|
|
203
|
+
Upload a file to Swarm.
|
|
204
|
+
|
|
205
|
+
**Parameters:**
|
|
206
|
+
|
|
207
|
+
- `data`: base64 encoded file content or file path.
|
|
208
|
+
- `isPath`: Wether the data parameter is a path.
|
|
209
|
+
- `redundancyLevel`: (Optional) Redundancy level for fault tolerance (higher values provide better fault tolerance but increase storage overhead). 0 - none, 1 - medium, 2 - strong, 3 - insane, 4 - paranoid.
|
|
210
|
+
- `postageBatchId`: (Optional) The postage stamp batch ID which will be used to perform the upload, if it is provided.
|
|
211
|
+
|
|
212
|
+
**Sample prompt:**
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
Upload to Swarm the file: uploads/file.txt.
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
### `swarm-upload-folder`
|
|
220
|
+
|
|
221
|
+
Upload a folder to Swarm.
|
|
222
|
+
|
|
223
|
+
**Parameters:**
|
|
224
|
+
|
|
225
|
+
- `folderPath`: Path to the folder to upload.
|
|
226
|
+
- `redundancyLevel`: (Optional) Redundancy level for fault tolerance (higher values provide better fault tolerance but increase storage overhead). 0 - none, 1 - medium, 2 - strong, 3 - insane, 4 - paranoid.
|
|
227
|
+
- `postageBatchId`: (Optional) The postage stamp batch ID which will be used to perform the upload, if it is provided.
|
|
228
|
+
|
|
229
|
+
**Sample prompt:**
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
Upload to Swarm folder: /home/conversational-agent-client/uploads.
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
### `swarm-download-files`
|
|
237
|
+
|
|
238
|
+
Download folder, files from a Swarm reference and save to file path or return file list of the reference.
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
**Parameters:**
|
|
242
|
+
|
|
243
|
+
- `reference`: Swarm reference hash.
|
|
244
|
+
- `filePath`: (Optional) Optional file path to save the downloaded content. If not provided list of files in the manifest will be returned.
|
|
245
|
+
|
|
246
|
+
**Sample prompt:**
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
Download from Swarm the file with reference ba35af06601ddf5ac3d71ee33da0db7537215a914fd6a5414b5597bb3d618bdb to folder downloads.
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
### `swarm-query-upload-progress`
|
|
254
|
+
|
|
255
|
+
Query upload progress for a specific upload session identified with the returned Tag ID.
|
|
256
|
+
|
|
257
|
+
**Parameters:**
|
|
258
|
+
|
|
259
|
+
- `tagId`: Tag ID returned by swarm-upload-file and swarm-upload-folder tools to track upload progress.
|
|
260
|
+
|
|
261
|
+
**Sample prompt:**
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
Query Swarm for upload tag with id: 1.
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
## Run tests
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
npm run test src/plugins/community/swarm
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
## Resources
|
|
277
|
+
|
|
278
|
+
- [Official Swarm Documentation](https://docs.ethswarm.org/)
|
|
279
|
+
- [The Book Of Swarm](https://papers.ethswarm.org/p/book-of-swarm/)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BasePlugin,
|
|
3
|
+
type GenericPluginContext,
|
|
4
|
+
type HederaAgentKit,
|
|
5
|
+
type HederaTool,
|
|
6
|
+
} from "hedera-agent-kit";
|
|
7
|
+
import { Bee } from "@ethersphere/bee-js";
|
|
8
|
+
import { ListPostageStampsTool } from "./tools/ListPostageStampsTool";
|
|
9
|
+
import { UploadDataTool } from "./tools/UploadDataTool";
|
|
10
|
+
import { DownloadDataTool } from "./tools/DownloadDataTool";
|
|
11
|
+
import { CreatePostageStampTool } from "./tools/CreatePostageStampTool";
|
|
12
|
+
import { ExtendPostageStampTool } from "./tools/ExtendPostageStampTool";
|
|
13
|
+
import { QueryUploadProgressTool } from "./tools/QueryUploadProgressTool";
|
|
14
|
+
import { DownloadFilesTool } from "./tools/DownloadFilesTool";
|
|
15
|
+
import { GetPostageStampTool } from "./tools/GetPostageStampTool";
|
|
16
|
+
import { ReadFeedTool } from "./tools/ReadFeedTool";
|
|
17
|
+
import { UpdateFeedTool } from "./tools/UpdateFeedTool";
|
|
18
|
+
import { UploadFileTool } from "./tools/UploadFileTool";
|
|
19
|
+
import { UploadFolderTool } from "./tools/UploadFolderTool";
|
|
20
|
+
import { SwarmConfig } from "./config";
|
|
21
|
+
|
|
22
|
+
export class SwarmPlugin extends BasePlugin<GenericPluginContext> {
|
|
23
|
+
id = "swarm";
|
|
24
|
+
name = "Swarm Plugin";
|
|
25
|
+
description =
|
|
26
|
+
"Swarm operations: tools for interacting with the Swarm decentralized storage.";
|
|
27
|
+
version = "1.0.0";
|
|
28
|
+
author = "Solar Punk";
|
|
29
|
+
namespace = "swarm";
|
|
30
|
+
|
|
31
|
+
private config: SwarmConfig | null;
|
|
32
|
+
private tools: HederaTool[] = [];
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
config?: SwarmConfig
|
|
36
|
+
) {
|
|
37
|
+
super();
|
|
38
|
+
this.config = config || null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override async initialize(context: GenericPluginContext): Promise<void> {
|
|
42
|
+
|
|
43
|
+
await super.initialize(context);
|
|
44
|
+
|
|
45
|
+
const hederaKit = context.config.hederaKit as HederaAgentKit | undefined;
|
|
46
|
+
|
|
47
|
+
if (!hederaKit) {
|
|
48
|
+
this.context.logger.warn(
|
|
49
|
+
'SwarmPlugin skipped because HederaAgentKit was not present in plugin context.'
|
|
50
|
+
);
|
|
51
|
+
this.tools = [];
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!this.config) {
|
|
56
|
+
this.context.logger.warn(
|
|
57
|
+
'SwarmPlugin skipped because Swarm config was not present.'
|
|
58
|
+
);
|
|
59
|
+
this.tools = [];
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const beeURL = this.config.beeApiUrl;
|
|
64
|
+
|
|
65
|
+
const bee = new Bee(beeURL);
|
|
66
|
+
|
|
67
|
+
const createPostageStampTool = new CreatePostageStampTool({
|
|
68
|
+
hederaKit,
|
|
69
|
+
bee,
|
|
70
|
+
config: this.config,
|
|
71
|
+
logger: this.context.logger,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const downloadDataTool = new DownloadDataTool({
|
|
75
|
+
hederaKit,
|
|
76
|
+
bee,
|
|
77
|
+
config: this.config,
|
|
78
|
+
logger: this.context.logger,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const downloadFilesTool = new DownloadFilesTool({
|
|
82
|
+
hederaKit,
|
|
83
|
+
bee,
|
|
84
|
+
config: this.config,
|
|
85
|
+
logger: this.context.logger,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const extendPostageStampTool = new ExtendPostageStampTool({
|
|
89
|
+
hederaKit,
|
|
90
|
+
bee,
|
|
91
|
+
config: this.config,
|
|
92
|
+
logger: this.context.logger,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const getPostageStampsTool = new GetPostageStampTool({
|
|
96
|
+
hederaKit,
|
|
97
|
+
bee,
|
|
98
|
+
config: this.config,
|
|
99
|
+
logger: this.context.logger,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const listPostageStampsTool = new ListPostageStampsTool({
|
|
103
|
+
hederaKit,
|
|
104
|
+
bee,
|
|
105
|
+
config: this.config,
|
|
106
|
+
logger: this.context.logger,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const queryUploadProgressTool = new QueryUploadProgressTool({
|
|
110
|
+
hederaKit,
|
|
111
|
+
bee,
|
|
112
|
+
config: this.config,
|
|
113
|
+
logger: this.context.logger,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const readFeedTool = new ReadFeedTool({
|
|
117
|
+
hederaKit,
|
|
118
|
+
bee,
|
|
119
|
+
config: this.config,
|
|
120
|
+
logger: this.context.logger,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const updateFeedTool = new UpdateFeedTool({
|
|
124
|
+
hederaKit,
|
|
125
|
+
bee,
|
|
126
|
+
config: this.config,
|
|
127
|
+
logger: this.context.logger,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const uploadDataTool = new UploadDataTool({
|
|
131
|
+
hederaKit,
|
|
132
|
+
bee,
|
|
133
|
+
config: this.config,
|
|
134
|
+
logger: this.context.logger,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const uploadFileTool = new UploadFileTool({
|
|
138
|
+
hederaKit,
|
|
139
|
+
bee,
|
|
140
|
+
config: this.config,
|
|
141
|
+
logger: this.context.logger,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const uploadFolderTool = new UploadFolderTool({
|
|
145
|
+
hederaKit,
|
|
146
|
+
bee,
|
|
147
|
+
config: this.config,
|
|
148
|
+
logger: this.context.logger,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
this.tools = [
|
|
152
|
+
createPostageStampTool,
|
|
153
|
+
downloadDataTool,
|
|
154
|
+
downloadFilesTool,
|
|
155
|
+
extendPostageStampTool,
|
|
156
|
+
getPostageStampsTool,
|
|
157
|
+
listPostageStampsTool,
|
|
158
|
+
queryUploadProgressTool,
|
|
159
|
+
readFeedTool,
|
|
160
|
+
updateFeedTool,
|
|
161
|
+
uploadDataTool,
|
|
162
|
+
uploadFileTool,
|
|
163
|
+
uploadFolderTool
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
this.context.logger.info(
|
|
167
|
+
"Swarm Plugin initialized."
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
override getTools(): HederaTool[] {
|
|
172
|
+
return this.tools;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
override async cleanup(): Promise<void> {
|
|
176
|
+
this.tools = [];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Must be imported before SwarmPlugin
|
|
2
|
+
import { jest } from '@jest/globals';
|
|
3
|
+
|
|
4
|
+
// Mock hedera-agent-kit
|
|
5
|
+
jest.mock('hedera-agent-kit', () => {
|
|
6
|
+
class MockBasePlugin {
|
|
7
|
+
context = {
|
|
8
|
+
logger: {
|
|
9
|
+
info: jest.fn(),
|
|
10
|
+
warn: jest.fn(),
|
|
11
|
+
error: jest.fn(),
|
|
12
|
+
debug: jest.fn(),
|
|
13
|
+
},
|
|
14
|
+
config: {},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
async initialize(context) {
|
|
18
|
+
this.context = { ...this.context, ...context };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async cleanup() {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
GenericPluginContext: jest.fn(),
|
|
26
|
+
HederaTool: jest.fn(),
|
|
27
|
+
BasePlugin: MockBasePlugin,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
jest.mock('../tools/ListPostageStampsTool', () => ({
|
|
32
|
+
ListPostageStampsTool: class {
|
|
33
|
+
executeQuery = jest.fn();
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
jest.mock('../tools/UploadDataTool', () => ({
|
|
38
|
+
UploadDataTool: class {
|
|
39
|
+
executeQuery = jest.fn();
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
jest.mock('../tools/DownloadDataTool', () => ({
|
|
44
|
+
DownloadDataTool: class {
|
|
45
|
+
executeQuery = jest.fn();
|
|
46
|
+
},
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
jest.mock('../tools/CreatePostageStampTool', () => ({
|
|
50
|
+
CreatePostageStampTool: class {
|
|
51
|
+
executeQuery = jest.fn();
|
|
52
|
+
},
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
jest.mock('../tools/ExtendPostageStampTool', () => ({
|
|
56
|
+
ExtendPostageStampTool: class {
|
|
57
|
+
executeQuery = jest.fn();
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
jest.mock('../tools/QueryUploadProgressTool', () => ({
|
|
62
|
+
QueryUploadProgressTool: class {
|
|
63
|
+
executeQuery = jest.fn();
|
|
64
|
+
},
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
jest.mock('../tools/DownloadFilesTool', () => ({
|
|
68
|
+
DownloadFilesTool: class {
|
|
69
|
+
executeQuery = jest.fn();
|
|
70
|
+
},
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
jest.mock('../tools/GetPostageStampTool', () => ({
|
|
74
|
+
GetPostageStampTool: class {
|
|
75
|
+
executeQuery = jest.fn();
|
|
76
|
+
},
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
jest.mock('../tools/ReadFeedTool', () => ({
|
|
80
|
+
ReadFeedTool: class {
|
|
81
|
+
executeQuery = jest.fn();
|
|
82
|
+
},
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
jest.mock('../tools/UpdateFeedTool', () => ({
|
|
86
|
+
UpdateFeedTool: class {
|
|
87
|
+
executeQuery = jest.fn();
|
|
88
|
+
},
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
jest.mock('../tools/UploadFileTool', () => ({
|
|
92
|
+
UploadFileTool: class {
|
|
93
|
+
executeQuery = jest.fn();
|
|
94
|
+
},
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
jest.mock('../tools/UploadFolderTool', () => ({
|
|
98
|
+
UploadFolderTool: class {
|
|
99
|
+
executeQuery = jest.fn();
|
|
100
|
+
},
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
jest.mock('@ethersphere/bee-js', () => ({
|
|
104
|
+
Bee: class {},
|
|
105
|
+
}));
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comprehensive tests for SwarmPlugin
|
|
3
|
+
* Tests all public methods and initialization scenarios.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, beforeEach, jest } from '@jest/globals';
|
|
7
|
+
|
|
8
|
+
import './SwarmPlugin.mocks';
|
|
9
|
+
|
|
10
|
+
import { BasePlugin, type GenericPluginContext, type HederaAgentKit } from "hedera-agent-kit";
|
|
11
|
+
import { SwarmConfig } from '../config';
|
|
12
|
+
import { SwarmPlugin } from "../SwarmPlugin";
|
|
13
|
+
|
|
14
|
+
describe("SwarmPlugin", () => {
|
|
15
|
+
let plugin: SwarmPlugin;
|
|
16
|
+
let mockContext: GenericPluginContext;
|
|
17
|
+
let hederaKitMock: HederaAgentKit;
|
|
18
|
+
let loggerMock: { info: jest.Mock; warn: jest.Mock };
|
|
19
|
+
let swarmConfig: SwarmConfig;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
loggerMock = {
|
|
24
|
+
info: jest.fn(),
|
|
25
|
+
warn: jest.fn(),
|
|
26
|
+
};
|
|
27
|
+
hederaKitMock = {} as HederaAgentKit; // Mock minimal HederaAgentKit
|
|
28
|
+
mockContext = {
|
|
29
|
+
config: {
|
|
30
|
+
hederaKit: hederaKitMock,
|
|
31
|
+
},
|
|
32
|
+
logger: loggerMock,
|
|
33
|
+
} as unknown as GenericPluginContext;
|
|
34
|
+
|
|
35
|
+
swarmConfig = {
|
|
36
|
+
beeApiUrl: "http://127.0.0.1:1633",
|
|
37
|
+
beeFeedPK: "",
|
|
38
|
+
autoAssignStamp: true,
|
|
39
|
+
deferredUploadSizeThresholdMB: 5
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
plugin = new SwarmPlugin(swarmConfig);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should construct with config", () => {
|
|
46
|
+
plugin = new SwarmPlugin(swarmConfig);
|
|
47
|
+
expect(plugin).toBeInstanceOf(SwarmPlugin);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should skip initialization if hederaKit is missing", async () => {
|
|
51
|
+
plugin = new SwarmPlugin(swarmConfig);
|
|
52
|
+
const contextWithoutKit = { ...mockContext, config: {} };
|
|
53
|
+
await plugin.initialize(contextWithoutKit);
|
|
54
|
+
expect(loggerMock.warn).toHaveBeenCalledWith(
|
|
55
|
+
"SwarmPlugin skipped because HederaAgentKit was not present in plugin context."
|
|
56
|
+
);
|
|
57
|
+
expect(plugin.getTools()).toHaveLength(0);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should skip initialization if config is missing", async () => {
|
|
61
|
+
plugin = new SwarmPlugin();
|
|
62
|
+
await plugin.initialize(mockContext);
|
|
63
|
+
expect(loggerMock.warn).toHaveBeenCalledWith(
|
|
64
|
+
"SwarmPlugin skipped because Swarm config was not present."
|
|
65
|
+
);
|
|
66
|
+
expect(plugin.getTools()).toHaveLength(0);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should initialize all tools and log info with valid config and hederaKit", async () => {
|
|
70
|
+
plugin = new SwarmPlugin(swarmConfig);
|
|
71
|
+
|
|
72
|
+
// Spy on super.initialize (BasePlugin's initialize)
|
|
73
|
+
const superInitializeSpy = jest.spyOn(BasePlugin.prototype, "initialize");
|
|
74
|
+
|
|
75
|
+
await plugin.initialize(mockContext);
|
|
76
|
+
|
|
77
|
+
expect(superInitializeSpy).toHaveBeenCalledWith(mockContext);
|
|
78
|
+
expect(plugin.getTools()).toHaveLength(12);
|
|
79
|
+
|
|
80
|
+
expect(loggerMock.info).toHaveBeenCalledWith(
|
|
81
|
+
"Swarm Plugin initialized."
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("getTools returns empty array after cleanup", async () => {
|
|
86
|
+
plugin = new SwarmPlugin(swarmConfig);
|
|
87
|
+
await plugin.initialize(mockContext);
|
|
88
|
+
expect(plugin.getTools()).toHaveLength(12);
|
|
89
|
+
|
|
90
|
+
await plugin.cleanup();
|
|
91
|
+
expect(plugin.getTools()).toHaveLength(0);
|
|
92
|
+
});
|
|
93
|
+
});
|