UNPKG

@hashgraphonline/conversational-agent

Version:

Hashgraph Online conversational AI agent implementing HCS-10 communication, HCS-2 registries, and content inscription on Hedera. https://hol.org

58 lines (57 loc) 1.8 kB
import { z } from "zod"; import { errorHasStatus, getErrorMessage, getResponseWithStructuredContent } from "./index62.js"; import { BaseHederaQueryTool } from "hedera-agent-kit"; import { BAD_REQUEST_STATUS } from "./index63.js"; const DownloadDataSchema = z.object({ reference: z.string() }); class DownloadDataTool extends BaseHederaQueryTool { constructor(params) { const { bee, config, ...rest } = params; super(rest); this.name = "swarm-download-data"; this.description = ` Downloads immutable data from a Swarm content address hash. reference: Swarm reference hash. `; this.namespace = "swarm"; this.specificInputSchema = DownloadDataSchema; this.bee = bee; this.config = config; } async executeQuery(input) { const { reference } = input; if (!reference) { this.logger.error( "Missing required parameter: reference." ); throw new Error("Missing required parameter: reference."); } const isRefNotSwarmHash = reference.length !== 64 && reference.length !== 66; if (isRefNotSwarmHash) { this.logger.error( "Invalid Swarm content address hash value for reference." ); throw new Error("Invalid Swarm content address hash value for reference."); } let data; try { data = await this.bee.downloadData(reference); } catch (error) { let errorMessage = "Downloading data failed."; if (errorHasStatus(error, BAD_REQUEST_STATUS)) { errorMessage = getErrorMessage(error); } this.logger.error(errorMessage, error); throw new Error(errorMessage); } const textData = data.toUtf8(); return getResponseWithStructuredContent({ textData }); } } export { DownloadDataTool }; //# sourceMappingURL=index50.js.map