@hashgraphonline/conversational-agent 0.2.216 → 0.2.218
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 +26 -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 +66 -173
- package/dist/esm/index45.js.map +1 -1
- package/dist/esm/index46.js +69 -24
- package/dist/esm/index46.js.map +1 -1
- package/dist/esm/index47.js +47 -88
- package/dist/esm/index47.js.map +1 -1
- package/dist/esm/index48.js +100 -7
- package/dist/esm/index48.js.map +1 -1
- package/dist/esm/index49.js +79 -0
- package/dist/esm/index49.js.map +1 -0
- package/dist/esm/index5.js +2 -2
- package/dist/esm/index50.js +75 -0
- package/dist/esm/index50.js.map +1 -0
- package/dist/esm/index51.js +124 -0
- package/dist/esm/index51.js.map +1 -0
- package/dist/esm/index52.js +58 -0
- package/dist/esm/index52.js.map +1 -0
- package/dist/esm/index53.js +83 -0
- package/dist/esm/index53.js.map +1 -0
- package/dist/esm/index54.js +100 -0
- package/dist/esm/index54.js.map +1 -0
- package/dist/esm/index55.js +118 -0
- package/dist/esm/index55.js.map +1 -0
- package/dist/esm/index56.js +108 -0
- package/dist/esm/index56.js.map +1 -0
- package/dist/esm/index57.js +8 -0
- package/dist/esm/index57.js.map +1 -0
- package/dist/esm/index58.js +325 -0
- package/dist/esm/index58.js.map +1 -0
- package/dist/esm/index59.js +187 -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 +10 -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
package/dist/esm/index45.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index45.js","sources":["../../src/execution/execution-pipeline.ts"],"sourcesContent":["import { ZodError } from 'zod';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport { SmartMemoryManager } from '../memory/smart-memory-manager';\nimport { FormEngine, ToolExecutionResult } from '../forms/form-engine';\nimport type { FormMessage, FormSubmission } from '../forms/types';\nimport type { ToolRegistry, ToolRegistryEntry } from '../core/tool-registry';\n\n/**\n * Session context for tool execution\n */\nexport interface SessionContext {\n sessionId: string;\n userId?: string;\n timestamp: number;\n conversationId?: string;\n}\n\n/**\n * Context passed through execution pipeline\n */\nexport interface ExecutionContext {\n toolName: string;\n input: unknown;\n session: SessionContext;\n memory: SmartMemoryManager;\n traceId: string;\n toolEntry: ToolRegistryEntry;\n}\n\n/**\n * Result of tool execution with metadata\n */\nexport interface ExecutionResult extends ToolExecutionResult {\n traceId: string;\n executionTime: number;\n}\n\n/**\n * ExecutionPipeline handles tool execution coordination\n */\nexport class ExecutionPipeline {\n private logger: Logger;\n private toolRegistry: ToolRegistry;\n private formEngine: FormEngine;\n private memory: SmartMemoryManager;\n\n constructor(\n toolRegistry: ToolRegistry,\n formEngine: FormEngine,\n memory: SmartMemoryManager,\n logger?: Logger\n ) {\n this.toolRegistry = toolRegistry;\n this.formEngine = formEngine;\n this.memory = memory;\n this.logger = logger || new Logger({ module: 'ExecutionPipeline' });\n }\n\n /**\n * Execute a tool through the pipeline\n */\n async execute(\n toolName: string,\n input: unknown,\n sessionContext?: SessionContext\n ): Promise<ExecutionResult> {\n const traceId = `trace-${Date.now()}-${Math.random()\n .toString(36)\n .substr(2, 9)}`;\n const startTime = Date.now();\n\n const toolEntry = this.toolRegistry.getTool(toolName);\n if (!toolEntry) {\n throw new Error(`Tool not found in registry: ${toolName}`);\n }\n\n const context: ExecutionContext = {\n toolName,\n input,\n session: sessionContext || this.buildDefaultSession(),\n memory: this.memory,\n traceId,\n toolEntry,\n };\n\n try {\n const shouldGenerateForm = await this.checkFormGeneration(context);\n if (shouldGenerateForm.requiresForm && shouldGenerateForm.formMessage) {\n return {\n success: false,\n output: 'Form generation required',\n requiresForm: true,\n formMessage: shouldGenerateForm.formMessage,\n traceId,\n executionTime: Date.now() - startTime,\n };\n }\n\n const result = await this.executeToolDirect(context);\n\n return {\n success: true,\n output: result,\n traceId,\n executionTime: Date.now() - startTime,\n };\n } catch (error) {\n return this.handleExecutionError(\n error,\n context,\n traceId,\n Date.now() - startTime\n );\n }\n }\n\n /**\n * Execute tool with validation\n */\n async executeWithValidation(\n toolName: string,\n input: unknown,\n sessionContext?: SessionContext\n ): Promise<ExecutionResult> {\n return this.execute(toolName, input, sessionContext);\n }\n\n /**\n * Process form submission\n */\n async processFormSubmission(\n toolName: string,\n formId: string,\n parameters: Record<string, unknown>,\n sessionContext?: SessionContext\n ): Promise<ExecutionResult> {\n const traceId = `form-${Date.now()}-${Math.random()\n .toString(36)\n .substr(2, 9)}`;\n const startTime = Date.now();\n\n try {\n const formSubmission: FormSubmission = {\n formId,\n toolName,\n parameters,\n timestamp: Date.now(),\n };\n\n const processedInput = await this.formEngine.processSubmission(\n formSubmission\n );\n\n return this.execute(toolName, processedInput, sessionContext);\n } catch (error) {\n return {\n success: false,\n output: 'Form submission processing failed',\n error: error instanceof Error ? error.message : String(error),\n traceId,\n executionTime: Date.now() - startTime,\n };\n }\n }\n\n /**\n * Check if form generation is required\n */\n private async checkFormGeneration(context: ExecutionContext): Promise<{\n requiresForm: boolean;\n formMessage?: FormMessage;\n }> {\n const inputRecord = context.input as Record<string, unknown>;\n if (inputRecord?.__fromForm === true || inputRecord?.renderForm === false) {\n return { requiresForm: false };\n }\n\n if (\n !this.formEngine.shouldGenerateForm(context.toolEntry.tool, context.input)\n ) {\n return { requiresForm: false };\n }\n\n const formMessage = await this.formEngine.generateForm(\n context.toolName,\n context.toolEntry.tool,\n context.input\n );\n\n if (formMessage) {\n return { requiresForm: true, formMessage };\n }\n\n return { requiresForm: false };\n }\n\n /**\n * Execute tool directly\n */\n private async executeToolDirect(context: ExecutionContext): Promise<string> {\n const { toolEntry, input } = context;\n const parameters = (input as Record<string, unknown>) || {};\n const mergedArgs = { ...parameters, renderForm: false };\n\n if (toolEntry.wrapper) {\n return this.executeWrappedTool(toolEntry, mergedArgs);\n }\n\n return await toolEntry.tool.call(mergedArgs);\n }\n\n /**\n * Execute wrapped tool\n */\n private async executeWrappedTool(\n toolEntry: ToolRegistryEntry,\n mergedArgs: Record<string, unknown>\n ): Promise<string> {\n const wrapper = toolEntry.wrapper;\n if (!wrapper) {\n throw new Error('Tool wrapper not found');\n }\n\n const wrapperAsAny = wrapper as unknown as {\n executeOriginal?: (args: Record<string, unknown>) => Promise<string>;\n originalTool?: {\n call?: (args: Record<string, unknown>) => Promise<string>;\n };\n };\n\n if (wrapperAsAny.executeOriginal) {\n return await wrapperAsAny.executeOriginal(mergedArgs);\n }\n\n if (wrapperAsAny.originalTool?.call) {\n return await wrapperAsAny.originalTool.call(mergedArgs);\n }\n\n return await toolEntry.originalTool.call(mergedArgs);\n }\n\n /**\n * Handle execution error\n */\n private handleExecutionError(\n error: unknown,\n context: ExecutionContext,\n traceId: string,\n executionTime: number\n ): ExecutionResult {\n const errorMessage = error instanceof Error ? error.message : String(error);\n\n if (error instanceof ZodError) {\n return {\n success: false,\n output: 'Validation error occurred',\n error: errorMessage,\n traceId,\n executionTime,\n };\n }\n\n this.logger.error(`Tool execution failed: ${context.toolName}`, {\n traceId,\n error: errorMessage,\n });\n\n return {\n success: false,\n output: 'Tool execution failed',\n error: errorMessage,\n traceId,\n executionTime,\n };\n }\n\n /**\n * Build default session context\n */\n private buildDefaultSession(): SessionContext {\n return {\n sessionId: `session-${Date.now()}-${Math.random()\n .toString(36)\n .substr(2, 9)}`,\n timestamp: Date.now(),\n };\n }\n\n /**\n * Get statistics about the pipeline\n */\n getStatistics(): {\n totalMiddleware: number;\n registeredMiddleware: string[];\n } {\n return {\n totalMiddleware: 0,\n registeredMiddleware: [],\n };\n }\n}\n"],"names":[],"mappings":";;AAwCO,MAAM,kBAAkB;AAAA,EAM7B,YACE,cACA,YACA,QACA,QACA;AACA,SAAK,eAAe;AACpB,SAAK,aAAa;AAClB,SAAK,SAAS;AACd,SAAK,SAAS,UAAU,IAAI,OAAO,EAAE,QAAQ,qBAAqB;AAAA,EACpE;AAAA;AAAA;AAAA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,IAAC;AAAA,EAE3B;AACF;"}
|
|
1
|
+
{"version":3,"file":"index45.js","sources":["../../src/plugins/community/swarm/tools/ListPostageStampsTool.ts"],"sourcesContent":["import {\r\n type GenericPluginContext,\r\n BaseHederaQueryTool,\r\n type HederaAgentKit,\r\n} from \"hedera-agent-kit\";\r\nimport { Bee } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport {\r\n PostageBatchCurated,\r\n PostageBatchSummary,\r\n ResponseContent,\r\n} from \"../model\";\r\nimport {\r\n errorHasStatus,\r\n getBatchSummary,\r\n getResponseWithStructuredContent,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS } from \"../constants\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst ListPostageStampsSchema = z.object({\r\n leastUsed: z.boolean().optional(),\r\n limit: z.number().optional(),\r\n minUsage: z.number().optional(),\r\n maxUsage: z.number().optional(),\r\n});\r\n\r\nexport class ListPostageStampsTool extends BaseHederaQueryTool<typeof ListPostageStampsSchema> {\r\n name = \"swarm-list-postage-stamps\";\r\n description =`\r\n List the available postage stamps.\r\n leastUsed: A boolean value that tells if stamps are sorted so least used comes first.\r\n limit: Limit is the maximum number of returned stamps.\r\n minUsage: Only list stamps with at least this usage percentage.\r\n maxUsage: Only list stamps with at most this usage percentage. \r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = ListPostageStampsSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n\r\n protected async executeQuery(\r\n input: z.infer<typeof ListPostageStampsSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { leastUsed, limit, minUsage, maxUsage } = input;\r\n\r\n let rawPostageBatches;\r\n\r\n try {\r\n rawPostageBatches = await this.bee.getPostageBatches();\r\n } catch (error) {\r\n let errorMessage = 'Retrieval of postage batches failed.';\r\n\r\n if (errorHasStatus(error, NOT_FOUND_STATUS)) {\r\n errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;\r\n }\r\n \r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n \r\n throw new Error(errorMessage);\r\n }\r\n\r\n const batches: PostageBatchCurated[] = rawPostageBatches.map((batch) => ({\r\n ...batch,\r\n batchID: batch.batchID.toHex(),\r\n }));\r\n let filteredPostageBatches = batches.filter((batch) => {\r\n if (!batch.usable) {\r\n return false;\r\n }\r\n\r\n const usagePercentage = batch.usage * 100;\r\n\r\n if (minUsage !== undefined && usagePercentage < minUsage) {\r\n return false;\r\n }\r\n\r\n if (maxUsage !== undefined && usagePercentage > maxUsage) {\r\n return false;\r\n }\r\n\r\n return true;\r\n });\r\n\r\n if (Boolean(leastUsed) && filteredPostageBatches.length) {\r\n filteredPostageBatches = filteredPostageBatches.sort(\r\n (batch1, batch2) => batch1.usage - batch2.usage\r\n );\r\n }\r\n\r\n if (limit !== undefined && limit < filteredPostageBatches.length) {\r\n filteredPostageBatches = filteredPostageBatches.slice(0, limit);\r\n }\r\n\r\n const computedPostageBatches: PostageBatchSummary[] =\r\n filteredPostageBatches.map((batch) => getBatchSummary(batch));\r\n\r\n const content: ResponseContent<\r\n PostageBatchCurated[],\r\n PostageBatchSummary[]\r\n > = {\r\n raw: filteredPostageBatches,\r\n summary: computedPostageBatches,\r\n };\r\n\r\n return getResponseWithStructuredContent(content);\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;AAqBA,MAAM,0BAA0B,EAAE,OAAO;AAAA,EACvC,WAAW,EAAE,QAAA,EAAU,SAAA;AAAA,EACvB,OAAO,EAAE,OAAA,EAAS,SAAA;AAAA,EAClB,UAAU,EAAE,OAAA,EAAS,SAAA;AAAA,EACrB,UAAU,EAAE,OAAA,EAAS,SAAA;A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AyB,uBAAuB,MAAM,GAAG,KAAK;AAAA,IAChE;AAEA,UAAM,yBACJ,uBAAuB,IAAI,CAAC,UAAU,gBAAgB,KAAK,CAAC;AAE9D,UAAM,UAGF;AAAA,MACF,KAAK;AAAA,MACL,SAAS;AAAA,IAAA;AAGX,WAAO,iCAAiC,OAAO;AAAA,EACjD;AACF;"}
|
package/dist/esm/index46.js
CHANGED
|
@@ -1,30 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { BaseHederaQueryTool } from "hedera-agent-kit";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { getUploadPostageBatchId, errorHasStatus, getErrorMessage, getResponseWithStructuredContent } from "./index62.js";
|
|
4
|
+
import { BAD_REQUEST_STATUS } from "./index63.js";
|
|
5
|
+
const UploadDataSchema = z.object({
|
|
6
|
+
data: z.string(),
|
|
7
|
+
redundancyLevel: z.number().optional(),
|
|
8
|
+
postageBatchId: z.string().optional()
|
|
9
|
+
});
|
|
10
|
+
class UploadDataTool extends BaseHederaQueryTool {
|
|
11
|
+
constructor(params) {
|
|
12
|
+
const { bee, config, ...rest } = params;
|
|
13
|
+
super(rest);
|
|
14
|
+
this.name = "swarm-upload-data";
|
|
15
|
+
this.description = `
|
|
16
|
+
Upload text data to Swarm.
|
|
17
|
+
data: Arbitrary string to upload.
|
|
18
|
+
redundancyLevel: 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.
|
|
19
|
+
postageBatchId: The postage stamp batch ID which will be used to perform the upload, if it is provided.
|
|
20
|
+
`;
|
|
21
|
+
this.namespace = "swarm";
|
|
22
|
+
this.specificInputSchema = UploadDataSchema;
|
|
23
|
+
this.bee = bee;
|
|
24
|
+
this.config = config;
|
|
15
25
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
async executeQuery(input) {
|
|
27
|
+
const { data, redundancyLevel, postageBatchId: inputPostageBatchId } = input;
|
|
28
|
+
if (!data) {
|
|
29
|
+
this.logger.error(
|
|
30
|
+
"Missing required parameter: data."
|
|
31
|
+
);
|
|
32
|
+
throw new Error("Missing required parameter: data.");
|
|
33
|
+
}
|
|
34
|
+
let postageBatchId = "";
|
|
35
|
+
try {
|
|
36
|
+
postageBatchId = await getUploadPostageBatchId(
|
|
37
|
+
inputPostageBatchId,
|
|
38
|
+
this.bee,
|
|
39
|
+
this.config
|
|
40
|
+
);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
let errorMessage = "Upload data failed.";
|
|
43
|
+
if (error instanceof Error) {
|
|
44
|
+
errorMessage = error.message;
|
|
45
|
+
}
|
|
46
|
+
this.logger.error(errorMessage);
|
|
47
|
+
throw new Error(errorMessage);
|
|
48
|
+
}
|
|
49
|
+
const binaryData = Buffer.from(data);
|
|
50
|
+
const options = redundancyLevel ? { redundancyLevel } : void 0;
|
|
51
|
+
let result;
|
|
52
|
+
try {
|
|
53
|
+
result = await this.bee.uploadData(postageBatchId, binaryData, options);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
let errorMessage = "Unable to upload data.";
|
|
56
|
+
if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
|
|
57
|
+
errorMessage = getErrorMessage(error);
|
|
58
|
+
}
|
|
59
|
+
this.logger.error(
|
|
60
|
+
errorMessage,
|
|
61
|
+
error
|
|
62
|
+
);
|
|
63
|
+
throw new Error(errorMessage);
|
|
64
|
+
}
|
|
65
|
+
return getResponseWithStructuredContent({
|
|
66
|
+
reference: result.reference.toString(),
|
|
67
|
+
url: this.bee.url + "/bytes/" + result.reference.toString(),
|
|
68
|
+
message: "Data successfully uploaded to Swarm"
|
|
69
|
+
});
|
|
24
70
|
}
|
|
25
71
|
}
|
|
26
72
|
export {
|
|
27
|
-
|
|
28
|
-
DEFAULT_CONTENT_REFERENCE_CONFIG
|
|
73
|
+
UploadDataTool
|
|
29
74
|
};
|
|
30
75
|
//# sourceMappingURL=index46.js.map
|
package/dist/esm/index46.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index46.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index46.js","sources":["../../src/plugins/community/swarm/tools/UploadDataTool.ts"],"sourcesContent":["import {\r\n BaseHederaQueryTool,\r\n HederaAgentKit,\r\n type GenericPluginContext,\r\n} from \"hedera-agent-kit\";\r\nimport { Bee } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport {\r\n errorHasStatus,\r\n getErrorMessage,\r\n getResponseWithStructuredContent,\r\n getUploadPostageBatchId,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { BAD_REQUEST_STATUS } from \"../constants\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst UploadDataSchema = z.object({\r\n data: z.string(),\r\n redundancyLevel: z.number().optional(),\r\n postageBatchId: z.string().optional(),\r\n});\r\n\r\nexport class UploadDataTool extends BaseHederaQueryTool<typeof UploadDataSchema> {\r\n name = \"swarm-upload-data\";\r\n description = `\r\n Upload text data to Swarm.\r\n data: Arbitrary string to upload.\r\n redundancyLevel: 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.\r\n postageBatchId: The postage stamp batch ID which will be used to perform the upload, if it is provided.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = UploadDataSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n \r\n protected async executeQuery(\r\n input: z.infer<typeof UploadDataSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { data, redundancyLevel, postageBatchId: inputPostageBatchId } = input;\r\n\r\n if (!data) {\r\n this.logger.error(\r\n 'Missing required parameter: data.'\r\n );\r\n\r\n throw new Error('Missing required parameter: data.');\r\n }\r\n\r\n let postageBatchId = \"\";\r\n\r\n try {\r\n postageBatchId = await getUploadPostageBatchId(\r\n inputPostageBatchId,\r\n this.bee,\r\n this.config,\r\n );\r\n } catch (error) {\r\n let errorMessage = 'Upload data failed.';\r\n if (error instanceof Error) {\r\n errorMessage = error.message;\r\n }\r\n this.logger.error(errorMessage);\r\n\r\n throw new Error(errorMessage);\r\n }\r\n\r\n const binaryData = Buffer.from(data);\r\n\r\n const options = redundancyLevel ? { redundancyLevel } : undefined;\r\n\r\n let result;\r\n\r\n try {\r\n result = await this.bee.uploadData(postageBatchId, binaryData, options);\r\n } catch (error) {\r\n let errorMessage = 'Unable to upload data.';\r\n\r\n if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n\r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n \r\n throw new Error(errorMessage);\r\n }\r\n\r\n return getResponseWithStructuredContent({\r\n reference: result.reference.toString(),\r\n url: this.bee.url + \"/bytes/\" + result.reference.toString(),\r\n message: 'Data successfully uploaded to Swarm',\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;AAiBA,MAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,MAAM,EAAE,OAAA;AAAA,EACR,iBAAiB,EAAE,OAAA,EAAS,SAAA;AAAA,EAC5B,gBAAgB,EAAE,OAAA,EAAS,SAAA;AAC7B,CAAC;AAEM,MAAM,uBAAuB,oBAA6C;AAAA,EAa/E,YAAY,QAKT;AACD,UAAM,EAAE,KA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/index47.js
CHANGED
|
@@ -1,98 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { errorHasStatus, getErrorMessage, getResponseWithStructuredContent } from "./index62.js";
|
|
3
|
+
import { BaseHederaQueryTool } from "hedera-agent-kit";
|
|
4
|
+
import { BAD_REQUEST_STATUS } from "./index63.js";
|
|
5
|
+
const DownloadDataSchema = z.object({
|
|
6
|
+
reference: z.string()
|
|
7
|
+
});
|
|
8
|
+
class DownloadDataTool extends BaseHederaQueryTool {
|
|
9
|
+
constructor(params) {
|
|
10
|
+
const { bee, config, ...rest } = params;
|
|
11
|
+
super(rest);
|
|
12
|
+
this.name = "swarm-download-data";
|
|
13
|
+
this.description = `
|
|
14
|
+
Downloads immutable data from a Swarm content address hash.
|
|
15
|
+
reference: Swarm reference hash.
|
|
16
|
+
`;
|
|
17
|
+
this.namespace = "swarm";
|
|
18
|
+
this.specificInputSchema = DownloadDataSchema;
|
|
19
|
+
this.bee = bee;
|
|
20
|
+
this.config = config;
|
|
7
21
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw new Error("HbarTransferParams must include at least one transfer.");
|
|
22
|
+
async executeQuery(input) {
|
|
23
|
+
const { reference } = input;
|
|
24
|
+
if (!reference) {
|
|
25
|
+
this.logger.error(
|
|
26
|
+
"Missing required parameter: reference."
|
|
27
|
+
);
|
|
28
|
+
throw new Error("Missing required parameter: reference.");
|
|
16
29
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (amountBigNum.isPositive()) {
|
|
24
|
-
const recipientAccountId = typeof receiverTransfer.accountId === "string" ? AccountId.fromString(receiverTransfer.accountId) : receiverTransfer.accountId;
|
|
25
|
-
const roundedAmount = amountBigNum.toFixed(8, BigNumber.ROUND_DOWN);
|
|
26
|
-
const sdkHbarAmount = Hbar.fromString(roundedAmount);
|
|
27
|
-
this.logger.info(
|
|
28
|
-
`[AccountBuilder.transferHbar] Configuring user-initiated scheduled transfer: ${sdkHbarAmount.toString()} from ${this.kit.userAccountId} to ${recipientAccountId.toString()}`
|
|
29
|
-
);
|
|
30
|
-
this.addNote(
|
|
31
|
-
`Configured HBAR transfer from your account (${this.kit.userAccountId}) to ${recipientAccountId.toString()} for ${sdkHbarAmount.toString()}.`
|
|
32
|
-
);
|
|
33
|
-
transaction.addHbarTransfer(recipientAccountId, sdkHbarAmount);
|
|
34
|
-
transaction.addHbarTransfer(
|
|
35
|
-
AccountId.fromString(this.kit.userAccountId),
|
|
36
|
-
sdkHbarAmount.negated()
|
|
37
|
-
);
|
|
38
|
-
userTransferProcessedForScheduling = true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (!userTransferProcessedForScheduling) {
|
|
42
|
-
const processedTransfers = [];
|
|
43
|
-
for (const transferInput of params.transfers) {
|
|
44
|
-
const accountId = typeof transferInput.accountId === "string" ? AccountId.fromString(transferInput.accountId) : transferInput.accountId;
|
|
45
|
-
const amountValue = typeof transferInput.amount === "string" || typeof transferInput.amount === "number" ? transferInput.amount : transferInput.amount.toString();
|
|
46
|
-
const amountBigNum = new BigNumber(amountValue);
|
|
47
|
-
const roundedAmount = amountBigNum.toFixed(8, BigNumber.ROUND_DOWN);
|
|
48
|
-
this.logger.info(
|
|
49
|
-
`Processing transfer: ${amountValue} HBAR (rounded to ${roundedAmount}) for account ${accountId.toString()}`
|
|
50
|
-
);
|
|
51
|
-
const sdkHbarAmount = Hbar.fromString(roundedAmount);
|
|
52
|
-
processedTransfers.push({
|
|
53
|
-
accountId,
|
|
54
|
-
amount: amountBigNum,
|
|
55
|
-
hbar: sdkHbarAmount
|
|
56
|
-
});
|
|
57
|
-
const tinybarsContribution = sdkHbarAmount.toTinybars();
|
|
58
|
-
netZeroInTinybars = netZeroInTinybars.plus(
|
|
59
|
-
tinybarsContribution.toString()
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
if (!netZeroInTinybars.isZero()) {
|
|
63
|
-
this.logger.warn(
|
|
64
|
-
`Transfer sum not zero: ${netZeroInTinybars.toString()} tinybars off. Adjusting last transfer.`
|
|
65
|
-
);
|
|
66
|
-
if (processedTransfers.length > 0) {
|
|
67
|
-
const lastTransfer = processedTransfers[processedTransfers.length - 1];
|
|
68
|
-
const adjustment = netZeroInTinybars.dividedBy(-1e8);
|
|
69
|
-
const adjustedAmount = lastTransfer.amount.plus(adjustment);
|
|
70
|
-
const adjustedRounded = adjustedAmount.toFixed(
|
|
71
|
-
8,
|
|
72
|
-
BigNumber.ROUND_DOWN
|
|
73
|
-
);
|
|
74
|
-
lastTransfer.hbar = Hbar.fromString(adjustedRounded);
|
|
75
|
-
this.logger.info(
|
|
76
|
-
`Adjusted last transfer for ${lastTransfer.accountId.toString()} to ${adjustedRounded} HBAR`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
for (const transfer of processedTransfers) {
|
|
81
|
-
transaction.addHbarTransfer(transfer.accountId, transfer.hbar);
|
|
82
|
-
}
|
|
30
|
+
const isRefNotSwarmHash = reference.length !== 64 && reference.length !== 66;
|
|
31
|
+
if (isRefNotSwarmHash) {
|
|
32
|
+
this.logger.error(
|
|
33
|
+
"Invalid Swarm content address hash value for reference."
|
|
34
|
+
);
|
|
35
|
+
throw new Error("Invalid Swarm content address hash value for reference.");
|
|
83
36
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
37
|
+
let data;
|
|
38
|
+
try {
|
|
39
|
+
data = await this.bee.downloadData(reference);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
let errorMessage = "Downloading data failed.";
|
|
42
|
+
if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
|
|
43
|
+
errorMessage = getErrorMessage(error);
|
|
89
44
|
}
|
|
45
|
+
this.logger.error(errorMessage, error);
|
|
46
|
+
throw new Error(errorMessage);
|
|
90
47
|
}
|
|
91
|
-
|
|
92
|
-
return
|
|
48
|
+
const textData = data.toUtf8();
|
|
49
|
+
return getResponseWithStructuredContent({
|
|
50
|
+
textData
|
|
51
|
+
});
|
|
93
52
|
}
|
|
94
53
|
}
|
|
95
54
|
export {
|
|
96
|
-
|
|
55
|
+
DownloadDataTool
|
|
97
56
|
};
|
|
98
57
|
//# sourceMappingURL=index47.js.map
|
package/dist/esm/index47.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index47.js","sources":["../../src/plugins/
|
|
1
|
+
{"version":3,"file":"index47.js","sources":["../../src/plugins/community/swarm/tools/DownloadDataTool.ts"],"sourcesContent":["import { Bee } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport { errorHasStatus, getErrorMessage, getResponseWithStructuredContent, ToolResponse } from \"../utils\";\r\nimport { BaseHederaQueryTool, GenericPluginContext, HederaAgentKit } from \"hedera-agent-kit\";\r\nimport { SwarmConfig } from \"../config\";\r\nimport { BAD_REQUEST_STATUS } from \"../constants\";\r\n\r\nconst DownloadDataSchema = z.object({\r\n reference: z.string(),\r\n});\r\n\r\nexport class DownloadDataTool extends BaseHederaQueryTool<typeof DownloadDataSchema> {\r\n name = \"swarm-download-data\";\r\n description = `\r\n Downloads immutable data from a Swarm content address hash.\r\n reference: Swarm reference hash.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = DownloadDataSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n\r\n protected async executeQuery(\r\n input: z.infer<typeof DownloadDataSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { reference } = input;\r\n\r\n if (!reference) {\r\n this.logger.error(\r\n 'Missing required parameter: reference.'\r\n );\r\n\r\n throw new Error(\"Missing required parameter: reference.\");\r\n }\r\n\r\n const isRefNotSwarmHash =\r\n reference.length !== 64 && reference.length !== 66;\r\n\r\n if (isRefNotSwarmHash) {\r\n this.logger.error(\r\n 'Invalid Swarm content address hash value for reference.'\r\n );\r\n\r\n throw new Error(\"Invalid Swarm content address hash value for reference.\");\r\n }\r\n\r\n let data;\r\n try {\r\n data = await this.bee.downloadData(reference);\r\n } catch (error) {\r\n let errorMessage = 'Downloading data failed.';\r\n\r\n if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n\r\n this.logger.error(errorMessage, error);\r\n throw new Error(errorMessage);\r\n }\r\n\r\n const textData = data.toUtf8();\r\n\r\n return getResponseWithStructuredContent({\r\n textData,\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;AAOA,MAAM,qBAAqB,EAAE,OAAO;AAAA,EAClC,WAAW,EAAE,OAAA;AACf,CAAC;AAEM,MAAM,yBAAyB,oBAA+C;AAAA,EAWnF,YAAY,QAKT;AACD,UAAM,EAAE,KAAK,QAAQ,GAAG,SAAS;AACjC,UAAM,IAAI;AAjBZ,SAAA,OAAO;AACP,SAAA,cAAc;AAAA;AAAA;AAAA;AAId,SAAA,YAAY;AACZ,SAAA,sBAAsB;AAYpB,SAAK,MAAM;AACX,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAgB,aACZ,OAC8B;AAChC,UAAM,EAAE,cAAc;AAEtB,QAAI,CAAC,WAAW;AACd,WAAK,OAAO;AAAA,QACV;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAEA,UAAM,oBACJ,UAAU,WAAW,MAAM,UAAU,WAAW;AAElD,QAAI,mBAAmB;AACrB,WAAK,OAAO;AAAA,QACV;AAAA,MAAA;AAGF,YAAM,IAAI,MAAM,yDAAyD;AAAA,IAC3E;AAEA,QAAI;AACJ,QAAI;AACF,aAAO,MAAM,KAAK,IAAI,aAAa,SAAS;AAAA,IAC9C,SAAS,OAAO;AACd,UAAI,eAAe;AAEnB,UAAI,eAAe,OAAO,kBAAkB,GAAG;AAC7C,uBAAe,gBAAgB,KAAK;AAAA,MACtC;AAEA,WAAK,OAAO,MAAM,cAAc,KAAK;AACrC,YAAM,IAAI,MAAM,YAAY;AAAA,IAC9B;AAEA,UAAM,WAAW,KAAK,OAAA;AAEtB,WAAO,iCAAiC;AAAA,MACtC;AAAA,IAAA,CACD;AAAA,EACH;AACF;"}
|
package/dist/esm/index48.js
CHANGED
|
@@ -1,10 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { BaseHederaQueryTool } from "hedera-agent-kit";
|
|
2
|
+
import { Size, Duration } from "@ethersphere/bee-js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { makeDate, runWithTimeout, errorHasStatus, getErrorMessage } from "./index62.js";
|
|
5
|
+
import { CALL_TIMEOUT, POSTAGE_CREATE_TIMEOUT_MESSAGE, GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS, BAD_REQUEST_STATUS } from "./index63.js";
|
|
6
|
+
const CreatePostageStampSchema = z.object({
|
|
7
|
+
size: z.number(),
|
|
8
|
+
duration: z.string(),
|
|
9
|
+
label: z.string().optional()
|
|
10
|
+
});
|
|
11
|
+
class CreatePostageStampTool extends BaseHederaQueryTool {
|
|
12
|
+
constructor(params) {
|
|
13
|
+
const { bee, config, ...rest } = params;
|
|
14
|
+
super(rest);
|
|
15
|
+
this.name = "swarm-create-postage-stamp";
|
|
16
|
+
this.description = `
|
|
17
|
+
Buy postage stamp based on size in megabytes and duration.
|
|
18
|
+
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.
|
|
19
|
+
duration: Duration for which the data should be stored. Time to live of the postage stamp, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.
|
|
20
|
+
label: Sets label for the postage batch (omit if the user didn't ask for one). Do not set a label with with specific capacity values because they can get misleading.
|
|
21
|
+
`;
|
|
22
|
+
this.namespace = "swarm";
|
|
23
|
+
this.specificInputSchema = CreatePostageStampSchema;
|
|
24
|
+
this.bee = bee;
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
async executeQuery(input) {
|
|
28
|
+
const { size, duration, label } = input;
|
|
29
|
+
if (!size) {
|
|
30
|
+
this.logger.error(
|
|
31
|
+
"Missing required parameter: size."
|
|
32
|
+
);
|
|
33
|
+
throw new Error("Missing required parameter: size.");
|
|
34
|
+
} else if (!duration) {
|
|
35
|
+
this.logger.error(
|
|
36
|
+
"Missing required parameter: duration."
|
|
37
|
+
);
|
|
38
|
+
throw new Error("Missing required parameter: duration.");
|
|
39
|
+
}
|
|
40
|
+
let durationMs;
|
|
41
|
+
try {
|
|
42
|
+
durationMs = makeDate(duration);
|
|
43
|
+
} catch (makeDateError) {
|
|
44
|
+
this.logger.error(
|
|
45
|
+
"Invalid parameter: duration."
|
|
46
|
+
);
|
|
47
|
+
throw new Error("Invalid parameter: duration.");
|
|
48
|
+
}
|
|
49
|
+
let buyStorageResponse;
|
|
50
|
+
try {
|
|
51
|
+
let options = {};
|
|
52
|
+
if (label !== void 0) {
|
|
53
|
+
options = {
|
|
54
|
+
label
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const buyStoragePromise = this.bee.buyStorage(
|
|
58
|
+
Size.fromMegabytes(size),
|
|
59
|
+
Duration.fromMilliseconds(durationMs),
|
|
60
|
+
options
|
|
61
|
+
);
|
|
62
|
+
const [response, hasTimedOut] = await runWithTimeout(
|
|
63
|
+
buyStoragePromise,
|
|
64
|
+
CALL_TIMEOUT
|
|
65
|
+
);
|
|
66
|
+
if (hasTimedOut) {
|
|
67
|
+
return JSON.stringify({
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
text: POSTAGE_CREATE_TIMEOUT_MESSAGE
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
buyStorageResponse = response;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
let errorMessage = "Unable to buy storage.";
|
|
79
|
+
if (errorHasStatus(error, NOT_FOUND_STATUS)) {
|
|
80
|
+
errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;
|
|
81
|
+
} else if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
|
|
82
|
+
errorMessage = getErrorMessage(error);
|
|
83
|
+
}
|
|
84
|
+
this.logger.error(
|
|
85
|
+
errorMessage,
|
|
86
|
+
error
|
|
87
|
+
);
|
|
88
|
+
throw new Error(errorMessage);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
content: [
|
|
92
|
+
{
|
|
93
|
+
type: "text",
|
|
94
|
+
text: `Postage batch ID: ${buyStorageResponse.toHex()}`
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
7
100
|
export {
|
|
8
|
-
|
|
101
|
+
CreatePostageStampTool
|
|
9
102
|
};
|
|
10
103
|
//# sourceMappingURL=index48.js.map
|
package/dist/esm/index48.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index48.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index48.js","sources":["../../src/plugins/community/swarm/tools/CreatePostageStampTool.ts"],"sourcesContent":["import {\r\n BaseHederaQueryTool,\r\n HederaAgentKit,\r\n type GenericPluginContext,\r\n} from \"hedera-agent-kit\";\r\nimport { BatchId, Bee, Duration, Size } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport {\r\n errorHasStatus,\r\n getErrorMessage,\r\n makeDate,\r\n runWithTimeout,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { BAD_REQUEST_STATUS, CALL_TIMEOUT, GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS, POSTAGE_CREATE_TIMEOUT_MESSAGE } from \"../constants\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst CreatePostageStampSchema = z.object({\r\n size: z.number(),\r\n duration: z.string(),\r\n label: z.string().optional(),\r\n});\r\n\r\nexport class CreatePostageStampTool extends BaseHederaQueryTool<typeof CreatePostageStampSchema> {\r\n name = \"swarm-create-postage-stamp\";\r\n description = `\r\n Buy postage stamp based on size in megabytes and duration.\r\n 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.\r\n duration: Duration for which the data should be stored. Time to live of the postage stamp, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.\r\n label: Sets label for the postage batch (omit if the user didn't ask for one). Do not set a label with with specific capacity values because they can get misleading.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = CreatePostageStampSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n \r\n protected async executeQuery(\r\n input: z.infer<typeof CreatePostageStampSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { size, duration, label } = input;\r\n\r\n if (!size) {\r\n this.logger.error(\r\n 'Missing required parameter: size.'\r\n );\r\n \r\n throw new Error('Missing required parameter: size.');\r\n } else if (!duration) {\r\n this.logger.error(\r\n 'Missing required parameter: duration.'\r\n );\r\n \r\n throw new Error('Missing required parameter: duration.');\r\n }\r\n\r\n let durationMs;\r\n\r\n try {\r\n durationMs = makeDate(duration);\r\n } catch (makeDateError) {\r\n this.logger.error(\r\n 'Invalid parameter: duration.'\r\n );\r\n\r\n throw new Error('Invalid parameter: duration.');\r\n }\r\n\r\n let buyStorageResponse: BatchId;\r\n\r\n try {\r\n let options = {};\r\n if (label !== undefined) {\r\n options = {\r\n label\r\n };\r\n }\r\n const buyStoragePromise = this.bee.buyStorage(\r\n Size.fromMegabytes(size),\r\n Duration.fromMilliseconds(durationMs),\r\n options\r\n );\r\n const [response, hasTimedOut] = await runWithTimeout(\r\n buyStoragePromise,\r\n CALL_TIMEOUT\r\n );\r\n\r\n if (hasTimedOut) {\r\n return JSON.stringify({\r\n content: [\r\n {\r\n type: 'text',\r\n text: POSTAGE_CREATE_TIMEOUT_MESSAGE,\r\n },\r\n ],\r\n });\r\n }\r\n\r\n buyStorageResponse = response as BatchId;\r\n } catch (error) {\r\n let errorMessage = 'Unable to buy storage.';\r\n\r\n if (errorHasStatus(error, NOT_FOUND_STATUS)) {\r\n errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;\r\n } else if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n\r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n\r\n throw new Error(errorMessage);\r\n }\r\n\r\n return {\r\n content: [\r\n {\r\n type: 'text',\r\n text: `Postage batch ID: ${buyStorageResponse.toHex()}`,\r\n },\r\n ],\r\n };\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;AAiBA,MAAM,2BAA2B,EAAE,OAAO;AAAA,EACxC,MAAM,EAAE,OAAA;AAAA,EACR,UAAU,EAAE,OAAA;AAAA,EACZ,OAAO,EAAE,OAAA,EAAS,SAAA;AACpB,CAAC;AAEM,MAAM,+BAA+B,oBAAqD;AAAA,EAa/F,YAAY,QAKT;AACD,UAAM,EAAE,KAAK,QAAQ,GAAG,SAAS;AACjC,UAAM,IAAI;AAnBZ,SAAA,OAAO;AACP,SAAA,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAMd,SAA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AAA;AAGF,YAAM,IAAI,MAAM,YAAY;AAAA,IAC9B;AAEA,WAAO;AAAA,MACL,SAAS;AAAA,QACP;AAAA,UACE,MAAM;AAAA,UACN,MAAM,qBAAqB,mBAAmB,MAAA,CAAO;AAAA,QAAA;AAAA,MACvD;AAAA,IACF;AAAA,EAEJ;AACF;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { BaseHederaQueryTool } from "hedera-agent-kit";
|
|
2
|
+
import { Size, Duration } from "@ethersphere/bee-js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { makeDate, errorHasStatus, getErrorMessage, getResponseWithStructuredContent } from "./index62.js";
|
|
5
|
+
import { NOT_FOUND_STATUS, GATEWAY_STAMP_ERROR_MESSAGE, BAD_REQUEST_STATUS } from "./index63.js";
|
|
6
|
+
const ExtendPostageStampSchema = z.object({
|
|
7
|
+
postageBatchId: z.string(),
|
|
8
|
+
duration: z.string().optional(),
|
|
9
|
+
size: z.number().optional()
|
|
10
|
+
});
|
|
11
|
+
class ExtendPostageStampTool extends BaseHederaQueryTool {
|
|
12
|
+
constructor(params) {
|
|
13
|
+
const { bee, config, ...rest } = params;
|
|
14
|
+
super(rest);
|
|
15
|
+
this.name = "swarm-extend-postage-stamp";
|
|
16
|
+
this.description = `Increase the duration (relative to current duration) or size (in megabytes) of a postage stamp.
|
|
17
|
+
postageBatchId: The id of the batch for which extend is performed.
|
|
18
|
+
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.
|
|
19
|
+
duration: Duration for which the data should be stored. Time to live of the postage stamp, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.
|
|
20
|
+
`;
|
|
21
|
+
this.namespace = "swarm";
|
|
22
|
+
this.specificInputSchema = ExtendPostageStampSchema;
|
|
23
|
+
this.bee = bee;
|
|
24
|
+
this.config = config;
|
|
25
|
+
}
|
|
26
|
+
async executeQuery(input) {
|
|
27
|
+
const { postageBatchId, duration, size } = input;
|
|
28
|
+
if (!postageBatchId) {
|
|
29
|
+
this.logger.error(
|
|
30
|
+
"Missing required parameter: postageBatchId."
|
|
31
|
+
);
|
|
32
|
+
throw new Error("Missing required parameter: postageBatchId.");
|
|
33
|
+
} else if (!duration && !size) {
|
|
34
|
+
this.logger.error(
|
|
35
|
+
"You need at least one parameter from duration and size."
|
|
36
|
+
);
|
|
37
|
+
throw new Error("You need at least one parameter from duration and size.");
|
|
38
|
+
}
|
|
39
|
+
const extendSize = !!size ? Size.fromMegabytes(size) : Size.fromBytes(1);
|
|
40
|
+
let extendDuration = Duration.ZERO;
|
|
41
|
+
try {
|
|
42
|
+
if (duration) {
|
|
43
|
+
extendDuration = Duration.fromMilliseconds(makeDate(duration));
|
|
44
|
+
}
|
|
45
|
+
} catch (makeDateError) {
|
|
46
|
+
this.logger.error(
|
|
47
|
+
"Invalid parameter: duration."
|
|
48
|
+
);
|
|
49
|
+
throw new Error("Invalid parameter: duration.");
|
|
50
|
+
}
|
|
51
|
+
let extendStorageResponse;
|
|
52
|
+
try {
|
|
53
|
+
extendStorageResponse = await this.bee.extendStorage(
|
|
54
|
+
postageBatchId,
|
|
55
|
+
extendSize,
|
|
56
|
+
extendDuration
|
|
57
|
+
);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
let errorMessage = "Extend failed.";
|
|
60
|
+
if (errorHasStatus(error, NOT_FOUND_STATUS)) {
|
|
61
|
+
errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;
|
|
62
|
+
} else if (errorHasStatus(error, BAD_REQUEST_STATUS)) {
|
|
63
|
+
errorMessage = getErrorMessage(error);
|
|
64
|
+
}
|
|
65
|
+
this.logger.error(
|
|
66
|
+
errorMessage,
|
|
67
|
+
error
|
|
68
|
+
);
|
|
69
|
+
throw new Error(errorMessage);
|
|
70
|
+
}
|
|
71
|
+
return getResponseWithStructuredContent({
|
|
72
|
+
postageBatchId: extendStorageResponse.toHex()
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
ExtendPostageStampTool
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=index49.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index49.js","sources":["../../src/plugins/community/swarm/tools/ExtendPostageStampTool.ts"],"sourcesContent":["import {\r\n BaseHederaQueryTool,\r\n HederaAgentKit,\r\n type GenericPluginContext,\r\n} from \"hedera-agent-kit\";\r\nimport { BatchId, Bee, Duration, Size } from \"@ethersphere/bee-js\";\r\nimport { z } from \"zod\";\r\nimport {\r\n errorHasStatus,\r\n getErrorMessage,\r\n getResponseWithStructuredContent,\r\n makeDate,\r\n ToolResponse,\r\n} from \"../utils\";\r\nimport { BAD_REQUEST_STATUS, GATEWAY_STAMP_ERROR_MESSAGE, NOT_FOUND_STATUS } from \"../constants\";\r\nimport { SwarmConfig } from \"../config\";\r\n\r\nconst ExtendPostageStampSchema = z.object({\r\n postageBatchId: z.string(),\r\n duration: z.string().optional(),\r\n size: z.number().optional(),\r\n});\r\n\r\nexport class ExtendPostageStampTool extends BaseHederaQueryTool<typeof ExtendPostageStampSchema> {\r\n name = \"swarm-extend-postage-stamp\";\r\n description = `Increase the duration (relative to current duration) or size (in megabytes) of a postage stamp.\r\n postageBatchId: The id of the batch for which extend is performed.\r\n 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.\r\n duration: Duration for which the data should be stored. Time to live of the postage stamp, e.g. 1d - 1 day, 1w - 1 week, 1month - 1 month.\r\n `;\r\n namespace = \"swarm\";\r\n specificInputSchema = ExtendPostageStampSchema;\r\n bee: Bee;\r\n config: SwarmConfig;\r\n \r\n constructor(params: {\r\n hederaKit: HederaAgentKit;\r\n config: SwarmConfig;\r\n logger?: GenericPluginContext['logger'];\r\n bee: Bee;\r\n }) {\r\n const { bee, config, ...rest } = params;\r\n super(rest);\r\n this.bee = bee;\r\n this.config = config;\r\n }\r\n \r\n protected async executeQuery(\r\n input: z.infer<typeof ExtendPostageStampSchema>\r\n ): Promise<ToolResponse | string> {\r\n const { postageBatchId, duration, size } = input;\r\n\r\n if (!postageBatchId) {\r\n this.logger.error(\r\n 'Missing required parameter: postageBatchId.'\r\n );\r\n\r\n throw new Error('Missing required parameter: postageBatchId.');\r\n } else if (!duration && !size) {\r\n this.logger.error(\r\n 'You need at least one parameter from duration and size.'\r\n );\r\n\r\n throw new Error('You need at least one parameter from duration and size.');\r\n }\r\n\r\n // If size is missing, Size.fromBytes(1) will get smallest depth and not increase size.\r\n const extendSize = !!size ? Size.fromMegabytes(size) : Size.fromBytes(1); \r\n let extendDuration = Duration.ZERO;\r\n\r\n try {\r\n if (duration) {\r\n extendDuration = Duration.fromMilliseconds(makeDate(duration));\r\n }\r\n } catch (makeDateError) {\r\n this.logger.error(\r\n 'Invalid parameter: duration.'\r\n );\r\n\r\n throw new Error('Invalid parameter: duration.');\r\n }\r\n\r\n let extendStorageResponse;\r\n\r\n try {\r\n extendStorageResponse = await this.bee.extendStorage(\r\n postageBatchId,\r\n extendSize,\r\n extendDuration\r\n );\r\n } catch (error) {\r\n let errorMessage = 'Extend failed.';\r\n\r\n if (errorHasStatus(error, NOT_FOUND_STATUS)) {\r\n errorMessage = GATEWAY_STAMP_ERROR_MESSAGE;\r\n } else if (errorHasStatus(error, BAD_REQUEST_STATUS)) {\r\n errorMessage = getErrorMessage(error);\r\n }\r\n\r\n this.logger.error(\r\n errorMessage,\r\n error\r\n );\r\n\r\n throw new Error(errorMessage);\r\n }\r\n\r\n return getResponseWithStructuredContent({\r\n postageBatchId: extendStorageResponse.toHex(),\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;AAiBA,MAAM,2BAA2B,EAAE,OAAO;AAAA,EACxC,gBAAgB,EAAE,OAAA;AAAA,EAClB,UAAU,EAAE,OAAA,EAAS,SAAA;AAAA,EACrB,MAAM,EAAE,OAAA,EAAS,SAAA;AACn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I,MAAM,YAAY;AAAA,IAC9B;AAEA,WAAO,iCAAiC;AAAA,MACtC,gBAAgB,sBAAsB,MAAA;AAAA,IAAM,CAC7C;AAAA,EACH;AACF;"}
|
package/dist/esm/index5.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BasePlugin, HederaAirdropTokenTool } from "hedera-agent-kit";
|
|
2
|
-
import { TransferHbarTool } from "./
|
|
3
|
-
import { AirdropToolWrapper } from "./
|
|
2
|
+
import { TransferHbarTool } from "./index38.js";
|
|
3
|
+
import { AirdropToolWrapper } from "./index39.js";
|
|
4
4
|
class HbarPlugin extends BasePlugin {
|
|
5
5
|
constructor() {
|
|
6
6
|
super(...arguments);
|