@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,148 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
import crypto from 'crypto';
|
|
4
|
+
import { UpdateFeedTool } from '../../tools/UpdateFeedTool';
|
|
5
|
+
import { beeMock, contextMock, mockedUtils, swarmConfigMock } from './SwarmTool.mocks';
|
|
6
|
+
import { getErrorMessage } from '../../utils';
|
|
7
|
+
import { BAD_REQUEST_STATUS } from '../../constants';
|
|
8
|
+
|
|
9
|
+
describe('UpdateFeedTool', () => {
|
|
10
|
+
let tool: UpdateFeedTool;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
tool = new UpdateFeedTool({
|
|
15
|
+
hederaKit: {} as any,
|
|
16
|
+
config: { ...swarmConfigMock, beeFeedPK: 'a'.repeat(64) },
|
|
17
|
+
bee: beeMock,
|
|
18
|
+
logger: contextMock.logger,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should throw if data is missing', async () => {
|
|
23
|
+
await expect(tool['executeQuery']({ memoryTopic: 'topic', data: '' } as any))
|
|
24
|
+
.rejects.toThrow('Missing required parameter: data.');
|
|
25
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
26
|
+
'Missing required parameter: data.'
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should throw if topic is missing', async () => {
|
|
31
|
+
await expect(tool['executeQuery']({ data: 'some data', memoryTopic: '' } as any))
|
|
32
|
+
.rejects.toThrow('Missing required parameter: topic.');
|
|
33
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
34
|
+
'Missing required parameter: topic.'
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should throw if getUploadPostageBatchId fails', async () => {
|
|
39
|
+
const error = new Error('Failed to get postage batch');
|
|
40
|
+
mockedUtils.getUploadPostageBatchId.mockRejectedValue(
|
|
41
|
+
error
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
await expect(tool['executeQuery']({ data: 'hello', memoryTopic: 'topic' }))
|
|
45
|
+
.rejects.toThrow('Failed to get postage batch');
|
|
46
|
+
|
|
47
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith('Failed to get postage batch');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should throw if feed private key is not configured', async () => {
|
|
51
|
+
tool.config.beeFeedPK = '';
|
|
52
|
+
mockedUtils.getUploadPostageBatchId.mockResolvedValue('batch-id');
|
|
53
|
+
|
|
54
|
+
await expect(tool['executeQuery']({ data: 'hi', memoryTopic: 'topic' }))
|
|
55
|
+
.rejects.toThrow('Feed private key not configured.');
|
|
56
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
57
|
+
'Feed private key not configured.'
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should hash non-hex topic and call bee.makeFeedWriter', async () => {
|
|
62
|
+
const topic = 'nonHexTopic';
|
|
63
|
+
const hash = crypto.createHash('sha256').update(topic).digest('hex');
|
|
64
|
+
|
|
65
|
+
mockedUtils.getUploadPostageBatchId.mockResolvedValue('batch-id');
|
|
66
|
+
|
|
67
|
+
const uploadPayloadMock = jest.fn().mockReturnValueOnce({
|
|
68
|
+
reference: { toString: () => 'ref123' },
|
|
69
|
+
});
|
|
70
|
+
const makeFeedWriterMock = jest.fn().mockReturnValue({
|
|
71
|
+
uploadPayload: uploadPayloadMock,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
(beeMock.makeFeedWriter as unknown as jest.Mock).mockImplementation(makeFeedWriterMock);
|
|
75
|
+
const result = await tool['executeQuery']({ data: 'hi', memoryTopic: topic });
|
|
76
|
+
|
|
77
|
+
expect(makeFeedWriterMock).toHaveBeenCalled();
|
|
78
|
+
expect(result["structuredContent"]).toStrictEqual({
|
|
79
|
+
reference: 'ref123',
|
|
80
|
+
topicString: 'nonHexTopic',
|
|
81
|
+
topic: '186143fbcbf933508c828567e5ebffa2cbfa34d7066b15d42ad1eb8c62a7d5db',
|
|
82
|
+
feedUrl: 'http://127.0.0.1:1633/feeds/8fd379246834eac74b8419ffda202cf8051f7a03/186143fbcbf933508c828567e5ebffa2cbfa34d7066b15d42ad1eb8c62a7d5db',
|
|
83
|
+
message: 'Data successfully uploaded to Swarm and linked to feed.'
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should remove 0x prefix from hex topic and succeed', async () => {
|
|
88
|
+
const topic = '0x' + 'a'.repeat(64);
|
|
89
|
+
mockedUtils.getUploadPostageBatchId.mockResolvedValue('batch-id');
|
|
90
|
+
const uploadPayloadMock = jest.fn().mockReturnValueOnce({
|
|
91
|
+
reference: { toString: () => 'ref123' },
|
|
92
|
+
});
|
|
93
|
+
const makeFeedWriterMock = jest.fn().mockReturnValue({
|
|
94
|
+
uploadPayload: uploadPayloadMock,
|
|
95
|
+
});
|
|
96
|
+
(beeMock.makeFeedWriter as unknown as jest.Mock).mockImplementation(makeFeedWriterMock);
|
|
97
|
+
|
|
98
|
+
const result = await tool['executeQuery']({ data: 'hello', memoryTopic: topic });
|
|
99
|
+
|
|
100
|
+
expect(makeFeedWriterMock).toHaveBeenCalled();
|
|
101
|
+
expect(result["structuredContent"]).toStrictEqual({
|
|
102
|
+
reference: 'ref123',
|
|
103
|
+
topicString: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
|
104
|
+
topic: '8d8b3cc160bb728e13db1c032741ad9566b3affd16fc0c805d3caf863694643e',
|
|
105
|
+
feedUrl: 'http://127.0.0.1:1633/feeds/8fd379246834eac74b8419ffda202cf8051f7a03/8d8b3cc160bb728e13db1c032741ad9566b3affd16fc0c805d3caf863694643e',
|
|
106
|
+
message: 'Data successfully uploaded to Swarm and linked to feed.'
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should handle BAD_REQUEST_STATUS error', async () => {
|
|
111
|
+
mockedUtils.getUploadPostageBatchId.mockResolvedValue('batch-id');
|
|
112
|
+
getErrorMessage as jest.MockedFunction<typeof getErrorMessage>;
|
|
113
|
+
(getErrorMessage as jest.Mock).mockReturnValue('Custom bad request message.');
|
|
114
|
+
const error = new Error('Custom bad request message.');
|
|
115
|
+
(error as any).status = BAD_REQUEST_STATUS;
|
|
116
|
+
|
|
117
|
+
(beeMock.makeFeedWriter as unknown as jest.Mock).mockImplementation(() => {
|
|
118
|
+
throw error;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
await expect(tool['executeQuery']({ data: 'test', memoryTopic: '0x' + 'a'.repeat(64) }))
|
|
122
|
+
.rejects.toThrow('Custom bad request message.');
|
|
123
|
+
|
|
124
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
125
|
+
'Custom bad request message.',
|
|
126
|
+
expect.anything()
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should handle generic feed upload error', async () => {
|
|
131
|
+
mockedUtils.getUploadPostageBatchId.mockResolvedValue('batch-id');
|
|
132
|
+
|
|
133
|
+
const error = new Error('Unable to update feed.');
|
|
134
|
+
|
|
135
|
+
(beeMock.makeFeedWriter as unknown as jest.Mock).mockImplementation(() => {
|
|
136
|
+
throw error;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await expect(
|
|
140
|
+
tool['executeQuery']({ data: 'abc', memoryTopic: 'topic' })
|
|
141
|
+
).rejects.toThrow('Unable to update feed.');
|
|
142
|
+
|
|
143
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
144
|
+
'Unable to update feed.',
|
|
145
|
+
expect.any(Error)
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
import { UploadDataTool } from '../../tools/UploadDataTool';
|
|
4
|
+
import { beeMock, contextMock, mockedUtils, swarmConfigMock } from './SwarmTool.mocks';
|
|
5
|
+
import { HederaAgentKit } from 'hedera-agent-kit';
|
|
6
|
+
import { Reference, UploadResult } from '@ethersphere/bee-js';
|
|
7
|
+
import { BAD_REQUEST_STATUS } from '../../constants';
|
|
8
|
+
|
|
9
|
+
describe('UploadDataTool', () => {
|
|
10
|
+
let tool: UploadDataTool;
|
|
11
|
+
const hederaKitMock = {} as HederaAgentKit;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
jest.clearAllMocks();
|
|
15
|
+
|
|
16
|
+
tool = new UploadDataTool({
|
|
17
|
+
hederaKit: hederaKitMock,
|
|
18
|
+
config: swarmConfigMock,
|
|
19
|
+
bee: beeMock,
|
|
20
|
+
logger: contextMock.logger,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Mock successful postage batch ID fetch
|
|
24
|
+
mockedUtils.getUploadPostageBatchId.mockResolvedValue('postage123');
|
|
25
|
+
|
|
26
|
+
// Mock upload result
|
|
27
|
+
const reference = { toString: () => 'data123' } as unknown as Reference;
|
|
28
|
+
const uploadResult = { reference } as unknown as UploadResult;
|
|
29
|
+
beeMock.uploadData.mockResolvedValue(uploadResult);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('uploads simple data successfully', async () => {
|
|
33
|
+
const result = await tool['executeQuery']({ data: 'hello swarm' });
|
|
34
|
+
|
|
35
|
+
expect(mockedUtils.getUploadPostageBatchId).toHaveBeenCalledWith(
|
|
36
|
+
undefined,
|
|
37
|
+
beeMock,
|
|
38
|
+
swarmConfigMock
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(beeMock.uploadData).toHaveBeenCalledWith(
|
|
42
|
+
'postage123',
|
|
43
|
+
expect.any(Buffer),
|
|
44
|
+
undefined
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(result['structuredContent']).toEqual(
|
|
48
|
+
expect.objectContaining({
|
|
49
|
+
reference: 'data123',
|
|
50
|
+
url: 'http://127.0.0.1:1633/bytes/data123',
|
|
51
|
+
message: 'Data successfully uploaded to Swarm',
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('uploads data with redundancy level', async () => {
|
|
57
|
+
const result = await tool['executeQuery']({
|
|
58
|
+
data: 'redundant swarm data',
|
|
59
|
+
redundancyLevel: 3,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(beeMock.uploadData).toHaveBeenCalledWith(
|
|
63
|
+
'postage123',
|
|
64
|
+
expect.any(Buffer),
|
|
65
|
+
{ redundancyLevel: 3 }
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(result['structuredContent'].message).toBe(
|
|
69
|
+
'Data successfully uploaded to Swarm'
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('throws error if data is missing', async () => {
|
|
74
|
+
await expect(
|
|
75
|
+
tool['executeQuery']({ data: '' })
|
|
76
|
+
).rejects.toThrow('Missing required parameter: data.');
|
|
77
|
+
|
|
78
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
79
|
+
'Missing required parameter: data.'
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('throws error if getUploadPostageBatchId fails', async () => {
|
|
84
|
+
const error = new Error('Failed to get postage batch');
|
|
85
|
+
mockedUtils.getUploadPostageBatchId.mockRejectedValue(error);
|
|
86
|
+
|
|
87
|
+
await expect(tool['executeQuery']({ data: 'abc' })).rejects.toThrow(
|
|
88
|
+
'Failed to get postage batch'
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith('Failed to get postage batch');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('handles uploadData error gracefully', async () => {
|
|
95
|
+
const error = new Error('Upload failed');
|
|
96
|
+
beeMock.uploadData.mockRejectedValueOnce(error);
|
|
97
|
+
|
|
98
|
+
await expect(tool['executeQuery']({ data: 'abc' })).rejects.toThrow(
|
|
99
|
+
'Unable to upload data.'
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
103
|
+
'Unable to upload data.',
|
|
104
|
+
error
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('handles BAD_REQUEST_STATUS errors using getErrorMessage', async () => {
|
|
109
|
+
const error = new Error();
|
|
110
|
+
(error as any).status = BAD_REQUEST_STATUS;
|
|
111
|
+
beeMock.uploadData.mockRejectedValueOnce(error);
|
|
112
|
+
|
|
113
|
+
mockedUtils.getErrorMessage.mockReturnValue('Bad request: malformed data');
|
|
114
|
+
|
|
115
|
+
await expect(tool['executeQuery']({ data: 'abc' })).rejects.toThrow(
|
|
116
|
+
'Bad request: malformed data'
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
expect(mockedUtils.getErrorMessage).toHaveBeenCalledWith(error);
|
|
120
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
121
|
+
'Bad request: malformed data',
|
|
122
|
+
error
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
import { UploadFileTool } from '../../tools/UploadFileTool';
|
|
4
|
+
import { beeMock, contextMock, mockedUtils, swarmConfigMock } from './SwarmTool.mocks';
|
|
5
|
+
import { HederaAgentKit } from 'hedera-agent-kit';
|
|
6
|
+
import { Reference, UploadResult } from '@ethersphere/bee-js';
|
|
7
|
+
import { GATEWAY_TAG_ERROR_MESSAGE } from '../../constants';
|
|
8
|
+
|
|
9
|
+
describe('UploadFileTool', () => {
|
|
10
|
+
let tool: UploadFileTool;
|
|
11
|
+
const hederaKitMock = {} as HederaAgentKit;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
jest.clearAllMocks();
|
|
15
|
+
|
|
16
|
+
tool = new UploadFileTool({
|
|
17
|
+
hederaKit: hederaKitMock,
|
|
18
|
+
config: swarmConfigMock,
|
|
19
|
+
bee: beeMock,
|
|
20
|
+
logger: contextMock.logger,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Default mocks
|
|
24
|
+
mockedUtils.getUploadPostageBatchId.mockResolvedValue('postage123');
|
|
25
|
+
|
|
26
|
+
const reference = { toString: () => 'postage123' } as unknown as Reference;
|
|
27
|
+
const uploadResult = { reference } as unknown as UploadResult;
|
|
28
|
+
beeMock.uploadFile.mockResolvedValue(uploadResult);
|
|
29
|
+
|
|
30
|
+
const tagDataMock = {
|
|
31
|
+
address: '0x123',
|
|
32
|
+
synced: 50,
|
|
33
|
+
seen: 25,
|
|
34
|
+
split: 100,
|
|
35
|
+
stored: 10,
|
|
36
|
+
sent: 10,
|
|
37
|
+
uid: 123,
|
|
38
|
+
startedAt: '2025-11-04T12:00:00Z',
|
|
39
|
+
};
|
|
40
|
+
beeMock.createTag.mockResolvedValue(tagDataMock);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('uploads base64 data successfully', async () => {
|
|
44
|
+
const data = Buffer.from('hello world').toString('base64');
|
|
45
|
+
|
|
46
|
+
const result = await tool['executeQuery']({
|
|
47
|
+
data,
|
|
48
|
+
isPath: false,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(mockedUtils.getUploadPostageBatchId).toHaveBeenCalledWith(
|
|
52
|
+
undefined,
|
|
53
|
+
beeMock,
|
|
54
|
+
swarmConfigMock
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(beeMock.uploadFile).toHaveBeenCalledWith(
|
|
58
|
+
'postage123',
|
|
59
|
+
expect.any(Buffer),
|
|
60
|
+
undefined,
|
|
61
|
+
expect.objectContaining({ deferred: false })
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(result['structuredContent']).toEqual(
|
|
65
|
+
expect.objectContaining({
|
|
66
|
+
reference: "postage123",
|
|
67
|
+
url: "http://127.0.0.1:1633/bzz/postage123",
|
|
68
|
+
message: "File successfully uploaded to Swarm",
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('uploads file from path successfully', async () => {
|
|
74
|
+
const readFileMock = jest.fn<any>().mockResolvedValue(Buffer.from('file content'));
|
|
75
|
+
jest.spyOn(require('util'), 'promisify').mockReturnValue(readFileMock);
|
|
76
|
+
|
|
77
|
+
const result = await tool['executeQuery']({
|
|
78
|
+
data: '/mock/path/file.txt',
|
|
79
|
+
isPath: true,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(readFileMock).toHaveBeenCalledWith('/mock/path/file.txt');
|
|
83
|
+
expect(beeMock.uploadFile).toHaveBeenCalledWith(
|
|
84
|
+
'postage123',
|
|
85
|
+
expect.any(Buffer),
|
|
86
|
+
'file.txt',
|
|
87
|
+
expect.objectContaining({ deferred: false })
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
expect(result['structuredContent']).toEqual(
|
|
91
|
+
expect.objectContaining({
|
|
92
|
+
reference: 'postage123',
|
|
93
|
+
url: 'http://127.0.0.1:1633/bzz/postage123',
|
|
94
|
+
message: 'File successfully uploaded to Swarm',
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('throws error if data is missing', async () => {
|
|
100
|
+
await expect(
|
|
101
|
+
tool['executeQuery']({ data: '', isPath: false })
|
|
102
|
+
).rejects.toThrow('Missing required parameter: data.');
|
|
103
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
104
|
+
'Missing required parameter: data.'
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('throws error if reading file fails', async () => {
|
|
109
|
+
|
|
110
|
+
const readFileMock = jest.fn<any>().mockRejectedValue(new Error('File read failed'));
|
|
111
|
+
jest.spyOn(require('util'), 'promisify').mockReturnValue(readFileMock);
|
|
112
|
+
jest.spyOn(require('util'), 'promisify').mockReturnValue(readFileMock);
|
|
113
|
+
|
|
114
|
+
await expect(
|
|
115
|
+
tool['executeQuery']({ data: '/bad/path.txt', isPath: true })
|
|
116
|
+
).rejects.toThrow('Unable to read file at path: /bad/path.txt.');
|
|
117
|
+
|
|
118
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
119
|
+
'Unable to read file at path: /bad/path.txt.',
|
|
120
|
+
expect.any(Error)
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('throws error if getUploadPostageBatchId fails', async () => {
|
|
125
|
+
const error = new Error('Failed to get postage batch');
|
|
126
|
+
mockedUtils.getUploadPostageBatchId.mockRejectedValue(error);
|
|
127
|
+
|
|
128
|
+
await expect(
|
|
129
|
+
tool['executeQuery']({ data: 'abc', isPath: false })
|
|
130
|
+
).rejects.toThrow('Failed to get postage batch');
|
|
131
|
+
|
|
132
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith('Failed to get postage batch');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('uploads large file in deferred mode and creates tag', async () => {
|
|
136
|
+
// Pretend threshold is small so any data triggers deferred mode
|
|
137
|
+
swarmConfigMock.deferredUploadSizeThresholdMB = 0.000001;
|
|
138
|
+
|
|
139
|
+
const bigData = Buffer.alloc(1024 * 1024, 'a').toString('base64'); // 1MB
|
|
140
|
+
const result = await tool['executeQuery']({
|
|
141
|
+
data: bigData,
|
|
142
|
+
isPath: false,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
expect(beeMock.createTag).toHaveBeenCalled();
|
|
146
|
+
expect(beeMock.uploadFile).toHaveBeenCalledWith(
|
|
147
|
+
'postage123',
|
|
148
|
+
expect.any(Buffer),
|
|
149
|
+
undefined,
|
|
150
|
+
expect.objectContaining({
|
|
151
|
+
deferred: true,
|
|
152
|
+
tag: 123,
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(result['structuredContent']).toEqual(
|
|
157
|
+
expect.objectContaining({
|
|
158
|
+
tagId: '123',
|
|
159
|
+
message:
|
|
160
|
+
'File upload started in deferred mode. Use query_upload_progress to track progress.',
|
|
161
|
+
})
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('handles createTag 404 and throws GATEWAY_TAG_ERROR_MESSAGE', async () => {
|
|
166
|
+
beeMock.createTag.mockRejectedValue({ status: 404 });
|
|
167
|
+
|
|
168
|
+
swarmConfigMock.deferredUploadSizeThresholdMB = 0.000001;
|
|
169
|
+
const bigData = Buffer.alloc(1024 * 1024, 'a').toString('base64');
|
|
170
|
+
|
|
171
|
+
await expect(
|
|
172
|
+
tool['executeQuery']({ data: bigData, isPath: false })
|
|
173
|
+
).rejects.toThrow(GATEWAY_TAG_ERROR_MESSAGE);
|
|
174
|
+
|
|
175
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
176
|
+
GATEWAY_TAG_ERROR_MESSAGE,
|
|
177
|
+
expect.any(Object)
|
|
178
|
+
);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('handles uploadFile error gracefully', async () => {
|
|
182
|
+
const error = new Error('Upload failed');
|
|
183
|
+
beeMock.uploadFile.mockRejectedValueOnce(error);
|
|
184
|
+
|
|
185
|
+
await expect(
|
|
186
|
+
tool['executeQuery']({ data: 'abc', isPath: false })
|
|
187
|
+
).rejects.toThrow('Unable to upload file.');
|
|
188
|
+
|
|
189
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(
|
|
190
|
+
'Unable to upload file.',
|
|
191
|
+
error
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach, jest } from '@jest/globals';
|
|
2
|
+
import './SwarmTool.mocks';
|
|
3
|
+
import { UploadFolderTool } from "../../tools/UploadFolderTool";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import { beeMock, contextMock, mockedUtils, swarmConfigMock } from './SwarmTool.mocks';
|
|
6
|
+
import { HederaAgentKit } from "hedera-agent-kit";
|
|
7
|
+
import { Reference, UploadResult } from '@ethersphere/bee-js';
|
|
8
|
+
|
|
9
|
+
describe("UploadFolderTool", () => {
|
|
10
|
+
let tool: UploadFolderTool;
|
|
11
|
+
|
|
12
|
+
const hederaKitMock = {} as HederaAgentKit;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
|
|
17
|
+
tool = new UploadFolderTool({
|
|
18
|
+
hederaKit: hederaKitMock,
|
|
19
|
+
config: swarmConfigMock,
|
|
20
|
+
bee: beeMock,
|
|
21
|
+
logger: contextMock.logger,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
mockedUtils.getUploadPostageBatchId.mockResolvedValue('postage123');
|
|
25
|
+
const reference = {
|
|
26
|
+
toString: () => "postage123",
|
|
27
|
+
} as unknown as Reference;
|
|
28
|
+
|
|
29
|
+
const uploadResult = {
|
|
30
|
+
reference
|
|
31
|
+
} as unknown as UploadResult;
|
|
32
|
+
|
|
33
|
+
beeMock.uploadFilesFromDirectory.mockResolvedValue(uploadResult);
|
|
34
|
+
|
|
35
|
+
const tagDataMock = {
|
|
36
|
+
address: '0x123',
|
|
37
|
+
synced: 50,
|
|
38
|
+
seen: 25,
|
|
39
|
+
split: 100,
|
|
40
|
+
stored: 10,
|
|
41
|
+
sent: 10,
|
|
42
|
+
uid: 123,
|
|
43
|
+
startedAt: '2025-11-04T12:00:00Z',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
beeMock.createTag.mockResolvedValue(tagDataMock);
|
|
47
|
+
|
|
48
|
+
const mockStats: fs.Stats = {
|
|
49
|
+
isDirectory: () => true,
|
|
50
|
+
} as unknown as fs.Stats;
|
|
51
|
+
const mockStatFn = jest.fn<any>().mockResolvedValue(mockStats);
|
|
52
|
+
jest.spyOn(require("util"), "promisify").mockReturnValue(mockStatFn);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("uploads folder successfully in deferred mode", async () => {
|
|
56
|
+
const folderPath = "/mock/folder";
|
|
57
|
+
|
|
58
|
+
const result = await tool['executeQuery']({ folderPath });
|
|
59
|
+
|
|
60
|
+
expect(mockedUtils.getUploadPostageBatchId).toHaveBeenCalledWith(undefined, beeMock, swarmConfigMock);
|
|
61
|
+
expect(beeMock.createTag).toHaveBeenCalled();
|
|
62
|
+
expect(beeMock.uploadFilesFromDirectory).toHaveBeenCalledWith(
|
|
63
|
+
"postage123",
|
|
64
|
+
folderPath,
|
|
65
|
+
expect.objectContaining({
|
|
66
|
+
deferred: true,
|
|
67
|
+
tag: 123,
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(result["structuredContent"]).toEqual(expect.objectContaining({
|
|
72
|
+
reference: "postage123",
|
|
73
|
+
url: "http://127.0.0.1:1633/bzz/postage123",
|
|
74
|
+
message: "Folder upload started in deferred mode. Use swarm-query-upload-progress to track progress.",
|
|
75
|
+
tagId: "123",
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("throws error if folderPath is missing", async () => {
|
|
80
|
+
await expect(tool['executeQuery']({ folderPath: "" }))
|
|
81
|
+
.rejects.toThrow("Missing required parameter: folderPath.");
|
|
82
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith("Missing required parameter: folderPath.");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("throws error if path is not a directory", async () => {
|
|
86
|
+
const mockStats: fs.Stats = {
|
|
87
|
+
isDirectory: () => false,
|
|
88
|
+
} as unknown as fs.Stats;
|
|
89
|
+
const mockStatFn = jest.fn<any>().mockResolvedValue(mockStats);
|
|
90
|
+
jest.spyOn(require("util"), "promisify").mockReturnValue(mockStatFn);
|
|
91
|
+
|
|
92
|
+
const folderPath = "/not/a/dir";
|
|
93
|
+
|
|
94
|
+
await expect(tool['executeQuery']({ folderPath }))
|
|
95
|
+
.rejects.toThrow(`Path is not a directory: ${folderPath}.`);
|
|
96
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith(`Path is not a directory: ${folderPath}.`);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("throws error if getUploadPostageBatchId fails", async () => {
|
|
100
|
+
const error = new Error('Failed to get postage batch');
|
|
101
|
+
mockedUtils.getUploadPostageBatchId.mockRejectedValue(
|
|
102
|
+
error
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
await expect(tool['executeQuery']({ folderPath: "/mock/folder" }))
|
|
106
|
+
.rejects.toThrow("Failed to get postage batch");
|
|
107
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith("Failed to get postage batch");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("handles uploadFilesFromDirectory error", async () => {
|
|
111
|
+
const error = new Error("Upload failed");
|
|
112
|
+
beeMock.uploadFilesFromDirectory.mockRejectedValueOnce(error);
|
|
113
|
+
|
|
114
|
+
await expect(tool['executeQuery']({ folderPath: "/mock/folder" }))
|
|
115
|
+
.rejects.toThrow("Unable to upload folder.");
|
|
116
|
+
expect(contextMock.logger.error).toHaveBeenCalledWith("Unable to upload folder.", error);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const NOT_FOUND_STATUS = 404;
|
|
2
|
+
export const BAD_REQUEST_STATUS = 400;
|
|
3
|
+
export const GATEWAY_STAMP_ERROR_MESSAGE =
|
|
4
|
+
"Endpoint not found. If using Swarm Gateway, postage stamp management endpoints are not available.";
|
|
5
|
+
export const GATEWAY_TAG_ERROR_MESSAGE =
|
|
6
|
+
"If using Swarm Gateway, tag endpoints are not available.";
|
|
7
|
+
export const POSTAGE_CREATE_TIMEOUT_MESSAGE =
|
|
8
|
+
"Purchase of postage batch is in progress, it may take a few minutes. Please list you batches after a few minutes to find it.";
|
|
9
|
+
export const CALL_TIMEOUT = 30000;
|
|
10
|
+
export const DEFAULT_DEFERRED_UPLOAD_SIZE_THRESHOLD_MB = 5;
|
|
11
|
+
export const DEFAULT_GATEWAY_BATCH_ID =
|
|
12
|
+
"0000000000000000000000000000000000000000000000000000000000000000";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PostageBatch } from "@ethersphere/bee-js";
|
|
2
|
+
|
|
3
|
+
export type PostageBatchCurated = Omit<PostageBatch, "batchID"> & {
|
|
4
|
+
batchID: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export interface PostageBatchSummary {
|
|
8
|
+
stampID: string;
|
|
9
|
+
usage: string;
|
|
10
|
+
capacity: string;
|
|
11
|
+
ttl: string;
|
|
12
|
+
immutable: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ResponseContent<U, V> {
|
|
16
|
+
raw: U;
|
|
17
|
+
summary: V;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ResponseWithStructuredContent<T> {
|
|
21
|
+
content: Array<{ type: "text"; text: string }>;
|
|
22
|
+
structuredContent: T;
|
|
23
|
+
}
|